16
16
17
17
#include < memory>
18
18
#include < string>
19
+ #include < unordered_map>
20
+ #include < vector>
19
21
20
22
namespace diagnostic_graph_aggregator
21
23
{
@@ -35,6 +37,29 @@ std::string level_to_string(DiagnosticLevel level)
35
37
return " UNKNOWN" ;
36
38
}
37
39
40
+ std::string parent_path (const std::string & path)
41
+ {
42
+ return path.substr (0 , path.rfind (' /' ));
43
+ }
44
+
45
+ std::vector<std::string> complement_paths (const DiagnosticGraph & graph)
46
+ {
47
+ std::unordered_map<std::string, bool > paths;
48
+ for (const auto & node : graph.nodes ) {
49
+ std::string path = node.status .name ;
50
+ paths[path] = false ;
51
+ while (path = parent_path (path), !path.empty ()) {
52
+ if (paths.count (path)) break ;
53
+ paths[path] = true ;
54
+ }
55
+ }
56
+ std::vector<std::string> result;
57
+ for (const auto & [path, flag] : paths) {
58
+ if (flag) result.push_back (path);
59
+ }
60
+ return result;
61
+ }
62
+
38
63
ToolNode::ToolNode () : Node(" diagnostic_graph_aggregator_converter" )
39
64
{
40
65
using std::placeholders::_1;
@@ -43,7 +68,8 @@ ToolNode::ToolNode() : Node("diagnostic_graph_aggregator_converter")
43
68
44
69
const auto callback = std::bind (&ToolNode::on_graph, this , _1);
45
70
sub_graph_ = create_subscription<DiagnosticGraph>(" /diagnostics_graph" , qos_graph, callback);
46
- pub_array_ = create_publisher<DiagnosticArray>(" /diagnostics_array" , qos_array);
71
+ pub_array_ = create_publisher<DiagnosticArray>(" /diagnostics_agg" , qos_array);
72
+ complement_inner_nodes_ = declare_parameter<bool >(" complement_inner_nodes" );
47
73
}
48
74
49
75
void ToolNode::on_graph (const DiagnosticGraph::ConstSharedPtr msg)
@@ -63,6 +89,18 @@ void ToolNode::on_graph(const DiagnosticGraph::ConstSharedPtr msg)
63
89
}
64
90
}
65
91
}
92
+
93
+ if (complement_inner_nodes_) {
94
+ if (!inner_node_names_) {
95
+ inner_node_names_ = complement_paths (*msg);
96
+ }
97
+ for (const auto & name : inner_node_names_.value ()) {
98
+ message.status .emplace_back ();
99
+ message.status .back ().name = name;
100
+ message.status .back ().level = DiagnosticStatus::STALE;
101
+ }
102
+ }
103
+
66
104
pub_array_->publish (message);
67
105
}
68
106
0 commit comments