OpenRTM-aist  2.0.1
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 
181  virtual ~PreComponentActionListener();
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 
348  virtual ~PostComponentActionListener();
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 
458  virtual ~PortActionListener();
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 
669  void removeListener(PreComponentActionListener* listener);
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 
773  void removeListener(PostComponentActionListener* listener);
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:
838  virtual ~PortActionListenerHolder();
839 
861  void addListener(PortActionListener* listener, bool autoclean);
862 
880  void removeListener(PortActionListener* listener);
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 
985  void removeListener(ExecutionContextActionListener* listener);
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:
1069  bool addListener(PreComponentActionListenerType type, PreComponentActionListener* listener, bool autoclean);
1095  bool addListener(PostComponentActionListenerType type, PostComponentActionListener* listener, bool autoclean);
1121  bool addListener(PortActionListenerType type, PortActionListener* listener, bool autoclean);
1147  bool addListener(ExecutionContextActionListenerType type, ExecutionContextActionListener* listener, bool autoclean);
1170  bool removeListener(PreComponentActionListenerType type, PreComponentActionListener* listener);
1193  bool removeListener(PostComponentActionListenerType type, PostComponentActionListener* listener);
1216  bool removeListener(PortActionListenerType type, PortActionListener* listener);
1239  bool removeListener(ExecutionContextActionListenerType type, ExecutionContextActionListener* listener);
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
static const char * toString(PortActionListenerType type)
PreComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:436
PreComponentActionListener ホルダクラス
Definition: ComponentActionListener.h:607
RTコンポーネント
ExecutionContextActionListener ホルダクラス
Definition: ComponentActionListener.h:924
PortActionListener ホルダクラス
Definition: ComponentActionListener.h:819
PreComponentActionListenerType
PreComponentActionListener のタイプ
Definition: ComponentActionListener.h:59
static const char * toString(ExecutionContextActionListenerType type)
PreComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:546
bool notify(PortActionListenerType type, const RTC::PortProfile &pprofile)
リスナーへ通知する
Definition: ComponentActionListener.h:1320
PortActionListenerType
PortActionListener のタイプ
Definition: ComponentActionListener.h:383
PreComponentActionListener クラス
Definition: ComponentActionListener.h:122
Connector base class
ExecutionContextHandle_t UniqueId
Definition: ComponentActionListener.h:34
static const char * toString(PostComponentActionListenerType type)
PostComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:315
bool notify(PostComponentActionListenerType type, UniqueId ec_id, ReturnCode_t ret)
リスナーへ通知する
Definition: ComponentActionListener.h:1291
ComponentActionListeners クラス
Definition: ComponentActionListener.h:1025
PostComponentActionListener ホルダクラス
Definition: ComponentActionListener.h:712
bool notify(ExecutionContextActionListenerType type, UniqueId ec_id)
リスナーへ通知する
Definition: ComponentActionListener.h:1349
static const char * toString(PreComponentActionListenerType type)
PreComponentActionListenerType を文字列に変換
Definition: ComponentActionListener.h:148
bool notify(PreComponentActionListenerType type, UniqueId ec_id)
リスナーへ通知する
Definition: ComponentActionListener.h:1260
RTComponent header
PostComponentActionListenerType
PostCompoenntActionListener のタイプ
Definition: ComponentActionListener.h:225
PortActionListener クラス
Definition: ComponentActionListener.h:410
ExecutionContextActionListenerType
ExecutionContextActionListener のタイプ
Definition: ComponentActionListener.h:493
PostComponentActionListener クラス
Definition: ComponentActionListener.h:289
ExecutionContextActionListener クラス
Definition: ComponentActionListener.h:520