From abdec22993b32fac613be836b8dcd5c0c07bc549 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 20 Aug 2018 18:16:09 +0200 Subject: [PATCH] plugin: replace plugin_name() by type-specific wrappers --- include/villas/format_type.h | 2 ++ include/villas/hook_type.h | 3 +++ lib/format_type.c | 5 +++++ lib/hook.c | 17 +++++++++++------ lib/hooks/decimate.c | 2 +- lib/hooks/limit_rate.c | 2 +- lib/hooks/print.c | 2 +- lib/hooks/scale.c | 2 +- lib/hooks/shift_seq.c | 2 +- lib/hooks/shift_ts.c | 4 ++-- lib/hooks/skip_first.c | 2 +- lib/hooks/stats.c | 2 +- lib/nodes/amqp.c | 2 +- lib/nodes/file.c | 2 +- lib/nodes/mqtt.c | 2 +- lib/nodes/nanomsg.c | 2 +- lib/nodes/socket.c | 2 +- lib/nodes/zeromq.c | 2 +- lib/super_node.c | 4 ++-- src/villas-test-rtt.cpp | 2 +- 20 files changed, 39 insertions(+), 24 deletions(-) diff --git a/include/villas/format_type.h b/include/villas/format_type.h index 2b65459d7..9b78be40d 100644 --- a/include/villas/format_type.h +++ b/include/villas/format_type.h @@ -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 diff --git a/include/villas/hook_type.h b/include/villas/hook_type.h index ab628b400..2cffb74d2 100644 --- a/include/villas/hook_type.h +++ b/include/villas/hook_type.h @@ -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 diff --git a/lib/format_type.c b/lib/format_type.c index b86a3cda0..f27585389 100644 --- a/lib/format_type.c +++ b/lib/format_type.c @@ -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); +} diff --git a/lib/hook.c b/lib/hook.c index 9b1ff8418..133f5bbe3 100644 --- a/lib/hook.c +++ b/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); +} diff --git a/lib/hooks/decimate.c b/lib/hooks/decimate.c index 772e2b6c8..63be064c9 100644 --- a/lib/hooks/decimate.c +++ b/lib/hooks/decimate.c @@ -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; } diff --git a/lib/hooks/limit_rate.c b/lib/hooks/limit_rate.c index 63500ff5e..f6526bab4 100644 --- a/lib/hooks/limit_rate.c +++ b/lib/hooks/limit_rate.c @@ -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")) diff --git a/lib/hooks/print.c b/lib/hooks/print.c index cebffb2cc..53e582fd8 100644 --- a/lib/hooks/print.c +++ b/lib/hooks/print.c @@ -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); diff --git a/lib/hooks/scale.c b/lib/hooks/scale.c index 5226e35f4..15c51ca26 100644 --- a/lib/hooks/scale.c +++ b/lib/hooks/scale.c @@ -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; } diff --git a/lib/hooks/shift_seq.c b/lib/hooks/shift_seq.c index 637fb9e55..84428d761 100644 --- a/lib/hooks/shift_seq.c +++ b/lib/hooks/shift_seq.c @@ -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; } diff --git a/lib/hooks/shift_ts.c b/lib/hooks/shift_ts.c index b0ee9e6ed..db308c26d 100644 --- a/lib/hooks/shift_ts.c +++ b/lib/hooks/shift_ts.c @@ -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); diff --git a/lib/hooks/skip_first.c b/lib/hooks/skip_first.c index 68ac1dfd6..f1c5d1398 100644 --- a/lib/hooks/skip_first.c +++ b/lib/hooks/skip_first.c @@ -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; } diff --git a/lib/hooks/stats.c b/lib/hooks/stats.c index d34f6c3c6..b8f69a4da 100644 --- a/lib/hooks/stats.c +++ b/lib/hooks/stats.c @@ -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); diff --git a/lib/nodes/amqp.c b/lib/nodes/amqp.c index cd512ca50..3fe07ba1a 100644 --- a/lib/nodes/amqp.c +++ b/lib/nodes/amqp.c @@ -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, diff --git a/lib/nodes/file.c b/lib/nodes/file.c index 0ecde7ffc..b68d6be1d 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -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, diff --git a/lib/nodes/mqtt.c b/lib/nodes/mqtt.c index 4e105e7ad..f9da98694 100644 --- a/lib/nodes/mqtt.c +++ b/lib/nodes/mqtt.c @@ -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", diff --git a/lib/nodes/nanomsg.c b/lib/nodes/nanomsg.c index b35b24581..9748f1340 100644 --- a/lib/nodes/nanomsg.c +++ b/lib/nodes/nanomsg.c @@ -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); diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 63ffd8557..5810a692c 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -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]; diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index e439f0d6e..05c40b69a 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -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", diff --git a/lib/super_node.c b/lib/super_node.c index b9f17516f..d498eac77 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -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)); } } diff --git a/src/villas-test-rtt.cpp b/src/villas-test-rtt.cpp index 24dec6b38..1e4dca6ad 100644 --- a/src/villas-test-rtt.cpp +++ b/src/villas-test-rtt.cpp @@ -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)