/******************************************************************************* * ALMA - Atacama Large Millimiter Array * Copyright (c) European Southern Observatory, 2011 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * "@(#) $Id: cdbCCS.cpp,v 1.28 2011/10/28 15:05:05 hsommer Exp $" * * who when what * -------- -------- ---------------------------------------------- * almadev 2011-10-28 created */ // // CCS wrapper for the VLT standard database // // ************************************************************************ #include // include only macros #include #include "ccs.h" #include "db.h" #include "string.h" #include "cdbCCS.h" #include #ifndef MAKE_VXWORKS #include "dbPrivate.h" #else #include "lccErrors.h" #define dbUNDEFINED_SIZE 0 typedef struct { dbTYPE type; /* data type */ const char *mnemonic; /* mnemonic of data type */ vltUINT16 size; /* size of data type */ } dbTYPES; static const dbTYPES dbTypes[] = { {dbUNDEFINED, "", dbUNDEFINED_SIZE }, {dbLOGICAL, "dbLOGICAL", sizeof(vltLOGICAL) }, {dbINT8, "dbINT8", sizeof(vltINT8) }, {dbUINT8, "dbUINT8", sizeof(vltUINT8) }, {dbINT16, "dbINT16", sizeof(vltINT16) }, {dbUINT16, "dbUINT16", sizeof(vltUINT16) }, {dbINT32, "dbINT32", sizeof(vltINT32) }, {dbUINT32, "dbUINT32", sizeof(vltUINT32) }, {dbFLOAT, "dbFLOAT", sizeof(vltFLOAT) }, {dbDOUBLE, "dbDOUBLE", sizeof(vltDOUBLE) }, {dbPOLAR, "dbPOLAR", sizeof(vltPOLAR) }, {dbRECTANGULAR, "dbRECTANGULAR", sizeof(vltRECTANGULAR)}, {dbUNDEFINED, "", dbUNDEFINED_SIZE }, {dbUNDEFINED, "", dbUNDEFINED_SIZE }, {dbUNDEFINED, "", dbUNDEFINED_SIZE }, {dbUNDEFINED, "", dbUNDEFINED_SIZE }, {dbBYTES4, "dbBYTES4", sizeof(vltBYTES4) }, {dbBYTES8, "dbBYTES8", sizeof(vltBYTES8) }, {dbBYTES12, "dbBYTES12", sizeof(vltBYTES12) }, {dbBYTES16, "dbBYTES16", sizeof(vltBYTES16) }, {dbBYTES20, "dbBYTES20", sizeof(vltBYTES20) }, {dbBYTES32, "dbBYTES32", sizeof(vltBYTES32) }, {dbBYTES48, "dbBYTES48", sizeof(vltBYTES48) }, {dbBYTES64, "dbBYTES64", sizeof(vltBYTES64) }, {dbBYTES80, "dbBYTES80", sizeof(vltBYTES80) }, {dbBYTES128, "dbBYTES128", sizeof(vltBYTES128) }, {dbBYTES256, "dbBYTES256", sizeof(vltBYTES256) }, {dbUNDEFINED, "", dbUNDEFINED_SIZE }, {dbXREF, "dbXREF", sizeof(vltDBXREF) }, {dbDATE, "dbDATE", sizeof(vltDATE) }, {dbTIME_OF_DAY, "dbTIME_OF_DAY", sizeof(vltTIME_OF_DAY)}, {dbABS_TIME, "dbABS_TIME", sizeof(vltABS_TIME) } }; #endif #include "err.h" #include "log.h" static char *rcsId="@(#) $Id: cdbCCS.cpp,v 1.28 2011/10/28 15:05:05 hsommer Exp $"; static void *use_rcsId = ((void)&use_rcsId,(void *) &rcsId); namespace cdb { Table* CCS::createTable( int argc, char** argv, CORBA::ORB_ptr orb) { const char* pProcess = ""; if( argc > 0 ) pProcess = argv[0]; return new CCS( pProcess ); } CCS::CCS(String process) : isInit(FALSE) { ccsERROR error; if (ccsInit(process.c_str(),0,NULL,NULL,&error)==FAILURE) { #ifndef MAKE_VXWORKS ACS_LOG (LM_RUNTIME_CONTEXT, "cdb::CCS::CCS", (LM_ERROR, "Error %d occured trying to initialize database", error.errorNumber)); #else if (error.errorNumber == lccERR_IN_USE) { isInit=TRUE; } else { ACS_LOG (LM_RUNTIME_CONTEXT, "cdb::CCS::CCS", (LM_ERROR, "Error %d occured trying to initialize database", error.errorNumber)); errCloseStack(&error); } #endif } else isInit=TRUE; } CCS::~CCS() { ccsERROR error; errResetStack(&error); if (ccsExit(&error)==FAILURE) { ACS_LOG (LM_RUNTIME_CONTEXT, "cdb::CCS::~CCS", (LM_ERROR, "Error %d occured trying to close database", error.errorNumber)); errCloseStack(&error); } } Boolean CCS::CreateRecord(const String &strRecordName, Boolean bTruncate) { ACE_UNUSED_ARG(strRecordName); ACE_UNUSED_ARG(bTruncate); return FALSE; } ULong CCS::GetRecordState(const String &strRecordName) { ACE_UNUSED_ARG(strRecordName); return CDB_RECORD_READABLE | CDB_RECORD_WRITABLE; } /****************************************************/ /* procedure used to get data from the CCS database */ /****************************************************/ Boolean CCS::GetField(const String &strRecordName, const String &strFieldName, Field &fld) { ACE_Guard guard(cdbMutex); dbSYMADDRESS pointName; dbATTRIBUTE attrName; dbTYPE dataType[dbMAX_FIELD_CNT]; char buffer[10000]; int i,j,totField; vltINT32 actual; vltUINT16 recordCnt; dbATTRTYPE attrType; ccsERROR error; unsigned char flag; /* cast to rtLOGICAL datatype */ unsigned char c; short s; long l; float f; double d; char string[257],*pBuf; ShortArray shortArray; OctetArray octetArray; StringArray stringArray; DoubleArray doubleArray; FloatArray floatArray; LongArray longArray; ULongArray uLongArray; UShortArray uShortArray; errResetStack(&error); strcpy((char *) pointName,strRecordName.c_str()); strcpy((char *) attrName,strFieldName.c_str()); if ( dbReadSymbolic(pointName,attrName,dataType, buffer,sizeof(buffer), &actual,&recordCnt,&attrType,&error) == FAILURE ) { char errmsg[256]; errmsg[0] = 0; switch (error.errorNumber) { #ifndef MAKE_VXWORKS case ccsERR_DB_INV_NAME: ACE_OS::strcpy(errmsg, "Invalid point, attribute or alias name"); break; case ccsERR_DB_READ: ACE_OS::strcpy(errmsg, "Generic failure during reading"); break; case ccsERR_DB_LCU: ACE_OS::strcpy(errmsg, "Failure during access to a LCU"); break; case ccsERR_DB_QUALITY: ACE_OS::strcpy(errmsg, "Bad data quality"); break; case ccsERR_NULL_PTR: ACE_OS::strcpy(errmsg, "In case of NULL pointer in input parameters"); break; case ccsERR_BUFF_SIZE: ACE_OS::strcpy(errmsg, "Buffer size too small"); break; case ccsERR_DB_NO_RTAP: ACE_OS::strcpy(errmsg, "Failure when calling RTAP with CCS LITE"); break; case ccsERR_DB_CATEGORY: ACE_OS::strcpy(errmsg, "Category mismatch"); break; case ccsERR_DB_GROUP: ACE_OS::strcpy(errmsg, "Group mismatch"); break; case ccsERR_DB_INV_RECEL: ACE_OS::strcpy(errmsg, "nvalid record/element in address"); break; case ccsERR_DB_INV_FIELD: ACE_OS::strcpy(errmsg, "Invalid field specifier in address"); break; case ccsERR_ENV_NOT_ACTIVE: ACE_OS::strcpy(errmsg, "Environment is not active"); break; case ccsERR_REMOTE_LINK: ACE_OS::strcpy(errmsg, "The DB is unreacheable"); break; case ccsERR_DB_OPEN: ACE_OS::strcpy(errmsg, "DB can not be opened"); break; #else case lccERR_BUF_SIZE: ACE_OS::strcpy(errmsg, "Buffer size too small"); break; case lccERR_NOT_FOUND: ACE_OS::strcpy(errmsg, "Invalid point, attribute or alias name"); break; case lccERR_ATTRIBUTE: ACE_OS::strcpy(errmsg, "Invalid attribute name"); break; case lccERR_POINT: ACE_OS::strcpy(errmsg, "Invalid point name"); break; case lccERR_INV_NAME: ACE_OS::strcpy(errmsg, "Invalid point, attribute or alias name"); break; case lccERR_DE_TYPE: ACE_OS::strcpy(errmsg, "Invalid data type"); break; case lccERR_ATTR_TYPE: ACE_OS::strcpy(errmsg, "Invalid attribute type"); break; case lccERR_INV_RECEL: ACE_OS::strcpy(errmsg, "Invalid record/element in address"); break; #endif default: ACE_OS::strcpy(errmsg, "Unknown error in reading CDB"); } ACS_LOG (LM_RUNTIME_CONTEXT, "cdb::CCS::GetField", (LM_NOTICE, "Error reading '%s.%s' : %s", pointName, attrName, errmsg)); errCloseStack(&error); return FALSE; } i=0; pBuf = (char *)buffer; totField = 0; while (dataType[totField] != dbUNDEFINED) totField++; for (j=0; j guard(cdbMutex); dbATTRTYPE attrType; dbTYPE dataType[dbMAX_FIELD_CNT]; ccsERROR error; unsigned int i,j,totRec; vltINT32 actual,bufSize; vltUINT32 recSize; vltUINT16 recCnt,/*startRec,endRec,*/recsUsed; vltUINT8 fieldCnt/*,startField,endField*/; Short cs; UShort us; ULong ul; Boolean bf; unsigned char flag; /* cast to rtLOGICAL datatype */ unsigned char c; short s; long l; float f; double d; /* Field::Type fieldType; ccsTIMEVAL myTime; vltPOLAR myPolar; vltRECTANGULAR myRec; vltDBXREF myXref; */ String string; StringArray stringArray; OctetArray octetArray; ShortArray shortArray; LongArray longArray; UShortArray uShortArray; ULongArray uLongArray; FloatArray floatArray; DoubleArray doubleArray; char userBuf[10000],*pBuf; char str[256]; ACE_UNUSED_ARG(bCreate); errResetStack(&error); /**************************************** * Check if attribute name is correct * * and get type of data * *****************************************/ if (dbGetAttrInfo(strRecordName.c_str(),strFieldName.c_str(),&attrType, &fieldCnt,&recCnt,&recSize, &recsUsed,dataType,&error) == FAILURE) goto exit; /* Parameter Initialization according to the data type */ /* if (dbParseIndex(strFieldName,attrType,fieldCnt,recCnt, &startRec,&endRec,&startField, &endField) == FAILURE) goto exit; */ //ACS_SHORT_LOG((LM_DEBUG, "fieldCnt: %d, recCnt: %d, recSize: %d.", fieldCnt, recCnt, recSize)); totRec = recCnt; // totRec = endRec - startRec +1; pBuf = userBuf; /************************************ * Prepare buffer to be written * ************************************/ bufSize = 0; for (j=0; j