DataLogger.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #ifndef DATA_LOGGER_H
00011 #define DATA_LOGGER_H
00012 
00013 #include <deque>
00014 #include <iomanip>
00015 
00016 #include <rtm/idl/BasicDataType.hh>
00017 #include <rtm/idl/ExtendedDataTypes.hh>
00018 #include "hrpsys/idl/HRPDataTypes.hh"
00019 #include <rtm/Manager.h>
00020 #include <rtm/DataFlowComponentBase.h>
00021 #include <rtm/CorbaPort.h>
00022 #include <rtm/DataInPort.h>
00023 #include <rtm/DataOutPort.h>
00024 #include <rtm/idl/BasicDataTypeSkel.h>
00025 #include <rtm/idl/ExtendedDataTypesSkel.h>
00026 
00027 // Service implementation headers
00028 // <rtc-template block="service_impl_h">
00029 #include "DataLoggerService_impl.h"
00030 
00031 // </rtc-template>
00032 
00033 // Service Consumer stub headers
00034 // <rtc-template block="consumer_stub_h">
00035 
00036 // </rtc-template>
00037 
00038 using namespace RTC;
00039 
00040 #define DEFAULT_MAX_LOG_LENGTH (200*20)
00041 
00042 class LoggerPortBase
00043 {
00044 public:
00045     LoggerPortBase() : m_maxLength(DEFAULT_MAX_LOG_LENGTH) {}
00046     virtual const char *name() = 0;
00047     virtual void clear() = 0;
00048     virtual void dumpLog(std::ostream& os, unsigned int precision = 0) = 0;
00049     virtual void log() = 0;
00050     void maxLength(unsigned int len) { m_maxLength = len; }
00051 protected:
00052     unsigned int m_maxLength;
00053 };
00054 
00058 class DataLogger
00059   : public RTC::DataFlowComponentBase
00060 {
00061  public:
00066   DataLogger(RTC::Manager* manager);
00070   virtual ~DataLogger();
00071 
00072   // The initialize action (on CREATED->ALIVE transition)
00073   // formaer rtc_init_entry()
00074   virtual RTC::ReturnCode_t onInitialize();
00075 
00076   // The finalize action (on ALIVE->END transition)
00077   // formaer rtc_exiting_entry()
00078   // virtual RTC::ReturnCode_t onFinalize();
00079 
00080   // The startup action when ExecutionContext startup
00081   // former rtc_starting_entry()
00082   // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id);
00083 
00084   // The shutdown action when ExecutionContext stop
00085   // former rtc_stopping_entry()
00086   // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id);
00087 
00088   // The activated action (Active state entry action)
00089   // former rtc_active_entry()
00090   virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00091 
00092   // The deactivated action (Active state exit action)
00093   // former rtc_active_exit()
00094   virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00095 
00096   // The execution action that is invoked periodically
00097   // former rtc_active_do()
00098   virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00099 
00100   // The aborting action when main logic error occurred.
00101   // former rtc_aborting_entry()
00102   // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id);
00103 
00104   // The error action in ERROR state
00105   // former rtc_error_do()
00106   // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id);
00107 
00108   // The reset action that is invoked resetting
00109   // This is same but different the former rtc_init_entry()
00110   // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id);
00111 
00112   // The state update action that is invoked after onExecute() action
00113   // no corresponding operation exists in OpenRTm-aist-0.2.0
00114   // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id);
00115 
00116   // The action that is invoked when execution context's rate is changed
00117   // no corresponding operation exists in OpenRTm-aist-0.2.0
00118   // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
00119   bool add(const char *i_type, const char *i_name);
00120   bool save(const char *i_basename);
00121   bool clear();
00122   void suspendLogging();
00123   void resumeLogging();
00124   void maxLength(unsigned int len);
00125 
00126   std::vector<LoggerPortBase *> m_ports;
00127 
00128  protected:
00129   // Configuration variable declaration
00130   // <rtc-template block="config_declare">
00131   
00132   // </rtc-template>
00133 
00134   TimedLong m_emergencySignal;
00135 
00136   // DataInPort declaration
00137   // <rtc-template block="inport_declare">
00138   InPort<TimedLong> m_emergencySignalIn;
00139   
00140   // </rtc-template>
00141 
00142   // DataOutPort declaration
00143   // <rtc-template block="outport_declare">
00144   
00145   // </rtc-template>
00146 
00147   // CORBA Port declaration
00148   // <rtc-template block="corbaport_declare">
00149   RTC::CorbaPort m_DataLoggerServicePort;
00150   
00151   // </rtc-template>
00152 
00153   // Service declaration
00154   // <rtc-template block="service_declare">
00155   DataLoggerService_impl m_service0;
00156   
00157   // </rtc-template>
00158 
00159   // Consumer declaration
00160   // <rtc-template block="consumer_declare">
00161   
00162   // </rtc-template>
00163 
00164  private:
00165   bool m_suspendFlag;
00166   coil::Mutex m_suspendFlagMutex;
00167   unsigned int m_log_precision;
00168   int dummy;
00169 };
00170 
00171 
00172 extern "C"
00173 {
00174   void DataLoggerInit(RTC::Manager* manager);
00175 };
00176 
00177 #endif // DATA_LOGGER_H


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:17