From 60c2b58c95af482bb5065996a77729896557c2ae Mon Sep 17 00:00:00 2001 From: koennecke Date: Thu, 18 Jan 2007 04:58:50 +0000 Subject: [PATCH] - Fixed a couple of Hipadaba Issues - Added properties to Hipadaba Nodes - Made Morpheus Hipadaba aware and implemented scans for Morpheus and Hipadaba SKIPPED: psi/tecs/make_crv --- .cdtproject | 34 ++++++- .project | 35 ++++++- .settings/org.eclipse.cdt.core.prefs | 3 + hipadaba.c | 41 ++++++++ hipadaba.h | 35 ++++++- linux_def | 2 +- makefile_linux | 12 +-- nserver.c | 6 +- sicshdbadapter.c | 34 +++++++ sicshipadaba.c | 136 ++++++++++++++++++++++----- stringdict.c | 3 +- tcl/sicstcldebug.tcl | 3 + 12 files changed, 307 insertions(+), 37 deletions(-) create mode 100644 .settings/org.eclipse.cdt.core.prefs diff --git a/.cdtproject b/.cdtproject index 0fc98cfb..9a0d3e73 100644 --- a/.cdtproject +++ b/.cdtproject @@ -7,8 +7,8 @@ - + @@ -24,7 +24,7 @@ - + @@ -32,6 +32,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project index 64b240cd..a8496969 100644 --- a/.project +++ b/.project @@ -7,7 +7,12 @@ org.eclipse.cdt.make.core.makeBuilder + clean,full,incremental, + + org.eclipse.cdt.make.core.build.arguments + -f makefile_linux + org.eclipse.cdt.core.errorOutputParser org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser; @@ -20,22 +25,42 @@ org.eclipse.cdt.make.core.incrementalBuildTarget all + + org.eclipse.cdt.make.core.buildLocation + + org.eclipse.cdt.make.core.enableAutoBuild false - org.eclipse.cdt.make.core.buildLocation + org.eclipse.cdt.make.core.environment org.eclipse.cdt.make.core.enableFullBuild true + + org.eclipse.cdt.make.core.build.target.inc + all + org.eclipse.cdt.make.core.enabledIncrementalBuild true + + org.eclipse.cdt.make.core.build.location + + + + org.eclipse.cdt.make.core.build.command + make + + + org.eclipse.cdt.make.core.build.target.clean + clean + org.eclipse.cdt.make.core.enableCleanBuild true @@ -44,6 +69,10 @@ org.eclipse.cdt.make.core.cleanBuildTarget clean + + org.eclipse.cdt.make.core.append_environment + true + org.eclipse.cdt.make.core.useDefaultBuildCmd false @@ -64,6 +93,10 @@ org.eclipse.cdt.make.core.stopOnError false + + org.eclipse.cdt.make.core.build.target.auto + all + diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs new file mode 100644 index 00000000..b0b2face --- /dev/null +++ b/.settings/org.eclipse.cdt.core.prefs @@ -0,0 +1,3 @@ +#Thu Jan 11 14:43:46 CET 2007 +eclipse.preferences.version=1 +indexerId=org.eclipse.cdt.core.fastIndexer diff --git a/hipadaba.c b/hipadaba.c index 33693785..28d100a9 100644 --- a/hipadaba.c +++ b/hipadaba.c @@ -39,6 +39,9 @@ static void DeleteNodeData(pHdb node){ DeleteCallbackChain(node->updateCallbacks); DeleteCallbackChain(node->readCallbacks); DeleteCallbackChain(node->treeChangeCallbacks); + if(node->properties != NULL){ + DeleteStringDict(node->properties); + } if(node->name != NULL){ free(node->name); @@ -352,6 +355,7 @@ hdbValue MakeHdbInt(int initValue){ hdbValue result; result.dataType = HIPINT; + result.arrayLength = 1; result.v.intValue = initValue; return result; } @@ -360,6 +364,7 @@ hdbValue MakeHdbFloat(double initValue){ hdbValue result; result.dataType = HIPFLOAT; + result.arrayLength = 1; result.v.doubleValue = initValue; return result; } @@ -529,6 +534,10 @@ pHdb MakeHipadabaNode(char *name, int datatype, int length){ pNew->magic = HDBMAGICK; pNew->name = strdup(name); pNew->value.dataType = datatype; + pNew->properties = CreateStringDict(); + if(pNew->properties == NULL || pNew->name == NULL){ + return NULL; + } switch(datatype){ case HIPINTAR: case HIPINTVARAR: @@ -1049,3 +1058,35 @@ int GetHdbPar(pHdb node, int dataType, void *data, int length, } return 1; } +/*============================= Property Functions ==========================*/ + void SetHdbProperty(pHdb node, char *key, char *value){ + if(node != NULL && key != NULL && node->properties != NULL){ + if(StringDictExists(node->properties, key)){ + StringDictUpdate(node->properties,key,value); + } else { + StringDictAddPair(node->properties,key,value); + } + } + } +/*---------------------------------------------------------------------------*/ +int GetHdbProperty(pHdb node, char *key, char *value, int len){ + if(node != NULL && node->properties != NULL){ + return StringDictGet(node->properties,key,value,len); + } else { + return 0; + } +} +/*---------------------------------------------------------------------------*/ +void InitHdbPropertySearch(pHdb node){ + if(node != NULL && node->properties != NULL){ + StringDictKillScan(node->properties); + } +} +/*--------------------------------------------------------------------------*/ +const char *GetNextHdbProperty(pHdb node, char *value ,int len){ + if(node != NULL && node->properties != NULL) { + return StringDictGetNext(node->properties, value, len); + } else { + return NULL; + } +} diff --git a/hipadaba.h b/hipadaba.h index 6d17462e..885d4280 100644 --- a/hipadaba.h +++ b/hipadaba.h @@ -22,9 +22,12 @@ * Mark Koennecke, June 2006 * * Added treeChange callback, Mark Koennecke, November 2006 + * + * Added support for properties, Mark Koennecke, January 2007 */ #ifndef HIPADABA #define HIPADABA +#include /*------- datatypes */ #define HIPNONE -1 @@ -70,6 +73,7 @@ typedef struct __hipadaba { char *name; hdbValue value; int protected; + pStringDict properties; }Hdb, *pHdb; /*-------------------------------------------------------------------------------*/ typedef int (*hdbCallbackFunction)(void *userData, void *callData, @@ -330,5 +334,34 @@ int UpdateHdbPar(pHdb node, int dataType, void *data, int length, */ int GetHdbPar(pHdb node, int dataType, void *data, int length, void *callData); - +/*================================ Property Interface ==============================================*/ +/** + * set a property + * @param node The node to set the property for + * @param key The key for the property + * @param value The value of the property + */ + void SetHdbProperty(pHdb node, char *key, char *value); + /** + * get the value of a property + * @param node The node to get the property from + * @param key The properties key + * @param value The area to which to copy the property + * @param len The length of value + * @return 0 on failure, 1 on success + */ + int GetHdbProperty(pHdb node, char *key, char *value, int len); + /** + * initialize a property scan on this node + * @param node The node for which to scan properties + */ +void InitHdbPropertySearch(pHdb node); +/** + * get the next property in a search + * @param node The node for which to search properties + * @param value An area where to copy the value of the property + * @param len The length of value + * @return The key of the property or NULL when the property list is exhausted + */ +const char *GetNextHdbProperty(pHdb node, char *value ,int len); #endif diff --git a/linux_def b/linux_def index ea98bcdb..4feb8a3b 100644 --- a/linux_def +++ b/linux_def @@ -9,4 +9,4 @@ MFLAGS=-f makefile_linux$(DUMMY) -HDFROOT=/afs/psi.ch/project/sinq/sl-linux +HDFROOT=/usr/local diff --git a/makefile_linux b/makefile_linux index 660eef3a..bb656195 100644 --- a/makefile_linux +++ b/makefile_linux @@ -6,11 +6,11 @@ # Markus Zolliker, March 2003 #========================================================================== # assign if the National Instrument GPIB driver is available -SINQDIR=/afs/psi.ch/project/sinq -NI= -#NI= -DHAVENI -#NIOBJ= nigpib.o -#NILIB=$(SINQDIR)/linux/lib/cib.o +SINQDIR=/usr/local +#NI= +NI= -DHAVENI +NIOBJ= nigpib.o +NILIB=$(SINQDIR)/lib/cib.o include linux_def @@ -26,7 +26,7 @@ SUBLIBS = psi/libpsi.a psi/hardsup/libhlib.a matrix/libmatrix.a \ LIBS = -L$(HDFROOT)/lib $(SUBLIBS) $(NILIB)\ -ltcl8.4 -lmxml $(HDFROOT)/lib/libhdf5.a \ $(HDFROOT)/lib/libmfhdf.a $(HDFROOT)/lib/libdf.a \ - -ljpeg -ldl -lz -lm -lc + -lmxml -lghttp -ljpeg -ldl -lz -lsz -lm -lc include make_gen diff --git a/nserver.c b/nserver.c index d79e03bd..f5114fe8 100644 --- a/nserver.c +++ b/nserver.c @@ -399,13 +399,13 @@ */ killTclDrivable(); - /* close the List system */ - LLDsystemClose(); - KillFreeConnections(); killSICSHipadaba(); + /* close the List system */ + LLDsystemClose(); + /* make fortify print his findings */ Fortify_DumpAllMemory(iFortifyScope); Fortify_LeaveScope(); diff --git a/sicshdbadapter.c b/sicshdbadapter.c index 87e44bb2..6de76d1e 100644 --- a/sicshdbadapter.c +++ b/sicshdbadapter.c @@ -23,6 +23,30 @@ #include "sicsvar.h" #include "sicshipadaba.h" #include "sicshdbadapter.h" + +#define PRIVNAM "priv" +/*==================== support code ====================================*/ +static void AddPrivProperty(pHdb node, int priv){ + char pPriv[80]; + switch(priv){ + case usInternal: + strcpy(pPriv,"internal"); + break; + case usMugger: + strcpy(pPriv,"manager"); + break; + case usUser: + strcpy(pPriv,"user"); + break; + case usSpy: + strcpy(pPriv,"spy"); + break; + default: + assert(0); + break; + } + SetHdbProperty(node,PRIVNAM,pPriv); +} /*=================== motor code =======================================*/ static int MoveCallback(int iEvent, void *eventData, void *userData, commandContext cc){ @@ -122,6 +146,7 @@ static int AddStdMotorPar(pHdb motorNode, pMotor pMot){ i = 0; while(addPar[i] != NULL){ parNode = MakeMotParNode(addPar[i],pMot); + SetHdbProperty(parNode,PRIVNAM,"internal"); if(parNode == NULL){ return 0; } @@ -138,6 +163,7 @@ static int AddStdMotorPar(pHdb motorNode, pMotor pMot){ return 0; } AddHipadabaChild(motorNode,parNode, NULL); + AddPrivProperty(parNode,pMot->ParArray[i].iCode); } return 1; } @@ -197,6 +223,7 @@ static int CreateDriverParameters(pMotor pM, pHdb parent){ while((pPtr = stptok(pPtr,line,79,"\n")) != NULL){ name = extractName(line); node = MakeMotParNode(name,pM); + SetHdbProperty(node,PRIVNAM,"manager"); if(node != NULL){ AddHipadabaChild(parent,node,NULL); } @@ -208,6 +235,7 @@ static int CreateDriverParameters(pMotor pM, pHdb parent){ static pHdb CreateMotorAdapter(char *name, pMotor pMot){ pHdb result = NULL; commandContext comCom; + float access; assert(pMot != NULL); @@ -215,6 +243,9 @@ static pHdb CreateMotorAdapter(char *name, pMotor pMot){ if(result == NULL){ return NULL; } + MotorGetPar(pMot,"accesscode",&access); + AddPrivProperty(result,(int)access); + SetHdbProperty(result,"type","Motor"); /* * We want to be notified when this motor drives around. Or * its parameters change. @@ -359,6 +390,7 @@ static pHdb MakeSicsVarNode(pSicsVariable pVar, char *name){ if(node == NULL){ return NULL; } + AddPrivProperty(node,pVar->iAccessCode); pCall = MakeHipadabaCallback(SicsVarSetCallback,pVar,NULL,-1,-1); if(pCall == NULL){ return NULL; @@ -427,6 +459,8 @@ int SICSHdbAdapter(SConnection *pCon, SicsInterp *pSics, void *pData, SCWrite(pCon,"ERROR: out of memory creating drivable node",eError); return 0; } + SetHdbProperty(node,PRIVNAM,"user"); + SetHdbProperty(node,"type","drivable"); AddHipadabaChild(path,node,pCon); SCSendOK(pCon); return 1; diff --git a/sicshipadaba.c b/sicshipadaba.c index 47554464..59f2a408 100644 --- a/sicshipadaba.c +++ b/sicshipadaba.c @@ -8,6 +8,11 @@ * Mark Koennecke, June 2006 * * Introduced notification on tree changes, Mark Koennecke, November 2006 + * + * Added Property functions, Mark Koennecke, January 2007 + * + * TODO: separate this into two modules: sicshipadaba proper and sicshipadabaint for the + * interpreter interface. */ #include #include @@ -745,6 +750,9 @@ static void SICSDeleteNodeData(pHdb node){ node->child = node->child->next; SICSDeleteNodeData(tmp); } + if(node->properties != NULL){ + DeleteStringDict(node->properties); + } DeleteCallbackChain(node->writeCallbacks); DeleteCallbackChain(node->updateCallbacks); DeleteCallbackChain(node->readCallbacks); @@ -1611,7 +1619,7 @@ static int UpdateHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, return 0; } - if(argc < 3) { + if(argc < 2) { SCWrite(pCon,"ERROR: insufficient number of arguments to UpdateHdbNode", eError); return 0; @@ -1621,26 +1629,30 @@ static int UpdateHdbNode(SConnection *pCon, SicsInterp *pSics, void *pData, if(targetNode == NULL){ return 0; } - if(!cloneHdbValue(&targetNode->value,&newValue)){ - SCWrite(pCon,"ERROR: out of mmeory cloning node", - eError); - return 0; - } - parData = CreateDynString(64,64); - if(parData == NULL){ - SCWrite(pCon,"ERROR: out of memory reading parameter",eError); - return 0; - } - for(i = 2; i < argc; i++){ - DynStringConcat(parData," "); - DynStringConcat(parData, argv[i]); - } - strcpy(error,"ERROR: "); - if(!readHdbValue(&newValue, GetCharArray(parData), - error+7,512-7)){ - SCWrite(pCon,error, eError); - return 0; - } + if(argc > 2){ + if(!cloneHdbValue(&targetNode->value,&newValue)){ + SCWrite(pCon,"ERROR: out of mmeory cloning node", + eError); + return 0; + } + parData = CreateDynString(64,64); + if(parData == NULL){ + SCWrite(pCon,"ERROR: out of memory reading parameter",eError); + return 0; + } + for(i = 2; i < argc; i++){ + DynStringConcat(parData," "); + DynStringConcat(parData, argv[i]); + } + strcpy(error,"ERROR: "); + if(!readHdbValue(&newValue, GetCharArray(parData), + error+7,512-7)){ + SCWrite(pCon,error, eError); + return 0; + } + } else { + GetHipadabaPar(targetNode,&newValue,pCon); + } status = UpdateHipadabaPar(targetNode,newValue,pCon); ReleaseHdbValue(&newValue); if(status == 1){ @@ -2243,7 +2255,84 @@ static int SicsCommandNode(SConnection *pCon, SicsInterp *pSics, void *pData, SCSendOK(pCon); return 1; } -/*---------------------------------------------------------------------------*/ +/*======================= Property Functions ================================*/ +static int SetSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pHdb targetNode = NULL; + char buffer[512]; + + if(argc < 4) { + SCWrite(pCon,"ERROR: need path key value as parameters",eError); + return 0; + } + targetNode = locateSICSNode(pSics,pCon,argv[1]); + if(targetNode == NULL){ + SCWrite(pCon,"ERROR: node not found",eError); + return 0; + } + Arg2Text(argc-3, &argv[3], buffer,512); + SetHdbProperty(targetNode,argv[2], buffer); + SCSendOK(pCon); + return 1; + } + /*--------------------------------------------------------------------------*/ +static int GetSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pHdb targetNode = NULL; + char buffer[512]; + int status; + + if(argc < 3) { + SCWrite(pCon,"ERROR: need path key as parameters",eError); + return 0; + } + targetNode = locateSICSNode(pSics,pCon,argv[1]); + if(targetNode == NULL){ + SCWrite(pCon,"ERROR: node not found",eError); + return 0; + } + status = GetHdbProperty(targetNode,argv[2],buffer,511); + if(status != 1){ + SCWrite(pCon,"ERROR: attribute not found",eError); + return 0; + } + SCPrintf(pCon,eValue,"%s.%s = %s", argv[1], argv[2], buffer); + return 1; + } + /*--------------------------------------------------------------------------*/ +static int ListSICSHdbProperty(SConnection *pCon, SicsInterp *pSics, void *pData, + int argc, char *argv[]){ + pHdb targetNode = NULL; + char buffer[512]; + const char *pKey = NULL; + pDynString data = NULL; + + if(argc < 2) { + SCWrite(pCon,"ERROR: need path as parameter",eError); + return 0; + } + targetNode = locateSICSNode(pSics,pCon,argv[1]); + if(targetNode == NULL){ + SCWrite(pCon,"ERROR: node not found",eError); + return 0; + } + data = CreateDynString(64,64); + if(data == NULL){ + SCWrite(pCon,"ERROR: out of memory in ListSICSHdbProperty",eError); + return 0; + } + InitHdbPropertySearch(targetNode); + while((pKey = GetNextHdbProperty(targetNode, buffer, 511)) != NULL){ + DynStringConcat(data,(char *)pKey); + DynStringConcat(data,"="); + DynStringConcat(data,buffer); + DynStringConcat(data,"\n"); + } + SCWrite(pCon,GetCharArray(data), eValue); + DeleteDynString(data); + return 1; + } +/*======================= Factory Functions =================================*/ void killSICSHipadaba(){ if(root != NULL){ DeleteHipadabaNode(root,NULL); @@ -2271,6 +2360,9 @@ int InstallSICSHipadaba(SConnection *pCon, SicsInterp *pSics, void *pData, AddCommand(pSics,"hval", HdbNodeVal, NULL, NULL); AddCommand(pSics,"hchain", ChainHdbNode, NULL, NULL); AddCommand(pSics,"hcommand",SicsCommandNode, NULL, NULL); + AddCommand(pSics,"hsetprop",SetSICSHdbProperty, NULL, NULL); + AddCommand(pSics,"hgetprop",GetSICSHdbProperty, NULL, NULL); + AddCommand(pSics,"hlistprop",ListSICSHdbProperty, NULL, NULL); InstallSICSPoll(pCon,pSics,pData,argc,argv); poller = (pSicsPoll)FindCommandData(pSics,"sicspoll","SicsPoll"); diff --git a/stringdict.c b/stringdict.c index 10219bfe..9cbf0c0a 100644 --- a/stringdict.c +++ b/stringdict.c @@ -75,12 +75,13 @@ return pNew; } /*------------------------------------------------------------------------*/ - void DeleteStringDict(pStringDict self) + void DeleteStringDict(pStringDict self) { int iRet; SDE sVal; assert(self); + iRet = LLDnodePtr2First(self->iList); while(iRet != 0) { diff --git a/tcl/sicstcldebug.tcl b/tcl/sicstcldebug.tcl index 9f6e4856..e9e6df97 100644 --- a/tcl/sicstcldebug.tcl +++ b/tcl/sicstcldebug.tcl @@ -30,6 +30,9 @@ proc unknown args { return $reply } else { append reply $line + if {[string first "\n" $line] < 0} { + append reply \n + } } } }