diff --git a/scriptcontext.c b/scriptcontext.c index 3152ecd1..e8e67a4f 100644 --- a/scriptcontext.c +++ b/scriptcontext.c @@ -28,7 +28,6 @@ typedef struct ScriptContext { ObjectDescriptor *desc; ContextItem *nodes; ContextItem *trash; - ContextItem *base; } ScriptContext; struct SctController { @@ -127,7 +126,7 @@ static char *GetProp(Hdb *node, Hdb *cNode, char *key) { if (val != NULL) return val; } if (cNode != NULL) { - val = GetHdbProp(node, key); + val = GetHdbProp(cNode, key); } return val; } @@ -140,12 +139,16 @@ int SctCommand(SConnection *con, SicsInterp *sics, void *object, static char value[1024]; char *val; char error[512]; - Hdb *node = sct->nodes->node; - Hdb *cNode = sct->nodes->controllerNode; + Hdb *node = NULL; + Hdb *cNode = NULL; hdbValue v; double dtime; assert(sct == object); + if (sct->nodes != NULL) { + node = sct->nodes->node; + cNode = sct->nodes->controllerNode; + } if (node == NULL && cNode == NULL) { SCPrintf(con, eError, "ERROR: %s may be called only in proper context", argv[0]); @@ -603,7 +606,6 @@ static int SctPollCmd(pSICSOBJ ccmd, SConnection *con, "%s poll registered on %s (%g sec, %s prio)", action, path, interval, prioText); } - sct->base->node = node; return 1; } @@ -725,7 +727,6 @@ static int SctWriteCmd(pSICSOBJ ccmd, SConnection *con, } SCSendOK(con); - sct->base->node = node; return 1; } @@ -942,14 +943,14 @@ static int SctMakeController(SConnection *con, SicsInterp *sics, ccmd->pPrivate = controller; ccmd->KillPrivate = SctKillController; - AddCommand(pServ->pSics, nodeName, InvokeSICSOBJ, KillSICSOBJ, ccmd); - SetDescriptorKey(ccmd->pDes, "creationCommand", "0"); - AddHipadabaChild(parent, controller->node, con); controller->devser = DevMake(con, argc - 2, argv + 2); if (!controller->devser) return 0; + AddCommand(pServ->pSics, nodeName, InvokeSICSOBJ, KillSICSOBJ, ccmd); + SetDescriptorKey(ccmd->pDes, "creationCommand", "0"); + cmd = AddSICSHdbPar(controller->node, "poll", usMugger, MakeSICSFunc(SctPollCmd)); AddSICSHdbPar(cmd, "node", usMugger, MakeHdbText("")); @@ -991,9 +992,6 @@ static int SctMakeController(SConnection *con, SicsInterp *sics, cb = MakeHipadabaCallback(SctDebugCallback, controller, NULL); if (cb) AppendHipadabaCallback(par, cb); - sct->base->controllerNode = controller->node; - sct->base->node = NULL; - return 1; } @@ -1021,8 +1019,6 @@ void SctInit(void) { sct = calloc(1, sizeof(*sct)); assert(sct); sct->desc = CreateDescriptor("ScriptContext"); - PushContext(NULL, NULL); - sct->base = sct->nodes; AddCommand(pServ->pSics, "sct", SctCommand, SctKill, sct); AddCmd("makesctcontroller", SctMakeController); }