mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
simplified path_init / prepare logic
This commit is contained in:
parent
de1058cbd6
commit
982cd91d63
4 changed files with 15 additions and 27 deletions
|
@ -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.
|
||||
|
|
|
@ -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) &&
|
||||
|
|
26
lib/path.c
26
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));
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue