53 ROS_ERROR(
"GenericAnalyzer was not given parameter \"path\". Namespace: %s",
59 if (n.
getParam(
"find_and_remove_prefix", find_remove))
61 vector<string> output;
68 if (n.
getParam(
"remove_prefix", removes))
72 if (n.
getParam(
"startswith", startswith))
80 if (n.
getParam(
"contains", contains))
84 if (n.
getParam(
"expected", expected))
87 for (
unsigned int i = 0; i < expected_.size(); ++i)
90 addItem(expected_[i], item);
97 vector<string> regex_strs;
100 for (
unsigned int i = 0; i < regex_strs.size(); ++i)
104 boost::regex re(regex_strs[i]);
105 regex_.push_back(re);
107 catch (boost::regex_error& e)
109 ROS_ERROR(
"Attempted to make regex from %s. Caught exception, ignoring value. Exception: %s",
110 regex_strs[i].c_str(), e.what());
115 if (startswith_.size() == 0 &&
name_.size() == 0 &&
116 contains_.size() == 0 && expected_.size() == 0 && regex_.size() == 0)
118 ROS_ERROR(
"GenericAnalyzer was not initialized with any way of checking diagnostics. Name: %s, namespace: %s", nice_name.c_str(), n.
getNamespace().c_str());
123 for(
size_t i=0; i<chaff_.size(); i++) {
128 int num_items_expected;
130 n.
param(
"timeout", timeout, 5.0);
131 n.
param(
"num_items", num_items_expected, -1);
132 n.
param(
"discard_stale", discard_stale,
false);
135 if (base_path ==
"/")
138 my_path = base_path +
"/" + nice_name;
140 if (my_path.find(
"/") != 0)
141 my_path =
"/" + my_path;
144 timeout, num_items_expected, discard_stale);
153 for (
unsigned int i = 0; i < regex_.size(); ++i)
155 if (boost::regex_match(name.c_str(), what, regex_[i]))
159 for (
unsigned int i = 0; i < expected_.size(); ++i)
161 if (name == expected_[i])
165 for (
unsigned int i = 0; i <
name_.size(); ++i)
167 if (name ==
name_[i])
171 for (
unsigned int i = 0; i < startswith_.size(); ++i)
173 if (name.find(startswith_[i]) == 0)
177 for (
unsigned int i = 0; i < contains_.size(); ++i)
179 if (name.find(contains_[i]) != string::npos)
191 vector<string> expected_names_missing;
192 bool has_name =
false;
194 for (
unsigned int i = 0; i < expected_.size(); ++i)
197 for (
unsigned int j = 0; j < processed.size(); ++j)
199 size_t last_slash = processed[j]->name.rfind(
"/");
200 string nice_name = processed[j]->name.substr(last_slash + 1);
201 if (nice_name == expected_[i] || nice_name ==
getOutputName(expected_[i]))
208 for (
unsigned int k = 0; k < chaff_.size(); ++k)
219 expected_names_missing.push_back(expected_[i]);
223 bool all_stale =
true;
224 for (
unsigned int j = 0; j < processed.size(); ++j)
231 for (
unsigned int i = 0; i < expected_names_missing.size(); ++i)
234 processed.push_back(item->toStatusMsg(path_,
true));
237 for (
unsigned int j = 0; j < processed.size(); ++j)
240 for (
unsigned int i = 0; i < chaff_.size(); ++i)
244 if (expected_names_missing.size() > 0 && processed[j]->name == path_)
249 processed[j]->message =
"Some diagnostics are stale - setting combined level to ERROR.";
254 processed[j]->message =
"All diagnostics are stale - setting combined level to STALE.";
258 for (
unsigned int k = 0; k < expected_names_missing.size(); ++k)
260 diagnostic_msgs::KeyValue kv;
261 kv.key = expected_names_missing[k];
262 kv.value =
"Missing";
263 processed[j]->values.push_back(kv);