- add MskeSICSFunc

- changed return value of AddSICSHdbPar et al.
This commit is contained in:
zolliker
2008-05-15 07:43:05 +00:00
parent 2b558550fb
commit b03ddddd8f
7 changed files with 68 additions and 92 deletions

View File

@ -425,52 +425,52 @@ static void Configure(pSICSOBJ self){
n = MakeHipadabaNode("queue",HIPNONE,1); n = MakeHipadabaNode("queue",HIPNONE,1);
AddHipadabaChild(obj,n, NULL); AddHipadabaChild(obj,n, NULL);
funcValue = MakeHdbFunc((voidFunc *)EnqueFunc); funcValue = MakeSICSFunc(EnqueFunc);
n = MakeSICSHdbPar("enqueue",usUser, funcValue); n = MakeSICSHdbPar("enqueue",usUser, funcValue);
AddSICSHdbPar(n,"description",usUser,textValue); AddSICSHdbPar(n,"description",usUser,textValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)AddCmdData); funcValue = MakeSICSFunc(AddCmdData);
n = MakeSICSHdbPar("addcommand",usUser, funcValue); n = MakeSICSHdbPar("addcommand",usUser, funcValue);
AddSICSHdbPar(n,"command",usUser,textValue); AddSICSHdbPar(n,"command",usUser,textValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Dequeue); funcValue = MakeSICSFunc(Dequeue);
n = MakeSICSHdbPar("dequeue",usUser,funcValue); n = MakeSICSHdbPar("dequeue",usUser,funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AddSICSHdbPar(n,"index",usUser,intValue); AddSICSHdbPar(n,"index",usUser,intValue);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Clean); funcValue = MakeSICSFunc(Clean);
n = MakeSICSHdbPar("clean",usUser, funcValue); n = MakeSICSHdbPar("clean",usUser, funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)CleanAll); funcValue = MakeSICSFunc(CleanAll);
n = MakeSICSHdbPar("cleanall",usUser, funcValue); n = MakeSICSHdbPar("cleanall",usUser, funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Start); funcValue = MakeSICSFunc(Start);
n = MakeSICSHdbPar("start",usUser, funcValue); n = MakeSICSHdbPar("start",usUser, funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Restart); funcValue = MakeSICSFunc(Restart);
n = MakeSICSHdbPar("restart",usUser, funcValue); n = MakeSICSHdbPar("restart",usUser, funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Stop); funcValue = MakeSICSFunc(Stop);
n = MakeSICSHdbPar("stop",usUser, funcValue); n = MakeSICSHdbPar("stop",usUser, funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self)); AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Move); funcValue = MakeSICSFunc(Move);
n = MakeSICSHdbPar("move",usUser,funcValue); n = MakeSICSHdbPar("move",usUser,funcValue);
AddHipadabaChild(obj,n,NULL); AddHipadabaChild(obj,n,NULL);
AddSICSHdbPar(n,"moveindex",usUser,intValue); AddSICSHdbPar(n,"moveindex",usUser,intValue);

View File

@ -452,7 +452,7 @@ int ProxyFactory(SConnection *pCon, SicsInterp *pSics, void *pData,
AppendHipadabaCallback(pNew->objectNode, AppendHipadabaCallback(pNew->objectNode,
MakeHipadabaCallback(ProxyCallback, pNew,NULL)); MakeHipadabaCallback(ProxyCallback, pNew,NULL));
v = MakeHdbFunc((voidFunc *)MapFunc); v = MakeSICSFunc(MapFunc);
mapFunc = MakeSICSHdbPar("map", usMugger, v); mapFunc = MakeSICSHdbPar("map", usMugger, v);
SetHdbProperty(mapFunc,"visible","false"); SetHdbProperty(mapFunc,"visible","false");
v = MakeHdbText("Undefined"); v = MakeHdbText("Undefined");

View File

@ -687,61 +687,28 @@ static int SctMakeController(SConnection *con, SicsInterp *sics,
controller->devser = DevMake(con, argc - 2, argv + 2); controller->devser = DevMake(con, argc - 2, argv + 2);
if (!controller->devser) return 0; if (!controller->devser) return 0;
cmd = MakeSICSHdbPar("poll", usMugger, cmd = AddSICSHdbPar(controller->node,
MakeHdbFunc((voidFunc*)SctPollCmd)); "poll", usMugger, MakeSICSFunc(SctPollCmd));
assert(cmd); AddSICSHdbPar(cmd, "node", usMugger, MakeHdbText(""));
AddHipadabaChild(controller->node, cmd, con); AddSICSHdbPar(cmd, "interval", usMugger, MakeHdbFloat(5.0));
AddSICSHdbPar(cmd, "prio", usMugger, MakeHdbText("read"));
par = MakeSICSHdbPar("node", usMugger, MakeHdbText("")); AddSICSHdbPar(cmd, "action", usMugger, MakeHdbText("read"));
assert(par);
AddHipadabaChild(cmd, par, con);
par = MakeSICSHdbPar("interval", usMugger, MakeHdbFloat(5.0)); cmd = AddSICSHdbPar(controller->node,
assert(par); "write", usMugger, MakeSICSFunc(SctWriteCmd));
AddHipadabaChild(cmd, par, con); AddSICSHdbPar(cmd, "node", usMugger, MakeHdbText(""));
par = MakeSICSHdbPar("prio", usMugger, MakeHdbText("read"));
assert(par);
AddHipadabaChild(cmd, par, con);
par = MakeSICSHdbPar("action", usMugger, MakeHdbText("read"));
assert(par);
AddHipadabaChild(cmd, par, con);
cmd = MakeSICSHdbPar("write", usMugger,
MakeHdbFunc((voidFunc*)SctWriteCmd));
assert(cmd);
AddHipadabaChild(controller->node, cmd, con);
par = MakeSICSHdbPar("node", usMugger, MakeHdbText(""));
assert(par);
AddHipadabaChild(cmd, par, con);
cmd = MakeSICSHdbPar("queue", usMugger, cmd = AddSICSHdbPar(controller->node,
MakeHdbFunc((voidFunc*)SctQueueCmd)); "queue", usMugger, MakeSICSFunc(SctQueueCmd));
assert(cmd); AddSICSHdbPar(cmd, "node", usMugger, MakeHdbText(""));
AddHipadabaChild(controller->node, cmd, con); AddSICSHdbPar(cmd, "prio", usMugger, MakeHdbText("write"));
AddSICSHdbPar(cmd, "action", usMugger, MakeHdbText("write"));
par = MakeSICSHdbPar("node", usMugger, MakeHdbText("")); par = AddSICSHdbPar(controller->node, "debug", usUser, MakeHdbInt(0));
assert(par);
AddHipadabaChild(cmd, par, con);
par = MakeSICSHdbPar("prio", usMugger, MakeHdbText("write"));
assert(par);
AddHipadabaChild(cmd, par, con);
par = MakeSICSHdbPar("action", usMugger, MakeHdbText("write"));
assert(par);
AddHipadabaChild(cmd, par, con);
par = MakeSICSHdbPar("debug", usUser, MakeHdbInt(0));
assert(par);
AddHipadabaChild(controller->node, par, con);
cb = MakeHipadabaCallback(SctDebugCallback, controller, NULL); cb = MakeHipadabaCallback(SctDebugCallback, controller, NULL);
assert(cb); if (cb) AppendHipadabaCallback(par, cb);
AppendHipadabaCallback(par, cb);
if (stack == NULL) { if (stack == NULL) {
cctx->node = controller->node; cctx->node = controller->node;

View File

@ -269,7 +269,7 @@ static hdbCallbackReturn CommandGetCallback(pHdb node, void *userData,
} }
hdbValue v2 = MakeHdbText("Nothing to get"); hdbValue v2 = MakeHdbText("Nothing to get");
*(mm->v) = v2; copyHdbValue(&v2, mm->v); /* MakeHdbText makes no strdup ! */
return hdbContinue; return hdbContinue;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/

View File

@ -1188,66 +1188,64 @@ void RemoveSICSPar(pHdb node, void *callData){
SICSDeleteNodeData(node); SICSDeleteNodeData(node);
} }
/*===================== add functions =======================================*/ /*===================== add functions =======================================*/
int AddSICSHdbPar(pHdb node, char *name, int priv, hdbValue v){ pHdb AddSICSHdbPar(pHdb parent, char *name, int priv, hdbValue v){
pHdb child = NULL; pHdb child = NULL;
child = MakeSICSHdbPar(name,priv,v); child = MakeSICSHdbPar(name,priv,v);
if(child == NULL){ if(child != NULL){
return 0; AddHipadabaChild(parent,child,NULL);
} }
AddHipadabaChild(node,child,NULL); return child;
return 1;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int AddSICSHdbROPar(pHdb node, char *name, hdbValue v){ pHdb AddSICSHdbROPar(pHdb parent, char *name, hdbValue v){
pHdb child = NULL; pHdb child = NULL;
child = MakeSICSROPar(name,v); child = MakeSICSROPar(name,v);
if(child == NULL){ if(child != NULL){
return 0; AddHipadabaChild(parent,child,NULL);
} }
AddHipadabaChild(node,child,NULL); return child;
return 1;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
int AddSICSHdbMemPar(pHdb node, char *name, int priv, pHdb AddSICSHdbMemPar(pHdb parent, char *name, int priv,
void *data, int datalength, int type, int length){ void *data, int datalength, int type, int length){
pHdb child = NULL; pHdb child = NULL;
pHdbCallback pHcb = NULL; pHdbCallback pHcb = NULL;
if(type == HIPINTVARAR || type == HIPFLOATVARAR){ if(type == HIPINTVARAR || type == HIPFLOATVARAR){
assert(0); assert(0);
return 0; return NULL;
} }
child = MakeHipadabaNode(name,type,length); child = MakeHipadabaNode(name,type,length);
if(child == NULL){ if(child == NULL){
return 0; return NULL;
} }
pHcb = MakeCheckPermissionCallback(priv); pHcb = MakeCheckPermissionCallback(priv);
if(pHcb == NULL){ if(pHcb == NULL){
DeleteHipadabaNode(child,NULL); DeleteHipadabaNode(child,NULL);
return 0; return NULL;
} }
AppendHipadabaCallback(child,pHcb); AppendHipadabaCallback(child,pHcb);
pHcb = MakeMemGenSetCallback(data); pHcb = MakeMemGenSetCallback(data);
if(pHcb == NULL){ if(pHcb == NULL){
DeleteHipadabaNode(child,NULL); DeleteHipadabaNode(child,NULL);
return 0; return NULL;
} }
AppendHipadabaCallback(child,pHcb); AppendHipadabaCallback(child,pHcb);
pHcb = MakeMemGenReadCallback(data); pHcb = MakeMemGenReadCallback(data);
if(pHcb == NULL){ if(pHcb == NULL){
DeleteHipadabaNode(child,NULL); DeleteHipadabaNode(child,NULL);
return 0; return NULL;
} }
AppendHipadabaCallback(child,pHcb); AppendHipadabaCallback(child,pHcb);
AddHipadabaChild(node,child,NULL); AddHipadabaChild(parent,child,NULL);
return 1; return child;
} }
/*==================== access support functions ==============================*/ /*==================== access support functions ==============================*/
pHdb FindHdbParent(char *rootpath, char *relpath, char **namePtr, SConnection *pCon) { pHdb FindHdbParent(char *rootpath, char *relpath, char **namePtr, SConnection *pCon) {
@ -1875,6 +1873,10 @@ int readHdbValue(hdbValue *v, char *data, char *error, int errlen){
} }
return 1; return 1;
} }
/*-------------------------------------------------------------------------*/
hdbValue MakeSICSFunc(SICSOBJFunc func) {
return MakeHdbFunc((voidFunc *)func);
}
/*================ interpreter interface ==================================*/ /*================ interpreter interface ==================================*/
pHdb GetHipadabaRoot(){ pHdb GetHipadabaRoot(){
return root; return root;
@ -2875,7 +2877,7 @@ static hdbCallbackReturn CommandGetCallback(pHdb node, void *userData,
} }
hdbValue v2 = MakeHdbText("Nothing to get"); hdbValue v2 = MakeHdbText("Nothing to get");
*(mm->v) = v2; copyHdbValue(&v2, mm->v); /* MakeHdbText makes no strdup ! */
return hdbContinue; return hdbContinue;
} }
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/

View File

@ -12,6 +12,7 @@
#include <hipadaba.h> #include <hipadaba.h>
#include <sics.h> #include <sics.h>
#include <dynstring.h> #include <dynstring.h>
#include <sicsobj.h>
/*======================== callback error codes ===============================*/ /*======================== callback error codes ===============================*/
#define SICSCBRO -607 #define SICSCBRO -607
#define SICSCBPERM -608 #define SICSCBPERM -608
@ -203,37 +204,37 @@ void RemoveSICSPar(pHdb node, void *callData);
/*=============== Add par functions =======================================*/ /*=============== Add par functions =======================================*/
/** /**
* add a new simple hdb parameter as child to node * add a new simple hdb parameter as child to node
* @param node The node to add the new node too. * @param parent The parent node to add the new node to.
* @param name The name of the new node * @param name The name of the new node
* @param priv The privilege required to change that parameter * @param priv The privilege required to change that parameter
* @param v The initial value and datatype of this parameter * @param v The initial value and datatype of this parameter
* @return 1 on success, 0 else * @return the created node on success, NULL else
*/ */
int AddSICSHdbPar(pHdb node, char *name, int priv, hdbValue v); pHdb AddSICSHdbPar(pHdb parent, char *name, int priv, hdbValue v);
/** /**
* add a new read only hdb parameter as child to node * add a new read only hdb parameter as child to node
* @param node The node to add the new node too. * @param parent The parent node to add the new node to.
* @param name The name of the new node * @param name The name of the new node
* @param v The initial value and datatype of this parameter * @param v The initial value and datatype of this parameter
* @return 1 on success, 0 else * @return the created node on success, NULL else
*/ */
int AddSICSHdbROPar(pHdb node, char *name, hdbValue v); pHdb AddSICSHdbROPar(pHdb parent, char *name, hdbValue v);
/** /**
* Add a new hdb parameter as child to node. Updates are synced * Add a new hdb parameter as child to node. Updates are synced
* to the memory location data. This works for simple variables, fixed size * to the memory location data. This works for simple variables, fixed size
* arrays and fixed sized strings. This does not work for dynamically sized * arrays and fixed sized strings. This does not work for dynamically sized
* arrays or strings. * arrays or strings.
* @param node The node to add the new node too. * @param parent The parent node to add the new node to.
* @param name The name of the new node * @param name The name of the new node
* @param priv The privilege required to change that parameter * @param priv The privilege required to change that parameter
* @param data The pointer to map this parameter too. This must be in * @param data The pointer to map this parameter to. This must be in
* dynamically allocated memory. * dynamically allocated memory.
* @param datalength The length of the data area pointed to by data. * @param datalength The length of the data area pointed to by data.
* @param type The data type of the parameter * @param type The data type of the parameter
* @param length The length of the type. Used for array types. * @param length The length of the type. Used for array types.
* @return 1 on success, 0 else * @return the created node on success, NULL else
*/ */
int AddSICSHdbMemPar(pHdb node, char *name, int priv, pHdb AddSICSHdbMemPar(pHdb parent, char *name, int priv,
void *data, int datalength, int type, int length); void *data, int datalength, int type, int length);
/*============== access support functions =================================*/ /*============== access support functions =================================*/
/** Find the parent of a node to be created /** Find the parent of a node to be created
@ -348,7 +349,7 @@ int ProcessSICSHdbPar(pHdb root, SConnection *pCon, char *printPrefix,
* print a listing of the parameters of node to pCon, using the * print a listing of the parameters of node to pCon, using the
* specified prefix. * specified prefix.
* @param node The node to print * @param node The node to print
* @param pCon The connection to print too * @param pCon The connection to print to
* @param prefix The prefix to use for printing * @param prefix The prefix to use for printing
*/ */
void PrintSICSParList(pHdb node, SConnection *pCon, char *prefix); void PrintSICSParList(pHdb node, SConnection *pCon, char *prefix);
@ -386,7 +387,7 @@ pDynString formatValue(hdbValue v, pHdb node);
* already have been initialised before this call in order to allow for * already have been initialised before this call in order to allow for
* checks. Arrays should also have been allocated in the right size. * checks. Arrays should also have been allocated in the right size.
* @param data The string to parse and convert. * @param data The string to parse and convert.
* @param error A string to copy failure reasons too * @param error A string to copy failure reasons to
* @param errlen The length of the error string * @param errlen The length of the error string
* @return 0 on failure, 1 on success * @return 0 on failure, 1 on success
*/ */
@ -397,6 +398,12 @@ int readHdbValue(hdbValue *v, char *data, char *error, int errlen);
* @return The converted Hipadaba type * @return The converted Hipadaba type
*/ */
int convertHdbType(char *text); int convertHdbType(char *text);
/**
* wrap a SICSOBJFunc function as an hdbValue
* @param func the function
* @return: A properly initialized hdbValue structure
*/
hdbValue MakeSICSFunc(SICSOBJFunc func);
/*================= SICS Interpreter Interface ===========================*/ /*================= SICS Interpreter Interface ===========================*/
/** /**

View File

@ -200,7 +200,7 @@ static int MakeScriptFunc(pSICSOBJ self, SConnection *pCon,
SCWrite(pCon,"ERROR: root path error or out of memory",eError); SCWrite(pCon,"ERROR: root path error or out of memory",eError);
return 0; return 0;
} }
node->value = MakeHdbFunc((voidFunc *)ScriptObjFunc); node->value = MakeSICSFunc(ScriptObjFunc);
SetHdbProperty(node,"script",argv[3]); SetHdbProperty(node,"script",argv[3]);
SetHdbProperty(node,"priv",argv[4]); SetHdbProperty(node,"priv",argv[4]);
AppendHipadabaCallback(node,MakeSICSFuncCallback(self)); AppendHipadabaCallback(node,MakeSICSFuncCallback(self));