37 #ifndef GENERIC_ANALYZER_BASE_H
38 #define GENERIC_ANALYZER_BASE_H
45 #include <boost/shared_ptr.hpp>
46 #include <boost/regex.hpp>
48 #include "diagnostic_msgs/DiagnosticStatus.h"
49 #include "diagnostic_msgs/KeyValue.h"
65 class GenericAnalyzerBase :
public Analyzer
86 double timeout = -1.0,
int num_items_expected = -1,
bool discard_stale =
false)
98 ROS_WARN(
"Cannot discard stale items if no timeout specified. No items will be discarded");
115 ROS_ERROR(
"GenericAnalyzerBase is asked to analyze diagnostics without being initialized. init() must be called in order to correctly use this class.");
121 items_[item->getName()] = item;
131 virtual std::vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> >
report()
136 ROS_ERROR(
"GenericAnalyzerBase is asked to report diagnostics without being initialized. init() must be called in order to correctly use this class.");
140 std::vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > vec;
145 header_status->name =
path_;
147 header_status->message =
"OK";
149 std::vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > processed;
150 processed.push_back(header_status);
152 bool all_stale =
true;
154 std::map<std::string, boost::shared_ptr<StatusItem> >::iterator it =
items_.begin();
171 const int8_t level = item->getLevel();
172 header_status->level = std::max(header_status->level, level);
174 diagnostic_msgs::KeyValue kv;
176 kv.value = item->getMessage();
178 header_status->values.push_back(kv);
184 processed.push_back(item->toStatusMsg(
path_, stale));
198 header_status->message =
valToMsg(header_status->level);
203 header_status->level = 0;
204 header_status->message =
"OK";
209 header_status->level = std::max(lvl, header_status->level);
211 std::stringstream expec, item;
216 header_status->message =
"Expected " + expec.str() +
", found " + item.str();
218 header_status->message =
"No items found, expected " + expec.str();
221 bool header_stale_timed_out =
false;
231 if (
discard_stale_ && processed.size() == 1 && header_stale_timed_out)
233 std::vector<boost::shared_ptr<diagnostic_msgs::DiagnosticStatus> > vec;
271 std::map<std::string, boost::shared_ptr<StatusItem> >
items_;
280 #endif //GENERIC_ANALYZER_BASE_H