- send debug message also on transact command

- small improvements
This commit is contained in:
zolliker
2009-11-10 08:04:24 +00:00
parent b8a0936b99
commit eb33c15016

View File

@@ -16,8 +16,6 @@
#include "scriptcontext.h" #include "scriptcontext.h"
#define MAX_HDB_PATH 1024
typedef struct ContextItem { typedef struct ContextItem {
struct ContextItem *next; struct ContextItem *next;
Hdb *node; Hdb *node;
@@ -197,7 +195,7 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
} }
Arg2Text(argc - 2, argv + 2, value, sizeof value); Arg2Text(argc - 2, argv + 2, value, sizeof value);
SCWrite(con, value, eWarning); SCWrite(con, value, eWarning);
SCsetMacro(con, 1); /* where are always in Macro */ SCsetMacro(con, 1); /* we are always in Macro */
return 1; return 1;
} }
@@ -350,10 +348,10 @@ static char *SctActionHandler(void *actionData, char *lastReply,
} }
/* /*
* When this is a followup, we use the content of the * When this is a followup, we use the content of the
* state field as the property storing the next script to * state field as the property storing the next script to
* run. If this is the start of a chain this is set to the * run. If this is the start of a chain this is set to the
* data->name which is either read or write * data->name which is mortly either read or write
*/ */
state = GetProp(node, controller->node, "state"); state = GetProp(node, controller->node, "state");
if (state == NULL || strcasecmp(state, "idle") == 0) { if (state == NULL || strcasecmp(state, "idle") == 0) {
@@ -368,10 +366,10 @@ static char *SctActionHandler(void *actionData, char *lastReply,
* then 10 scripts can be changed in this way. * then 10 scripts can be changed in this way.
*/ */
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
/* /*
* read the script to invoke from the property living * read the script to invoke from the property living
* in state * in state
*/ */
script = GetProp(node, controller->node, state); script = GetProp(node, controller->node, state);
if (script == NULL) if (script == NULL)
script = state; script = state;
@@ -391,9 +389,11 @@ static char *SctActionHandler(void *actionData, char *lastReply,
ret = SctCallInContext(con, script, node, controller, &result); ret = SctCallInContext(con, script, node, controller, &result);
sct->sendNode = NULL; sct->sendNode = NULL;
if (ret == 0) { if (ret == 0) {
/* /*
* an error occurred in the script: complain bitterly * an error occurred in the script: store error message in
*/ * a property, and write the error message the first time it
* occurs
*/
snprintf(eprop, sizeof eprop, "error_during_%s", data->name); snprintf(eprop, sizeof eprop, "error_during_%s", data->name);
emsg = GetHdbProp(node, eprop); emsg = GetHdbProp(node, eprop);
if (emsg == NULL || con != controller->conn) { if (emsg == NULL || con != controller->conn) {
@@ -403,6 +403,9 @@ static char *SctActionHandler(void *actionData, char *lastReply,
data->name, origScript, path, result); data->name, origScript, path, result);
} }
snprintf(msg, sizeof msg, "<%s> %s", origScript, result); snprintf(msg, sizeof msg, "<%s> %s", origScript, result);
if (strcasecmp(data->name, "read") == 0) {
SetHdbProperty(node, "geterror", result);
}
SetHdbProperty(node, eprop, msg); SetHdbProperty(node, eprop, msg);
blank = strchr(origScript, ' '); blank = strchr(origScript, ' ');
if (blank != NULL) { if (blank != NULL) {
@@ -433,15 +436,18 @@ static char *SctActionHandler(void *actionData, char *lastReply,
* and terminate the script chain * and terminate the script chain
*/ */
if (strcasecmp(state, "idle") == 0 || strcasecmp(state, "unpoll") == 0) { if (strcasecmp(state, "idle") == 0 || strcasecmp(state, "unpoll") == 0) {
/* if (queueData == data) { /* it was a write action */
* send an O.k. if there was no othe rreply on write's SetHdbProperty(node, "requested", NULL);
*/ if (!data->answered) {
if (queueData == data && !data->answered) { if (queueData->inMacro == 0) {
if (queueData->inMacro == 0) { /*
iMacro = SCinMacro(con); * send an O.k. if there was no other reply on write's
con->iMacro = 0; */
SCWrite(con, "o.k.", eValue); iMacro = SCinMacro(con);
SCsetMacro(con, iMacro); con->iMacro = 0;
SCWrite(con, "o.k.", eWarning);
SCsetMacro(con, iMacro);
}
} }
} }
snprintf(eprop, sizeof eprop, "error_during_%s", data->name); snprintf(eprop, sizeof eprop, "error_during_%s", data->name);
@@ -483,7 +489,9 @@ static char *SctActionHandler(void *actionData, char *lastReply,
SCPrintf(con, eLogError, "ERROR: too many quick scripts chained"); SCPrintf(con, eLogError, "ERROR: too many quick scripts chained");
finish: finish:
if (strcmp(data->name, "write") == 0) { if (strcmp(data->name, "write") == 0) {
SetProp(node, controller->node, "writestatus", "commandsent"); if (GetHdbProp(node, "writestatus") != NULL) {
SetHdbProperty(node, "writestatus", "commandsent");
}
} }
if (strcasecmp(state, "unpoll") == 0) { if (strcasecmp(state, "unpoll") == 0) {
DevUnschedule(controller->devser, data, SctActionHandler, SctMatch); DevUnschedule(controller->devser, data, SctActionHandler, SctMatch);
@@ -633,6 +641,7 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
/* set target value */ /* set target value */
text = formatValue(*(mm->v), node); text = formatValue(*(mm->v), node);
SetHdbProperty(node, "target", GetCharArray(text)); SetHdbProperty(node, "target", GetCharArray(text));
SetHdbProperty(node, "requested", GetCharArray(text));
/* call check script, if available */ /* call check script, if available */
script = GetProp(node, data->controller->node, "check"); script = GetProp(node, data->controller->node, "check");
@@ -1040,6 +1049,7 @@ typedef struct SctTransact {
char *command; char *command;
int sent; int sent;
SConnection *con; SConnection *con;
SctController *controller;
} SctTransact, *pSctTransact; } SctTransact, *pSctTransact;
static void KillSctTransact(void *data) static void KillSctTransact(void *data)
@@ -1064,9 +1074,15 @@ static char *TransactionHandler(void *actionData, char *lastReply,
if (st->sent == 0) { if (st->sent == 0) {
st->sent = 1; st->sent = 1;
if (st->controller->verbose) {
SCPrintf(st->con, eLog, "send : %s", st->command);
}
return st->command; return st->command;
} else { } else {
st->sent = 2; st->sent = 2;
if (st->controller->verbose) {
SCPrintf(st->con, eLog, "reply : %s", lastReply);
}
SCWrite(st->con, lastReply, eValue); SCWrite(st->con, lastReply, eValue);
return NULL; return NULL;
} }
@@ -1091,6 +1107,7 @@ static int SctTransactCmd(pSICSOBJ ccmd, SConnection * con,
} }
st->con = SCCopyConnection(con); st->con = SCCopyConnection(con);
st->command = strdup(par[0]->value.v.text); st->command = strdup(par[0]->value.v.text);
st->controller = c;
DevQueue(c->devser, st, WritePRIO, DevQueue(c->devser, st, WritePRIO,
TransactionHandler, SctTransactMatch, NULL); TransactionHandler, SctTransactMatch, NULL);
@@ -1121,6 +1138,7 @@ static int SctSendCmd(pSICSOBJ ccmd, SConnection * con,
} }
st->con = SCCopyConnection(con); st->con = SCCopyConnection(con);
st->command = strdup(par[0]->value.v.text); st->command = strdup(par[0]->value.v.text);
st->controller = c;
prioText = ParText(cmdNode, "prio", nPar, "write"); prioText = ParText(cmdNode, "prio", nPar, "write");
prio = DevText2Prio(prioText); prio = DevText2Prio(prioText);