DiagnosticStatusWrapper.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*********************************************************************
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the Willow Garage nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *********************************************************************/
35 
40 #ifndef DIAGNOSTICMESSAGEWRAPPER_HH
41 #define DIAGNOSTICMESSAGEWRAPPER_HH
42 
43 #include <vector>
44 #include <string>
45 #include <sstream>
46 #include <stdarg.h>
47 #include <cstdio>
48 
49 #include "ros/ros.h"
50 
52 
53 namespace diagnostic_updater
54 {
55 
67  class DiagnosticStatusWrapper : public diagnostic_msgs::DiagnosticStatus
68  {
69  public:
70 
77  void summary(unsigned char lvl, const std::string s)
78  {
79  level = lvl;
80  message = s;
81  }
82 
102  void mergeSummary(unsigned char lvl, const std::string s)
103  {
104  if ((lvl>0) && (level>0))
105  {
106  if (!message.empty())
107  message += "; ";
108  message += s;
109  }
110  else if (lvl > level)
111  message = s;
112 
113  if (lvl > level)
114  level = lvl;
115  }
116 
125  {
126  mergeSummary(src.level, src.message);
127  }
128 
141  void mergeSummaryf(unsigned char lvl, const char *format, ...)
142  {
143  va_list va;
144  char buff[1000]; // @todo This could be done more elegantly.
145  va_start(va, format);
146  if (vsnprintf(buff, 1000, format, va) >= 1000)
147  ROS_DEBUG("Really long string in DiagnosticStatusWrapper::addf, it was truncated.");
148  std::string value = std::string(buff);
149  mergeSummary(lvl, value);
150  va_end(va);
151  }
152 
164  void summaryf(unsigned char lvl, const char *format, ...)
165  {
166  va_list va;
167  char buff[1000]; // @todo This could be done more elegantly.
168  va_start(va, format);
169  if (vsnprintf(buff, 1000, format, va) >= 1000)
170  ROS_DEBUG("Really long string in DiagnosticStatusWrapper::addf, it was truncated.");
171  std::string value = std::string(buff);
172  summary(lvl, value);
173  va_end(va);
174  }
175 
180  void clearSummary()
181  {
182  summary(0, "");
183  }
184 
191  {
192  summary(src.level, src.message);
193  }
194 
204  template<class T>
205  void add(const std::string &key, const T &val)
206  {
207  std::stringstream ss;
208  ss << val;
209  std::string sval = ss.str();
210  add(key, sval);
211  }
212 
221  void addf(const std::string &key, const char *format, ...); // In practice format will always be a char *
222 
229  void clear()
230  {
231  values.clear();
232  }
233  };
234 
235  template<>
236  inline void DiagnosticStatusWrapper::add<std::string>(const std::string &key, const std::string &s)
237  {
239  ds.key = key;
240  ds.value = s;
241  values.push_back(ds);
242  }
243 
245 template<>
246 inline void DiagnosticStatusWrapper::add<bool>(const std::string &key, const bool &b)
247 {
249  ds.key = key;
250  ds.value = b ? "True" : "False";
251 
252  values.push_back(ds);
253 }
254 
255  // Need to place addf after DiagnosticStatusWrapper::add<std::string> or
256  // gcc complains that the specialization occurs after instatiation.
257  inline void DiagnosticStatusWrapper::addf(const std::string &key, const char *format, ...) // In practice format will always be a char *
258  {
259  va_list va;
260  char buff[1000]; // @todo This could be done more elegantly.
261  va_start(va, format);
262  if (vsnprintf(buff, 1000, format, va) >= 1000)
263  ROS_DEBUG("Really long string in DiagnosticStatusWrapper::addf, it was truncated.");
264  std::string value = std::string(buff);
265  add(key, value);
266  va_end(va);
267  }
268 
269 
270 }
271 #endif
diagnostic_updater::DiagnosticStatusWrapper::add
void add(const std::string &key, const bool &b)
diagnostic_msgs::DiagnosticStatus_::level
_level_type level
Definition: DiagnosticStatus.h:47
s
XmlRpcServer s
diagnostic_updater::DiagnosticStatusWrapper::clearSummary
void clearSummary()
diagnostic_msgs::KeyValue_::key
_key_type key
Definition: KeyValue.h:40
DiagnosticStatus.h
diagnostic_msgs::KeyValue_::value
_value_type value
Definition: KeyValue.h:43
diagnostic_msgs::KeyValue_
Definition: KeyValue.h:23
diagnostic_updater::DiagnosticStatusWrapper::mergeSummaryf
void mergeSummaryf(unsigned char lvl, const char *format,...)
diagnostic_updater::DiagnosticStatusWrapper::clear
void clear()
diagnostic_msgs::DiagnosticStatus_::message
_message_type message
Definition: DiagnosticStatus.h:53
message
def message(msg, *args, **kwargs)
diagnostic_updater::DiagnosticStatusWrapper::summary
void summary(const diagnostic_msgs::DiagnosticStatus &src)
diagnostic_updater
Author: Blaise Gassend.
diagnostic_updater::DiagnosticStatusWrapper::mergeSummary
void mergeSummary(const diagnostic_msgs::DiagnosticStatus &src)
values
std::vector< double > values
diagnostic_updater::DiagnosticStatusWrapper::addf
void addf(const std::string &key, const char *format,...)
Definition: eloquent/include/diagnostic_updater/diagnostic_status_wrapper.hpp:282
sick_scan_base.h
ROS_DEBUG
#define ROS_DEBUG(...)
Definition: sick_scan_logging.h:112
diagnostic_msgs::DiagnosticStatus_
Definition: DiagnosticStatus.h:24
diagnostic_updater::DiagnosticStatusWrapper::summaryf
void summaryf(unsigned char lvl, const char *format,...)


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:08