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

hook: add hook_list_check()

This commit is contained in:
Steffen Vogel 2021-07-06 18:33:33 +02:00
parent bc77cf0d9f
commit 9ae9ce4dae
7 changed files with 33 additions and 16 deletions

View file

@ -90,6 +90,11 @@ public:
logger = log;
}
Logger getLogger()
{
return logger;
}
/** Called whenever a hook is started; before threads are created. */
virtual
void start()

View file

@ -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);

View file

@ -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);

View file

@ -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;
}

View file

@ -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)

View file

@ -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)

View file

@ -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;
}