- 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"
#define MAX_HDB_PATH 1024
typedef struct ContextItem {
struct ContextItem *next;
Hdb *node;
@@ -197,7 +195,7 @@ int SctCommand(SConnection * con, SicsInterp * sics, void *object,
}
Arg2Text(argc - 2, argv + 2, value, sizeof value);
SCWrite(con, value, eWarning);
SCsetMacro(con, 1); /* where are always in Macro */
SCsetMacro(con, 1); /* we are always in Macro */
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
* 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");
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.
*/
for (i = 0; i < 10; i++) {
/*
* read the script to invoke from the property living
* in state
*/
/*
* read the script to invoke from the property living
* in state
*/
script = GetProp(node, controller->node, state);
if (script == NULL)
script = state;
@@ -391,9 +389,11 @@ static char *SctActionHandler(void *actionData, char *lastReply,
ret = SctCallInContext(con, script, node, controller, &result);
sct->sendNode = NULL;
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);
emsg = GetHdbProp(node, eprop);
if (emsg == NULL || con != controller->conn) {
@@ -403,6 +403,9 @@ static char *SctActionHandler(void *actionData, char *lastReply,
data->name, origScript, path, result);
}
snprintf(msg, sizeof msg, "<%s> %s", origScript, result);
if (strcasecmp(data->name, "read") == 0) {
SetHdbProperty(node, "geterror", result);
}
SetHdbProperty(node, eprop, msg);
blank = strchr(origScript, ' ');
if (blank != NULL) {
@@ -433,15 +436,18 @@ static char *SctActionHandler(void *actionData, char *lastReply,
* and terminate the script chain
*/
if (strcasecmp(state, "idle") == 0 || strcasecmp(state, "unpoll") == 0) {
/*
* send an O.k. if there was no othe rreply on write's
*/
if (queueData == data && !data->answered) {
if (queueData->inMacro == 0) {
iMacro = SCinMacro(con);
con->iMacro = 0;
SCWrite(con, "o.k.", eValue);
SCsetMacro(con, iMacro);
if (queueData == data) { /* it was a write action */
SetHdbProperty(node, "requested", NULL);
if (!data->answered) {
if (queueData->inMacro == 0) {
/*
* send an O.k. if there was no other reply on write's
*/
iMacro = SCinMacro(con);
con->iMacro = 0;
SCWrite(con, "o.k.", eWarning);
SCsetMacro(con, iMacro);
}
}
}
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");
finish:
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) {
DevUnschedule(controller->devser, data, SctActionHandler, SctMatch);
@@ -633,6 +641,7 @@ static hdbCallbackReturn SctActionCallback(Hdb * node, void *userData,
/* set target value */
text = formatValue(*(mm->v), node);
SetHdbProperty(node, "target", GetCharArray(text));
SetHdbProperty(node, "requested", GetCharArray(text));
/* call check script, if available */
script = GetProp(node, data->controller->node, "check");
@@ -1040,6 +1049,7 @@ typedef struct SctTransact {
char *command;
int sent;
SConnection *con;
SctController *controller;
} SctTransact, *pSctTransact;
static void KillSctTransact(void *data)
@@ -1064,9 +1074,15 @@ static char *TransactionHandler(void *actionData, char *lastReply,
if (st->sent == 0) {
st->sent = 1;
if (st->controller->verbose) {
SCPrintf(st->con, eLog, "send : %s", st->command);
}
return st->command;
} else {
st->sent = 2;
if (st->controller->verbose) {
SCPrintf(st->con, eLog, "reply : %s", lastReply);
}
SCWrite(st->con, lastReply, eValue);
return NULL;
}
@@ -1091,6 +1107,7 @@ static int SctTransactCmd(pSICSOBJ ccmd, SConnection * con,
}
st->con = SCCopyConnection(con);
st->command = strdup(par[0]->value.v.text);
st->controller = c;
DevQueue(c->devser, st, WritePRIO,
TransactionHandler, SctTransactMatch, NULL);
@@ -1121,6 +1138,7 @@ static int SctSendCmd(pSICSOBJ ccmd, SConnection * con,
}
st->con = SCCopyConnection(con);
st->command = strdup(par[0]->value.v.text);
st->controller = c;
prioText = ParText(cmdNode, "prio", nPar, "write");
prio = DevText2Prio(prioText);