00001
00019 #ifndef RTC_COMPONENTACTIONLISTENER_H
00020 #define RTC_COMPONENTACTIONLISTENER_H
00021
00022 #include <vector>
00023 #include <utility>
00024 #include <rtm/RTC.h>
00025 #include <rtm/idl/RTCSkel.h>
00026 #include <rtm/ConnectorBase.h>
00027
00028 namespace RTC
00029 {
00030 typedef ExecutionContextHandle_t UniqueId;
00031
00055 enum PreComponentActionListenerType
00056 {
00057 PRE_ON_INITIALIZE,
00058 PRE_ON_FINALIZE,
00059 PRE_ON_STARTUP,
00060 PRE_ON_SHUTDOWN,
00061 PRE_ON_ACTIVATED,
00062 PRE_ON_DEACTIVATED,
00063 PRE_ON_ABORTING,
00064 PRE_ON_ERROR,
00065 PRE_ON_RESET,
00066 PRE_ON_EXECUTE,
00067 PRE_ON_STATE_UPDATE,
00068 PRE_ON_RATE_CHANGED,
00069 PRE_COMPONENT_ACTION_LISTENER_NUM
00070 };
00071
00118 class PreComponentActionListener
00119 {
00120 public:
00144 static const char* toString(PreComponentActionListenerType type)
00145 {
00146 static const char* typeString[] =
00147 {
00148 "PRE_ON_INITIALIZE",
00149 "PRE_ON_FINALIZE",
00150 "PRE_ON_STARTUP",
00151 "PRE_ON_SHUTDOWN",
00152 "PRE_ON_ACTIVATED",
00153 "PRE_ON_DEACTIVATED",
00154 "PRE_ON_ABORTING",
00155 "PRE_ON_ERROR",
00156 "PRE_ON_RESET",
00157 "PRE_ON_EXECUTE",
00158 "PRE_ON_STATE_UPDATE",
00159 "PRE_ON_RATE_CHANGED",
00160 "PRE_COMPONENT_ACTION_LISTENER_NUM"
00161 };
00162 if (type < PRE_COMPONENT_ACTION_LISTENER_NUM) { return typeString[type]; }
00163 return "";
00164 }
00165
00173 virtual ~PreComponentActionListener();
00174
00190 virtual void operator()(UniqueId ec_id) = 0;
00191 };
00192
00193
00194
00217 enum PostComponentActionListenerType
00218 {
00219 POST_ON_INITIALIZE,
00220 POST_ON_FINALIZE,
00221 POST_ON_STARTUP,
00222 POST_ON_SHUTDOWN,
00223 POST_ON_ACTIVATED,
00224 POST_ON_DEACTIVATED,
00225 POST_ON_ABORTING,
00226 POST_ON_ERROR,
00227 POST_ON_RESET,
00228 POST_ON_EXECUTE,
00229 POST_ON_STATE_UPDATE,
00230 POST_ON_RATE_CHANGED,
00231 POST_COMPONENT_ACTION_LISTENER_NUM
00232 };
00233
00234
00281 class PostComponentActionListener
00282 {
00283 public:
00307 static const char* toString(PostComponentActionListenerType type)
00308 {
00309 static const char* typeString[] =
00310 {
00311 "POST_ON_INITIALIZE",
00312 "POST_ON_FINALIZE",
00313 "POST_ON_STARTUP",
00314 "POST_ON_SHUTDOWN",
00315 "POST_ON_ACTIVATED",
00316 "POST_ON_DEACTIVATED",
00317 "POST_ON_ABORTING",
00318 "POST_ON_ERROR",
00319 "POST_ON_RESET",
00320 "POST_ON_EXECUTE",
00321 "POST_ON_STATE_UPDATE",
00322 "POST_ON_RATE_CHANGED",
00323 "POST_COMPONENT_ACTION_LISTENER_NUM"
00324 };
00325 if (type < POST_COMPONENT_ACTION_LISTENER_NUM)
00326 {
00327 return typeString[type];
00328 }
00329 return "";
00330 }
00331
00339 virtual ~PostComponentActionListener();
00340
00356 virtual void operator()(UniqueId ec_id,
00357 ReturnCode_t ret) = 0;
00358 };
00359
00360
00374 enum PortActionListenerType
00375 {
00376 ADD_PORT,
00377 REMOVE_PORT,
00378 PORT_ACTION_LISTENER_NUM
00379 };
00380
00401 class PortActionListener
00402 {
00403 public:
00427 static const char* toString(PortActionListenerType type)
00428 {
00429 static const char* typeString[] =
00430 {
00431 "ADD_PORT",
00432 "REMOVE_PORT",
00433 "PORT_ACTION_LISTENER_NUM"
00434 };
00435 if (type < PORT_ACTION_LISTENER_NUM) { return typeString[type]; }
00436 return "";
00437 }
00438
00446 virtual ~PortActionListener();
00447
00463 virtual void operator()(const ::RTC::PortProfile& pprof) = 0;
00464 };
00465
00466
00467
00481 enum ExecutionContextActionListenerType
00482 {
00483 EC_ATTACHED,
00484 EC_DETACHED,
00485 EC_ACTION_LISTENER_NUM
00486 };
00487
00508 class ExecutionContextActionListener
00509 {
00510 public:
00534 static const char* toString(ExecutionContextActionListenerType type)
00535 {
00536 static const char* typeString[] =
00537 {
00538 "ATTACH_EC",
00539 "DETACH_ECT",
00540 "EC_ACTION_LISTENER_NUM"
00541 };
00542 if (type < EC_ACTION_LISTENER_NUM) { return typeString[type]; }
00543 return "";
00544 }
00545
00553 virtual ~ExecutionContextActionListener();
00554
00570 virtual void operator()(UniqueId ec_id) = 0;
00571 };
00572
00573
00574
00575
00592 class PreComponentActionListenerHolder
00593 {
00594 typedef std::pair<PreComponentActionListener*, bool> Entry;
00595 public:
00603 PreComponentActionListenerHolder();
00604
00612 virtual ~PreComponentActionListenerHolder();
00613
00635 void addListener(PreComponentActionListener* listener, bool autoclean);
00636
00654 void removeListener(PreComponentActionListener* listener);
00655
00673 void notify(UniqueId ec_id);
00674
00675 private:
00676 std::vector<Entry> m_listeners;
00677 };
00678
00679
00696 class PostComponentActionListenerHolder
00697 {
00698 typedef std::pair<PostComponentActionListener*, bool> Entry;
00699 public:
00707 PostComponentActionListenerHolder();
00715 virtual ~PostComponentActionListenerHolder();
00716
00738 void addListener(PostComponentActionListener* listener, bool autoclean);
00739
00757 void removeListener(PostComponentActionListener* listener);
00758
00778 void notify(UniqueId ec_id, ReturnCode_t ret);
00779
00780 private:
00781 std::vector<Entry> m_listeners;
00782 };
00783
00784
00785
00802 class PortActionListenerHolder
00803 {
00804 typedef std::pair<PortActionListener*, bool> Entry;
00805 public:
00813 PortActionListenerHolder();
00821 virtual ~PortActionListenerHolder();
00822
00844 void addListener(PortActionListener* listener, bool autoclean);
00845
00863 void removeListener(PortActionListener* listener);
00864
00884 void notify(const RTC::PortProfile& pprofile);
00885
00886 private:
00887 std::vector<Entry> m_listeners;
00888 };
00889
00906 class ExecutionContextActionListenerHolder
00907 {
00908 typedef std::pair<ExecutionContextActionListener*, bool> Entry;
00909 public:
00917 ExecutionContextActionListenerHolder();
00925 virtual ~ExecutionContextActionListenerHolder();
00926
00948 void addListener(ExecutionContextActionListener* listener, bool autoclean);
00949
00967 void removeListener(ExecutionContextActionListener* listener);
00968
00988 void notify(UniqueId ec_id);
00989
00990 private:
00991 std::vector<Entry> m_listeners;
00992 };
00993
00994
01008 class ComponentActionListeners
01009 {
01010 public:
01020 PreComponentActionListenerHolder
01021 preaction_[PRE_COMPONENT_ACTION_LISTENER_NUM];
01031 PostComponentActionListenerHolder
01032 postaction_[POST_COMPONENT_ACTION_LISTENER_NUM];
01042 PortActionListenerHolder
01043 portaction_[PORT_ACTION_LISTENER_NUM];
01053 ExecutionContextActionListenerHolder
01054 ecaction_[EC_ACTION_LISTENER_NUM];
01055 };
01056
01057
01058 };
01059
01060 #endif // RTC_COMPONENTACTIONLISTENER_H