From c52c03265b6876bd5e379f5e34a317b787282d8a Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 20 Aug 2018 19:06:24 +0200 Subject: [PATCH] super_node: move execution of periodic hooks to super_node_periodic() --- include/villas/super_node.h | 3 +++ lib/super_node.c | 45 +++++++++++++++++++++++++++++++++++++ src/villas-node.cpp | 33 +-------------------------- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/include/villas/super_node.h b/include/villas/super_node.h index 68f3034dc..45ccd108a 100644 --- a/include/villas/super_node.h +++ b/include/villas/super_node.h @@ -88,6 +88,9 @@ int super_node_stop(struct super_node *sn); /** Desctroy configuration object. */ int super_node_destroy(struct super_node *sn); +/** Run periodic hooks of this super node. */ +int super_node_periodic(struct super_node *sn); + #ifdef __cplusplus } #endif diff --git a/lib/super_node.c b/lib/super_node.c index d04b2c0a1..7e0c94004 100644 --- a/lib/super_node.c +++ b/lib/super_node.c @@ -491,3 +491,48 @@ int super_node_destroy(struct super_node *sn) return 0; } + +int super_node_periodic(struct super_node *sn) +{ + int ret; + + for (size_t i = 0; i < list_length(&sn->paths); i++) { + struct path *p = (struct path *) list_at(&sn->paths, i); + + if (p->state != STATE_STARTED) + continue; + + for (size_t j = 0; j < list_length(&p->hooks); j++) { + struct hook *h = (struct hook *) list_at(&p->hooks, j); + + ret = hook_periodic(h); + if (ret) + return ret; + } + } + + for (size_t i = 0; i < list_length(&sn->nodes); i++) { + struct node *n = (struct node *) list_at(&sn->nodes, i); + + if (n->state != STATE_STARTED) + continue; + + for (size_t j = 0; j < list_length(&n->in.hooks); j++) { + struct hook *h = (struct hook *) list_at(&n->in.hooks, j); + + ret = hook_periodic(h); + if (ret) + return ret; + } + + for (size_t j = 0; j < list_length(&n->out.hooks); j++) { + struct hook *h = (struct hook *) list_at(&n->out.hooks, j); + + ret = hook_periodic(h); + if (ret) + return ret; + } + } + + return 0; +} diff --git a/src/villas-node.cpp b/src/villas-node.cpp index 6b7e9e8e3..037b3f38f 100644 --- a/src/villas-node.cpp +++ b/src/villas-node.cpp @@ -177,38 +177,7 @@ int main(int argc, char *argv[]) for (;;) { task_wait(&t); - - for (size_t i = 0; i < list_length(&sn.paths); i++) { - struct path *p = (struct path *) list_at(&sn.paths, i); - - if (p->state != STATE_STARTED) - continue; - - for (size_t j = 0; j < list_length(&p->hooks); j++) { - struct hook *h = (struct hook *) list_at(&p->hooks, j); - - hook_periodic(h); - } - } - - for (size_t i = 0; i < list_length(&sn.nodes); i++) { - struct node *n = (struct node *) list_at(&sn.nodes, i); - - if (n->state != STATE_STARTED) - continue; - - for (size_t j = 0; j < list_length(&n->in.hooks); j++) { - struct hook *h = (struct hook *) list_at(&n->in.hooks, j); - - hook_periodic(h); - } - - for (size_t j = 0; j < list_length(&n->out.hooks); j++) { - struct hook *h = (struct hook *) list_at(&n->out.hooks, j); - - hook_periodic(h); - } - } + super_node_periodic(&sn); } } else