diff --git a/include/villas/hook.h b/include/villas/hook.h index 28ecfddf6..bfc348ac1 100644 --- a/include/villas/hook.h +++ b/include/villas/hook.h @@ -81,6 +81,12 @@ int hook_process_list(struct vlist *hs, struct sample *smps[], unsigned cnt); /** Compare two hook functions with their priority. Used by vlist_sort() */ int hook_cmp_priority(const void *a, const void *b); +static inline +struct hook_type * hook_type(struct hook *h) +{ + return h->_vt; +} + /** Parses an object of hooks * * Example: diff --git a/include/villas/node.h b/include/villas/node.h index 0673f2ef9..59a3b111f 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -199,7 +199,11 @@ int node_poll_fds(struct node *n, int fds[]); int node_netem_fds(struct node *n, int fds[]); -struct node_type * node_type(struct node *n); +static inline +struct node_type * node_type(struct node *n) +{ + return n->_vt; +} struct memory_type * node_memory_type(struct node *n, struct memory_type *parent); diff --git a/lib/hook.c b/lib/hook.c index 17b693e7a..85bd71b2f 100644 --- a/lib/hook.c +++ b/lib/hook.c @@ -45,7 +45,7 @@ int hook_init(struct hook *h, struct hook_type *vt, struct path *p, struct node h->_vt = vt; h->_vd = alloc(vt->size); - ret = h->_vt->init ? h->_vt->init(h) : 0; + ret = hook_type(h)->init ? hook_type(h)->init(h) : 0; if (ret) return ret; @@ -66,9 +66,9 @@ int hook_parse(struct hook *h, json_t *cfg) "enabled", &h->enabled ); if (ret) - jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(h->_vt)); + jerror(&err, "Failed to parse configuration of hook '%s'", hook_type_name(hook_type(h))); - ret = h->_vt->parse ? h->_vt->parse(h, cfg) : 0; + ret = hook_type(h)->parse ? hook_type(h)->parse(h, cfg) : 0; if (ret) return ret; @@ -84,7 +84,7 @@ int hook_destroy(struct hook *h) assert(h->state != STATE_DESTROYED); - ret = h->_vt->destroy ? h->_vt->destroy(h) : 0; + ret = hook_type(h)->destroy ? hook_type(h)->destroy(h) : 0; if (ret) return ret; @@ -101,10 +101,10 @@ int hook_start(struct hook *h) if (!h->enabled) return 0; - if (h->_vt->start) { - debug(LOG_HOOK | 10, "Start hook %s: priority=%d", hook_type_name(h->_vt), h->priority); + if (hook_type(h)->start) { + debug(LOG_HOOK | 10, "Start hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority); - return h->_vt->start(h); + return hook_type(h)->start(h); } else return 0; @@ -115,10 +115,10 @@ int hook_stop(struct hook *h) if (!h->enabled) return 0; - if (h->_vt->stop) { - debug(LOG_HOOK | 10, "Stopping hook %s: priority=%d", hook_type_name(h->_vt), h->priority); + if (hook_type(h)->stop) { + debug(LOG_HOOK | 10, "Stopping hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority); - return h->_vt->stop(h); + return hook_type(h)->stop(h); } else return 0; @@ -129,10 +129,10 @@ int hook_periodic(struct hook *h) if (!h->enabled) return 0; - if (h->_vt->periodic) { - debug(LOG_HOOK | 10, "Periodic hook %s: priority=%d", hook_type_name(h->_vt), h->priority); + if (hook_type(h)->periodic) { + debug(LOG_HOOK | 10, "Periodic hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority); - return h->_vt->periodic(h); + return hook_type(h)->periodic(h); } else return 0; @@ -143,10 +143,10 @@ int hook_restart(struct hook *h) if (!h->enabled) return 0; - if (h->_vt->restart) { - debug(LOG_HOOK | 10, "Restarting hook %s: priority=%d", hook_type_name(h->_vt), h->priority); + if (hook_type(h)->restart) { + debug(LOG_HOOK | 10, "Restarting hook %s: priority=%d", hook_type_name(hook_type(h)), h->priority); - return h->_vt->restart(h); + return hook_type(h)->restart(h); } else return 0; @@ -157,10 +157,10 @@ int hook_process(struct hook *h, struct sample *smps[], unsigned *cnt) if (!h->enabled) return 0; - if (h->_vt->process) { - debug(LOG_HOOK | 10, "Process hook %s: priority=%d, cnt=%d", hook_type_name(h->_vt), h->priority, *cnt); + if (hook_type(h)->process) { + debug(LOG_HOOK | 10, "Process hook %s: priority=%d, cnt=%d", hook_type_name(hook_type(h)), h->priority, *cnt); - return h->_vt->process(h, smps, cnt); + return hook_type(h)->process(h, smps, cnt); } else return 0; diff --git a/lib/node.c b/lib/node.c index a25e0ff22..d3659d39a 100644 --- a/lib/node.c +++ b/lib/node.c @@ -704,13 +704,6 @@ int node_netem_fds(struct node *n, int fds[]) return node_type(n)->netem_fds ? node_type(n)->netem_fds(n, fds) : -1; } -struct node_type * node_type(struct node *n) -{ - assert(n->state != STATE_DESTROYED); - - return n->_vt; -} - struct memory_type * node_memory_type(struct node *n, struct memory_type *parent) { return node_type(n)->memory_type ? node_type(n)->memory_type(n, parent) : &memory_hugepage;