OpenRTM-aist 2.0.2
Loading...
Searching...
No Matches
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
32namespace RTC
33{
34 using UniqueId = ExecutionContextHandle_t;
35 //============================================================
75
123 {
124 public:
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 //============================================================
241
242
290 {
291 public:
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,
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 //============================================================
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 class.
Definition ComponentActionListener.h:1026
bool removeListener(PostComponentActionListenerType type, PostComponentActionListener *listener)
Remove the listener.
bool removeListener(PortActionListenerType type, PortActionListener *listener)
Remove the listener.
ComponentActionListeners()
Constructor .
bool addListener(ExecutionContextActionListenerType type, ExecutionContextActionListener *listener, bool autoclean)
Add the listener.
bool notify(ExecutionContextActionListenerType type, UniqueId ec_id)
Definition ComponentActionListener.h:1349
bool addListener(PortActionListenerType type, PortActionListener *listener, bool autoclean)
Add the listener.
bool removeListener(ExecutionContextActionListenerType type, ExecutionContextActionListener *listener)
Remove the listener.
bool notify(PostComponentActionListenerType type, UniqueId ec_id, ReturnCode_t ret)
Definition ComponentActionListener.h:1291
bool removeListener(PreComponentActionListenerType type, PreComponentActionListener *listener)
Remove the listener.
~ComponentActionListeners()
Destructor .
bool addListener(PostComponentActionListenerType type, PostComponentActionListener *listener, bool autoclean)
Add the listener.
bool addListener(PreComponentActionListenerType type, PreComponentActionListener *listener, bool autoclean)
Add the listener.
bool notify(PortActionListenerType type, const RTC::PortProfile &pprofile)
Definition ComponentActionListener.h:1320
bool notify(PreComponentActionListenerType type, UniqueId ec_id)
Definition ComponentActionListener.h:1260
ExecutionContextActionListener holder class.
Definition ComponentActionListener.h:925
void removeListener(ExecutionContextActionListener *listener)
Remove the listener.
void addListener(ExecutionContextActionListener *listener, bool autoclean)
Add the listener.
virtual ~ExecutionContextActionListenerHolder()
Destructor .
void notify(UniqueId ec_id)
Notify listeners.
ExecutionContextActionListener class.
Definition ComponentActionListener.h:521
virtual ~ExecutionContextActionListener()
Destructor .
virtual void operator()(UniqueId ec_id)=0
Virtual Callback function.
static const char * toString(ExecutionContextActionListenerType type)
Convert PreComponentActionListenerType into the string.
Definition ComponentActionListener.h:546
PortActionListener holder class.
Definition ComponentActionListener.h:820
PortActionListenerHolder()
Constructor .
virtual ~PortActionListenerHolder()
Destructor .
void removeListener(PortActionListener *listener)
Remove the listener.
void notify(const RTC::PortProfile &pprofile)
Notify listeners.
void addListener(PortActionListener *listener, bool autoclean)
Add the listener.
PortActionListener class.
Definition ComponentActionListener.h:411
virtual void operator()(const ::RTC::PortProfile &pprof)=0
Virtual Callback function.
virtual ~PortActionListener()
Destructor .
static const char * toString(PortActionListenerType type)
Convert PreComponentActionListenerType into the string.
Definition ComponentActionListener.h:436
PostComponentActionListener holder class.
Definition ComponentActionListener.h:713
void addListener(PostComponentActionListener *listener, bool autoclean)
Add the listener.
void notify(UniqueId ec_id, ReturnCode_t ret)
Notify listeners.
virtual ~PostComponentActionListenerHolder()
Destructor .
void removeListener(PostComponentActionListener *listener)
Remove the listener.
PostComponentActionListener class.
Definition ComponentActionListener.h:290
static const char * toString(PostComponentActionListenerType type)
Convert PostComponentActionListenerType into the string.
Definition ComponentActionListener.h:315
virtual ~PostComponentActionListener()
Destructor .
virtual void operator()(UniqueId ec_id, ReturnCode_t ret)=0
Virtual Callback function.
PreComponentActionListener holder class.
Definition ComponentActionListener.h:608
void removeListener(PreComponentActionListener *listener)
Remove the listener.
void notify(UniqueId ec_id)
Notify listeners.
void addListener(PreComponentActionListener *listener, bool autoclean)
Add the listener.
virtual ~PreComponentActionListenerHolder()
Destructor .
PreComponentActionListener class.
Definition ComponentActionListener.h:123
virtual void operator()(UniqueId ec_id)=0
Virtual Callback function.
virtual ~PreComponentActionListener()
Destructor .
static const char * toString(PreComponentActionListenerType type)
Convert PreComponentActionListenerType into the string.
Definition ComponentActionListener.h:148
RT-Component.
ExecutionContextActionListenerType
The types of ExecutionContextActionListener.
Definition ComponentActionListener.h:494
ExecutionContextHandle_t UniqueId
Definition ComponentActionListener.h:34
PreComponentActionListenerType
The types of ConnectorDataListener.
Definition ComponentActionListener.h:60
PortActionListenerType
The types of PortActionListener.
Definition ComponentActionListener.h:384
PostComponentActionListenerType
The types of ConnectorDataListener.
Definition ComponentActionListener.h:226