utils.h
Go to the documentation of this file.
00001 /*
00002  * File: utils.h
00003  * Author: Vladislav Tananaev
00004  *
00005  */
00006 
00007 #ifndef MRPT_BRIDGE_UTILS_H
00008 #define MRPT_BRIDGE_UTILS_H
00009 
00010 #include <ros/console.h>
00011 #include <mrpt/system/datetime.h>
00012 #include <mrpt/version.h>
00013 #include <mrpt/utils/COutputLogger.h>
00014 #include <log4cxx/logger.h>
00015 
00016 namespace mrpt_bridge
00017 {
00022 inline mrpt::utils::VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(
00023         log4cxx::LevelPtr lvl)
00024 {
00025         using namespace mrpt::utils;
00026         using namespace log4cxx;
00027 
00028         // determine on the corresponding VerbosityLevel
00029         VerbosityLevel mrpt_lvl;
00030 
00031         if (lvl == Level::getFatal() || lvl == Level::getError())
00032         {
00033                 mrpt_lvl = LVL_ERROR;
00034         }
00035         else if (lvl == Level::getWarn())
00036         {
00037                 mrpt_lvl = LVL_WARN;
00038         }
00039         else if (lvl == Level::getInfo())
00040         {
00041                 mrpt_lvl = LVL_INFO;
00042         }
00043         else if (lvl == Level::getDebug())
00044         {
00045                 mrpt_lvl = LVL_DEBUG;
00046         }
00047         else
00048         {
00049                 THROW_EXCEPTION("Unknown log4cxx::Level is given.");
00050         }
00051 
00052         return mrpt_lvl;
00053 
00054 }  // end of rosLoggerLvlToMRPTLoggerLvl
00055 
00063 inline void mrptToROSLoggerCallback(
00064         const std::string& msg, const mrpt::utils::VerbosityLevel level,
00065         const std::string& loggerName, const mrpt::system::TTimeStamp timestamp,
00066         void* userParam)
00067 {
00068         // Remove trailing \n if present
00069         std::string tmsg = msg;
00070         if (!tmsg.empty() &&
00071                 tmsg.compare(tmsg.length() - 1, tmsg.length(), "\n") == 0)
00072         {
00073                 tmsg.erase(tmsg.end() - 1);
00074         }
00075 
00076         if (level == mrpt::utils::LVL_DEBUG)
00077         {
00078                 ROS_DEBUG("%s", tmsg.c_str());
00079         }
00080         else if (level == mrpt::utils::LVL_INFO)
00081         {
00082                 ROS_INFO("%s", tmsg.c_str());
00083         }
00084         else if (level == mrpt::utils::LVL_WARN)
00085         {
00086                 ROS_WARN("%s", tmsg.c_str());
00087         }
00088         else if (level == mrpt::utils::LVL_ERROR)
00089         {
00090                 ROS_ERROR("%s", tmsg.c_str());
00091         }
00092 }
00093 }  // namespace mrpt_bridge
00094 
00095 #endif  // MRPT_BRIDGE_UTILS_H


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Mon Sep 18 2017 03:12:06