-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathanalyzer_group.hpp
200 lines (174 loc) · 6.5 KB
/
analyzer_group.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2009, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
/**
* \author Kevin Watts
*/
#ifndef DIAGNOSTIC_AGGREGATOR__ANALYZER_GROUP_HPP_
#define DIAGNOSTIC_AGGREGATOR__ANALYZER_GROUP_HPP_
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "diagnostic_aggregator/analyzer.hpp"
#include "diagnostic_aggregator/status_item.hpp"
#include "diagnostic_aggregator/visibility_control.hpp"
#include "diagnostic_msgs/msg/diagnostic_status.hpp"
#include "diagnostic_msgs/msg/key_value.hpp"
#include "pluginlib/class_list_macros.hpp"
#include "pluginlib/class_loader.hpp"
#include "rclcpp/rclcpp.hpp"
namespace diagnostic_aggregator
{
/*!
*\brief Allows analyzers to be grouped together, or used as sub-analyzers
*
* The AnalyzerGroup is used by the diagnostic aggregator internally to
* load and handle analyzers. It can be used as a normal analyzer plugin to
* allow analyzers to become "sub-analyzers", or move as a group.
*
* The "sub-analyzers" are initialized using parameters in the "~analyzers"
* namespace of the AnalyzerGroup. The "type" parameters determines the analyzer type.
*
* Example initialization:
*\verbatim
* sensors:
* type: AnalyzerGroup
* path: Sensors
* analyzers:
* base_hk:
* type: GenericAnalyzer
* path: Base Hokuyo
* timeout: 5.0
* find_and_remove_prefix: base_hokuyo_node
* num_items: 3
* tilt_hk:
* type: GenericAnalyzer
* path: Tilt Hokuyo
* timeout: 5.0
* find_and_remove_prefix: tilt_hokuyo_node
* num_items: 3
* imu:
* type: GenericAnalyzer
* path: IMU
* timeout: 5.0
* find_and_remove_prefix: imu_node
* num_items: 3
*\endverbatim
*
* Each namespace below "analyzers" describes a new Analyzer that will be loaded as a
* sub-analyzer. Any analyzer that fails to initialize or loads incorrectly will
* generate an error in the console output, and a special diagnostic item in the output
* of the AnalyzerGroup that describes the error.
*
* In the above example, the AnalyzerGroup will have three sub-analyzers. The
* AnalyzerGroup will report a DiagnosticStatus message in the processed output with
* the name "Sensors" (the top-level state). The "Sensors" message will have the
* level of the highest of the sub-analyzers, or the highest of "Sensors/Base Hokuyo",
* "Sensors/Tilt Hokuyo" and "Sensors/IMU". The state of any other items, like
* "Sensors/IMU/Connection" won't matter to the AnalyzerGroup.
*
* The Aggregator uses the AnalyzerGroup internally to load and update analyzers.
*
*/
class AnalyzerGroup : public Analyzer
{
public:
DIAGNOSTIC_AGGREGATOR_PUBLIC
AnalyzerGroup();
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual ~AnalyzerGroup();
/*!
*\brief Initialized with base path and namespace.
*
* The parameters in its namespace determine the sub-analyzers.
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual bool init(
const std::string & base_path, const std::string & breadcrumb,
const rclcpp::Node::SharedPtr node);
/**!
*\brief Add an analyzer to this analyzerGroup
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual bool addAnalyzer(std::shared_ptr<Analyzer> & analyzer);
/**!
*\brief Remove an analyzer from this analyzerGroup
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual bool removeAnalyzer(std::shared_ptr<Analyzer> & analyzer);
/*!
*\brief Match returns true if any sub-analyzers match an item
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual bool match(const std::string & name);
/*!
*\brief Clear match arrays. Used when analyzers are added or removed
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
void resetMatches();
/*!
*\brief Analyze returns true if any sub-analyzers will analyze an item
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual bool analyze(const std::shared_ptr<StatusItem> item);
/*!
*\brief The processed output is the combined output of the sub-analyzers,
* and the top level status
*/
DIAGNOSTIC_AGGREGATOR_PUBLIC
virtual std::vector<std::shared_ptr<diagnostic_msgs::msg::DiagnosticStatus>> report();
virtual std::string getPath() const {return path_;}
virtual std::string getName() const {return nice_name_;}
private:
std::string path_;
std::string nice_name_;
std::string breadcrumb_;
/*!
*\brief Loads Analyzer plugins in "analyzers" namespace
*/
pluginlib::ClassLoader<Analyzer> analyzer_loader_;
rclcpp::Logger logger_;
/*!
*\brief These items store errors, if any, for analyzers that failed to initialize or load
*/
std::vector<std::shared_ptr<StatusItem>> aux_items_;
std::vector<std::shared_ptr<Analyzer>> analyzers_;
/*
*\brief The map of names to matchings is stored internally.
*/
std::map<const std::string, std::vector<bool>> matched_;
};
} // namespace diagnostic_aggregator
#endif // DIAGNOSTIC_AGGREGATOR__ANALYZER_GROUP_HPP_