- fixed mess with SCWrite / SCPrintf due to changes in conman.c

This commit is contained in:
2017-06-14 15:44:34 +02:00
parent 11d6308834
commit 199c8cde5f
2 changed files with 58 additions and 49 deletions

View File

@ -34,7 +34,7 @@ struct SctController {
DevSer *devser; DevSer *devser;
Hdb *node; /* the controller node */ Hdb *node; /* the controller node */
SConnection *conn; SConnection *conn;
int verbose; SConnection *debugConn;
FILE *fd; FILE *fd;
}; };
@ -337,13 +337,13 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
int ret, l; int ret, l;
char *result = NULL; char *result = NULL;
int iRet = 1; int iRet = 1;
int verbose = controller->verbose;
char path[MAX_HDB_PATH]; char path[MAX_HDB_PATH];
PushContext(node, controller); PushContext(node, controller);
if (verbose) { if (controller->debugConn) {
GetHdbPath(node, path, sizeof path); GetHdbPath(node, path, sizeof path);
SCPrintf(con, eLog, "%6.3f script: (on %s) %s", secondsOfMinute(), path, script); SCPf(SCPureSockWrite, controller->debugConn, eLog,
"%6.3f script: (on %s) %s", secondsOfMinute(), path, script);
} }
if (controller->fd != NULL) { if (controller->fd != NULL) {
GetHdbPath(node, path, sizeof path); GetHdbPath(node, path, sizeof path);
@ -362,8 +362,9 @@ int SctCallInContext(SConnection * con, char *script, Hdb * node,
result++; result++;
} }
} }
if (verbose) { if (controller->debugConn) {
SCPrintf(con, eLog, "%6.3f error: %s", secondsOfMinute(), result); SCPf(SCPureSockWrite, controller->debugConn, eLog,
"%6.3f error: %s", secondsOfMinute(), result);
} }
if(controller->fd != NULL){ if(controller->fd != NULL){
fprintf(controller->fd, "%6.3f error: %s\n", secondsOfMinute(), result); fprintf(controller->fd, "%6.3f error: %s\n", secondsOfMinute(), result);
@ -438,8 +439,9 @@ static char *SctActionHandler(void *actionData, char *lastReply,
if (lastReply != NULL) { if (lastReply != NULL) {
SetProp(node, controller->node, "result", lastReply); SetProp(node, controller->node, "result", lastReply);
if (*lastReply != '\0') { if (*lastReply != '\0') {
if (!commError && controller->verbose) { if (!commError && controller->debugConn) {
SCPrintf(con, eLog, "%6.3f reply : %s\n", secondsOfMinute(), lastReply); SCPf(SCPureSockWrite, controller->debugConn, eLog,
"%6.3f reply : %s\n", secondsOfMinute(), lastReply);
} }
if(!commError && controller->fd != NULL) { if(!commError && controller->fd != NULL) {
fprintf(controller->fd, "%6.3f reply : %s\n", secondsOfMinute(), lastReply); fprintf(controller->fd, "%6.3f reply : %s\n", secondsOfMinute(), lastReply);
@ -518,9 +520,8 @@ static char *SctActionHandler(void *actionData, char *lastReply,
emsg = GetHdbProp(node, eprop); emsg = GetHdbProp(node, eprop);
if (emsg == NULL || con != controller->conn) { if (emsg == NULL || con != controller->conn) {
GetHdbPath(node, path, sizeof path); GetHdbPath(node, path, sizeof path);
snprintf(msg,sizeof(msg),"ERROR: action {%s} in {%s} node %s:\nERROR: %s", SCPrintf(con, eLogError,
data->name, origScript, path, result); "ERROR: action {%s} in {%s} node %s:\nERROR: %s", data->name, origScript, path, result);
SCPureSockWrite(con, msg,eLogError);
if(data != NULL && data->controller != NULL){ if(data != NULL && data->controller != NULL){
traceIO(data->controller->node->name, "ERROR: action {%s} in {%s} node %s:ERROR: %s", traceIO(data->controller->node->name, "ERROR: action {%s} in {%s} node %s:ERROR: %s",
data->name, origScript, path, result); data->name, origScript, path, result);
@ -602,7 +603,7 @@ static char *SctActionHandler(void *actionData, char *lastReply,
*/ */
iMacro = SCinMacro(con); iMacro = SCinMacro(con);
con->iMacro = 0; con->iMacro = 0;
SCPureSockWrite(con, "o.k.", eLog); SCWrite(con, "o.k.", eLog);
SCsetMacro(con, iMacro); SCsetMacro(con, iMacro);
} }
} }
@ -638,9 +639,9 @@ static char *SctActionHandler(void *actionData, char *lastReply,
send = GetProp(node, controller->node, "send"); send = GetProp(node, controller->node, "send");
if (send == NULL) if (send == NULL)
send = ""; send = "";
if (controller->verbose) { if (controller->debugConn) {
snprintf(msg,sizeof(msg),"%6.3f send : %s", secondsOfMinute(), send); SCPf(SCPureSockWrite, controller->debugConn, eLog,
SCPureSockWrite(con, msg,eLog); "%6.3f send : %s", secondsOfMinute(), send);
} }
if (controller->fd != NULL) { if (controller->fd != NULL) {
fprintf(controller->fd, "%6.3f send : %s\n", secondsOfMinute(), send); fprintf(controller->fd, "%6.3f send : %s\n", secondsOfMinute(), send);
@ -1469,8 +1470,9 @@ 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) { if (st->controller->debugConn) {
SCPrintf(st->con, eLog, "%6.3f send : %s", secondsOfMinute(), st->command); SCPf(SCPureSockWrite, st->controller->debugConn, eLog,
"%6.3f send : %s", secondsOfMinute(), st->command);
} }
if (st->controller->fd != NULL) { if (st->controller->fd != NULL) {
fprintf(st->controller->fd, "%6.3f send : %s\n", secondsOfMinute(), st->command); fprintf(st->controller->fd, "%6.3f send : %s\n", secondsOfMinute(), st->command);
@ -1506,8 +1508,9 @@ static char *SendHandler(void *actionData, char *lastReply,
if (st->sent == 2) { if (st->sent == 2) {
SetHdbProperty(st->controller->node, "reply", lastReply); SetHdbProperty(st->controller->node, "reply", lastReply);
if (st->controller->verbose) { if (st->controller->debugConn) {
SCPrintf(st->con, eLog, "%6.3f reply : %s", secondsOfMinute(), lastReply); SCPf(SCPureSockWrite, st->controller->debugConn, eLog,
"%6.3f reply : %s", secondsOfMinute(), lastReply);
} }
if (st->controller->fd != NULL) { if (st->controller->fd != NULL) {
fprintf(st->controller->fd, "%6.3f reply : %s\n", secondsOfMinute(), lastReply); fprintf(st->controller->fd, "%6.3f reply : %s\n", secondsOfMinute(), lastReply);
@ -1802,29 +1805,34 @@ static int SctLog(pSICSOBJ ccmd, SConnection * con,
return 1; return 1;
} }
static hdbCallbackReturn SctDebugCallback(Hdb * node, void *userData, static int SctDebug(pSICSOBJ ccmd, SConnection * con,
hdbMessage * msg) Hdb * cmdNode, Hdb * par[], int nPar)
{ {
hdbDataMessage *mm; SctController *c;
SctController *controller = userData; char *result;
SConnection *con; hdbValue *v = &cmdNode->child->value;
int i; int value;
mm = GetHdbSetMessage(msg); c = (SctController *) ccmd->pPrivate;
if (mm != NULL) { if (nPar != 0) {
i = mm->v->v.intValue; value = v->v.intValue;
if (i < 0) { if (c->debugConn) {
controller->verbose = 0; SCDeleteConnection(c->debugConn);
DevDebugMode(controller->devser, -1); }
} else if (i == 0) { if (value < 0) {
controller->verbose = 1; c->debugConn = NULL;
DevDebugMode(controller->devser, -1); DevDebugMode(c->devser, -1);
} else { } else {
controller->verbose = 1; c->debugConn = SCCopyConnection(con);
DevDebugMode(controller->devser, i); if (value == 0) {
DevDebugMode(c->devser, -1);
} else {
DevDebugMode(c->devser, value);
}
} }
} }
return hdbContinue; SCPrintf(con, eValue, "%d", v->v.intValue);
return 1;
} }
static void SctDeferredFree(void *data) static void SctDeferredFree(void *data)
@ -1851,6 +1859,9 @@ static void SctKillController(void *c)
if (controller->conn) { if (controller->conn) {
SCDeleteConnection(controller->conn); SCDeleteConnection(controller->conn);
} }
if (controller->debugConn) {
SCDeleteConnection(controller->debugConn);
}
DevKill(controller->devser); DevKill(controller->devser);
controller->devser = NULL; controller->devser = NULL;
@ -1896,7 +1907,7 @@ static int SctMakeController(SConnection * con, SicsInterp * sics,
controller = calloc(1, sizeof(*controller)); controller = calloc(1, sizeof(*controller));
assert(controller); assert(controller);
controller->verbose = 0; controller->debugConn = NULL;
ccmd = MakeSICSOBJv(objName, "SctController", HIPNONE, usSpy); ccmd = MakeSICSOBJv(objName, "SctController", HIPNONE, usSpy);
controller->node = ccmd->objectNode; controller->node = ccmd->objectNode;
@ -1986,8 +1997,6 @@ static int SctMakeController(SConnection * con, SicsInterp * sics,
"reconnect", usMugger, MakeSICSFunc(SctReconnect)); "reconnect", usMugger, MakeSICSFunc(SctReconnect));
AddSICSHdbPar(cmd, "hostport", usMugger, MakeHdbText("")); AddSICSHdbPar(cmd, "hostport", usMugger, MakeHdbText(""));
par = AddSICSHdbPar(controller->node, "debug", usUser, MakeHdbInt(-1));
cmd = AddSICSHdbPar(controller->node, cmd = AddSICSHdbPar(controller->node,
"actions", usUser, MakeSICSFunc(SctListActions)); "actions", usUser, MakeSICSFunc(SctListActions));
@ -2011,9 +2020,9 @@ static int SctMakeController(SConnection * con, SicsInterp * sics,
/* get the actual timeout value */ /* get the actual timeout value */
SctTimeout(ccmd, con, cmd, &par, 0); SctTimeout(ccmd, con, cmd, &par, 0);
cb = MakeHipadabaCallback(SctDebugCallback, controller, NULL); cmd = AddSICSHdbPar(controller->node, "debug", usUser, MakeSICSFunc(SctDebug));
if (cb) AddSICSHdbPar(cmd, "value", usUser, MakeHdbInt(-1));
AppendHipadabaCallback(par, cb);
return 1; return 1;
} }
@ -2050,9 +2059,9 @@ void SctInit(void)
AddCmd("makesctcomtask", SctMakeComTask); AddCmd("makesctcomtask", SctMakeComTask);
} }
int SctVerbose(SctController * c) SConnection *SctDebugConn(SctController * c)
{ {
return c->verbose; return c->debugConn;
} }
DevSer *SctGetDevser(void *data) DevSer *SctGetDevser(void *data)

View File

@ -30,11 +30,11 @@ void SctQueueNode(SctController * controller, Hdb * node,
int SctCallInContext(SConnection * con, char *script, Hdb * node, int SctCallInContext(SConnection * con, char *script, Hdb * node,
SctController * controller, char **resPtr); SctController * controller, char **resPtr);
/** /**
* test the controller verbose flag * get the controller debug connection (if any)
* \param c The SctController to test * \param c The SctController
* \return 1 for verbose, 0 for silent * \return the connection for verbose, NULL for silent
*/ */
int SctVerbose(SctController * c); SConnection *SctDebugConn(SctController * c);
/** /**
* retrieve the device serializer * retrieve the device serializer
* \param data A pointer to a SICSObject representing a SctController * \param data A pointer to a SICSObject representing a SctController