diff --git a/etc/example.conf b/etc/example.conf index 0ad8845f2..a0e638f65 100644 --- a/etc/example.conf +++ b/etc/example.conf @@ -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 + } + ) } ); diff --git a/etc/gtnet-skt/test1.conf b/etc/gtnet-skt/test1.conf index 71ad5a1d5..4b4482a3a 100644 --- a/etc/gtnet-skt/test1.conf +++ b/etc/gtnet-skt/test1.conf @@ -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" } + ) } ); diff --git a/etc/gtnet-skt/test2.conf b/etc/gtnet-skt/test2.conf index a22c06db6..afa463635 100644 --- a/etc/gtnet-skt/test2.conf +++ b/etc/gtnet-skt/test2.conf @@ -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" } + ) } ); diff --git a/etc/gtnet-skt/test3.conf b/etc/gtnet-skt/test3.conf index e945e2cf4..db055a684 100644 --- a/etc/gtnet-skt/test3.conf +++ b/etc/gtnet-skt/test3.conf @@ -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" } + ) } ); diff --git a/etc/gtnet-skt/test4.conf b/etc/gtnet-skt/test4.conf index 7037b61e4..9bcd116bb 100644 --- a/etc/gtnet-skt/test4.conf +++ b/etc/gtnet-skt/test4.conf @@ -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" } + ) } ); diff --git a/etc/gtnet-skt/test5.conf b/etc/gtnet-skt/test5.conf index 43d429575..6a8e9ef87 100644 --- a/etc/gtnet-skt/test5.conf +++ b/etc/gtnet-skt/test5.conf @@ -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" } + ) } ); diff --git a/etc/gtnet-skt/test6_gtsync_compare.conf b/etc/gtnet-skt/test6_gtsync_compare.conf index 23076da73..5887bb492 100644 --- a/etc/gtnet-skt/test6_gtsync_compare.conf +++ b/etc/gtnet-skt/test6_gtsync_compare.conf @@ -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" } + ) } ); diff --git a/etc/shmem.conf b/etc/shmem.conf index ef9ebf13e..9d3779506 100644 --- a/etc/shmem.conf +++ b/etc/shmem.conf @@ -34,6 +34,8 @@ paths = ( in = "file", out = "shmem", reverse = true, - hook = ["print"] + hooks = ( + { priority = 10, type = "print" } + ) } ); diff --git a/lib/hook.c b/lib/hook.c index 2df4ec00a..4461ad751 100644 --- a/lib/hook.c +++ b/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;