- Adapted indenation to new agreed upon system

- Added support for second generation scriptcontext based counter
This commit is contained in:
koennecke
2009-02-13 09:00:03 +00:00
parent a3dcad2bfa
commit 91d4af0541
405 changed files with 88101 additions and 88173 deletions

154
devser.c
View File

@ -12,7 +12,7 @@ typedef struct DevAction {
typedef struct SchedHeader {
struct SchedHeader *next;
DevAction *actions; /* list of actions for given interval and prio */
DevAction *actions; /* list of actions for given interval and prio */
DevAction *followingAction;
double interval;
double timeDue;
@ -20,48 +20,54 @@ typedef struct SchedHeader {
} SchedHeader;
struct DevSer {
Ascon *asyncConn; /* connection */
Ascon *asyncConn; /* connection */
DevAction *current;
int killCurrent;
DevAction *actions; /* the action queue */
DevAction *actions; /* the action queue */
SchedHeader *headers;
ErrMsg *errmsg;
int steps;
int stopTask;
};
static char *devPrio[NumberOfPRIO] = {
"null", "slow", "read", "progress", "write", "halt"
};
char *DevPrio2Text(DevPrio prio) {
char *DevPrio2Text(DevPrio prio)
{
if (prio <= 0 || prio >= NumberOfPRIO) {
prio = NullPRIO;
}
return devPrio[prio];
return devPrio[prio];
}
DevPrio DevText2Prio(char *text) {
DevPrio DevText2Prio(char *text)
{
DevPrio prio;
for (prio = 0; prio < NumberOfPRIO; prio++) {
if (strcasecmp(text, devPrio[prio]) == 0) return prio;
if (strcasecmp(text, devPrio[prio]) == 0)
return prio;
}
return NullPRIO;
}
static void DevFreeActionList(DevAction *actions) {
static void DevFreeActionList(DevAction * actions)
{
DevAction *victim;
while (actions != NULL) {
victim = actions;
actions = victim->next;
if (victim->kill != NULL) victim->kill(victim->data);
if (victim->kill != NULL)
victim->kill(victim->data);
free(victim);
}
}
static void DevKillTask(void *ds) {
static void DevKillTask(void *ds)
{
DevSer *devser = ds;
if (devser->stopTask) {
free(devser);
} else {
@ -69,11 +75,12 @@ static void DevKillTask(void *ds) {
}
}
DevAction *DevNextAction(DevSer *devser) {
DevAction *DevNextAction(DevSer * devser)
{
DevPrio prio;
double now;
SchedHeader *header;
devser->current = NULL;
if (devser->actions) {
@ -83,8 +90,7 @@ DevAction *DevNextAction(DevSer *devser) {
}
now = DoubleTime();
for (header = devser->headers;
header != NULL && header->prio > prio;
header = header->next) {
header != NULL && header->prio > prio; header = header->next) {
if (header->followingAction == NULL) {
if (now >= header->timeDue) {
header->followingAction = header->actions;
@ -92,7 +98,7 @@ DevAction *DevNextAction(DevSer *devser) {
header->timeDue = now;
} else {
header->timeDue = (floor(now / header->interval) + 1)
* header->interval;
* header->interval;
}
}
}
@ -111,14 +117,16 @@ DevAction *DevNextAction(DevSer *devser) {
return devser->current;
}
int DevQueueTask(void *ds) {
int DevQueueTask(void *ds)
{
DevSer *devser = ds;
AsconStatus status;
DevAction *action;
char *sendData;
char *replyData;
if (devser->steps == 0) return 1;
if (devser->steps == 0)
return 1;
if (devser->stopTask) {
return 0;
}
@ -134,10 +142,10 @@ int DevQueueTask(void *ds) {
} else if (status != AsconReady) {
return 1;
}
if (devser->steps > 0) { /* debugging mode */
if (devser->steps > 0) { /* debugging mode */
devser->steps--;
}
if(status == AsconFailure){
if (status == AsconFailure) {
replyData = devser->errmsg->text;
} else {
replyData = AsconRead(devser->asyncConn);
@ -148,7 +156,8 @@ int DevQueueTask(void *ds) {
return 1;
}
if (devser->killCurrent) {
if (action->kill != NULL) action->kill(action->data);
if (action->kill != NULL)
action->kill(action->data);
devser->killCurrent = 0;
free(action);
devser->current = NULL;
@ -158,10 +167,11 @@ int DevQueueTask(void *ds) {
return 1;
}
DevSer *DevMake(SConnection *con, int argc, char *argv[]) {
DevSer *DevMake(SConnection * con, int argc, char *argv[])
{
DevSer *devser = NULL;
Ascon *asyncConn = NULL;
asyncConn = AsconMake(con, argc, argv);
if (!asyncConn) {
return NULL;
@ -174,17 +184,19 @@ DevSer *DevMake(SConnection *con, int argc, char *argv[]) {
devser->actions = NULL;
devser->headers = NULL;
devser->stopTask = 0;
devser->steps = -1; /* no debugging by default */
devser->steps = -1; /* no debugging by default */
TaskRegister(pServ->pTasker, DevQueueTask, NULL, DevKillTask, devser, 0);
return devser;
}
void DevDebugMode(DevSer *devser, int steps) {
void DevDebugMode(DevSer * devser, int steps)
{
devser->steps = steps;
}
DevAction *DevNewAction(void *data, DevActionHandler hdl,
DevKillActionData *killFunc, DevPrio prio) {
DevKillActionData * killFunc, DevPrio prio)
{
DevAction *action;
action = calloc(1, sizeof(*action));
assert(action);
@ -196,7 +208,8 @@ DevAction *DevNewAction(void *data, DevActionHandler hdl,
return action;
}
void DevKill(DevSer *devser) {
void DevKill(DevSer * devser)
{
SchedHeader *h, *victim;
if (devser->asyncConn) {
@ -217,24 +230,29 @@ void DevKill(DevSer *devser) {
}
}
void DevDisconnect(DevSer *devser){
if(devser->asyncConn){
AsconDisconnect(devser->asyncConn);
}
void DevDisconnect(DevSer * devser)
{
if (devser->asyncConn) {
AsconDisconnect(devser->asyncConn);
}
}
int DevQueue(DevSer *devser, void *actionData, DevPrio prio,
DevActionHandler hdl, DevActionMatch *matchFunc,
DevKillActionData *killFunc) {
int DevQueue(DevSer * devser, void *actionData, DevPrio prio,
DevActionHandler hdl, DevActionMatch * matchFunc,
DevKillActionData * killFunc)
{
DevAction *action, **ptr2Last;
DevAction *new;
if (prio <= NullPRIO) prio = NullPRIO + 1;
if (prio >= NumberOfPRIO) prio = NumberOfPRIO - 1;
if (prio <= NullPRIO)
prio = NullPRIO + 1;
if (prio >= NumberOfPRIO)
prio = NumberOfPRIO - 1;
ptr2Last = &devser->actions;
for (action = devser->actions; action != NULL && action->prio >= prio; action = action->next) {
for (action = devser->actions; action != NULL && action->prio >= prio;
action = action->next) {
if (action->hdl == hdl && matchFunc(actionData, action->data)) {
return 0; /* there is already an identical action */
return 0; /* there is already an identical action */
}
ptr2Last = &action->next;
}
@ -244,30 +262,32 @@ int DevQueue(DevSer *devser, void *actionData, DevPrio prio,
return 1;
}
int DevUnschedule(DevSer *devser, void *actionData,
DevActionHandler hdl, DevActionMatch *matchFunc) {
int DevUnschedule(DevSer * devser, void *actionData,
DevActionHandler hdl, DevActionMatch * matchFunc)
{
SchedHeader *header = NULL;
DevAction **ptr2Last = NULL;
DevAction *action = NULL;
int cnt=0;
DevAction *action = NULL;
int cnt = 0;
/* scan through all headers */
for (header = devser->headers; header != NULL; header = header->next) {
ptr2Last = &header->actions;
for (action = header->actions; action != NULL; action = *ptr2Last) {
if (action->hdl == hdl && matchFunc(actionData, action->data)) {
if (action == header->followingAction) {
/* advance followingAction if equal*/
/* advance followingAction if equal */
header->followingAction = action->next;
}
if (action == devser->current) {
devser->current = NULL;
devser->killCurrent = 0; /* should already be 0 */
devser->killCurrent = 0; /* should already be 0 */
}
cnt++;
/* remove from list */
*ptr2Last = action->next;
if (action->kill != NULL) action->kill(action->data);
if (action->kill != NULL)
action->kill(action->data);
free(action);
} else {
ptr2Last = &action->next;
@ -277,10 +297,11 @@ int DevUnschedule(DevSer *devser, void *actionData,
return cnt;
}
int DevSchedule(DevSer *devser, void *actionData,
int DevSchedule(DevSer * devser, void *actionData,
DevPrio prio, double interval,
DevActionHandler hdl, DevActionMatch *matchFunc,
DevKillActionData *killFunc) {
DevActionHandler hdl, DevActionMatch * matchFunc,
DevKillActionData * killFunc)
{
SchedHeader *header = NULL;
SchedHeader **ptr2LastHeader = NULL;
SchedHeader *newHeader;
@ -289,10 +310,12 @@ int DevSchedule(DevSer *devser, void *actionData,
DevAction *newAction;
int ret;
if (prio <= NullPRIO) prio = NullPRIO + 1;
if (prio >= NumberOfPRIO) prio = NumberOfPRIO - 1;
if (prio <= NullPRIO)
prio = NullPRIO + 1;
if (prio >= NumberOfPRIO)
prio = NumberOfPRIO - 1;
ret = DevUnschedule(devser, actionData, hdl, matchFunc);
newAction = DevNewAction(actionData, hdl, killFunc, prio);
/* find matching header */
ptr2LastHeader = &devser->headers;
@ -300,7 +323,7 @@ int DevSchedule(DevSer *devser, void *actionData,
if (header->prio == newAction->prio && header->interval == interval) {
/* append new action at the tail */
ptr2Last = &header->actions;
for (action = header->actions; action != NULL; action=action->next) {
for (action = header->actions; action != NULL; action = action->next) {
ptr2Last = &action->next;
}
*ptr2Last = newAction;
@ -319,7 +342,7 @@ int DevSchedule(DevSer *devser, void *actionData,
ptr2LastHeader = &header->next;
}
}
/* insert new header */
newHeader = calloc(1, sizeof(*newHeader));
assert(newHeader);
@ -333,19 +356,21 @@ int DevSchedule(DevSer *devser, void *actionData,
return ret;
}
int DevRemoveAction(DevSer *devser, void *actionData) {
int DevRemoveAction(DevSer * devser, void *actionData)
{
SchedHeader *header = NULL;
DevAction **ptr2Last = NULL;
DevAction *action = NULL;
int cnt=0;
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. */
action = devser->current;
if (action != NULL && actionData == action->data) {
if (devser->killCurrent) {
if (action->kill != NULL) action->kill(action->data);
if (action->kill != NULL)
action->kill(action->data);
devser->killCurrent = 0;
free(action);
}
@ -358,7 +383,8 @@ int DevRemoveAction(DevSer *devser, void *actionData) {
cnt++;
/* remove from list */
*ptr2Last = action->next;
if (action->kill != NULL) action->kill(action->data);
if (action->kill != NULL)
action->kill(action->data);
free(action);
} else {
ptr2Last = &action->next;