added driver list function
This commit is contained in:
@ -12,8 +12,9 @@ Markus Zolliker, March 2005
|
||||
|
||||
typedef struct Item {
|
||||
struct Item *next;
|
||||
const char *type;
|
||||
const char *name;
|
||||
char *type;
|
||||
char *name;
|
||||
char *desc;
|
||||
Initializer maker;
|
||||
int startupOnly;
|
||||
} Item;
|
||||
@ -21,15 +22,17 @@ typedef struct Item {
|
||||
static Item *list = NULL;
|
||||
static int startup = 1;
|
||||
|
||||
void MakeInitializer(const char *type, const char *name, Initializer maker, int startupOnly) {
|
||||
void MakeInitializer(const char *type, const char *name, Initializer maker,
|
||||
int startupOnly, const char *desc) {
|
||||
Item *item;
|
||||
|
||||
item = calloc(1, sizeof *item);
|
||||
assert(item);
|
||||
item->maker = maker;
|
||||
item->next = list;
|
||||
item->type = type;
|
||||
item->name = name;
|
||||
item->type = strdup(type);
|
||||
item->name = strdup(name);
|
||||
item->desc = strdup(desc);
|
||||
item->startupOnly = startupOnly;
|
||||
list = item;
|
||||
}
|
||||
@ -84,6 +87,40 @@ static int MakeObject(SConnection *con, SicsInterp *sics,
|
||||
}
|
||||
}
|
||||
|
||||
static int DriverList(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]) {
|
||||
Item *p;
|
||||
char *name, *type;
|
||||
|
||||
if (argc < 2 || strcasecmp(argv[1], "list") == 0) {
|
||||
for (p = list; p != NULL; p = p->next) {
|
||||
if (argc < 3) {
|
||||
SCPrintf(con, eStatus, "%s %s %s", p->type, p->name, p->desc);
|
||||
} else if (strcasecmp(argv[2], p->type) == 0) {
|
||||
SCPrintf(con, eStatus, "%s %s", p->name, p->desc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (argc == 2) {
|
||||
name = argv[1];
|
||||
type = "Object";
|
||||
} else {
|
||||
name = argv[2];
|
||||
type = argv[1];
|
||||
}
|
||||
p = list;
|
||||
while (p != NULL && (strcasecmp(p->type, type) != 0 || strcasecmp(p->name, name) != 0)) {
|
||||
p = p->next;
|
||||
}
|
||||
if (p) {
|
||||
SCPrintf(con, eValue, "%s", p->desc);
|
||||
} else {
|
||||
SCPrintf(con, eValue, "notfound");
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int RemoveObject(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]) {
|
||||
CmdInitializer cmdin;
|
||||
@ -91,7 +128,7 @@ static int RemoveObject(SConnection *con, SicsInterp *sics,
|
||||
char *className;
|
||||
|
||||
if (argc != 2) {
|
||||
SCPrintf(con, eError, "%s has 1 argument", argv[0]);
|
||||
SCPrintf(con, eError, "%s needs 1 argument", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -124,16 +161,20 @@ static void KillInitializers(void *data) {
|
||||
item = list;
|
||||
while (item) {
|
||||
next = item->next;
|
||||
if (item->name) free(item->name);
|
||||
if (item->type) free(item->type);
|
||||
if (item->desc) free(item->desc);
|
||||
free(item);
|
||||
item = next;
|
||||
}
|
||||
list = NULL;
|
||||
}
|
||||
|
||||
void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly) {
|
||||
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, "RemoveObject", RemoveObject, NULL, NULL, 0);
|
||||
AddCommandWithFlag(pServ->pSics, "DriverList", DriverList, NULL, NULL, 0);
|
||||
}
|
||||
MakeInitializer("Object", driver, (Initializer)maker, startupOnly);
|
||||
MakeInitializer("Object", driver, (Initializer)maker, startupOnly, desc);
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ Markus Zolliker, March 2005
|
||||
|
||||
typedef void (*Initializer)(void);
|
||||
|
||||
void MakeInitializer(const char *type, const char *name, Initializer maker, int startupOnly);
|
||||
void MakeInitializer(const char *type, const char *name, Initializer maker, int startupOnly,
|
||||
const char *desc);
|
||||
/*
|
||||
install an initializer
|
||||
|
||||
@ -54,7 +55,8 @@ typedef int (*CmdInitializer) (SConnection *pCon, int argc, char *argv[], int dy
|
||||
- dynamic: the initializer was called _after_ startup
|
||||
*/
|
||||
|
||||
void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly);
|
||||
void MakeDriver(const char *driver, CmdInitializer maker, int startupOnly,
|
||||
const char *desc);
|
||||
/*
|
||||
Install a driver of type "Object" with the initializer function maker.
|
||||
- startupOnly: the driver creation should only be possible at startup
|
||||
|
Reference in New Issue
Block a user