2016-06-08 22:38:50 +02:00
|
|
|
/** Hook-releated functions.
|
2014-08-31 14:43:28 +00:00
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2016-02-09 05:33:19 +01:00
|
|
|
* @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC
|
2015-06-02 21:53:04 +02:00
|
|
|
* This file is part of S2SS. All Rights Reserved. Proprietary and confidential.
|
2015-08-07 01:11:43 +02:00
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2015-03-18 16:13:18 +01:00
|
|
|
|
2014-08-31 14:43:28 +00:00
|
|
|
#include <string.h>
|
2015-09-28 19:18:39 +02:00
|
|
|
#include <math.h>
|
2014-08-31 14:43:28 +00:00
|
|
|
|
2015-06-10 15:05:36 +02:00
|
|
|
#include "timing.h"
|
2015-05-06 11:38:57 +02:00
|
|
|
#include "config.h"
|
2014-08-31 14:43:28 +00:00
|
|
|
#include "msg.h"
|
|
|
|
#include "hooks.h"
|
2015-03-18 16:13:18 +01:00
|
|
|
#include "path.h"
|
|
|
|
#include "utils.h"
|
2015-12-13 00:42:59 +01:00
|
|
|
#include "node.h"
|
2015-06-10 15:10:51 +02:00
|
|
|
|
2015-09-19 15:26:30 +02:00
|
|
|
struct list hooks;
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2016-01-15 15:34:28 +01:00
|
|
|
/* Those references can be used inside the hook callbacks after initializing them with hook_init() */
|
2016-06-08 22:38:50 +02:00
|
|
|
struct list *hook_nodes = NULL;
|
|
|
|
struct list *hook_paths = NULL;
|
|
|
|
struct settings *hook_settings = NULL;
|
2016-01-15 15:34:28 +01:00
|
|
|
|
|
|
|
void hook_init(struct list *nodes, struct list *paths, struct settings *set)
|
|
|
|
{
|
|
|
|
hook_nodes = nodes;
|
|
|
|
hook_paths = paths;
|
|
|
|
hook_settings = set;
|
|
|
|
}
|
|
|
|
|
2016-01-14 22:59:57 +01:00
|
|
|
int hooks_sort_priority(const void *a, const void *b) {
|
|
|
|
struct hook *ha = (struct hook *) a;
|
|
|
|
struct hook *hb = (struct hook *) b;
|
|
|
|
|
|
|
|
return ha->priority - hb->priority;
|
|
|
|
}
|
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
int hook_run(struct path *p, struct sample *smps[], size_t cnt, int when)
|
2016-02-07 14:24:58 +01:00
|
|
|
{
|
|
|
|
list_foreach(struct hook *h, &p->hooks) {
|
2016-06-08 22:38:50 +02:00
|
|
|
if (h->type & when) {
|
|
|
|
debug(DBG_HOOK | 22, "Running hook when=%u '%s' prio=%u, cnt=%zu", when, h->name, h->priority, cnt);
|
2015-08-07 01:11:43 +02:00
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
cnt = h->cb(p, h, when, smps, cnt);
|
|
|
|
if (cnt == 0)
|
|
|
|
break;
|
2015-10-09 13:30:41 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-12 16:16:25 +02:00
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
return cnt;
|
2015-10-12 16:16:25 +02:00
|
|
|
}
|
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
void * hook_storage(struct hook *h, int when, size_t len)
|
2015-10-09 13:30:41 +02:00
|
|
|
{
|
|
|
|
switch (when) {
|
2016-06-08 22:38:50 +02:00
|
|
|
case HOOK_INIT:
|
|
|
|
h->_vd = alloc(len);
|
2015-10-09 13:30:41 +02:00
|
|
|
break;
|
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
case HOOK_DEINIT:
|
|
|
|
free(h->_vd);
|
|
|
|
h->_vd = NULL;
|
2015-10-09 13:30:41 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
return h->_vd;
|
2015-10-09 13:30:41 +02:00
|
|
|
}
|