Advertisement
dustingooding

TestComponent.cpp

Jul 16th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include "logging/tests/TestComponent.hpp"
  2. #include <rtt/rt_string.hpp>
  3. #include "logging/Category.hpp"
  4.  
  5. #include <rtt/Logger.hpp>
  6. #include "ocl/Component.hpp"
  7.  
  8. #include <log4cpp/HierarchyMaintainer.hh>
  9.  
  10. namespace OCL {
  11. namespace logging {
  12. namespace test {
  13.  
  14. static const char* parentCategory = "org.orocos.ocl.logging.tests";
  15.  
  16. Component::Component(std::string name) :
  17.         RTT::TaskContext(name),
  18.         categoryName(parentCategory + std::string(".") + name),
  19.         logger(dynamic_cast<OCL::logging::Category*>(
  20.                    &log4cpp::Category::getInstance(categoryName)))
  21. {
  22. }
  23.  
  24. Component::~Component()
  25. {
  26. }
  27.  
  28. bool Component::startHook()
  29. {
  30.     bool ok = (0 != logger);
  31.     if (!ok)
  32.     {
  33.         log(Error) << "Unable to find existing OCL category '"
  34.                    << categoryName << "'" << endlog();
  35.     }
  36.    
  37.     return ok;
  38. }
  39.        
  40. void Component::updateHook()
  41. {
  42.     static int i=0;
  43.     std::stringstream   str;
  44.     str << getName() << " " << i;
  45.  
  46.     // existing logging
  47. //  log(Debug) << str.str() << endlog();
  48.  
  49.     // new logging
  50.     logger->error("ERROR " + RTT::rt_string(str.str().c_str()));
  51.     logger->info( "INFO  " + RTT::rt_string(str.str().c_str()));
  52.     logger->debug("DEBUG " + RTT::rt_string(str.str().c_str()));
  53.  
  54.     // RTT logging
  55.     log(Error)   << std::string("RTT ERROR " + str.str())   << endlog();
  56.     log(Warning) << std::string("RTT WARNING " + str.str()) << endlog();
  57.     log(Info)    << std::string("RTT INFO " + str.str())    << endlog();
  58.  
  59.     // and trying to use the std::string versions ...
  60. //    logger->error(std::string("Hello")); // COMPILER error - not accessible!
  61. //    logger->debug("DEBUG"); // COMPILER error - not accessible with char*!
  62.  
  63.     ++i;
  64. }
  65.  
  66. // namespaces
  67. }
  68. }
  69. }
  70.  
  71. ORO_CREATE_COMPONENT_TYPE();
  72. ORO_LIST_COMPONENT_TYPE(OCL::logging::test::Component);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement