- enhancements (new command makestaticobject)
This commit is contained in:
@@ -39,7 +39,7 @@ void MakeInitializer(const char *type, const char *name, Initializer maker,
|
||||
|
||||
Initializer GetInitializer(const char *type, const char *name) {
|
||||
Item *p, **last;
|
||||
|
||||
|
||||
if (startup && pServ->pReader != NULL) {
|
||||
/* pServ->pReader exists: startup finished */
|
||||
startup = 0;
|
||||
@@ -57,12 +57,10 @@ Initializer GetInitializer(const char *type, const char *name) {
|
||||
}
|
||||
}
|
||||
}
|
||||
p = list;
|
||||
while (p != NULL && (strcasecmp(p->name, name) != 0 || strcasecmp(p->type, type) != 0)) {
|
||||
p = p->next;
|
||||
}
|
||||
if (p) {
|
||||
return p->maker;
|
||||
for (p = list; p != NULL; p = p->next) {
|
||||
if (strcasecmp(p->name, name) == 0 && strcasecmp(p->type, type) == 0) {
|
||||
return p->maker;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -70,8 +68,6 @@ Initializer GetInitializer(const char *type, const char *name) {
|
||||
static int MakeObject(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]) {
|
||||
CmdInitializer cmdin;
|
||||
CommandList *command;
|
||||
char *className;
|
||||
|
||||
if (argc < 3) {
|
||||
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]);
|
||||
if (cmdin) {
|
||||
return cmdin(con, argc, argv, ! startup);
|
||||
return cmdin(con, argc, argv, strcasecmp(argv[0],"makeobject") == 0);
|
||||
} else {
|
||||
SCPrintf(con, eError, "do not know how to make a %s object", argv[2]);
|
||||
return 0;
|
||||
@@ -126,6 +122,8 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
|
||||
CmdInitializer cmdin;
|
||||
CommandList *command;
|
||||
char *className;
|
||||
char shortClassName[32];
|
||||
char *p;
|
||||
|
||||
if (argc != 2) {
|
||||
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;
|
||||
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 we have an initializer, we are allowed to remove */
|
||||
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) {
|
||||
if (! FindCommand(pServ->pSics, "MakeObject")) {
|
||||
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, "DriverList", DriverList, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
@@ -33,16 +33,19 @@ Initializer GetInitializer(const char *type, const char *name);
|
||||
type.
|
||||
*/
|
||||
|
||||
/*
|
||||
static int MakeObject(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]);
|
||||
/*
|
||||
|
||||
MakeObject has the following syntax:
|
||||
|
||||
MakeObject objectName driver [ args ... ]
|
||||
|
||||
It executes the initializer with the type "Object" and and the
|
||||
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
|
||||
- argc: the total number of args
|
||||
- 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,
|
||||
|
||||
Reference in New Issue
Block a user