- design improvements in scriptcontext (sct send) and ascon (AsconBaseHandler)
- bug fixes
This commit is contained in:
@@ -28,6 +28,8 @@ typedef struct ScriptContext {
|
||||
ObjectDescriptor *desc;
|
||||
ContextItem *nodes;
|
||||
ContextItem *trash;
|
||||
Hdb *sendNode;
|
||||
int sendCalled;
|
||||
} ScriptContext;
|
||||
|
||||
struct SctController {
|
||||
@@ -152,7 +154,6 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
|
||||
Hdb *cNode = NULL;
|
||||
hdbValue v;
|
||||
double dtime;
|
||||
int iMacro;
|
||||
|
||||
assert(sct == object);
|
||||
if (sct->nodes != NULL) {
|
||||
@@ -190,14 +191,13 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
|
||||
* print
|
||||
*/
|
||||
if (strcmp(argv[1], "print") == 0) {
|
||||
iMacro = con->iMacro;
|
||||
if (queueData != NULL) {
|
||||
queueData->answered = 1;
|
||||
con->iMacro = queueData->inMacro; /* take macro flag stored at set callback */
|
||||
SCsetMacro(con, queueData->inMacro); /* take macro flag stored at set callback */
|
||||
}
|
||||
Arg2Text(argc - 2, argv + 2, value, sizeof value);
|
||||
SCWrite(con, value, eWarning);
|
||||
con->iMacro = iMacro;
|
||||
SCsetMacro(con, 1); /* where are always in Macro */
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -223,6 +223,19 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* send command
|
||||
*/
|
||||
if (strcmp(argv[1], "send") == 0 && argc > 2) {
|
||||
if (sct->sendNode != node) {
|
||||
SCPrintf(con, eError, "ERROR: %s may be called only in action scripts",
|
||||
argv[0]);
|
||||
return 0;
|
||||
}
|
||||
sct->sendCalled = 1;
|
||||
/* continue with property handling */
|
||||
}
|
||||
|
||||
/*
|
||||
* property handling
|
||||
*/
|
||||
@@ -265,6 +278,13 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
|
||||
ret = Tcl_EvalEx(pTcl, script, l, 0);
|
||||
result = (char *) Tcl_GetStringResult(pTcl);
|
||||
if (ret != TCL_OK && result[0] != '\0') {
|
||||
if (strncmp(result, "ERROR:", 6) == 0) {
|
||||
/* remove "ERROR:", as it will be added later */
|
||||
result += 6;
|
||||
if (result[0] == ' ') {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
SCPrintf(con, eLog, "error: %s", result);
|
||||
}
|
||||
@@ -306,8 +326,10 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
char *emsg;
|
||||
size_t l;
|
||||
int cnt;
|
||||
int ret;
|
||||
char timeKey[50], timeVal[50];
|
||||
|
||||
int iMacro;
|
||||
|
||||
if (queueData != NULL && queueData->conCtx != NULL) {
|
||||
con = queueData->conCtx;
|
||||
} else {
|
||||
@@ -325,9 +347,6 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
SetProp(node, controller->node, "state", state);
|
||||
}
|
||||
for (i = 0; i < 10; i++) {
|
||||
SetProp(node, controller->node, "sent",
|
||||
GetProp(node, controller->node, "send"));
|
||||
SetProp(node, controller->node, "send", NULL);
|
||||
script = GetProp(node, controller->node, state);
|
||||
if (script == NULL)
|
||||
script = state;
|
||||
@@ -339,11 +358,12 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
commError = 0;
|
||||
}
|
||||
script = strdup(script);
|
||||
if (!SctCallInContext(con, script, node, controller, &result)) {
|
||||
sct->sendNode = node;
|
||||
sct->sendCalled = 0;
|
||||
ret = SctCallInContext(con, script, node, controller, &result);
|
||||
sct->sendNode = NULL;
|
||||
if (ret == 0) {
|
||||
snprintf(eprop, sizeof eprop, "error_during_%s", data->name);
|
||||
if (strncmp(result, "ERROR: ", 7) == 0) {
|
||||
result += 7;
|
||||
}
|
||||
emsg = GetHdbProp(node, eprop);
|
||||
if (emsg == NULL || con != controller->conn) {
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
@@ -366,7 +386,7 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
sscanf(emsg, "%d", &cnt);
|
||||
}
|
||||
cnt++;
|
||||
snprintf(msg, sizeof msg, "%dx {%s} %s", cnt, origScript, result);
|
||||
snprintf(msg, sizeof msg, "%dx {%s}: %s", cnt, origScript, result);
|
||||
SetHdbProperty(node, eprop, msg);
|
||||
send = NULL;
|
||||
free(script);
|
||||
@@ -375,7 +395,12 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
state = result;
|
||||
if (strcasecmp(state, "idle") == 0 || strcasecmp(state, "unpoll") == 0) {
|
||||
if (queueData == data && !data->answered) {
|
||||
SCWrite(con, "o.k.", eWarning);
|
||||
if (queueData->inMacro == 0) {
|
||||
iMacro = SCinMacro(con);
|
||||
con->iMacro = 0;
|
||||
SCWrite(con, "o.k.", eWarning);
|
||||
SCsetMacro(con, iMacro);
|
||||
}
|
||||
}
|
||||
snprintf(eprop, sizeof eprop, "error_during_%s", data->name);
|
||||
emsg = GetHdbProp(node, eprop);
|
||||
@@ -396,8 +421,10 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
SetProp(node, controller->node, "state", state);
|
||||
free(script);
|
||||
script = NULL;
|
||||
send = GetProp(node, controller->node, "send");
|
||||
if (send != NULL && send[0] != '\0') {
|
||||
if (sct->sendCalled) {
|
||||
send = GetProp(node, controller->node, "send");
|
||||
if (send == NULL)
|
||||
send = "";
|
||||
if (controller->verbose) {
|
||||
SCPrintf(con, eLog, "send : %s", send);
|
||||
}
|
||||
@@ -522,7 +549,9 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
|
||||
char *error;
|
||||
SConnection *con;
|
||||
char path[MAX_HDB_PATH];
|
||||
|
||||
char *sicsCommand;
|
||||
int iMacro;
|
||||
|
||||
pm = GetKillPtrMessage(msg);
|
||||
if (pm != NULL) {
|
||||
if (data->controller == pm->pPtr) {
|
||||
@@ -554,7 +583,7 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
|
||||
if (script != NULL) {
|
||||
if (SctCallInContext(con, script, node, data->controller, &error) ==
|
||||
0) {
|
||||
SCPrintf(con, eError, "ERROR: %s", error);
|
||||
SCPrintf(con, eError, "ERROR: in {%s}: %s", script, error);
|
||||
SetHdbProperty(node, "target", NULL);
|
||||
return hdbAbort;
|
||||
}
|
||||
@@ -574,16 +603,19 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
|
||||
}
|
||||
|
||||
if (data->conCtx != NULL) {
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
SCPrintf(data->conCtx, eWarning,
|
||||
"%s target changed to %s before completion", path,
|
||||
GetCharArray(text));
|
||||
if (data->inMacro == 0) {
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
SCsetMacro(data->conCtx, 0);
|
||||
SCPrintf(data->conCtx, eWarning,
|
||||
"%s target changed to %s before completion", path,
|
||||
GetCharArray(text));
|
||||
}
|
||||
SCDeleteConnection(data->conCtx);
|
||||
}
|
||||
DeleteDynString(text);
|
||||
data->conCtx = SCCopyConnection(con);
|
||||
data->answered = 0;
|
||||
data->inMacro = con->iMacro;
|
||||
data->inMacro = SCinMacro(con);
|
||||
DevQueue(data->controller->devser, data, prio,
|
||||
SctWriteHandler, SctMatch, NULL);
|
||||
/* no kill function in DevQueue: data is owned by the node (callback list) */
|
||||
@@ -594,10 +626,20 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
|
||||
if (mm != NULL) {
|
||||
if (queueData != NULL && queueData->conCtx != NULL && !data->answered) {
|
||||
/* update called from a write action */
|
||||
data->answered = 1;
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
text = formatValue(*(mm->v), node);
|
||||
SCPrintf(queueData->conCtx, eWarning, "OK: %s set to: %s", path, GetCharArray(text));
|
||||
if (queueData->inMacro == 0 && queueData->node == node) {
|
||||
data->answered = 1;
|
||||
iMacro = SCinMacro(queueData->conCtx);
|
||||
SCsetMacro(queueData->conCtx, 0);
|
||||
sicsCommand = GetHdbProp(node, "sicscommand");
|
||||
if (sicsCommand) {
|
||||
SCPrintf(queueData->conCtx, eWarning, "OK: %s %s", sicsCommand, GetCharArray(text));
|
||||
} else {
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
SCPrintf(queueData->conCtx, eWarning, "OK: hset %s %s", path, GetCharArray(text));
|
||||
}
|
||||
SCsetMacro(queueData->conCtx, iMacro);
|
||||
}
|
||||
DeleteDynString(text);
|
||||
}
|
||||
return hdbContinue;
|
||||
@@ -1137,7 +1179,8 @@ static int SctMakeController(SConnection * con, SicsInterp * sics,
|
||||
return 0;
|
||||
|
||||
SetHdbProperty(controller->node, "controllerName", objName);
|
||||
|
||||
SetHdbProperty(controller->node, "sicsdev", objName);
|
||||
|
||||
AddCommand(pServ->pSics, objName, InterInvokeSICSOBJ, KillSICSOBJ, ccmd);
|
||||
RegisterSICSOBJKillCmd(ccmd, objName);
|
||||
SetDescriptorKey(ccmd->pDes, "creationCommand", "0");
|
||||
|
||||
Reference in New Issue
Block a user