ComponentActionListener.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00019 #ifndef RTC_COMPONENTACTIONLISTENER_H
00020 #define RTC_COMPONENTACTIONLISTENER_H
00021 
00022 #include <vector>
00023 #include <utility>
00024 #include <coil/Mutex.h>
00025 #include <coil/Guard.h>
00026 #include <rtm/RTC.h>
00027 #include <rtm/idl/RTCSkel.h>
00028 #include <rtm/ConnectorBase.h>
00029 
00030 namespace RTC
00031 {
00032   typedef ExecutionContextHandle_t UniqueId;
00033   //============================================================
00057   enum PreComponentActionListenerType
00058     {
00059       PRE_ON_INITIALIZE,
00060       PRE_ON_FINALIZE,
00061       PRE_ON_STARTUP,
00062       PRE_ON_SHUTDOWN,
00063       PRE_ON_ACTIVATED,
00064       PRE_ON_DEACTIVATED,
00065       PRE_ON_ABORTING,
00066       PRE_ON_ERROR,
00067       PRE_ON_RESET,
00068       PRE_ON_EXECUTE,
00069       PRE_ON_STATE_UPDATE,
00070       PRE_ON_RATE_CHANGED,
00071       PRE_COMPONENT_ACTION_LISTENER_NUM
00072     };
00073 
00120   class PreComponentActionListener
00121   {
00122   public:
00146     static const char* toString(PreComponentActionListenerType type)
00147     {
00148       static const char* typeString[] =
00149         {
00150           "PRE_ON_INITIALIZE",
00151           "PRE_ON_FINALIZE",
00152           "PRE_ON_STARTUP",
00153           "PRE_ON_SHUTDOWN",
00154           "PRE_ON_ACTIVATED",
00155           "PRE_ON_DEACTIVATED",
00156           "PRE_ON_ABORTING",
00157           "PRE_ON_ERROR",
00158           "PRE_ON_RESET",
00159           "PRE_ON_EXECUTE",
00160           "PRE_ON_STATE_UPDATE",
00161           "PRE_ON_RATE_CHANGED",
00162           "PRE_COMPONENT_ACTION_LISTENER_NUM"
00163         };
00164       if (type < PRE_COMPONENT_ACTION_LISTENER_NUM) { return typeString[type]; }
00165       return "";
00166     }
00167 
00175     virtual ~PreComponentActionListener();
00176 
00192     virtual void operator()(UniqueId ec_id) = 0;
00193   };
00194 
00195 
00196   //============================================================
00219   enum PostComponentActionListenerType
00220     {
00221       POST_ON_INITIALIZE,
00222       POST_ON_FINALIZE,
00223       POST_ON_STARTUP,
00224       POST_ON_SHUTDOWN,
00225       POST_ON_ACTIVATED,
00226       POST_ON_DEACTIVATED,
00227       POST_ON_ABORTING,
00228       POST_ON_ERROR,
00229       POST_ON_RESET,
00230       POST_ON_EXECUTE,
00231       POST_ON_STATE_UPDATE,
00232       POST_ON_RATE_CHANGED,
00233       POST_COMPONENT_ACTION_LISTENER_NUM
00234     };
00235 
00236 
00283   class PostComponentActionListener
00284   {
00285   public:
00309     static const char* toString(PostComponentActionListenerType type)
00310     {
00311       static const char* typeString[] =
00312         {
00313           "POST_ON_INITIALIZE",
00314           "POST_ON_FINALIZE",
00315           "POST_ON_STARTUP",
00316           "POST_ON_SHUTDOWN",
00317           "POST_ON_ACTIVATED",
00318           "POST_ON_DEACTIVATED",
00319           "POST_ON_ABORTING",
00320           "POST_ON_ERROR",
00321           "POST_ON_RESET",
00322           "POST_ON_EXECUTE",
00323           "POST_ON_STATE_UPDATE",
00324           "POST_ON_RATE_CHANGED",
00325           "POST_COMPONENT_ACTION_LISTENER_NUM"
00326         };
00327       if (type < POST_COMPONENT_ACTION_LISTENER_NUM)
00328         {
00329           return typeString[type];
00330         }
00331       return "";
00332     }
00333 
00341     virtual ~PostComponentActionListener();
00342 
00358     virtual void operator()(UniqueId ec_id,
00359                             ReturnCode_t ret) = 0;
00360   };
00361 
00362   //============================================================
00376   enum PortActionListenerType
00377     {
00378       ADD_PORT,
00379       REMOVE_PORT,
00380       PORT_ACTION_LISTENER_NUM
00381     };
00382 
00403   class PortActionListener
00404   {
00405   public:
00429     static const char* toString(PortActionListenerType type)
00430     {
00431       static const char* typeString[] =
00432         {
00433           "ADD_PORT",
00434           "REMOVE_PORT",
00435           "PORT_ACTION_LISTENER_NUM"
00436         };
00437       if (type < PORT_ACTION_LISTENER_NUM) { return typeString[type]; }
00438       return "";
00439     }
00440 
00448     virtual ~PortActionListener();
00449 
00465     virtual void operator()(const ::RTC::PortProfile& pprof) = 0;
00466   };
00467 
00468 
00469   //============================================================
00483   enum ExecutionContextActionListenerType
00484     {
00485       EC_ATTACHED,
00486       EC_DETACHED,
00487       EC_ACTION_LISTENER_NUM
00488     };
00489 
00510   class ExecutionContextActionListener
00511   {
00512   public:
00536     static const char* toString(ExecutionContextActionListenerType type)
00537     {
00538       static const char* typeString[] =
00539         {
00540           "ATTACH_EC",
00541           "DETACH_ECT",
00542           "EC_ACTION_LISTENER_NUM"
00543         };
00544       if (type < EC_ACTION_LISTENER_NUM) { return typeString[type]; }
00545       return "";
00546     }
00547 
00555     virtual ~ExecutionContextActionListener();
00556 
00572     virtual void operator()(UniqueId ec_id) = 0;
00573   };
00574 
00575 
00576 
00577   //============================================================
00594   class PreComponentActionListenerHolder
00595   {
00596     typedef std::pair<PreComponentActionListener*, bool> Entry;
00597     typedef coil::Guard<coil::Mutex> Guard;
00598   public:
00606     PreComponentActionListenerHolder();
00607     
00615     virtual ~PreComponentActionListenerHolder();
00616     
00638     void addListener(PreComponentActionListener* listener, bool autoclean);
00639     
00657     void removeListener(PreComponentActionListener* listener);
00658 
00676     void notify(UniqueId ec_id);
00677       
00678   private:
00679     std::vector<Entry> m_listeners;
00680     coil::Mutex m_mutex;
00681   };
00682 
00683 
00700   class PostComponentActionListenerHolder
00701   {
00702     typedef std::pair<PostComponentActionListener*, bool> Entry;
00703     typedef coil::Guard<coil::Mutex> Guard;
00704   public:
00712     PostComponentActionListenerHolder();
00720     virtual ~PostComponentActionListenerHolder();
00721     
00743     void addListener(PostComponentActionListener* listener, bool autoclean);
00744     
00762     void removeListener(PostComponentActionListener* listener);
00763     
00783     void notify(UniqueId ec_id, ReturnCode_t ret);
00784     
00785   private:
00786     std::vector<Entry> m_listeners;
00787     coil::Mutex m_mutex;
00788   };
00789 
00790 
00791   //============================================================
00808   class PortActionListenerHolder
00809   {
00810     typedef std::pair<PortActionListener*, bool> Entry;
00811     typedef coil::Guard<coil::Mutex> Guard;
00812   public:
00820     PortActionListenerHolder();
00828     virtual ~PortActionListenerHolder();
00829     
00851     void addListener(PortActionListener* listener, bool autoclean);
00852     
00870     void removeListener(PortActionListener* listener);
00871     
00891     void notify(const RTC::PortProfile& pprofile);
00892     
00893   private:
00894     std::vector<Entry> m_listeners;
00895     coil::Mutex m_mutex;
00896   };
00897 
00914   class ExecutionContextActionListenerHolder
00915   {
00916     typedef std::pair<ExecutionContextActionListener*, bool> Entry;
00917     typedef coil::Guard<coil::Mutex> Guard;
00918   public:
00926     ExecutionContextActionListenerHolder();
00934     virtual ~ExecutionContextActionListenerHolder();
00935     
00957     void addListener(ExecutionContextActionListener* listener, bool autoclean);
00958     
00976     void removeListener(ExecutionContextActionListener* listener);
00977     
00997     void notify(UniqueId ec_id);
00998     
00999   private:
01000     std::vector<Entry> m_listeners;
01001     coil::Mutex m_mutex;
01002   };
01003 
01004 
01018   class ComponentActionListeners
01019   {
01020   public:
01030     PreComponentActionListenerHolder 
01031     preaction_[PRE_COMPONENT_ACTION_LISTENER_NUM];
01041     PostComponentActionListenerHolder 
01042     postaction_[POST_COMPONENT_ACTION_LISTENER_NUM];
01052     PortActionListenerHolder
01053     portaction_[PORT_ACTION_LISTENER_NUM];
01063    ExecutionContextActionListenerHolder
01064     ecaction_[EC_ACTION_LISTENER_NUM];
01065   };
01066 
01067 
01068 }; // namespace RTC
01069 
01070 #endif // RTC_COMPONENTACTIONLISTENER_H


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