TOC PREV NEXT INDEX

Put your logo here!


5 INCLUDE FILES

5.1 evhCALLBACK.h


#ifndef evhCALLBACK_H
#define evhCALLBACK_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhCALLBACK.h,v 1.98 1999/09/08 14:07:49 vltsccm Exp $"
*
* evhCALLBACK.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Split .h and .icc file
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef fndOBJECT_H
#include <fndOBJECT.h>
#endif

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhErrors_H
#include "evhErrors.h"
#endif

/* Defines for the return value from callback routines */
/* Group of valuee must be in OR to build the actual return code */
/* Some examples of return codes: */
/* evhCB_DELETE SUCCESS and delete the callback */
/* evhCB_DELETE | evhCB_SUCCESS SUCCESS and delete the callback */
/* evhCB_DELETE | evhCB_FAILURE FAILURE and delete the callback */
/* evhCB_DELETE | evhCB_FAILURE FAILURE and delete the callback */
/* evhCB_NO_DELETE SUCCESS and do not delete the callback */
/* evhCB_FAILURE FAILURE and DO NOT delete the cb. */
/* */
/* Returning 0 means: evhCB_NO_DELETE | evhCB_SUCCESS */

typedef vltUINT32 evhCB_COMPL_STAT;

// Bit 1: 1 if FAILURE 0 if SUCCESS
#define evhCB_FAILURE 1
#define evhCB_SUCCESS 0

// Bit 2: 0 if NO DELETE 1 if delete requested
#define evhCB_NO_DELETE 0
#define evhCB_DELETE 2

// Bit 3 1 if return from main loop requested
#define evhCB_RETURN 4

// Bit 4 1 if no callback installed for a received message
#define evhCB_NOCALLS 8


/* Typedef for the callback proc type */
typedef evhCB_COMPL_STAT(*evhCB_PROC )(const msgRAW_MESSAGE &, void* );
typedef evhCB_COMPL_STAT(*evhCB_PROC2 )(const msgMESSAGE &, void* );

/* A callback is described as a pointer to function + the data to be passed */
#define evhCALLBACK_CLASS (classType)evhCALLBACK::CreateNew

class evhCALLBACK: public fndOBJECT, virtual public eccsERROR_CLASS
{
public:
evhCALLBACK();
evhCALLBACK(const evhCB_PROC procedure,void *udata = NULL);
evhCALLBACK(const evhCB_PROC2 procedure,void *udata = NULL);
evhCALLBACK(const evhCALLBACK &source);

evhCALLBACK &Proc(const evhCB_PROC procedure) ;
evhCALLBACK &Proc(const evhCB_PROC2 procedure) ;
evhCALLBACK &UserData(void *udata);

virtual int IsEqual( const fndOBJECT& ) const;

evhCALLBACK &operator =(const evhCALLBACK &source);

virtual evhCB_COMPL_STAT Run(const msgRAW_MESSAGE &msg);
virtual evhCALLBACK *Clone() const;

fndStdObjectDef(evhCALLBACK, fndOBJECT);

protected:
void *UserData() const { return userData; }
private:
evhCB_PROC proc;
void *userData;

}; /* end class evhCALLBACK */

#include "evhCALLBACK.icc"

#endif /*!evhCALLBACK_H*/


5.2 evhCALLBACK_DICT.h


#ifndef evhCALLBACK_DICT_H
#define evhCALLBACK_DICT_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhCALLBACK_DICT.h,v 1.98 1999/09/08 14:07:50 vltsccm Exp $"
*
* evhCALLBACK_DICT.h
*
* who when what
* -------- -------- ----------------------------------------------
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* vltsw 23/07/96 Added memory collector to make safer callback removal
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef fndDICTIONARY_H
#include <fndDICTIONARY.h>
#endif
#ifndef fndASSOCIATION_H
#include <fndASSOCIATION.h>
#endif

#ifndef evhMSG_TYPE_KEY_H
#include "evhMSG_TYPE_KEY.h"
#endif
#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif
#ifndef evhOBJ_CALLBACK_H
#include "evhOBJ_CALLBACK.h"
#endif

/* The callback dictionary has some special methods */
#define evhCALLBACK_DICT_CLASS (classType)evhCALLBACK_DICT::CreateNew

class evhCALLBACK_DICT: public fndDICTIONARY, virtual public eccsERROR_CLASS
{
public:

evhCALLBACK_DICT(const unsigned sz = fndDEFAULT_DICT_SIZE ):
fndDICTIONARY(sz) { collector.DelItemsOnDelete(); }

virtual ccsCOMPL_STAT AddCallback(const evhMSG_TYPE_KEY &key,
const evhCALLBACK &cb);
virtual ccsCOMPL_STAT ClearCallback(const evhMSG_TYPE_KEY &key);
virtual ccsCOMPL_STAT DelCallback(const evhMSG_TYPE_KEY &key,
const evhCALLBACK &cb);
virtual evhCB_COMPL_STAT Run(const evhMSG_TYPE_KEY &key,
const msgRAW_MESSAGE &msg);

virtual ccsCOMPL_STAT Collect();

fndStdObjectDef(evhCALLBACK_DICT, fndDICTIONARY);

protected:
fndLIST collector;

}; /* end class evhCALLBACK_DICT */



#endif /*!evhCALLBACK_DICT_H*/






5.3 evhCALLBACK_LIST.h


#ifndef evhCALLBACK_LIST_H
#define evhCALLBACK_LIST_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhCALLBACK_LIST.h,v 1.98 1999/09/08 14:07:50 vltsccm Exp $"
*
* evhCALLBACK_LIST.h
*
* who when what
* -------- -------- ----------------------------------------------
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef fndLIST_H
#include <fndLIST.h>
#endif

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif

/* The dictionary value is a list for callbacks */
#define evhCALLBACK_LIST_CLASS (classType)evhCALLBACK_LIST::CreateNew

class evhCALLBACK_LIST: public fndLIST, virtual public eccsERROR_CLASS
{
public:
evhCALLBACK_LIST() {};

evhCB_COMPL_STAT Run(const msgRAW_MESSAGE &msg);

fndStdObjectDef(evhCALLBACK_LIST, fndLIST);

}; /* end class evhCALLBACK_LIST */




#endif /*!evhCALLBACK_LIST_H*/









5.4 evhCOMMAND.h


#ifndef evhCOMMAND_H
#define evhCOMMAND_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhCOMMAND.h,v 1.98 1999/09/08 14:07:50 vltsccm Exp $"
*
* evhTIMEOUT.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Replace ccsTIMEVAL with eccsTIMEVAL.
* gchiozzi 12/06/97 Split in .h and .icc
* gchiozzi 07/10/96 Added TimeoutRefresh() method
* gchiozzi 04/10/96 Added call to ResetTimeout() in SetTimeout()
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 12/05/95 Added protected methods to interface private members
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef fndOBJECT_H
#include <fndOBJECT.h>
#endif

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif
#ifndef evhTIMEOUT_H
#include "evhTIMEOUT.h"
#endif

#define evhCOMMAND_CLASS (classType)evhCOMMAND::CreateNew

class evhCOMMAND: public fndOBJECT, virtual public eccsERROR_CLASS
{
public:
evhCOMMAND();
~evhCOMMAND();

static eccsTIMEVAL nullInterval;

virtual ccsCOMPL_STAT Send(msgMESSAGE &msg); /* Send the command */
virtual vltLOGICAL Status() const; /* Gets the internal status */
virtual ccsCOMPL_STAT Reset(); /* Reset the command handler */

virtual ccsCOMPL_STAT Reply(evhCALLBACK &cb);
virtual ccsCOMPL_STAT ErrReply(evhCALLBACK &cb);

virtual ccsCOMPL_STAT Timeout(evhCALLBACK &cb, eccsTIMEVAL interval);
virtual ccsCOMPL_STAT Timeout(eccsTIMEVAL interval);
virtual ccsCOMPL_STAT TimeoutRefresh(eccsTIMEVAL interval = evhCOMMAND::nullInterval);

const char *Command() const;
msgCMDID CommandId() const;

virtual int IsEqual( const fndOBJECT& ) const;

fndStdObjectDef(evhCOMMAND, fndOBJECT);


protected:
virtual int _ReplyCB(msgMESSAGE &msg, void *udata);
virtual int _ErrReplyCB(msgMESSAGE &msg, void *udata);
virtual int _TimeoutCB(msgMESSAGE &msg, void *udata);

virtual evhCOMMAND &Status(vltLOGICAL newStatus);

evhCALLBACK *Reply() const;
evhCALLBACK *ErrReply() const;
evhCALLBACK *Timeout() const;

ccsCOMPL_STAT SetCallbacks(msgMESSAGE &msg);
ccsCOMPL_STAT ResetCallbacks();
ccsCOMPL_STAT SetTimeout();
ccsCOMPL_STAT ResetTimeout();

private:
vltLOGICAL status;

evhCALLBACK *reply;
evhCALLBACK *errReply;
evhCALLBACK *timeout;
eccsTIMEVAL interval;
evhTIMEOUT *timeHndl;

msgCMD command;
msgCMDID commandId;

}; /* end class evhCOMMAND */

#include "evhCOMMAND.icc"

#endif /*!evhCOMMAND_H*/


5.5 evhCRONOMETER.h


#ifndef evhCRONOMETER_H
#define evhCRONOMETER_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhCRONOMETER.h,v 1.98 1999/09/08 14:07:56 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Replace ccsTIMEVAL with eccsTIMEVAL.
* gchiozzi 12/06/97 Split in .h and .icc
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* rabuter 25/10/95 created
*
*/
/************************************************************************
*
*----------------------------------------------------------------------
*/
#ifndef _UNISTD_INCLUDED
#include <unistd.h>
#endif
#ifndef _STDLIB_INCLUDED
#include <stdlib.h>
#endif
#ifndef _LIMITS_INCLUDED
#include "limits.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif
#ifndef evhTIMEOUT_H
#include "evhTIMEOUT.h"
#endif

extern "C" {
#include "timer.h"
#include "tims.h"
}



// Status
#define CRONOMETER_RUNNING 1
#define CRONOMETER_STOPPED 0
// Units
#define CRONOMETER_MSEC 2
#define CRONOMETER_USEC 1
#define CRONOMETER_SEC 0


class evhCRONOMETER : virtual public eccsERROR_CLASS
{
public:
evhCRONOMETER();
virtual ~evhCRONOMETER(){};

virtual ccsCOMPL_STAT Reset();
virtual ccsCOMPL_STAT Start();
virtual vltUINT32 Stop( vltLOGICAL unit = CRONOMETER_MSEC );
vltLOGICAL Status()const;
vltUINT32 ElapsedUsec();
vltUINT32 ElapsedSec();
vltUINT32 ElapsedMsec();

private:
eccsTIMEVAL *Elapsed();
eccsTIMEVAL elapsed;
vltLOGICAL status;
eccsTIMEVAL start_time;
eccsTIMEVAL stop_time;
}; /* end class evhCRONOMETER */

#include "evhCRONOMETER.icc"

#endif /*!evhCRONOMETER_H*/


5.6 evhDB_CMD_SEND.h


#ifndef evhDB_CMD_SEND_H
#define evhDB_CMD_SEND_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_CMD_SEND.h,v 1.98 1999/09/08 14:07:53 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 31/07/98 Added proper fndStdObject...() calls
* gchiozzi 12/02/97 Added new ActualSendCommand protected method
* gchiozzi 15/03/96 Added protected access methods for user installed callbacks
* gchiozzi 04/07/95 Added inst. cb for completion, errors and timeout
* gchiozzi 02/05/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef db_H
#include "db.h"
#endif
#ifndef evhDB_TASK_H
#include "evhDB_TASK.h"
#endif
#ifndef evhDB_COMMAND_H
#include "evhDB_COMMAND.h"
#endif
#ifndef evhDB_COMMAND_H
#include "evhDB_COMMAND.h"
#endif

#ifndef fndLIST_H
#include "fndLIST.h"
#endif
#ifndef evhDB_SEND_ID_H
#include "evhDB_SEND_ID.h"
#endif

#define evhCMD_POINT "cmd"

typedef classType evhDB_COMMAND_TYPE;

class evhDB_CMD_SEND : public evhDB_TASK
{
public:
/* Static variable used as default when no wait id is requested */
static evhDB_SEND_ID noWaitId;

evhDB_CMD_SEND(const dbSYMADDRESS dbPoint, evhDB_COMMAND_TYPE type);
~evhDB_CMD_SEND();

virtual ccsCOMPL_STAT Init();
virtual ccsCOMPL_STAT Reset();
virtual ccsCOMPL_STAT Send(const msgCMD command,
const char *newBuffer,
msgLENGTH newBuflen=0,
evhDB_SEND_ID *sendId=NULL,
evhDB_SEND_ID waitId=
evhDB_CMD_SEND::noWaitId);
virtual ccsCOMPL_STAT Timeout(int timeout);

virtual ccsCOMPL_STAT Completed(evhCALLBACK &cb);
virtual ccsCOMPL_STAT Error(evhCALLBACK &cb);
virtual ccsCOMPL_STAT Timeout(evhCALLBACK &cb);

const char *Destination();

/* Should not be necessary to have these public: protected should be OK */
/* I think that here GCC has some problems */
ccsCOMPL_STAT Register(evhDB_CMD_SEND *who, vltUINT32 id);
ccsCOMPL_STAT UnRegister(evhDB_CMD_SEND *who, vltUINT32 id);
virtual ccsCOMPL_STAT SendCommand(evhDB_SEND_ID &);

fndStdObjectDef(evhDB_CMD_SEND, evhDB_TASK);

protected:


virtual ccsCOMPL_STAT Notify();
ccsCOMPL_STAT SetCommand(const msgCMD command,
const char *newBuffer, msgLENGTH newBuflen=0);
ccsCOMPL_STAT ActualSendCommand();

/* Hook functions to implement a user defined behaviour on completion */
virtual evhCB_COMPL_STAT CompletedCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT ErrorCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT TimeoutCB(msgMESSAGE &msg, void *udata);

/* Real callbacks. Call hooks and do internal administration */
virtual evhCB_COMPL_STAT EventCompletedCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT EventErrorCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT EventTimeoutCB(msgMESSAGE &msg, void *udata);

virtual evhCALLBACK *CompletedUserInstCB();
virtual evhCALLBACK *ErrorUserInstCB();
virtual evhCALLBACK *TimeoutUserInstCB();

vltUINT32 Id();
ccsCOMPL_STAT SetId();
fndLIST &WaitingList();

virtual evhDB_COMMAND *Cmd();
evhDB_COMMAND *NewCmd(const dbSYMADDRESS dbPoint,evhDB_COMMAND_TYPE type);

evhDB_CMD_SEND(); // NON to be used!!!

private:
evhDB_COMMAND *cmd;
msgMESSAGE msg;
vltUINT32 id;

evhCALLBACK *completed;
evhCALLBACK *error;
evhCALLBACK *timeout;

evhDB_SEND_ID waitingFor;
fndLIST waitingList;

static vltUINT32 lastId;
};


#include "evhDB_CMD_SEND.icc"

#endif /*!evhDB_CMD_SEND_H*/


5.7 evhDB_CMD_SERIAL.h


#ifndef evhDB_CMD_SERIAL_H
#define evhDB_CMD_SERIAL_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_CMD_SERIAL.h,v 1.98 1999/09/08 14:07:53 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 31/07/98 Added proper fndStdObject...() calls
* gchiozzi 15/05/96 Necessary to add also Timeout(evhCALLBACK &cb). GCC bug?
* gchiozzi 02/05/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef evhDB_CMD_SEND_H
#include "evhDB_CMD_SEND.h"
#endif
#ifndef fndLIST_H
#include "fndLIST.h"
#endif

class evhDB_CMD_SERIAL : public evhDB_CMD_SEND
{
public:
evhDB_CMD_SERIAL(const dbSYMADDRESS dbPoint, evhDB_COMMAND_TYPE type);
~evhDB_CMD_SERIAL();

virtual ccsCOMPL_STAT Init();
virtual ccsCOMPL_STAT Reset();
virtual ccsCOMPL_STAT Send(const msgCMD command,
const char *newBuffer, msgLENGTH newBuflen=0,
evhDB_SEND_ID *sendId = NULL,
evhDB_SEND_ID waitId = evhDB_CMD_SEND::noWaitId);
virtual ccsCOMPL_STAT Timeout(int timeout);
virtual ccsCOMPL_STAT Timeout(evhCALLBACK &cb);

virtual ccsCOMPL_STAT SendCommand(evhDB_SEND_ID &);

protected:
virtual ccsCOMPL_STAT Notify();
virtual ccsCOMPL_STAT SelfClean(evhDB_SEND_ID &);

/* Real callbacks. Call hooks and do internal administration */
virtual evhCB_COMPL_STAT EventCompletedCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT EventErrorCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT EventTimeoutCB(msgMESSAGE &msg, void *udata);

virtual evhDB_COMMAND *Cmd();

ccsCOMPL_STAT QueueCheck();

evhDB_CMD_SERIAL(); // NON to be used!!!

fndStdObjectDef(evhDB_CMD_SERIAL, evhDB_CMD_SEND);

private:
fndLIST queue;
evhDB_COMMAND *cmdAlt;
vltLOGICAL cmdSwitchFlag;

};


#endif /*!evhDB_CMD_SERIAL_H*/


5.8 evhDB_COMMAND.h


#ifndef evhDB_COMMAND_H
#define evhDB_COMMAND_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_COMMAND.h,v 1.98 1999/09/08 14:07:53 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 23/09/96 ParseTarget() method: parameter target is now const char*
* gchiozzi 22/01/96 Added CopyConfig() method.
* gchiozzi 02/05/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef db_H
#include "db.h"
#endif
#ifndef evhHANDLER_H
#include "evhHANDLER.h"
#endif
#ifndef evhCOMMAND_H
#include "evhCOMMAND.h"
#endif

#define evhDB_COMMAND_CLASS (classType)evhDB_COMMAND::CreateNew

class evhDB_COMMAND : public evhCOMMAND
{
public:
evhDB_COMMAND(const dbSYMADDRESS dbPoint = "");
~evhDB_COMMAND();

virtual const char *Destination();
virtual const char *DbPoint();
virtual ccsCOMPL_STAT DbPoint(const dbSYMADDRESS dbPoint);
virtual ccsCOMPL_STAT Send(msgMESSAGE &msg);

virtual ccsCOMPL_STAT CopyConfig(evhDB_COMMAND &cmd);

virtual int IsEqual( const fndOBJECT& ) const;

fndStdObjectDef(evhDB_COMMAND, evhCOMMAND);

protected:
ccsCOMPL_STAT ParseTarget(ccsENVNAME destEnv, ccsPROCNAME destProc,
const char *target);

private:
dbSYMADDRESS dbPoint;
vltBYTES32 destination;
};


#endif /*!evhDB_COMMAND_H*/


5.9 evhDB_LIST_COMMAND.h


#ifndef evhDB_LIST_COMMAND_H
#define evhDB_LIST_COMMAND_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_LIST_COMMAND.h,v 1.98 1999/09/08 14:07:54 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 02/05/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef evhDB_COMMAND_H
#include "evhDB_COMMAND.h"
#endif

#define evhDB_LIST_DEST "List of destinations"

#define evhDB_LIST_COMMAND_CLASS (classType)evhDB_LIST_COMMAND::CreateNew

class evhDB_LIST_COMMAND : public evhDB_COMMAND
{
public:
evhDB_LIST_COMMAND(const dbSYMADDRESS dbPoint = "");
~evhDB_LIST_COMMAND();

virtual ccsCOMPL_STAT Send(msgMESSAGE &msg);
virtual ccsCOMPL_STAT Reset(); /* Reset the command handler */

virtual const char *Destination();

int Counter() const;

fndStdObjectDef(evhDB_LIST_COMMAND, evhDB_COMMAND);

protected:
virtual int _ReplyCB(msgMESSAGE &msg, void *udata);
evhDB_LIST_COMMAND &Counter(int counter);

private:
vltINT32 counter; // number of commands not completed.

};


#endif /*!evhDB_LIST_COMMAND_H*/


5.10 evhDB_SEND_ID.h


#ifndef evhDB_SEND_ID_H
#define evhDB_SEND_ID_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_SEND_ID.h,v 1.98 1999/09/08 14:07:54 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 02/05/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef db_H
#include "db.h"
#endif
#ifndef fndOBJECT_H
#include "fndOBJECT.h"
#endif

class evhDB_CMD_SEND;

class evhDB_SEND_ID: public fndOBJECT {

public:

evhDB_SEND_ID(evhDB_CMD_SEND *cmd = NULL, vltUINT32 id = 0);
evhDB_SEND_ID(const evhDB_SEND_ID &newId);

virtual int IsEqual(const fndOBJECT&) const;

evhDB_SEND_ID &operator =(const evhDB_SEND_ID&);

evhDB_CMD_SEND *cmd;
vltUINT32 id;

fndStdObjectDef(evhDB_SEND_ID,fndOBJECT);

};


#include "evhDB_SEND_ID.icc"

#endif /*!evhDB_SEND_ID_H*/


5.11 evhDB_SERIAL_DATA.h


#ifndef evhDB_SERIAL_DATA_H
#define evhDB_SERIAL_DATA_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_SERIAL_DATA.h,v 1.98 1999/09/08 14:07:55 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 02/05/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif

#ifndef db_H
#include "db.h"
#endif
#ifndef fndOBJECT_H
#include "fndOBJECT.h"
#endif
#ifndef evhHANDLER_H
#include "evhHANDLER.h"
#endif
#ifndef evhDB_CMD_SEND_H
#include "evhDB_CMD_SEND.h"
#endif

class evhDB_SERIAL_DATA: public fndOBJECT {

public:

evhDB_SERIAL_DATA(const msgCMD command,
const char *newBuffer,
msgLENGTH newBuflen,
evhDB_SEND_ID sendId,
evhDB_SEND_ID waitId = evhDB_CMD_SEND::noWaitId);
evhDB_SERIAL_DATA(const evhDB_SERIAL_DATA &newId);
~evhDB_SERIAL_DATA();

virtual int IsEqual(const fndOBJECT&) const;

evhDB_SERIAL_DATA &operator =(const evhDB_SERIAL_DATA&);

vltLOGICAL Active();
evhDB_SERIAL_DATA &Active(vltLOGICAL newState);

/* In a clean implementation these should be private */
msgCMD command;
char *buffer;
msgLENGTH buflen;
evhDB_SEND_ID sendId;
evhDB_SEND_ID waitId;

fndStdObjectDef(evhDB_SERIAL_DATA,fndOBJECT);

private:
evhDB_SERIAL_DATA() {}; // Cannot be used
vltLOGICAL active;
};


#include "evhDB_SERIAL_DATA.icc"

#endif /*!evhDB_SERIAL_DATA_H*/


5.12 evhDB_SYNC.h


#ifndef evhDB_SYNC_H
#define evhDB_SYNC_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_SYNC.h,v 1.98 1999/09/08 14:07:55 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 01/06/95 Created
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef evhSYNC_H
#include "evhSYNC.h"
#endif
#ifndef eccsEvt_H
#include "eccsEvt.h"
#endif
#ifndef eccsDB_ATTR_H
#include "eccsDB_ATTR.h"
#endif

class evhDB_SYNC: public evhSYNC
{
public:
evhDB_SYNC();
~evhDB_SYNC();

ccsCOMPL_STAT AddCondition(const evhMSG_TYPE_KEY &key,
int *flag = NULL, int value = TRUE);
ccsCOMPL_STAT AddCondition(const dbSYMADDRESS attr,
int value = TRUE, int check = FALSE);

fndStdObjectDef(evhDB_SYNC, evhSYNC);

protected:
virtual evhCB_COMPL_STAT HandlerCB(msgMESSAGE &msg, void *udata);

}; /* end class evhDB_SYNC */


/* This is a special class, used privately only */
/* by the class evhDB_SYNC to hold the conditions */
/* to be tested */
class evhDB_CONDITION : public evhCONDITION
{
public:
evhDB_CONDITION();
evhDB_CONDITION(const dbSYMADDRESS attr,
int value = TRUE);

virtual ccsCOMPL_STAT Reset(evhCALLBACK &ocb);
virtual ccsCOMPL_STAT Run(evhCALLBACK &ocb);
virtual int Status();
virtual ccsCOMPL_STAT TryUpdate(msgMESSAGE &msg);

virtual int IsEqual( const fndOBJECT& ) const;

evhDB_CONDITION &operator =( const evhDB_CONDITION& );

virtual evhCONDITION &Status(int status);

fndStdObjectDef(evhDB_CONDITION, evhCONDITION);

private:
evtEVENT evt;
eccsDB_INT32 attribute;

};

#endif /*!evhDB_SYNC_H*/










5.13 evhDB_TASK.h


#ifndef evhDB_TASK_H
#define evhDB_TASK_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDB_TASK.h,v 1.98 1999/09/08 14:07:54 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 31/07/98 Added proper fndStdObject...() calls
* gchiozzi 18/08/97 Added handling of db write access rules
* gchiozzi 16/04/97 DbPoint is now virtual
* gchiozzi 28/07/95 Moved Init command handling in base class evhTASK
* gchiozzi 24/04/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef evhHANDLER_H
#include "evhHANDLER.h"
#endif
#ifndef evhTASK_H
#include "evhTASK.h"
#endif
#ifndef eccsDB_ATTR_H
#include "eccsDB_ATTR.h"
#endif
#ifndef fndNAME_MAP_H
#include "fndNAME_MAP.h"
#endif



/************************************/
/* Defines for commonly used states */
/************************************/
#ifndef evhStates_H
#include "evhStates.h"
#endif

class evhDB_TASK : public evhTASK
{
public:
evhDB_TASK(const dbSYMADDRESS dbPoint);
virtual ~evhDB_TASK();

vltINT32 State();
const char* StateName();

virtual const char *DbPoint() const;

fndStdObjectDef(evhDB_TASK, evhTASK);

protected:
vltLOGICAL DbWriteEnabled() const;

ccsCOMPL_STAT State(vltINT32 state);
const fndNAME_MAP *StateNames() const;

ccsCOMPL_STAT SetStateNamesTable(fndNAME_AND_INDEX *newTable,
unsigned int nelem);
ccsCOMPL_STAT SetStateNamesTable(fndNAME_MAP *newNameMap);

evhDB_TASK(); // NON to be used!!!

private:

dbSYMADDRESS dbPoint;

vltLOGICAL dbWriteEnabled;
vltINT32 state;
eccsDB_INT32 dbState;

fndNAME_MAP *stateNames;
vltLOGICAL privStateNames;

static fndNAME_AND_INDEX stateNamesTable[];
};


#endif /*!evhDB_TASK_H*/


5.14 evhDUMMY.h


#ifndef evhDUMMY_H
#define evhDUMMY_H
/***********************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDUMMY.h,v 1.98 1999/09/08 14:07:49 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 31/07/98 Added proper fndStdObject...() calls
* gchiozzi 13/06/97 Created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef __cplusplus
#error This is a C++ include file and cannot be used from plain C
#endif


#include "fndSTRING.h"
#include "fndASSOCIATION.h"
#include "fndINT.h"
#include "fndDICTIONARY.h"

/* Include files for EasyCCS and Evh Toolkit */
#include "ECCS.h"
#include "eccsTestTools.h"
#include "evhHANDLER.h"
#include "evhTIMEOUT.h"
#include "evhTASK.h"

#include "evhErrors.h"

/*
* Commands accepted by the class
*/

#define REGISTER_CMD "REGCMD"
#define UNREGISTER_CMD "UREGCMD"
#define PRINT_CMD "PRNCMD"
#define DMEXIT_CMD "DMEXIT"

/**************************************/
/* Support class for defining a reply */
/**************************************/

class evhDUMMY_REP_DATA: public fndOBJECT
{
public:
fndSTRING reply; // Message buffer
fndINT errReply; // FALSE/TRUE (error reply)
fndINT errCode; // 0 or code for error reply
fndINT timeout; // Timeout in seconds (0 == no timeout)

void PrintOn( ostream& ) const;

fndStdObjectDef(evhDUMMY_REP_DATA, fndOBJECT)

}; /* end class evhDUMMY_REP_DATA */


/*************************************************/
/* Support class to pass reply data and original */
/* message to the reply callback */
/*************************************************/

class evhDUMMY_CB_DATA: public fndOBJECT
{
public:
evhDUMMY_CB_DATA(msgMESSAGE &m,evhDUMMY_REP_DATA &d) :
msg(m), data(d), timeout(NULL) {};
~evhDUMMY_CB_DATA() { if(timeout) delete timeout; }

msgMESSAGE msg;
evhDUMMY_REP_DATA data;

/* We save here, if any, the pointer to the timeout for the */
/* waiting before sending the reply. In this way is at garbage */
/* collection the timeout is not expired, it will be cleanly */
/* deleted */
evhTIMEOUT *timeout;

fndStdObjectDef(evhDUMMY_CB_DATA, fndOBJECT);

private:
evhDUMMY_CB_DATA() {}; // NON to be used!!!

}; /* end class evhDUMMY_CB_DATA */


/******************************************/
/* Definition for the evhDUMMY class */
/******************************************/
class evhDUMMY: public evhTASK
{
public:
evhDUMMY();

ccsCOMPL_STAT LoadCommands(char *fname);

virtual evhCB_COMPL_STAT GenericCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT PrintCmdListCB(msgMESSAGE &msg, void *udata);

evhCB_COMPL_STAT RegisterCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT UnregisterCB(msgMESSAGE &msg, void *udata);

virtual ccsCOMPL_STAT StdMain(int argc, char *argv[]);
virtual ccsCOMPL_STAT PrintCLineHelp(void);
virtual ccsCOMPL_STAT ParseArguments(int argc, char *argv[]);

fndStdObjectDef(evhDUMMY, evhTASK);

protected:
virtual evhCB_COMPL_STAT SendReplyCB(msgMESSAGE &msg, evhDUMMY_CB_DATA *);
virtual ccsCOMPL_STAT SendErrorReply(msgMESSAGE &msg);
virtual ccsCOMPL_STAT SendReply(msgMESSAGE &msg, evhDUMMY_REP_DATA &data);

evhDUMMY_REP_DATA &Lookup(fndSTRING &cmd);
ccsCOMPL_STAT RegisterReply(msgMESSAGE &msg, evhDUMMY_REP_DATA &data);
virtual ccsCOMPL_STAT ParseCommandDesc(const char *mbuffer,
fndSTRING &cmd, evhDUMMY_REP_DATA &data);

fndDICTIONARY &RegCommands();

private:
fndDICTIONARY cmdDict;

/* List to contain dynamic objects created by RegisterReply() */
/* of type evhDUMMY_CB_DATA. This allow garbage collection of */
/* all the memory used for replies waiting to be sent when */
/* the object is deleted */
fndLIST collector;

char *procName; // Name of the evhDUMMY process
char *dataFile; // Name of the data configuration file

}; /* end class evhDUMMY */

#endif /*!evhDUMMY_H*/


5.15 evhFILEIO.h


#ifndef evhFILEIO_H
#define evhFILEIO_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhFILEIO.h,v 1.98 1999/09/08 14:07:51 vltsccm Exp $"
*
* evhFileIO.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 03/08/98 Added conditional include of evhSELECT.h
* jknudstr 09/01/95 created
*/

/************************************************************************
* Contains definition of FILEIO class for the CCS Event Handler
* module. Use to handle list of file descriptors.
*----------------------------------------------------------------------
*/

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhSELECT_H
#include "evhSELECT.h"
#endif

#define evhFILE_IO_CMD "EVHFDIO"

// The file IO class for handling input from UNIX file descriptors
class evhFILEIO: eccsERROR_CLASS
{
public:
evhFILEIO(int fd);
~evhFILEIO();

// To attach the fd stored in the object to be polled
ccsCOMPL_STAT Attach();

// To detach the fd so that no events for this are detected
ccsCOMPL_STAT Detach();

// Returns the fd for this object
int Fd() const;

// Indicates whether the fd for this obejct is attached or not
vltLOGICAL Status() const;

// Builds a 'fake' message if event was file IO
static ccsCOMPL_STAT BuildMsg(int fd, msgMSG *fileIoMsg);

// Returns the pointer to the fds list
static const int *FdsList();

private:
int file;
static int fds[evhMAX_NO_OF_FDS];
};

#endif /*!evhFILEIO_H*/


5.16 evhHANDLER.h


#ifndef evhHANDLER_H
#define evhHANDLER_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhHANDLER.h,v 1.98 1999/09/08 14:07:51 vltsccm Exp $"
*
* evhHANDLER.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Split in .h and .icc
* gchiozzi 24/09/96 Added checking of incoming commands
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* vltsw 12/07/96 Added destructor
* gchiozzi 24/11/95 Added convenience methods to Add/Del command callbacks
* G.Chiozzi 18/01/94 Added headers and documentation
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef evhErrors_H
#include "evhErrors.h"
#endif

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef eccsEvt_H
#include "eccsEvt.h"
#endif
#ifndef evhCRONOMETER_H
#include "evhCRONOMETER.h"
#endif
#ifndef evhCALLBACK_DICT_H
#include "evhCALLBACK_DICT.h"
#endif
#ifndef evhSELECT_H
#include "evhSELECT.h"
#endif
#ifndef eccsAlrmCon_H
#include "eccsAlrmCon.h"
#endif
#ifndef eccsAlrmMsg_H
#include "eccsAlrmMsg.h"
#endif

/* The callback dictionary has some special methods */
#define evhHANDLER_CLASS (classType)evhHANDLER::CreateNew

class evhHANDLER: public fndOBJECT, virtual public eccsERROR_CLASS
{
public:

evhHANDLER();
virtual ~evhHANDLER();

virtual ccsCOMPL_STAT AddCallback(const evhMSG_TYPE_KEY &key,
const evhCALLBACK &cb);
virtual ccsCOMPL_STAT ClearCallback(const evhMSG_TYPE_KEY &key);
virtual ccsCOMPL_STAT DelCallback(const evhMSG_TYPE_KEY &key,
const evhCALLBACK &cb);
virtual ccsCOMPL_STAT SetCallback(const evhMSG_TYPE_KEY &key,
const evhCALLBACK &cb);

virtual ccsCOMPL_STAT AddCmdCallback(const msgCMD cmd,
const evhCB_PROC procedure);
virtual ccsCOMPL_STAT AddCmdCallback(const msgCMD cmd,
fndOBJECT *obj,
const evhCB_METHOD procedure);
virtual ccsCOMPL_STAT DelCmdCallback(const msgCMD cmd,
const evhCB_PROC procedure);
virtual ccsCOMPL_STAT DelCmdCallback(const msgCMD cmd,
fndOBJECT *obj,
const evhCB_METHOD procedure);
virtual ccsCOMPL_STAT SetCmdCallback(const msgCMD cmd,
const evhCB_PROC procedure);
virtual ccsCOMPL_STAT SetCmdCallback(const msgCMD cmd,
fndOBJECT *obj,
const evhCB_METHOD procedure);

virtual ccsCOMPL_STAT UseSelect(vltLOGICAL mode = TRUE);
virtual ccsCOMPL_STAT MainLoop();

ccsCOMPL_STAT SetDefCmdHandler(evhCB_PROC newHandler = NULL);

ccsCOMPL_STAT CbTimeMonitor(vltLOGICAL mode = TRUE, vltUINT32 msec = 100);
static ccsCOMPL_STAT Trace(vltLOGICAL mode = TRUE);
static ccsCOMPL_STAT CheckCmd(vltLOGICAL mode = TRUE);

fndStdObjectDef(evhHANDLER, fndOBJECT)

protected:

virtual msgRAW_MESSAGE *Parse(msgHEADER *msgh);
virtual ccsCOMPL_STAT Receive(msgHEADER **msgh);
virtual ccsCOMPL_STAT CheckCmd(msgMESSAGE *msg);

evhCB_PROC GetDefCmdHandler() const;
evhCALLBACK_DICT &Dictionary();
evhSELECT &Select();
vltLOGICAL UseSelect() const;
vltLOGICAL CbTimeMonitor() const;

static vltLOGICAL TraceStatus();
static vltLOGICAL CheckCmdStatus();

private:

static vltLOGICAL trace;
static vltLOGICAL checkCmd;

vltLOGICAL cbtimemonitor;

/*Max default callback execution time*/
vltUINT32 cbtimedefault;

evhCALLBACK_DICT dict;
evhCB_PROC defCmdHandler;

/* Object used to select on files and signals */
vltLOGICAL useSelect;
evhSELECT select;

/* Variables to hold known messages after parsing */
msgMESSAGE cmdMsg;
evtEVENT_MSG evtMsg;
alrmMESSAGE alrmMsg;
/* Object to monitor callbacks exec time*/
evhCRONOMETER cbCronometer;


}; /* end class evhHANDLER */

/* Standard event handler */
extern evhHANDLER *evhHandler;

#include "evhHANDLER.icc"

#endif /*!evhHANDLER_H*/


5.17 evhMSG_TYPE_KEY.h


#ifndef evhMSG_TYPE_KEY_H
#define evhMSG_TYPE_KEY_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhMSG_TYPE_KEY.h,v 1.98 1999/09/08 14:07:51 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Split in .h and .icc
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/


#ifndef fndOBJECT_H
#include "fndOBJECT.h"
#endif

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif

/* A first key is based on TYPE, COMMAND and COMMANDID */
#define evhMSG_TYPE_KEY_CLASS (classType)evhMSG_TYPE_KEY::CreateNew

class evhMSG_TYPE_KEY: public fndOBJECT, virtual public eccsERROR_CLASS
{
public:
evhMSG_TYPE_KEY(const vltUINT8 type = 0 ,
const msgCMD cmd = msgNULL_CMD,
const msgCMDID cmdId = 0);
evhMSG_TYPE_KEY(const evhMSG_TYPE_KEY &source);


evhMSG_TYPE_KEY &MsgType(const vltUINT8 type);
vltUINT8 MsgType() const;
evhMSG_TYPE_KEY &Command(const msgCMD cmd);
const char *Command() const;
evhMSG_TYPE_KEY &CommandId(const msgCMDID cmdId);
msgCMDID CommandId() const;

virtual int IsEqual( const fndOBJECT& ) const;
virtual hashValueType HashValue() const;
virtual void PrintOn( ostream& ) const;

evhMSG_TYPE_KEY &operator =( const evhMSG_TYPE_KEY& );

fndStdObjectDef(evhMSG_TYPE_KEY, fndOBJECT)

private:
vltUINT8 msgType;
msgCMD command;
msgCMDID commandId;


}; /* end class evhMSG_TYPE_KEY */

#include "evhMSG_TYPE_KEY.icc"

#endif /*!evhMSG_TYPE_KEY_H*/


5.18 evhOBJ_CALLBACK.h


#ifndef evhOBJ_CALLBACK_H
#define evhOBJ_CALLBACK_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhOBJ_CALLBACK.h,v 1.98 1999/09/08 14:07:52 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Split in .h and .icc
* gfilippi 09/07/99 (evhCB_METHOD)NULL -> NULL in const evhCB_METHOD ...
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef fndOBJECT_H
#include <fndOBJECT.h>
#endif

#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif

/* Typedef for the callback proc type */
typedef evhCB_COMPL_STAT
(fndOBJECT::*evhCB_METHOD)(const msgRAW_MESSAGE &,void*);
typedef evhCB_COMPL_STAT
(fndOBJECT::*evhCB_METHOD2)(const msgMESSAGE &,void*);

/* A callback is described as a pointer to function + the data to be passed */
#define evhCALLBACK_CLASS (classType)evhCALLBACK::CreateNew

class evhOBJ_CALLBACK: public evhCALLBACK
{
public:
evhOBJ_CALLBACK();
evhOBJ_CALLBACK(fndOBJECT *obj,
const evhCB_METHOD procedure = NULL,
void *udata = NULL);
evhOBJ_CALLBACK(fndOBJECT *obj,
const evhCB_METHOD2 procedure,void *udata = NULL);
evhOBJ_CALLBACK(const evhOBJ_CALLBACK &source);

evhOBJ_CALLBACK &Object(fndOBJECT *obj);
evhOBJ_CALLBACK &Proc(const evhCB_METHOD procedure) ;
evhOBJ_CALLBACK &Proc(const evhCB_METHOD2 procedure) ;

virtual int IsEqual( const fndOBJECT& ) const;

evhOBJ_CALLBACK &operator =(const evhOBJ_CALLBACK &source);

virtual evhCB_COMPL_STAT Run(const msgRAW_MESSAGE &msg);
virtual evhCALLBACK *Clone() const;

fndStdObjectDef(evhOBJ_CALLBACK, evhCALLBACK)

private:
fndOBJECT *object;
evhCB_METHOD method;

}; /* end class evhOBJ_CALLBACK */


#include "evhOBJ_CALLBACK.icc"

#endif /*!evhOBJ_CALLBACK_H*/


5.19 evhSELECT.h


#ifndef evhSELECT_H
#define evhSELECT_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSELECT.h,v 1.98 1999/09/08 14:07:51 vltsccm Exp $"
*
* evhSelect.h
*
* who when what
* -------- -------- ----------------------------------------------
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* jknudstr 09/01/95 created
*/

/************************************************************************
* Contains definition of SELECT class for the CCS Event Handler
* module. Used to handle asynchronous wait on any UNIX file descriptor,
* and to handle incoming signals.
*----------------------------------------------------------------------
*/

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif

/////////////////////////////////////////////////////////////////////////
// Macros to be moved somewhere else
/////////////////////////////////////////////////////////////////////////

// Maximum number of possible file descriptors
#define evhMAX_NO_OF_FDS 256
#define evhNO_OF_SIGNALS 30

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////


// The evhSELECT class for handling asynchronous wait for incoming
// events
class evhSELECT: virtual public eccsERROR_CLASS
{
public:
evhSELECT();
~evhSELECT();

// Performs an asynchroneous wait for events
ccsCOMPL_STAT Select(msgHEADER **msgHeader);

private:
static msgMSG *msg;
};

#endif /*!evhSELECT_H*/









5.20 evhSIGNAL.h


#ifndef evhSIGNAL_H
#define evhSIGNAL_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSIGNAL.h,v 1.98 1999/09/08 14:07:52 vltsccm Exp $"
*
* evhSignal.h
*
* who when what
* -------- -------- ----------------------------------------------
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* jknudstr 09/01/95 created
*/

/************************************************************************
* Contains definition of evhSIGNAL class for the CCS Event Handler
* module. Used to handle installation and deinstallation of the
* EVH signal handler.
*----------------------------------------------------------------------
*/

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif


#define evhSIG_DATA_SIZE 64

#define evhSIGNAL_CMD "EVHSIG"

// The Signal Class to administrate the adding and deleting of
// signal handlers
class evhSIGNAL: virtual public eccsERROR_CLASS
{
public:
evhSIGNAL(int sig);
virtual ~evhSIGNAL();

// To install the EVH signal handler for the specified signal
virtual ccsCOMPL_STAT Install();

// To desintall the EVH signal handler, and to reinstall the
// default signal handler
virtual ccsCOMPL_STAT Deinstall();

// Returns the signal registered for this object
int Sig() const;

// Indicates whether a signal handler is installed for this obejct or not
vltLOGICAL Status() const;

// Builds a 'fake' message if the event was a signal
static ccsCOMPL_STAT BuildMsg(int sig, msgMSG *signalMsg);

// Methods to get information about the last signal catched
// Gets the type of the last handled signal
static int LastSignal();
static void ResetSignal();
static const char *SignalData();
static int SignalErrStatus();

private:

int sig; // signal handled in this instance

// This row contains a flag indicating if a signal handler has
// already been installed for this signal:
// SIG_FREE = nothing installed,
// SIG_REGISTERED = signal handler registerd, but not installed,
// SIG_INSTALLED = signal handler installed
enum SIG_STATUS { SIG_FREE, SIG_REGISTERED, SIG_INSTALLED };
static SIG_STATUS signalsInst[evhNO_OF_SIGNALS];

// Static variables used for handling the signal
// and set by the signal handler
static int signalHandle; // Signal id
static char signalData[evhSIG_DATA_SIZE]; // Buffer to pass back data
static int signalErrStatus; // Return status from the signal handler

// The EVH signal handler
static void SignalHandler(int sig);
};

#endif /*!evhSIGNAL_H*/


5.21 evhStates.h


#ifndef evhStates_H
#define evhStates_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhStates.h,v 1.98 1999/09/08 14:07:55 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 17/04/97 Patched to be used without including ccs.h
* gchiozzi 22/05/96 Removed c++ style comments
* gchiozzi 23/05/95 created
*/

/************************************************************************
*
* This include file contains standard definitions for state codes and
* names.
* It is used both by C++ code and by dbLoader database definitions
*----------------------------------------------------------------------
*/

/************************************
* Defines for commonly used states *
************************************/

/* This should be replaced by */
/* #include "ccsStates.h" */

#ifndef ccsSTATE_UNK
#define ccsSTATE_UNK 0
#define ccsSTATE_OFF 1
#define ccsSTATE_LOADED 2
#define ccsSTATE_STANDBY 3
#define ccsSTATE_ONLINE 4
#define ccsSTATE_STANDALONE 11
#endif

#define evhSTATE_UNK ccsSTATE_UNK
#define evhSTATE_OFF ccsSTATE_OFF
#define evhSTATE_LOADED ccsSTATE_LOADED
#define evhSTATE_STANDBY ccsSTATE_STANDBY
#define evhSTATE_ONLINE ccsSTATE_ONLINE
#define evhSTATE_READY 5
#define evhSTATE_ERROR 6
#define evhSTATE_IDLE 7
#define evhSTATE_WAITING 8
#define evhSTATE_BUSY 9
#define evhSTATE_Q_CHECK 10
#define evhSTATE_STANDALONE ccsSTATE_STANDALONE

/******************************************
* Defines for commonly used states names *
******************************************/

#define evhSTATE_STR_UNK "UNKNOWN"
#define evhSTATE_STR_OFF "OFF"
#define evhSTATE_STR_LOADED "LOADED"
#define evhSTATE_STR_STANDBY "STANDBY"
#define evhSTATE_STR_ONLINE "ONLINE"
#define evhSTATE_STR_READY "READY"
#define evhSTATE_STR_ERROR "ERROR"
#define evhSTATE_STR_IDLE "IDLE"
#define evhSTATE_STR_WAITING "WAITING"
#define evhSTATE_STR_BUSY "BUSY"
#define evhSTATE_STR_Q_CHECK "QUEUE_CHECK"

/*
* evhDB_TASK.C contains the fndNAME_AND_INDEX table for name-index conversion
* The table must be updated whenever these definitions change
*/

#endif /*!evhStates_H*/



5.22 evhSTD_COMMANDS.h


#ifndef evhSTD_COMMANDS_H
#define evhSTD_COMMANDS_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhSTD_COMMANDS.h,v 1.98 1999/09/08 14:07:55 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 31/07/98 Added proper fndStdObject...() calls
* gchiozzi 24/04/95 created
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef evhHANDLER_H
#include "evhHANDLER.h"
#endif
#ifndef evhDB_TASK_H
#include "evhDB_TASK.h"
#endif

/**********************************************************/
/* Defines for selection of implemented standard commands */
/**********************************************************/

// All commands
#define evhSTD_USE_ALL 0xffffffff

// Standard commands
#define evhSTD_USE_STATE 0x00000001
#define evhSTD_USE_STATUS 0x00000002
#define evhSTD_USE_STANDBY 0x00000004
#define evhSTD_USE_ONLINE 0x00000008
#define evhSTD_USE_OFF 0x00000010
#define evhSTD_USE_SELFTST 0x00000020
#define evhSTD_USE_TEST 0x00000040
#define evhSTD_USE_SIMULAT 0x00000080
#define evhSTD_USE_STOPSIM 0x00000100
#define evhSTD_USE_VERBOSE 0x00000200
#define evhSTD_USE_VERSION 0x00000400
#define evhSTD_USE_EXIT 0x00000800
#define evhSTD_USE_STOP 0x00001000
#define evhSTD_USE_INIT 0x00002000

// Special commands handled by CCS
#define evhSTD_USE_KILL 0x00004000
#define evhSTD_USE_BREAK 0x00008000
#define evhSTD_USE_PING 0x00010000


/**********************************************************/
/* Command names for implemented standard commands */
/**********************************************************/

#include "evhSTD_COMMANDS_NAMES.h"

class evhSTD_COMMANDS : public evhDB_TASK
{
public:
evhSTD_COMMANDS(const dbSYMADDRESS dbPoint,
vltUINT32 commands = evhSTD_USE_ALL,
const char *version = "No module version set");
~evhSTD_COMMANDS();

virtual evhCB_COMPL_STAT StateCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT StatusCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT StandByCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT OnlineCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT OffCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT SelfTestCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT TestCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT SimulatCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT StopSimCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT VerboseCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT VersionCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT StopCB(msgMESSAGE &msg, void *udata);

vltLOGICAL Simulation();
ccsCOMPL_STAT Simulation(vltLOGICAL value);
vltLOGICAL Verbose();
ccsCOMPL_STAT Verbose(vltLOGICAL value);

fndStdObjectDef(evhSTD_COMMANDS, evhDB_TASK);

protected:
virtual evhCB_COMPL_STAT SetStateCB(vltINT32 newState,
msgMESSAGE &msg,
void *udata);

evhSTD_COMMANDS(); // NON to be used!!!

private:

vltUINT32 commands;
const char *version;

vltLOGICAL simulation;
vltLOGICAL verbose;
eccsDB_LOGICAL dbSimulation;
eccsDB_LOGICAL dbVerbose;
};

#endif /*!evhSTD_COMMANDS_H*/


5.23 evhSYNC.h


#ifndef evhSYNC_H
#define evhSYNC_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSYNC.h,v 1.98 1999/09/08 14:07:49 vltsccm Exp $"
*
* evhSYNC.h
*
* who when what
* -------- -------- ----------------------------------------------
* rkarban 06/08/99 remove defaulting to NULL in Action method
* gchiozzi 12/06/97 Replace ccsTIMEVAL with eccsTIMEVAL.
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 28/06/95 Restructured class
* gchiozzi 01/06/95 Completely restructured.
* gchiozzi 20/02/95 created
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef fndLIST_H
#include "fndLIST.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhTIMEOUT_H
#include "evhTIMEOUT.h"
#endif

class evhSYNC: public fndLIST, virtual public eccsERROR_CLASS
{
public:
evhSYNC();
~evhSYNC();

ccsCOMPL_STAT Action(evhCALLBACK &newCB);
ccsCOMPL_STAT AddCondition(const evhMSG_TYPE_KEY &key,
int *flag = NULL, int value = TRUE);
ccsCOMPL_STAT Timeout(evhCALLBACK &cb, eccsTIMEVAL interval);
ccsCOMPL_STAT Timeout(eccsTIMEVAL interval);

virtual int Check();
virtual ccsCOMPL_STAT ClearConditions();
virtual ccsCOMPL_STAT Reset();
virtual ccsCOMPL_STAT Run();

virtual vltLOGICAL Status();

fndStdObjectDef(evhSYNC, fndLIST);

protected:
virtual evhCB_COMPL_STAT HandlerCB(msgMESSAGE &msg, void *udata);

virtual evhCB_COMPL_STAT _HandlerCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT _TimeoutCB(msgMESSAGE &msg, void *udata);

private:
vltLOGICAL status;

evhCALLBACK *cb;
evhCALLBACK *timeout;
eccsTIMEVAL interval;
evhTIMEOUT *timeHndl;

}; /* end class evhSYNC */


/* This is a special class, used privately only */
/* by the class evhSYNC to hold the conditions */
/* to be tested */
class evhCONDITION : public fndOBJECT
{
public:
evhCONDITION();
evhCONDITION(const evhMSG_TYPE_KEY &key,int *flag = NULL,int value = TRUE);

virtual ccsCOMPL_STAT Reset(evhCALLBACK &ocb);
virtual ccsCOMPL_STAT Run(evhCALLBACK &ocb);
virtual int Status();
virtual ccsCOMPL_STAT TryUpdate(msgMESSAGE &msg);

virtual int IsEqual( const fndOBJECT& ) const;

evhCONDITION &operator =( const evhCONDITION& );

fndStdObjectDef(evhCONDITION, fndOBJECT);

protected:

virtual evhMSG_TYPE_KEY &Key();
virtual evhCONDITION &Key(evhMSG_TYPE_KEY &key);
virtual evhCONDITION &Status(int status);

int Value();

private:
evhMSG_TYPE_KEY key;
int *flag;
int value;
int status;
};

#endif /*!evhSYNC_H*/


5.24 evhTASK.h


#ifndef evhTASK_H
#define evhTASK_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhTASK.h,v 1.98 1999/09/08 14:07:52 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 31/07/98 Added proper fndStdObject...() calls
* gchiozzi 12/06/97 Split in .h and .icc
* gchiozzi 13/02/97 Added include of evhCALLBACK.h
* gchiozzi 13/02/97 Added include of fndOBJECT.h
* gchiozzi 29/08/96 Added LogExitWarning()
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 28/07/95 Added class instances counter
* gchiozzi 28/07/95 Added INIT command handling
* gchiozzi 08/12/94 created
*/

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif

#ifndef fndOBJECT_H
#include "fndOBJECT.h"
#endif
#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif

#define evhEXIT_CMD "EXIT"
#define evhPING_CMD "PING"
#define evhINIT_CMD "INIT"

/************************************/
/* Definition for the evhTASK class */
/************************************/
class evhSIMPLE_TASK: public fndOBJECT, virtual public eccsERROR_CLASS
{
public:
evhSIMPLE_TASK();

const char *Name() const;

fndStdObjectDef(evhSIMPLE_TASK, fndOBJECT);

protected:
char *name; /* Task name */

}; /* end class evhSIMPLE_TASK */


class evhTASK: public evhSIMPLE_TASK
{
public:
evhTASK();
virtual ~evhTASK();

virtual evhCB_COMPL_STAT ExitCB(msgMESSAGE &msg, void *udata);
virtual evhCB_COMPL_STAT InitCB(msgMESSAGE &msg, void *udata);

virtual ccsCOMPL_STAT Init();

static ccsCOMPL_STAT LogExitWarning(vltLOGICAL flag=TRUE);

fndStdObjectDef(evhTASK, evhSIMPLE_TASK);

protected:
static vltUINT32 TaskInstances();

private:
static vltUINT32 counter;
static vltLOGICAL logExitWarning;

}; /* end class evhTASK */

#include "evhTASK.icc"

#endif /*!evhTASK_H*/


5.25 evhTIMEOUT.h


#ifndef evhTIMEOUT_H
#define evhTIMEOUT_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhTIMEOUT.h,v 1.98 1999/09/08 14:07:52 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Replace ccsTIMEVAL with eccsTIMEVAL.
* gchiozzi 12/06/97 Split in .h and .icc
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 28/06/95 The static 'cmd' is now allocated dynamically
* G.Chiozzi 11/02/94 Added headers and documentation
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/

#ifndef fndOBJECT_H
#include <fndOBJECT.h>
#endif

#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef evhCALLBACK_H
#include "evhCALLBACK.h"
#endif
#ifndef evhMSG_TYPE_KEY_H
#include "evhMSG_TYPE_KEY.h"
#endif


#define evhTIMEOUT_CMD "TIMEOUT"

#define evhTIMEOUT_CLASS (classType)evhTIMEOUT::CreateNew

class evhTIMEOUT: public fndOBJECT, virtual public eccsERROR_CLASS
{
public:
evhTIMEOUT(evhCALLBACK &user_cb, eccsTIMEVAL interval);
~evhTIMEOUT();

virtual int IsEqual( const fndOBJECT& ) const;

fndStdObjectDef(evhTIMEOUT, fndOBJECT);

protected:

evhTIMEOUT(evhCALLBACK &user_cb); /* This is only for subclasses */
vltLOGICAL Status() const;
virtual int TimeoutCB(msgMESSAGE &msg, void *udata);

void Init(evhCALLBACK &user_cb); /* Used by const. to init data struct */

vltUINT32 requestId;
evhCALLBACK *cb;
evhMSG_TYPE_KEY key;

static vltUINT32 count;
static msgMESSAGE *cmd;

evhTIMEOUT(){ /* not allowed */ };

private:
evhTIMEOUT &operator =(const evhTIMEOUT &) {
return *this; /* not allowed */ };

}; /* end class evhTIMEOUT */

#include "evhTIMEOUT.icc"

#endif /*!evhTIMEOUT_H*/


5.26 evhTIMER.h


#ifndef evhTIMER_H
#define evhTIMER_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhTIMER.h,v 1.98 1999/09/08 14:07:52 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Replace ccsTIMEVAL with eccsTIMEVAL.
* G.Chiozzi 11/02/94 Added headers and documentation
*
*/

/************************************************************************
*
*----------------------------------------------------------------------
*/
#ifndef evhTIMEOUT_H
#include "evhTIMEOUT.h"
#endif

#define evhTIMER_CLASS (classType)evhTIMER::CreateNew

class evhTIMER: public evhTIMEOUT
{
public:
evhTIMER(evhCALLBACK &user_cb, eccsTIMEVAL interval);
evhTIMER(evhCALLBACK &user_cb, eccsTIMEVAL interval, eccsTIMEVAL startTime);
fndStdObjectDef(evhTIMER, evhTIMEOUT);

protected:
virtual int TimeoutCB(msgMESSAGE &msg, void *udata);
evhTIMER() { /* not allowed */ };

}; /* end class evhTIMER */


#endif /*!evhTIMER_H*/


6 EXAMPLE PROGRAMS

6.1 RECEIVE A COMMAND AND SEND BACK REPLY


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_1.C,v 1.98 1999/09/08 14:08:26 vltsccm Exp $"
*
* evhSample_1.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 08/12/94 created
*/

/************************************************************************
* NAME
* evhSample_1
*
* SYNOPSIS
*
* evhSample_1
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* It can receive the commands implemented in the base class evhTASK
* plus the new command "SAMPLE".
* The callback for the "SAMPLE" command just send back a reply to the
* caller.
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Addition of a new command and simple usage of evhMSG_TYPE_KEY
* and evhOBJ_CALLBACK classes
* - Usage of EasyCCS class msgMESSAGE to receive messages and send replies
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for EasyCCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include for the basic class
#include "evhTASK.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

// Definition for the callback to be used receiving the
// "SAMPLE" command
evhCB_COMPL_STAT SampleCB(msgMESSAGE &msg, void *udata);

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/* This variable is used to define the event: */
/* a message of type msgTYPE_COMMAND, with */
/* Command="SAMPLE", no regard for the CommandId */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND,"SAMPLE");

/* This variable is used to define the callback: */
/* It is a method of this object, no user parameters */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::SampleCB);

/* Then the callback is attached to the event handler */
evhHandler->AddCallback(key,cb);
}

/* Body for the callback */
evhCB_COMPL_STAT APPLICATION::SampleCB(msgMESSAGE &msg, void *)
{
/* Just print the message buffer on stdout */
printf("Received a SAMPLE command: %s\n", msg.Buffer());

/* Send back the reply to the command */
msg.LastReply(ccsTRUE);
msg.Buffer("Command received!");
msg.SendReply();

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.2 SEND OFF COMMAND AND RECEIVE REPLIES

6.2.1 Process 1


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_2.C,v 1.98 1999/09/08 14:08:26 vltsccm Exp $"
*
* evhSample_2.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 12/06/97 Removet ccsTIMEVAL when not necessary
* gchiozzi 09/12/94 created
*/

/************************************************************************
* NAME
* evhSample_2
*
* SYNOPSIS
*
* evhSample_2 value
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* It sends the command "REPLYME" to the companion program evhSample_2bis
* and waits fo the replies.
*
* The command line parameter can be:
*
* n > 0 We ask evhSample_2bis to send back n replies
* n = 0 We ask evhSample_2bis to send back NO reply.
* As a consequence the timeout (5 seconds) will expire
* n < 0 We ask evhSample_2bis to send back an error reply
*
* The handling of replies is done using an object of class evhCOMMAND.
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Usage of the evhCOMMAND class
* - Usage of EasyCCS class msgMESSAGE to receive messages and send replies
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include file for the evhCOMMAND class
#include "evhCOMMAND.h"

// Include for the basic class
#include "evhTASK.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:

// The constructor gets the number we want to pass in the command
// (by defaults it is 1, requesting for 1 standard reply
APPLICATION(int n=1);

// Definition for the callbacks to be used receiving the
// replies from the sent command
evhCB_COMPL_STAT ReplyCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT ErrReplyCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT TimeoutCB(msgMESSAGE &msg, void *udata);

private:

evhCOMMAND cmd; // Object to handle the commands

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
/* In this simple example, the constructor init */
/* everything AND send the command to the */
/* companion application */
APPLICATION::APPLICATION(int n)
{

/******************************************************/
/* The evhCOMMAND cmd data member is available and */
/* must be initialized, setting the callbacks for the */
/* events */
/******************************************************/

evhOBJ_CALLBACK cb(this);

cmd.Reply(cb.Proc((evhCB_METHOD)&APPLICATION::ReplyCB));
cmd.ErrReply(cb.Proc((evhCB_METHOD)&APPLICATION::ErrReplyCB));
cmd.Timeout(cb.Proc((evhCB_METHOD)&APPLICATION::TimeoutCB),5); /* with the time */

/*****************************************/
/* Then I prepare the command to be sent */
/*****************************************/
msgMESSAGE msg;
char buff[20];

sprintf(buff,"%d",n);

msg.Command("REPLYME");
msg.Destenv(getenv("RTAPENV"));
msg.Buffer(buff);
msg.Destproc("evhSample_2bis");

/*****************************************/
/* Then I send the command. */
/*****************************************/

/* The commandId for the set command is a unique value */
/* and the callbacks defined in the previous lines are */
/* set in order to wait only for replies with that */
/* specific commandId */
cmd.Send(msg);

}

/* Body for the callbacks */
evhCB_COMPL_STAT APPLICATION::ReplyCB(msgMESSAGE &msg, void *)
{
/* Just print the message buffer on stdout */
printf("Received a REPLY: %s\n", msg.Buffer());

/* Test if this is the last reply */
/* If so, exit in a clean way */
if(msg.LastReply() == ccsTRUE)
{
ccsExit();
exit(0);
}

/* The callback must remain installed for another reply */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::ErrReplyCB(msgMESSAGE &, void *)
{
/* Just print the message buffer on stdout */
printf("Received an ERROR REPLY\n");

ccsExit();
exit(1);

/* The GCC complain if there is no return, but this instruction */
/* will never be executed */
return(evhCB_DELETE);
}

evhCB_COMPL_STAT APPLICATION::TimeoutCB(msgMESSAGE &, void *)
{
/* Just print the message buffer on stdout */
printf("Timeout expired\n");

ccsExit();
exit(1);

/* The GCC complain if there is no return, but this instruction */
/* will never be executed */
return(evhCB_DELETE);
}



/**********************************/
/* main procedure */
/**********************************/

int main(int argc, char *argv[])
{
int value = 1;

ccsInit(argv[0]);

if(argc > 1) value = atoi(argv[1]);

printf("Calling evhSample_2 with the parameter: %d\n",value);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app(value); USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.2.2 Process 2


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_2bis.C,v 1.98 1999/09/08 14:08:27 vltsccm Exp $"
*
* evhSample_1.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 09/12/94 created
*/

/************************************************************************
* NAME
* evhSample_2bis
*
* SYNOPSIS
*
* evhSample_2bis
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* It reveives the command "REPLYME" from the companion program evhSample_2
* and waits fo the replies.
*
* The command buffer can be:
*
* n > 0 We ask evhSample_2bis to send back n replies
* n = 0 We ask evhSample_2bis to send back NO reply.
* As a consequence the timeout (5 seconds) will expire
* n < 0 We ask evhSample_2bis to send back an error reply
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Addition of a new command and simple usage of evhMSG_TYPE_KEY
* and evhOBJ_CALLBACK classes
* - Usage of EasyCCS class msgMESSAGE to receive messages and send replies
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include for the basic class
#include "evhTASK.h"
#include "eccsTestTools.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

// Definition for the callback to be used receiving the
// "SAMPLE" command
evhCB_COMPL_STAT ReplyMeCB(msgMESSAGE &msg, void *udata);

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/* This variable is used to define the event: */
/* a message of type msgTYPE_COMMAND, with */
/* Command="SAMPLE", no regard for the CommandId */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND,"REPLYME");

/* This variable is used to define the callback: */
/* It is a method of this object, no user parameters */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::ReplyMeCB);

/* Then the callback is attached to the event handler */
evhHandler->AddCallback(key,cb);
}

/* Body for the callback */

evhCB_COMPL_STAT APPLICATION::ReplyMeCB(msgMESSAGE &msg, void *)
{
/* Read from the buffer the value and stores it in a local variable */
int value = atoi(msg.Buffer());

/* Just print the message buffer on stdout */
eccsLogComment("Received a REPLYME command: %d", value);

/* Send back the requested number of replies for the command: */
/* Sends n replies if the given value was a positive one */
if( value > 0)
while(value--)
{
msg.LastReply(value ? ccsFALSE : ccsTRUE);
msg.Buffer("Reply!");
msg.SendReply();
}

/* Sends an error reply if the given value was a negative one */
else if( value < 0)
{
errAdd(&(msg.Errmsg()),"eccs",eccsERR_GENERIC,__FILE_LINE__,"");
msg.SendReply();
}
/* Do nothing if the given value was 0 */

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

eccsLogComment("Entering the main loop and waiting for commands!");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.3 HANDLING OF A TIMEOUT


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_3.C,v 1.98 1999/09/08 14:08:27 vltsccm Exp $"
*
* evhSample_3.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 12/06/97 Removet ccsTIMEVAL when not necessary
* gchiozzi 08/12/94 created
*/

/************************************************************************
* NAME
* evhSample_3
*
* SYNOPSIS
*
* evhSample_3
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* After 10 seconds, a timeout expires and the program exit.
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Usage of the evhTIMEOUT class
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

#include "evhTIMEOUT.h"

// Include for the basic class
#include "evhTASK.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

evhCB_COMPL_STAT TimeoutCB(msgMESSAGE &msg, void *udata);

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/*********************************************/
/*********************************************/
/* A TIMEOUT of 10 seconds is installed */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::TimeoutCB);

/* Observe here that the evhTIMEOUT is created on the heap */
/* with the 'new' command (C++ equivalent of malloc()) */
/* It the evhTIMEOUT object is created as a local variable with: */
/* evhTIMEOUT tm(cb.Proc((evhCB_METHOD)TimeoutCB),interval); */
/* it is automatically deleted on return from this function, and */
/* no timeout occurs. */
/* The new evhTIMEOUT() call, returns a pointer to the */
/* newly created object. This pointer can be stored to delete */
/* explicitly the timeout object before the time expires */

new evhTIMEOUT(cb,10);
}

/* Body for the callback */
evhCB_COMPL_STAT APPLICATION::TimeoutCB(msgMESSAGE &msg, void *)
{
/* Just print the message buffer on stdout */
printf("My lifetime is expired: %s\n", msg.Command());

ccsExit();
exit(0);

/* Just to make GCC happy: this instruction will never be executed */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.4 USAGE OF THE EVH TIMER FEATURE


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_4.C,v 1.98 1999/09/08 14:08:27 vltsccm Exp $"
*
* evhSample_4.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 08/12/94 created
*/

/************************************************************************
* NAME
* evhSample_4
*
* SYNOPSIS
*
* evhSample_4
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* Every 100 micro seconds, for 50 times, it prints a message, then
* exit (the real timing depends on the machine performances).
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Usage of the evhTIMER class
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

#include "evhTIMER.h"

// Include for the basic class
#include "evhTASK.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

evhCB_COMPL_STAT TimerCB(msgMESSAGE &msg, void *udata);

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/*********************************************/
/*********************************************/
/* A TIMEOUT of 10 seconds is installed */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::TimerCB);
ccsTIMEVAL interval;

interval.tv_sec = 0;
interval.tv_usec = 100;

/* Observe here that the evhTIMER is created on the heap */
/* with the 'new' command (C++ equivalent of malloc()) */
/* It the evhTIMEOUT object is created as a local variable with: */
/* evhTIMEOUT tm(cb.Proc((evhCB_METHOD)TimeoutCB),interval); */
/* it is automatically deleted on return from this function, and */
/* no timeout occurs. */
/* The new evhTIMER() call, returns a pointer to the */
/* newly created object. This pointer can be stored to delete */
/* explicitly the timeout object before the time expires */

new evhTIMER(cb,interval);
}

/* Body for the callback */
evhCB_COMPL_STAT APPLICATION::TimerCB(msgMESSAGE &, void *)
{
static int counter = 0;
/* Just print the message buffer on stdout */
printf("Another clock tick: %d\n", counter);

if( counter++ == 50)
{
printf("End of work: %d\n", counter);
ccsExit();
exit(0);
}

/* The callback must remain installed for another tick */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.5 SYNCHRONIZATION WITH MULTIPLE EVENTS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_5.C,v 1.98 1999/09/08 14:08:27 vltsccm Exp $"
*
* evhSample_5.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 12/06/97 Removet ccsTIMEVAL when not necessary
* gchiozzi 01/06/95 Modif. doc. according to new behaviour of callbacks
* gchiozzi 08/12/94 created
*/

/************************************************************************
* NAME
* evhSample_5
*
* SYNOPSIS
*
* evhSample_5
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* It waits until it has received tree command "PASS1","PASS2" and
* "PASS3", then exit.
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Usage of the class evhSYNC to handle conditions based over
* multiple events
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* Observe that the generic callback CommandCB() is not executed
* while the SYNC callback is installed.
* As a consequence, when the "PASS1" command is sent for the first
* time, the SYNC callback is executed and deinstalled.
* Id the "PASS1" command is executed again, no other specific callback
* is installed, so the generic CommandCB() callback is executed.
* The only callback that is always executed is the generic callback
* installed with unspecified message type, command name and command ID.
*
* This DIFFERS from the previous version ov evh..
*
* In the older omplementation, the CommandCB() callback was always executed.
* Callbacks were executed in the same order for a specific event (same
* message type, command and command id).
* After the specific callbacks, the database was searched for callbacks
* with command id = 0 and finally for callbacks installed also with
* also command = "".
*
* This was the case for the CommandCB() callback, that was executed after
* the more specific ActionCB(), where the command was ONE of "PASS1",
* "PASS2" and "PASS3",
*
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"
#include "evhSYNC.h"

// Include for the basic class
#include "evhTASK.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

// This function will be called when all the events are verified
evhCB_COMPL_STAT ActionCB(msgMESSAGE &msg, void *udata);
// This function will be called on the timeout
evhCB_COMPL_STAT TimeoutCB(msgMESSAGE &msg, void *udata);

// This function is called when any command is received
evhCB_COMPL_STAT CommandCB(msgMESSAGE &msg, void *udata);

private:

// The APPLICATION class uses an instance od evhSYNC to handle
// multiple conditions
evhSYNC test;

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/*********************************************/
/**** Install the generic command handler ****/
/* This variable is used to define the event: */
/* a message of type msgTYPE_COMMAND, with */
/* no regard for the Command and the CommandId */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND);

/* This variable is used to define the callback: */
/* It is a method of this object, no user parameters */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::CommandCB);

/* Then the callback is attached to the event handler */
evhHandler->AddCallback(key,cb);

/*****************************************************/
/**** Install the event handler to terminate when ****/
/**** all the conditions are satisfied ****/

// Install the callbacks for the action and the timeout
test.Action(cb.Proc((evhCB_METHOD)&APPLICATION::ActionCB));
test.Timeout(cb.Proc((evhCB_METHOD)&APPLICATION::TimeoutCB),20);

// Defines the conditions
test.AddCondition( key.Command("PASS1"));
test.AddCondition( key.Command("PASS2"));
test.AddCondition( key.Command("PASS3"));

// Activate the syncronizer
test.Run();
}

/* Body for the callback */
evhCB_COMPL_STAT APPLICATION::CommandCB(msgMESSAGE &msg, void *)
{
/* Just print the message buffer on stdout */
printf("Received a command: %s\n", msg.Command());

/* Send back the reply to the command */
msg.LastReply(ccsTRUE);
msg.Buffer("Command received!");
msg.SendReply();

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}


evhCB_COMPL_STAT APPLICATION::ActionCB(msgMESSAGE &, void *)
{
/* Just print the message buffer on stdout */
printf("OK, all conditions verified. I exit.\n");

/* Just to make GCC happy */
return evhCB_NO_DELETE | evhCB_RETURN;
}


evhCB_COMPL_STAT APPLICATION::TimeoutCB(msgMESSAGE &, void *)
{
/* Just print the message buffer on stdout */
printf("Timeout: not all the events received\n");

ccsExit();
exit(0);

/* Just to make GCC happy */
return evhCB_NO_DELETE | evhCB_RETURN;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/



6.6 HANDLING OF DATABASE EVENTS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_6.C,v 1.98 1999/09/08 14:08:28 vltsccm Exp $"
*
* evhSample_6.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/09/99 Improved to attach to a specific event
* gchiozzi 05/01/95 created
*/

/************************************************************************
* NAME
* evhSample_6
*
* SYNOPSIS
*
* evhSample_6
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* The APPLICATION class demonstrate the functions to attach to
* and handle database events.
*
* The program handle the following commands:
* - ANAME set the name of the database attribute
* - FILTER set the event filter (integer mask value. See CCS defines)
* - UMSG set the user message associate to the event
* - ATTACH attach the event configured with the previous commands
* - DETACH detach the event is attached
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include for the basic class
#include "evhTASK.h"
#include "eccsTestTools.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:

// Class constructor: here all the basic event handler are installed
APPLICATION();

// Class destructor: here everything is cleaned up
~APPLICATION();

// Definition for the callbacks to be used receiving the
// replies from the sent command
evhCB_COMPL_STAT AttrNameCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT FilterCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT UserMsgCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT AttachCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT DetachCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT DbEventCB(evtEVENT_MSG &msg, void *udata);

private:

/* Private methods to handle attach and detach of the event */
/* and of the related callbacks at the same time */
ccsCOMPL_STAT Attach();
ccsCOMPL_STAT Detach();

/* Event object */
evtEVENT evt;

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/* This variable is used to define the events */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND);

/* This variable is used to define the callbacks procedures */
evhOBJ_CALLBACK cb(this);

/* Then the callbacks are attached to the event handler */
evhHandler->AddCallback(key.Command("ANAME"),
cb.Proc((evhCB_METHOD)&APPLICATION::AttrNameCB));
evhHandler->AddCallback(key.Command("FILTER"),
cb.Proc((evhCB_METHOD)&APPLICATION::FilterCB));
evhHandler->AddCallback(key.Command("UMSG"),
cb.Proc((evhCB_METHOD)&APPLICATION::UserMsgCB));
evhHandler->AddCallback(key.Command("ATTACH"),
cb.Proc((evhCB_METHOD)&APPLICATION::AttachCB));
evhHandler->AddCallback(key.Command("DETACH"),
cb.Proc((evhCB_METHOD)&APPLICATION::DetachCB));

}


APPLICATION::~APPLICATION()
{
/* Detach the callback */
/* This variable is used to define the events */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND);

/* This variable is used to define the callbacks procedures */
evhOBJ_CALLBACK cb(this);

/* Then the callbacks are attached to the event handler */
evhHandler->DelCallback(key.Command("ANAME"),
cb.Proc((evhCB_METHOD)&APPLICATION::AttrNameCB));
evhHandler->DelCallback(key.Command("FILTER"),
cb.Proc((evhCB_METHOD)&APPLICATION::FilterCB));
evhHandler->DelCallback(key.Command("UMSG"),
cb.Proc((evhCB_METHOD)&APPLICATION::UserMsgCB));
evhHandler->DelCallback(key.Command("ATTACH"),
cb.Proc((evhCB_METHOD)&APPLICATION::AttachCB));
evhHandler->DelCallback(key.Command("DETACH"),
cb.Proc((evhCB_METHOD)&APPLICATION::DetachCB));
}

ccsCOMPL_STAT APPLICATION::Attach()
{
/* First of all attach the event */
evt.Attach();

/* Then attach the callback using the CommandId() */
/* generated by the attached event */

evhMSG_TYPE_KEY key;
evhOBJ_CALLBACK cb(this);

key.MsgType(msgTYPE_EVENT)
.Command(evtEVENT_CMD)
.CommandId(evt.CommandId());
cb.Proc((evhCB_METHOD)&APPLICATION::DbEventCB);

evhHandler->AddCallback(key,cb);

return SUCCESS;
}

ccsCOMPL_STAT APPLICATION::Detach()
{
/* Only if already attached */
if(evt.Status())
{
/* First detach the callback based on the CommandId() */
/* generated by the attached event */
evhMSG_TYPE_KEY key;
evhOBJ_CALLBACK cb(this);

key.MsgType(msgTYPE_EVENT)
.Command(evtEVENT_CMD)
.CommandId(evt.CommandId());
cb.Proc((evhCB_METHOD)&APPLICATION::DbEventCB);

/* The detach the event */
evt.Detach();
evhHandler->DelCallback(key,cb);
}

return SUCCESS;
}

/* Body for the callbacks */
evhCB_COMPL_STAT APPLICATION::AttrNameCB(msgMESSAGE &msg, void *)
{
/* Saves the current status */
int status = evt.Status();

eccsLogComment("Received a %s command: %s",
msg.Command(), msg.Buffer());

Detach();
evt.AttrName(msg.Buffer());

/* Is it was attached, reattach it */
if(status) Attach();

/* Send back the reply to the caller */
msg.SendReply("Command handled!");

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::FilterCB(msgMESSAGE &msg, void *)
{
/* Saves the current status */
int status = evt.Status();
evtFILTER f = (evtFILTER)atoi(msg.Buffer());

eccsLogComment("Received a %s command: %s",
msg.Command(), msg.Buffer());

Detach();
evt.Filter(f);

/* Is it was attached, reattach it */
if(status) Attach();

/* Send back the reply to the caller */
msg.SendReply("Command handled!");

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::UserMsgCB(msgMESSAGE &msg, void *)
{
/* Saves the current status */
int status = evt.Status();

eccsLogComment("Received a %s command: %s",
msg.Command(), msg.Buffer());

Detach();
evt.UserMsg(msg.Buffer());

/* Is it was attached, reattach it */
if(status) Attach();

/* Send back the reply to the caller */
msg.SendReply("Command handled!");

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::AttachCB(msgMESSAGE &msg, void *)
{
eccsLogComment("Received a %s command: %s",
msg.Command(), msg.Buffer());

/* Saves the current status */
if(!evt.Status())
Attach();

/* Send back the reply to the caller */
msg.SendReply("Command handled!");

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::DetachCB(msgMESSAGE &msg, void *)
{
eccsLogComment("Received a %s command: %s",
msg.Command(), msg.Buffer());

Detach();

/* Send back the reply to the caller */
msg.SendReply("Command handled!");

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

/* This callback is linked to DB events */
evhCB_COMPL_STAT APPLICATION::DbEventCB(evtEVENT_MSG &msg, void *)
{
char string[256];

/* Print what can of the new value for the attribute */
eccsLogComment("Received a db event for attribute: %s (type is: %d)",
msg.AttrName(), msg.AttrType());

if( msg.AttrType() == dbSCALAR)
{
dbDeToStr(msg.EventInfo().scalar.dataType,
(char *)(msg.EventInfo().scalar.newValue),
string,0,sizeof(string)-1);
eccsLogComment("\tThe new value is: %s", string);
}

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

eccsLogComment("Application started");

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */
APPLICATION app; USE(app);

/* enter the main loop */
evhHandler->MainLoop();

ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.7 HANDLING OF UNIX FILE I/O (USING THE SELECT FEATURE)


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_7.C,v 1.98 1999/09/08 14:08:28 vltsccm Exp $"
*
* evhSample_7.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 12/01/95 created
*/

/************************************************************************
* NAME
* evhSample_7
*
* SYNOPSIS
*
* evhSample_7
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
*
* It demonstrates how to handle input/output from unix file descriptors
*
* - Main program with TASK object instance and entering the main loop
* The event handler is set to use the "select" strategy for the
* handling of messages. This allows the handling of events from
* unix file descriptors.
* - Inheritance of a new TASK class
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include for the basic class
#include "evhTASK.h"

// Include for the evhFILEIO class
#include <fcntl.h>
#include "evhFILEIO.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

// Definition for the callback to be used receiving the
// "SAMPLE" command
evhCB_COMPL_STAT SampleCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT FileCB(msgMESSAGE &msg, void *udata);

private:
evhFILEIO *fio;

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION()
{
/* This variable is used to define the event: */
/* a message of type msgTYPE_COMMAND, with */
/* Command="SAMPLE", no regard for the CommandId */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND,"SAMPLE");

/* This variable is used to define the callback: */
/* It is a method of this object, no user parameters */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::SampleCB);

/* Then the callback is attached to the event handler */
evhHandler->AddCallback(key,cb);

/* Here I open a file for read and attach a callback */
/* to be used when there is something coming from that */
/* file */
int fd = open("evhSample_7.dat",O_RDONLY);
if(fd == -1)
{
printf("Cannot open the file!\n");
}
else
{
fio = new evhFILEIO(fd);
fio->Attach();
evhHandler->AddCallback(key.Command(evhFILE_IO_CMD).CommandId(fd),
cb.Proc((evhCB_METHOD)&APPLICATION::FileCB));
}
}

/* Body for the callback */
evhCB_COMPL_STAT APPLICATION::SampleCB(msgMESSAGE &msg, void *)
{
/* Just print the message buffer on stdout */
printf("Received a SAMPLE command: %s\n", msg.Buffer());

/* Send back the reply to the command */
msg.LastReply(ccsTRUE);
msg.Buffer("Command received!");
msg.SendReply();

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::FileCB(msgMESSAGE &msg, void *)
{
/* Loop to read from the file */

/* ATTENTION: for UNIX disk files this is not efficient */
/* because the select() function returns */
/* whenever the file is "ready" for ready, */
/* i.e. also if the are no characters to be */
/* read. In this case the read() returns 0 */
/* but the call to this function is anyway */
/* CPU consuming: it becomes more or less */
/* a poll. */

int n = 0;
const int bsize = 257;
char buff[bsize];
/* I read (bsize-1) characters to leave 1 byte for the '\0' */
while((n = read(msg.CommandId(),buff,bsize-1)) > 0)
{
buff[n] = '\0';
printf("fd: %d - %s\n", msg.CommandId(),buff);
}

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* Tells the standard event handler to catch messages */
/* using the select() system call. In this case is */
/* possible to catch also signals and file IO events */
/* as normal messages */
evhHandler->UseSelect(TRUE);

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.8 HANDLING OF UNIX SIGNALS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_8.C,v 1.98 1999/09/08 14:08:28 vltsccm Exp $"
*
* evhSample_8.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 12/01/95 created
*/

/************************************************************************
* NAME
* evhSample_8
*
* SYNOPSIS
*
* evhSample_8
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
*
* It demonstrate how to handle unix signals as events
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Handling of the SIGCHLD signal
*
* Every time the program receives the XCLOCK command, executes a new instance
* of the xclock program.
* Whenever one of these xclock terminates, it receives a SIGCHLD signal; it
* is catched and the registered callback executed, printing on standard
* output the pid of the child process
*
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include for the basic class
#include "evhTASK.h"

// Include for the evhSIGNAL class
#include <signal.h>
#include "evhSIGNAL.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:
APPLICATION();

// Definition for the callback to be used receiving the
// "XCLOCK" command
evhCB_COMPL_STAT XClockCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT SigChildCB(msgMESSAGE &msg, void *udata);

private:
evhSIGNAL sig;

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
APPLICATION::APPLICATION() : sig(SIGCHLD)
{
/* This variable is used to define the event: */
/* a message of type msgTYPE_COMMAND, with */
/* Command="XCLOCK", no regard for the CommandId */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND,"XCLOCK");

/* This variable is used to define the callback: */
/* It is a method of this object, no user parameters */
evhOBJ_CALLBACK cb(this,(evhCB_METHOD)&APPLICATION::XClockCB);

/* Then the callback is attached to the event handler */
evhHandler->AddCallback(key,cb);

/* Here I install the handler for the SIGCHLD signal */
sig.Install();
evhHandler->AddCallback(key.Command(evhSIGNAL_CMD).CommandId(SIGCHLD),
cb.Proc((evhCB_METHOD)&APPLICATION::SigChildCB));
}

/* Body for the callback */
evhCB_COMPL_STAT APPLICATION::XClockCB(msgMESSAGE &msg, void *)
{
int pid;
/* Just print the message buffer on stdout */
printf("Received a XCLOCK command, spawning the process\n");

/* Send back the reply to the command */
msg.LastReply(ccsTRUE);
msg.Buffer("Command received!");
msg.SendReply();

/* fork/exec to run the xclock */
if( pid = fork(), pid==0) /* in the child */
{
execl("/usr/bin/X11/xclock","xclock",0);
}

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::SigChildCB(msgMESSAGE &msg, void *)
{
int *pid = (int*)(msg.Buffer());
printf("Received a SIGCHLD signal: the xclock with pid %d is died\n",
*pid);

/* The callback must remain installed for another command */
return evhCB_NO_DELETE;
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* Tells the standard event handler to catch messages */
/* using the select() system call. In this case is */
/* possible to catch also signals and file IO events */
/* as normal messages */
evhHandler->UseSelect(TRUE);

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.9 DYNAMIC HANDLING OF COMMANDS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: evhSample_9.C,v 1.98 1999/09/08 14:08:28 vltsccm Exp $"
*
* evhSample_9.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 06/08/98 APPLICATION object is now within a scope area
* gchiozzi 13/01/95 created
*/

/************************************************************************
* NAME
* evhSample_2
*
* SYNOPSIS
*
* evhSample_2 value
*
* DESCRIPTION
*
* This program is a small example of usage of the Evh Toolkit.
* It demonstrate dynamic handling of commands
*
* It receives the following commands:
* - INSTALL n To dynamically install the HANDLE command
* - DELETE To dynamically delete the HANDLE command
* - HANDLE (if installed) to send itself a request
* with the REPLY command for n REPLIES
* When the last reply, an error reply or the timeout are
* received, the handle deinstall itself
* - REPLY n To send back to the requester n replies
*
* The n parameter can be:
*
* n > 0 We ask to send back n replies
* n = 0 We ask to send back NO reply.
* As a consequence the timeout on HANDLE (15 seconds)
* will expire
* n < 0 We ask to send back an error reply
*
* The HANDLE command is implemented using a dynamically allocated obejct
* of class evhCOMMAND. The callbacks delete the object itself when it
* is no more needed
*
* The program demonstrates the following aspects:
*
* - Main program with TASK object instance and entering the main loop
* - Inheritance of a new TASK class
* - Usage of the evhCOMMAND class with delete of the objec itself
* - Usage of EasyCCS class msgMESSAGE to receive messages and send replies
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
* To keep this example as small as possible, no error handling has been
* done: this is a bad practice and error conditions must always be catched
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
/*
* Local Headers
*/

// Include files for ECCS and Evh Toolkit
#include "ECCS.h"
#include "evhHANDLER.h"

// Include file for the evhCOMMAND class
#include "evhCOMMAND.h"

// Include for the basic class
#include "evhTASK.h"


/******************************************/
/* Definition for the APPLICATION class */
/******************************************/
class APPLICATION: public evhTASK
{
public:

// The constructor gets the number we want to pass in the command
// (by defaults it is 1, requesting for 1 standard reply
APPLICATION();

evhCB_COMPL_STAT InstallCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT DeleteCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT HandleCB(msgMESSAGE &msg, void *udata);

evhCB_COMPL_STAT SendReplyCB(msgMESSAGE &msg, void *udata);

// Definition for the callbacks to be used receiving the
// replies from the sent command
evhCB_COMPL_STAT ReplyCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT ErrReplyCB(msgMESSAGE &msg, void *udata);
evhCB_COMPL_STAT TimeoutCB(msgMESSAGE &msg, void *udata);

private:

evhCOMMAND *handle; // Pointer for the dymanically created handler

}; /* end class APPLICATION */


/* Body of the constructor method. */
/* It is called whenever an instance is created */
/* In this simple example, the constructor init */
/* everything AND send the command to the */
/* companion application */
APPLICATION::APPLICATION()
{
handle = NULL;

/* Install the callback for the commands that can be received */
/* by this application */
evhMSG_TYPE_KEY key(msgTYPE_COMMAND);
evhOBJ_CALLBACK cb(this);

evhHandler->AddCallback(key.Command("INSTALL"),
cb.Proc((evhCB_METHOD)&APPLICATION::InstallCB));
evhHandler->AddCallback(key.Command("DELETE"),
cb.Proc((evhCB_METHOD)&APPLICATION::DeleteCB));
evhHandler->AddCallback(key.Command("HANDLE"),
cb.Proc((evhCB_METHOD)&APPLICATION::HandleCB));
evhHandler->AddCallback(key.Command("REPLY"),
cb.Proc((evhCB_METHOD)&APPLICATION::SendReplyCB));


}


evhCB_COMPL_STAT APPLICATION::InstallCB(msgMESSAGE &msg, void *)
{
/* Check if already installed */
if(handle != NULL)
{
printf("Command handler already installed\n");
}
else
{
printf("Installing the command handler.\n");
evhOBJ_CALLBACK cb(this);

handle = new evhCOMMAND;

handle->Reply(cb.Proc((evhCB_METHOD)&APPLICATION::ReplyCB));
handle->ErrReply(cb.Proc((evhCB_METHOD)&APPLICATION::ErrReplyCB));
handle->Timeout(cb.Proc((evhCB_METHOD)&APPLICATION::TimeoutCB),15);
}

/* Send back the (last) reply */
msg.LastReply(ccsTRUE).SendReply();

return(evhCB_NO_DELETE);
}


evhCB_COMPL_STAT APPLICATION::DeleteCB(msgMESSAGE &msg, void *)
{
/* Check if not already installed */
if(handle == NULL)
{
printf("Command handler not installed!\n");
}
else
{
printf("Deleting the installed command handler\n");
delete handle;
handle = NULL;
}

/* Send back the (last) reply */
msg.LastReply(ccsTRUE).SendReply();

return(evhCB_NO_DELETE);
}


evhCB_COMPL_STAT APPLICATION::HandleCB(msgMESSAGE &msg, void *)
{
/* Check if not already installed */
if(handle == NULL)
{
printf("Command handler not installed!\n");
}
else
{
printf("Sending a request for %s replies\n", msg.Buffer());
msgMESSAGE rmsg;

rmsg.Command("REPLY");
rmsg.Destenv(getenv("RTAPENV"));
rmsg.Buffer(msg.Buffer());
rmsg.Destproc("evhSample_9");

/* Then I send the command */
handle->Send(rmsg);

}


/* Send back the (last) reply */
msg.LastReply(ccsTRUE).SendReply();

return(evhCB_NO_DELETE);
}


evhCB_COMPL_STAT APPLICATION::SendReplyCB(msgMESSAGE &msg, void *)
{
/* Read from the buffer the value and stores it in a local variable */
int value = atoi(msg.Buffer());

/* Just print the message buffer on stdout */
printf("Received a REPLYME command: %d\n", value);

/* Send back the requested number of replies for the command: */
/* Sends n replies if the given value was a positive one */
if( value > 0)
while(value--)
{
msg.LastReply(value ? ccsFALSE : ccsTRUE);
msg.Buffer("Reply!");
msg.SendReply();
}

/* Sends an error reply if the given value was a negative one */
else if( value < 0)
{
errAdd(&(msg.Errmsg()),"eccs",eccsERR_GENERIC,__FILE_LINE__,"");
msg.SendReply();
}
/* Do nothing if the given value was 0 */

return(evhCB_NO_DELETE);
}


/* Body for the callbacks */
evhCB_COMPL_STAT APPLICATION::ReplyCB(msgMESSAGE &msg, void *)
{
/* Just print the message buffer on stdout */
printf("Received a REPLY: %s\n", msg.Buffer());

if(msg.LastReply() == ccsTRUE)
{
if(handle != NULL)
{
delete handle; // This also removes the callback
handle = NULL;
}
}

/* The callback must remain installed for another reply */
return evhCB_NO_DELETE;
}

evhCB_COMPL_STAT APPLICATION::ErrReplyCB(msgMESSAGE &, void *)
{
/* Just print the message buffer on stdout */
printf("Received an ERROR REPLY\n");

if(handle != NULL)
{
delete handle;
handle = NULL;
/* I have to return evhCB_NO_DELETE, because the callbacks */
/* have been already removed in the previous "delete handle" */
return(evhCB_NO_DELETE);
}

return(evhCB_DELETE);
}

evhCB_COMPL_STAT APPLICATION::TimeoutCB(msgMESSAGE &, void *)
{
/* Just print the message buffer on stdout */
printf("Timeout expired\n");

if(handle != NULL)
{
delete handle;
handle = NULL;
/* I have to return evhCB_NO_DELETE, because the callbacks */
/* have been already removed in the previous "delete handle" */
return(evhCB_NO_DELETE);
}

return(evhCB_DELETE);
}



/**********************************/
/* main procedure */
/**********************************/

int main(int , char *argv[])
{
ccsInit(argv[0]);

/* Create the instance of APPLICATION */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */

// The instance of application has to be
// within a scope section, so that the object is deleted
// when it goes out of scope before ccsExit();
{
APPLICATION app; USE(app);

printf("Entering the main loop and waiting for commands!\n");

/* enter the main loop */
evhHandler->MainLoop();

}
ccsExit();
}

/*
*****************************************************************************
*/


/*___oOo___*/


6.10 A DUMMY COMMAND SERVER


/***********************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: evhDummy.C,v 1.86 1998/09/30 13:07:22 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 13/06/97 Put evhDUMMY class in an independent class.
* gchiozzi 12/06/97 Replace ccsTIMEVAL with eccsTIMEVAL.
* gchiozzi 09/01/97 Improved man page
* gchiozzi 08/10/96 Added error handling for failure on reply
* gchiozzi 29/07/96 Fixed parsing errors
* gchiozzi 09/05/96 Fixed deallocation bug in UnregisterCB
* gchiozzi 02/01/96 Changed the limit on buf size for logs from 20 to 60 chars
* gchiozzi 21/12/95 Fixed bug: put a limit on buffer size for logs
* gchiozzi 08/12/95 Added option -n to set process name
* gchiozzi 06/12/95 LoadCommands: Replaced fopen with ccsOpenFile
* gchiozzi 27/11/95 eccsLOG_LEVEL is always defined internally
* gchiozzi 16/10/95 Fixed INIT command: now can be registered
* gchiozzi 21/07/95 Added DMEXIT command
* gchiozzi 09/05/95 created
*/

/************************************************************************
* NAME
* evhDummy - Dummy process used for testing
*
* SYNOPSIS
* evhDummy <-n proc name> <file name>
*
* DESCRIPTION
* The program can be dynamically configured via a command
* interface to reply to any command. You can dynamically tell to the
* program how to behave when it receives any command: - What kind of
* reply it has to send (normal/error) - What message buffer to send -
* What error code in case of error reply - After how many seconds from
* the receiving of the command it must send the reply.
*
* There is no limit to the number of commands that can be
* handled by the same instance of the dummy and on the dynamic
* configuration chanes you can request while it is running.
*
* When the program is started it can read from a file an initial
* configuration containing a list of commands and reply descriptions.
* Empty lines are ignored and lines starting with '#' are comments.
*
* Every record in the file has comma delimited fields with the
* following meaning:
*
* <cmd name>,<reply buffer>,<err reply>,<err code>,<timeout>
*
* The <reply buffer> can be enclosed in quotes (for example
* in order to define replies containing commas). The enclosing
* quotes are removed. It is not possible to register replies
* containing quotes.
*
* The file is searched calling the standard ccsOpenFile() function
* Using the command line option -n procName, it is possible to register
* to the message system the evhDummy process with the given process
* name. This name will have to be used to send it messages in place
* of the executable's name.
*
* While it is running it accepts the following configuration
* commands:
*
* REGCMD <cmd name>,<reply buffer>,<err reply>,<err code>,<timeout>
* Register command
* To add a new command to the list of accepted commands or
* to change the behaviour of an existing one.
* The <reply buffer> can be enclosed in quotes (for example
* in order to define replies containing commas). The enclosing
* quotes are removed. It is not possible to register replies
* containing quotes.
*
* UREGCMD Un-register command
* To delete a command from the list of accepted commands
*
* PRNCMD Print command list
* To print on standard output the list of accepted commands
* and their configuration parameters.
*
* DMEXIT Exit the program
*
* All the informations about commands received and replies sent
* are exensively logged on stdout and/or on the CCS logging system.
*
* The program can be used in the following ways:
*
* - During development to easily replace not yet available processes.
*
* - During testing of a process to replace the processes this
* one has to send commands. A test script sets the dummy
* configuration, then stymulate the program under test to send
* commands to it, then changes the dummy configuration and so
* on. In this way it is much easier to test the dynamical
* behaviour of a process, taking into account also timeouts
* and timing constraints.
*
* The log report can be used to verify the tests and, along
* with eccsTestDriver, to write automatic tests.
*
* The program is easily extensible and new features (if
* necessary) can be added.
*
* The class evhDUMMY used as a basic component is available
* as a public evh class to develop user specific dummies.
*
* FILES
* What follows is an example of configuration file:
*
* #****************************************
* # NAME
* # trkwsTestDummy.dat
* #
* # Tracking LCUs emulation
*
* OFFSAD, "OK OFFSAD", 0,0,2
* OFFSAA, "OK OFFSAA", 1,15,1
* #
* # ___oOo___
*
* When the command OFFSAD is received, the final reply with buffer
* "OK OFFSAD" is returned after 2 seconds.
* When the command OFFSAA is received, an error reply with error code
* 15 is returned after 1 second.
*
* ENVIRONMENT
*
* COMMANDS
*
* RETURN VALUES
*
* CAUTIONS
* Error handling should be improved!
* In particular when error replies are returned, the error buffer is not
* filled properly, but only the error code is set.
*
* EXAMPLES
*
* SEE ALSO
* evhDUMMY(5)
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

static char *rcsId="@(#) $Id: evhDummy.C,v 1.86 1998/09/30 13:07:22 vltsccm Exp $";
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#ifdef eccsLOG_LEVEL
#undef eccsLOG_LEVEL
#endif
#define eccsLOG_LEVEL 3

/*
* Headers
*/

#include "evhDUMMY.h"

/**********************************/
/* main procedure */
/**********************************/

int main(int argc, char *argv[])
{
ccsCOMPL_STAT stat = SUCCESS;


/* Create the instance of evhDUMMY */
/* The call to the macro USE() prevents the GCC compiler */
/* from issuing a warning: it assumes that app is not used ! */
evhDUMMY app; USE(app);

stat = app.StdMain(argc, argv);

return EXIT_SUCCESS;
}

/*
*****************************************************************************
*/





Quadralay Corporation
http://www.webworks.com
Voice: (512) 719-3399
Fax: (512) 719-3606
sales@webworks.com
TOC PREV NEXT INDEX