- simplified devser queue
- added inherited sct variables starting with @ - inserted SctIsPending / DevIsPending - some general improvements in scriptcontext.c/sctdriveobj.c
This commit is contained in:
104
scriptcontext.c
104
scriptcontext.c
@@ -54,8 +54,6 @@ static struct {
|
||||
char *name;
|
||||
} actionCallback;
|
||||
|
||||
static char *mainCallback = "main callback";
|
||||
|
||||
void PushContext(Hdb * node, Hdb * controllerNode)
|
||||
{
|
||||
ContextItem *new;
|
||||
@@ -98,45 +96,58 @@ void CleanStack(Hdb * node)
|
||||
}
|
||||
}
|
||||
|
||||
static void SetProp(Hdb * node, Hdb * cNode, char *key, char *value)
|
||||
static char *GetPropAndNode(Hdb * node, Hdb * cNode, char *key, Hdb **foundNode)
|
||||
{
|
||||
char *val;
|
||||
Hdb *mama;
|
||||
|
||||
if (node == NULL) {
|
||||
if (cNode == NULL)
|
||||
return;
|
||||
node = cNode;
|
||||
} else {
|
||||
val = GetHdbProp(node, key);
|
||||
if (val == NULL && cNode != NULL) {
|
||||
val = GetHdbProp(cNode, key);
|
||||
if (key[0] == '@') {
|
||||
/* for keys starting with @ look also at the ancestors */
|
||||
for (mama = node; mama != NULL; mama = mama->mama) {
|
||||
val = GetHdbProp(mama, key);
|
||||
if (val != NULL) {
|
||||
node = cNode;
|
||||
*foundNode = mama;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node != NULL) {
|
||||
val = GetHdbProp(node, key);
|
||||
if (val != NULL) {
|
||||
*foundNode = node;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
if (cNode != NULL) {
|
||||
val = GetHdbProp(cNode, key);
|
||||
if (val != NULL) {
|
||||
*foundNode = cNode;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
*foundNode = node;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void SetProp(Hdb * node, Hdb * cNode, char *key, char *value)
|
||||
{
|
||||
Hdb *propNode;
|
||||
char *val;
|
||||
|
||||
val = GetPropAndNode(node, cNode, key, &propNode);
|
||||
if (value == NULL) {
|
||||
if (GetHdbProperty(node, key, NULL, 0) > 0) {
|
||||
SetHdbProperty(node, key, "");
|
||||
if (val != NULL) {
|
||||
SetHdbProperty(propNode, key, "");
|
||||
}
|
||||
} else {
|
||||
SetHdbProperty(node, key, value);
|
||||
SetHdbProperty(propNode, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
static char *GetProp(Hdb * node, Hdb * cNode, char *key)
|
||||
{
|
||||
char *val;
|
||||
|
||||
if (node != NULL) {
|
||||
val = GetHdbProp(node, key);
|
||||
if (val != NULL)
|
||||
return val;
|
||||
}
|
||||
if (cNode != NULL) {
|
||||
val = GetHdbProp(cNode, key);
|
||||
}
|
||||
return val;
|
||||
Hdb *propNode;
|
||||
return GetPropAndNode(node, cNode, key, &propNode);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -302,6 +313,7 @@ static int SctMatch(void *data1, void *data2)
|
||||
|
||||
return a->node == b->node && strcasecmp(a->name, b->name) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine is running the script chain. It is called repeatedly
|
||||
* with response data from the device serializer (devser). This function
|
||||
@@ -350,7 +362,7 @@ static char *SctActionHandler(void *actionData, char *lastReply,
|
||||
script = NULL;
|
||||
if (!commError && controller->verbose && lastReply != NULL
|
||||
&& *lastReply != '\0') {
|
||||
SCPrintf(con, eLog, "reply : %s", lastReply);
|
||||
SCPrintf(con, eLog, "reply : %s\n", lastReply);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -534,7 +546,7 @@ static int SctMatchNode(void *vNode, void *vData)
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the read callback for nodes participating in the
|
||||
* This is the callback for all nodes participating in the
|
||||
* scriptcontext system
|
||||
*/
|
||||
static hdbCallbackReturn SctMainCallback(Hdb * node, void *userData,
|
||||
@@ -584,11 +596,11 @@ static hdbCallbackReturn SctMainCallback(Hdb * node, void *userData,
|
||||
if (geterror != NULL) {
|
||||
snprintf(error,255,"ERROR: %s", geterror);
|
||||
SCWrite(con, error, eError);
|
||||
if(mm->v->dataType == HIPTEXT){
|
||||
if(mm->v->v.text != NULL){
|
||||
free(mm->v->v.text);
|
||||
}
|
||||
mm->v->v.text = strdup(error);
|
||||
if (mm->v->dataType == HIPTEXT) {
|
||||
if (mm->v->v.text != NULL) {
|
||||
free(mm->v->v.text);
|
||||
}
|
||||
mm->v->v.text = strdup(error);
|
||||
}
|
||||
return hdbAbort;
|
||||
}
|
||||
@@ -982,11 +994,7 @@ void SctQueueNode(SctController * controller, Hdb * node,
|
||||
SctData *data;
|
||||
hdbCallback *cb;
|
||||
|
||||
/*
|
||||
* The test for read below is questionable. If this becomes a problem
|
||||
* take it out and tell Mark and Markus about the fact.
|
||||
*/
|
||||
if (!FindHdbCallbackData(node, controller) && strcmp(action,"read") == 0) {
|
||||
if (!FindHdbCallbackData(node, controller)) {
|
||||
cb = MakeHipadabaCallback(SctMainCallback, controller, NULL);
|
||||
assert(cb);
|
||||
AppendHipadabaCallback(node, cb);
|
||||
@@ -1207,9 +1215,12 @@ static void SctKillController(void *c)
|
||||
{
|
||||
SctController *controller = c;
|
||||
SConnection *con;
|
||||
hdbPtrMessage m;
|
||||
|
||||
CleanStack(controller->node);
|
||||
RemoveSICSInternalCallback(controller);
|
||||
RemoveSICSInternalCallbackFrom(controller->node, controller);
|
||||
|
||||
if (controller->conn) {
|
||||
SCDeleteConnection(controller->conn);
|
||||
}
|
||||
@@ -1361,3 +1372,20 @@ int SctVerbose(SctController * c)
|
||||
{
|
||||
return c->verbose;
|
||||
}
|
||||
|
||||
int SctIsPending(SctController *controller, Hdb * node, char *name, int kind)
|
||||
{
|
||||
void *currentAction;
|
||||
|
||||
SctData data;
|
||||
data.node = node;
|
||||
data.name = name;
|
||||
switch (kind) {
|
||||
case 0:
|
||||
return DevIsPending(controller->devser, &data, SctWriteHandler, SctMatch);
|
||||
case 1:
|
||||
return DevIsPending(controller->devser, &data, SctActionHandler, SctMatch);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user