PrintService.cpp
Go to the documentation of this file.
00001 #include <rtt/Service.hpp>
00002 #include <rtt/Logger.hpp>
00003 #include <iostream>
00004 
00005 #include <rtt/types/GlobalsRepository.hpp>
00006 #include <rtt/types/Types.hpp>
00007 #include <rtt/types/TypeInfoName.hpp>
00008 #include <rtt/plugin/ServicePlugin.hpp>
00009 #include "OCL.hpp"
00010 
00011 namespace OCL
00012 {
00013 
00018     class PrintService: public RTT::Service
00019     {
00020     public:
00021         PrintService(TaskContext* parent) :
00022             RTT::Service("print", parent)
00023         {
00024             doc("A service that provides basic printing to std::cout, std::cerr and the RTT::Logger.");
00025             // add the operations
00026             addOperation("ln", &PrintService::println, this).doc(
00027                     "Prints a line to standard output.").arg("line",
00028                     "A string. Use a '+' to mix strings with numbers/variables.");
00029             addOperation("err", &PrintService::printerr, this).doc(
00030                     "Prints a line to standard error.").arg("line",
00031                     "A string. Use a '+' to mix strings with numbers/variables.");
00032             addOperation("log", &PrintService::printlog, this).doc(
00033                     "Prints a line to Orocos logger class.").arg("level","The LogLevel to use.").arg("line",
00034                     "A string. Use a '+' to mix strings with numbers/variables.");
00035 
00036             // add the log-levels as global variables.
00037             if (types::Types()->type("LogLevel") == 0) {
00038                 types::Types()->addType( new types::TypeInfoName<Logger::LogLevel>("LogLevel") );
00039                 types::GlobalsRepository::shared_ptr globals = types::GlobalsRepository::Instance();
00040 
00041 
00042                 // Data Flow enums:
00043                 globals->setValue( new Constant<Logger::LogLevel>("Never",Logger::Never) );
00044                 globals->setValue( new Constant<Logger::LogLevel>("Error",Logger::Error) );
00045                 globals->setValue( new Constant<Logger::LogLevel>("Fatal",Logger::Fatal) );
00046                 globals->setValue( new Constant<Logger::LogLevel>("Critical",Logger::Critical) );
00047                 globals->setValue( new Constant<Logger::LogLevel>("Warning",Logger::Warning) );
00048                 globals->setValue( new Constant<Logger::LogLevel>("Info",Logger::Info) );
00049                 globals->setValue( new Constant<Logger::LogLevel>("Debug",Logger::Debug) );
00050                 globals->setValue( new Constant<Logger::LogLevel>("RealTime",Logger::RealTime) );
00051             }
00052         }
00053 
00054         void println(const std::string& arg)
00055         {
00056             std::cout << arg << std::endl;
00057         }
00058         void printerr(const std::string& arg)
00059         {
00060             std::cerr << arg << std::endl;
00061         }
00062         void printlog(Logger::LogLevel level, const std::string& arg)
00063         {
00064             log(LoggerLevel(level)) << arg <<endlog();
00065         }
00066     };
00067 }
00068 
00069 ORO_SERVICE_NAMED_PLUGIN( OCL::PrintService, "print")
00070 


ocl
Author(s): OCL Development Team
autogenerated on Mon Sep 14 2015 14:21:46