- enhancements (new command makestaticobject)

This commit is contained in:
zolliker
2008-01-18 07:25:48 +00:00
parent 1bcb418ad4
commit af233c713a
2 changed files with 24 additions and 13 deletions

View File

@@ -57,21 +57,17 @@ Initializer GetInitializer(const char *type, const char *name) {
} }
} }
} }
p = list; for (p = list; p != NULL; p = p->next) {
while (p != NULL && (strcasecmp(p->name, name) != 0 || strcasecmp(p->type, type) != 0)) { if (strcasecmp(p->name, name) == 0 && strcasecmp(p->type, type) == 0) {
p = p->next;
}
if (p) {
return p->maker; return p->maker;
} }
}
return NULL; return NULL;
} }
static int MakeObject(SConnection *con, SicsInterp *sics, static int MakeObject(SConnection *con, SicsInterp *sics,
void *data, int argc, char *argv[]) { void *data, int argc, char *argv[]) {
CmdInitializer cmdin; CmdInitializer cmdin;
CommandList *command;
char *className;
if (argc < 3) { if (argc < 3) {
SCPrintf(con, eError, "%s needs more arguments", argv[0]); SCPrintf(con, eError, "%s needs more arguments", argv[0]);
@@ -80,7 +76,7 @@ static int MakeObject(SConnection *con, SicsInterp *sics,
cmdin = (CmdInitializer)GetInitializer("Object", argv[2]); cmdin = (CmdInitializer)GetInitializer("Object", argv[2]);
if (cmdin) { if (cmdin) {
return cmdin(con, argc, argv, ! startup); return cmdin(con, argc, argv, strcasecmp(argv[0],"makeobject") == 0);
} else { } else {
SCPrintf(con, eError, "do not know how to make a %s object", argv[2]); SCPrintf(con, eError, "do not know how to make a %s object", argv[2]);
return 0; return 0;
@@ -126,6 +122,8 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
CmdInitializer cmdin; CmdInitializer cmdin;
CommandList *command; CommandList *command;
char *className; char *className;
char shortClassName[32];
char *p;
if (argc != 2) { if (argc != 2) {
SCPrintf(con, eError, "%s needs 1 argument", argv[0]); SCPrintf(con, eError, "%s needs 1 argument", argv[0]);
@@ -139,6 +137,14 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
} }
className = ((pDummy)command->pData)->pDescriptor->name; className = ((pDummy)command->pData)->pDescriptor->name;
cmdin = (CmdInitializer)GetInitializer("Object", className); cmdin = (CmdInitializer)GetInitializer("Object", className);
if (cmdin == 0) {
/* allow also a longer descriptor starting with the initializer name and a blank */
p = strchr(className, ' ');
if (p) {
snprintf(shortClassName, sizeof shortClassName, "%.*s", p - className, className);
cmdin = (CmdInitializer)GetInitializer("Object", shortClassName);
}
}
if (cmdin) { if (cmdin) {
/* if we have an initializer, we are allowed to remove */ /* if we have an initializer, we are allowed to remove */
if (pServ->pExecutor && isInRunMode(pServ->pExecutor)) { if (pServ->pExecutor && isInRunMode(pServ->pExecutor)) {
@@ -173,6 +179,7 @@ static void KillInitializers(void *data) {
void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly, const char *desc) { void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly, const char *desc) {
if (! FindCommand(pServ->pSics, "MakeObject")) { if (! FindCommand(pServ->pSics, "MakeObject")) {
AddCommandWithFlag(pServ->pSics, "MakeObject", MakeObject, KillInitializers, NULL, 0); AddCommandWithFlag(pServ->pSics, "MakeObject", MakeObject, KillInitializers, NULL, 0);
AddCommandWithFlag(pServ->pSics, "MakeStaticObject", MakeObject, NULL, NULL, 0);
AddCommandWithFlag(pServ->pSics, "RemoveObject", RemoveObject, NULL, NULL, 0); AddCommandWithFlag(pServ->pSics, "RemoveObject", RemoveObject, NULL, NULL, 0);
AddCommandWithFlag(pServ->pSics, "DriverList", DriverList, NULL, NULL, 0); AddCommandWithFlag(pServ->pSics, "DriverList", DriverList, NULL, NULL, 0);
} }

View File

@@ -33,16 +33,19 @@ Initializer GetInitializer(const char *type, const char *name);
type. type.
*/ */
/*
static int MakeObject(SConnection *con, SicsInterp *sics, static int MakeObject(SConnection *con, SicsInterp *sics,
void *data, int argc, char *argv[]); void *data, int argc, char *argv[]);
/*
MakeObject has the following syntax: MakeObject has the following syntax:
MakeObject objectName driver [ args ... ] MakeObject objectName driver [ args ... ]
It executes the initializer with the type "Object" and and the It executes the initializer with the type "Object" and and the
driver given as name. The found initalizer should use the given arguments driver given as name. The found initalizer should use the given arguments
to create a driver. to create a driver. Objects should be dynamic, i.e. there should be
a creation command in the status file, except when the creation command
was MakeStaticObject instead of MakeObject.
*/ */
@@ -52,7 +55,8 @@ typedef int (*CmdInitializer) (SConnection *pCon, int argc, char *argv[], int dy
- pCon: the sics connection calling this initializer - pCon: the sics connection calling this initializer
- argc: the total number of args - argc: the total number of args
- argv: the args (argv[0]: "MakeObject", argv[1]: object name, argv[3]: driver ...) - argv: the args (argv[0]: "MakeObject", argv[1]: object name, argv[3]: driver ...)
- dynamic: the initializer was called _after_ startup - dynamic: 1, if the creation command was MakeObject,
0, if the creation command was MakeStaticObject
*/ */
void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly, void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly,