- allow scriptcontext objects to be dynamic
- enhancements in scriptcontext (error messages stored as properties)
This commit is contained in:
55
devser.c
55
devser.c
@ -24,14 +24,14 @@ struct DevSer {
|
||||
DevAction *current;
|
||||
int killCurrent;
|
||||
DevAction *actions; /* the action queue */
|
||||
DevAction *toKill; /* list of actions to be killed */
|
||||
SchedHeader *headers;
|
||||
ErrMsg *errmsg;
|
||||
int steps;
|
||||
int stopTask;
|
||||
};
|
||||
|
||||
static char *devPrio[NumberOfPRIO] = {
|
||||
"null", "slow", "read", "progress", "write", "halt"
|
||||
"null", "slow", "read", "progress", "write", "halt", "start"
|
||||
};
|
||||
|
||||
char *DevPrio2Text(DevPrio prio)
|
||||
@ -100,6 +100,9 @@ DevAction *DevNextAction(DevSer * devser)
|
||||
header->timeDue = (floor(now / header->interval) + 1)
|
||||
* header->interval;
|
||||
}
|
||||
} else if (header->prio == StartPRIO && header->actions != NULL) {
|
||||
/* special case: poll with StartPRIO pending: block all other actions */
|
||||
return devser->current;
|
||||
}
|
||||
}
|
||||
if (header->followingAction != NULL) {
|
||||
@ -123,13 +126,18 @@ int DevQueueTask(void *ds)
|
||||
AsconStatus status;
|
||||
DevAction *action;
|
||||
char *sendData;
|
||||
char *replyData;
|
||||
|
||||
char *replyData = NULL;
|
||||
|
||||
if (devser->steps == 0)
|
||||
return 1;
|
||||
if (devser->stopTask) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* deferred deallocation of removed actions */
|
||||
DevFreeActionList(devser->toKill);
|
||||
devser->toKill = NULL;
|
||||
|
||||
action = devser->current;
|
||||
if (action == NULL) {
|
||||
action = DevNextAction(devser);
|
||||
@ -138,19 +146,16 @@ int DevQueueTask(void *ds)
|
||||
while (action != NULL) {
|
||||
status = AsconTask(devser->asyncConn);
|
||||
if (status == AsconFailure) {
|
||||
devser->errmsg = AsconGetErrList(devser->asyncConn);
|
||||
} else if (status != AsconReady) {
|
||||
replyData = AsconGetError(devser->asyncConn);
|
||||
} else if (status == AsconReady) {
|
||||
replyData = AsconRead(devser->asyncConn);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
if (devser->steps > 0) { /* debugging mode */
|
||||
devser->steps--;
|
||||
}
|
||||
if (status == AsconFailure) {
|
||||
replyData = devser->errmsg->text;
|
||||
} else {
|
||||
replyData = AsconRead(devser->asyncConn);
|
||||
}
|
||||
sendData = action->hdl(action->data, replyData);
|
||||
sendData = action->hdl(action->data, replyData, (status == AsconFailure));
|
||||
if (sendData != NULL) {
|
||||
AsconWrite(devser->asyncConn, sendData, 0);
|
||||
return 1;
|
||||
@ -184,6 +189,7 @@ DevSer *DevMake(SConnection * con, int argc, char *argv[])
|
||||
devser->actions = NULL;
|
||||
devser->headers = NULL;
|
||||
devser->stopTask = 0;
|
||||
devser->toKill = NULL;
|
||||
devser->steps = -1; /* no debugging by default */
|
||||
TaskRegister(pServ->pTasker, DevQueueTask, NULL, DevKillTask, devser, 0);
|
||||
return devser;
|
||||
@ -216,6 +222,7 @@ void DevKill(DevSer * devser)
|
||||
AsconKill(devser->asyncConn);
|
||||
}
|
||||
DevFreeActionList(devser->actions);
|
||||
DevFreeActionList(devser->toKill);
|
||||
h = devser->headers;
|
||||
while (h != NULL) {
|
||||
victim = h;
|
||||
@ -223,6 +230,11 @@ void DevKill(DevSer * devser)
|
||||
DevFreeActionList(victim->actions);
|
||||
free(victim);
|
||||
}
|
||||
if (devser->killCurrent) {
|
||||
if (devser->current->kill != NULL) devser->current->kill(devser->current);
|
||||
devser->killCurrent = 0;
|
||||
free(devser->current);
|
||||
}
|
||||
if (devser->stopTask) {
|
||||
free(devser);
|
||||
} else {
|
||||
@ -286,9 +298,9 @@ int DevUnschedule(DevSer * devser, void *actionData,
|
||||
cnt++;
|
||||
/* remove from list */
|
||||
*ptr2Last = action->next;
|
||||
if (action->kill != NULL)
|
||||
action->kill(action->data);
|
||||
free(action);
|
||||
/* add to kill list */
|
||||
action->next = devser->toKill;
|
||||
devser->toKill = action;
|
||||
} else {
|
||||
ptr2Last = &action->next;
|
||||
}
|
||||
@ -360,12 +372,13 @@ int DevRemoveAction(DevSer * devser, void *actionData)
|
||||
{
|
||||
SchedHeader *header = NULL;
|
||||
DevAction **ptr2Last = NULL;
|
||||
DevAction *action = NULL;
|
||||
DevAction *action = NULL;
|
||||
int cnt = 0;
|
||||
|
||||
|
||||
/* Remove current action, if matched. If a reply is pending, the next action will
|
||||
get the reply. But as in the inital state no reply is expected, this should not harm. */
|
||||
|
||||
|
||||
/* Remove current action, if matched. If a reply is pending, the next
|
||||
action will get the reply. But as in the inital state no reply is
|
||||
expected, this should not harm. */
|
||||
action = devser->current;
|
||||
if (action != NULL && actionData == action->data) {
|
||||
if (devser->killCurrent) {
|
||||
@ -378,7 +391,7 @@ int DevRemoveAction(DevSer * devser, void *actionData)
|
||||
}
|
||||
/* remove from queue */
|
||||
ptr2Last = &devser->actions;
|
||||
for (action = devser->actions; action != NULL; action = action->next) {
|
||||
for (action = devser->actions; action != NULL; action = *ptr2Last) {
|
||||
if (actionData == action->data) {
|
||||
cnt++;
|
||||
/* remove from list */
|
||||
|
Reference in New Issue
Block a user