mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
plugin: replace plugin_name() by type-specific wrappers
This commit is contained in:
parent
ccd658a2d5
commit
abdec22993
20 changed files with 39 additions and 24 deletions
|
@ -109,6 +109,8 @@ struct format_type {
|
|||
|
||||
struct format_type * format_type_lookup(const char *name);
|
||||
|
||||
const char * format_type_name(struct format_type *vt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -76,6 +76,9 @@ struct hook_type {
|
|||
|
||||
struct hook_type * hook_type_lookup(const char *name);
|
||||
|
||||
/** Return a printable representation of the hook-type. */
|
||||
const char * hook_type_name(struct hook_type *vt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -36,3 +36,8 @@ struct format_type * format_type_lookup(const char *name)
|
|||
|
||||
return &p->format;
|
||||
}
|
||||
|
||||
const char * format_type_name(struct format_type *vt)
|
||||
{
|
||||
return plugin_name(vt);
|
||||
}
|
||||
|
|
17
lib/hook.c
17
lib/hook.c
|
@ -75,7 +75,7 @@ int hook_parse(struct hook *h, json_t *cfg)
|
|||
"enabled", &h->enabled
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
ret = h->_vt->parse ? h->_vt->parse(h, cfg) : 0;
|
||||
if (ret)
|
||||
|
@ -111,7 +111,7 @@ int hook_start(struct hook *h)
|
|||
return 0;
|
||||
|
||||
if (h->_vt->start) {
|
||||
debug(LOG_HOOK | 10, "Start hook %s: priority=%d", plugin_name(h->_vt), h->priority);
|
||||
debug(LOG_HOOK | 10, "Start hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
|
||||
return h->_vt->start(h);
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ int hook_stop(struct hook *h)
|
|||
return 0;
|
||||
|
||||
if (h->_vt->stop) {
|
||||
debug(LOG_HOOK | 10, "Stopping hook %s: priority=%d", plugin_name(h->_vt), h->priority);
|
||||
debug(LOG_HOOK | 10, "Stopping hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
|
||||
return h->_vt->stop(h);
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ int hook_periodic(struct hook *h)
|
|||
return 0;
|
||||
|
||||
if (h->_vt->periodic) {
|
||||
debug(LOG_HOOK | 10, "Periodic hook %s: priority=%d", plugin_name(h->_vt), h->priority);
|
||||
debug(LOG_HOOK | 10, "Periodic hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
|
||||
return h->_vt->periodic(h);
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ int hook_restart(struct hook *h)
|
|||
return 0;
|
||||
|
||||
if (h->_vt->restart) {
|
||||
debug(LOG_HOOK | 10, "Restarting hook %s: priority=%d", plugin_name(h->_vt), h->priority);
|
||||
debug(LOG_HOOK | 10, "Restarting hook %s: priority=%d", hook_type_name(h->_vt), h->priority);
|
||||
|
||||
return h->_vt->restart(h);
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ int hook_process(struct hook *h, struct sample *smps[], unsigned *cnt)
|
|||
return 0;
|
||||
|
||||
if (h->_vt->process) {
|
||||
debug(LOG_HOOK | 10, "Process hook %s: priority=%d, cnt=%d", plugin_name(h->_vt), h->priority, *cnt);
|
||||
debug(LOG_HOOK | 10, "Process hook %s: priority=%d, cnt=%d", hook_type_name(h->_vt), h->priority, *cnt);
|
||||
|
||||
return h->_vt->process(h, smps, cnt);
|
||||
}
|
||||
|
@ -276,3 +276,8 @@ int hook_init_builtin_list(struct list *l, bool builtin, int mask, struct path *
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * hook_type_name(struct hook_type *vt)
|
||||
{
|
||||
return plugin_name(vt);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ static int decimate_parse(struct hook *h, json_t *cfg)
|
|||
"ratio", &p->ratio
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ static int limit_rate_parse(struct hook *h, json_t *cfg)
|
|||
"mode", &mode
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
if (mode) {
|
||||
if (!strcmp(mode, "origin"))
|
||||
|
|
|
@ -92,7 +92,7 @@ static int print_parse(struct hook *h, json_t *cfg)
|
|||
"format", &format
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
if (prefix)
|
||||
p->prefix = strdup(prefix);
|
||||
|
|
|
@ -57,7 +57,7 @@ static int scale_parse(struct hook *h, json_t *cfg)
|
|||
"offset", &p->offset
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ static int shift_seq_parse(struct hook *h, json_t *cfg)
|
|||
"offset", &p->offset
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ static int shift_ts_parse(struct hook *h, json_t *cfg)
|
|||
"offset", &offset
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
if (mode) {
|
||||
if (!strcmp(mode, "origin"))
|
||||
|
@ -69,7 +69,7 @@ static int shift_ts_parse(struct hook *h, json_t *cfg)
|
|||
else if (!strcmp(mode, "received"))
|
||||
p->mode = SHIFT_RECEIVED;
|
||||
else
|
||||
jerror(&err, "Invalid mode parameter '%s' for hook '%s'", mode, plugin_name(h->_vt));
|
||||
jerror(&err, "Invalid mode parameter '%s' for hook '%s'", mode, hook_type_name(h->_vt));
|
||||
}
|
||||
|
||||
p->offset = time_from_double(offset);
|
||||
|
|
|
@ -75,7 +75,7 @@ static int skip_first_parse(struct hook *h, json_t *cfg)
|
|||
return 0;
|
||||
}
|
||||
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ static int stats_collect_parse(struct hook *h, json_t *cfg)
|
|||
"output", &uri
|
||||
);
|
||||
if (ret)
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt));
|
||||
jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt));
|
||||
|
||||
if (format) {
|
||||
fmt = stats_lookup_format(format);
|
||||
|
|
|
@ -199,7 +199,7 @@ char * amqp_print(struct node *n)
|
|||
|
||||
char *buf = NULL;
|
||||
|
||||
strcatf(&buf, "format=%s, uri=%s://%s:%s@%s:%d%s, exchange=%s, routing_key=%s", plugin_name(a->format),
|
||||
strcatf(&buf, "format=%s, uri=%s://%s:%s@%s:%d%s, exchange=%s, routing_key=%s", format_type_name(a->format),
|
||||
a->connection_info.ssl ? "amqps" : "amqp",
|
||||
a->connection_info.user,
|
||||
a->connection_info.password,
|
||||
|
|
|
@ -170,7 +170,7 @@ char * file_print(struct node *n)
|
|||
|
||||
strcatf(&buf, "uri=%s, format=%s, flush=%s, eof=%s, epoch_mode=%s, epoch=%.2f",
|
||||
f->uri ? f->uri : f->uri_tmpl,
|
||||
plugin_name(f->format),
|
||||
format_type_name(f->format),
|
||||
f->flush ? "yes" : "no",
|
||||
eof_str,
|
||||
epoch_str,
|
||||
|
|
|
@ -219,7 +219,7 @@ char * mqtt_print(struct node *n)
|
|||
|
||||
char *buf = NULL;
|
||||
|
||||
strcatf(&buf, "format=%s, host=%s, port=%d, keepalive=%s, ssl=%s", plugin_name(m->format),
|
||||
strcatf(&buf, "format=%s, host=%s, port=%d, keepalive=%s, ssl=%s", format_type_name(m->format),
|
||||
m->host,
|
||||
m->port,
|
||||
m->keepalive ? "yes" : "no",
|
||||
|
|
|
@ -125,7 +125,7 @@ char * nanomsg_print(struct node *n)
|
|||
|
||||
char *buf = NULL;
|
||||
|
||||
strcatf(&buf, "format=%s, subscribe=[ ", plugin_name(m->format));
|
||||
strcatf(&buf, "format=%s, in.endpoints=[ ", format_type_name(m->format));
|
||||
|
||||
for (size_t i = 0; i < list_length(&m->subscriber.endpoints); i++) {
|
||||
char *ep = (char *) list_at(&m->subscriber.endpoints, i);
|
||||
|
|
|
@ -154,7 +154,7 @@ char * socket_print(struct node *n)
|
|||
char *local = socket_print_addr((struct sockaddr *) &s->local);
|
||||
char *remote = socket_print_addr((struct sockaddr *) &s->remote);
|
||||
|
||||
buf = strf("layer=%s, format=%s, local=%s, remote=%s", layer, plugin_name(s->format), local, remote);
|
||||
buf = strf("layer=%s, format=%s, in.address=%s, out.address=%s", layer, format_type_name(s->format), local, remote);
|
||||
|
||||
if (s->multicast.enabled) {
|
||||
char group[INET_ADDRSTRLEN];
|
||||
|
|
|
@ -211,7 +211,7 @@ char * zeromq_print(struct node *n)
|
|||
}
|
||||
|
||||
strcatf(&buf, "format=%s, pattern=%s, ipv6=%s, crypto=%s, subscribe=%s, publish=[ ",
|
||||
plugin_name(z->format),
|
||||
format_type_name(z->format),
|
||||
pattern,
|
||||
z->ipv6 ? "yes" : "no",
|
||||
z->curve.enabled ? "yes" : "no",
|
||||
|
|
|
@ -377,7 +377,7 @@ int super_node_start(struct super_node *sn)
|
|||
|
||||
ret = node_type_start(n->_vt, sn);
|
||||
if (ret)
|
||||
error("Failed to start node-type: %s", plugin_name(n->_vt));
|
||||
error("Failed to start node-type: %s", node_type_name(n->_vt));
|
||||
}
|
||||
|
||||
info("Starting nodes");
|
||||
|
@ -449,7 +449,7 @@ int super_node_stop(struct super_node *sn)
|
|||
if (p->type == PLUGIN_TYPE_NODE) {
|
||||
ret = node_type_stop(&p->node);
|
||||
if (ret)
|
||||
error("Failed to stop node-type: %s", plugin_name(p));
|
||||
error("Failed to stop node-type: %s", node_type_name(p));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ check: if (optarg == endptr)
|
|||
|
||||
ret = node_type_start(node->_vt, &sn);
|
||||
if (ret)
|
||||
error("Failed to start node-type %s: reason=%d", plugin_name(node->_vt), ret);
|
||||
error("Failed to start node-type %s: reason=%d", node_type_name(node->_vt), ret);
|
||||
|
||||
ret = node_init2(node);
|
||||
if (ret)
|
||||
|
|
Loading…
Add table
Reference in a new issue