mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
properly use ne plugin system to find node-types
This commit is contained in:
parent
fa648d5cac
commit
10bdf4db51
4 changed files with 24 additions and 23 deletions
23
lib/cfg.c
23
lib/cfg.c
|
@ -52,14 +52,22 @@ int cfg_init_post(struct cfg *cfg)
|
|||
info("Initialize web sub-system");
|
||||
web_init(&cfg->web, &cfg->api);
|
||||
|
||||
info("Initialize node types");
|
||||
list_foreach(struct node *n, &cfg->nodes) { INDENT
|
||||
config_setting_t *cfg_root = config_root_setting(&cfg->cfg);
|
||||
|
||||
node_type_init(n->_vt, cfg->cli.argc, cfg->cli.argv, cfg_root);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cfg_deinit(struct cfg *cfg)
|
||||
{
|
||||
info("De-initializing node types");
|
||||
list_foreach(struct node_type *vt, &node_types) { INDENT
|
||||
node_deinit(vt);
|
||||
list_foreach(struct plugin *p, &plugins) { INDENT
|
||||
if (p->type == PLUGIN_TYPE_NODE)
|
||||
node_type_deinit(&p->node);
|
||||
}
|
||||
|
||||
info("De-initializing web interface");
|
||||
|
@ -201,19 +209,20 @@ int cfg_parse(struct cfg *cfg, const char *uri)
|
|||
|
||||
for (int i = 0; i < config_setting_length(cfg_nodes); i++) {
|
||||
config_setting_t *cfg_node = config_setting_get_elem(cfg_nodes, i);
|
||||
|
||||
struct node_type *vt;
|
||||
|
||||
struct plugin *p;
|
||||
const char *type;
|
||||
|
||||
/* Required settings */
|
||||
if (!config_setting_lookup_string(cfg_node, "type", &type))
|
||||
cerror(cfg_node, "Missing node type");
|
||||
|
||||
vt = list_lookup(&node_types, type);
|
||||
if (!vt)
|
||||
|
||||
p = plugin_lookup(PLUGIN_TYPE_NODE, type);
|
||||
if (!p)
|
||||
cerror(cfg_node, "Invalid node type: %s", type);
|
||||
|
||||
struct node *n = node_create(vt);
|
||||
struct node *n = node_create(&p->node);
|
||||
|
||||
ret = node_parse(n, cfg_node);
|
||||
if (ret)
|
||||
|
|
14
lib/node.c
14
lib/node.c
|
@ -13,9 +13,7 @@
|
|||
#include "cfg.h"
|
||||
#include "utils.h"
|
||||
#include "config.h"
|
||||
|
||||
/** List of registered node-types */
|
||||
struct list node_types = LIST_INIT();
|
||||
#include "plugin.h"
|
||||
|
||||
int node_read(struct node *n, struct sample *smps[], unsigned cnt)
|
||||
{
|
||||
|
@ -262,7 +260,7 @@ int node_parse_list(struct list *list, config_setting_t *cfg, struct list *all)
|
|||
|
||||
int node_parse(struct node *n, config_setting_t *cfg)
|
||||
{
|
||||
struct node_type *vt;
|
||||
struct plugin *p;
|
||||
const char *type, *name;
|
||||
int ret;
|
||||
|
||||
|
@ -271,9 +269,11 @@ int node_parse(struct node *n, config_setting_t *cfg)
|
|||
if (!config_setting_lookup_string(cfg, "type", &type))
|
||||
cerror(cfg, "Missing node type");
|
||||
|
||||
vt = list_lookup(&node_types, type);
|
||||
if (!vt)
|
||||
cerror(cfg, "Invalid type for node '%s'", config_setting_name(cfg));
|
||||
p = plugin_lookup(PLUGIN_TYPE_NODE, type);
|
||||
assert(&p->node == n->_vt);
|
||||
|
||||
if (!config_setting_lookup_int(cfg, "vectorize", &n->vectorize))
|
||||
n->vectorize = 1;
|
||||
|
||||
n->name = name;
|
||||
n->cfg = cfg;
|
||||
|
|
|
@ -127,13 +127,6 @@ int main(int argc, char *argv[])
|
|||
|
||||
cfg_init_post(&cfg);
|
||||
|
||||
info("Initialize node types");
|
||||
list_foreach(struct node_type *vt, &node_types) { INDENT
|
||||
int refs = list_length(&vt->instances);
|
||||
if (refs > 0)
|
||||
node_init(vt, argc, argv, config_root_setting(&cfg.cfg));
|
||||
}
|
||||
|
||||
info("Starting nodes");
|
||||
list_foreach(struct node *n, &cfg.nodes) { INDENT
|
||||
int refs = list_count(&cfg.paths, (cmp_cb_t) path_uses_node, n);
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
static struct list nodes; /**< List of all nodes */
|
||||
static struct cfg cfg; /**< The global configuration */
|
||||
|
||||
struct dir {
|
||||
|
@ -223,7 +222,7 @@ int main(int argc, char *argv[])
|
|||
memory_init();
|
||||
|
||||
/* Initialize node */
|
||||
node = list_lookup(&nodes, argv[2]);
|
||||
node = list_lookup(&cfg.nodes, argv[2]);
|
||||
if (!node)
|
||||
error("Node '%s' does not exist!", argv[2]);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue