OpenRTM-aist  2.1.0
ComponentActionListener.h
[詳解]
1 // -*- C++ -*-
19 #ifndef RTC_COMPONENTACTIONLISTENER_H
20 #define RTC_COMPONENTACTIONLISTENER_H
21 
22 #include <mutex>
23 
24 #include <rtm/RTC.h>
25 #include <rtm/idl/RTCSkel.h>
26 #include <rtm/ConnectorBase.h>
27 
28 #include <vector>
29 #include <utility>
30 #include <array>
31 
32 namespace RTC
33 {
34  using UniqueId = ExecutionContextHandle_t;
35  //============================================================
59  enum class PreComponentActionListenerType : uint8_t
60  {
74  };
75 
123  {
124  public:
148  static const char* toString(PreComponentActionListenerType type)
149  {
150  if (type <
152  {
153  static const char* const typeString[] =
154  {
155  "PRE_ON_INITIALIZE",
156  "PRE_ON_FINALIZE",
157  "PRE_ON_STARTUP",
158  "PRE_ON_SHUTDOWN",
159  "PRE_ON_ACTIVATED",
160  "PRE_ON_DEACTIVATED",
161  "PRE_ON_ABORTING",
162  "PRE_ON_ERROR",
163  "PRE_ON_RESET",
164  "PRE_ON_EXECUTE",
165  "PRE_ON_STATE_UPDATE",
166  "PRE_ON_RATE_CHANGED",
167  "PRE_COMPONENT_ACTION_LISTENER_NUM"
168  };
169  return typeString[static_cast<uint8_t>(type)];
170  }
171  return "";
172  }
173 
182 
198  virtual void operator()(UniqueId ec_id) = 0;
199  };
200 
201 
202  //============================================================
225  enum class PostComponentActionListenerType : uint8_t
226  {
240  };
241 
242 
290  {
291  public:
315  static const char* toString(PostComponentActionListenerType type)
316  {
317  if (type <
319  {
320  static const char* const typeString[] =
321  {
322  "POST_ON_INITIALIZE",
323  "POST_ON_FINALIZE",
324  "POST_ON_STARTUP",
325  "POST_ON_SHUTDOWN",
326  "POST_ON_ACTIVATED",
327  "POST_ON_DEACTIVATED",
328  "POST_ON_ABORTING",
329  "POST_ON_ERROR",
330  "POST_ON_RESET",
331  "POST_ON_EXECUTE",
332  "POST_ON_STATE_UPDATE",
333  "POST_ON_RATE_CHANGED",
334  "POST_COMPONENT_ACTION_LISTENER_NUM"
335  };
336  return typeString[static_cast<uint8_t>(type)];
337  }
338  return "";
339  }
340 
349 
365  virtual void operator()(UniqueId ec_id,
366  ReturnCode_t ret) = 0;
367  };
368 
369  //============================================================
383  enum class PortActionListenerType : uint8_t
384  {
385  ADD_PORT,
386  REMOVE_PORT,
388  };
389 
411  {
412  public:
436  static const char* toString(PortActionListenerType type)
437  {
439  {
440  static const char* const typeString[] =
441  {
442  "ADD_PORT",
443  "REMOVE_PORT",
444  "PORT_ACTION_LISTENER_NUM"
445  };
446  return typeString[static_cast<uint8_t>(type)];
447  }
448  return "";
449  }
450 
459 
475  virtual void operator()(const ::RTC::PortProfile& pprof) = 0;
476  };
477 
478 
479  //============================================================
494  {
495  EC_ATTACHED,
496  EC_DETACHED,
498  };
499 
521  {
522  public:
547  {
549  {
550  static const char* const typeString[] =
551  {
552  "ATTACH_EC",
553  "DETACH_ECT",
554  "EC_ACTION_LISTENER_NUM"
555  };
556  return typeString[static_cast<uint8_t>(type)];
557  }
558  return "";
559  }
560 
569 
585  virtual void operator()(UniqueId ec_id) = 0;
586  };
587 
588 
589 
590  //============================================================
608  {
609  using Entry = std::pair<PreComponentActionListener*, bool>;
610  public:
619 
628 
650  void addListener(PreComponentActionListener* listener, bool autoclean);
651 
670 
688  void notify(UniqueId ec_id);
689 
690  private:
691  std::vector<Entry> m_listeners;
692  std::mutex m_mutex;
693  };
694 
695 
713  {
714  using Entry = std::pair<PostComponentActionListener*, bool>;
715  public:
732 
754  void addListener(PostComponentActionListener* listener, bool autoclean);
755 
774 
794  void notify(UniqueId ec_id, ReturnCode_t ret);
795 
796  private:
797  std::vector<Entry> m_listeners;
798  std::mutex m_mutex;
799  };
800 
801 
802  //============================================================
820  {
821  using Entry = std::pair<PortActionListener*, bool>;
822  public:
839 
861  void addListener(PortActionListener* listener, bool autoclean);
862 
881 
901  void notify(const RTC::PortProfile& pprofile);
902 
903  private:
904  std::vector<Entry> m_listeners;
905  std::mutex m_mutex;
906  };
907 
925  {
926  using Entry = std::pair<ExecutionContextActionListener*, bool>;
927  public:
944 
966  void addListener(ExecutionContextActionListener* listener, bool autoclean);
967 
986 
1004  void notify(UniqueId ec_id);
1005 
1006  private:
1007  std::vector<Entry> m_listeners;
1008  std::mutex m_mutex;
1009  };
1010 
1011 
1026  {
1027  public:
1121  bool addListener(PortActionListenerType type, PortActionListener* listener, bool autoclean);
1261  {
1262  if (static_cast<uint8_t>(type) < preaction_.size())
1263  {
1264  preaction_[static_cast<uint8_t>(type)].notify(ec_id);
1265  return true;
1266  }
1267  return false;
1268  }
1291  inline bool notify(PostComponentActionListenerType type, UniqueId ec_id, ReturnCode_t ret)
1292  {
1293  if (static_cast<uint8_t>(type) < postaction_.size())
1294  {
1295  postaction_[static_cast<uint8_t>(type)].notify(ec_id, ret);
1296  return true;
1297  }
1298  return false;
1299  }
1320  inline bool notify(PortActionListenerType type, const RTC::PortProfile& pprofile)
1321  {
1322  if (static_cast<uint8_t>(type) < portaction_.size())
1323  {
1324  portaction_[static_cast<uint8_t>(type)].notify(pprofile);
1325  return true;
1326  }
1327  return false;
1328  }
1350  {
1351  if (static_cast<uint8_t>(type) < ecaction_.size())
1352  {
1353  ecaction_[static_cast<uint8_t>(type)].notify(ec_id);
1354  return true;
1355  }
1356  return false;
1357  }
1358  private:
1368  std::array<PreComponentActionListenerHolder, static_cast<uint8_t>(PreComponentActionListenerType::PRE_COMPONENT_ACTION_LISTENER_NUM)> preaction_;
1378  std::array<PostComponentActionListenerHolder, static_cast<uint8_t>(PostComponentActionListenerType::POST_COMPONENT_ACTION_LISTENER_NUM)> postaction_;
1388  std::array<PortActionListenerHolder, static_cast<uint8_t>(PortActionListenerType::PORT_ACTION_LISTENER_NUM)> portaction_;
1398  std::array<ExecutionContextActionListenerHolder, static_cast<uint8_t>(ExecutionContextActionListenerType::EC_ACTION_LISTENER_NUM)> ecaction_;
1399  };
1400 
1401 
1402 } // namespace RTC
1403 
1404 #endif // RTC_COMPONENTACTIONLISTENER_H
Connector base class
RTComponent header
ComponentActionListeners クラス
Definition: ComponentActionListener.h:1026
bool removeListener(PostComponentActionListenerType type, PostComponentActionListener *listener)
リスナーの削除
bool removeListener(PortActionListenerType type, PortActionListener *listener)
リスナーの削除
ComponentActionListeners()
コンストラクタ
bool addListener(ExecutionContextActionListenerType type, ExecutionContextActionListener *listener, bool autoclean)
リスナーの追加
bool notify(ExecutionContextActionListenerType type, UniqueId ec_id)
リスナーへ通知する
Definition: ComponentActionListener.h:1349
bool addListener(PortActionListenerType type, PortActionListener *listener, bool autoclean)
リスナーの追加
bool removeListener(ExecutionContextActionListenerType type, ExecutionContextActionListener *listener)
リスナーの削除
bool notify(PostComponentActionListenerType type, UniqueId ec_id, ReturnCode_t ret)
リスナーへ通知する
Definition: ComponentActionListener.h:1291
bool removeListener(PreComponentActionListenerType type, PreComponentActionListener *listener)
リスナーの削除
~ComponentActionListeners()
デストラクタ
bool addListener(PostComponentActionListenerType type, PostComponentActionListener *listener, bool autoclean)
リスナーの追加
bool addListener(PreComponentActionListenerType type, PreComponentActionListener *listener, bool autoclean)
リスナーの追加
bool notify(PortActionListenerType type, const RTC::PortProfile &pprofile)
リスナーへ通知する
Definition: ComponentActionListener.h:1320
bool notify(PreComponentActionListenerType type, UniqueId ec_id)
リスナーへ通知する
Definition: ComponentActionListener.h:1260
ExecutionContextActionListener ホルダクラス
Definition: ComponentActionListener.h:925
ExecutionContextActionListenerHolder()
コンストラクタ
void removeListener(ExecutionContextActionListener *listener)
リスナーの削除
void addListener(ExecutionContextActionListener *listener, bool autoclean)
リスナーの追加
virtual ~ExecutionContextActionListenerHolder()
デストラクタ
void notify(UniqueId ec_id)
リスナーへ通知する
ExecutionContextActionListener クラス
Definition: ComponentActionListener.h:521
static const char * toString(ExecutionContextActionListenerType type)
PreComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:546
virtual ~ExecutionContextActionListener()
デストラクタ
virtual void operator()(UniqueId ec_id)=0
仮想コールバック関数
PortActionListener ホルダクラス
Definition: ComponentActionListener.h:820
PortActionListenerHolder()
コンストラクタ
virtual ~PortActionListenerHolder()
デストラクタ
void removeListener(PortActionListener *listener)
リスナーの削除
void notify(const RTC::PortProfile &pprofile)
リスナーへ通知する
void addListener(PortActionListener *listener, bool autoclean)
リスナーの追加
PortActionListener クラス
Definition: ComponentActionListener.h:411
static const char * toString(PortActionListenerType type)
PreComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:436
virtual void operator()(const ::RTC::PortProfile &pprof)=0
仮想コールバック関数
virtual ~PortActionListener()
デストラクタ
PostComponentActionListener ホルダクラス
Definition: ComponentActionListener.h:713
void addListener(PostComponentActionListener *listener, bool autoclean)
リスナーの追加
PostComponentActionListenerHolder()
コンストラクタ
void notify(UniqueId ec_id, ReturnCode_t ret)
リスナーへ通知する
virtual ~PostComponentActionListenerHolder()
デストラクタ
void removeListener(PostComponentActionListener *listener)
リスナーの削除
PostComponentActionListener クラス
Definition: ComponentActionListener.h:290
virtual ~PostComponentActionListener()
デストラクタ
virtual void operator()(UniqueId ec_id, ReturnCode_t ret)=0
仮想コールバック関数
static const char * toString(PostComponentActionListenerType type)
PostComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:315
PreComponentActionListener ホルダクラス
Definition: ComponentActionListener.h:608
void removeListener(PreComponentActionListener *listener)
リスナーの削除
PreComponentActionListenerHolder()
コンストラクタ
void notify(UniqueId ec_id)
リスナーへ通知する
void addListener(PreComponentActionListener *listener, bool autoclean)
リスナーの追加
virtual ~PreComponentActionListenerHolder()
デストラクタ
PreComponentActionListener クラス
Definition: ComponentActionListener.h:123
virtual void operator()(UniqueId ec_id)=0
仮想コールバック関数
virtual ~PreComponentActionListener()
デストラクタ
static const char * toString(PreComponentActionListenerType type)
PreComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:148
RTコンポーネント
ExecutionContextActionListenerType
ExecutionContextActionListener のタイプ
Definition: ComponentActionListener.h:494
ExecutionContextHandle_t UniqueId
Definition: ComponentActionListener.h:34
PreComponentActionListenerType
PreComponentActionListener のタイプ
Definition: ComponentActionListener.h:60
PortActionListenerType
PortActionListener のタイプ
Definition: ComponentActionListener.h:384
PostComponentActionListenerType
PostCompoenntActionListener のタイプ
Definition: ComponentActionListener.h:226