1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

remove {node, path}_create() functions

This commit is contained in:
Steffen Vogel 2017-03-11 23:33:41 -03:00
parent c90343d4af
commit d5bcd02b2c
5 changed files with 96 additions and 42 deletions

View file

@ -51,13 +51,6 @@ struct node
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this node */
};
/** Create a node by allocating dynamic memory.
*
* @see node_type::create
* @param vt A pointer to the node-type table of virtual functions.
*/
struct node * node_create(struct node_type *vt);
/** Destroy node by freeing dynamically allocated memory.
*
* @see node_type::destroy

View file

@ -73,9 +73,6 @@ struct path
config_setting_t *cfg; /**< A pointer to the libconfig object which instantiated this path */
};
/** Allocate memory for a new path */
struct path * path_create();
/** Initialize internal data structures. */
int path_init(struct path *p, struct cfg *cfg);

107
lib/cfg.c
View file

@ -229,13 +229,13 @@ int cfg_parse(struct cfg *cfg, const char *uri)
if (!p)
cerror(cfg_node, "Invalid node type: %s", type);
struct node *n = node_create(&p->node);
struct node n;
ret = node_parse(n, cfg_node);
ret = node_parse(&n, cfg_node);
if (ret)
cerror(cfg_node, "Failed to parse node");
list_push(&cfg->nodes, n);
list_push(&cfg->nodes, memdup(&n, sizeof(n)));
}
}
@ -248,26 +248,111 @@ int cfg_parse(struct cfg *cfg, const char *uri)
for (int i = 0; i < config_setting_length(cfg_paths); i++) {
config_setting_t *cfg_path = config_setting_get_elem(cfg_paths, i);
struct path *p = path_create();
struct path p;
ret = path_parse(p, cfg_path, &cfg->nodes);
ret = path_parse(&p, cfg_path, &cfg->nodes);
if (ret)
cerror(cfg_path, "Failed to parse path");
list_push(&cfg->paths, p);
list_push(&cfg->paths, memdup(&p, sizeof(p)));
if (p->reverse) {
struct path *r = path_create();
if (p.reverse) {
struct path r;
ret = path_reverse(p, r);
ret = path_reverse(&p, &r);
if (ret)
cerror(cfg_path, "Failed to reverse path %s", path_name(p));
cerror(cfg_path, "Failed to reverse path %s", path_name(&p));
list_push(&cfg->paths, r);
list_push(&cfg->paths, memdup(&r, sizeof(p)));
}
}
}
}
cfg->state = STATE_PARSED;
return 0;
}
int cfg_start(struct cfg *cfg)
{
memory_init(cfg->hugepages);
rt_init(cfg->priority, cfg->affinity);
api_start(&cfg->api);
web_start(&cfg->web);
info("Start node types");
list_foreach(struct node *n, &cfg->nodes) { INDENT
config_setting_t *cfg_root = config_root_setting(&cfg->cfg);
node_type_start(n->_vt, cfg->cli.argc, cfg->cli.argv, cfg_root);
}
info("Starting nodes");
list_foreach(struct node *n, &cfg->nodes) { INDENT
int refs = list_count(&cfg->paths, (cmp_cb_t) path_uses_node, n);
if (refs > 0)
node_start(n);
else
warn("No path is using the node %s. Skipping...", node_name(n));
}
info("Starting paths");
list_foreach(struct path *p, &cfg->paths) { INDENT
if (p->enabled) {
path_init(p, cfg);
path_start(p);
}
else
warn("Path %s is disabled. Skipping...", path_name(p));
}
cfg->state = STATE_STARTED;
return 0;
}
int cfg_stop(struct cfg *cfg)
{
info("Stopping paths");
list_foreach(struct path *p, &cfg->paths) { INDENT
path_stop(p);
}
info("Stopping nodes");
list_foreach(struct node *n, &cfg->nodes) { INDENT
node_stop(n);
}
info("De-initializing node types");
list_foreach(struct plugin *p, &plugins) { INDENT
if (p->type == PLUGIN_TYPE_NODE)
node_type_stop(&p->node);
}
web_stop(&cfg->web);
api_stop(&cfg->api);
log_stop(&cfg->log);
cfg->state = STATE_STOPPED;
return 0;
}
int cfg_destroy(struct cfg *cfg)
{
config_destroy(&cfg->cfg);
web_destroy(&cfg->web);
log_destroy(&cfg->log);
api_destroy(&cfg->api);
list_destroy(&cfg->plugins, (dtor_cb_t) plugin_destroy, false);
list_destroy(&cfg->paths, (dtor_cb_t) path_destroy, true);
list_destroy(&cfg->nodes, (dtor_cb_t) node_destroy, true);
cfg->state = STATE_DESTROYED;
return 0;
}

View file

@ -131,23 +131,7 @@ int node_reverse(struct node *n)
return n->_vt->reverse ? n->_vt->reverse(n) : -1;
}
struct node * node_create(struct node_type *vt)
{
struct node *n = alloc(sizeof(struct node));
list_push(&vt->instances, n);
n->_vt = vt;
n->_vd = alloc(n->_vt->size);
if (n->_vt->create)
n->_vt->create(n);
n->state = NODE_CREATED;
return n;
}
int node_destroy(struct node *n)
{
if (n->_vt->destroy)

View file

@ -182,11 +182,6 @@ const char * path_name(struct path *p)
return p->_name;
}
struct path * path_create()
{
return (struct path *) alloc(sizeof(struct path));
}
static int path_source_destroy(struct path_source *ps)
{
pool_destroy(&ps->pool);