TOC PREV NEXT INDEX

Put your logo here!


A - B - C - D - E - F - G - H - I - J - K - L - M - N - O - P - Q - R - S - T - U - V - W - X - Y - Z

5 INCLUDE FILES

5.1 ECCS.h


#ifndef ECCS_H
#define ECCS_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: ECCS.h,v 1.107 1999/09/15 09:26:20 vltsccm Exp $"
*
* ECCS.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 16/09/94 created
* gchiozzi 05/01/95 added new files (eevt.h)
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

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

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

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsDb_H
#include "eccsDb.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
#ifndef eccsLog_H
#include "eccsLog.h"
#endif
#ifndef eccsErr_H
#include "eccsErr.h"
#endif
#ifndef eccsEvt_H
#include "eccsEvt.h"
#endif

#endif /* ! ECCS_ALL_H */


5.2 eccs.h


#ifndef eccs_H
#define eccs_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccs.h,v 1.107 1999/09/15 09:26:21 vltsccm Exp $"
*
* eccs.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 10/02/97 Added prototype for new eccsParseTarget() function
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

/************************************************************************
*
* This include file is the EasyCCS interface to CCS base module
* and must be included by any application using EasyCCS
*
*----------------------------------------------------------------------
*/

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

extern "C" {

#include "ccs.h" /* Standard ccs include */

}

#include <eccsErrors.h>

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

/* Usefull macros for defining what parameters */
/* are in INPUT or OUTPUT in function declarations */
#ifndef IN
#ifndef OUT
#define IN
#define OUT
#endif
#endif

/* The macro __FILE_LINE__ produces a string in the format: "FileName:Line" */
/* with the name and line of the file where it has been called. */
/* It is usefull in error messages */
/* (the other macros defined here are just for support, since I have not */
/* found a cleaner way to define __FILE_LINE__ macro */

#define _eccs_tostr(a) #a
#define _eccs_tostr_pass2(a) _eccs_tostr(a)

#define __FILE_LINE__ __FILE__ ":" _eccs_tostr_pass2(__LINE__)

/* The macro USE(var) can be used to prevent the GCC compiler from */
/* complaining about an unused variable. Specially with objects, */
/* can happens that the compiler thinks that a variable is not used */
/* and issues a warning. This macro prevents the warning */
#ifndef USE
#define USE(var) static void *use_##var = ((void)&use_##var, (void *) &var);
#endif


/*
* Class eccsERROR for error handling.
* The true definition is in eerr.h
*/
struct eccsERROR;

/* This is the global eccs error stack */
extern eccsERROR *stdErr;


/****************************************/
/* Prototypes for general CCS functions */
/****************************************/

ccsCOMPL_STAT ccsExit (); /* Release CCS resources used by application */

ccsCOMPL_STAT ccsGetMyProcId ( /* Retrieves the Rtap process identifier */
OUT ccsENVNAME envName,
OUT ccsPROCNUM *procNum,
OUT ccsPROCNAME procName);

ccsCOMPL_STAT ccsInit ( /* Initialize the CCS resources */
IN const ccsPROCNAME procName,
IN void (*breakHandler)(int signal) = NULL,
IN void (*killHandler)(int signal) = NULL);

ccsCOMPL_STAT ccsOpenFile ( /* Open file located in standard search path */
IN const char *fileName,
IN const char * mode,
OUT FILE **fileHANDLE);


/* Error handling must always be included when eccs is used */
#ifndef eccsErr_H
#include "eccsErr.h"
#endif

/****************************************/
/* Prototypes for new ECCS functions */
/****************************************/

ccsCOMPL_STAT eccsParseTarget(OUT ccsENVNAME destEnv,
OUT ccsPROCNAME destProc,
IN const char *target);

/* Include the code for inline methods */
#include "eccs.icc"

#include "eccsTIMEVAL.h"

#endif /* ! ECCS_H */


5.3 eccsAlrmCon.h


#ifndef eccsAlrmCon_H
#define eccsAlrmCon_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsAlrmCon.h,v 1.107 1999/09/15 09:26:26 vltsccm Exp $"
*
* eccsAlrm.h
*
* who when what
* -------- -------- ----------------------------------------------
* gfilippi 25/05/99 fixed alrmCONNECTION(const alrmCONNECTION &source)
* gluca 24/08/97 Changed illegal method names
* rabuter 20/11/95 Created
*/

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

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

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
extern "C" {
#include "alrmCCS.h"
#include "evt.h"
}

class alrmCONNECTION : virtual public eccsERROR_CLASS {

public:

alrmCONNECTION();
alrmCONNECTION(const alrmCONNECTION &source);
virtual ~alrmCONNECTION();

virtual ccsCOMPL_STAT Attach();
virtual ccsCOMPL_STAT Detach();

// Inline methods for returning/settung data member values
const char *EnvName() const;
ccsCOMPL_STAT EnvName(ccsENVNAME newEnv);

const char *EnvBranch() const;
ccsCOMPL_STAT EnvBranch(dbSYMADDRESS newBranch);

const vltUINT16 Filter() const;
ccsCOMPL_STAT Filter(vltUINT16 newFilter);

const vltINT16 ConId() const;
const vltUINT16 Status() const;

private :
ccsENVNAME envname;
dbSYMADDRESS envbranch;
vltUINT16 filter;
vltINT16 id; //Connection identifier
vltUINT16 status;

};
#define eccsALARM_CMD "ALARM"

#include "eccsAlrmCon.icc"

#endif /* ! ECCSALRMCON_H */


5.4 eccsAlrmMsg.h


#ifndef eccsAlrmMsg_H
#define eccsAlrmMsg_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsAlrmMsg.h,v 1.107 1999/09/15 09:26:26 vltsccm Exp $"
*
* eccsAlrm.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 22/08/97 Removed LogString(), added TraceMsgString()
* vltsw 15/10/96 Added default NULL parameter to Parse()
* rabuter 20/11/95 Created
*/

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

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

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsMsg_H
#include "eccsMsg.h"
#endif
extern "C" {
#include "alrmCCS.h"
#include "evt.h"
}
#include "eccsAlrmCon.h"

class alrmMESSAGE : public msgRAW_MESSAGE {

public:

alrmMESSAGE(const msgHEADER *msg = NULL);
alrmMESSAGE(const alrmMESSAGE &source);
virtual ~alrmMESSAGE();

ccsCOMPL_STAT Parse(const msgHEADER *msg = NULL);
ccsCOMPL_STAT Receive( msgTIMEOUT timeout = msgNO_TIMEOUT,
const msgRECEIVEFILTER *filter = NULL);

/* Methods to access safely the values of parameters */
vltUINT8 Type() const;

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

const char *EnvName() const;
const char *Point() const;
const char *Subpoint() const;
const char *Attribute() const;
const char *AttrValue() const;
const vltINT16 Plin() const;
const vltINT16 Ain() const;
const vltINT32 Size() const;
const vltUINT8 AttrType() const;
const vltUINT16 Severity() const;
const vltUINT8 Scope() const;
const vltINT32 Timeout() const;
const vltINT16 Ack() const;
const char *Message() const;
const vltUINT8 Action() const;
const vltUINT16 Next() const;

protected:
const char *TraceMsgString(char *buf, vltLOGICAL recv=TRUE) const;

private:
void Init();

ccsENVNAME envname;
dbSYMADDRESS point;
dbSYMADDRESS subpoint;
dbATTRIBUTE attribute;
char *attrvalue;
vltINT16 plin;
vltINT16 ain;
vltINT32 size;
vltUINT8 attrtype;
vltUINT16 severity;
vltUINT8 scope;
vltUINT32 timeout;
vltINT16 ack;
char *message;
vltUINT8 type;
vltINT16 id; //Connection identifier
vltUINT8 action;
vltUINT16 next;

};
#include "eccsAlrmMsg.icc"

#endif /* ! ECCSALRMCON_H */


5.5 eccsDB_ATTR.h


#ifndef eccsDB_ATTR_H
#define eccsDB_ATTR_H
/****************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsDB_ATTR.h,v 1.107 1999/09/15 09:26:24 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 27/08/97 Added option parameter to check buffer size on read/write
* rkarban 03/07/97 Added INT8 and UINT8 classes
* gchiozzi 10/06/97 Removed DbRead() and DbWrite() with index
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* mnastvog 23/04/96 Added classes for UINT32 and UINT16
* gchiozzi 20/11/95 Added new DbWrite methods for attribute details specifications
* gchiozzi 15/11/95 Moved here RecordLen() method
* rabuter 27/10/95 Added DbRead DbWrite by index, RecordCnt()
* gchiozzi 18/08/95 Added define eccsDB_STRING_MAX_SIZE
* gchiozzi 24/07/95 Added assignement operators
* gchiozzi 20/07/95 Modified class eccsDB_STRING
* gchiozzi 26/04/95 created
*/

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

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

#include <iostream.h>
#ifndef eccsErr_H
#include "eccsErr.h"
#endif
#ifndef eccsDb_H
#include "eccsDb.h"
#endif

class eccsDB_ATTR : virtual public eccsERROR_CLASS
{
public:
eccsDB_ATTR(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_ATTR(const eccsDB_ATTR &attr);
virtual ~eccsDB_ATTR();

virtual ccsCOMPL_STAT GetValue(void *buffer, vltINT32 bsize = 0);
virtual ccsCOMPL_STAT SetValue(void *buffer, vltINT32 bsize = 0);

virtual vltUINT32 RecordCnt();
virtual vltUINT32 RecordLen();

virtual void PrintOn( ostream& outputStream)const;

protected:
virtual ccsCOMPL_STAT CopyDataType(const dbTYPE *newDataType);
virtual ccsCOMPL_STAT DbRead(void *buffer, vltINT32 bsize = 0);
virtual ccsCOMPL_STAT DbRead(char *attrSpec, vltUINT16 nrec,
void *buffer, vltINT32 bsize = 0);
virtual ccsCOMPL_STAT DbWrite(void *buffer, vltINT32 bsize = 0);
virtual ccsCOMPL_STAT DbWrite(char *attrSpec, vltUINT16 nrec,
void *buffer, vltINT32 bsize = 0);
virtual ccsCOMPL_STAT LoadInfo();

dbSYMADDRESS symAddr;
dbTYPE *dataType;
vltINT32 size;
vltUINT16 recordCnt;
vltUINT32 recordLen;
dbATTRTYPE attrType;

private:
eccsDB_ATTR &operator=(const eccsDB_ATTR &);

};

class eccsDB_LOGICAL : public eccsDB_ATTR
{
public:
eccsDB_LOGICAL(const dbSYMADDRESS pointName, const char *attrName=dbEMPTY);
eccsDB_LOGICAL(const eccsDB_LOGICAL &attr);

eccsDB_LOGICAL &operator=(vltLOGICAL newValue);
eccsDB_LOGICAL &operator=(eccsDB_LOGICAL &from);
operator vltLOGICAL();

};

class eccsDB_INT8 : public eccsDB_ATTR
{
public:
eccsDB_INT8(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_INT8(const eccsDB_INT8 &attr);

eccsDB_INT8 &operator=(vltINT8 newValue);
eccsDB_INT8 &operator=(eccsDB_INT8 &from);
operator vltINT8();

};

class eccsDB_UINT8 : public eccsDB_ATTR
{
public:
eccsDB_UINT8(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_UINT8(const eccsDB_UINT8 &attr);

eccsDB_UINT8 &operator=(vltUINT8 newValue);
eccsDB_UINT8 &operator=(eccsDB_UINT8 &from);
operator vltUINT8();

};

class eccsDB_INT16 : public eccsDB_ATTR
{
public:
eccsDB_INT16(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_INT16(const eccsDB_INT16 &attr);

eccsDB_INT16 &operator=(vltINT16 newValue);
eccsDB_INT16 &operator=(eccsDB_INT16 &from);
operator vltINT16();

};

class eccsDB_UINT16 : public eccsDB_ATTR
{
public:
eccsDB_UINT16(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_UINT16(const eccsDB_UINT16 &attr);

eccsDB_UINT16 &operator=(vltUINT16 newValue);
eccsDB_UINT16 &operator=(eccsDB_UINT16 &from);
operator vltUINT16();

};

class eccsDB_INT32 : public eccsDB_ATTR
{
public:
eccsDB_INT32(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_INT32(const eccsDB_INT32 &attr);

eccsDB_INT32 &operator=(vltINT32 newValue);
eccsDB_INT32 &operator=(eccsDB_INT32 &from);
operator vltINT32();

};

class eccsDB_UINT32 : public eccsDB_ATTR
{
public:
eccsDB_UINT32(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_UINT32(const eccsDB_UINT32 &attr);

eccsDB_UINT32 &operator=(vltUINT32 newValue);
eccsDB_UINT32 &operator=(eccsDB_UINT32 &from);
operator vltUINT32();

};

class eccsDB_FLOAT : public eccsDB_ATTR
{
public:
eccsDB_FLOAT(const dbSYMADDRESS pointName, const char *attrName = dbEMPTY);
eccsDB_FLOAT(const eccsDB_FLOAT &attr);

eccsDB_FLOAT &operator=(vltFLOAT newValue);
eccsDB_FLOAT &operator=(eccsDB_FLOAT &from);
operator vltFLOAT();

};

class eccsDB_DOUBLE : public eccsDB_ATTR
{
public:
eccsDB_DOUBLE(const dbSYMADDRESS pointName,const char *attrName = dbEMPTY);
eccsDB_DOUBLE(const eccsDB_DOUBLE &attr);

eccsDB_DOUBLE &operator=(vltDOUBLE newValue);
eccsDB_DOUBLE &operator=(eccsDB_DOUBLE &from);
operator vltDOUBLE();

};

#define eccsDB_STRING_MAX_SIZE 256

class eccsDB_STRING : public eccsDB_ATTR
{
public:
eccsDB_STRING(const dbSYMADDRESS pointName,const char *attrName = dbEMPTY);
eccsDB_STRING(const eccsDB_STRING &attr);
virtual ~eccsDB_STRING();

eccsDB_STRING &operator=(const char *newValue);
eccsDB_STRING &operator=(eccsDB_STRING &from);
operator const char *();
private:
char *string;

static char buffer[eccsDB_STRING_MAX_SIZE];
};

#include "eccsDB_ATTR.icc"

#endif /*!eccsDB_ATTR_H*/


5.6 eccsDB_VECTOR.h


#ifndef eccsDB_VECTOR_H
#define eccsDB_VECTOR_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsDB_VECTOR.h,v 1.107 1999/09/15 09:26:25 vltsccm Exp $"
*
* who when what
* -------- -------- -----------------------------------------------------------
* gchiozzi 31/08/99 Reintroduced const in cast operator.
* rkarban 13/08/99 remove const from cast operator
* rkarban 12/08/99 cast away const-ness newVal in operator=
* gchiozzi 10/06/97 Added handling of table columns as vectors
* gchiozzi 10/06/97 Removed template eccsDB_VECTOR_BYTES<T>.
* gchiozzi 10/06/97 In eccsDB_VECTOR_HELPER replaced DbXXX XXXValue
* gchiozzi 03/03/97 Removed include of dbPrivate.h
* gchiozzi 15/11/95 Changed macros, cleaned up and made OK on GCC 2.7
* rabuter 27/10/95 Factorize DbReadOne, DbWriteOne, RecordCnt up in eccsDB_ATTR
* add error handling, templates access macros, man pages.
* gchiozzi 18/10/95 created
*/

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


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

#define _POSIX_SOURCE 1
#ifndef vltPort_H
#include "vltPort.h"
#endif


/*
* System Headers
*/
#ifndef _STDLIB_INCLUDED
#include <stdlib.h>
#endif
#ifndef _STDIO_INCLUDED
#include <stdio.h>
#endif
#ifndef _STRING_INCLUDED
#include <string.h>
#endif
#ifndef _STDARG_INCLUDED
#include <stdarg.h>
#endif


/*
* Local Headers
*/

#ifndef err_H
#include "err.h"
#endif
#ifndef msg_H
#include "msg.h"
#endif
#ifndef db_H
#include "db.h"
#endif
#ifndef eccsDB_ATTR_H
#include "eccsDB_ATTR.h"
#endif
#ifndef eccsTestTools_H
#include "eccsTestTools.h"
#endif



/************************************/
/* Support class */
/************************************/

template<class T> class eccsDB_VECTOR;

template<class T>
class eccsDB_VECTOR_HELPER
{
public:
T value;
vltUINT32 index;
eccsDB_VECTOR<T> *ptr;
ccsCOMPL_STAT stat;
eccsDB_VECTOR_HELPER& operator =(const T &newVal)
{
value = const_cast<T &>(newVal);
stat = ptr->SetValue(index,value);
// Error already logged: cannot add anything usefull here
return *this;
}

operator const T&()
{
stat = ptr->GetValue(index,&value);
// Error already logged: cannot add anything usefull here
return value;
}

};


/*******************************************/
/* Class for vectors of standard types */
/*******************************************/

enum eccsDB_VECTOR_TYPE { eccsDB_TBL_COL };

template<class T>
class eccsDB_VECTOR : public eccsDB_ATTR
{
friend eccsDB_VECTOR_HELPER<T>;

public:
eccsDB_VECTOR(const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY);
eccsDB_VECTOR(const eccsDB_VECTOR_TYPE type,
const dbSYMADDRESS pointName,
const char *fieldName);
~eccsDB_VECTOR();

virtual ccsCOMPL_STAT GetValue(T *buffer);
virtual ccsCOMPL_STAT SetValue(T *buffer);

virtual ccsCOMPL_STAT GetValue(vltUINT32 index, T *v);
virtual ccsCOMPL_STAT SetValue(vltUINT32 index, T &v);

eccsDB_VECTOR_HELPER<T>& operator[](int index);

protected:
eccsDB_VECTOR_HELPER<T> helper;

virtual ccsCOMPL_STAT LoadInfo();

private:
char *tblField;
};


/*
* Access Macros for templates of allowed types
*/
#define eccsDB_VECTOR_vltINT8 eccsDB_VECTOR<vltINT8>
#define eccsDB_VECTOR_vltUINT8 eccsDB_VECTOR<vltUINT8>
#define eccsDB_VECTOR_vltINT16 eccsDB_VECTOR<vltINT16>
#define eccsDB_VECTOR_vltUINT16 eccsDB_VECTOR<vltUINT16>
#define eccsDB_VECTOR_vltINT32 eccsDB_VECTOR<vltINT32>
#define eccsDB_VECTOR_vltUINT32 eccsDB_VECTOR<vltUINT32>
#define eccsDB_VECTOR_vltLOGICAL eccsDB_VECTOR<vltLOGICAL>
#define eccsDB_VECTOR_vltDOUBLE eccsDB_VECTOR<vltDOUBLE>
#define eccsDB_VECTOR_vltFLOAT eccsDB_VECTOR<vltFLOAT>

#define eccsDB_VECTOR_vltBYTES4 eccsDB_VECTOR<vltBYTES4>
#define eccsDB_VECTOR_vltBYTES8 eccsDB_VECTOR<vltBYTES8>
#define eccsDB_VECTOR_vltBYTES16 eccsDB_VECTOR<vltBYTES16>
#define eccsDB_VECTOR_vltBYTES12 eccsDB_VECTOR<vltBYTES12>
#define eccsDB_VECTOR_vltBYTES16 eccsDB_VECTOR<vltBYTES16>
#define eccsDB_VECTOR_vltBYTES20 eccsDB_VECTOR<vltBYTES20>
#define eccsDB_VECTOR_vltBYTES32 eccsDB_VECTOR<vltBYTES32>
#define eccsDB_VECTOR_vltBYTES48 eccsDB_VECTOR<vltBYTES48>
#define eccsDB_VECTOR_vltBYTES64 eccsDB_VECTOR<vltBYTES64>
#define eccsDB_VECTOR_vltBYTES80 eccsDB_VECTOR<vltBYTES80>
#define eccsDB_VECTOR_vltBYTES128 eccsDB_VECTOR<vltBYTES128>
#define eccsDB_VECTOR_vltBYTES256 eccsDB_VECTOR<vltBYTES256>

#include "eccsDB_VECTOR.icc"

#endif


5.7 eccsDB_TABLE.h


#ifndef eccsDB_TABLE_H
#define eccsDB_TABLE_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsDB_TABLE.h,v 1.107 1999/09/15 09:26:25 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 03/03/97 Removed include of dbPrivate.h
* gchiozzi 09/01/97 Added const to char*
* rabuter 27/10/95 created
*/

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


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

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#ifndef _STDLIB_INCLUDED
#include <stdlib.h>
#endif
#ifndef _STDIO_INCLUDED
#include <stdio.h>
#endif
#ifndef _STRING_INCLUDED
#include <string.h>
#endif
#ifndef _STDARG_INCLUDED
#include <stdarg.h>
#endif



/*
* Local Headers
*/

#ifndef err_H
#include "err.h"
#endif
#ifndef msg_H
#include "msg.h"
#endif
#ifndef db_H
#include "db.h"
#endif
#ifndef eccsDB_ATTR_H
#include "eccsDB_ATTR.h"
#endif
#ifndef eccsTestTools_H
#include "eccsTestTools.h"
#endif


/****************************/
/* Classes for TABLES */
/****************************/


template<class T> class eccsDB_TABLE;


/*
* Base class for table record classes
*/

class eccsDB_TABLE_RECORD
{
public:
virtual ccsCOMPL_STAT Pack( void * buffer )=0;
virtual ccsCOMPL_STAT Unpack( void * buffer )=0;
};


/*
* Support template class used to handle tables
*/

template<class T>
struct eccsDB_TABLE_HELPER
{
T value;
vltUINT32 index;
const char *name;
eccsDB_TABLE<T> *ptr;

eccsDB_TABLE_HELPER& operator =(T newVal) {
if(name != NULL)
ptr->SetValue(name,newVal);
else
ptr->SetValue(index,newVal);
return *this;
}
operator const T&() {
if(name != NULL)
ptr->GetValue(name,&value);
else
ptr->GetValue(index,&value);
return value;
}
};

/*
* Template class for handling tables
*/


template<class T>
class eccsDB_TABLE : public eccsDB_ATTR
{
friend eccsDB_TABLE_HELPER<T>;

public:
eccsDB_TABLE(const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY);

virtual ccsCOMPL_STAT GetValue(T *buffer);
virtual ccsCOMPL_STAT SetValue(T *buffer);
virtual ccsCOMPL_STAT GetValue(vltUINT32 index, T *buffer);
virtual ccsCOMPL_STAT SetValue(vltUINT32 index, T &buffer);
virtual ccsCOMPL_STAT GetValue(const char *name, T *buffer);
virtual ccsCOMPL_STAT SetValue(const char *name, T &buffer);

eccsDB_TABLE_HELPER<T>& operator[](int index) {
helper.index = index;
helper.name = NULL;
return helper;
};

eccsDB_TABLE_HELPER<T>& operator[](const char *name) {
helper.name = name;
return helper;
};


protected:
eccsDB_TABLE_HELPER<T> helper;
};

/* Include code for inline methods */
#include "eccsDB_TABLE.icc"

#endif


5.8 eccsDb.h


#ifndef eccsDb_H
#define eccsDb_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsDb.h,v 1.107 1999/09/15 09:26:21 vltsccm Exp $"
*
* eccsDb.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

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

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

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

extern "C" {
#include "db.h"
}


/* General class to handle buffers of a given size */
/* The class does not hide completely the true */
/* buffer and is responsibility of the user to not */
/* corrupt it and not to go out of boundaries */

class eccsBUFFER
{
public:
eccsBUFFER(int bytes);
~eccsBUFFER();
void *Buffer();
int Size() const;

operator const int() const;
operator void*();

private:
void *buffer;
int size;
};


/**********************************/
/* General CCS database functions */
/**********************************/

ccsCOMPL_STAT dbExit ( /* Close a specific database connection or all */
IN const ccsENVNAME envName = dbALL_ENV);

ccsCOMPL_STAT dbOpen( /* Establishes a connection to a database */
IN const ccsENVNAME envName = ccsLOCAL_ENV);


/*****************************************/
/* CCS database READ and WRITE functions */
/*****************************************/

/* The typedef are automatically used for conversions from-to VLT */
/* standad types, since more VLT type can be mapped on the same */
/* C-language basic type */

/* WARNING: attributes of type: */
/* ------- vltLOGICAL, */
/* vltINT8 */
/* vltUINT8 */
/* are treated in a special way and not transparently by */
/* edbRead() / edbWrite() function. */
/* Look forward for special functions */
/* This is due to intrinsical problems in type definition*/
/* The "clean" solution is in special ATTIBUTE classes */

/*******************************************************************/
/* edbRead() functions: they are defined using basic C types */

/* The following overloaded functions are able to read types: */
/* Parms: Types: */
/* short * vltINT16 */
/* u short * vltUINT16 */
/* int * vltINT32 */
/* u int * vltUINT32 */
/* double * vltDOUBLE */
/* float * vltFLOAT */
/* vltPOLAR * vltPOLAR */
/* vltRECTANGULAR * vltRECTANGULAR */
/* Types derived by the basic char * type must be handled in a */
/* special way (unfortunately this includes vltLOGICAL, vltINT8 */
/* and vltUINT8). */
/* This special handling is necessary in order to have a check */
/* over buffer sizes and to be symmetrical with write functions */

ccsCOMPL_STAT dbRead(
short *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
unsigned short *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
int *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
unsigned int *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
float *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
double *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
vltPOLAR *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbRead(
vltRECTANGULAR *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

/* This read function uses an eccsBUFFER object */
ccsCOMPL_STAT dbRead(
eccsBUFFER *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

/* These functions are used to read buffers of type BYTES... */
/* The macro VLTBYTES(buff[]) can be used to pass only one */
/* parameter instead of buffer and size. */
/* This MUST BE AN ARRAY and cannot be a simple pointer */

ccsCOMPL_STAT dbRead(
unsigned char *value,
vltINT32 buffSize,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

/*************************************************************/
/* edbWrite() functions */
/* */
/* Write functions are more complex than Read, because it is */
/* necessary to know exactly the RTAP type of the data to be */
/* written and not only the buffer sizes */

ccsCOMPL_STAT dbWrite(
short *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
unsigned short *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
int *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
unsigned int *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
float *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
double *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
vltPOLAR *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

ccsCOMPL_STAT dbWrite(
vltRECTANGULAR *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );


#if 0

/* The functions commented out by the #if 0 .... #endif section */
/* have not been implemented. */
/* The main problem, that makes not trivial their implementation */
/* is that it is mecessary to know the deTYPE of what we want */
/* to write. In the case of vltBYTES... it is not a problem. */
/* More complex is the case of general eccsBUFFER. A solution */
/* could be to query the database, but this has an impact on */
/* performances. */
/* Once again: the clean solution is in the ATTRIBUTE class */

ccsCOMPL_STAT dbWrite(
eccsBUFFER *value,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

#endif

ccsCOMPL_STAT dbWrite(
unsigned char *value,
vltINT32 buffSize,
const dbSYMADDRESS pointName,
const char *attrName = dbEMPTY,
ccsERROR *error = NULL );

/************************************************/
/* CCS Database: macros used for READ and WRITE */
/************************************************/

/* This macro is used for buffers of type vltBYTES.... */
/* It split the parameter in two parameters suitable */
/* for the specific implementations of the dbRead() and */
/* dbWrite() functions: the buffer itself and its size */

#define VLTBYTES(a) (a),sizeof(a)

/* Include the code for inline methods */
#include "eccsDb.icc"

#endif /* ! ECCSDB_H */


5.9 eccsErr.h


#ifndef eccsErr_H
#define eccsErr_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsErr.h,v 1.107 1999/09/15 09:26:21 vltsccm Exp $"
*
* eccsErr.h
*
* who when what
* -------- -------- ----------------------------------------------
* rkarban 13/08/99 cast NULL in errClassNullPtr macros to (void *)
* gchiozzi 21/07/98 Added errIsReason functions and IsReason methods.
* gchiozzi 12/06/97 In eccsERROR_CLASS made const all methods.
* gchiozzi 18/10/95 Added handling of "object status"
* gchiozzi 26/07/95 Added new macros to complete the set
* gchiozzi 26/07/95 Macro errClassReturnNullPtr return FAILURE
* gchiozzi 25/05/95 Added new methods in eccsERROR_CLASS
* gchiozzi 15/05/95 Add macro errFlag(). Corrected bug in errReturnGeneric()
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

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

#ifndef _STDARG_INCLUDED
#include <stdarg.h>
#endif

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

extern "C" {
#include "err.h"
}

/************************************************/
/* Mapping of some standard CCS error functions */
/* to use standard error stack */
/************************************************/

ccsCOMPL_STAT errAdd(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, ...);
ccsCOMPL_STAT errAdd_v(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, va_list va_parList);
ccsCOMPL_STAT errSysAdd(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId,char *sysModule=modRTAP, ...);
ccsCOMPL_STAT errSysAdd_v(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, char *sysModule,
va_list va_parList);

ccsCOMPL_STAT errCloseStack();
ccsCOMPL_STAT errResetStack();
ccsCOMPL_STAT errPrint();
ccsCOMPL_STAT errDisplay(vltLOGICAL syncFlag=FALSE);

ccsCOMPL_STAT errIsReason(const ccsMODULEID moduleId,
vltINT16 errorNumber,
vltLOGICAL *errFound,
ccsSTACK_ELEM **errDescription = NULL);

/***************************************************************/
/* Class eccsERROR for error handling. */
/* It is a subclass of ccsERROR, the standard CCS error class */
/***************************************************************/

struct eccsERROR: public ccsERROR
{
eccsERROR();
~eccsERROR();

ccsCOMPL_STAT Add(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, ...);
ccsCOMPL_STAT Add_v(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, va_list va_parList);
ccsCOMPL_STAT SysAdd(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, char *sysModule=modRTAP, ...);
ccsCOMPL_STAT SysAdd_v(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, char *sysModule,
va_list va_parList);

ccsCOMPL_STAT Close();
ccsCOMPL_STAT Display(vltLOGICAL syncFlag=FALSE);
ccsCOMPL_STAT Print();
ccsCOMPL_STAT Reset();

ccsCOMPL_STAT IsReason(const ccsMODULEID moduleId,
vltINT16 errorNumber,
vltLOGICAL *errFound,
ccsSTACK_ELEM **errDescription = NULL);

vltLOGICAL IsReason(const ccsMODULEID moduleId,
vltINT16 errorNumber);

eccsERROR &operator =(const ccsERROR &e);

/* This static section is used to handle default eccs error stack */
static void DefErrorStack(eccsERROR *err = NULL);
};



/********************************************************************/
/* Class eccsERROR_CLASS for objects than can have error conditions */
/* This has to be used as a base class */
/********************************************************************/

class eccsERROR_CLASS
{
public:

eccsERROR_CLASS(eccsERROR *s = stdErr);

ccsCOMPL_STAT ErrStatus() const;
eccsERROR &ErrStack() const;

ccsCOMPL_STAT ErrStackClose() const;
ccsCOMPL_STAT ErrStackReset() const;

ccsCOMPL_STAT ObjStatus() const;

operator ccsCOMPL_STAT() const;
operator eccsERROR &() const;

protected:
const eccsERROR_CLASS &ErrStatus(const ccsCOMPL_STAT s) const;
const eccsERROR_CLASS &ErrReset() const;
const eccsERROR_CLASS &ObjStatus(const ccsCOMPL_STAT s) const;

const eccsERROR_CLASS &operator =(const ccsCOMPL_STAT s) const;

ccsCOMPL_STAT ErrAdd(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, ...) const;
ccsCOMPL_STAT ErrAdd_v(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, va_list va_parList) const;
ccsCOMPL_STAT ErrSysAdd(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, char *sysModule=modRTAP, ...) const;
ccsCOMPL_STAT ErrSysAdd_v(ccsMODULEID moduleId, vltINT16 errorNumber,
ccsLOC_ID locId, char *sysModule,
va_list va_parList) const;

private:

ccsCOMPL_STAT status;
ccsCOMPL_STAT objStatus;
eccsERROR *stack;
};


/*******************************************************/
/* This macros makes easier handling error conditions */
/*******************************************************/

#define errFlag(a,b) { (a) = ((b)==FAILURE) ? FAILURE : (a); }


#define errAddGeneric(a) if( (a) == FAILURE ) \
{ \
errAdd(stdErr,"eccs", \
eccsERR_GENERIC, \
__FILE_LINE__,""); \
}
#define errReturnGeneric(a) if( (a) == FAILURE ) \
{ \
errAdd(stdErr,"eccs", \
eccsERR_GENERIC, \
__FILE_LINE__,""); \
return(FAILURE); \
}
#define errExitGeneric(a) if( (a) == FAILURE ) \
{ \
errAdd(stdErr,"eccs", \
eccsERR_GENERIC, \
__FILE_LINE__,""); \
errCloseStack(stdErr); \
exit(1); \
}

#define errClassAddGeneric(a) if( (a) == FAILURE ) \
{ \
ErrAdd(stdErr,"eccs", \
eccsERR_GENERIC, \
__FILE_LINE__,""); \
}
#define errClassReturnGeneric(a) if( (a) == FAILURE ) \
{ \
ErrAdd(stdErr,"eccs", \
eccsERR_GENERIC, \
__FILE_LINE__,""); \
return(FAILURE); \
}
#define errClassExitGeneric(a) if( (a) == FAILURE ) \
{ \
ErrAdd(stdErr,"eccs", \
eccsERR_GENERIC, \
__FILE_LINE__,""); \
ErrStackClose(stdErr); \
exit(1); \
}

#define errNullPtr(a) if( (a) == NULL ) \
{ \
errAdd(stdErr,"eccs", \
eccsERR_NULL_PTR, \
__FILE_LINE__,"",#a); \
}

#define errReturnNullPtr(a) if( (a) == NULL ) \
{ \
errAdd(stdErr,"eccs", \
eccsERR_NULL_PTR, \
__FILE_LINE__,"",#a); \
return(FAILURE); \
}

#define errClassNullPtr(a) if( (a) == reinterpret_cast<void *>(NULL) ) \
{ \
ErrAdd("eccs", \
eccsERR_NULL_PTR, \
__FILE_LINE__,#a); \
}

#define errClassReturnNullPtr(a) if( (a) == reinterpret_cast<void *>(NULL) ) \
{ \
ErrAdd("eccs", \
eccsERR_NULL_PTR, \
__FILE_LINE__,#a); \
return(FAILURE); \
}


/* Include the code for inline methods */
#include "eccsErr.icc"

#endif /* ! ECCSERR_H */


5.10 eccsEvt.h


#ifndef eccsEvt_H
#define eccsEvt_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsEvt.h,v 1.107 1999/09/15 09:26:22 vltsccm Exp $"
*
* eccsEvt.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 22/08/97 Removed LogString(), added TraceMsgString()
* gchiozzi 28/04/97 evtdict now a pointer.
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 05/01/96 LogString is a protected method
* rabuter 20/11/95 added LogString
* gchiozzi 04/01/95 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

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

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

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

extern "C" {
#include "evt.h"
}

#include "eccsEvtIdMap.h"

#define evtEVENT_CMD "EVENT"


class evtEVENT: virtual public eccsERROR_CLASS {

public:

evtEVENT(const dbSYMADDRESS attr = NULL, int attach = FALSE);
evtEVENT(const evtEVENT &source);
virtual ~evtEVENT();

virtual int Status(); // TRUE if attached, FALSE if not
virtual ccsCOMPL_STAT Attach();
virtual ccsCOMPL_STAT Detach();
virtual ccsCOMPL_STAT Disable();
virtual ccsCOMPL_STAT Enable();

/* Methods to access safely the values of parameters */
const char *AttrName() const;
evtEVENT &AttrName(const dbSYMADDRESS newName);

evtFILTER Filter() const;
evtEVENT &Filter(evtFILTER newFilter);

const char *Env() const;
evtEVENT &Env(const ccsENVNAME newEnv);

const char *Proc() const;
evtEVENT &Proc(const ccsPROCNAME newProc);

const char *UserMsg() const;
evtEVENT &UserMsg(const ccsPROCNAME newUserMsg);

const evtEVENT_ID &EventId() const;

msgCMDID CommandId() const;

evtEVENT &operator =(const evtEVENT &e);

private:

dbSYMADDRESS attrName; /* Attribute name */
evtFILTER filter; /* Condition to generate the event */
ccsENVNAME env; /* Event receiver process environment */
ccsPROCNAME proc; /* Event receiver process */
char *userMsg; /* User message attached to event */
evtEVENT_ID eventId; /* Returned event identifier */

friend class evtEVENT_MSG;
friend class evtEVENT_INIT;

static evtID_MAP *evtdict;

void Init();
void Status(int value); // TRUE if attached, FALSE if not


}; /* end class evtEVENT */


class evtEVENT_MSG: public msgRAW_MESSAGE {
public:
evtEVENT_MSG(const msgHEADER *msg = NULL);
evtEVENT_MSG(const evtEVENT_MSG &source);
~evtEVENT_MSG();

ccsCOMPL_STAT Parse(const msgHEADER *msg);
ccsCOMPL_STAT Receive(msgTIMEOUT timeout = msgNO_TIMEOUT,
const msgRECEIVEFILTER *filter = NULL);

/* Methods to access safely the values of parameters */
vltUINT8 Type() const;
const char *Command() const;
msgCMDID CommandId() const;

const evtEVENT_ID &EventId() const;
vltUINT8 Trigger() const;
const msgPROCESSID &TriggerProc() const;
const char *AttrName() const;
dbATTRTYPE AttrType() const;
const evtDATA &EventInfo() const;
const char *UserMsg() const;

evtEVENT_MSG &operator =(const evtEVENT_MSG &e);

protected:
const char *TraceMsgString(char *buf, vltLOGICAL recv=TRUE) const;

private:

evtEVENT_ID event; /* Event Identifier */
vltUINT8 trigger; /* Event triggering condition */
msgPROCESSID triggerProc; /* Process that triggered the event */
dbSYMADDRESS attrName; /* DB Element where the event occurred */
dbATTRTYPE attrType; /* Attribute Type */
evtDATA eventInfo; /* returned event information */
char *userMsg; /* Attached user message, if any */

void Init();

}; /* end class evtEVENT_MSG */

/* Include the code for inline methods */
#include "eccsEvt.icc"

#endif /* ! ECCSEVT_H */


5.11 eccsEvtIdMap.h


#ifndef eccsEvtIdMap_H
#define eccsEvtIdMap_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsEvtIdMap.h,v 1.107 1999/09/15 09:26:27 vltsccm Exp $"
*
* eccsEvtIdMap.h
*
* who when what
* -------- -------- ----------------------------------------------
* gfilippi 25/05/99 std/string.h removed (port to gcc 2.8.1)
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 23/05/96 Modified to include filter in event id data
* gchiozzi 15/05/96 Replaced map with multimap
* gchiozzi 01/04/96 Added include std/string.h. Not clear why it is necessary.
* rabuter 20/02/96 Created
*
*/

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

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

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

extern "C" {
#include "evt.h"
}

/* gcc 2.8.1 complains about this:
#include <std/string.h>
*/

#include <multimap.h>
#include <algo.h>

#include "eccsEVENT_ID_OBJ.h"

typedef multimap<eccsEVENT_ID_OBJ,vltUINT16,less<eccsEVENT_ID_OBJ> > eventID_MAP;

class evtID_MAP : virtual public eccsERROR_CLASS {

public:
evtID_MAP(){ count = 1; }
ccsCOMPL_STAT Insert( const evtEVENT_ID &e );
ccsCOMPL_STAT Remove( const evtEVENT_ID &e );
vltUINT16 Search( const evtEVENT_ID &e );
private:
eventID_MAP map;
vltUINT16 count;

};


/* Include the code for inline methods */
#include "eccsEvtIdMap.icc"

#endif /* ! ECCSEVTIDMAP_H */


5.12 eccsEVENT_ID_OBJ.h

#ifndef eccsEVENT_ID_OBJ_H
#define eccsEVENT_ID_OBJ_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsEVENT_ID_OBJ.h,v 1.107 1999/09/15 09:26:27 vltsccm Exp $"
*
* eccsEvtIdMap.h
*
* who when what
* -------- -------- ----------------------------------------------
* vltsw 11/07/96 Created
*/

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

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

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

extern "C" {
#include "evt.h"
}

class eccsEVENT_ID_OBJ : public evtEVENT_ID
{
public:
eccsEVENT_ID_OBJ();
eccsEVENT_ID_OBJ(const eccsEVENT_ID_OBJ &b);
eccsEVENT_ID_OBJ(const evtEVENT_ID &b);
bool operator==(const eccsEVENT_ID_OBJ &b) const;
bool operator<(const eccsEVENT_ID_OBJ &b) const;
};


/* Include the code for inline methods */
#include "eccsEVENT_ID_OBJ.icc"

#endif /* ! eccsEVENT_ID_OBJ_H */


5.13 eccsLog.h


#ifndef eccsLog_H
#define eccsLog_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsLog.h,v 1.107 1999/09/15 09:26:22 vltsccm Exp $"
*
* eccsLog.h
*
* who when what
* -------- -------- ----------------------------------------------
* mcomin 08/04/98 Modification to ParArray class
* tcsmgr 25/03/98 Created logFITS class
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

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

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

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

extern "C" {
#include "log.h"
}

ccsCOMPL_STAT logData(ccsMODULEID mod,const char *logText, ...);
ccsCOMPL_STAT logData_v(ccsMODULEID mod,const char *logText,
va_list va_parList);

/*
* Basic FITS logging class
*/
class logFITS: virtual public eccsERROR_CLASS {

public:
logFITS(const ccsMODULEID module = "", /* Module reporting the log. */
const logDICTIONARY fitsDict = ""); /* Dictionary where to check the log. */

virtual ~logFITS() {};

logFITS &Module(const ccsMODULEID module);
const char *Module();

logFITS &FitsDict(const logDICTIONARY mask);
const char *FitsDict();

logFITS &Level(vltINT32 level);
vltINT32 Level();

static void Mask(const logMASK mask);
static const char *Mask();

/*
* FITS logging methods
*/
virtual ccsCOMPL_STAT Comment (const char *who, /* Who generated the log */
const char *text, /* String describing the comment */
vltINT32 level = 1);
virtual ccsCOMPL_STAT Event(logFITS_TYPE fitsType, /* Log type : FITS_UNFORSEEN, FITS_RECOVERY */
const char *text, /* String describing the condition */
vltINT32 level = 1);
virtual ccsCOMPL_STAT Action(const logCATEGORY fitsCat, /* Category */
const logFITS_KEY fitsSys, /* System : identifies a component */
const logACTION fitsAction, /* Verb describing the action */
vltINT32 level = 1);

virtual ccsCOMPL_STAT ParRecord(const logCATEGORY fitsCat, /* Category */
const logFITS_KEY fitsSys, /* System : identifies a component */
const logFITS_KEY fitsParam, /* System Parameter */
const vltLOGICAL value, /* Current value for Parameter */
vltINT32 level = 1);
virtual ccsCOMPL_STAT ParRecord(const logCATEGORY fitsCat,
const logFITS_KEY fitsSys,
const logFITS_KEY fitsParam,
const vltINT32 value,
vltINT32 level = 1);
virtual ccsCOMPL_STAT ParRecord(const logCATEGORY fitsCat,
const logFITS_KEY fitsSys,
const logFITS_KEY fitsParam,
const vltDOUBLE value,
vltINT32 level = 1);
virtual ccsCOMPL_STAT ParRecord(const logCATEGORY fitsCat,
const logFITS_KEY fitsSys,
const logFITS_KEY fitsParam,
const char *value,
vltINT32 level = 1);

virtual ccsCOMPL_STAT ParRecord(const logCATEGORY fitsCat,
const logFITS_KEY fitsSys,
const logFITS_KEY fitsParam,
const unsigned char *value,
vltINT32 level = 1);

virtual ccsCOMPL_STAT ParArray(const logCATEGORY fitsCat, /* Category */
const logFITS_KEY fitsSys, /* System : identifies a component */
const logFITS_KEY fitsParam, /* System Parameter */
vltINT16 first, /* Index of the first element */
vltINT16 last, /* Index of the last element */
vltINT16 elemSize, /* Array element size */
const void *array, /* Pointer to the first element */
vltINT32 level = 1);

protected:

private:
ccsMODULEID module; /* Module reporting the log. */
logDICTIONARY fitsDict; /* Dictionary where to check the log. */
vltINT32 level; /* Current logging level. */

static logMASK mask; /* Mask used for the FITS logs. */

}; /* end class logFITS */

/* Include the code for inline methods */
#include "eccsLog.icc"

#endif /* ! ECCSLOG_H */


5.14 eccsMsg.h


#ifndef eccsMsg_H
#define eccsMsg_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsMsg.h,v 1.107 1999/09/15 09:26:23 vltsccm Exp $"
*
* eccsMsg.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 22/08/97 Added to OrgName() long/short flag
* gchiozzi 22/08/97 Changed Trace() functionality
* gchiozzi 24/09/96 Added replyErrorStack member
* gchiozzi 24/09/96 Added emptyErrorStack member
* gchiozzi 04/09/96 Major changes to adapt to new error system
* vltsw 23/07/96 Derived public virtual from eccsERROR_CLASS
* gchiozzi 05/01/96 LogString is a protected method
* gchiozzi 07/07/95 Added class handling of command send checking
* gchiozzi 12/06/95 Added defines for "null" command
* gchiozzi 16/09/94 created
* gchiozzi 05/01/94 added the new class msgROUGH_MESSAGE
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
* Renamed class msgROUGH_MESSAGE in msgRAW_MESSAGE
*/

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

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

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

#ifndef fndNAME_MAP_H
#include "fndNAME_MAP.h"
#endif

extern "C" {
#include "msg.h"
}

/********************************/
/* CCS message system functions */
/********************************/

/* Defines for a "null" command */
#define msgNULL_CMD ""
#define msgNULL_CMD_LEN (strlen(NULL_CMD)+1)


/* Basic message class */
class msgRAW_MESSAGE: virtual public eccsERROR_CLASS {

public:
virtual ~msgRAW_MESSAGE() {};

/* Methods to access safely the values of parameters */
virtual vltUINT8 Type() const = 0;
virtual msgCMDID CommandId() const = 0;
virtual const char *Command() const = 0;

const char *TypeName() const;

static ccsCOMPL_STAT Trace(vltLOGICAL mode = TRUE);
static fndNAME_MAP &MsgTypeMap();

protected:
virtual ccsCOMPL_STAT TraceMsg(vltLOGICAL recv=TRUE) const;
virtual const char *TraceMsgString(char *buf, vltLOGICAL recv=TRUE) const;

static vltLOGICAL TraceStatus();

private:
static vltLOGICAL trace;

static fndNAME_AND_INDEX msgTypeNames[];
static fndNAME_MAP msgTypeMap;

}; /* end class msgRAW_MESSAGE */



class msgMESSAGE: public msgRAW_MESSAGE {
public:
msgMESSAGE();
msgMESSAGE(const msgHEADER *msg);
msgMESSAGE(const msgMESSAGE &source);
~msgMESSAGE();

ccsCOMPL_STAT Parse(const msgHEADER *msg);
ccsCOMPL_STAT Receive(msgTIMEOUT timeout = msgNO_TIMEOUT,
const msgRECEIVEFILTER *filter = NULL);

ccsCOMPL_STAT SendCommand();
ccsCOMPL_STAT SendCommand(msgCHECKFLAG flag);

ccsCOMPL_STAT SendReply();
ccsCOMPL_STAT SendReply(const char *newBuffer,
msgLENGTH newBuflen=0,
vltLOGICAL lastReply=ccsTRUE);
ccsCOMPL_STAT SendReply(const ccsERROR &errmsg);


/* Methods to access safely the values of parameters */
vltUINT8 Type() const;
msgMESSAGE &Type(vltUINT8 newType);

const char *Command() const;
msgMESSAGE &Command(const msgCMD newCommand);

msgCMDID CommandId() const;
msgMESSAGE &CommandId(msgCMDID newCommandId);

const char *Destenv() const;
msgMESSAGE &Destenv(const ccsENVNAME newDestenv);

const char *Destproc() const;
msgMESSAGE &Destproc(const ccsPROCNAME newDestProc);

const msgPROCESSID &OrgId() const;
msgMESSAGE &OrgId(const msgPROCESSID &newOrgId);

const char *OrgName(vltLOGICAL longForm=TRUE) const;

vltLOGICAL LastReply() const;
msgMESSAGE &LastReply(vltLOGICAL newLastReply);

const char *Buffer() const;
msgLENGTH Buflen() const;
msgMESSAGE &Buffer(const char *newBuffer, msgLENGTH newBuflen=0);

ccsERROR &Errmsg();
msgMESSAGE &Errmsg(const ccsERROR &newErrmsg);

msgCHECKFLAG Check() const;
msgMESSAGE &Check(msgCHECKFLAG flag);

msgMESSAGE &operator =(const msgMESSAGE &source);

static ccsCOMPL_STAT GlobalCheckOn(msgCHECKFLAG flag);
static ccsCOMPL_STAT GlobalCheckOff();

protected:
ccsCOMPL_STAT SetBuffer(const char *buffer,msgLENGTH newlen);

const char *TraceMsgString(char *buf, vltLOGICAL recv=TRUE) const;
ccsCOMPL_STAT TraceReply() const;

private:
vltUINT8 type;
msgCMD command;
msgCMDID commandId;
ccsENVNAME destenv;
ccsPROCNAME destproc;
msgPROCESSID orgId;
vltLOGICAL lastReply;
char *buffer;
msgLENGTH buflen;

const ccsERROR *replyErrorStack;

msgCHECKFLAG check;

msgLENGTH fullBuflen;
vltLOGICAL autoCommandId;

static int cmdProg;
static const eccsERROR emptyErrorStack;
static vltLOGICAL globalCheck;
static msgCHECKFLAG globalCheckBitmask;

}; /* end class msgMESSAGE */


ccsCOMPL_STAT msgParseMsg(msgMESSAGE *msg,
msgHEADER *input);

ccsCOMPL_STAT msgRecvMsg(msgMESSAGE *msg,
msgTIMEOUT timeout = msgNO_TIMEOUT,
const msgRECEIVEFILTER *filter = NULL);

ccsCOMPL_STAT msgRecvMsg(msgHEADER **msg,
msgTIMEOUT timeout = msgNO_TIMEOUT,
const msgRECEIVEFILTER *filter = NULL);

ccsCOMPL_STAT msgSendCommand(msgMESSAGE *msg);

ccsCOMPL_STAT msgSendCommand(msgMESSAGE *msg,
msgCHECKFLAG flag);

ccsCOMPL_STAT msgSendReply(msgMESSAGE *msg);



/* Include the code for inline methods */
#include "eccsMsg.icc"


#endif /* ! ECCSMSG_H */


5.15 eccsTestTools.h


#ifndef eccsTestTools_H
#define eccsTestTools_H
/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsTestTools.h,v 1.107 1999/09/15 09:26:24 vltsccm Exp $"
*
* eccsTestTools.h
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 18/08/95 In eccsErrLog() replaced ResetStack() with CloseStack()
* gchiozzi 04/05/95 Added macros for debugging logs
* gchiozzi 18/10/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

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

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

/* Tools for developing test programs */

#ifndef eccs_H
#include "eccs.h"
#endif
#ifndef eccsLog_H
#include "eccsLog.h"
#endif
#ifndef eccsErr_H
#include "eccsErr.h"
#endif

ccsCOMPL_STAT eccsLogComment(const char *logstr, ...);
ccsCOMPL_STAT eccsLogError(const ccsERROR *error_p,
const char * errstr, ...);
void eccsLogSave(const int value);

/*******************************************************/
/* These macros makes easier handling error conditions */
/*******************************************************/

#define eccsErrExit(a,b) if( (a) == FAILURE ) \
{ \
eccsLogError(stdErr, (b)); \
errCloseStack(stdErr); \
exit(1); \
}

#define eccsErrLog(a,b) if( (a) == FAILURE ) \
{ \
eccsLogError(stdErr, (b)); \
errCloseStack(stdErr); \
}

/*************************************************************************/
/* These macros can be used to log messages (on standard output AND/OR */
/* on the log system) depending on the value of a control variable: */
/* eccsLOG_LEVEL (between 0 to 3) */
/* if it is not defined or if its value is 0, only level 0 are logged */
/*************************************************************************/

#define eccsLOG_0(args) eccsLogComment args
#define eccsLOG_1(args)
#define eccsLOG_2(args)
#define eccsLOG_3(args)

#if eccsLOG_LEVEL >= 1
#undef eccsLOG_1
#define eccsLOG_1(args) eccsLogComment args
#endif
#if eccsLOG_LEVEL >= 2
#undef eccsLOG_2
#define eccsLOG_2(args) eccsLogComment args
#endif
#if eccsLOG_LEVEL >= 3
#undef eccsLOG_3
#define eccsLOG_3(args) eccsLogComment args
#endif

/* Include the code for inline methods */
#include "eccsTestTools.icc"


#endif /* ! ECCSTESTTOOLS_H */


5.16 eccsTIMEVAL


#ifndef eccsTIMEVAL_H
#define eccsTIMEVAL_H
/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsTIMEVAL.h,v 1.107 1999/09/15 09:26:27 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 12/06/97 Created
*/

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

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

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

struct eccsTIMEVAL: public ccsTIMEVAL
{
eccsTIMEVAL(unsigned long sec = 0, long usec = 0);
eccsTIMEVAL(const ccsTIMEVAL &e);

eccsTIMEVAL &operator =(const ccsTIMEVAL &e);
operator unsigned long() const;
};

/* Include the code for inline methods */
#include "eccsTIMEVAL.icc"

#endif /* ! eccsTIMEVAL_H */


6 EXAMPLE PROGRAMS

6.1 BASIC FUNCTIONS AND SIMPLE DATABASE ACCESS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsSamp.C,v 1.107 1999/09/15 09:26:33 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

/************************************************************************
* NAME
* eccsSamp - ECCS sample program
*
* SYNOPSIS
* eccsSamp
*
* DESCRIPTION
* Sample program using ECCS.
* Reads some attributes from the online database
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>


/*
* Local Headers
*/
#include "ECCS.h"
#include "eccsTestTools.h"



/*
* Function definition
*/
int main(int, char *argv[])
{
vltFLOAT fvar;
vltUINT32 ivar;
ccsCOMPL_STAT stat;

if (ccsInit(argv[0]) == FAILURE)
eccsErrExit(FAILURE,"Error in Init \n");

/* This expression is equivalent to the more compact but
* (perhaps) less readable:
*
* eccsErrExit(eccsInit(argv[0]),"Error in Init \n");
*
*/


stat = dbOpen();
eccsErrExit(stat,"Error in Open\n");

stat = dbRead(&ivar,":PARAMS:SCALARS.scalar_uint32");
eccsErrExit(stat,"Error in Read \n");

printf("Float value : %f\n", fvar);
printf("Int32 value : %d\n", ivar);

fvar = 4.63;
ivar = 8;
stat = dbWrite(&fvar,":PARAMS:SCALARS.scalar_float");
eccsErrExit(stat,"Error in WR \n");
stat = dbWrite(&ivar,":PARAMS:SCALARS.scalar_uint32");
eccsErrExit(stat,"Error in WR \n");

stat = dbRead(&fvar,":PARAMS:SCALARS.scalar_float");
eccsErrExit(stat,"Error in Read \n");
stat = dbRead(&ivar,":PARAMS:SCALARS.scalar_uint32");
eccsErrExit(stat,"Error in Read \n");

printf("Float value : %f\n", fvar);
printf("Int32 value : %d\n", ivar);


fvar = 5.3;
ivar = 4;
stat = dbWrite(&fvar,":PARAMS:SCALARS.scalar_float");
eccsErrExit(stat,"Error in WR \n");
stat = dbWrite(&ivar,":PARAMS:SCALARS.scalar_uint32");
eccsErrExit(stat,"Error in WR \n");

stat = dbRead(&fvar,":PARAMS:SCALARS.scalar_float");
eccsErrExit(stat,"Error in Read \n");
stat = dbRead(&ivar,":PARAMS:SCALARS.scalar_uint32");
eccsErrExit(stat,"Error in Read \n");

printf("Float value : %f\n", fvar);
printf("Int32 value : %d\n", ivar);

stat = dbExit();
eccsErrExit(stat,"Error in Exit\n");

ccsExit();
}

/*___oOo___*/


6.2 DATABASE ACCESS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsSampRW.C,v 1.107 1999/09/15 09:26:40 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

/************************************************************************
* NAME
* eccsSampRW - ECCS database access sample program
*
* SYNOPSIS
* eccsSampRW
*
* DESCRIPTION
* Sample ECCS program to show how database access functions work.
* It accesses the default environment.
* It assumes that the default test branch is present on the database.
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

/* Set this define TRUE to have compile time errors */
#ifndef WITHERRORS
#define WITHERRORS 0
#endif


#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>


/*
* Local Headers
*/
#include "ECCS.h"
#include "eccsTestTools.h"


/*
* Function definition
*/

struct TEST_DATA
{
vltINT16 int16;
vltUINT16 uint16;
vltINT32 int32;
vltUINT32 uint32;
vltFLOAT flt;
vltDOUBLE dbl;

vltPOLAR polar; /* Not implemented */
vltRECTANGULAR rectangular; /* Not implemented */

vltBYTES8 bytes8;
vltBYTES16 bytes16;

TEST_DATA();
ccsCOMPL_STAT Clear();
ccsCOMPL_STAT Set( vltUINT16 basei, char basec);
ccsCOMPL_STAT Print();
ccsCOMPL_STAT Read();
ccsCOMPL_STAT Write();
};


int main(int, char *argv[])
{
ccsCOMPL_STAT stat;
TEST_DATA data;

/* This expression is equivalent to the more compact but
* (perhaps) less readable:
*
* eccsErrExit(eccsInit(argv[0]),"Error in Init \n");
* and to:
* stat = eccsInit(argv[0]);
* eccsErrExit(stat,"Error in Init \n");
*/
if (ccsInit(argv[0]) == FAILURE)
eccsErrExit(FAILURE,"Error in Init \n");


eccsLogComment("Testing Easy CCS Read/Write functions\n");

stat = dbOpen();
eccsErrExit(stat,"Error in Open\n");

/* First control test */
data.Set(10,'a');
stat = data.Write();
eccsErrExit(stat,"Error in Write \n");
data.Clear();
stat = data.Read();
eccsErrExit(stat,"Error in Read \n");
data.Print();

/* Second control test */
data.Set(11,'b');
stat = data.Write();
eccsErrExit(stat,"Error in Write \n");
data.Clear();
stat = data.Read();
eccsErrExit(stat,"Error in Read \n");
data.Print();


#if WITHERRORS == 1
/* These lines are rejected at compile type */
vltLOGICAL logical;
vltINT8 int8;
vltUINT8 uint8;
char *string;
char string4[4];

dbRead(&logical,"doesnt matter");
dbRead(&int8,"doesnt matter");
dbRead(&uint8,"doesnt matter");
dbRead(string,"doesnt matter");
dbRead(string4,"doesnt matter");

#endif

stat = dbExit();
eccsErrExit(stat,"Error in Exit\n");

} /* end main() */

/**************************************/
/* Implementation for class TEST_DATA */
/**************************************/

TEST_DATA::TEST_DATA()
{
Clear();
}

ccsCOMPL_STAT TEST_DATA::Clear()
{
eccsLogComment("TEST_DATA - clearing");

int16 = 0;
uint16 = 0;
int32 = 0;
uint32 = 0;
flt = 0;
dbl = 0;

// memset( &polar, sizeof(polar), '\0');
// memset( &rectangular, sizeof(rectangular), '\0');
memset( bytes8, '\0', sizeof(bytes8));
memset( bytes16, '\0', sizeof(bytes16));

return SUCCESS;

} /* end Clear() */

ccsCOMPL_STAT TEST_DATA::Set( vltUINT16 basei, char basec)
{
eccsLogComment("TEST_DATA - setting with base (%d, %c)", basei, basec);

int16 = -basei;
uint16 = basei;
int32 = -basei;
uint32 = basei;
flt = basei+0.5;
dbl = basei+0.5;

// memset( &polar, sizeof(polar), '\0');
// memset( &rectangular, sizeof(rectangular), '\0');
memset( bytes8, basec, sizeof(bytes8)-1);
memset( bytes16, basec, sizeof(bytes16)-1);

return SUCCESS;

} /* end Set() */

ccsCOMPL_STAT TEST_DATA::Print()
{
eccsLogComment("TEST_DATA - current values:");

/* No printout of polar and rectangular */
eccsLogComment(" int16 = %d", int16);
eccsLogComment(" uint16 = %ud", uint16);
eccsLogComment(" int32 = %d", int32);
eccsLogComment(" uint32 = %ud", uint32);
eccsLogComment(" flt = %f", flt);
eccsLogComment(" dbl = %f", dbl);
eccsLogComment(" bytes8 = %s", bytes8);
eccsLogComment(" bytes16 = %s", bytes16);

return SUCCESS;

} /* end Print() */

ccsCOMPL_STAT TEST_DATA::Read()
{
eccsLogComment("TEST_DATA - reading");
if(dbRead(&int16,":PARAMS:SCALARS.scalar_int16")==FAILURE )
return FAILURE;
if(dbRead(&uint16,":PARAMS:SCALARS.scalar_uint16")==FAILURE )
return FAILURE;
if(dbRead(&int32,":PARAMS:SCALARS.scalar_int32")==FAILURE )
return FAILURE;
if(dbRead(&uint32,":PARAMS:SCALARS.scalar_uint32")==FAILURE )
return FAILURE;
if(dbRead(&flt,":PARAMS:SCALARS.scalar_float")==FAILURE )
return FAILURE;
if(dbRead(&dbl,":PARAMS:SCALARS.scalar_double")==FAILURE )
return FAILURE;
if(dbRead(VLTBYTES(bytes8),":PARAMS:SCALARS.scalar_string8")==FAILURE )
return FAILURE;
if(dbRead(VLTBYTES(bytes16),":PARAMS:SCALARS.scalar_string16")==FAILURE )
return FAILURE;

return SUCCESS;

} /* end Read() */

ccsCOMPL_STAT TEST_DATA::Write()
{
eccsLogComment("TEST_DATA - writing");

if(dbWrite(&int16,":PARAMS:SCALARS.scalar_int16")==FAILURE)
return FAILURE;
if(dbWrite(&uint16,":PARAMS:SCALARS.scalar_uint16")==FAILURE)
return FAILURE;
if(dbWrite(&int32,":PARAMS:SCALARS.scalar_int32")==FAILURE)
return FAILURE;
if(dbWrite(&uint32,":PARAMS:SCALARS.scalar_uint32")==FAILURE)
return FAILURE;
if(dbWrite(&flt,":PARAMS:SCALARS.scalar_float")==FAILURE)
return FAILURE;
if(dbWrite(&dbl,":PARAMS:SCALARS.scalar_double")==FAILURE)
return FAILURE;
if(dbWrite(VLTBYTES(bytes8),":PARAMS:SCALARS.scalar_string8")==FAILURE)
return FAILURE;
if(dbWrite(VLTBYTES(bytes16),":PARAMS:SCALARS.scalar_string16")==FAILURE)
return FAILURE;

return SUCCESS;

} /* end Write() */

/*___oOo___*/


6.3 DATABASE ACCESS USING THE eccsDB_ATTR CLASS



/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsTestDB_ATTR.C,v 1.107 1999/09/15 09:26:34 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* mnastvog 23/04/96 Updated tests for UINT32 and UINT16
* gchiozzi 27/04/95 created
*/

/************************************************************************
* NAME
*
*
* SYNOPSIS
*
* DESCRIPTION
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* This test needs to be extended to all the features.
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>


/*
* Local Headers
*/
#include "ECCS.h"
#include "eccsTestTools.h"
#include "eccsDB_ATTR.h"

#define TestAttr(dbattr) if(dbattr.ErrStatus() == FAILURE) \
eccsErrLog(FAILURE,"Error found in " #dbattr);

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

eccsLogComment("ECCS test for database eccsDB_ATTR classes");

eccsLogComment("Init");
stat = ccsInit(argv[0]);
eccsErrLog(stat,"Error in Init");

eccsLogComment("Open");
stat = dbOpen();
eccsErrLog(stat,"Error in Open");



/* Creates some generic attributes */
eccsLogComment("==== Test eccsDB_ATTR base class");
eccsLogComment("== Creating instances");
vltBYTES32 aString = "db_attr_test";
eccsDB_ATTR stringAttr(":PARAMS:SCALARS.scalar_string32");
TestAttr(stringAttr);

vltDOUBLE aDouble = 3.14159;
eccsDB_ATTR doubleAttr(":PARAMS:SCALARS.scalar_double");
TestAttr(doubleAttr);

vltFLOAT aFloat = 2.89;
eccsDB_ATTR floatAttr(":PARAMS:SCALARS.scalar_float");
TestAttr(floatAttr);

vltINT32 anInt32 = 32;
vltUINT32 anUInt32 = 32;

eccsDB_ATTR int32Attr(":PARAMS:SCALARS.scalar_int32");
TestAttr(int32Attr);

vltINT16 anInt16 = 16;
vltUINT16 anUInt16 = 16;

eccsDB_ATTR int16Attr(":PARAMS:SCALARS.scalar_int16");
TestAttr(int16Attr);

vltINT8 anInt8 = 8;
vltUINT8 anUInt8 = 8;

eccsDB_ATTR int8Attr(":PARAMS:SCALARS.scalar_int8");
TestAttr(int8Attr);

vltLOGICAL aLogical = 1;
eccsDB_ATTR logicalAttr(":PARAMS:SCALARS.scalar_logical");
TestAttr(logicalAttr);

/* Read the value and print it */
stringAttr.SetValue((char *)aString); TestAttr(stringAttr);
stringAttr.GetValue((char *)aString); TestAttr(stringAttr);
eccsLogComment("String = %s", aString);

doubleAttr.SetValue((char *)&aDouble); TestAttr(doubleAttr);
doubleAttr.GetValue((char *)&aDouble); TestAttr(doubleAttr);
eccsLogComment("Double = %f", aDouble);

floatAttr.SetValue((char *)&aFloat); TestAttr(floatAttr);
floatAttr.GetValue((char *)&aFloat); TestAttr(floatAttr);
eccsLogComment("Float = %f", aFloat);

int32Attr.SetValue((char *)&anInt32); TestAttr(int32Attr);
int32Attr.GetValue((char *)&anInt32); TestAttr(int32Attr);
eccsLogComment("Int32 = %ld", anInt32);

int16Attr.SetValue((char *)&anInt16); TestAttr(int16Attr);
int16Attr.GetValue((char *)&anInt16); TestAttr(int16Attr);
eccsLogComment("Int16 = %d", anInt16);

int8Attr.SetValue((char *)&anInt8); TestAttr(int8Attr);
int8Attr.GetValue((char *)&anInt8); TestAttr(int8Attr);
eccsLogComment("Int8 = %d", anInt8);

logicalAttr.SetValue((char *)&aLogical); TestAttr(logicalAttr);
logicalAttr.GetValue((char *)&aLogical); TestAttr(logicalAttr);
eccsLogComment("Logical = %d", aLogical);

/* Creates some invalid attribute to test error stack */
eccsLogComment("== Creating invalid attribute");
eccsDB_DOUBLE aDbDoublex_2(":PARAMS:SCALARS","scalar_doubleerr");
TestAttr(aDbDoublex_2);
aDbDoublex_2 = 25; TestAttr(aDbDoublex_2);

/* Test using correct and wrong buffer sizes */
int16Attr.SetValue((char *)&anInt16, sizeof(anInt16)); TestAttr(int16Attr);
int16Attr.GetValue((char *)&anInt16, sizeof(anInt16)); TestAttr(int16Attr);
eccsLogComment("Int16 = %d", anInt16);

int16Attr.SetValue((char *)&anInt16, 32); TestAttr(int16Attr);
int16Attr.GetValue((char *)&anInt16, 1); TestAttr(int16Attr);
eccsLogComment("Int16 = %d", anInt16);

/* Uses the class eccsDB_STRING to test read and write */
/* through assignment operators (first constructor) */
eccsLogComment("== Assignement operator on string");
eccsDB_STRING aDbString8(":PARAMS:SCALARS.scalar_string8");
TestAttr(aDbString8);
const char *ptr_string;

aDbString8 = "1212121"; TestAttr(aDbString8);
ptr_string = aDbString8; TestAttr(aDbString8);
eccsLogComment("String 8 = %s", ptr_string);
aDbString8 = "7654321"; TestAttr(aDbString8);
ptr_string = aDbString8; TestAttr(aDbString8);
eccsLogComment("String 8 = %s", ptr_string);

/* Uses the class eccsDB_STRING to test read and write */
/* through assignment operators (second constructor) */
eccsDB_STRING aDbString8_2(":PARAMS:SCALARS","scalar_string8");
TestAttr(aDbString8_2);

aDbString8_2 = "1234567"; TestAttr(aDbString8_2);
ptr_string = aDbString8_2; TestAttr(aDbString8_2);
eccsLogComment("String 8 = %s", ptr_string);
aDbString8_2 = "7654321"; TestAttr(aDbString8_2);
ptr_string = aDbString8_2; TestAttr(aDbString8_2);
eccsLogComment("String 8 = %s", ptr_string);


/* Uses the class eccsDB_DOUBLE to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_double");
eccsDB_DOUBLE aDbDouble(":PARAMS:SCALARS.scalar_double");

aDbDouble= 15; TestAttr(aDbDouble);
aDouble = aDbDouble; TestAttr(aDbDouble);
eccsLogComment("Double = %f", aDouble);
aDbDouble= 18; TestAttr(aDbDouble);
aDouble = aDbDouble; TestAttr(aDbDouble);
eccsLogComment("Double = %f", aDouble);

/* Uses the class eccsDB_DOUBLE to test read and write */
/* through assignment operators (second constructor) */
eccsDB_DOUBLE aDbDouble_2(":PARAMS:SCALARS","scalar_double");

aDbDouble_2 = 25; TestAttr(aDbDouble_2);
aDouble = aDbDouble_2; TestAttr(aDbDouble_2);
eccsLogComment("Double = %f", aDouble);
aDbDouble_2 = 28; TestAttr(aDbDouble_2);
aDouble = aDbDouble_2; TestAttr(aDbDouble_2);
eccsLogComment("Double = %f", aDouble);


/* Uses the class eccsDB_FLOAT to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_float");
eccsDB_FLOAT aDbFloat(":PARAMS:SCALARS.scalar_float");

aDbFloat= 15; TestAttr(aDbFloat);
aFloat = aDbFloat; TestAttr(aDbFloat);
eccsLogComment("Float = %f", aFloat);
aDbFloat= 18; TestAttr(aDbFloat);
aFloat = aDbFloat; TestAttr(aDbFloat);
eccsLogComment("Float = %f", aFloat);

/* Uses the class eccsDB_FLOAT to test read and write */
/* through assignment operators (second constructor) */
eccsDB_FLOAT aDbFloat_2(":PARAMS:SCALARS","scalar_float");

aDbFloat_2 = 25; TestAttr(aDbFloat_2);
aFloat = aDbFloat_2; TestAttr(aDbFloat_2);
eccsLogComment("Float = %f", aFloat);
aDbFloat_2 = 28; TestAttr(aDbFloat_2);
aFloat = aDbFloat_2; TestAttr(aDbFloat_2);
eccsLogComment("Float = %f", aFloat);



/* Uses the class eccsDB_INT32 to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_int32");
eccsDB_INT32 aDbInt32(":PARAMS:SCALARS.scalar_int32");

aDbInt32 = 15; TestAttr(aDbInt32);
anInt32 = aDbInt32; TestAttr(aDbInt32);
eccsLogComment("Int32 = %ld", anInt32);
aDbInt32 = 18; TestAttr(aDbInt32);
anInt32 = aDbInt32; TestAttr(aDbInt32);
eccsLogComment("Int32 = %ld", anInt32);

/* Uses the class eccsDB_INT32 to test read and write */
/* through assignment operators (second constructor) */
eccsDB_INT32 aDbInt32_2(":PARAMS:SCALARS","scalar_int32");

aDbInt32_2 = 25; TestAttr(aDbInt32);
anInt32 = aDbInt32_2; TestAttr(aDbInt32);
eccsLogComment("Int32 = %ld", anInt32);
aDbInt32_2 = 28; TestAttr(aDbInt32);
anInt32 = aDbInt32_2; TestAttr(aDbInt32);
eccsLogComment("Int32 = %ld", anInt32);



/* Uses the class eccsDB_UINT32 to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_uint32");
eccsDB_UINT32 aDbUInt32(":PARAMS:SCALARS.scalar_uint32");

aDbUInt32 = 15; TestAttr(aDbUInt32);
anUInt32 = aDbUInt32; TestAttr(aDbUInt32);
eccsLogComment("UInt32 = %ld", anUInt32);
aDbUInt32 = 18; TestAttr(aDbUInt32);
anUInt32 = aDbUInt32; TestAttr(aDbUInt32);
eccsLogComment("UInt32 = %ld", anUInt32);

/* Uses the class eccsDB_UINT32 to test read and write */
/* through assignment operators (second constructor) */
eccsDB_UINT32 aDbUInt32_2(":PARAMS:SCALARS","scalar_uint32");

aDbUInt32_2 = 25; TestAttr(aDbUInt32);
anUInt32 = aDbUInt32_2; TestAttr(aDbUInt32);
eccsLogComment("UInt32 = %ld", anUInt32);
aDbUInt32_2 = 28; TestAttr(aDbUInt32);
anUInt32 = aDbUInt32_2; TestAttr(aDbUInt32);
eccsLogComment("UInt32 = %ld", anUInt32);



/* Uses the class eccsDB_INT16 to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_int16");
eccsDB_INT16 aDbInt16(":PARAMS:SCALARS.scalar_int16");

aDbInt16 = 15; TestAttr(aDbInt16);
anInt16 = aDbInt16; TestAttr(aDbInt16);
eccsLogComment("Int16 = %d", anInt16);
aDbInt16 = 18; TestAttr(aDbInt16);
anInt16 = aDbInt16; TestAttr(aDbInt16);
eccsLogComment("Int16 = %d", anInt16);

/* Uses the class eccsDB_INT16 to test read and write */
/* through assignment operators (second constructor) */
eccsDB_INT16 aDbInt16_2(":PARAMS:SCALARS","scalar_int16");

aDbInt16_2 = 25; TestAttr(aDbInt16);
anInt16 = aDbInt16_2; TestAttr(aDbInt16);
eccsLogComment("Int16 = %d", anInt16);
aDbInt16_2 = 28; TestAttr(aDbInt16);
anInt16 = aDbInt16_2; TestAttr(aDbInt16);
eccsLogComment("Int16 = %d", anInt16);



/* Uses the class eccsDB_UINT16 to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_uint16");
eccsDB_UINT16 aDbUInt16(":PARAMS:SCALARS.scalar_uint16");

aDbUInt16 = 15; TestAttr(aDbUInt16);
anUInt16 = aDbUInt16; TestAttr(aDbUInt16);
eccsLogComment("UInt16 = %d", anUInt16);
aDbUInt16 = 18; TestAttr(aDbUInt16);
anUInt16 = aDbUInt16; TestAttr(aDbUInt16);
eccsLogComment("UInt16 = %d", anUInt16);

/* Uses the class eccsDB_UINT16 to test read and write */
/* through assignment operators (second constructor) */
eccsDB_UINT16 aDbUInt16_2(":PARAMS:SCALARS","scalar_uint16");

aDbUInt16_2 = 25; TestAttr(aDbUInt16);
anUInt16 = aDbUInt16_2; TestAttr(aDbUInt16);
eccsLogComment("UInt16 = %d", anUInt16);
aDbUInt16_2 = 28; TestAttr(aDbUInt16);
anUInt16 = aDbUInt16_2; TestAttr(aDbUInt16);
eccsLogComment("UInt16 = %d", anUInt16);

/* Uses the class eccsDB_INT8 to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_int8");
eccsDB_INT8 aDbInt8(":PARAMS:SCALARS.scalar_int8");

aDbInt8 = 15; TestAttr(aDbInt8);
anInt8 = aDbInt8; TestAttr(aDbInt8);
eccsLogComment("Int8 = %d", anInt8);
aDbInt8 = 18; TestAttr(aDbInt8);
anInt8 = aDbInt8; TestAttr(aDbInt8);
eccsLogComment("Int8 = %d", anInt8);

/* Uses the class eccsDB_INT8 to test read and write */
/* through assignment operators (second constructor) */
eccsDB_INT8 aDbInt8_2(":PARAMS:SCALARS","scalar_int8");

aDbInt8_2 = 25; TestAttr(aDbInt8);
anInt8 = aDbInt8_2; TestAttr(aDbInt8);
eccsLogComment("Int8 = %d", anInt8);
aDbInt8_2 = 28; TestAttr(aDbInt8);
anInt8 = aDbInt8_2; TestAttr(aDbInt8);
eccsLogComment("Int8 = %d", anInt8);



/* Uses the class eccsDB_UINT8 to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_uint8");
eccsDB_UINT8 aDbUInt8(":PARAMS:SCALARS.scalar_uint8");

aDbUInt8 = 15; TestAttr(aDbUInt8);
anUInt8 = aDbUInt8; TestAttr(aDbUInt8);
eccsLogComment("UInt8 = %d", anUInt8);
aDbUInt8 = 18; TestAttr(aDbUInt8);
anUInt8 = aDbUInt8; TestAttr(aDbUInt8);
eccsLogComment("UInt8 = %d", anUInt8);

/* Uses the class eccsDB_UINT8 to test read and write */
/* through assignment operators (second constructor) */
eccsDB_UINT8 aDbUInt8_2(":PARAMS:SCALARS","scalar_uint8");

aDbUInt8_2 = 25; TestAttr(aDbUInt8);
anUInt8 = aDbUInt8_2; TestAttr(aDbUInt8);
eccsLogComment("UInt8 = %d", anUInt8);
aDbUInt8_2 = 28; TestAttr(aDbUInt8);
anUInt8 = aDbUInt8_2; TestAttr(aDbUInt8);
eccsLogComment("UInt8 = %d", anUInt8);


/* Uses the class eccsDB_LOGICAL to test read and write */
/* through assignment operators */
eccsLogComment("Testing :PARAMS:SCALARS.scalar_logical");
eccsDB_LOGICAL aDbLogical(":PARAMS:SCALARS.scalar_logical");

aDbLogical = 1; TestAttr(aDbLogical);
aLogical = aDbLogical; TestAttr(aDbLogical);
eccsLogComment("Logical = %d", aLogical);
aDbLogical = 0; TestAttr(aDbLogical);
aLogical = aDbLogical; TestAttr(aDbLogical);
eccsLogComment("Logical = %d", aLogical);

/* Uses the class eccsDB_LOGICAL to test read and write */
/* through assignment operators (second constructor) */
eccsDB_LOGICAL aDbLogical_2(":PARAMS:SCALARS","scalar_logical");

aDbLogical_2 = 25; TestAttr(aDbLogical);
aLogical = aDbLogical_2; TestAttr(aDbLogical);
eccsLogComment("Logical = %d", aLogical);
aDbLogical_2 = 28; TestAttr(aDbLogical);
aLogical = aDbLogical_2; TestAttr(aDbLogical);
eccsLogComment("Logical = %d", aLogical);


/*************************************************/
/* Test accessing elements in tables and vectors */
eccsLogComment("== Vector and array access");
eccsLogComment("Testing :PARAMS:VECTORS.vector_logical(1)");
vltLOGICAL vecLog = 1;
vltLOGICAL savLog;

eccsDB_LOGICAL arrayLogAttr(":PARAMS:VECTORS.vector_logical(1)");
TestAttr(arrayLogAttr);

savLog = arrayLogAttr; TestAttr(arrayLogAttr);
arrayLogAttr = vecLog; TestAttr(arrayLogAttr);
vecLog = 0;
vecLog = arrayLogAttr; TestAttr(arrayLogAttr);
eccsLogComment("Logical = %d", vecLog);
arrayLogAttr = vecLog; TestAttr(arrayLogAttr);

eccsLogComment("Testing :PARAMS:TABLES.full_table(1,float)");
vltFLOAT tblFloat = 2.89;
vltFLOAT savFloat;
eccsDB_FLOAT tableFloatAttr(":PARAMS:TABLES.full_table(1,float)");
TestAttr(tableFloatAttr);
savFloat = tableFloatAttr; TestAttr(tableFloatAttr);
tableFloatAttr = tblFloat; TestAttr(tableFloatAttr);
tblFloat = 0;
tblFloat = tableFloatAttr; TestAttr(tableFloatAttr);
eccsLogComment("Float = %f", tblFloat);
tableFloatAttr = tblFloat; TestAttr(tableFloatAttr);





/* TEST ASSIGNEMENT OPERATORS AND COPY CONSTRUCTORS */
/* This test is not good, because uses embedded environment */
/* names: it must be rewritten using special points or other */
/* conventions for environment names */
/* Assignement between eccsDB_LOGICAL */

#if 0
// Commented now to not create problems with automatic tests
eccsDB_LOGICAL aDbLogicalA("@wte13:PARAMS:SCALARS.scalar_logical");
eccsDB_LOGICAL aDbLogicalB("@wte16:PARAMS:SCALARS.scalar_logical");

aDbLogicalA = 1;
eccsLogComment("Logical A = %d", (vltLOGICAL)aDbLogicalA);

aDbLogicalB = 0;
eccsLogComment("Logical B = %d", (vltLOGICAL)aDbLogicalB);

eccsLogComment("Assign B to A");

aDbLogicalA = aDbLogicalB;
eccsLogComment("Logical A = %d", (vltLOGICAL)aDbLogicalA);
#endif

/* Assignement between strings of different size */
eccsLogComment("== Assignement between strings of different size");
eccsDB_STRING aDbString16(":PARAMS:SCALARS","scalar_string16");
eccsDB_STRING aDbString32(":PARAMS:SCALARS","scalar_string32");

aDbString16 = "12345671234567";
eccsLogComment("String 16 = %s", (const char *)aDbString16);

aDbString32 = "abcdefgabcgefgabcdefgabcgefg";
eccsLogComment("String 32 = %s", (const char *)aDbString32);

eccsLogComment("Assign 16 to 32");
aDbString32 = aDbString16;
eccsLogComment("String 32 = %s", (const char *)aDbString32);

eccsLogComment("Assign 32 to 16 (after cleanup)");
aDbString32 = "abcdefgabcgefgabcdefgabcgefg";
aDbString16 = aDbString32;
eccsLogComment("String 16 = %s", (const char *)aDbString16);

/* Use the copy constructor */
eccsDB_STRING aCopiedString32(aDbString32);
aCopiedString32 = "copied string";
eccsLogComment("Copied = %s", (const char *)aCopiedString32);
eccsLogComment("String 32 = %s", (const char *)aDbString32);

/* Assignment using char* instead of const char * */
aCopiedString32 = "Newly copied string";
aDbString32 = (const char*)aCopiedString32;
eccsLogComment("String 32 = %s", (const char *)aDbString32);


/* Mixed assignements are not allowed and are catched by the compiler */
#if 0
aDbString16 = aDbLogical;
intAttr = aDbInt32;
#endif

/* DB quality error handling */
eccsDB_DOUBLE badboy(":Appl_data:eccsTest:eccsTable.badboy");

vltDOUBLE accessVar = badboy;

if(badboy.ErrStatus() == FAILURE)
{
if(badboy.ErrStack().IsReason("db",ccsERR_DB_QUALITY) )
eccsLogComment("Expected quality error");
else
eccsLogComment("Unexpected error");
errCloseStack();
}
accessVar = 5;

/* Exit */
eccsLogComment("End of test");
stat = dbExit();
eccsErrLog(stat,"Error in Exit");

} /* end main() */




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







/*___oOo___*/



6.4 DATABASE ACCESS TO VECTORS USING eccsDB_VECTOR


/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsTestVector.C,v 1.107 1999/09/15 09:26:36 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 28/04/97 Replace delete with delete[] in arrays
* vltsw 04/07/96 Fixed memory leaks
* gchiozzi 18/10/95 created
* rabuter 07/11/95 test for vectors
*/



#define _POSIX_SOURCE 1
#include "vltPort.h"



static char *rcsId="@(#) $Id: eccsTestVector.C,v 1.107 1999/09/15 09:26:36 vltsccm Exp $";
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#include "eccsDB_VECTOR.h"

/*****************/
/* MAIN function */
/*****************/


int main(int, char *argv[])
{
/************/
/* Init */
/************/

ccsCOMPL_STAT stat,st;

eccsLogComment("ECCS test for database eccsDB_ATTR classes");

eccsLogComment("Init");
stat = ccsInit(argv[0]);
eccsErrLog(stat,"Error in Init \n");

eccsLogComment("Open");
stat = dbOpen();
eccsErrLog(stat,"Error in Open\n");


/***********/
/* Body */
/***********/

vltINT32 recordCnt;
vltINT32 i;

// ======== vltINT32 =========================================
// Define an array ov vltINT32
{
cout << "\n===== Testing vltINT32 ======\n";
//eccsDB_VECTOR<vltINT32> vector(":PARAMS:VECTORS.vector_int32");

eccsDB_VECTOR_vltINT32 vector(":PARAMS:VECTORS.vector_int32");

// Get the number of records in the array
recordCnt = vector.RecordCnt();

// Allocate the memory array
vltINT32 *array = new vltINT32[recordCnt];

// Read the vector
st = vector.GetValue(array);

// Set new value in the array:
for(i =0; i<recordCnt; i++)
{
array[i] = i;
}
// Store it in the vector
st = vector.SetValue(array);

// Clean the array in memory
for(i =0; i<recordCnt; i++)
{
array[i] = 0;
}
// Show that it has been cleaned
cout << "Verify that it is clean in memory:\n";
for(i =0; i<recordCnt; i++)
{
cout << " " << array[i];
}
cout << "\n"; cout.flush();

// Reread from the vector
st = vector.GetValue(array);
cout << "New contents read from db (0->7)\n";
for(i =0; i<recordCnt; i++)
{
cout << " " << array[i];
}
cout << "\n"; cout.flush();


// Testing subscript operator
cout << "Subscript operator\n";
cout << "Writing new values one by one and read immediately\n";
for(i =0; i<recordCnt; i++)
{
vector[i] = recordCnt-i;
cout << " " << (vltINT32)vector[i];
}
cout << "\n"; cout.flush();

cout << "Reading values one by one and read immediately\n";
for(i =0; i<recordCnt; i++)
{
array[i] = vector[i];
cout << " " << array[i];
}
cout << "\n"; cout.flush();


delete []array;
}

// ======== vltBYTES20 =========================================
// Define an array ov vltBYTES20
{
cout << "\n===== Testing vltBYTES20 ======\n";
//eccsDB_VECTOR<vltBYTES20> vector(":PARAMS:VECTORS.vector_string20");

eccsDB_VECTOR_vltBYTES20 vector(":PARAMS:VECTORS.vector_string20");


// Get the number of records in the array
recordCnt = vector.RecordCnt();

// Allocate the memory array
vltBYTES20 *array = new vltBYTES20[recordCnt];

// Read the vector
st = vector.GetValue(array);

// Set new value in the array:
for(i =0; i<recordCnt; i++)
{
sprintf((char*)array[i],"String: %d",i);
}
// Store it in the vector
st = vector.SetValue(array);

// Clean the array in memory
for(i =0; i<recordCnt; i++)
{
sprintf((char*)array[i],"String:---");
}
// Show that it has been cleaned
cout << "Verify that it is clean in memory:\n";
for(i =0; i<recordCnt; i++)
{
cout << " " << array[i];
}
cout << "\n"; cout.flush();

// Reread from the vector
st = vector.GetValue(array);
cout << "New contents read from db\n";
for(i =0; i<recordCnt; i++)
{
cout << " " << array[i];
}
cout << "\n"; cout.flush();


// Clean the array in memory
for(i =0; i<recordCnt; i++)
{
sprintf((char*)array[i],"String: new %d", i);
st = vector.SetValue(i,array[i]);
}
for(i =0; i<recordCnt; i++)
{
sprintf((char*)array[i],"String: ---");
st = vector.GetValue(i,&array[i]);
cout << " " << array[i];
}

cout << "\n"; cout.flush();

// Testing subscript operator
cout << "Subscript operator\n";
cout << "Writing new values one by one and read immediately\n";
vltBYTES20 svalue;

for(i =0; i<recordCnt; i++)
{
memset ((char*)svalue, 0, sizeof (svalue));
sprintf((char*)svalue, "%3.3d", recordCnt-i);
vector[i] = svalue;
cout << " " << static_cast<const vltBYTES20&>(vector[i]);
}
cout << "\n"; cout.flush();

cout << "Reading values one by one and read immediately\n";
for(i =0; i<recordCnt; i++)
{
sprintf((char*)array[i],"String: ---");
strcpy((char*)array[i],
reinterpret_cast<const char *>(static_cast<const vltBYTES20&>(vector[i])));
cout << " " << array[i];
}
cout << "\n"; cout.flush();

delete array;
}

{
cout << "testing Invalid vector attr" << endl ;
eccsDB_VECTOR_vltINT32 vector(":PARAMS:VECTORS.novector");
if ( vector.ErrStatus() == FAILURE )
{
// No check is done on attribute name
cout << "failure Invalid vector" << endl;
}
}

cout.flush();

/***********/
/* Exit */
/***********/
stat = dbExit();
eccsErrLog(stat,"Error in Exit\n");

} /* end main() */













6.5 DATABASE ACCESS TO TABLES USING eccsDB_TABLE


/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsTestTable.C,v 1.107 1999/09/15 09:26:36 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* rkarban 11/08/99 cast void *buffer to char*
* gchiozzi 28/04/97 Replace delete with delete[] in arrays
* vltsw 04/07/96 Fixed memory leaks
* gchiozzi 18/10/95 created
* rabuter 07/11/95 test for tables and vectors of vltbytes
*/



#define _POSIX_SOURCE 1
#include "vltPort.h"



static char *rcsId="@(#) $Id: eccsTestTable.C,v 1.107 1999/09/15 09:26:36 vltsccm Exp $";
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#include "eccsDB_VECTOR.h"
#include "eccsDB_TABLE.h"

/*****************/
/* MAIN function */
/*****************/

// user provided TABLE class for db table TABLES.full_table

class TABLE : public eccsDB_TABLE_RECORD
{
public:
vltLOGICAL logical;
vltINT8 int8;
vltUINT32 uint32;
vltFLOAT floatvar;
vltBYTES4 bytes4;
vltBYTES32 bytes32;
ccsCOMPL_STAT Unpack( void *pBuffer )
{
char *buffer = reinterpret_cast<char *>(pBuffer);
memcpy( &logical, buffer,sizeof(vltLOGICAL));
buffer += sizeof(vltLOGICAL);
memcpy( &int8, buffer,sizeof(vltINT8) );
buffer += sizeof(vltINT8);
memcpy( &uint32, buffer,sizeof(vltUINT32) );
buffer += sizeof(vltUINT32);
memcpy( &floatvar,buffer,sizeof(vltFLOAT) );
buffer += sizeof(vltFLOAT);
memcpy( &bytes4, buffer,sizeof(vltBYTES4) );
buffer += sizeof(vltBYTES4);
memcpy( &bytes32, buffer,sizeof(vltBYTES32));

return(SUCCESS);
}
ccsCOMPL_STAT Pack( void *buffer )
{
int size = 0;
dbFillBuf( (char**)&buffer, (char*)&logical ,&size, dbLOGICAL);
dbFillBuf( (char**)&buffer, (char*)&int8 ,&size, dbINT8);
dbFillBuf( (char**)&buffer, (char*)&uint32 ,&size, dbUINT32);
dbFillBuf( (char**)&buffer, (char*)&floatvar ,&size, dbFLOAT);
dbFillBuf( (char**)&buffer, (char*)&bytes4 ,&size, dbBYTES4);
dbFillBuf( (char**)&buffer, (char*)&bytes32 ,&size, dbBYTES32);
return(SUCCESS);
}

};

int main(int, char *argv[])
{
/************/
/* Init */
/************/

ccsCOMPL_STAT stat,st;

eccsLogComment("ECCS test for database eccsDB_ATTR classes");

eccsLogComment("Init");
stat = ccsInit(argv[0]);
eccsErrLog(stat,"Error in Init \n");

eccsLogComment("Open");
stat = dbOpen();
eccsErrLog(stat,"Error in Open\n");


/***********/
/* Body */
/***********/

vltINT32 recordCnt;

// ======== TABLE =========================================
// Define a TABLE
{
cout << "\n===== Testing TABLE ======\n";

eccsDB_TABLE<TABLE> table("<alias>TABLES.full_table");
if ( table.ErrStatus() == FAILURE )
{
cout << "failure Invalid table" << endl;
exit(1);
}

// Get the number of records in the array
recordCnt = table.RecordCnt();
cout << "Table contains " << recordCnt << " records" << endl;


// Allocate the memory array
TABLE *table_array = new TABLE[recordCnt];

//Read all table
st = table.GetValue(table_array);

// Print all values (commented out since not deterministic)
int i;
cout << "Actual values:" << endl;
for ( i=0;i<recordCnt;i++)
{
//cout << "logical: " << (int)table_array[i].logical << "\n";
//cout << "int8 : " << (int)table_array[i].int8 << "\n";
// cout << "uint32 : " << table_array[i].uint32 << "\n";
//cout << "float : " << table_array[i].floatvar << "\n";
//cout << "bytes4 : " << table_array[i].bytes4 << "\n";
//cout << "bytes32: " << table_array[i].bytes32 << "\n";
}
cout << endl ;

// Modify values in memory
for ( i=0;i<recordCnt;i++)
{
table_array[i].logical=TRUE;
table_array[i].int8 = i;
table_array[i].uint32 = i;
table_array[i].floatvar = i;
strcpy( (char*)table_array[i].bytes4, (char*)"123");
strcpy( (char*)table_array[i].bytes32, (char*)"1234567");
}


// Rewrite whole table with changes
st = table.SetValue(table_array);


// Clean Memory
for ( i=0;i<recordCnt;i++)
{
table_array[i].logical=FALSE;
table_array[i].int8 = 0;
table_array[i].uint32 = 0;
table_array[i].floatvar = 0;
strcpy( (char*)table_array[i].bytes4, (char*)"---");
strcpy( (char*)table_array[i].bytes32, (char*)"---------------");
}

//Print Cleaned
cout << "Cleaned : " << endl;
for ( i=0;i<recordCnt;i++)
{
cout << "logical: " << (int)table_array[i].logical << "\n";
cout << "int8 : " << (int)table_array[i].int8 << "\n";
cout << "uint32 : " << table_array[i].uint32 << "\n";
cout << "float : " << table_array[i].floatvar << "\n";
cout << "bytes4 : " << table_array[i].bytes4 << "\n";
cout << "bytes32: " << table_array[i].bytes32 << "\n";
}
cout << endl ;



//ReRead
//Read all table
st = table.GetValue(table_array);

// Print new readed values
cout << "Modified values readed in block : " << endl;
for ( i=0;i<recordCnt;i++)
{
cout << "logical: " << (int)table_array[i].logical << "\n";
cout << "int8 : " << (int)table_array[i].int8 << "\n";
cout << "uint32 : " << table_array[i].uint32 << "\n";
cout << "float : " << table_array[i].floatvar << "\n";
cout << "bytes4 : " << table_array[i].bytes4 << "\n";
cout << "bytes32: " << table_array[i].bytes32 << "\n";
}
cout << endl ;



// Clean Memory
for ( i=0;i<recordCnt;i++)
{
table_array[i].logical=FALSE;
table_array[i].int8 = 0;
table_array[i].uint32 = 0;
table_array[i].floatvar = 0;
strcpy( (char*)table_array[i].bytes4, (char*)"---");
strcpy( (char*)table_array[i].bytes32, (char*)"---------------");
}




// Read one by one
for ( i=0;i<recordCnt;i++)
{
table_array[i] = table[i];
}

// Print new readed values
cout << "Modified values readed one by one : " << endl;
for ( i=0;i<recordCnt;i++)
{
cout << "logical: " << (int)table_array[i].logical << "\n";
cout << "int8 : " << (int)table_array[i].int8 << "\n";
cout << "uint32 : " << table_array[i].uint32 << "\n";
cout << "float : " << table_array[i].floatvar << "\n";
cout << "bytes4 : " << table_array[i].bytes4 << "\n";
cout << "bytes32: " << table_array[i].bytes32 << "\n";
}
cout << endl ;


// Set new values on memory
for ( i=0;i<recordCnt;i++)
{
table_array[i].logical = TRUE;
table_array[i].int8 = i*2;
table_array[i].uint32 = i*2;
table_array[i].floatvar = i*2;
strcpy( (char*)table_array[i].bytes4, (char*)"new");
strcpy( (char*)table_array[i].bytes32, (char*)"new value");
}


// Write new one by one
for ( i=0;i<recordCnt;i++)
{
table[i] = table_array[i];
}


// Clean Memory
for ( i=0;i<recordCnt;i++)
{
table_array[i].logical=FALSE;
table_array[i].int8 = 0;
table_array[i].uint32 = 0;
table_array[i].floatvar = 0;
strcpy( (char*)table_array[i].bytes4, (char*)"---");
strcpy( (char*)table_array[i].bytes32, (char*)"---------------");
}



//Print Cleaned
cout << "Cleaned : " << endl;
for ( i=0;i<recordCnt;i++)
{
cout << "logical: " << (int)table_array[i].logical << "\n";
cout << "int8 : " << (int)table_array[i].int8 << "\n";
cout << "uint32 : " << table_array[i].uint32 << "\n";
cout << "float : " << table_array[i].floatvar << "\n";
cout << "bytes4 : " << table_array[i].bytes4 << "\n";
cout << "bytes32: " << table_array[i].bytes32 << "\n";
}
cout << endl ;



// Read One by One
for ( i=0;i<recordCnt;i++)
{
table_array[i] = table[i];
}



//Print New values
cout << "New values written and readed one by one : " << endl;
for ( i=0;i<recordCnt;i++)
{
cout << "logical: " << (int)table_array[i].logical << "\n";
cout << "int8 : " << (int)table_array[i].int8 << "\n";
cout << "uint32 : " << table_array[i].uint32 << "\n";
cout << "float : " << table_array[i].floatvar << "\n";
cout << "bytes4 : " << table_array[i].bytes4 << "\n";
cout << "bytes32: " << table_array[i].bytes32 << "\n";
}
cout << endl ;


// Test access by name
// =====================
// Set new values on memory
int logiFlag = FALSE;
for ( i=0;i<recordCnt;i++)
{
logiFlag = logiFlag ? FALSE :TRUE;
table_array[i].logical = logiFlag;
table_array[i].int8 = i;
table_array[i].uint32 = i;
table_array[i].floatvar = i;
strcpy( (char*)table_array[i].bytes4, (char*)"new");
strcpy( (char*)table_array[i].bytes32, (char*)"new value");
}


// Write new one by one
for ( i=0;i<recordCnt;i++)
{
table[i] = table_array[i];
}

delete []table_array;
}


/***********/
/* Exit */
/***********/
stat = dbExit();
eccsErrLog(stat,"Error in Exit\n");

} /* end main() */













6.6 DATABASE ACCESS TO TABLES USING eccsDB_TABLE TO ACCESS RECORDS BY NAME


/*******************************************************************************
* E.S.O. - VLT project
*
* tblTest.C
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 28/04/97 Replace delete with delete[] in arrays
* vltsw 04/07/96 Fixed memory leaks
* gchiozzi 24/11/95 Modified to be used as eccs modular test
* therlin 24/11/95 created
*/

/************************************************************************
* NAME
* tblTest - little table test example
*
* SYNOPSIS
*
* DESCRIPTION
*
* ON LINE DATABASE
*
* POINT
* BEGIN
* ATTRIBUTE Table replies (25,
* rtBYTES8 command,
* rtBYTES256 reply)
* END
*
* COMMANDS
*
* RETURN VALUES
*
* SEE ALSO
* evhTASK(4)
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

static char *rcsId="@(#) $Id: eccsTestTable_2.C,v 1.107 1999/09/15 09:26:37 vltsccm Exp $";
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#include "ECCS.h"
#include "eccsDB_TABLE.h"

class simREPLY_TABLE : public eccsDB_TABLE_RECORD
{
public:
vltBYTES8 command;
vltBYTES256 reply;

simREPLY_TABLE()
{ strcpy((char*)command,""); strcpy((char*)reply,""); };

ccsCOMPL_STAT Unpack( void *pBuffer )
{
char *buffer = reinterpret_cast<char *>(pBuffer);
memcpy( &command, buffer,sizeof(command) );
buffer = buffer+sizeof(command);
memcpy( &reply, buffer,sizeof(reply));
return(SUCCESS);
}
ccsCOMPL_STAT Pack( void *buffer )
{
int size = 0;
dbFillBuf( (char**)&buffer, (char*)&command ,&size, dbBYTES8);
dbFillBuf( (char**)&buffer, (char*)&reply ,&size, dbBYTES256);
return(SUCCESS);
}

void Print()
{
cout << "Command: " << command << " - Reply: " << reply;
cout << endl;
}

};

#define NREF 6
vltBYTES8 cmdRef[NREF] =
{ "COMMENT","STATUS","SETUP","STOP","HELP","DISABLE"};
vltBYTES256 repRef = "Simulation reply OK !";

////////////////////////////////////
// main procedure //
////////////////////////////////////
int main(int, char *argv[])
{
/************/
/* Init */
/************/

ccsCOMPL_STAT stat,st;

eccsLogComment(
"ECCS test for database eccsDB_TABLE classes (access by contents");

eccsLogComment("Init");
stat = ccsInit(argv[0]);
eccsErrLog(stat,"Error in Init \n");

eccsLogComment("Open");
stat = dbOpen();
eccsErrLog(stat,"Error in Open\n");

/***********/
/* Body */
/***********/

vltINT32 recordCnt;

// ======== TABLE =========================================
// Define a TABLE
{
int i;
simREPLY_TABLE testRec;

cout << "\n===== Testing TABLE ======\n";

eccsDB_TABLE<simREPLY_TABLE> table("<alias>eccsTest:eccsTable.replies");
if ( table.ErrStatus() == FAILURE )
{
cout << "failure Invalid table" << endl;
exit(1);
}

// Get the number of records in the array
recordCnt = table.RecordCnt();
cout << "Table contains " << recordCnt << " records" << endl;


// Allocate the memory array
simREPLY_TABLE *table_array = new simREPLY_TABLE[recordCnt];

//Read all table
st = table.GetValue(table_array);

// Set values in memory
for ( i=0;i<recordCnt;i++)
{
strcpy((char*)table_array[i].command, (const char*)cmdRef[i%NREF]);
strcpy((char*)table_array[i].reply, (const char*)repRef);
}

// Rewrite whole table with changes
st = table.SetValue(table_array);

// Clean Memory
for ( i=0;i<recordCnt;i++)
{
strcpy((char*)table_array[i].command, "---");
strcpy((char*)table_array[i].reply, "---");
}

/* Print whole array */
cout << "Cleaned : " << endl;
for ( i=0;i<recordCnt;i++) table_array[i].Print();


/* Read random values and print contents */
cout << "Read values by contents: " << endl;

testRec = table["COMMENT"]; testRec.Print();
testRec = table["SETUP"]; testRec.Print();
testRec = table["STOP"]; testRec.Print();
testRec = table["DISABLE"]; testRec.Print();
testRec = table["HELP"]; testRec.Print();

testRec = table["WRONG"]; testRec.Print();

/* Write random values and reread to print contents */
cout << "Write values by contents: " << endl;

strcpy((char*)testRec.command,"NEWVAL");
strcpy((char*)testRec.reply,"A new reply");
table["STOP"] = testRec;

strcpy((char*)testRec.command,"---");
strcpy((char*)testRec.reply,"---");
testRec = table["NEWVAL"]; testRec.Print();

delete []table_array;
}


/***********/
/* Exit */
/***********/
stat = dbExit();
eccsErrLog(stat,"Error in Exit\n");
}

// __o0o__


6.7 DATABASE ACCESS TO TABLE COLUMNS USING eccsDB_VECTOR


/*******************************************************************************
* E.S.O. - VLT project
*
* "@(#) $Id: eccsTestVecTbl.C,v 1.107 1999/09/15 09:26:40 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 09/06/97 Creater from eccsTestVector.C
*/

/************************************************************************
* NAME
* eccsTestVecTbl - Test of "vector" like access to DB table columns
*
* SYNOPSIS
*
* DESCRIPTION
* The optional argument is the name of the environment to
* where the table is.
* This test uses the standard test database table:
*
* ":PARAMS:TABLES:full_table"
*
* with the following definition (dbl/CCS.db):
*
* ATTRIBUTE Table full_table (6,
* logical logical,
* int8 int8,
* uint32 uint32,
* float float,
* bytes4 string4,
* bytes32 string32 )
*
* It then:
* - saves the current values in the table, column by column
* - reads/writes new values in all columns
* - restores the original values before exiting
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/



#define _POSIX_SOURCE 1
#include "vltPort.h"



static char *rcsId="@(#) $Id: eccsTestVecTbl.C,v 1.107 1999/09/15 09:26:40 vltsccm Exp $";
static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId);

#include "eccsDB_VECTOR.h"

/*****************/
/* MAIN function */
/*****************/


int main(int argc, char *argv[])
{
/************/
/* Init */
/************/

ccsCOMPL_STAT stat,st;

eccsLogComment("ECCS test for database eccsDB_VECTOR classes:");
eccsLogComment(" Access to table columns as vectors.");

eccsLogComment("Init");
stat = ccsInit(argv[0]);
eccsErrLog(stat,"Error in Init ");

eccsLogComment("Open");
stat = dbOpen();
eccsErrLog(stat,"Error in Open");


/***********/
/* Body */
/***********/

vltINT32 recordCnt;

char tablePath[] = ":PARAMS:TABLES.full_table";
char baseAddr[256];

if (argc == 2)
sprintf(baseAddr, "@%s%s", argv[1], tablePath);
else
strcpy(baseAddr, tablePath);

// ======== Saving current table =========================================
// Allocate the DB vectors as table columns
eccsDB_VECTOR<vltLOGICAL> savLogical(eccsDB_TBL_COL,baseAddr,"logical");
eccsDB_VECTOR<vltINT8> savInt8(eccsDB_TBL_COL,baseAddr,"int8");
eccsDB_VECTOR<vltUINT32> savUint32(eccsDB_TBL_COL,baseAddr,"uint32");
eccsDB_VECTOR<vltFLOAT> savFloat(eccsDB_TBL_COL,baseAddr,"float");
eccsDB_VECTOR<vltBYTES4> savString4(eccsDB_TBL_COL,baseAddr,"string4");
eccsDB_VECTOR<vltBYTES32> savString32(eccsDB_TBL_COL,baseAddr,"string32");

// Allocate the memory vectors
recordCnt = savLogical.RecordCnt(); // The same for all

vltLOGICAL *savLogicalA = new vltLOGICAL[recordCnt];
vltINT8 *savInt8A = new vltINT8[recordCnt];
vltUINT32 *savUint32A = new vltUINT32[recordCnt];
vltFLOAT *savFloatA = new vltFLOAT[recordCnt];
vltBYTES4 *savString4A = new vltBYTES4[recordCnt];
vltBYTES32 *savString32A = new vltBYTES32[recordCnt];

// Read current values
st = SUCCESS;
errFlag(st, savLogical.GetValue(savLogicalA));
errFlag(st, savInt8.GetValue(savInt8A));
errFlag(st, savUint32.GetValue(savUint32A));
errFlag(st, savFloat.GetValue(savFloatA));
errFlag(st, savString4.GetValue(savString4A));
errFlag(st, savString32.GetValue(savString32A));

eccsErrLog(st,"Error in table reading");

// ======== Store new values in table ==============================

eccsLogComment("Writing new table by column:");
for(int i = 0; i < recordCnt; i++)
{
vltBYTES4 buf4;
vltBYTES32 buf32;

sprintf((char*)buf4, "%3.3d",i);
sprintf((char*)buf32, "Test: %3.3d",i);

savLogical[i] = 1;
savInt8[i] = i + 5;
savUint32[i] = i + 10;
savFloat[i] = i + 10.0 + i/10.0;
savString4[i] = buf4;
savString32[i] = buf32;
}


// ======== Retrieves new values in table ==============================
eccsLogComment("Reading and printing new table by column:");
for(int i = 0; i < recordCnt; i++)
{
/* IMPORTANT: you cannot put directly savString4[i]; in the printf() !!!! */
const vltBYTES4 &ref4 = savString4[i];
const vltBYTES32 &ref32 = savString32[i];

eccsLogComment(
"[%2.2d]: %-2.2d| %-6.6d| %-6.6d| %-6.2f| %-4.4s| %-32.32s|",
i,
(vltLOGICAL)savLogical[i],
(vltINT8)savInt8[i],
(vltUINT32)savUint32[i],
(vltFLOAT)savFloat[i],
ref4,
ref32
);
}

// ======== Store new values in table by whole col=====================
// Allocate the memory vectors
recordCnt = savLogical.RecordCnt(); // The same for all

vltLOGICAL *logicalA = new vltLOGICAL[recordCnt];
vltINT8 *int8A = new vltINT8[recordCnt];
vltUINT32 *uint32A = new vltUINT32[recordCnt];
vltFLOAT *floatA = new vltFLOAT[recordCnt];
vltBYTES4 *string4A = new vltBYTES4[recordCnt];
vltBYTES32 *string32A = new vltBYTES32[recordCnt];

// ======== Store new values in table ==============================

eccsLogComment("Filling table by column:");
for(int i = 0; i < recordCnt; i++)
{
vltBYTES4 buf4;
vltBYTES32 buf32;

sprintf((char*)buf4, "%3.3d",i+11);
sprintf((char*)buf32, "Test: %3.3d",i+11);

logicalA[i] = 1;
int8A[i] = i+11 + 5;
uint32A[i] = i+11 + 10;
floatA[i] = i+11 + 10.0 + i/10.0;
string4A[i] = buf4;
string32A[i] = buf32;
}


// Write current values
st = SUCCESS;
errFlag(st, savLogical.SetValue(logicalA));
errFlag(st, savInt8.SetValue(int8A));
errFlag(st, savUint32.SetValue(uint32A));
errFlag(st, savFloat.SetValue(floatA));
errFlag(st, savString4.SetValue(string4A));
errFlag(st, savString32.SetValue(string32A));

eccsErrLog(st,"Error in table writing");

// ======== Retrieves new values in table ==============================
eccsLogComment("Reading and printing new table by column:");
for(int i = 0; i < recordCnt; i++)
{
/* IMPORTANT: you cannot put directly savString4[i]; in the printf() !!!! */
const vltBYTES4 &ref4 = savString4[i];
const vltBYTES32 &ref32 = savString32[i];

eccsLogComment(
"[%2.2d]: %-2.2d| %-6.6d| %-6.6d| %-6.2f| %-4.4s| %-32.32s|",
i,
(vltLOGICAL)savLogical[i],
(vltINT8)savInt8[i],
(vltUINT32)savUint32[i],
(vltFLOAT)savFloat[i],
ref4,
ref32
);
}

// ======== Restore original table ========================================
st = SUCCESS;
errFlag(st, savLogical.SetValue(savLogicalA));
errFlag(st, savInt8.SetValue(savInt8A));
errFlag(st, savUint32.SetValue(savUint32A));
errFlag(st, savFloat.SetValue(savFloatA));
errFlag(st, savString4.SetValue(savString4A));
errFlag(st, savString32.SetValue(savString32A));

eccsErrLog(st,"Error in table restore");


/***********/
/* Exit */
/***********/
stat = dbExit();
eccsErrLog(stat,"Error in Exit");

} /* end main() */

/* __oOo__ */


6.8 ERROR HANDLING


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsSampErr.C,v 1.107 1999/09/15 09:26:33 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 15/12/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

/************************************************************************
* NAME
* eccsSampErr - ECCS error handling sample program
*
* SYNOPSIS
* eccsSampErr
*
* DESCRIPTION
* This sample ECCS program demonstrates some error handling features
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>


/*
* Local Headers
*/
#include "ECCS.h"
#include "eccsTestTools.h"



/*
* Function definition
*/
int main(int, char *argv[])
{
ccsCOMPL_STAT stat;

stat = ccsInit(argv[0]) ;
eccsErrExit(stat,"Error in Init \n");

stat = dbOpen();
eccsErrExit(stat,"Error in Open\n");


/*************************************************************/
/* In the following section we generate some run time errors */
/* using the database module */
/*************************************************************/

/* Activates loggin with eccsLog..() both on stdout AND log monitor */
eccsLogSave(TRUE);

vltFLOAT fvar;

/* Test using the standard error stack */
eccsLogComment("Reading from non existing DB point");

stat = dbRead(&fvar,"AAAA:PARAMS:SCALARS.scalar_uint32");
if(stat == FAILURE)
{
errAdd("eccs",eccsERR_GENERIC,__FILE_LINE__);
errPrint();
errResetStack();
}

/* Test using explicitly the standard error stack */
eccsLogComment("Reading with wrong parameters");

stat = dbRead((float *)NULL,"AAAA:PARAMS:SCALARS.scalar_uint32");
if(stat == FAILURE)
{
stdErr->Add("eccs",eccsERR_GENERIC,__FILE_LINE__);
stdErr->Print();
stdErr->Reset();
}

/* Test using a wrong dbBYTES type */
eccsLogComment("Writing with wrong size for dbBYTES ");

unsigned char str[14] = "Hello!";

stat = dbWrite(VLTBYTES(str),":PARAMS:SCALARS.scalar_string32");
if(stat == FAILURE)
{
errAdd("eccs",eccsERR_GENERIC,__FILE_LINE__);
errPrint();
errResetStack();
}


/* Test using a new specific error stack */
eccsLogComment("Reading with wrong parameters");

eccsERROR myErr;

stat = dbRead(&fvar,NULL,NULL,&myErr);
if(stat == FAILURE)
{
myErr.Add("eccs",eccsERR_GENERIC,__FILE_LINE__);
myErr.Print();
myErr.Reset();
}


#if 0
/* Displaying the result (asyncronous mode) */
eccsLogComment("Reading with wrong parameters");

stat = dbRead(&fvar,NULL,NULL,stdErr);
if(stat == FAILURE)
{
stdErr->Add("eccs",eccsERR_GENERIC,__FILE_LINE__);
stdErr->Print();
stdErr->Display();
stdErr->Reset();
}
#endif
/* Displaying the result (syncronous mode) */
eccsLogComment("Reading with wrong parameters");

stat = dbRead(&fvar,"AAAA:PARAMS:SCALARS.scalar_uint32");
if(stat == FAILURE)
{
stdErr->Add("eccs",eccsERR_GENERIC,__FILE_LINE__);
stdErr->Print();
stdErr->Display(TRUE);
stdErr->Reset();
}

/************* end of tests: exit in a clean way ************/

stat = dbExit();
eccsErrExit(stat,"Error in dbExit()\n");

stat = ccsExit();
eccsErrExit(stat,"Error in ccsExit()\n");

return 0;
}

/*___oOo___*/



6.9 DATABASE EVENTS


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsSampEvt.C,v 1.107 1999/09/15 09:26:40 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 16/09/94 created
*/

/************************************************************************
* NAME
* eccsSampEvt - ECCS database event handling sample program
*
* SYNOPSIS
* eccsSampEvt
*
* DESCRIPTION
* This sample ECCS program demonstrates some db event handling features
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>


/*
* Local Headers
*/
#include "ECCS.h"
#include "eccsTestTools.h"


/*
* Function definition
*/

void printEvent(evtEVENT_MSG &msg);

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

/* parameters must be handled better: use ParseArguments */
if ( argc != 2)
{
printf("usage: %s <attribute>\n",
argv[0]);
printf(" Program to monitor the value of an attribute\n");
printf(" on a specified environment\n");
exit(1);
}
/*
* Initialize CCS.
*/
stat = ccsInit(argv[0]);
eccsErrExit(stat,"Error in Init \n");

/*
* Attach the event
*/

evtEVENT evt(argv[1]);
evtEVENT_MSG msg;

evt.Attach();

/*
* Loop over database events.
* Exit only if the value of the monitored attribute becomes == 0
* (It is assumd that this program can receive only messages for
* database events)
*/
int flag = TRUE;

while(flag == TRUE)
{
msg.Receive();

printEvent(msg);

} /* end loop over db events */

/*
* end of work
*/

evt.Detach();

stat = ccsExit();
eccsErrExit(stat, "--> Error in ccsExit()");
}




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

void printEvent(evtEVENT_MSG &msg)
{
vltINT32 val;
printf("Received database event for attribute: %s\n",msg.AttrName() );

memcpy(&val,msg.EventInfo().scalar.newValue,sizeof(vltINT32));
printf("\t new value is: %d\n", val);
}


/*___oOo___*/


6.10 SENDING AND RECEIVING CCS MESSAGES


/*******************************************************************************
* E.S.O. - VLT project
#
# "@(#) $Id: eccsSampMsgMaster.C,v 1.107 1999/09/15 09:26:34 vltsccm Exp $"
*
* who when what
* -------- -------- ----------------------------------------------
* gchiozzi 16/09/94 created
* gchiozzi 18/01/95 cleanup and changed file names to be compliant with
* VLT rules. Moved inline code in .icc files
*/

/************************************************************************
* NAME
* eccsSampMsgMaster - ECCS message system's features sample program
*
* SYNOPSIS
* eccsSampMsgMaster <process name> <env> <command> ...<cmd args>...
*
* DESCRIPTION
* This ECCS example send a command to a process on a given environment
* and waits for replies.
*
* FILES
*
* ENVIRONMENT
*
* RETURN VALUES
*
* CAUTIONS
*
* EXAMPLES
*
* SEE ALSO
*
* BUGS
*
*------------------------------------------------------------------------
*/

#define _POSIX_SOURCE 1
#include "vltPort.h"

/*
* System Headers
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>


/*
* Local Headers
*/
#include "ECCS.h"
#include "eccsTestTools.h"


/*
* Function definition
*/

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

/* parameters must be handled better: use ParseArguments */
if ( argc < 4)
{
printf("usage: %s <process name> <env> <command> ...<cmd args>...\n",
argv[0]);
printf(" Program to send commands.:\n");
printf(" Companion process perfMsgSlave responds to commands:\n");
printf(" REPLY nrep size = gives nrep replies of size bytes\n");
printf(" QUIT = called replies and exits\n");
printf(" KILL/BREAK if <environment> supports these commands\n");
printf(" anything else gives error reply\n");
exit(1);
}
/*
* Initialize CCS.
*/
stat = ccsInit(argv[0]);
eccsErrExit(stat,"Error in Init \n");

/*
* Send the command
*/
msgMESSAGE cmd;
char buffer[80];

msgCMD pippo;
strcpy(pippo,argv[3]);
cmd.Command(pippo);
cmd.Destenv(argv[2]);
cmd.Destproc(argv[1]);

/* Verify arguments and send a request for REPLY command */
if (strcmp((const char *)cmd.Command(),"REPLY") == 0)
{
sprintf(buffer,"%s %s", argv[4], argv[5]);
if( argc != 6)
{
printf("REPLY command needs nrep and size parameters\n");
exit(1);
}
}
/* Send any other command */
else
sprintf(buffer,"No parameters");

cmd.Buffer(buffer);
stat = msgSendCommand ( &cmd );
eccsErrExit(stat, "--> Error in msgSendCommand");

/*
* loop on replies
*/

/* Log a message */
if(argc >4 && atoi(argv[4]) > 0)
eccsLogComment("Waiting for reply ...");

msgMESSAGE reply;
int repCount = 0;

reply.LastReply(ccsFALSE);

/* Loop to receive replies up to the last one */
while(reply.LastReply() == ccsFALSE)
{
repCount++;

/* Receive the queued reply */
stat = msgRecvMsg(&reply);
eccsErrExit(stat,"--> Error in msgRecvMsg");

/* The received message MUST be a reply */
if (reply.Type() == msgTYPE_REPLY)
{
/* Print the received reply and its ordinal number */
if (reply.LastReply() == ccsFALSE)
eccsLogComment("Reply n. %4.4d (more), %4.4d bytes - %s",
repCount, reply.Buflen(), reply.Buffer());
else
eccsLogComment("Reply n. %4.4d (last), %4.4d bytes - %s",
repCount, reply.Buflen(), reply.Buffer());
}
/* If the message is not a true reply can be an error reply */
else if (reply.Type() == msgTYPE_ERROR_REPLY)
{
eccsLogComment("Received error reply");
eccsLogComment(" env = %s",reply.Errmsg().envName);
eccsLogComment(" stackId = %d",reply.Errmsg().stackId.id);
eccsLogComment(" seqnum = %d",reply.Errmsg().sequenceNumber);
eccsLogComment(" modId = %s",reply.Errmsg().moduleId);
eccsLogComment(" errnum = %d",reply.Errmsg().errorNumber);
eccsLogComment(" location = %s",reply.Errmsg().location);
eccsLogComment(" runTimePar = %s",reply.Errmsg().runTimePar);
}
/* any other message is unexpected */
else
{
eccsLogComment("Received unexpected msg type %d",reply.Type());
}

} /* end loop on reply */

/* end of work */
stat = ccsExit();
eccsErrExit(stat, "--> Error in ccsExit()");
}

/*___oOo___*/


7 SAMPLE eccsTestDriver FILES

This chapter contains some examples of files used by the eccsTestDriver tool to define a test environment for programs.

7.1 TESTLIST

The TESTLIST file contains a list of the tests to be executed.

Command line options of eccsTestDriver defines which tests among these are actually esecuted when the program is called.


###################################################################
#
# ECCS TESTLIST
#
# Following is a list of test programs that are called
# sequencially.
# When two programs are specified the first one is treated
# as a server and started in the background.
#
# !!! NOTE currently only a maximum of two programs are supported
#
# Following actions are performed:
#
# - Program is started with output redirected into file.
# - If two programs are specified the output is merged.
# - The timestamp is striped off the output
# - The output is compared with the reference output <program>.REF
# - If difference are found the are listed in <program>.diff
#
#
###################################################################
#
# Test the main engine for eccs
#

1 eccsTest1 eccsTest1
2 eccsTestDb eccsTestDb
3 eccsTestErr eccsTestErr
4 eccsTestEvt eccsTestEvt
5 eccsTestLog eccsTestLog
6 eccsTestDB_ATTR eccsTestDB_ATTR
7 eccsTestCLASS_ERROR eccsTestCLASS_ERROR
8 eccsTestOBJ_STATUS eccsTestOBJ_STATUS
9 eccsTestMsg eccsTestMsg_bis eccsTestMsg
10 eccsTestVector eccsTestVector
11 eccsTestTable eccsTestTable
12 eccsTestTable_2 eccsTestTable_2
13 eccsTestTrc "@SLEEP 3" eccsTestTrc_bis "@SLEEP 5" eccsTestTrc
14 eccsTestBigLog eccsTestBigLog
15 eccsTestEvtIdMap eccsTestEvtIdMap
16 eccsTestAlarm eccsTestAlarm eccsTestAlarm.sh
17 eccsTestSpr960215 eccsTestSpr960215
18 eccsTestParseTarget eccsTestParseTarget
19 eccsTestVecTbl eccsTestVecTbl
20 eccsTestTIMEVAL eccsTestTIMEVAL
21 eccsTestEvtLcu "eccsTestWrap.sh eccsTestEvt"

# This test currently shows a problem in dbGetAttrInfo(). See spr. 980404
22 eccsTestVecTblLcu "eccsTestWrap.sh eccsTestVecTbl"

# Test for spr.980224
23 eccsTestErrMsg eccsTestErrMsg eccsTestErrMsg.sh

#___o0o___


7.2 TestDriver.grep

This file contains regular expressions used by eccsTestDriver to filter the output of the programs under test, in order to strip all the lines that can change from run to run of the test program.

Each record in the file contain a regular expression.

Every line in the output of the test programs matching any of the given regular expressions is discarded.

In the following example, every line containing the string "StackId" will be discarded, since the stack id of an error message varies on every run of a program.

-->BEGIN IMPORTED FILE: ../test/TestDriver.grep (95/8/2 19: 5)

StackId



7.3 TestDriver.sed

This file contains sed commands used by eccsTestDriver to filter the output of the programs under test, in order to cleanup all the expressions that can change from run to run of the test program.

Each record in the file contain a sed command.

Sed is run on the output of the programs under test passing this file as a command file.

In the following example, variable strings like names of environments and stack ids are replaced with the `-' character.


-->BEGIN IMPORTED FILE: ../test/TestDriver.sed (95/8/2 19: 5)


s/[lw]te[0-9][0-9]../-te----/g
s/StackId : [ 0-9][ 0-9][ 0-9][ 0-9][ 0-9][ 0-9]/StackId : ---- /g
s/signal: [ 0-9][ 0-9]/signal: --/g





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