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

some cleanups in the hook system

This commit is contained in:
Steffen Vogel 2016-11-08 00:26:06 -05:00
parent fab53b0302
commit 1d3bb7c730
3 changed files with 5 additions and 17 deletions

View file

@ -103,7 +103,7 @@ enum hook_type {
HOOK_INIT = 1 << 9, /**< Called before path is started to parseHOOK_DESTROYs. */
HOOK_DESTROY = 1 << 10, /**< Called after path has been stopped to release memory allocated by HOOK_INIT */
HOOK_INTERNAL = 1 << 11, /**< Internal hooks are added to every path implicitely. */
HOOK_AUTO = 1 << 11, /**< Internal hooks are added to every path implicitely. */
HOOK_PARSE = 1 << 12, /**< Called for parsing hook arguments. */
/** @{ Classes of hooks */
@ -113,9 +113,6 @@ enum hook_type {
HOOK_PATH = HOOK_PATH_START | HOOK_PATH_STOP | HOOK_PATH_RESTART,
/** Hooks which are used to collect statistics. */
HOOK_STATS = HOOK_INTERNAL | HOOK_STORAGE | HOOK_PATH | HOOK_READ | HOOK_PERIODIC,
/** All hooks */
HOOK_ALL = HOOK_INTERNAL - 1
/** @} */
};

View file

@ -12,14 +12,11 @@
#include "path.h"
#include "utils.h"
REGISTER_HOOK("fix_ts", "Update timestamps of sample if not set", 0, 0, hook_fix_ts, HOOK_INTERNAL | HOOK_READ)
REGISTER_HOOK("fix_ts", "Update timestamps of sample if not set", 0, 0, hook_fix_ts, HOOK_AUTO | HOOK_READ)
int hook_fix_ts(struct hook *h, int when, struct hook_info *j)
{
struct timespec now = time_now();
if (when != HOOK_READ)
return 0;
assert(j->smps);
for (int i = 0; i < j->cnt; i++) {
@ -41,12 +38,9 @@ int hook_fix_ts(struct hook *h, int when, struct hook_info *j)
return j->cnt;
}
REGISTER_HOOK("restart", "Call restart hooks for current path", 1, 1, hook_restart, HOOK_INTERNAL | HOOK_READ)
REGISTER_HOOK("restart", "Call restart hooks for current path", 1, 1, hook_restart, HOOK_AUTO | HOOK_READ)
int hook_restart(struct hook *h, int when, struct hook_info *j)
{
if (when != HOOK_READ)
return 0;
assert(j->smps);
assert(j->path);
@ -69,14 +63,11 @@ int hook_restart(struct hook *h, int when, struct hook_info *j)
return j->cnt;
}
REGISTER_HOOK("drop", "Drop messages with reordered sequence numbers", 3, 1, hook_drop, HOOK_INTERNAL | HOOK_READ)
REGISTER_HOOK("drop", "Drop messages with reordered sequence numbers", 3, 1, hook_drop, HOOK_AUTO | HOOK_READ)
int hook_drop(struct hook *h, int when, struct hook_info *j)
{
int i, ok, dist;
if (when != HOOK_READ)
return 0;
assert(j->smps);
for (i = 0, ok = 0; i < j->cnt; i++) {

View file

@ -171,7 +171,7 @@ int path_init(struct path *p)
/* Add internal hooks if they are not already in the list*/
list_foreach(struct hook *h, &hooks) {
if (
(h->type & HOOK_INTERNAL) && /* is internal hook? */
(h->type & HOOK_AUTO) && /* should this hook be added implicitely? */
(list_lookup(&p->hooks, h->name) == NULL) /* is not already in list? */
)
list_push(&p->hooks, memdup(h, sizeof(struct hook)));