- various enhancements

This commit is contained in:
zolliker
2008-01-18 07:35:34 +00:00
parent a3df7d2729
commit 661df39166
11 changed files with 165 additions and 118 deletions

View File

@ -128,7 +128,7 @@ int ParPrintf(void *object, int iOut, const char *fmt, ...) {
if (ctx && pobj == ctx->obj && ctx->con) {
con = ctx->con;
} else {
con = SCLoad(&pobj->conn);
con = SCLoad(pobj->conn);
}
} else if (ctx) {
con = ctx->con;
@ -278,17 +278,27 @@ int ParLog(void *object) {
ParData *o = ParCheck(&parClass, object);
int next;
if (o->desc == NULL) {
free(o);
return 0;
}
if (o->logPending == 2) {
o->logPending = 0;
return 0;
}
ParBegin();
ctx->now = time(NULL);
next = ctx->now - (o->logTime / o->period + 1) * o->period;
if (next >= 0) {
showTime = 1;
ParDo(0, o, PAR_LOG, NULL);
o->logTime = ctx->now;
o->logPending = 0;
if (next < 0) {
ParEnd();
return 1;
}
showTime = 1;
ParDo(0, o, PAR_LOG, NULL);
o->logTime = ctx->now;
o->logPending = 0;
ParEnd();
return next;
return 0;
}
/*--------------------------------------------------------------------------*/
void ParLogForced(void *object) {
@ -300,7 +310,9 @@ void ParLogForced(void *object) {
showTime = 1;
ParDo(0, o, PAR_LOG, NULL);
o->logTime = ctx->now;
o->logPending = 0;
if (o->logPending) {
o->logPending = 2; /* tell ParLog that we are done already, but task is still pending */
}
ParEnd();
}
/*-------------------------------------------------------------------------*/
@ -382,7 +394,7 @@ void ParSaveConn(void *object, SConnection *con) {
rights = SCGetRights(con);
if (rights >= usMugger && rights <= usUser && con->pSock != NULL) {
SCSave(&o->conn, con);
o->conn = SCSave(con, o->conn);
}
}
/*----------------------------------------------------------------------------*/
@ -457,6 +469,10 @@ static int ParExecute(SConnection *con, SicsInterp *sics, void *object, int argc
ctx->enumText = 1;
ParDo(con, o, PAR_SHOW, argv[2]);
}
} else if (strcmp(argv[1],"endinit") == 0) {
initObj = NULL;
ParEnd();
return 1;
} else {
if (strcmp(argv[1], "=") == 0) {
ctx->argc = argc - 2;
@ -1198,13 +1214,7 @@ void *ParObject(void) {
return ctx->obj;
}
/*----------------------------------------------------------------------------*/
static int ParEndInit(void *object, void *arg, int argc, char *argv[]) {
initObj = NULL;
return 1;
}
/*----------------------------------------------------------------------------*/
void ParStdDef(void) {
ParName("endinit"); ParCmd(ParEndInit, NULL);
ParName("verbose"); ParAccess(usUser); ParSave(0); ParLogAs(NULL); ParInt(&ctx->obj->verbose, 1);
ParName("driver"); ParLogAs(NULL); ParStr(&ctx->obj->desc->name, NULL);
ParName("creationCmd"); ParLogAs(NULL); ParStr(&ctx->obj->creationCmd, NULL);
@ -1238,6 +1248,7 @@ void ParKill(void *object) {
if (o->creationCmd) free(o->creationCmd);
if (o->pCall) DeleteCallBackInterface(o->pCall);
if (o->desc) DeleteDescriptor(o->desc);
if (o->conn) SCStoreFree(o->conn);
p = o->infoList;
while (p) {
q = p->next;
@ -1246,7 +1257,11 @@ void ParKill(void *object) {
free(p);
p = q;
}
free(o);
if (o->logPending) { /* will be free in scheduled ParLog function */
o->desc = NULL;
} else {
free(o);
}
ParEnd();
if (ctx == NULL && pServ->pSics->iDeleting) { /* finish, no more contexts nested -> free all of them */
while (freeContexts) {
@ -1300,6 +1315,8 @@ void *ParMake(SConnection *con, char *name, ParClass *class, ParDef pardef,
o->period = 5;
o->infoList = NULL;
o->verbose = 0;
o->logPending = 0;
o->conn = NULL;
ParSaveConn(o, con);
o->pardef = pardef;
ParBegin();