mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
add {node,path,hook_list}_to_json()
This commit is contained in:
parent
57f570d9b0
commit
2f29e30c33
8 changed files with 103 additions and 86 deletions
|
@ -74,3 +74,5 @@ void hook_list_start(struct vlist *hs);
|
|||
void hook_list_stop(struct vlist *hs);
|
||||
|
||||
struct vlist * hook_list_get_signals(struct vlist *hs);
|
||||
|
||||
json_t * hook_list_to_json(struct vlist *hs);
|
|
@ -215,4 +215,6 @@ bool node_is_enabled(const struct node *n);
|
|||
|
||||
struct vlist * node_get_signals(struct node *n, enum NodeDir dir);
|
||||
|
||||
json_t * node_to_json(struct node *);
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -165,4 +165,6 @@ bool path_is_reversed(const struct vpath *p);
|
|||
|
||||
struct vlist * path_get_signals(struct vpath *p);
|
||||
|
||||
json_t * path_to_json(struct vpath *p);
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -55,42 +55,7 @@ public:
|
|||
for (size_t i = 0; i < vlist_length(nodes); i++) {
|
||||
struct node *n = (struct node *) vlist_at(nodes, i);
|
||||
|
||||
struct vlist *output_signals;
|
||||
|
||||
json_t *json_node;
|
||||
json_t *json_signals_in = nullptr;
|
||||
json_t *json_signals_out = nullptr;
|
||||
|
||||
char uuid[37];
|
||||
uuid_unparse(n->uuid, uuid);
|
||||
|
||||
json_signals_in = signal_list_to_json(&n->in.signals);
|
||||
|
||||
output_signals = node_output_signals(n);
|
||||
if (output_signals)
|
||||
json_signals_out = signal_list_to_json(output_signals);
|
||||
|
||||
json_node = json_pack("{ s: s, s: s, s: s, s: i, s: { s: i, s: o? }, s: { s: i, s: o? } }",
|
||||
"name", node_name_short(n),
|
||||
"uuid", uuid,
|
||||
"state", state_print(n->state),
|
||||
"affinity", n->affinity,
|
||||
"in",
|
||||
"vectorize", n->in.vectorize,
|
||||
"signals", json_signals_in,
|
||||
"out",
|
||||
"vectorize", n->out.vectorize,
|
||||
"signals", json_signals_out
|
||||
);
|
||||
|
||||
if (n->stats)
|
||||
json_object_set_new(json_node, "stats", n->stats->toJson());
|
||||
|
||||
/* Add all additional fields of node here.
|
||||
* This can be used for metadata */
|
||||
json_object_update(json_node, n->cfg);
|
||||
|
||||
json_array_append_new(json_nodes, json_node);
|
||||
json_array_append_new(json_nodes, node_to_json(n));
|
||||
}
|
||||
|
||||
return new Response(session, json_nodes);
|
||||
|
|
|
@ -56,56 +56,7 @@ public:
|
|||
for (size_t i = 0; i < vlist_length(paths); i++) {
|
||||
struct vpath *p = (struct vpath *) vlist_at(paths, i);
|
||||
|
||||
char uuid[37];
|
||||
uuid_unparse(p->uuid, uuid);
|
||||
|
||||
json_t *json_signals = json_array();
|
||||
json_t *json_hooks = json_array();
|
||||
json_t *json_sources = json_array();
|
||||
json_t *json_destinations = json_array();
|
||||
|
||||
for (size_t i = 0; i < vlist_length(&p->signals); i++) {
|
||||
struct signal *sig = (struct signal *) vlist_at_safe(&p->signals, i);
|
||||
|
||||
json_array_append(json_signals, signal_to_json(sig));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < vlist_length(&p->hooks); i++) {
|
||||
Hook *h = (Hook *) vlist_at_safe(&p->hooks, i);
|
||||
|
||||
json_array_append(json_hooks, h->getConfig());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < vlist_length(&p->sources); i++) {
|
||||
struct vpath_source *pd = (struct vpath_source *) vlist_at_safe(&p->sources, i);
|
||||
|
||||
json_array_append_new(json_sources, json_string(node_name_short(pd->node)));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < vlist_length(&p->destinations); i++) {
|
||||
struct vpath_destination *pd = (struct vpath_destination *) vlist_at_safe(&p->destinations, i);
|
||||
|
||||
json_array_append_new(json_destinations, json_string(node_name_short(pd->node)));
|
||||
}
|
||||
|
||||
json_t *json_path = json_pack("{ s: s, s: s, s: s, s: b, s: b s: b, s: b, s: b, s: b s: i, s: o, s: o, s: o, s: o }",
|
||||
"uuid", uuid,
|
||||
"state", state_print(p->state),
|
||||
"mode", p->mode == PathMode::ANY ? "any" : "all",
|
||||
"enabled", p->enabled,
|
||||
"builtin", p->builtin,
|
||||
"reverse", p->reverse,
|
||||
"original_sequence_no", p->original_sequence_no,
|
||||
"last_sequence", p->last_sequence,
|
||||
"poll", p->poll,
|
||||
"queuelen", p->queuelen,
|
||||
"signals", json_signals,
|
||||
"hooks", json_hooks,
|
||||
"in", json_sources,
|
||||
"out", json_destinations
|
||||
);
|
||||
|
||||
json_array_append_new(json_paths, json_path);
|
||||
json_array_append_new(json_paths, path_to_json(p));
|
||||
}
|
||||
|
||||
return new Response(session, json_paths);
|
||||
|
|
|
@ -201,3 +201,16 @@ vlist * hook_list_get_signals(vlist *hs)
|
|||
|
||||
return h->getSignals();
|
||||
}
|
||||
|
||||
json_t * hook_list_to_json(vlist *hs)
|
||||
{
|
||||
json_t *json_hooks = json_array();
|
||||
|
||||
for (size_t i = 0; i < vlist_length(hs); i++) {
|
||||
Hook *h = (Hook *) vlist_at_safe(hs, i);
|
||||
|
||||
json_array_append(json_hooks, h->getConfig());
|
||||
}
|
||||
|
||||
return json_hooks;
|
||||
}
|
40
lib/node.cpp
40
lib/node.cpp
|
@ -666,3 +666,43 @@ struct vlist * node_get_signals(struct node *n, enum NodeDir dir)
|
|||
|
||||
return node_direction_get_signals(nd);
|
||||
}
|
||||
|
||||
json_t * node_to_json(struct node *n)
|
||||
{
|
||||
struct vlist *output_signals;
|
||||
|
||||
json_t *json_node;
|
||||
json_t *json_signals_in = nullptr;
|
||||
json_t *json_signals_out = nullptr;
|
||||
|
||||
char uuid[37];
|
||||
uuid_unparse(n->uuid, uuid);
|
||||
|
||||
json_signals_in = signal_list_to_json(&n->in.signals);
|
||||
|
||||
output_signals = node_output_signals(n);
|
||||
if (output_signals)
|
||||
json_signals_out = signal_list_to_json(output_signals);
|
||||
|
||||
json_node = json_pack("{ s: s, s: s, s: s, s: i, s: { s: i, s: o? }, s: { s: i, s: o? } }",
|
||||
"name", node_name_short(n),
|
||||
"uuid", uuid,
|
||||
"state", state_print(n->state),
|
||||
"affinity", n->affinity,
|
||||
"in",
|
||||
"vectorize", n->in.vectorize,
|
||||
"signals", json_signals_in,
|
||||
"out",
|
||||
"vectorize", n->out.vectorize,
|
||||
"signals", json_signals_out
|
||||
);
|
||||
|
||||
if (n->stats)
|
||||
json_object_set_new(json_node, "stats", n->stats->toJson());
|
||||
|
||||
/* Add all additional fields of node here.
|
||||
* This can be used for metadata */
|
||||
json_object_update(json_node, n->cfg);
|
||||
|
||||
return json_node;
|
||||
}
|
42
lib/path.cpp
42
lib/path.cpp
|
@ -842,3 +842,45 @@ struct vlist * path_get_signals(struct vpath *p)
|
|||
{
|
||||
return &p->signals;
|
||||
}
|
||||
|
||||
json_t * path_to_json(struct vpath *p)
|
||||
{
|
||||
char uuid[37];
|
||||
uuid_unparse(p->uuid, uuid);
|
||||
|
||||
json_t *json_signals = signal_list_to_json(&p->signals);
|
||||
json_t *json_hooks = hook_list_to_json(&p->hooks);
|
||||
json_t *json_sources = json_array();
|
||||
json_t *json_destinations = json_array();
|
||||
|
||||
for (size_t i = 0; i < vlist_length(&p->sources); i++) {
|
||||
struct vpath_source *pd = (struct vpath_source *) vlist_at_safe(&p->sources, i);
|
||||
|
||||
json_array_append_new(json_sources, json_string(node_name_short(pd->node)));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < vlist_length(&p->destinations); i++) {
|
||||
struct vpath_destination *pd = (struct vpath_destination *) vlist_at_safe(&p->destinations, i);
|
||||
|
||||
json_array_append_new(json_destinations, json_string(node_name_short(pd->node)));
|
||||
}
|
||||
|
||||
json_t *json_path = json_pack("{ s: s, s: s, s: s, s: b, s: b s: b, s: b, s: b, s: b s: i, s: o, s: o, s: o, s: o }",
|
||||
"uuid", uuid,
|
||||
"state", state_print(p->state),
|
||||
"mode", p->mode == PathMode::ANY ? "any" : "all",
|
||||
"enabled", p->enabled,
|
||||
"builtin", p->builtin,
|
||||
"reverse", p->reverse,
|
||||
"original_sequence_no", p->original_sequence_no,
|
||||
"last_sequence", p->last_sequence,
|
||||
"poll", p->poll,
|
||||
"queuelen", p->queuelen,
|
||||
"signals", json_signals,
|
||||
"hooks", json_hooks,
|
||||
"in", json_sources,
|
||||
"out", json_destinations
|
||||
);
|
||||
|
||||
return json_path;
|
||||
}
|
Loading…
Add table
Reference in a new issue