diff --git a/include/villas/hook_type.h b/include/villas/hook_type.h
index 37d02225a..6c6d7ec70 100644
--- a/include/villas/hook_type.h
+++ b/include/villas/hook_type.h
@@ -71,3 +71,6 @@ struct hook_type {
int (*process)(struct hook *h, struct sample *smps[], unsigned *cnt); /**< Called whenever muxed samples are processed. */
int (*write)(struct hook *h, struct sample *smps[], unsigned *cnt); /**< Called whenever samples are written to a node. */
};
+
+struct hook_type * hook_type_lookup(const char *name);
+
diff --git a/include/villas/node_type.h b/include/villas/node_type.h
index 1667cfc7d..b9819e2c4 100644
--- a/include/villas/node_type.h
+++ b/include/villas/node_type.h
@@ -166,4 +166,6 @@ int node_type_stop(struct node_type *vt);
/** Return a printable representation of the node-type. */
const char * node_type_name(struct node_type *vt);
+struct node_type * node_type_lookup(const char *name);
+
/** @} */
diff --git a/lib/Makefile.villas.inc b/lib/Makefile.villas.inc
index 52d832fc4..dc0a3ca0a 100644
--- a/lib/Makefile.villas.inc
+++ b/lib/Makefile.villas.inc
@@ -50,7 +50,7 @@ ifeq ($(WITH_IO),1)
endif
ifeq ($(WITH_HOOKS),1)
- LIB_SRCS += lib/hook.c
+ LIB_SRCS += lib/hook.c lib/hook_type.c
include lib/hooks/Makefile.inc
endif
diff --git a/lib/hook.c b/lib/hook.c
index 3c1b0c6a9..bc1095827 100644
--- a/lib/hook.c
+++ b/lib/hook.c
@@ -19,6 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*********************************************************************************/
+
#include
#include
@@ -250,22 +251,22 @@ int hook_parse_list(struct list *list, json_t *cfg, struct path *o, struct node
json_array_foreach(cfg, index, json_hook) {
int ret;
const char *type;
- struct plugin *p;
+ struct hook_type *ht;
json_error_t err;
ret = json_unpack_ex(json_hook, &err, 0, "{ s: s }", "type", &type);
if (ret)
jerror(&err, "Failed to parse hook");
- p = plugin_lookup(PLUGIN_TYPE_HOOK, type);
- if (!p)
+ ht = hook_type_lookup(type);
+ if (!ht)
jerror(&err, "Unkown hook type '%s'", type);
struct hook *h = (struct hook *) alloc(sizeof(struct hook));
- ret = hook_init(h, &p->hook, o, n);
+ ret = hook_init(h, ht, o, n);
if (ret)
- error("Failed to initialize hook: %s", p->name);
+ error("Failed to initialize hook: %s", type);
ret = hook_parse(h, json_hook);
if (ret)
diff --git a/lib/hook_type.c b/lib/hook_type.c
new file mode 100644
index 000000000..ab0756378
--- /dev/null
+++ b/lib/hook_type.c
@@ -0,0 +1,35 @@
+/** Hook-releated functions.
+ *
+ * @author Steffen Vogel
+ * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
+ * @license GNU General Public License (version 3)
+ *
+ * VILLASnode
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *********************************************************************************/
+
+#include
+#include
+
+struct hook_type * hook_type_lookup(const char *name)
+{
+ struct plugin *p;
+
+ p = plugin_lookup(PLUGIN_TYPE_HOOK, name);
+ if (!p)
+ return NULL;
+
+ return &p->hook;
+}
diff --git a/lib/node.c b/lib/node.c
index d1a207f55..cb7be67b4 100644
--- a/lib/node.c
+++ b/lib/node.c
@@ -23,6 +23,7 @@
#include
#include
+#include
#include
#include
#include
@@ -101,7 +102,7 @@ int node_init2(struct node *n)
int node_parse(struct node *n, json_t *cfg, const char *name)
{
- struct plugin *p;
+ struct node_type *nt;
int ret;
json_error_t err;
@@ -123,8 +124,8 @@ int node_parse(struct node *n, json_t *cfg, const char *name)
if (ret)
jerror(&err, "Failed to parse node '%s'", node_name(n));
- p = plugin_lookup(PLUGIN_TYPE_NODE, type);
- assert(&p->node == n->_vt);
+ nt = node_type_lookup(type);
+ assert(nt == n->_vt);
#ifdef WITH_HOOKS
if (json_hooks) {
diff --git a/lib/node_type.c b/lib/node_type.c
index b6d7df22f..f962ab1f6 100644
--- a/lib/node_type.c
+++ b/lib/node_type.c
@@ -69,3 +69,14 @@ const char * node_type_name(struct node_type *vt)
{
return plugin_name(vt);
}
+
+struct node_type * node_type_lookup(const char *name)
+{
+ struct plugin *p;
+
+ p = plugin_lookup(PLUGIN_TYPE_NODE, name);
+ if (!p)
+ return NULL;
+
+ return &p->node;
+}
diff --git a/lib/super_node.c b/lib/super_node.c
index a4a8b150c..4a6a9ebf9 100644
--- a/lib/super_node.c
+++ b/lib/super_node.c
@@ -244,20 +244,20 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
const char *name;
json_t *json_node;
json_object_foreach(json_nodes, name, json_node) {
- struct plugin *p;
+ struct node_type *nt;
const char *type;
ret = json_unpack_ex(json_node, &err, 0, "{ s: s }", "type", &type);
if (ret)
jerror(&err, "Failed to parse node");
- p = plugin_lookup(PLUGIN_TYPE_NODE, type);
- if (!p)
+ nt = node_type_lookup(type);
+ if (!nt)
error("Invalid node type: %s", type);
struct node *n = (struct node *) alloc(sizeof(struct node));
- ret = node_init(n, &p->node);
+ ret = node_init(n, nt);
if (ret)
error("Failed to initialize node");
diff --git a/src/convert.c b/src/convert.c
index 0d54c171d..87afd6638 100644
--- a/src/convert.c
+++ b/src/convert.c
@@ -80,10 +80,9 @@ check: if (optarg == endptr)
exit(EXIT_FAILURE);
}
- struct plugin *p;
+ struct format_type *fmt;
struct log log;
- struct io input;
- struct io output;
+ struct io input, output;
ret = log_init(&log, level, LOG_ALL);
if (ret)
@@ -102,11 +101,11 @@ check: if (optarg == endptr)
};
for (int i = 0; i < ARRAY_LEN(dirs); i++) {
- p = plugin_lookup(PLUGIN_TYPE_FORMAT, dirs[i].name);
- if (!p)
+ fmt = format_type_lookup(dirs[i].name);
+ if (!fmt)
error("Invalid format: %s", dirs[i].name);
- ret = io_init(dirs[i].io, &p->io, NULL, SAMPLE_HAS_ALL);
+ ret = io_init(dirs[i].io, fmt, NULL, SAMPLE_HAS_ALL);
if (ret)
error("Failed to initialize IO: %s", dirs[i].name);
diff --git a/src/hook.c b/src/hook.c
index d9e04cd26..27747283a 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -44,7 +44,6 @@
int cnt;
struct sample **smps;
-struct plugin *p;
struct log l = { .state = STATE_DESTROYED };
struct pool q = { .state = STATE_DESTROYED };
@@ -110,6 +109,9 @@ int main(int argc, char *argv[])
int ret, recv, sent;
char *format = "villas.human";
+ struct format_type *ft;
+ struct hook_type *ht;
+
/* Default values */
cnt = 1;
@@ -181,11 +183,11 @@ check: if (optarg == endptr)
error("Failed to initilize memory pool");
/* Initialize IO */
- p = plugin_lookup(PLUGIN_TYPE_FORMAT, format);
- if (!p)
+ ft = format_type_lookup(format);
+ if (!ft)
error("Unknown IO format '%s'", format);
- ret = io_init(&io, &p->io, NULL, SAMPLE_HAS_ALL);
+ ret = io_init(&io, ft, NULL, SAMPLE_HAS_ALL);
if (ret)
error("Failed to initialize IO");
@@ -194,11 +196,11 @@ check: if (optarg == endptr)
error("Failed to open IO");
/* Initialize hook */
- p = plugin_lookup(PLUGIN_TYPE_HOOK, hook);
- if (!p)
+ ht = hook_type_lookup(hook);
+ if (!ht)
error("Unknown hook function '%s'", hook);
- ret = hook_init(&h, &p->hook, NULL, NULL);
+ ret = hook_init(&h, ht, NULL, NULL);
if (ret)
error("Failed to initialize hook");
diff --git a/src/pipe.c b/src/pipe.c
index a244e5ca7..76f296c37 100644
--- a/src/pipe.c
+++ b/src/pipe.c
@@ -295,7 +295,7 @@ check: if (optarg == endptr)
char *configfile = argv[optind];
char *nodestr = argv[optind+1];
- struct plugin *p;
+ struct format_type *fmt;
ret = log_init(&sn.log, level, LOG_ALL);
if (ret)
@@ -325,11 +325,11 @@ check: if (optarg == endptr)
if (ret)
error("Failed to initalize real-time");
- p = plugin_lookup(PLUGIN_TYPE_FORMAT, format);
- if (!p)
+ fmt = format_type_lookup(format);
+ if (!fmt)
error("Invalid format: %s", format);
- ret = io_init(&io, &p->io, NULL, SAMPLE_HAS_ALL);
+ ret = io_init(&io, fmt, NULL, SAMPLE_HAS_ALL);
if (ret)
error("Failed to initialize IO");
diff --git a/src/signal.c b/src/signal.c
index f61ad57b3..324f12733 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -108,7 +108,8 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx)
int main(int argc, char *argv[])
{
int ret;
- struct plugin *p;
+ struct node_type *nt;
+ struct format_type *ft;
char *format = "villas.human"; /** @todo hardcoded for now */
@@ -124,19 +125,19 @@ int main(int argc, char *argv[])
if (ret)
error("Failed to intialize signals");
- p = plugin_lookup(PLUGIN_TYPE_NODE, "signal");
- if (!p)
+ nt = node_type_lookup("signal");
+ if (!nt)
error("Signal generation is not supported.");
- ret = node_init(&n, &p->node);
+ ret = node_init(&n, nt);
if (ret)
error("Failed to initialize node");
- p = plugin_lookup(PLUGIN_TYPE_FORMAT, format);
- if (!p)
+ ft = format_type_lookup(format);
+ if (!ft)
error("Invalid output format '%s'", format);
- ret = io_init(&io, &p->io, NULL, IO_FLUSH | (SAMPLE_HAS_ALL & ~SAMPLE_HAS_OFFSET));
+ ret = io_init(&io, ft, NULL, IO_FLUSH | (SAMPLE_HAS_ALL & ~SAMPLE_HAS_OFFSET));
if (ret)
error("Failed to initialize output");