- 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);
AddHipadabaChild(obj,n, NULL);
funcValue = MakeHdbFunc((voidFunc *)EnqueFunc);
funcValue = MakeSICSFunc(EnqueFunc);
n = MakeSICSHdbPar("enqueue",usUser, funcValue);
AddSICSHdbPar(n,"description",usUser,textValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)AddCmdData);
funcValue = MakeSICSFunc(AddCmdData);
n = MakeSICSHdbPar("addcommand",usUser, funcValue);
AddSICSHdbPar(n,"command",usUser,textValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Dequeue);
funcValue = MakeSICSFunc(Dequeue);
n = MakeSICSHdbPar("dequeue",usUser,funcValue);
AddHipadabaChild(obj,n,NULL);
AddSICSHdbPar(n,"index",usUser,intValue);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Clean);
funcValue = MakeSICSFunc(Clean);
n = MakeSICSHdbPar("clean",usUser, funcValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)CleanAll);
funcValue = MakeSICSFunc(CleanAll);
n = MakeSICSHdbPar("cleanall",usUser, funcValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Start);
funcValue = MakeSICSFunc(Start);
n = MakeSICSHdbPar("start",usUser, funcValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Restart);
funcValue = MakeSICSFunc(Restart);
n = MakeSICSHdbPar("restart",usUser, funcValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Stop);
funcValue = MakeSICSFunc(Stop);
n = MakeSICSHdbPar("stop",usUser, funcValue);
AddHipadabaChild(obj,n,NULL);
AppendHipadabaCallback(n,HCBSET,MakeSICSFuncCallback(self));
funcValue = MakeHdbFunc((voidFunc *)Move);
funcValue = MakeSICSFunc(Move);
n = MakeSICSHdbPar("move",usUser,funcValue);
AddHipadabaChild(obj,n,NULL);
AddSICSHdbPar(n,"moveindex",usUser,intValue);

View File

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

View File

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

View File

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

View File

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

View File

@ -12,6 +12,7 @@
#include <hipadaba.h>
#include <sics.h>
#include <dynstring.h>
#include <sicsobj.h>
/*======================== callback error codes ===============================*/
#define SICSCBRO -607
#define SICSCBPERM -608
@ -203,37 +204,37 @@ void RemoveSICSPar(pHdb node, void *callData);
/*=============== Add par functions =======================================*/
/**
* 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 priv The privilege required to change that 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
* @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 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
* 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 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 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.
* @param datalength The length of the data area pointed to by data.
* @param type The data type of the parameter
* @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);
/*============== access support functions =================================*/
/** 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
* specified prefix.
* @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
*/
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
* checks. Arrays should also have been allocated in the right size.
* @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
* @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
*/
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 ===========================*/
/**

View File

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