mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
add macros to get plugin name and description from pointer to plugin specific data
This commit is contained in:
parent
a397c117c7
commit
0b06a77c15
13 changed files with 18 additions and 18 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ static struct plugin p = {
|
|||
.open = file_open,
|
||||
.close = file_close,
|
||||
.read = file_read,
|
||||
.write = file_write
|
||||
.write = file_write,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue