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

refactored path_run_hook() to hook_run()

This commit is contained in:
Steffen Vogel 2016-02-07 14:24:58 +01:00
parent dba5fe7696
commit 5efc178408
5 changed files with 34 additions and 34 deletions

View file

@ -91,6 +91,15 @@ void hook_init(struct list *nodes, struct list *paths, struct settings *set);
/** Sort hook list according to the their priority. See hook::priority. */
int hooks_sort_priority(const void *a, const void *b);
/** Conditionally execute the hooks
*
* @param p A pointer to the path structure.
* @param t Which type of hooks should be executed?
* @retval 0 All registred hooks for the specified type have been executed successfully.
* @retval <0 On of the hook functions signalized, that the processing should be aborted; message should be skipped.
*/
int hook_run(struct path *p, enum hook_type t);
/** The following prototypes are example hooks
*
* @addtogroup hooks_examples Examples for hook functions

View file

@ -126,15 +126,6 @@ void path_print_stats(struct path *p);
*/
const char * path_name(struct path *p);
/** Conditionally execute the hooks
*
* @param p A pointer to the path structure.
* @param t Which type of hooks should be executed?
* @retval 0 All registred hooks for the specified type have been executed successfully.
* @retval <0 On of the hook functions signalized, that the processing should be aborted; message should be skipped.
*/
int path_run_hook(struct path *p, enum hook_type t);
/** Check if node is used as source or destination of a path. */
int path_uses_node(struct path *p, struct node *n);

View file

@ -44,6 +44,23 @@ int hooks_sort_priority(const void *a, const void *b) {
return ha->priority - hb->priority;
}
int hook_run(struct path *p, enum hook_type t)
{
int ret = 0;
list_foreach(struct hook *h, &p->hooks) {
if (h->type & t) {
debug(22, "Running hook when=%u '%s' prio=%u", t, h->name, h->priority);
ret = ((hook_cb_t) h->cb)(p, h, t);
if (ret)
return ret;
}
}
return ret;
}
REGISTER_HOOK("print", 99, hook_print, HOOK_MSG)
int hook_print(struct path *p, struct hook *h, int when)
{
@ -324,7 +341,7 @@ int hook_restart(struct path *p, struct hook *h, int when)
p->dropped = 0;
p->received = 1;
if (path_run_hook(p, HOOK_PATH_RESTART))
if (hook_run(p, HOOK_PATH_RESTART))
return -1;
}

View file

@ -31,23 +31,6 @@ static void path_write(struct path *p)
}
}
int path_run_hook(struct path *p, enum hook_type t)
{
int ret = 0;
list_foreach(struct hook *h, &p->hooks) {
if (h->type & t) {
debug(22, "Running hook when=%u '%s' prio=%u", t, h->name, h->priority);
ret = ((hook_cb_t) h->cb)(p, h, t);
if (ret)
return ret;
}
}
return ret;
}
/** Send messages asynchronously */
static void * path_run_async(void *arg)
{
@ -67,7 +50,7 @@ static void * path_run_async(void *arg)
if (p->received == 0)
continue;
if (path_run_hook(p, HOOK_ASYNC))
if (hook_run(p, HOOK_ASYNC))
continue;
path_write(p);
@ -97,7 +80,7 @@ static void * path_run(void *arg)
debug(15, "Received %u messages from node %s", recv, node_name(p->in));
/* Run preprocessing hooks */
if (path_run_hook(p, HOOK_PRE)) {
if (hook_run(p, HOOK_PRE)) {
p->skipped += recv;
continue;
}
@ -110,14 +93,14 @@ static void * path_run(void *arg)
p->received++;
/* Run hooks for filtering, stats collection and manipulation */
if (path_run_hook(p, HOOK_MSG)) {
if (hook_run(p, HOOK_MSG)) {
p->skipped++;
continue;
}
}
/* Run post processing hooks */
if (path_run_hook(p, HOOK_POST)) {
if (hook_run(p, HOOK_POST)) {
p->skipped += recv;
continue;
}
@ -138,7 +121,7 @@ int path_start(struct path *p)
/* We sort the hooks according to their priority before starting the path */
list_sort(&p->hooks, hooks_sort_priority);
if (path_run_hook(p, HOOK_PATH_START))
if (hook_run(p, HOOK_PATH_START))
return -1;
/* At fixed rate mode, we start another thread for sending */
@ -171,7 +154,7 @@ int path_stop(struct path *p)
p->state = PATH_STOPPED;
if (path_run_hook(p, HOOK_PATH_STOP))
if (hook_run(p, HOOK_PATH_STOP))
return -1;
return 0;

View file

@ -188,7 +188,7 @@ int main(int argc, char *argv[])
for (;;) {
list_foreach(struct path *p, &paths)
path_run_hook(p, HOOK_PERIODIC);
hook_run(p, HOOK_PERIODIC);
usleep(settings.stats * 1e6);
}
}