mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
changed configuration format for hooks
This commit is contained in:
parent
a87cad471d
commit
001400774e
9 changed files with 73 additions and 57 deletions
|
@ -180,25 +180,43 @@ paths = (
|
|||
out = "file_node", # This path includes all available example hooks.
|
||||
|
||||
# A complete list of supported hooks
|
||||
print = {
|
||||
output = "stdout"
|
||||
priority = 0
|
||||
},
|
||||
ts = {
|
||||
priority = 1
|
||||
}
|
||||
decimate = {
|
||||
ratio = 2 # Only forward every 2nd message
|
||||
},
|
||||
convert = {
|
||||
mode = "fixed" # Convert all values to fixed precission. Use 'float' to convert to floating point.
|
||||
},
|
||||
skip_first = {
|
||||
seconds = 10 # Skip the first 10 seconds of this path
|
||||
},
|
||||
shift = {
|
||||
mode = "origin", # Shift origin timestam of samples by +10 seconds
|
||||
offset = 10
|
||||
}
|
||||
|
||||
hooks = (
|
||||
{
|
||||
type = "print"
|
||||
|
||||
output = "stdout"
|
||||
priority = 0
|
||||
},
|
||||
{
|
||||
type = "ts"
|
||||
|
||||
priority = 1
|
||||
},
|
||||
{
|
||||
type = "decimate"
|
||||
|
||||
ratio = 2 # Only forward every 2nd message
|
||||
},
|
||||
{
|
||||
type = "convert"
|
||||
|
||||
mask = 0x1 # only convert the first value
|
||||
mode = "fixed" # Convert all values to fixed precission. Use 'float' to convert to floating point.
|
||||
scale = 1.0
|
||||
},
|
||||
{
|
||||
type = "skip_first"
|
||||
|
||||
seconds = 10 # Skip the first 10 seconds of this path
|
||||
# samples = 1000 # Skip the first 1000 samples
|
||||
},
|
||||
{
|
||||
type = "shift"
|
||||
|
||||
mode = "origin", # Shift origin timestam of samples by +10 seconds
|
||||
offset = 10 # Seconds
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -57,9 +57,8 @@ paths = (
|
|||
in = "node1", # Name of the node we listen to (see above)
|
||||
out = "node1", # And we loop back to the origin
|
||||
|
||||
# Hooks
|
||||
print = {
|
||||
output = "stdout"
|
||||
}
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -57,9 +57,8 @@ paths = (
|
|||
in = "node1", # Name of the node we listen to (see above)
|
||||
out = "node2", # And we loop back to the origin
|
||||
|
||||
# Hooks
|
||||
print = {
|
||||
output = "stdout"
|
||||
}
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -57,9 +57,8 @@ paths = (
|
|||
in = "node1", # Name of the node we listen to (see above)
|
||||
out = "node2", # And we loop back to the origin
|
||||
|
||||
# Hooks
|
||||
print = {
|
||||
output = "stdout"
|
||||
}
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -57,9 +57,8 @@ paths = (
|
|||
in = "node1", # Name of the node we listen to (see above)
|
||||
out = "node1", # And we loop back to the origin
|
||||
|
||||
# Hooks
|
||||
print = {
|
||||
output = "stdout"
|
||||
}
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -58,9 +58,8 @@ paths = (
|
|||
in = "node1", # Name of the node we listen to (see above)
|
||||
out = "node1", # And we loop back to the origin
|
||||
|
||||
# Hooks
|
||||
print = {
|
||||
output = "stdout"
|
||||
}
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -59,11 +59,15 @@ paths = (
|
|||
{
|
||||
in = "node1", # Name of the node we listen to (see above)
|
||||
out = "node1", # And we loop back to the origin
|
||||
hook = ["print"]
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
},
|
||||
{
|
||||
in = "node2",
|
||||
out = "node2",
|
||||
hook = ["print"]
|
||||
hooks = (
|
||||
{ type = "print", output = "stdout" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
|
@ -34,6 +34,8 @@ paths = (
|
|||
in = "file",
|
||||
out = "shmem",
|
||||
reverse = true,
|
||||
hook = ["print"]
|
||||
hooks = (
|
||||
{ priority = 10, type = "print" }
|
||||
)
|
||||
}
|
||||
);
|
||||
|
|
25
lib/hook.c
25
lib/hook.c
|
@ -44,7 +44,6 @@ int hook_init(struct hook *h, struct hook_type *vt, struct path *p)
|
|||
h->_vt = vt;
|
||||
h->_vd = alloc(vt->size);
|
||||
|
||||
|
||||
ret = h->_vt->init ? h->_vt->init(h) : 0;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
@ -165,33 +164,31 @@ int hook_parse_list(struct list *list, config_setting_t *cfg, struct path *o)
|
|||
{
|
||||
struct plugin *p;
|
||||
|
||||
int ret, priority = 10;
|
||||
int ret;
|
||||
const char *type;
|
||||
|
||||
if (!config_setting_is_group(cfg))
|
||||
cerror(cfg, "Hooks must be configured with an object");
|
||||
if (!config_setting_is_list(cfg))
|
||||
cerror(cfg, "Hooks must be configured as a list of objects");
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++) {
|
||||
config_setting_t *cfg_hook = config_setting_get_elem(cfg, i);
|
||||
|
||||
const char *name = config_setting_name(cfg_hook);
|
||||
|
||||
p = plugin_lookup(PLUGIN_TYPE_HOOK, name);
|
||||
if (!p)
|
||||
continue; /* We ignore all non hook settings in this libconfig object setting */
|
||||
|
||||
if (!config_setting_is_group(cfg_hook))
|
||||
cerror(cfg_hook, "The 'hooks' setting must be an array of strings.");
|
||||
|
||||
if (!config_setting_lookup_string(cfg_hook, "type", &type))
|
||||
cerror(cfg_hook, "Missing setting 'type' for hook");
|
||||
|
||||
p = plugin_lookup(PLUGIN_TYPE_HOOK, type);
|
||||
if (!p)
|
||||
continue; /* We ignore all non hook settings in this libconfig object setting */
|
||||
|
||||
struct hook h = { .state = STATE_DESTROYED };
|
||||
|
||||
ret = hook_init(&h, &p->hook, o);
|
||||
if (ret)
|
||||
continue;
|
||||
|
||||
/* If the user does not assign a priority, we will use the
|
||||
* position of the hook section in the congiguration file. */
|
||||
h.priority = priority++;
|
||||
|
||||
ret = hook_parse(&h, cfg_hook);
|
||||
if (ret)
|
||||
continue;
|
||||
|
|
Loading…
Add table
Reference in a new issue