mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
improved node creation
This commit is contained in:
parent
ef2bcda344
commit
41cd1402be
3 changed files with 31 additions and 20 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue