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

refactor: add {node, path}_is_{enabled, reversed}()

This commit is contained in:
Steffen Vogel 2019-02-24 11:10:44 +01:00
parent 34137545bc
commit 7e5b4ac5ce
5 changed files with 33 additions and 16 deletions

View file

@ -198,7 +198,8 @@ struct node_type * node_type(struct node *n)
struct memory_type * node_memory_type(struct node *n, struct memory_type *parent);
int node_is_valid_name(const char *name);
bool node_is_valid_name(const char *name);
bool node_is_enabled(const struct node *n);

View file

@ -157,7 +157,11 @@ int path_uses_node(struct path *p, struct node *n);
*/
int path_parse(struct path *p, json_t *cfg, struct vlist *nodes);
int path_is_simple(struct path *p);
bool path_is_simple(const struct path *p);
bool path_is_enabled(const struct path *p);
bool path_is_reversed(const struct path *p);
/** @} */

View file

@ -595,16 +595,18 @@ invalid2:
return 0;
}
int node_is_valid_name(const char *name)
bool node_is_valid_name(const char *name)
{
for (const char *p = name; *p; p++) {
if (isalnum(*p) || (*p == '_') || (*p == '-'))
continue;
return -1;
return false;
}
return 0;
return true;
}
bool node_is_enabled(const struct node *n)
{
return n->enabled;

View file

@ -545,8 +545,8 @@ int path_start(struct path *p)
p->poll ? "yes" : "no",
mask,
p->rate,
p->enabled ? "yes" : "no",
p->reverse ? "yes" : "no",
path_is_enabled(p) ? "yes" : "no",
path_is_reversed(p) ? "yes" : "no",
p->queuelen,
vlist_length(&p->hooks),
vlist_length(&p->sources),
@ -723,22 +723,32 @@ int path_uses_node(struct path *p, struct node *n)
return -1;
}
int path_is_simple(struct path *p)
bool path_is_simple(const struct path *p)
{
int ret;
const char *in = NULL, *out = NULL;
ret = json_unpack(p->cfg, "{ s: s, s: s }", "in", &in, "out", &out);
if (ret)
return ret;
return false;
ret = node_is_valid_name(in);
if (ret)
return ret;
if (!ret)
return false;
ret = node_is_valid_name(out);
if (ret)
return ret;
if (!ret)
return false;
return 0;
return true;
}
bool path_is_enabled(const struct path *p)
{
return p->enabled;
}
bool path_is_reversed(const struct path *p)
{
return p->reverse;
}

View file

@ -218,7 +218,7 @@ int SuperNode::parseJson(json_t *j)
const char *type;
ret = node_is_valid_name(name);
if (ret)
if (!ret)
throw RuntimeError("Invalid name for node: {}", name);
ret = json_unpack_ex(json_node, &err, 0, "{ s: s }", "type", &type);
@ -266,7 +266,7 @@ parse: path *p = (path *) alloc(sizeof(path));
if (p->reverse) {
/* Only simple paths can be reversed */
ret = path_is_simple(p);
if (ret)
if (!ret)
throw RuntimeError("Complex paths can not be reversed!");
/* Parse a second time with in/out reversed */