MyServiceConsumer.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00010 #ifndef MYSERVICECONSUMER_H
00011 #define MYSERVICECONSUMER_H
00012 
00013 #include <rtm/idl/BasicDataTypeSkel.h>
00014 #include <rtm/Manager.h>
00015 #include <rtm/DataFlowComponentBase.h>
00016 #include <rtm/CorbaPort.h>
00017 #include <rtm/DataInPort.h>
00018 #include <rtm/DataOutPort.h>
00019 #include <iostream>
00020 #include <coil/Async.h>
00021 
00022 // Service implementation headers
00023 // <rtc-template block="service_impl_h">
00024 
00025 // </rtc-template>
00026 
00027 // Service Consumer stub headers
00028 // <rtc-template block="consumer_stub_h">
00029 #include "MyServiceStub.h"
00030 
00031 // </rtc-template>
00032 
00033 using namespace RTC;
00034 
00035 class MyServiceConsumer
00036   : public RTC::DataFlowComponentBase
00037 {
00038  public:
00039   MyServiceConsumer(RTC::Manager* manager);
00040   ~MyServiceConsumer();
00041 
00042   // The initialize action (on CREATED->ALIVE transition)
00043   // formaer rtc_init_entry() 
00044   virtual RTC::ReturnCode_t onInitialize();
00045 
00046   // The finalize action (on ALIVE->END transition)
00047   // formaer rtc_exiting_entry()
00048   // virtual RTC::ReturnCode_t onFinalize();
00049 
00050   // The startup action when ExecutionContext startup
00051   // former rtc_starting_entry()
00052   // virtual RTC::ReturnCode_t onStartup(RTC::UniqueId ec_id);
00053 
00054   // The shutdown action when ExecutionContext stop
00055   // former rtc_stopping_entry()
00056   // virtual RTC::ReturnCode_t onShutdown(RTC::UniqueId ec_id);
00057 
00058   // The activated action (Active state entry action)
00059   // former rtc_active_entry()
00060   // virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id);
00061 
00062   // The deactivated action (Active state exit action)
00063   // former rtc_active_exit()
00064   // virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id);
00065 
00066   // The execution action that is invoked periodically
00067   // former rtc_active_do()
00068   virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id);
00069 
00070   // The aborting action when main logic error occurred.
00071   // former rtc_aborting_entry()
00072   // virtual RTC::ReturnCode_t onAborting(RTC::UniqueId ec_id);
00073 
00074   // The error action in ERROR state
00075   // former rtc_error_do()
00076   // virtual RTC::ReturnCode_t onError(RTC::UniqueId ec_id);
00077 
00078   // The reset action that is invoked resetting
00079   // This is same but different the former rtc_init_entry()
00080   // virtual RTC::ReturnCode_t onReset(RTC::UniqueId ec_id);
00081   
00082   // The state update action that is invoked after onExecute() action
00083   // no corresponding operation exists in OpenRTm-aist-0.2.0
00084   // virtual RTC::ReturnCode_t onStateUpdate(RTC::UniqueId ec_id);
00085 
00086   // The action that is invoked when execution context's rate is changed
00087   // no corresponding operation exists in OpenRTm-aist-0.2.0
00088   // virtual RTC::ReturnCode_t onRateChanged(RTC::UniqueId ec_id);
00089 
00090 
00091  protected:
00092   // DataInPort declaration
00093   // <rtc-template block="inport_declare">
00094   
00095   // </rtc-template>
00096 
00097 
00098   // DataOutPort declaration
00099   // <rtc-template block="outport_declare">
00100   
00101   // </rtc-template>
00102 
00103   // CORBA Port declaration
00104   // <rtc-template block="corbaport_declare">
00105   RTC::CorbaPort m_MyServicePort;
00106   
00107   // </rtc-template>
00108 
00109   // Service declaration
00110   // <rtc-template block="service_declare">
00111   
00112   // </rtc-template>
00113 
00114   // Consumer declaration
00115   // <rtc-template block="consumer_declare">
00116   RTC::CorbaConsumer<SimpleService::MyService> m_myservice0;
00117   
00118   // </rtc-template>
00119 
00120   class set_value_functor
00121   {
00122   public:
00123     set_value_functor(CORBA::Float val) : m_val(val) {}
00124 
00125     void operator()(RTC::CorbaConsumer<SimpleService::MyService>* obj)
00126     {
00127       try
00128         {
00129           if( CORBA::is_nil((*obj).operator->()) )
00130             {
00131               std::cout << "No service connected." << std::endl;
00132             }
00133           else
00134             {
00135               (*obj)->set_value(m_val);
00136             }
00137         }
00138       catch (const CORBA::INV_OBJREF &)
00139         {
00140         }
00141       catch (const CORBA::OBJECT_NOT_EXIST &)
00142         {
00143         }
00144       catch (const CORBA::OBJ_ADAPTER &)
00145         {
00146         }
00147       catch (...)
00148         {
00149         }
00150     }
00151     CORBA::Float m_val;
00152   };
00153 
00154   class echo_functor
00155   {
00156   public:
00157     echo_functor(std::string msg, std::string& result)
00158       : m_msg(msg), m_result(result) {}
00159     void operator()(RTC::CorbaConsumer<SimpleService::MyService>* obj)
00160     {
00161       try
00162         {
00163           if( CORBA::is_nil((*obj).operator->()) )
00164             {
00165               std::cout << "No service connected." << std::endl;
00166             }
00167           else
00168             {
00169               m_result = (*obj)->echo(m_msg.c_str());
00170             }
00171         }
00172       catch (const CORBA::INV_OBJREF &)
00173         {
00174         }
00175       catch (const CORBA::OBJECT_NOT_EXIST &)
00176         {
00177         }
00178       catch (const CORBA::OBJ_ADAPTER &)
00179         {
00180         }
00181       catch (...)
00182         {
00183         }
00184     }
00185     std::string m_msg;
00186     std::string& m_result;
00187   };
00188  private:
00189   coil::Async* async_set_value;
00190   coil::Async* async_echo;
00191   std::string m_result;
00192 
00193   template <class T>
00194   struct seq_print
00195   {
00196     seq_print() : m_cnt(0) {};
00197     void operator()(T val)
00198     {
00199       std::cout << m_cnt << ": " << val << std::endl;
00200       ++m_cnt;
00201     }
00202     int m_cnt;
00203   };
00204 
00205 };
00206 
00207 
00208 extern "C"
00209 {
00210   DLL_EXPORT void MyServiceConsumerInit(RTC::Manager* manager);
00211 };
00212 
00213 #endif // MYSERVICECONSUMER_H


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:05