CARMA C++
MonitorSystemWithThreshold.h
Go to the documentation of this file.
1 
12 #ifndef CARMA_MONITOR_MONITORSYSTEMWITHTHRESHOLD_H
13 #define CARMA_MONITOR_MONITORSYSTEMWITHTHRESHOLD_H
14 
15 #include <vector>
16 
19 
20 namespace carma {
21 namespace monitor {
22 
23 class MonitorSystem;
24 
32  public:
33  explicit MonitorSystemWithThreshold(MonitorSystem &monitorSystem);
34 
35  virtual ~MonitorSystemWithThreshold() {}
36 
43  template <typename T>
44  std::vector<T>
45  getThresholdValues(const std::string &searchString,
46  carma::monitor::ThresholdValueEnum type);
47 
53  template<typename T>
54  T getThresholdValue(const std::string &mpName,
55  carma::monitor::ThresholdValueEnum type);
56 
62  template<typename T>
63  T getThresholdValue(const MonitorPointThreshold &threshold,
64  carma::monitor::ThresholdValueEnum type);
65 
72  std::vector<MonitorPointThreshold*>
73  getThresholds(const std::string &searchString);
74 
80  MonitorPointThreshold& getThreshold(const std::string &mpName);
81 
88  std::vector<std::string> getMonitorPointNames(const std::string &searchString);
89 
94  std::vector<std::string> getAllMonitorPointNames();
95 
102  template <typename T>
103  void setThresholdValue(const std::string &mpName,
104  carma::monitor::ThresholdValueEnum type,
105  T value);
106 
113  template <typename T>
114  void setThresholdValue(MonitorPointThreshold* threshold,
115  carma::monitor::ThresholdValueEnum type,
116  T value);
117 
124  template <typename T>
125  void setThresholdValues(const std::string &searchString,
126  carma::monitor::ThresholdValueEnum type,
127  T value) {
128  std::vector<carma::monitor::MonitorPointThreshold*> thresholds =
129  getThresholds(searchString);
130  std::vector<carma::monitor::MonitorPointThreshold*>::iterator mpt;
131  std::vector<carma::monitor::MonitorPointThreshold*>::iterator thresholdsEnd =
132  thresholds.end();
133 
134  for (mpt = thresholds.begin(); mpt != thresholdsEnd; mpt++) {
135  setThresholdValue(*mpt, type, value);
136  }
137  }
138 
139 
140  private:
141  MonitorSystem &monitorSystem_;
142 
143 }; // end class MonitorSystemWithThreshold
144 
145 template <typename T>
146 inline T
148  carma::monitor::ThresholdValueEnum type) {
149  struct we_should_not_be_here;
150 
151  if ( sizeof( we_should_not_be_here ) != 3 )
152  throw -13;
153 
154  return 0;
155 }
156 template <>
157 inline char
158 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
159  carma::monitor::ThresholdValueEnum type) {
160  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
161  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BYTE) {
162  throw CARMA_ERROR("Monitor point value is not a char");
163  return 0;
164  }
165  return threshold.getByteThresholdValue(type);
166 }
167 template <>
168 inline short
169 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
170  carma::monitor::ThresholdValueEnum type) {
171  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
172  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_SHORT) {
173  throw CARMA_ERROR("Monitor point value is not a short");
174  return 0;
175  }
176  return threshold.getShortThresholdValue(type);
177 }
178 template <>
179 inline long
180 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
181  carma::monitor::ThresholdValueEnum type) {
182  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
183  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_INTEGER) {
184  throw CARMA_ERROR("Monitor point value is not a long");
185  return 0;
186  }
187  return threshold.getLongThresholdValue(type);
188 }
189 template <>
190 inline bool
191 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
192  carma::monitor::ThresholdValueEnum type) {
193  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
194  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BOOLEAN) {
195  throw CARMA_ERROR("Monitor point value is not a bool");
196  return 0;
197  }
198  return threshold.getBoolThresholdValue(type);
199 }
200 template <>
201 inline float
202 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
203  carma::monitor::ThresholdValueEnum type) {
204  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
205  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_FLOAT) {
206  throw CARMA_ERROR("Monitor point value is not a float");
207  return 0;
208  }
209  return threshold.getFloatThresholdValue(type);
210 }
211 template <>
212 inline double
213 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
214  carma::monitor::ThresholdValueEnum type) {
215  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
216  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_DOUBLE) {
217  throw CARMA_ERROR("Monitor point value is not a double");
218  return 0;
219  }
220  return threshold.getDoubleThresholdValue(type);
221 }
222 template <>
223 inline std::string
224 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
225  carma::monitor::ThresholdValueEnum type) {
226  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
227  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_STRING) {
228  throw CARMA_ERROR("Monitor point value is not a string");
229  return 0;
230  }
231  return threshold.getStringThresholdValue(type);
232 }
233 template <>
234 inline std::complex<float>
235 MonitorSystemWithThreshold::getThresholdValue(const std::string &mpName,
236  carma::monitor::ThresholdValueEnum type) {
237  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
238  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_COMPLEX) {
239  throw CARMA_ERROR("Monitor point value is not a complex");
240  return 0;
241  }
242  return threshold.getComplexThresholdValue(type);
243 }
244 
245 
246 template <typename T>
247 inline T
248 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
249  carma::monitor::ThresholdValueEnum type) {
250  struct we_should_not_be_here;
251 
252  if ( sizeof( we_should_not_be_here ) != 3 )
253  throw -13;
254 
255  return 0;
256 }
257 template <>
258 inline char
259 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
260  carma::monitor::ThresholdValueEnum type) {
261  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BYTE) {
262  throw CARMA_ERROR("Monitor point value is not a char");
263  return 0;
264  }
265  return threshold.getByteThresholdValue(type);
266 }
267 template <>
268 inline short
269 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
270  carma::monitor::ThresholdValueEnum type) {
271  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_SHORT) {
272  throw CARMA_ERROR("Monitor point value is not a short");
273  return 0;
274  }
275  return threshold.getShortThresholdValue(type);
276 }
277 template <>
278 inline long
279 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
280  carma::monitor::ThresholdValueEnum type) {
281  if (threshold.getValueType() == carma::monitor::MONITOR_VALUE_TYPE_INTEGER) {
282  return threshold.getLongThresholdValue(type);
283  } else if (threshold.getValueType() == carma::monitor::MONITOR_VALUE_TYPE_SERIAL_NUMBER) {
284  return threshold.getSerialNoThresholdValue(type);
285  } else {
286  throw CARMA_ERROR("Monitor point value is not a long or serial number");
287  }
288  return 0;
289 }
290 template <>
291 inline bool
292 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
293  carma::monitor::ThresholdValueEnum type) {
294  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BOOLEAN) {
295  throw CARMA_ERROR("Monitor point value is not a bool");
296  return 0;
297  }
298  return threshold.getBoolThresholdValue(type);
299 }
300 template <>
301 inline float
302 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
303  carma::monitor::ThresholdValueEnum type) {
304  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_FLOAT) {
305  throw CARMA_ERROR("Monitor point value is not a float");
306  return 0;
307  }
308  return threshold.getFloatThresholdValue(type);
309 }
310 
311 template <>
312 inline double
313 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
314  carma::monitor::ThresholdValueEnum type) {
315  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_DOUBLE) {
316  throw CARMA_ERROR("Monitor point value is not a double");
317  return 0;
318  }
319  return threshold.getDoubleThresholdValue(type);
320 }
321 template <>
322 inline std::string
323 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
324  carma::monitor::ThresholdValueEnum type) {
325  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_STRING) {
326  throw CARMA_ERROR("Monitor point value is not a string");
327  return 0;
328  }
329  return threshold.getStringThresholdValue(type);
330 }
331 template <>
332 inline std::complex<float>
333 MonitorSystemWithThreshold::getThresholdValue(const MonitorPointThreshold &threshold,
334  carma::monitor::ThresholdValueEnum type) {
335  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_COMPLEX) {
336  throw CARMA_ERROR("Monitor point value is not a complex");
337  return 0;
338  }
339  return threshold.getComplexThresholdValue(type);
340 }
341 
342 
343 template <typename T>
344 std::vector<T>
345 MonitorSystemWithThreshold::getThresholdValues(const std::string &searchString,
346  carma::monitor::ThresholdValueEnum type) {
347 
348  std::vector<T> values;
349 
350  // get list of monitor point names matching searchString
351  std::vector<std::string> monitorPointNames;
352  monitorPointNames = getMonitorPointNames(searchString);
353 
354  std::vector<std::string>::iterator nameIterator;
355  std::vector<std::string>::iterator monitorPointNamesEnd = monitorPointNames.end();
356 
357  for (nameIterator = monitorPointNames.begin();
358  nameIterator != monitorPointNamesEnd;
359  nameIterator++) {
360  values.push_back(getThresholdValue<T>(*nameIterator, type));
361  }
362 
363  return values;
364 }
365 
366 
367 template <typename T>
368 inline void
370  carma::monitor::ThresholdValueEnum type,
371  T value) {
372  struct we_should_not_be_here;
373 
374  if ( sizeof( we_should_not_be_here ) != 3 )
375  throw -13;
376 
377  return;
378 }
379 template <>
380 inline void
381 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
382  carma::monitor::ThresholdValueEnum type,
383  char value) {
384  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
385  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BYTE) {
386  throw CARMA_ERROR("Monitor point value is not a char");
387  return;
388  }
389  threshold.setRangeValue(type, value);
390 }
391 template <>
392 inline void
393 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
394  carma::monitor::ThresholdValueEnum type,
395  short value) {
396  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
397  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_SHORT) {
398  throw CARMA_ERROR("Monitor point value is not a short");
399  return;
400  }
401  threshold.setRangeValue(type, value);
402 }
403 template <>
404 inline void
405 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
406  carma::monitor::ThresholdValueEnum type,
407  long value) {
408  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
409  if (threshold.getValueType() == carma::monitor::MONITOR_VALUE_TYPE_INTEGER) {
410  threshold.setRangeValue(type, value);
411  } else if (threshold.getValueType() == carma::monitor::MONITOR_VALUE_TYPE_SERIAL_NUMBER) {
412  threshold.setRangeValueSerialNo(type, value);
413  } else {
414  throw CARMA_ERROR("Monitor point value is not an integer (long) or serial number");
415  }
416 }
417 template <>
418 inline void
419 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
420  carma::monitor::ThresholdValueEnum type,
421  bool value) {
422  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
423  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BOOLEAN) {
424  throw CARMA_ERROR("Monitor point value is not a bool");
425  return;
426  }
427  threshold.setRangeValue(type, value);
428 }
429 template <>
430 inline void
431 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
432  carma::monitor::ThresholdValueEnum type,
433  float value) {
434  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
435  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_FLOAT) {
436  throw CARMA_ERROR("Monitor point value is not a float");
437  return;
438  }
439  threshold.setRangeValue(type, value);
440 }
441 template <>
442 inline void
443 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
444  carma::monitor::ThresholdValueEnum type,
445  double value) {
446  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
447  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_DOUBLE) {
448  throw CARMA_ERROR("Monitor point value is not a double");
449  return;
450  }
451  threshold.setRangeValue(type, value);
452 }
453 template <>
454 inline void
455 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
456  carma::monitor::ThresholdValueEnum type,
457  std::complex<float> value) {
458  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
459  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_COMPLEX) {
460  throw CARMA_ERROR("Monitor point value is not a complex");
461  return;
462  }
463  threshold.setRangeValue(type, value);
464 }
465 template <>
466 inline void
467 MonitorSystemWithThreshold::setThresholdValue(const std::string &mpName,
468  carma::monitor::ThresholdValueEnum type,
469  std::string value) {
470  carma::monitor::MonitorPointThreshold threshold = getThreshold(mpName);
471  if (threshold.getValueType() != carma::monitor::MONITOR_VALUE_TYPE_STRING) {
472  throw CARMA_ERROR("Monitor point value is not a string");
473  return;
474  }
475  threshold.setRangeValue(type, value);
476 }
477 
478 
479 template <typename T>
480 inline void
481 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
482  carma::monitor::ThresholdValueEnum type,
483  T value) {
484  struct we_should_not_be_here;
485 
486  if ( sizeof( we_should_not_be_here ) != 3 )
487  throw -13;
488 
489  return;
490 }
491 template <>
492 inline void
493 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
494  carma::monitor::ThresholdValueEnum type,
495  char value) {
496  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BYTE) {
497  throw CARMA_ERROR("Monitor point value is not a char");
498  return;
499  }
500  threshold->setRangeValue(type, value);
501 }
502 template <>
503 inline void
504 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
505  carma::monitor::ThresholdValueEnum type,
506  short value) {
507  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_SHORT) {
508  throw CARMA_ERROR("Monitor point value is not a short");
509  return;
510  }
511  threshold->setRangeValue(type, value);
512 }
513 template <>
514 inline void
515 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
516  carma::monitor::ThresholdValueEnum type,
517  long value) {
518  if (threshold->getValueType() == carma::monitor::MONITOR_VALUE_TYPE_INTEGER) {
519  threshold->setRangeValue(type, value);
520  } else if (threshold->getValueType() == carma::monitor::MONITOR_VALUE_TYPE_SERIAL_NUMBER) {
521  threshold->setRangeValueSerialNo(type, value);
522  } else {
523  throw CARMA_ERROR("Monitor point value is not an integer (long) or serial number");
524  }
525 }
526 template <>
527 inline void
528 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
529  carma::monitor::ThresholdValueEnum type,
530  bool value) {
531  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_BOOLEAN) {
532  throw CARMA_ERROR("Monitor point value is not a bool");
533  return;
534  }
535  threshold->setRangeValue(type, value);
536 }
537 template <>
538 inline void
539 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
540  carma::monitor::ThresholdValueEnum type,
541  float value) {
542  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_FLOAT) {
543  throw CARMA_ERROR("Monitor point value is not a float");
544  return;
545  }
546  threshold->setRangeValue(type, value);
547 }
548 template <>
549 inline void
550 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
551  carma::monitor::ThresholdValueEnum type,
552  double value) {
553  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_DOUBLE) {
554  throw CARMA_ERROR("Monitor point value is not a double");
555  return;
556  }
557  threshold->setRangeValue(type, value);
558 }
559 template <>
560 inline void
561 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
562  carma::monitor::ThresholdValueEnum type,
563  std::complex<float> value) {
564  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_COMPLEX) {
565  throw CARMA_ERROR("Monitor point value is not a complex");
566  return;
567  }
568  threshold->setRangeValue(type, value);
569 }
570 template <>
571 inline void
572 MonitorSystemWithThreshold::setThresholdValue(MonitorPointThreshold *threshold,
573  carma::monitor::ThresholdValueEnum type,
574  std::string value) {
575  if (threshold->getValueType() != carma::monitor::MONITOR_VALUE_TYPE_STRING) {
576  throw CARMA_ERROR("Monitor point value is not a string");
577  return;
578  }
579  threshold->setRangeValue(type, value);
580 }
581 
582 
583 } // end namespace monitor
584 } // end namespace carma
585 
586 
587 #endif
std::vector< std::string > getMonitorPointNames(const std::string &searchString)
method for obtaining monitor point names
MonitorSystemWithThreshold is a class that contains methods for retrieving and setting threshold valu...
std::vector< T > getThresholdValues(const std::string &searchString, carma::monitor::ThresholdValueEnum type)
method for obtaining threshold values
std::vector< MonitorPointThreshold * > getThresholds(const std::string &searchString)
method for obtaining threshold objects
T getThresholdValue(const std::string &mpName, carma::monitor::ThresholdValueEnum type)
method for obtaining threshold value for a particular MP
Monitor system base class.
Definition: MonitorSystem.h:81
MonitorPointThreshold & getThreshold(const std::string &mpName)
method for obtaining threshold object for a particular MP
std::vector< std::string > getAllMonitorPointNames()
method for obtaining all monitor point names
void setThresholdValue(const std::string &mpName, carma::monitor::ThresholdValueEnum type, T value)
method for setting threshold value for a specific mp
Class that manages the IPQ version of SystemThresholdFrame.
#define CARMA_ERROR(y)
Trick to get the file name and line number passed to the exception handler.
void setThresholdValues(const std::string &searchString, carma::monitor::ThresholdValueEnum type, T value)
method for setting threshold values for multiple monitor points using