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

added new tool to run hook functions with villas-pipe and villas-signal

This commit is contained in:
Steffen Vogel 2016-10-22 20:43:36 -04:00
parent a9363dad44
commit 5ba5164c1a
4 changed files with 129 additions and 6 deletions

View file

@ -1,7 +1,7 @@
#include <villas/hooks.h>
#include <villas/log.h>
static int hook_example(struct path *p, struct hook *h, int when, struct sample *smps[], size_t cnt)
static int hook_example(struct hook *h, int when, struct hook_info *j)
{
info("Hello world from example hook!");

View file

@ -2,7 +2,8 @@
TARGETS = $(BUILDDIR)/villas-node \
$(BUILDDIR)/villas-pipe \
$(BUILDDIR)/villas-signal \
$(BUILDDIR)/villas-test
$(BUILDDIR)/villas-test \
$(BUILDDIR)/villas-hook
SRC_LDLIBS = $(LDLIBS) -pthread -lm -lvillas
SRC_CFLAGS = $(CFLAGS)

121
src/hook.c Normal file
View file

@ -0,0 +1,121 @@
/** Receive messages from server snd print them on stdout.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC
* This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited.
*
* @addtogroup tools Test and debug tools
* @{
*********************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <villas/sample.h>
#include <villas/hooks.h>
#include <villas/utils.h>
#include <villas/pool.h>
#include <villas/log.h>
#include <config.h>
static void usage()
{
printf("Usage: villas-hook [OPTIONS] NAME [PARAMETER] \n");
printf(" NAME the name of the hook function to run\n");
printf(" PARAM the name of the node to which samples are sent and received from\n\n");
printf(" OPTIONS are:\n");
printf(" -h show this help\n");
printf(" -d lvl set debug level\n");
printf(" -v process multiple samples at once\n\n");
print_copyright();
}
int main(int argc, char *argv[])
{
int j, ret, cnt = 1;
char *name, *parameter;
struct hook *h;
struct hook_info *i = alloc(sizeof(struct hook_info));
char c;
while ((c = getopt(argc, argv, "hv:d:")) != -1) {
switch (c) {
case 'v':
cnt = atoi(optarg);
break;
case 'd':
log_setlevel(atoi(optarg), -1);
break;
case 'h':
case '?':
usage(argv[0]);
exit(EXIT_SUCCESS);
}
}
if (argc <= optind)
name = argc > optind ? argv[optind ] : NULL;
parameter = argc > optind + 1 ? argv[optind+1] : NULL;
if (argc > optind)
name = argv[optind];
else {
usage(argv[0]);
exit(EXIT_FAILURE);
}
if (argc > optind + 1)
parameter = argv[optind + 1];
h = list_lookup(&hooks, name);
if (!h)
error("Unknown hook function '%s'", argv[optind]);
if (cnt < 1)
error("Vectorize option must be greater than 0");
struct pool pool;
struct sample *smps[cnt];
ret = pool_init(&pool, 10 * cnt, SAMPLE_LEN(DEFAULT_VALUES), &memtype_hugepage);
if (ret)
error("Failed to initilize memory pool");
ret = sample_alloc(&pool, smps, cnt);
if (ret)
error("Failed to allocate %u samples from pool", cnt);
h->parameter = parameter;
i->smps = smps;
h->cb(h, HOOK_INIT, i);
h->cb(h, HOOK_PARSE, i);
h->cb(h, HOOK_PATH_START, i);
while (!feof(stdin)) {
for (j = 0; j < cnt && !feof(stdin); j++)
sample_fscan(stdin, i->smps[j], NULL);
i->cnt = j;
i->cnt = h->cb(h, HOOK_READ, i);
i->cnt = h->cb(h, HOOK_WRITE, i);
for (j = 0; j < i->cnt; j++)
sample_fprint(stdout, i->smps[j], SAMPLE_ALL);
}
h->cb(h, HOOK_PATH_STOP, i);
h->cb(h, HOOK_DESTROY, i);
sample_free(smps, cnt);
pool_destroy(&pool);
return 0;
}

View file

@ -128,9 +128,6 @@ int main(int argc, char *argv[])
info("Initialize signals");
signals_init();
info("Initialize hook sub-system");
hook_init(&nodes, &paths, &settings);
info("Initialize node types");
list_foreach(struct node_type *vt, &node_types) { INDENT
int refs = list_length(&vt->instances);
@ -151,6 +148,10 @@ int main(int argc, char *argv[])
list_foreach(struct path *p, &paths) { INDENT
if (p->enabled) {
path_init(p);
list_foreach(struct hook *h, &p->hooks)
hook_init(h, &nodes, &paths, &settings);
path_start(p);
}
else
@ -159,7 +160,7 @@ int main(int argc, char *argv[])
/* Run! */
if (settings.stats > 0) {
hook_stats_header();
stats_print_header();
for (;;) {
list_foreach(struct path *p, &paths)