diff --git a/include/villas/path.h b/include/villas/path.h index abd1dfbc2..0bcb4cf56 100644 --- a/include/villas/path.h +++ b/include/villas/path.h @@ -77,8 +77,8 @@ struct path /** @} */ }; -/** Create a path by allocating dynamic memory. */ -void path_init(struct path *p); +/** Initialize internal data structures. */ +int path_init(struct path *p); /** Destroy path by freeing dynamically allocated memory. * @@ -86,12 +86,6 @@ void path_init(struct path *p); */ void path_destroy(struct path *p); -/** Initialize pool queue and hooks. - * - * Should be called after path_init() and before path_start(). - */ -int path_prepare(struct path *p); - /** Start a path. * * Start a new pthread for receiving/sending messages over this path. diff --git a/lib/cfg.c b/lib/cfg.c index 84fbfd35f..f8f4b963d 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -154,7 +154,9 @@ int cfg_parse_path(config_setting_t *cfg, /* Allocate memory and intialize path structure */ p = alloc(sizeof(struct path)); - path_init(p); + + list_init(&p->destinations); + list_init(&p->hooks); /* Input node */ if (!config_setting_lookup_string(cfg, "in", &in) && diff --git a/lib/path.c b/lib/path.c index f94feeea3..6399bb6e1 100644 --- a/lib/path.c +++ b/lib/path.c @@ -135,28 +135,20 @@ const char * path_name(struct path *p) return p->_name; } -void path_init(struct path *p) -{ - list_init(&p->destinations); - list_init(&p->hooks); - - /* Initialize hook system */ - list_foreach(struct hook *h, &hooks) { - if (h->type & HOOK_INTERNAL) - list_push(&p->hooks, memdup(h, sizeof(*h))); - } - - p->state = PATH_CREATED; -} - -int path_prepare(struct path *p) +int path_init(struct path *p) { int ret; - + + /* Add internal hooks if they are not already in the list*/ + list_foreach(struct hook *h, &hooks) { + if ((h->type & HOOK_INTERNAL) && (list_lookup(&p->hooks, h->name) == NULL)) + list_push(&p->hooks, memdup(h, sizeof(struct hook))); + } + /* We sort the hooks according to their priority before starting the path */ list_sort(&p->hooks, hooks_sort_priority); - /* Allocate hook private memory */ + /* Allocate hook private memory for storing state / parameters */ ret = hook_run(p, NULL, 0, HOOK_INIT); if (ret) error("Failed to initialize hooks of path: %s", path_name(p)); diff --git a/src/node.c b/src/node.c index b4cf53cd7..1a4305b90 100644 --- a/src/node.c +++ b/src/node.c @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) info("Starting paths"); list_foreach(struct path *p, &paths) { INDENT if (p->enabled) { - path_prepare(p); + path_init(p); path_start(p); } else