OpenRTM-aist  2.0.1
ComponentActionListener.h
Go to the documentation of this file.
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 
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 
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:
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 
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);
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
RTC::ComponentActionListeners::notify
bool notify(PostComponentActionListenerType type, UniqueId ec_id, ReturnCode_t ret)
Definition: ComponentActionListener.h:1291
RTC::PostComponentActionListenerHolder::PostComponentActionListenerHolder
PostComponentActionListenerHolder()
Constructor.
RTC::PostComponentActionListenerType::POST_ON_STARTUP
@ POST_ON_STARTUP
RTC::PreComponentActionListenerType::PRE_ON_ACTIVATED
@ PRE_ON_ACTIVATED
RTC::PostComponentActionListenerType::POST_COMPONENT_ACTION_LISTENER_NUM
@ POST_COMPONENT_ACTION_LISTENER_NUM
RTC::PostComponentActionListenerHolder
PostComponentActionListener holder class.
Definition: ComponentActionListener.h:712
RTC::ComponentActionListeners::~ComponentActionListeners
~ComponentActionListeners()
Destructor.
RTC::ExecutionContextActionListenerType::EC_DETACHED
@ EC_DETACHED
RTC::PostComponentActionListener::operator()
virtual void operator()(UniqueId ec_id, ReturnCode_t ret)=0
Virtual Callback function.
RTC::ExecutionContextActionListenerHolder::addListener
void addListener(ExecutionContextActionListener *listener, bool autoclean)
Add the listener.
RTC::PreComponentActionListener::~PreComponentActionListener
virtual ~PreComponentActionListener()
Destructor.
RTC::PostComponentActionListenerType::POST_ON_SHUTDOWN
@ POST_ON_SHUTDOWN
RTC::PreComponentActionListenerType::PRE_ON_SHUTDOWN
@ PRE_ON_SHUTDOWN
RTC::PreComponentActionListenerType::PRE_COMPONENT_ACTION_LISTENER_NUM
@ PRE_COMPONENT_ACTION_LISTENER_NUM
RTC::PreComponentActionListenerHolder::notify
void notify(UniqueId ec_id)
Notify listeners.
RTC::PortActionListener::~PortActionListener
virtual ~PortActionListener()
Destructor.
RTC::ExecutionContextActionListenerHolder::ExecutionContextActionListenerHolder
ExecutionContextActionListenerHolder()
Constructor.
RTC::PreComponentActionListenerType::PRE_ON_RESET
@ PRE_ON_RESET
RTC::PostComponentActionListenerType::POST_ON_ABORTING
@ POST_ON_ABORTING
RTC::PostComponentActionListenerHolder::notify
void notify(UniqueId ec_id, ReturnCode_t ret)
Notify listeners.
RTC::PostComponentActionListenerType
PostComponentActionListenerType
The types of ConnectorDataListener.
Definition: ComponentActionListener.h:225
RTC::PostComponentActionListener::~PostComponentActionListener
virtual ~PostComponentActionListener()
Destructor.
RTC::PostComponentActionListenerType::POST_ON_ACTIVATED
@ POST_ON_ACTIVATED
RTC::ComponentActionListeners::notify
bool notify(PortActionListenerType type, const RTC::PortProfile &pprofile)
Definition: ComponentActionListener.h:1320
RTC::PostComponentActionListenerHolder::removeListener
void removeListener(PostComponentActionListener *listener)
Remove the listener.
RTC::ExecutionContextActionListenerHolder::notify
void notify(UniqueId ec_id)
Notify listeners.
RTC::ExecutionContextActionListenerType
ExecutionContextActionListenerType
The types of ExecutionContextActionListener.
Definition: ComponentActionListener.h:493
RTC::PostComponentActionListenerType::POST_ON_STATE_UPDATE
@ POST_ON_STATE_UPDATE
RTC::ComponentActionListeners::removeListener
bool removeListener(PreComponentActionListenerType type, PreComponentActionListener *listener)
Remove the listener.
RTC::PreComponentActionListener
PreComponentActionListener class.
Definition: ComponentActionListener.h:122
RTC::PortActionListenerHolder
PortActionListener holder class.
Definition: ComponentActionListener.h:819
RTC::PortActionListener
PortActionListener class.
Definition: ComponentActionListener.h:410
RTC::PreComponentActionListenerType::PRE_ON_STARTUP
@ PRE_ON_STARTUP
RTC::ExecutionContextActionListener::toString
static const char * toString(ExecutionContextActionListenerType type)
Convert PreComponentActionListenerType into the string.
Definition: ComponentActionListener.h:546
RTC::PreComponentActionListenerType::PRE_ON_STATE_UPDATE
@ PRE_ON_STATE_UPDATE
RTC::PreComponentActionListener::operator()
virtual void operator()(UniqueId ec_id)=0
Virtual Callback function.
RTC::PostComponentActionListenerType::POST_ON_DEACTIVATED
@ POST_ON_DEACTIVATED
RTC::PortActionListener::toString
static const char * toString(PortActionListenerType type)
Convert PreComponentActionListenerType into the string.
Definition: ComponentActionListener.h:436
RTC::PreComponentActionListenerType::PRE_ON_FINALIZE
@ PRE_ON_FINALIZE
RTC::ExecutionContextActionListener
ExecutionContextActionListener class.
Definition: ComponentActionListener.h:520
RTC::PostComponentActionListenerHolder::~PostComponentActionListenerHolder
virtual ~PostComponentActionListenerHolder()
Destructor.
RTC::ExecutionContextActionListenerType::EC_ATTACHED
@ EC_ATTACHED
RTC::PostComponentActionListenerType::POST_ON_RESET
@ POST_ON_RESET
RTC::PreComponentActionListener::toString
static const char * toString(PreComponentActionListenerType type)
Convert PreComponentActionListenerType into the string.
Definition: ComponentActionListener.h:148
ConnectorBase.h
Connector base class.
RTC::ExecutionContextActionListenerHolder::~ExecutionContextActionListenerHolder
virtual ~ExecutionContextActionListenerHolder()
Destructor.
RTC::PreComponentActionListenerHolder::addListener
void addListener(PreComponentActionListener *listener, bool autoclean)
Add the listener.
RTC::PostComponentActionListenerType::POST_ON_INITIALIZE
@ POST_ON_INITIALIZE
RTC::PostComponentActionListenerType::POST_ON_EXECUTE
@ POST_ON_EXECUTE
RTC::PostComponentActionListenerType::POST_ON_RATE_CHANGED
@ POST_ON_RATE_CHANGED
RTC::PortActionListener::operator()
virtual void operator()(const ::RTC::PortProfile &pprof)=0
Virtual Callback function.
RTC::PostComponentActionListenerHolder::addListener
void addListener(PostComponentActionListener *listener, bool autoclean)
Add the listener.
RTC::PortActionListenerHolder::notify
void notify(const RTC::PortProfile &pprofile)
Notify listeners.
RTC::ComponentActionListeners::addListener
bool addListener(PreComponentActionListenerType type, PreComponentActionListener *listener, bool autoclean)
Add the listener.
RTC::ComponentActionListeners
ComponentActionListeners class.
Definition: ComponentActionListener.h:1025
RTC::PreComponentActionListenerHolder::PreComponentActionListenerHolder
PreComponentActionListenerHolder()
Constructor.
RTC::PreComponentActionListenerType::PRE_ON_ERROR
@ PRE_ON_ERROR
RTC::PortActionListenerType::PORT_ACTION_LISTENER_NUM
@ PORT_ACTION_LISTENER_NUM
RTC::ComponentActionListeners::notify
bool notify(PreComponentActionListenerType type, UniqueId ec_id)
Definition: ComponentActionListener.h:1260
RTC::PreComponentActionListenerType::PRE_ON_INITIALIZE
@ PRE_ON_INITIALIZE
RTC::PortActionListenerHolder::~PortActionListenerHolder
virtual ~PortActionListenerHolder()
Destructor.
RTC::PortActionListenerType
PortActionListenerType
The types of PortActionListener.
Definition: ComponentActionListener.h:383
RTC::PreComponentActionListenerHolder::removeListener
void removeListener(PreComponentActionListener *listener)
Remove the listener.
RTC::PostComponentActionListenerType::POST_ON_FINALIZE
@ POST_ON_FINALIZE
RTC::PreComponentActionListenerType::PRE_ON_EXECUTE
@ PRE_ON_EXECUTE
RTC::PreComponentActionListenerType
PreComponentActionListenerType
The types of ConnectorDataListener.
Definition: ComponentActionListener.h:59
RTC::PreComponentActionListenerHolder
PreComponentActionListener holder class.
Definition: ComponentActionListener.h:607
RTC::UniqueId
ExecutionContextHandle_t UniqueId
Definition: ComponentActionListener.h:34
RTC::PreComponentActionListenerType::PRE_ON_ABORTING
@ PRE_ON_ABORTING
RTC::PreComponentActionListenerType::PRE_ON_DEACTIVATED
@ PRE_ON_DEACTIVATED
RTC::ComponentActionListeners::notify
bool notify(ExecutionContextActionListenerType type, UniqueId ec_id)
Definition: ComponentActionListener.h:1349
RTC
RT-Component.
RTC::PortActionListenerHolder::addListener
void addListener(PortActionListener *listener, bool autoclean)
Add the listener.
RTC::ExecutionContextActionListenerType::EC_ACTION_LISTENER_NUM
@ EC_ACTION_LISTENER_NUM
RTC::PreComponentActionListenerType::PRE_ON_RATE_CHANGED
@ PRE_ON_RATE_CHANGED
RTC::ExecutionContextActionListener::operator()
virtual void operator()(UniqueId ec_id)=0
Virtual Callback function.
RTC.h
RTComponent header.
RTC::PortActionListenerHolder::removeListener
void removeListener(PortActionListener *listener)
Remove the listener.
RTC::PostComponentActionListener::toString
static const char * toString(PostComponentActionListenerType type)
Convert PostComponentActionListenerType into the string.
Definition: ComponentActionListener.h:315
RTC::PostComponentActionListener
PostComponentActionListener class.
Definition: ComponentActionListener.h:289
RTC::PortActionListenerType::REMOVE_PORT
@ REMOVE_PORT
RTC::PortActionListenerHolder::PortActionListenerHolder
PortActionListenerHolder()
Constructor.
RTC::ExecutionContextActionListener::~ExecutionContextActionListener
virtual ~ExecutionContextActionListener()
Destructor.
RTC::PortActionListenerType::ADD_PORT
@ ADD_PORT
RTC::PreComponentActionListenerHolder::~PreComponentActionListenerHolder
virtual ~PreComponentActionListenerHolder()
Destructor.
RTC::ComponentActionListeners::ComponentActionListeners
ComponentActionListeners()
Constructor.
RTC::PostComponentActionListenerType::POST_ON_ERROR
@ POST_ON_ERROR
RTC::ExecutionContextActionListenerHolder
ExecutionContextActionListener holder class.
Definition: ComponentActionListener.h:924
RTC::ExecutionContextActionListenerHolder::removeListener
void removeListener(ExecutionContextActionListener *listener)
Remove the listener.