diff --git a/src/gdd/gdd.cc b/src/gdd/gdd.cc index 1b3277a16..18403bafa 100644 --- a/src/gdd/gdd.cc +++ b/src/gdd/gdd.cc @@ -4,6 +4,9 @@ // $Id$ // // $Log$ +// Revision 1.10 1996/08/23 20:29:36 jbk +// completed fixes for the aitString and fixed string management +// // Revision 1.9 1996/08/22 21:05:40 jbk // More fixes to make strings and fixed string work better. // @@ -70,6 +73,23 @@ gdd_NEWDEL_NEW(gdd) gdd_NEWDEL_DEL(gdd) gdd_NEWDEL_STAT(gdd) +// -------------------------- Error messages ------------------------- + +char* gddErrorMessages[]= +{ + "Invalid", + "TypeMismatch", + "NotAllowed", + "AlreadyDefined", + "NewFailed", + "OutOfBounds", + "AtLimit", + "NotDefined", + "NotSupported", + "Overflow", + "Underflow" +}; + // --------------------------The gddBounds functions------------------- // gddBounds::gddBounds(void) { first=0; count=0; } @@ -246,7 +266,10 @@ gddStatus gdd::registerDestructor(gddDestructor* dest) { // this is funky, will not register a destructor if one is present if(destruct) + { + gddAutoPrint("gdd::registerDestructor()",gddErrorAlreadyDefined); return gddErrorAlreadyDefined; + } else return replaceDestructor(dest); } @@ -275,7 +298,10 @@ gddStatus gdd::genCopy(aitEnum t, const void* d) { sz=describedDataSizeBytes(); if((buf=new aitInt8[sz])==NULL) + { + gddAutoPrint("gdd::genCopy()",gddErrorNewFailed); rc=gddErrorNewFailed; + } else { setData(buf); @@ -289,7 +315,10 @@ gddStatus gdd::genCopy(aitEnum t, const void* d) getDataSizeElements()); } else + { + gddAutoPrint("gdd::genCopy()",gddErrorTypeMismatch); rc=gddErrorTypeMismatch; + } return rc; } @@ -308,7 +337,10 @@ gddStatus gdd::changeType(int app,aitEnum prim) setPrimType(prim); } else + { + gddAutoPrint("gdd::changeType()",gddErrorTypeMismatch); rc=gddErrorTypeMismatch; + } return rc; } @@ -319,7 +351,10 @@ gddStatus gdd::setBound(unsigned index_dim, aitIndex first, aitIndex count) if(index_dimgetData(); // copy the data reference @@ -860,7 +904,10 @@ gddStatus gdd::convertAddressToOffsets(void) // does not ensure that all the members of a container are flat! if(!isFlat()) + { + gddAutoPrint("gdd::convertAddressToOffsets()",gddErrorNotAllowed); return gddErrorNotAllowed; + } if(isContainer()) { @@ -920,7 +967,10 @@ gddStatus gdd::clearData(void) gddStatus rc=0; if(isContainer()) + { + gddAutoPrint("gdd::clearData()",gddErrorNotAllowed); rc=gddErrorNotAllowed; + } else { if(destruct) @@ -937,7 +987,10 @@ gddStatus gdd::clearData(void) gddStatus gdd::clear(void) { if(isFlat()||isManaged()) + { + gddAutoPrint("gdd::clear()",gddErrorNotAllowed); return gddErrorNotAllowed; + } if(isAtomic()) { @@ -983,7 +1036,10 @@ gddStatus gdd::reset(aitEnum prim, int dimen, aitIndex* cnt) gddStatus rc; if(isFlat()||isManaged()||isContainer()) + { + gddAutoPrint("gdd::reset()",gddErrorNotAllowed); return gddErrorNotAllowed; + } app=applicationType(); @@ -1058,7 +1114,7 @@ void gdd::getConvert(aitFixedString& d) get(aitEnumFixedString,d.fixed_string); } -gddStatus gdd::put(aitString d) +gddStatus gdd::put(const aitString& d) { gddStatus rc=0; if(isScalar()) @@ -1068,13 +1124,34 @@ gddStatus gdd::put(aitString d) setPrimType(aitEnumString); } else + { + gddAutoPrint("gdd::put(aitString&)",gddErrorNotAllowed); rc=gddErrorNotAllowed; + } + + return rc; +} + +gddStatus gdd::put(aitString& d) +{ + gddStatus rc=0; + if(isScalar()) + { + aitString* s=(aitString*)dataAddress(); + *s=d; + setPrimType(aitEnumString); + } + else + { + gddAutoPrint("gdd::put(aitString&)",gddErrorNotAllowed); + rc=gddErrorNotAllowed; + } return rc; } // this is dangerous, should the fixed string be copied here? -gddStatus gdd::put(aitFixedString& d) +gddStatus gdd::put(const aitFixedString& d) { gddStatus rc=0; @@ -1094,7 +1171,7 @@ gddStatus gdd::put(aitFixedString& d) return rc; } -void gdd::putConvert(aitString d) +void gdd::putConvert(const aitString& d) { if(primitiveType()==aitEnumInt8 && dim==1) { @@ -1105,10 +1182,10 @@ void gdd::putConvert(aitString d) cp[len]='\0'; } else - set(aitEnumString,&d); + set(aitEnumString,(aitString*)&d); } -void gdd::putConvert(aitFixedString& d) +void gdd::putConvert(const aitFixedString& d) { if(primitiveType()==aitEnumInt8 && dim==1) { @@ -1119,7 +1196,7 @@ void gdd::putConvert(aitFixedString& d) cp[len]='\0'; } else - set(aitEnumFixedString,d.fixed_string); + set(aitEnumFixedString,(void*)d.fixed_string); } // copy each of the strings into this DDs storage area @@ -1140,7 +1217,10 @@ gddStatus gdd::put(const aitFixedString* const d) else genCopy(aitEnumFixedString,d); else + { + gddAutoPrint("gdd::put(const aitFixedString*const)",gddErrorNotAllowed); rc=gddErrorTypeMismatch; + } return rc; } @@ -1151,7 +1231,10 @@ gddStatus gdd::put(const gdd* dd) // bail out quickly is either dd is a container if(isContainer() || dd->isContainer()) + { + gddAutoPrint("gdd::put(const gdd*)",gddErrorNotSupported); return gddErrorNotSupported; + } if(!aitConvertValid(primitiveType())) { @@ -1221,7 +1304,10 @@ gddStatus gdd::put(const gdd* dd) // which marks it flat if(isFlat()) + { + gddAutoPrint("gdd::put(const gdd*)",gddErrorNotAllowed); rc=gddErrorNotAllowed; + } else { // convert it to a scalar - is this OK to do? @@ -1240,16 +1326,25 @@ gddStatus gdd::put(const gdd* dd) if(dataPointer()==NULL) { if(destruct) + { + gddAutoPrint("gdd::put(const gdd*)",gddErrorNotAllowed); rc=gddErrorNotAllowed; + } else rc=copyData(dd); // is this the correct thing to do? } else if(dd->getDataSizeElements()>getDataSizeElements()) + { + gddAutoPrint("gdd::put(const gdd*)",gddErrorOutOfBounds); rc=gddErrorOutOfBounds; + } else { if(dd->dimension()>1) + { + gddAutoPrint("gdd::put(const gdd*)",gddErrorNotSupported); rc=gddErrorNotSupported; + } else { aitUint8* arr = (aitUint8*)dataPointer(); @@ -1277,7 +1372,10 @@ gddStatus gdd::copyData(const gdd* dd) gddStatus rc=0; if(isFlat() || isManaged() || isContainer()) + { + gddAutoPrint("gdd::copyData(const gdd*)",gddErrorNotAllowed); rc=gddErrorNotAllowed; + } else { if((rc=clear())==0) @@ -1296,7 +1394,10 @@ gddStatus gdd::copyData(const gdd* dd) setData(arr); } else + { + gddAutoPrint("gdd::copyData(const gdd*)",gddErrorNewFailed); rc=gddErrorNewFailed; + } } } return rc; @@ -1328,7 +1429,10 @@ gddStatus gddAtomic::getBoundingBoxSize(aitUint32* b) if(dimension()>0) for(i=0;i0) for(i=0;i0) for(i=0;i0) for(i=0;i1) rc=gddErrorNotAllowed; + if(ref_cnt>1) + { + gddAutoPrint("gdd::noReferencing()",gddErrorNotAllowed); + rc=gddErrorNotAllowed; + } else flags|=GDD_NOREF_MASK; return rc; } @@ -685,12 +694,17 @@ inline gddStatus gdd::reference(void) { int rc=0; - if(isNoRef()) rc=gddErrorNotAllowed; + if(isNoRef()) + { + gddAutoPrint("gdd::reference()",gddErrorNotAllowed); + rc=gddErrorNotAllowed; + } else ref_cnt++; if(ref_cnt>((1u<<(sizeof(ref_cnt)*CHAR_BIT))-2u)) { fprintf(stderr,"gdd reference count overflow!!\n"); + gddAutoPrint("gdd::reference()",gddErrorOverflow); rc=gddErrorOverflow; } return rc; @@ -703,6 +717,7 @@ inline gddStatus gdd::unreference(void) if(ref_cnt==0u) { fprintf(stderr,"gdd reference count underflow!!\n"); + gddAutoPrint("gdd::unreference()",gddErrorUnderflow); rc=gddErrorUnderflow; } else if(--ref_cnt<=0u) @@ -712,6 +727,7 @@ inline gddStatus gdd::unreference(void) // managed dd always destroys the entire thing ref_cnt=1; if(destruct) destruct->run(this); + destruct=NULL; } else if(!isFlat()) delete this; @@ -894,55 +910,55 @@ inline gddStatus gdd::put(const aitInt8* const d) inline gddStatus gdd::put(aitFloat64 d) { gddStatus rc=0; if(isScalar()) { data.Float64=d; setPrimType(aitEnumFloat64); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitFloat32 d) { gddStatus rc=0; if(isScalar()) { data.Float32=d;setPrimType(aitEnumFloat32); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitUint32 d) { gddStatus rc=0; if(isScalar()) { data.Uint32=d; setPrimType(aitEnumUint32); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitInt32 d) { gddStatus rc=0; if(isScalar()) { data.Int32=d; setPrimType(aitEnumInt32); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitUint16 d) { gddStatus rc=0; if(isScalar()) { data.Uint16=d; setPrimType(aitEnumUint16); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitInt16 d) { gddStatus rc=0; if(isScalar()) { data.Int16=d; setPrimType(aitEnumInt16); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitUint8 d) { gddStatus rc=0; if(isScalar()) { data.Uint8=d; setPrimType(aitEnumUint8); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitInt8 d) { gddStatus rc=0; if(isScalar()) { data.Int8=d; setPrimType(aitEnumInt8); } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } inline gddStatus gdd::put(aitType* d) { gddStatus rc=0; if(isScalar()) { data=*d; } - else rc=gddErrorNotAllowed; + else { rc=gddErrorNotAllowed; gddAutoPrint("gdd:put()",rc); } return rc; } @@ -1072,7 +1088,9 @@ inline gdd& gdd::operator=(aitUint8 d) { data.Uint8=d; setPrimType(aitEnumUint8); return *this; } inline gdd& gdd::operator=(aitInt8 d) { data.Int8=d; setPrimType(aitEnumInt8); return *this; } -inline gdd& gdd::operator=(aitString d) +inline gdd& gdd::operator=(aitString& d) + { put(d); return *this; } +inline gdd& gdd::operator=(const aitString& d) { put(d); return *this; } // ------------- primitive type pointer = gdd x functions -------------- @@ -1177,14 +1195,24 @@ protected: // disallow const gddBounds* getBounds(void) { return NULL; } - gddStatus getBoundingBoxSize(aitUint32*) { return gddErrorNotAllowed; } - gddStatus setBoundingBoxSize(const aitUint32* const) - { return gddErrorNotAllowed; } - gddStatus getBoundingBoxOrigin(aitUint32*) { return gddErrorNotAllowed; } - gddStatus setBoundingBoxOrigin(const aitUint32* const) - { return gddErrorNotAllowed; } - gddStatus setBound(int,aitIndex,aitIndex) { return gddErrorNotAllowed; } - gddStatus getBound(int,aitIndex&,aitIndex&) { return gddErrorNotAllowed; } + gddStatus getBoundingBoxSize(aitUint32*) { + gddAutoPrint("gddScalar::getBoundingBoxSize()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus setBoundingBoxSize(const aitUint32* const) { + gddAutoPrint("gddScalar::setBoundingBoxSize()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus getBoundingBoxOrigin(aitUint32*) { + gddAutoPrint("gddScalar::getBoundingBoxOrigin()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus setBoundingBoxOrigin(const aitUint32* const) { + gddAutoPrint("gddScalar::setBoundingBoxOrigin()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus setBound(int,aitIndex,aitIndex) { + gddAutoPrint("gddScalar::setBound()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus getBound(int,aitIndex&,aitIndex&) { + gddAutoPrint("gddScalar::getBound()",gddErrorNotAllowed); + return gddErrorNotAllowed; } // disallow void adjust(aitFloat64* const, gddDestructor*) { } @@ -1236,9 +1264,15 @@ protected: ~gddContainer(void) { } void cInit(int num_things_within); - gddStatus changeType(int,aitEnum) { return gddErrorNotAllowed; } - gddStatus setBound(int,aitIndex,aitIndex) { return gddErrorNotAllowed; } - gddStatus getBound(int,aitIndex&,aitIndex&) { return gddErrorNotAllowed; } + gddStatus changeType(int,aitEnum) { + gddAutoPrint("gddContainer::changeType()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus setBound(int,aitIndex,aitIndex) { + gddAutoPrint("setBound()",gddErrorNotAllowed); + return gddErrorNotAllowed; } + gddStatus getBound(int,aitIndex&,aitIndex&) { + gddAutoPrint("getBound()",gddErrorNotAllowed); + return gddErrorNotAllowed; } gddStatus setBound(aitIndex,aitIndex); private: diff --git a/src/gdd/gddAppDefs.cc b/src/gdd/gddAppDefs.cc index 154c9d06a..9f86f13f0 100644 --- a/src/gdd/gddAppDefs.cc +++ b/src/gdd/gddAppDefs.cc @@ -4,6 +4,9 @@ // $Id$ // // $Log$ +// Revision 1.5 1996/08/22 21:05:42 jbk +// More fixes to make strings and fixed string work better. +// // Revision 1.4 1996/08/06 19:14:13 jbk // Fixes to the string class. // Changes units field to a aitString instead of aitInt8. @@ -51,7 +54,7 @@ void gddApplicationTypeTable::GenerateTypes(void) // Just describe the menu - allow the block of choiced to be // referenced in. - gddAtomic* add_enum = new gddAtomic(0,aitEnumFixedString,1,16); + // gddAtomic* add_enum = new gddAtomic(0,aitEnumFixedString,1,16); // ---------------------------------------------------------------- // register simple types @@ -86,7 +89,7 @@ void gddApplicationTypeTable::GenerateTypes(void) int type_units=registerApplicationTypeWithProto(GDD_NAME_UNITS,add_units); // old menu method - // int type_menu=registerApplicationTypeWithProto(GDD_NAME_ENUM,add_enum); + // int type_menu=registerApplicationType(GDD_NAME_ENUM); // ---------------------------------------------------------------- // register container types - not as easy @@ -150,8 +153,8 @@ void gddApplicationTypeTable::GenerateTypes(void) // DBR_GR_ENUM gddContainer* cdd_gr_enum=new gddContainer(0); - // old menu method: cdd_gr_enum->insert(getDD(type_menu)); - cdd_gr_enum->insert(new gddAtomic(type_menu,aitEnumFixedString,1)); + // old: cdd_gr_enum->insert(new gddAtomic(type_menu,aitEnumFixedString,1)); + cdd_gr_enum->insert(getDD(type_menu)); cdd_gr_enum->insert(new gddScalar(type_value,aitEnumEnum16)); registerApplicationTypeWithProto("dbr_gr_enum",cdd_gr_enum); @@ -223,8 +226,8 @@ void gddApplicationTypeTable::GenerateTypes(void) // DBR_CTRL_ENUM gddContainer* cdd_ctrl_enum=new gddContainer(0); - // old method: cdd_ctrl_enum->insert(getDD(type_menu)); - cdd_ctrl_enum->insert(new gddAtomic(type_menu,aitEnumFixedString,1)); + //old:cdd_ctrl_enum->insert(new gddAtomic(type_menu,aitEnumFixedString,1)); + cdd_ctrl_enum->insert(getDD(type_menu)); cdd_ctrl_enum->insert(new gddScalar(type_value,aitEnumEnum16)); registerApplicationTypeWithProto("dbr_ctrl_enum",cdd_ctrl_enum); diff --git a/src/gdd/gddAppTable.cc b/src/gdd/gddAppTable.cc index 323a948d6..7b0190aca 100644 --- a/src/gdd/gddAppTable.cc +++ b/src/gdd/gddAppTable.cc @@ -4,6 +4,10 @@ // $Id$ // // $Log$ +// Revision 1.2 1996/06/26 21:00:08 jbk +// Fixed up code in aitHelpers, removed unused variables in others +// Fixed potential problem in gddAppTable.cc with the map functions +// // Revision 1.1 1996/06/25 19:11:41 jbk // new in EPICS base // @@ -215,9 +219,15 @@ gddStatus gddApplicationTypeTable::registerApplicationType( gddStatus rc; if(new_app=getApplicationType(name)) + { + // gddAutoPrint(gddErrorAlreadyDefined); return gddErrorAlreadyDefined; + } if(total_registered>max_allowed) + { + gddAutoPrint("gddAppTable::registerApplicationType()",gddErrorAtLimit); return gddErrorAtLimit; + } sem.take(); rapp=total_registered++; @@ -229,7 +239,10 @@ gddStatus gddApplicationTypeTable::registerApplicationType( { // group already allocated - check is app already refined if(attr_table[group][app].type!=gddApplicationTypeUndefined) + { + // gddAutoPrint(gddErrorAlreadyDefined); return gddErrorAlreadyDefined; + } } else { @@ -346,17 +359,21 @@ gddStatus gddApplicationTypeTable::mapAppToIndex( aitUint32 c_app, aitUint32 m_app, aitUint32& x) { aitUint32 group,app; - gddStatus rc; + gddStatus rc=0; - if((rc=splitApplicationType(c_app,group,app))<0) return rc; - - if(attr_table[group][app].map && m_appisContainer() && dest->isManaged()) rc=copyDD_src(dest,src); else if(src->isContainer() && src->isManaged()) @@ -531,5 +553,6 @@ gddStatus gddApplicationTypeTable::smartCopy(gdd* dest, gdd* src) else rc=gddErrorNotAllowed; + gddAutoPrint("gddAppTable::smartCopy()",rc); return rc; } diff --git a/src/gdd/gddAppTable.h b/src/gdd/gddAppTable.h index a57722068..3ca8dd6aa 100644 --- a/src/gdd/gddAppTable.h +++ b/src/gdd/gddAppTable.h @@ -8,6 +8,9 @@ * $Id$ * * $Log$ + * Revision 1.1 1996/06/25 19:11:42 jbk + * new in EPICS base + * * * *Revision 1.3 1996/06/24 03:15:36 jbk * *name changes and fixes for aitString and fixed string functions @@ -167,9 +170,15 @@ inline aitUint32 gddApplicationTypeTable::index(aitUint32 rapp) const inline gddStatus gddApplicationTypeTable::splitApplicationType(aitUint32 rapp, aitUint32& g, aitUint32& app) const { + gddStatus rc=0; g=group(rapp); app=index(rapp); - if(rapp>=total_registered) return gddErrorOutOfBounds; else return 0; + if(rapp>=total_registered) + { + rc=gddErrorOutOfBounds; + gddAutoPrint("gddAppTable::splitApplicationType()",rc); + } + return rc; } inline aitUint32 gddApplicationTypeTable::registerApplicationType( diff --git a/src/gdd/gddErrorCodes.h b/src/gdd/gddErrorCodes.h index 19eefc78e..bdb11a2ca 100644 --- a/src/gdd/gddErrorCodes.h +++ b/src/gdd/gddErrorCodes.h @@ -8,6 +8,9 @@ * $Id$ * * $Log$ + * Revision 1.1 1996/06/25 19:11:43 jbk + * new in EPICS base + * * * *Revision 1.2 1996/06/13 21:32:00 jbk * *Various fixes and correction - including ref_cnt change to unsigned short @@ -16,6 +19,11 @@ * */ +/* + gdd.cc contains a table (gddErrorMessages) that has all the text + strings for each of the error codes +*/ + typedef long gddStatus; #define gddErrorTypeMismatch -1 @@ -29,4 +37,20 @@ typedef long gddStatus; #define gddErrorOverflow -9 #define gddErrorUnderflow -10 +extern char* gddErrorMessages[]; + +#define gddPrintError(x) \ + fprintf(stderr,"gdd Error: %s\n",gddErrorMessages[x*(-1)]); + +#define gddPrintErrorWithMessage(msg,x) \ + fprintf(stderr,"gdd Error: %s (%s)\n",gddErrorMessages[x*(-1)],msg); + +#define gddGetErrorMessage(x) gddErrorMessages[x*(-1)] + +#ifdef GDDAUTOPRINT +#define gddAutoPrint(s,x) if(x) gddPrintErrorWithMessage(s,x) +#else +#define gddAutoPrint(s,x) ; +#endif + #endif