diff --git a/server/include/node.h b/server/include/node.h index 185246c3f..c498b080f 100644 --- a/server/include/node.h +++ b/server/include/node.h @@ -56,7 +56,7 @@ extern struct list node_types; /** C++ like vtable construct for node_types */ struct node_type { /** The unique name of this node. This must be allways the first member! */ - char *name; + const char *name; enum { BSD_SOCKET, /**< BSD Socket API */ @@ -162,7 +162,8 @@ struct node_type { */ struct node { - char *name; /**< A short identifier of the node, only used for configuration and logging */ + const char *name; /**< A short identifier of the node, only used for configuration and logging */ + int refcnt; /**< How many paths are sending / receiving from this node? */ int combine; /**< Number of messages to send / recv at once (scatter / gather) */ int affinity; /**< CPU Affinity of this node */ @@ -231,7 +232,7 @@ int node_stop(struct node *n); void node_reverse(struct node *n); /** Create a node by allocating dynamic memory. */ -struct node * node_create(); +struct node * node_create(struct node_type *vt); /** Destroy node by freeing dynamically allocated memory. * diff --git a/server/src/cfg.c b/server/src/cfg.c index 827fd257a..acfb915b2 100644 --- a/server/src/cfg.c +++ b/server/src/cfg.c @@ -245,33 +245,39 @@ int config_parse_nodelist(config_setting_t *cfg, struct list *list, struct list int config_parse_node(config_setting_t *cfg, struct list *nodes, struct settings *set) { - const char *type; + const char *type, *name; int ret; - struct node *n = node_create(); + struct node *n; + struct node_type *vt; /* Required settings */ - n->cfg = cfg; - n->name = config_setting_name(cfg); - if (!n->name) - cerror(cfg, "Missing node name"); - if (!config_setting_lookup_string(cfg, "type", &type)) cerror(cfg, "Missing node type"); + + name = config_setting_name(cfg); + + vt = list_lookup(&node_types, type); + if (!vt) + cerror(cfg, "Invalid type for node '%s'", config_setting_name(cfg)); + + n = node_create(vt); + + n->name = name; + n->cfg = cfg; + + ret = node_parse(n, cfg); + if (ret) + cerror(cfg, "Failed to parse node '%s'", n->name); if (!config_setting_lookup_int(cfg, "combine", &n->combine)) n->combine = 1; if (!config_setting_lookup_int(cfg, "affinity", &n->combine)) n->affinity = set->affinity; - - n->_vt = list_lookup(&node_types, type); - if (!n->_vt) - cerror(cfg, "Invalid type for node '%s'", n->name); - - ret = n->_vt->parse(cfg, n); - if (!ret) - list_push(nodes, n); + + list_push(nodes, n); + list_push(&vt->nodes, n); return ret; } diff --git a/server/src/node.c b/server/src/node.c index 52d54114e..dfda0c8fe 100644 --- a/server/src/node.c +++ b/server/src/node.c @@ -101,9 +101,13 @@ void node_reverse(struct node *n) } } -struct node * node_create() +struct node * node_create(struct node_type *vt) { - return alloc(sizeof(struct node)); + struct node *n = alloc(sizeof(struct node)); + + n->_vt = vt; + + return n; } void node_destroy(struct node *n)