console.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  * Copyright (c) 2008, Willow Garage, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of Willow Garage, Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 // Author: Josh Faust
32 
33 #ifndef ROSCONSOLE_ROSCONSOLE_H
34 #define ROSCONSOLE_ROSCONSOLE_H
35 
36 #include "console_backend.h"
37 
38 #include <cstdio>
39 #include <sstream>
40 #include <ros/time.h>
41 #include <cstdarg>
42 #include <ros/macros.h>
43 #include <map>
44 #include <vector>
45 
46 #ifdef ROSCONSOLE_BACKEND_LOG4CXX
47 #include "log4cxx/level.h"
48 #endif
49 
50 // Import/export for windows dll's and visibility for gcc shared libraries.
51 
52 #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries
53  #ifdef rosconsole_EXPORTS // we are building a shared lib/dll
54  #define ROSCONSOLE_DECL ROS_HELPER_EXPORT
55  #else // we are using shared lib/dll
56  #define ROSCONSOLE_DECL ROS_HELPER_IMPORT
57  #endif
58 #else // ros is being built around static libraries
59  #define ROSCONSOLE_DECL
60 #endif
61 
62 #ifdef __GNUC__
63 #if __GNUC__ >= 3
64 #define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b) __attribute__ ((__format__ (__printf__, a, b)));
65 #endif
66 #endif
67 
68 #ifndef ROSCONSOLE_PRINTF_ATTRIBUTE
69 #define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b)
70 #endif
71 
72 namespace boost
73 {
74 template<typename T> class shared_array;
75 }
76 
77 namespace roswrap
78 {
79 namespace console
80 {
81 
83 
84 #ifdef ROSCONSOLE_BACKEND_LOG4CXX
85 extern ROSCONSOLE_DECL log4cxx::LevelPtr g_level_lookup[];
86 #endif
87 
88 extern ROSCONSOLE_DECL bool get_loggers(std::map<std::string, levels::Level>& loggers);
89 extern ROSCONSOLE_DECL bool set_logger_level(const std::string& name, levels::Level level);
90 
94 // extern ROSCONSOLE_DECL bool g_initialized;
95 
99 extern ROSCONSOLE_DECL std::string g_last_error_message;
100 
102 {
103 public:
104 
105  virtual ~LogAppender() {}
106 
107  virtual void log(::ros::console::Level level, const char* str, const char* file, const char* function, int line) = 0;
108 
109 };
110 
111 ROSCONSOLE_DECL void register_appender(LogAppender* appender);
112 
113 struct Token
114 {
115  virtual ~Token() {}
116  /*
117  * @param level
118  * @param message
119  * @param file
120  * @param function
121  * @param line
122  */
123  virtual std::string getString(void*, ::ros::console::Level, const char*, const char*, const char*, int) = 0;
124 };
125 typedef std::shared_ptr<Token> TokenPtr;
126 typedef std::vector<TokenPtr> V_Token;
127 
128 struct Formatter
129 {
130  void init(const char* fmt);
131  void print(void* logger_handle, ::ros::console::Level level, const char* str, const char* file, const char* function, int line);
132  std::string format_;
134 };
135 
140 
148 
149 class FilterBase;
157 ROSCONSOLE_DECL void print(FilterBase* filter, void* logger, Level level,
158  const char* file, int line,
159  const char* function, const char* fmt, ...) ROSCONSOLE_PRINTF_ATTRIBUTE(7, 8);
160 
161 ROSCONSOLE_DECL void print(FilterBase* filter, void* logger, Level level,
162  const std::stringstream& str, const char* file, int line, const char* function);
163 
165 
174 
184 
185 ROSCONSOLE_DECL void setFixedFilterToken(const std::string& key, const std::string& val);
186 
191 {
192  // input parameters
193  const char* file;
194  int line;
195  const char* function;
196  const char* message;
197 
198  // input/output parameters
199  void* logger;
201 
202  // output parameters
203  std::string out_message;
204 };
205 
228 {
229 public:
230  virtual ~FilterBase() {}
235  inline virtual bool isEnabled() { return true; }
240  inline virtual bool isEnabled(FilterParams&) { return true; }
241 };
242 
247 ROSCONSOLE_DECL void initializeLogLocation(LogLocation* loc, const std::string& name, Level level);
256 
261 {
265  void* logger_;
266 };
267 
268 ROSCONSOLE_DECL void vformatToBuffer(boost::shared_array<char>& buffer, size_t& buffer_size, const char* fmt, va_list args);
269 ROSCONSOLE_DECL void formatToBuffer(boost::shared_array<char>& buffer, size_t& buffer_size, const char* fmt, ...);
270 ROSCONSOLE_DECL std::string formatToString(const char* fmt, ...);
271 
272 } // namespace console
273 } // namespace roswrap
274 
275 #ifdef WIN32
276 #define ROS_LIKELY(x) (x)
277 #define ROS_UNLIKELY(x) (x)
278 #else
279 #define ROS_LIKELY(x) __builtin_expect((x),1)
280 #define ROS_UNLIKELY(x) __builtin_expect((x),0)
281 #endif
282 
283 #if defined(MSVC)
284  #define __ROSCONSOLE_FUNCTION__ __FUNCSIG__
285 #elif defined(__GNUC__)
286  #define __ROSCONSOLE_FUNCTION__ __PRETTY_FUNCTION__
287 #else
288  #define __ROSCONSOLE_FUNCTION__ ""
289 #endif
290 
291 
292 #ifdef ROS_PACKAGE_NAME
293 #define ROSCONSOLE_PACKAGE_NAME ROS_PACKAGE_NAME
294 #else
295 #define ROSCONSOLE_PACKAGE_NAME "unknown_package"
296 #endif
297 
298 #define ROSCONSOLE_ROOT_LOGGER_NAME "ros"
299 #define ROSCONSOLE_NAME_PREFIX ROSCONSOLE_ROOT_LOGGER_NAME "." ROSCONSOLE_PACKAGE_NAME
300 #define ROSCONSOLE_DEFAULT_NAME ROSCONSOLE_NAME_PREFIX
301 
302 // These allow you to compile-out everything below a certain severity level if necessary
303 #define ROSCONSOLE_SEVERITY_DEBUG 0
304 #define ROSCONSOLE_SEVERITY_INFO 1
305 #define ROSCONSOLE_SEVERITY_WARN 2
306 #define ROSCONSOLE_SEVERITY_ERROR 3
307 #define ROSCONSOLE_SEVERITY_FATAL 4
308 #define ROSCONSOLE_SEVERITY_NONE 5
309 
315 #ifndef ROSCONSOLE_MIN_SEVERITY
316 #define ROSCONSOLE_MIN_SEVERITY ROSCONSOLE_SEVERITY_DEBUG
317 #endif
318 
323 #define ROSCONSOLE_AUTOINIT
324 
325 #define ROSCONSOLE_DEFINE_LOCATION(cond, level, name) \
326  ROSCONSOLE_AUTOINIT; \
327  static ::ros::console::LogLocation __rosconsole_define_location__loc = {false, false, ::ros::console::levels::Count, 0}; /* Initialized at compile-time */ \
328  if (ROS_UNLIKELY(!__rosconsole_define_location__loc.initialized_)) \
329  { \
330  initializeLogLocation(&__rosconsole_define_location__loc, name, level); \
331  } \
332  if (ROS_UNLIKELY(__rosconsole_define_location__loc.level_ != level)) \
333  { \
334  setLogLocationLevel(&__rosconsole_define_location__loc, level); \
335  checkLogLocationEnabled(&__rosconsole_define_location__loc); \
336  } \
337  bool __rosconsole_define_location__enabled = __rosconsole_define_location__loc.logger_enabled_ && (cond);
338 
339 #define ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, ...) \
340  ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__, __VA_ARGS__)
341 
342 #define ROSCONSOLE_PRINT_AT_LOCATION(...) \
343  ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(0, __VA_ARGS__)
344 
345 // inside a macro which uses args use only well namespaced variable names in order to not overlay variables coming in via args
346 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args) \
347  do \
348  { \
349  std::stringstream __rosconsole_print_stream_at_location_with_filter__ss__; \
350  __rosconsole_print_stream_at_location_with_filter__ss__ << args; \
351  ::ros::console::print(filter, __rosconsole_define_location__loc.logger_, __rosconsole_define_location__loc.level_, __rosconsole_print_stream_at_location_with_filter__ss__, __FILE__, __LINE__, __ROSCONSOLE_FUNCTION__); \
352  } while (0)
353 
354 #define ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args) \
355  ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(0, args)
356 
366 #define ROS_LOG_COND(cond, level, name, ...) \
367  do \
368  { \
369  ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \
370  \
371  if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \
372  { \
373  ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
374  } \
375  } while(0)
376 
386 #define ROS_LOG_STREAM_COND(cond, level, name, args) \
387  do \
388  { \
389  ROSCONSOLE_DEFINE_LOCATION(cond, level, name); \
390  if (ROS_UNLIKELY(__rosconsole_define_location__enabled)) \
391  { \
392  ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
393  } \
394  } while(0)
395 
402 #define ROS_LOG_ONCE(level, name, ...) \
403  do \
404  { \
405  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
406  static bool hit = false; \
407  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!hit)) \
408  { \
409  hit = true; \
410  ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
411  } \
412  } while(0)
413 
414 // inside a macro which uses args use only well namespaced variable names in order to not overlay variables coming in via args
421 #define ROS_LOG_STREAM_ONCE(level, name, args) \
422  do \
423  { \
424  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
425  static bool __ros_log_stream_once__hit__ = false; \
426  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(!__ros_log_stream_once__hit__)) \
427  { \
428  __ros_log_stream_once__hit__ = true; \
429  ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
430  } \
431  } while(0)
432 
440 #define ROS_LOG_THROTTLE(rate, level, name, ...) \
441  do \
442  { \
443  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
444  static double last_hit = 0.0; \
445  ::ros::Time now = ::ros::Time::now(); \
446  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(last_hit + rate <= now.toSec())) \
447  { \
448  last_hit = now.toSec(); \
449  ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
450  } \
451  } while(0)
452 
453 // inside a macro which uses args use only well namespaced variable names in order to not overlay variables coming in via args
461 #define ROS_LOG_STREAM_THROTTLE(rate, level, name, args) \
462  do \
463  { \
464  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
465  static double __ros_log_stream_throttle__last_hit__ = 0.0; \
466  ::ros::Time __ros_log_stream_throttle__now__ = ::ros::Time::now(); \
467  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_stream_throttle__last_hit__ + rate <= __ros_log_stream_throttle__now__.toSec())) \
468  { \
469  __ros_log_stream_throttle__last_hit__ = __ros_log_stream_throttle__now__.toSec(); \
470  ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
471  } \
472  } while(0)
473 
481 #define ROS_LOG_DELAYED_THROTTLE(rate, level, name, ...) \
482  do \
483  { \
484  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
485  ::ros::Time __ros_log_delayed_throttle__now__ = ::ros::Time::now(); \
486  static double __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__.toSec(); \
487  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_delayed_throttle__last_hit__ + rate <= __ros_log_delayed_throttle__now__.toSec())) \
488  { \
489  __ros_log_delayed_throttle__last_hit__ = __ros_log_delayed_throttle__now__.toSec(); \
490  ROSCONSOLE_PRINT_AT_LOCATION(__VA_ARGS__); \
491  } \
492  } while(0)
493 
494 // inside a macro which uses args use only well namespaced variable names in order to not overlay variables coming in via args
502 #define ROS_LOG_STREAM_DELAYED_THROTTLE(rate, level, name, args) \
503  do \
504  { \
505  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
506  ::ros::Time __ros_log_stream_delayed_throttle__now__ = ::ros::Time::now(); \
507  static double __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__.toSec(); \
508  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && ROS_UNLIKELY(__ros_log_stream_delayed_throttle__last_hit__ + rate <= __ros_log_stream_delayed_throttle__now__.toSec())) \
509  { \
510  __ros_log_stream_delayed_throttle__last_hit__ = __ros_log_stream_delayed_throttle__now__.toSec(); \
511  ROSCONSOLE_PRINT_STREAM_AT_LOCATION(args); \
512  } \
513  } while(0)
514 
522 #define ROS_LOG_FILTER(filter, level, name, ...) \
523  do \
524  { \
525  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
526  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \
527  { \
528  ROSCONSOLE_PRINT_AT_LOCATION_WITH_FILTER(filter, __VA_ARGS__); \
529  } \
530  } while(0)
531 
539 #define ROS_LOG_STREAM_FILTER(filter, level, name, args) \
540  do \
541  { \
542  ROSCONSOLE_DEFINE_LOCATION(true, level, name); \
543  if (ROS_UNLIKELY(__rosconsole_define_location__enabled) && (filter)->isEnabled()) \
544  { \
545  ROSCONSOLE_PRINT_STREAM_AT_LOCATION_WITH_FILTER(filter, args); \
546  } \
547  } while(0)
548 
555 #define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__)
556 
562 #define ROS_LOG_STREAM(level, name, args) ROS_LOG_STREAM_COND(true, level, name, args)
563 
564 #include "rosconsole/macros_generated.h"
565 
566 #endif // ROSCONSOLE_ROSCONSOLE_H
roswrap::console::FilterBase::isEnabled
virtual bool isEnabled(FilterParams &)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
Definition: console.h:240
roswrap::console::initializeLogLocation
ROSCONSOLE_DECL void initializeLogLocation(LogLocation *loc, const std::string &name, Level level)
Internal.
roswrap::console::vformatToBuffer
ROSCONSOLE_DECL void vformatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt, va_list args)
roswrap::console::set_logger_level
ROSCONSOLE_DECL bool set_logger_level(const std::string &name, levels::Level level)
Definition: rossimu.cpp:105
const
#define const
Definition: getopt.c:38
roswrap::console::FilterParams::line
int line
[input] Line the message came from
Definition: console.h:194
roswrap::console::formatToString
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
roswrap::console::setLogLocationLevel
ROSCONSOLE_DECL void setLogLocationLevel(LogLocation *loc, Level level)
Internal.
roswrap::console::FilterBase::isEnabled
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
Definition: console.h:235
roswrap::console::register_appender
ROSCONSOLE_DECL void register_appender(LogAppender *appender)
roswrap::console::LogLocation::logger_enabled_
bool logger_enabled_
Definition: console.h:263
roswrap::console::checkLogLocationEnabled
ROSCONSOLE_DECL void checkLogLocationEnabled(LogLocation *loc)
Internal.
roswrap::console::notifyLoggerLevelsChanged
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
roswrap::console::registerLogLocation
ROSCONSOLE_DECL void registerLogLocation(LogLocation *loc)
Registers a logging location with the system.
roswrap::console::shutdown
ROSCONSOLE_DECL void shutdown()
Definition: rossimu.cpp:269
roswrap::console::TokenPtr
std::shared_ptr< Token > TokenPtr
Definition: console.h:125
roswrap::console::g_formatter
ROSCONSOLE_DECL Formatter g_formatter
Only exported because the implementation need it. Do not use directly.
roswrap::console::print
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
Don't call this directly. Use the ROS_LOG() macro instead.
roswrap::console::LogLocation::logger_
void * logger_
Definition: console.h:265
boost
roswrap::console::LogAppender::log
virtual void log(::ros::console::Level level, const char *str, const char *file, const char *function, int line)=0
roswrap::console::FilterParams::logger
void * logger
[input/output] Handle identifying logger that this message will be output to. If changed,...
Definition: console.h:199
roswrap::console::LogAppender::~LogAppender
virtual ~LogAppender()
Definition: console.h:105
roswrap::console::initialize
ROSCONSOLE_DECL void initialize()
Don't call this directly. Performs any required initialization/configuration. Happens automatically w...
Definition: rossimu.cpp:235
ROSCONSOLE_DECL
#define ROSCONSOLE_DECL
Definition: console.h:59
roswrap::console::FilterParams::file
const char * file
[input] File the message came from
Definition: console.h:193
api.setup.name
name
Definition: python/api/setup.py:12
roswrap::console::FilterParams
Parameter structure passed to FilterBase::isEnabled(...);. Includes both input and output parameters.
Definition: console.h:190
roswrap::console::setFixedFilterToken
ROSCONSOLE_DECL void setFixedFilterToken(const std::string &key, const std::string &val)
roswrap::console::Formatter::format_
std::string format_
Definition: console.h:132
roswrap::console::LogLocation
Internal.
Definition: console.h:260
boost::shared_array
Definition: shared_array.hpp:46
roswrap::console::V_Token
std::vector< TokenPtr > V_Token
Definition: console.h:126
roswrap
Definition: param_modi.cpp:41
imu_delay_tester.line
line
Definition: imu_delay_tester.py:135
roswrap::console::FilterParams::level
Level level
[input/output] Severity level. If changed, uses the new level
Definition: console.h:200
ros::console::levels::Level
Level
ROSCONSOLE_PRINTF_ATTRIBUTE
#define ROSCONSOLE_PRINTF_ATTRIBUTE(a, b)
Definition: console.h:69
roswrap::console::Formatter
Definition: console.h:128
roswrap::console::LogLocation::level_
::ros::console::Level level_
Definition: console.h:264
roswrap::console::Formatter::tokens_
V_Token tokens_
Definition: console.h:133
roswrap::console::FilterParams::out_message
std::string out_message
[output] If set, writes this message instead of the original
Definition: console.h:203
roswrap::console::LogLocation::initialized_
bool initialized_
Definition: console.h:262
roswrap::console::FilterParams::message
const char * message
[input] The formatted message that will be output
Definition: console.h:196
roswrap::console::levels::Level
Level
Definition: console_backend.h:41
roswrap::console::LogAppender
Definition: console.h:101
g_level_lookup
log4cxx::LevelPtr g_level_lookup[levels::Count]
std
roswrap::console::Formatter::init
void init(const char *fmt)
roswrap::console::Formatter::print
void print(void *logger_handle, ::ros::console::Level level, const char *str, const char *file, const char *function, int line)
roswrap::console::get_loggers
ROSCONSOLE_DECL bool get_loggers(std::map< std::string, levels::Level > &loggers)
roswrap::console::g_last_error_message
ROSCONSOLE_DECL std::string g_last_error_message
Only exported because the macros need it. Do not use directly.
sick_scan_base.h
roswrap::console::Token::~Token
virtual ~Token()
Definition: console.h:115
roswrap::console::FilterBase::~FilterBase
virtual ~FilterBase()
Definition: console.h:230
roswrap::console::Token::getString
virtual std::string getString(void *, ::ros::console::Level, const char *, const char *, const char *, int)=0
args
console_backend.h
roswrap::console::formatToBuffer
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)
roswrap::console::LogLocation
struct ROSCONSOLE_DECL LogLocation
Definition: console.h:164
roswrap::console::FilterBase
Base-class for filters. Filters allow full user-defined control over whether or not a message should ...
Definition: console.h:227
roswrap::console::Token
Definition: console.h:113
sick_scan_timing_dump_analyser.loc
loc
Definition: sick_scan_timing_dump_analyser.py:50


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