From 382161b00bacf2aec28fdeada4533e71b60e60ab Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 31 Aug 2017 09:42:36 +0200 Subject: [PATCH] mapping: move parser from node.c to mapping.c --- include/villas/mapping.h | 2 ++ include/villas/node.h | 2 -- lib/hooks/map.c | 2 +- lib/mapping.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/node.c | 39 --------------------------------------- lib/path.c | 2 +- 6 files changed, 43 insertions(+), 43 deletions(-) diff --git a/include/villas/mapping.h b/include/villas/mapping.h index 2d3d9076c..67cd8e5e4 100644 --- a/include/villas/mapping.h +++ b/include/villas/mapping.h @@ -92,3 +92,5 @@ int mapping_update(struct mapping_entry *e, struct sample *remapped, struct samp int mapping_parse(struct mapping_entry *e, json_t *cfg, struct list *nodes); int mapping_parse_str(struct mapping_entry *e, const char *str, struct list *nodes); + +int mapping_parse_list(struct list *l, json_t *cfg, struct list *nodes); diff --git a/include/villas/node.h b/include/villas/node.h index 0eeeb7cbc..2b186ee57 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -139,6 +139,4 @@ int node_fd(struct node *n); */ int node_parse_list(struct list *list, json_t *cfg, struct list *all); -int node_parse_mapping_list(struct list *l, json_t *cfg, struct list *all); - /** @} */ diff --git a/lib/hooks/map.c b/lib/hooks/map.c index 7e7460a48..4988efd15 100644 --- a/lib/hooks/map.c +++ b/lib/hooks/map.c @@ -65,7 +65,7 @@ static int map_parse(struct hook *h, json_t *cfg) if (ret) jerror(&err, "Failed to parse configuration of hook '%s'", plugin_name(h->_vt)); - ret = node_parse_mapping_list(&p->mapping, cfg_mapping, NULL); + ret = mapping_parse_list(&p->mapping, cfg_mapping, NULL); if (ret) return ret; diff --git a/lib/mapping.c b/lib/mapping.c index d11fad758..d8fcb5da2 100644 --- a/lib/mapping.c +++ b/lib/mapping.c @@ -191,6 +191,45 @@ int mapping_parse(struct mapping_entry *e, json_t *j, struct list *nodes) return mapping_parse_str(e, str, nodes); } +int mapping_parse_list(struct list *l, json_t *cfg, struct list *nodes) +{ + int ret, off, len; + + size_t i; + json_t *json_entry; + json_t *json_mapping; + + if (json_is_string(cfg)) { + json_mapping = json_array(); + json_array_append(json_mapping, cfg); + } + else if (json_is_array(cfg)) + json_mapping = cfg; + else + return -1; + + off = 0; + len = json_array_size(json_mapping); + json_array_foreach(json_mapping, i, json_entry) { + struct mapping_entry *e = alloc(sizeof(struct mapping_entry)); + + ret = mapping_parse(e, json_entry, nodes); + if (ret) + return ret; + + /* Variable length mapping entries are currently only supported as the last element in a mapping */ + if (e->length == 0 && i != len - 1) + return -1; + + e->offset = off; + off += e->length; + + list_push(l, e); + } + + return 0; +} + int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sample *original, struct stats *s) { int len = me->length; diff --git a/lib/node.c b/lib/node.c index 5ef81398c..9bba2a331 100644 --- a/lib/node.c +++ b/lib/node.c @@ -345,44 +345,5 @@ invalid2: error("Unknown node '%s'. Choose of one of: %s", str, allstr); - return 0; -} - -int node_parse_mapping_list(struct list *l, json_t *cfg, struct list *all) -{ - int ret, off, len; - - size_t i; - json_t *json_entry; - json_t *json_mapping; - - if (json_is_string(cfg)) { - json_mapping = json_array(); - json_array_append(json_mapping, cfg); - } - else if (json_is_array(cfg)) - json_mapping = cfg; - else - return -1; - - off = 0; - len = json_array_size(json_mapping); - json_array_foreach(json_mapping, i, json_entry) { - struct mapping_entry *e = alloc(sizeof(struct mapping_entry)); - - ret = mapping_parse(e, json_entry, all); - if (ret) - return ret; - - /* Variable length mapping entries are currently only supported as the last element in a mapping */ - if (e->length == 0 && i != len - 1) - return -1; - - e->offset = off; - off += e->length; - - list_push(l, e); - } - return 0; } \ No newline at end of file diff --git a/lib/path.c b/lib/path.c index e159917f8..36bd0c4d1 100644 --- a/lib/path.c +++ b/lib/path.c @@ -316,7 +316,7 @@ int path_parse(struct path *p, json_t *cfg, struct list *nodes) jerror(&err, "Failed to parse path configuration"); /* Input node(s) */ - ret = node_parse_mapping_list(&sources, json_in, nodes); + ret = mapping_parse_list(&sources, json_in, nodes); if (ret) error("Failed to parse input mapping of path %s", path_name(p));