mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
mapping: move parser from node.c to mapping.c
This commit is contained in:
parent
ad98bd5f5a
commit
382161b00b
6 changed files with 43 additions and 43 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
39
lib/node.c
39
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;
|
||||
}
|
|
@ -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));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue