diff --git a/include/villas/api.h b/include/villas/api.h index 2258d7b90..9ae344e42 100644 --- a/include/villas/api.h +++ b/include/villas/api.h @@ -83,8 +83,6 @@ struct api_session { * Every command is described by a descriptor. */ struct api_ressource { - char *name; - char *description; api_cb_t cb; }; diff --git a/include/villas/hook.h b/include/villas/hook.h index b8bb822d9..3f121b81b 100644 --- a/include/villas/hook.h +++ b/include/villas/hook.h @@ -94,9 +94,7 @@ enum hook_type { /** Descriptor for user defined hooks. See hooks[]. */ struct hook { - const char *name; /**< The unique name of this hook. This must be the first member! */ const char *parameter; /**< A parameter string for this hook. Can be used to configure the hook behaviour. */ - const char *description;/**< A short description of this hook function. */ int priority; /**< A priority to change the order of execution within one type of hook */ int history; /**< How many samples of history this hook requires. */ diff --git a/include/villas/node_type.h b/include/villas/node_type.h index 277380f13..94d23072b 100644 --- a/include/villas/node_type.h +++ b/include/villas/node_type.h @@ -20,8 +20,6 @@ struct sample; /** C++ like vtable construct for node_types */ struct node_type { - const char *name; /**< The unique name of this node. This must be allways the first member! */ - const char *description; /**< A short description of this node type. Will be shown in help text. */ int vectorize; /**< Maximal vector length supported by this node type. Zero is unlimited. */ struct list instances; /**< A list of all existing nodes of this type. */ diff --git a/include/villas/plugin.h b/include/villas/plugin.h index 5b14a466d..dded61cd1 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -59,6 +59,12 @@ struct plugin { }; }; +/** Return a pointer to the plugin structure */ +#define plugin(vt) ((struct plugin *) ((char *) (vt) - offsetof(struct plugin, api))) + +#define plugin_name(vt) plugin(vt)->name +#define plugin_description(vt) plugin(vt)->description + int plugin_init(struct plugin *p, char *name, char *path); int plugin_destroy(struct plugin *p); diff --git a/lib/hook.c b/lib/hook.c index 5a2d86e47..2d24369c5 100644 --- a/lib/hook.c +++ b/lib/hook.c @@ -72,7 +72,7 @@ int hook_run(struct path *p, struct sample *smps[], size_t cnt, int when) if (h->type & when) { cnt = h->cb(h, when, &i); - debug(LOG_HOOK | 22, "Ran hook '%s' when=%u prio=%u, cnt=%zu", h->name, when, h->priority, cnt); + debug(LOG_HOOK | 22, "Ran hook '%s' when=%u prio=%u, cnt=%zu", plugin_name(h), when, h->priority, cnt); if (cnt == 0) break; diff --git a/lib/hooks/convert.c b/lib/hooks/convert.c index 7ae6ed487..4b4a4a645 100644 --- a/lib/hooks/convert.c +++ b/lib/hooks/convert.c @@ -23,7 +23,7 @@ static int hook_convert(struct hook *h, int when, struct hook_info *k) switch (when) { case HOOK_PARSE: if (!h->parameter) - error("Missing parameter for hook: '%s'", h->name); + error("Missing parameter for hook: '%s'", plugin_name(h)); if (!strcmp(h->parameter, "fixed")) private->mode = TO_FIXED; diff --git a/lib/hooks/decimate.c b/lib/hooks/decimate.c index c9efb5eb1..1accd40f9 100644 --- a/lib/hooks/decimate.c +++ b/lib/hooks/decimate.c @@ -21,7 +21,7 @@ static int hook_decimate(struct hook *h, int when, struct hook_info *j) switch (when) { case HOOK_PARSE: if (!h->parameter) - error("Missing parameter for hook: '%s'", h->name); + error("Missing parameter for hook: '%s'", plugin_name(h)); private->ratio = strtol(h->parameter, NULL, 10); if (!private->ratio) diff --git a/lib/hooks/skip_first.c b/lib/hooks/skip_first.c index 84998ce67..0e9ab9c83 100644 --- a/lib/hooks/skip_first.c +++ b/lib/hooks/skip_first.c @@ -25,7 +25,7 @@ static int hook_skip_first(struct hook *h, int when, struct hook_info *j) switch (when) { case HOOK_PARSE: if (!h->parameter) - error("Missing parameter for hook: '%s'", h->name); + error("Missing parameter for hook: '%s'", plugin_name(h)); wait = strtof(h->parameter, &endptr); if (h->parameter == endptr) diff --git a/lib/hooks/stats.c b/lib/hooks/stats.c index 643fa5ea0..770ba7c2f 100644 --- a/lib/hooks/stats.c +++ b/lib/hooks/stats.c @@ -63,11 +63,11 @@ static int hook_stats_send(struct hook *h, int when, struct hook_info *j) assert(j->path); if (!h->parameter) - error("Missing parameter for hook '%s'", h->name); + error("Missing parameter for hook '%s'", plugin_name(h)); private->dest = list_lookup(j->nodes, h->parameter); if (!private->dest) - error("Invalid destination node '%s' for hook '%s'", h->parameter, h->name); + error("Invalid destination node '%s' for hook '%s'", h->parameter, plugin_name(h)); break; case HOOK_PATH_START: diff --git a/lib/node.c b/lib/node.c index 9b06c076d..de1adbe70 100644 --- a/lib/node.c +++ b/lib/node.c @@ -101,7 +101,7 @@ int node_stop(struct node *n) char * node_name(struct node *n) { if (!n->_name) - strcatf(&n->_name, RED("%s") "(" YEL("%s") ")", n->name, n->_vt->name); + strcatf(&n->_name, RED("%s") "(" YEL("%s") ")", n->name, plugin_name(n->_vt)); return n->_name; } diff --git a/lib/node_type.c b/lib/node_type.c index 9e6a329a8..dd1ca868c 100644 --- a/lib/node_type.c +++ b/lib/node_type.c @@ -21,9 +21,9 @@ int node_type_init(struct node_type *vt, int argc, char *argv[], config_setting_ if (vt->state != NODE_TYPE_DEINITIALIZED) return -1; - info("Initializing " YEL("%s") " node type", vt->name); + info("Initializing " YEL("%s") " node type", plugin_name(vt)); { INDENT - ret = vt->init ? vt->init(argc, argv, cfg) : -1; + ret = vt->init ? vt->init(argc, argv, cfg) : 0; } if (ret == 0) @@ -39,7 +39,7 @@ int node_type_deinit(struct node_type *vt) if (vt->state != NODE_TYPE_INITIALIZED) return -1; - info("De-initializing " YEL("%s") " node type", vt->name); + info("De-initializing " YEL("%s") " node type", plugin_name(vt)); { INDENT ret = vt->deinit ? vt->deinit() : -1; } diff --git a/lib/nodes/file.c b/lib/nodes/file.c index bc175aa59..0789e4b48 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -348,7 +348,7 @@ static struct plugin p = { .open = file_open, .close = file_close, .read = file_read, - .write = file_write + .write = file_write, } }; diff --git a/lib/path.c b/lib/path.c index a167f41a7..758961e93 100644 --- a/lib/path.c +++ b/lib/path.c @@ -242,7 +242,7 @@ int path_init(struct path *p, struct cfg *cfg) struct hook *h = &pl->hook; if ((h->type & HOOK_AUTO) && /* should this hook be added implicitely? */ - (list_lookup(&p->hooks, h->name) == NULL)) /* is not already in list? */ + (list_lookup(&p->hooks, pl->name) == NULL)) /* is not already in list? */ list_push(&p->hooks, memdup(h, sizeof(struct hook))); } }