53 n.
param(
"path", nice_name_,
string(
""));
55 if (base_path.size() > 0 && base_path !=
"/")
56 if (nice_name_.size() > 0)
57 path_ = base_path +
"/" + nice_name_;
64 if (path_.find(
"/") != 0)
70 analyzers_nh.
getParam(
"", analyzer_params);
71 ROS_DEBUG(
"Analyzer params: %s.", analyzer_params.
toXml().c_str());
76 for (xml_it = analyzer_params.
begin(); xml_it != analyzer_params.
end(); ++xml_it)
82 string ns = analyzer_name;
84 if (!analyzer_value.hasMember(
"type"))
86 ROS_ERROR(
"Namespace %s has no member 'type', unable to initialize analyzer for this namespace.", analyzers_nh.
getNamespace().c_str());
88 aux_items_.push_back(item);
94 string an_type = analyzer_type;
100 if (!analyzer_loader_.isClassAvailable(an_type))
102 bool have_class =
false;
103 vector<string> classes = analyzer_loader_.getDeclaredClasses();
104 for(
unsigned int i = 0; i < classes.size(); ++i)
106 if(an_type == analyzer_loader_.getName(classes[i]))
109 ROS_WARN(
"Analyzer specification should now include the package name. You are using a deprecated API. Please switch from %s to %s in your Analyzer specification.",
110 an_type.c_str(), classes[i].c_str());
111 an_type = classes[i];
118 ROS_ERROR(
"Unable to find Analyzer class %s. Check that Analyzer is fully declared.", an_type.c_str());
123 analyzer = analyzer_loader_.createInstance(an_type);
127 ROS_ERROR(
"Failed to load analyzer %s, type %s. Caught exception. %s", ns.c_str(), an_type.c_str(), e.what());
129 aux_items_.push_back(item);
136 ROS_ERROR(
"Pluginlib returned a null analyzer for %s, namespace %s.", an_type.c_str(), analyzers_nh.
getNamespace().c_str());
138 aux_items_.push_back(item);
145 ROS_ERROR(
"Unable to initialize analyzer NS: %s, type: %s", analyzers_nh.
getNamespace().c_str(), an_type.c_str());
147 aux_items_.push_back(item);
152 analyzers_.push_back(analyzer);
155 if (analyzers_.size() == 0)
164 AnalyzerGroup::~AnalyzerGroup()
171 analyzers_.push_back(analyzer);
177 vector<boost::shared_ptr<Analyzer> >::iterator it = find(analyzers_.begin(), analyzers_.end(), analyzer);
178 if (it != analyzers_.end())
180 analyzers_.erase(it);
186 bool AnalyzerGroup::match(
const string name)
188 if (analyzers_.size() == 0)
191 bool match_name =
false;
192 if (matched_.count(name))
194 vector<bool> &mtch_vec = matched_[name];
195 for (
unsigned int i = 0; i < mtch_vec.size(); ++i)
203 matched_[name].resize(analyzers_.size());
204 for (
unsigned int i = 0; i < analyzers_.size(); ++i)
206 bool mtch = analyzers_[i]->match(name);
207 match_name = mtch || match_name;
208 matched_[name].at(i) = mtch;
214 void AnalyzerGroup::resetMatches()
222 ROS_ASSERT_MSG(matched_.count(item->getName()),
"AnalyzerGroup was asked to analyze an item it hadn't matched.");
224 bool analyzed =
false;
225 vector<bool> &mtch_vec = matched_[item->getName()];
226 for (
unsigned int i = 0; i < mtch_vec.size(); ++i)
229 analyzed = analyzers_[i]->analyze(item) || analyzed;
235 vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > AnalyzerGroup::report()
237 vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > output;
240 header_status->name = path_;
241 header_status->level = 0;
242 header_status->message =
"OK";
244 if (analyzers_.size() == 0)
246 header_status->level = 2;
247 header_status->message =
"No analyzers";
248 output.push_back(header_status);
250 if (header_status->name ==
"" || header_status->name ==
"/")
251 header_status->name =
"/AnalyzerGroup";
256 bool all_stale =
true;
258 for (
unsigned int j = 0; j < analyzers_.size(); ++j)
260 string path = analyzers_[j]->getPath();
261 string nice_name = analyzers_[j]->getName();
263 vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > processed = analyzers_[j]->report();
266 if (processed.size() == 0)
271 for (
unsigned int i = 0; i < processed.size(); ++i)
273 output.push_back(processed[i]);
276 if (processed[i]->name == path)
278 diagnostic_msgs::KeyValue kv;
280 kv.value = processed[i]->message;
282 all_stale = all_stale && (processed[i]->level == 3);
283 header_status->level = max(header_status->level, processed[i]->level);
284 header_status->values.push_back(kv);
290 if (header_status->level == 3 && !all_stale)
291 header_status->level = 2;
293 header_status->message =
valToMsg(header_status->level);
295 if (path_ !=
"" && path_ !=
"/")
297 output.push_back(header_status);
300 for (
unsigned int i = 0; i < aux_items_.size(); ++i)
302 output.push_back(aux_items_[i]->toStatusMsg(path_,
true));
ValueStruct::iterator iterator
std::string valToMsg(const int val)
Converts int to message {0: 'OK', 1: 'Warning', 2: 'Error', 3: 'Stale' }.
std::string toXml() const
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
#define ROS_ASSERT_MSG(cond,...)
const std::string & getNamespace() const
Base class of all Analyzers. Loaded by aggregator.
Allows analyzers to be grouped together, or used as sub-analyzers.
bool getParam(const std::string &key, std::string &s) const
Helper class to hold, store DiagnosticStatus messages.
PLUGINLIB_EXPORT_CLASS(diagnostic_aggregator::AnalyzerGroup, diagnostic_aggregator::Analyzer) AnalyzerGroup