diff --git a/include/villas/hook.hpp b/include/villas/hook.hpp index 1b3036a79..943f92983 100644 --- a/include/villas/hook.hpp +++ b/include/villas/hook.hpp @@ -90,6 +90,11 @@ public: logger = log; } + Logger getLogger() + { + return logger; + } + /** Called whenever a hook is started; before threads are created. */ virtual void start() diff --git a/include/villas/hook_list.hpp b/include/villas/hook_list.hpp index 831cc177f..517b4d157 100644 --- a/include/villas/hook_list.hpp +++ b/include/villas/hook_list.hpp @@ -59,6 +59,8 @@ int hook_list_destroy(struct vlist *hs) __attribute__ ((warn_unused_result)); */ void hook_list_parse(struct vlist *hs, json_t *json, int mask, struct vpath *p, struct vnode *n); +void hook_list_check(struct vlist *hs); + void hook_list_prepare(struct vlist *hs, struct vlist *sigs, int mask, struct vpath *p, struct vnode *n); int hook_list_prepare_signals(struct vlist *hs, struct vlist *signals); diff --git a/include/villas/node_direction.h b/include/villas/node_direction.h index a353dd6e0..4610d3a14 100644 --- a/include/villas/node_direction.h +++ b/include/villas/node_direction.h @@ -69,7 +69,7 @@ int node_direction_destroy(struct vnode_direction *nd, struct vnode *n) __attrib int node_direction_parse(struct vnode_direction *nd, struct vnode *n, json_t *json); -int node_direction_check(struct vnode_direction *nd, struct vnode *n); +void node_direction_check(struct vnode_direction *nd, struct vnode *n); int node_direction_prepare(struct vnode_direction *nd, struct vnode *n); diff --git a/lib/hook_list.cpp b/lib/hook_list.cpp index 1b247ba79..cca317e7c 100644 --- a/lib/hook_list.cpp +++ b/lib/hook_list.cpp @@ -80,9 +80,9 @@ void hook_list_parse(struct vlist *hs, json_t *json, int mask, struct vpath *o, break; case JSON_OBJECT: - ret = json_unpack_ex(json_hook, &err, 0, "{ s: s }", "type", &type); - if (ret) - throw ConfigError(json_hook, err, "node-config-hook", "Failed to parse hook"); + ret = json_unpack_ex(json_hook, &err, 0, "{ s: s }", "type", &type); + if (ret) + throw ConfigError(json_hook, err, "node-config-hook", "Failed to parse hook"); json_config = json_hook; break; @@ -114,6 +114,15 @@ static int hook_is_enabled(const Hook *h) return h->isEnabled() ? 0 : -1; } +void hook_list_check(struct vlist *hs) +{ + for (size_t i = 0; i < vlist_length(hs); i++) { + Hook *h = (Hook *) vlist_at(hs, i); + + h->check(); + } +} + void hook_list_prepare(struct vlist *hs, vlist *sigs, int m, struct vpath *p, struct vnode *n) { assert(hs->state == State::INITIALIZED); @@ -233,11 +242,11 @@ unsigned hook_list_get_signals_max_cnt(struct vlist *hs) struct vlist *sigs = h->getSignals(); unsigned sigs_cnt = vlist_length(sigs); - + if (sigs_cnt > max_cnt) max_cnt = sigs_cnt; } - + return max_cnt; } diff --git a/lib/node.cpp b/lib/node.cpp index 5be36eaff..d9699942e 100644 --- a/lib/node.cpp +++ b/lib/node.cpp @@ -244,13 +244,8 @@ int node_check(struct vnode *n) int ret; assert(n->state != State::DESTROYED); - ret = node_direction_check(&n->in, n); - if (ret) - return ret; - - ret = node_direction_check(&n->out, n); - if (ret) - return ret; + node_direction_check(&n->in, n); + node_direction_check(&n->out, n); ret = node_type(n)->check ? node_type(n)->check(n) : 0; if (ret) diff --git a/lib/node_direction.cpp b/lib/node_direction.cpp index a02f5a157..4e72e5848 100644 --- a/lib/node_direction.cpp +++ b/lib/node_direction.cpp @@ -168,16 +168,18 @@ int node_direction_parse(struct vnode_direction *nd, struct vnode *n, json_t *js return 0; } -int node_direction_check(struct vnode_direction *nd, struct vnode *n) +void node_direction_check(struct vnode_direction *nd, struct vnode *n) { assert(n->state != State::DESTROYED); if (nd->vectorize <= 0) throw RuntimeError("Invalid setting 'vectorize' with value {}. Must be natural number!", nd->vectorize); - nd->state = State::CHECKED; +#ifdef WITH_HOOKS + hook_list_check(&nd->hooks); +#endif /* WITH_HOOKS */ - return 0; + nd->state = State::CHECKED; } int node_direction_start(struct vnode_direction *nd, struct vnode *n) diff --git a/lib/path.cpp b/lib/path.cpp index 9e3d79ccb..538fc7871 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -567,6 +567,10 @@ void path_check(struct vpath *p) path_destination_check(ps); } +#ifdef WITH_HOOKS + hook_list_check(&p->hooks); +#endif /* WITH_HOOKS */ + p->state = State::CHECKED; }