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

hooks: add hook_list_is_read_only()

This commit is contained in:
Steffen Vogel 2021-06-18 22:08:16 -04:00
parent d9859fe20c
commit 5a64f25b67
4 changed files with 27 additions and 11 deletions

View file

@ -169,7 +169,7 @@ public:
bool isReadOnly() const
{
return flags & HookFlags::READ_ONLY;
return flags & (int) Flags::READ_ONLY;
}
};

View file

@ -76,3 +76,5 @@ void hook_list_stop(struct vlist *hs);
struct vlist * hook_list_get_signals(struct vlist *hs);
json_t * hook_list_to_json(struct vlist *hs);
bool hook_list_is_read_only(struct vlist *hs);

View file

@ -53,8 +53,10 @@ struct vnode_direction {
*/
struct vpath *path;
int enabled;
int builtin; /**< This node should use built-in hooks by default. */
bool enabled; /**< This node direction is enabled. */
bool builtin_hooks; /**< This node direction should use built-in hooks by default. */
bool read_only_hooks; /**< The hooks of this node direction do not alter samples while processing them. */
unsigned vectorize; /**< Number of messages to send / recv at once (scatter / gather) */
struct vlist hooks; /**< List of read / write hooks (struct hook). */

View file

@ -105,25 +105,24 @@ void hook_list_prepare(struct vlist *hs, vlist *sigs, int m, struct vpath *p, st
{
assert(hs->state == State::INITIALIZED);
if (!m)
goto skip_add;
/* Add internal hooks if they are not already in the list */
for (auto f : plugin::Registry::lookup<HookFactory>()) {
if ((f->getFlags() & m) == m) {
auto h = f->make(p, n);
if (m) {
for (auto f : plugin::Registry::lookup<HookFactory>()) {
if ((f->getFlags() & m) == m) {
auto h = f->make(p, n);
vlist_push(hs, h);
vlist_push(hs, h);
}
}
}
skip_add:
/* Remove filters which are not enabled */
vlist_filter(hs, (dtor_cb_t) hook_is_enabled);
/* We sort the hooks according to their priority */
vlist_sort(hs, (cmp_cb_t) hook_cmp_priority);
/* Prepare signal list by passing is through all hooks */
for (size_t i = 0; i < vlist_length(hs); i++) {
Hook *h = (Hook *) vlist_at(hs, i);
@ -222,3 +221,16 @@ json_t * hook_list_to_json(struct vlist *hs)
return json_hooks;
}
bool hook_list_is_read_only(struct vlist *hs)
{
bool ret = true;
for (size_t i = 0; i < vlist_length(hs); i++) {
Hook *h = (Hook *) vlist_at_safe(hs, i);
ret &= h->isReadOnly();
}
return ret;
}