- send debug message also on transact command
- small improvements
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +351,7 @@ 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) {
|
||||||
@@ -392,7 +390,9 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
|||||||
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);
|
||||||
@@ -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,17 +436,20 @@ 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 */
|
||||||
|
SetHdbProperty(node, "requested", NULL);
|
||||||
|
if (!data->answered) {
|
||||||
|
if (queueData->inMacro == 0) {
|
||||||
/*
|
/*
|
||||||
* send an O.k. if there was no other reply on write's
|
* send an O.k. if there was no other reply on write's
|
||||||
*/
|
*/
|
||||||
if (queueData == data && !data->answered) {
|
|
||||||
if (queueData->inMacro == 0) {
|
|
||||||
iMacro = SCinMacro(con);
|
iMacro = SCinMacro(con);
|
||||||
con->iMacro = 0;
|
con->iMacro = 0;
|
||||||
SCWrite(con, "o.k.", eValue);
|
SCWrite(con, "o.k.", eWarning);
|
||||||
SCsetMacro(con, iMacro);
|
SCsetMacro(con, iMacro);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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) {
|
if (emsg != NULL) {
|
||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user