OpenRTM-aist  2.1.0
FsmActionListener.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_FSMACTIONLISTENER_H
20 #define RTC_FSMACTIONLISTENER_H
21 
22 #include <vector>
23 #include <utility>
24 #include <mutex>
25 #include <array>
26 #include <rtm/RTC.h>
27 #include <rtm/idl/RTCSkel.h>
28 #include <rtm/ConnectorBase.h>
29 #include <rtm/idl/ExtendedFsmServiceStub.h>
30 
31 namespace RTC
32 {
60  //============================================================
89  enum class PreFsmActionListenerType : uint8_t
90  {
93  PRE_ON_DO,
97  };
98 
232  {
233  public:
257  static const char* toString(PreFsmActionListenerType type)
258  {
259  static const char* const typeString[] =
260  {
261  "PRE_ON_INIT",
262  "PRE_ON_ENTRY",
263  "PRE_ON_DO",
264  "PRE_ON_EXIT",
265  "PRE_ON_STATE_CHANGE",
266  "PRE_FSM_ACTION_LISTENER_NUM"
267  };
269  {
270  return typeString[static_cast<uint8_t>(type)];
271  }
272  return "";
273  }
274 
283 
299  virtual void operator()(const char*) = 0;
300  };
301 
302 
303  //============================================================
332  enum class PostFsmActionListenerType : uint8_t
333  {
334  POST_ON_INIT,
336  POST_ON_DO,
337  POST_ON_EXIT,
340  };
341 
475  {
476  public:
500  static const char* toString(PostFsmActionListenerType type)
501  {
502  static const char* const typeString[] =
503  {
504  "POST_ON_INIT",
505  "POST_ON_ENTRY",
506  "POST_ON_DO",
507  "POST_ON_EXIT",
508  "POST_ON_STATE_CHANGE",
509  "POST_FSM_ACTION_LISTENER_NUM"
510  };
512  {
513  return typeString[static_cast<uint8_t>(type)];
514  }
515  return "";
516  }
517 
526 
542  virtual void operator()(const char* state,
543  ReturnCode_t ret) = 0;
544  };
545 
546  //============================================================
574  enum class FsmProfileListenerType : uint8_t
575  {
585  };
586 
723  {
724  public:
746  static const char* toString(FsmProfileListenerType type)
747  {
748  static const char* const typeString[] =
749  {
750  "SET_FSM_PROFILE",
751  "GET_FSM_PROFILE",
752  "ADD_FSM_STATE",
753  "REMOVE_FSM_STATE",
754  "ADD_FSM_TRANSITION",
755  "REMOVE_FSM_TRANSITION",
756  "BIND_FSM_EVENT",
757  "UNBIND_FSM_EVENT",
758  "FSM_PROFILE_LISTENER_NUM"
759  };
761  {
762  return typeString[static_cast<uint8_t>(type)];
763  }
764  return "";
765  }
766 
775 
791  virtual void operator()(const ::RTC::FsmProfile& fsmprof) = 0;
792  };
793 
794 
795  //============================================================
811  enum class FsmStructureListenerType : uint8_t
812  {
816  };
817 
942  {
943  public:
967  static const char* toString(FsmStructureListenerType type)
968  {
969  static const char* const typeString[] =
970  {
971  "SET_FSM_STRUCTURE",
972  "GET_FSM_STRUCTURE",
973  "FSM_STRUCTURE_LISTENER_NUM"
974  };
976  {
977  return typeString[static_cast<uint8_t>(type)];
978  }
979  return "";
980  }
981 
990 
1006  virtual void operator()(::RTC::FsmStructure& pprof) = 0;
1007  };
1008 
1009  //============================================================
1010  // Holder classes
1011  //============================================================
1029  {
1030  using Entry = std::pair<PreFsmActionListener*, bool>;
1031  public:
1040 
1049 
1071  void addListener(PreFsmActionListener* listener, bool autoclean);
1072 
1091 
1109  void notify(const char* state);
1110 
1111  private:
1112  std::vector<Entry> m_listeners;
1113  std::mutex m_mutex;
1114  };
1115 
1116 
1134  {
1135  using Entry = std::pair<PostFsmActionListener*, bool>;
1136  public:
1153 
1175  void addListener(PostFsmActionListener* listener, bool autoclean);
1176 
1195 
1215  void notify(const char* state, ReturnCode_t ret);
1216 
1217  private:
1218  std::vector<Entry> m_listeners;
1219  std::mutex m_mutex;
1220  };
1221 
1222 
1223  //============================================================
1241  {
1242  using Entry = std::pair<FsmProfileListener*, bool>;
1243  public:
1260 
1282  void addListener(FsmProfileListener* listener, bool autoclean);
1283 
1302 
1320  void notify(RTC::FsmProfile& profile);
1321 
1322  private:
1323  std::vector<Entry> m_listeners;
1324  std::mutex m_mutex;
1325  };
1326 
1344  {
1345  using Entry = std::pair<FsmStructureListener*, bool>;
1346  public:
1363 
1385  void addListener(FsmStructureListener* listener, bool autoclean);
1386 
1405 
1423  void notify(RTC::FsmStructure& structure);
1424 
1425  private:
1426  std::vector<Entry> m_listeners;
1427  std::mutex m_mutex;
1428  };
1429 
1430  //============================================================
1445  {
1446  public:
1488  bool addListener(PreFsmActionListenerType type, PreFsmActionListener* listener, bool autoclean=true);
1537  bool addListener(PostFsmActionListenerType type, PostFsmActionListener* listener, bool autoclean=true);
1586  bool addListener(FsmProfileListenerType type, FsmProfileListener* listener, bool autoclean=true);
1635  bool addListener(FsmStructureListenerType type, FsmStructureListener* listener, bool autoclean=true);
1679  inline bool notify(PreFsmActionListenerType type, const char* state)
1680  {
1681  if (static_cast<uint8_t>(type) < preaction_.size())
1682  {
1683  preaction_[static_cast<uint8_t>(type)].notify(state);
1684  return true;
1685  }
1686  return false;
1687  }
1710  inline bool notify(PostFsmActionListenerType type, const char* state, ReturnCode_t ret)
1711  {
1712  if (static_cast<uint8_t>(type) < postaction_.size())
1713  {
1714  postaction_[static_cast<uint8_t>(type)].notify(state, ret);
1715  return true;
1716  }
1717  return false;
1718  }
1739  inline bool notify(FsmProfileListenerType type, RTC::FsmProfile& profile)
1740  {
1741  if (static_cast<uint8_t>(type) < profile_.size())
1742  {
1743  profile_[static_cast<uint8_t>(type)].notify(profile);
1744  return true;
1745  }
1746  return false;
1747  }
1768  inline bool notify(FsmStructureListenerType type, RTC::FsmStructure& structure)
1769  {
1770  if (static_cast<uint8_t>(type) < structure_.size())
1771  {
1772  structure_[static_cast<uint8_t>(type)].notify(structure);
1773  return true;
1774  }
1775  return false;
1776  }
1777  private:
1787  std::array<PreFsmActionListenerHolder, static_cast<uint8_t>(PreFsmActionListenerType::PRE_FSM_ACTION_LISTENER_NUM)> preaction_;
1797  std::array<PostFsmActionListenerHolder, static_cast<uint8_t>(PostFsmActionListenerType::POST_FSM_ACTION_LISTENER_NUM)> postaction_;
1807  std::array<FsmProfileListenerHolder, static_cast<uint8_t>(FsmProfileListenerType::FSM_PROFILE_LISTENER_NUM)> profile_;
1817  std::array<FsmStructureListenerHolder, static_cast<uint8_t>(FsmStructureListenerType::FSM_STRUCTURE_LISTENER_NUM)> structure_;
1818  };
1819 
1820 } // namespace RTC
1821 
1822 #endif // RTC_FSMACTIONLISTENER_H
Connector base class.
RTComponent header.
FsmActionListeners class.
Definition: FsmActionListener.h:1445
bool notify(FsmProfileListenerType type, RTC::FsmProfile &profile)
Definition: FsmActionListener.h:1739
bool notify(PostFsmActionListenerType type, const char *state, ReturnCode_t ret)
Definition: FsmActionListener.h:1710
FsmActionListeners()
Constructor.
bool addListener(PostFsmActionListenerType type, PostFsmActionListener *listener, bool autoclean=true)
Add the listener.
bool notify(PreFsmActionListenerType type, const char *state)
Definition: FsmActionListener.h:1679
bool removeListener(FsmProfileListenerType type, FsmProfileListener *listener)
Remove the listener.
~FsmActionListeners()
Destructor.
bool notify(FsmStructureListenerType type, RTC::FsmStructure &structure)
Definition: FsmActionListener.h:1768
bool removeListener(PostFsmActionListenerType type, PostFsmActionListener *listener)
Remove the listener.
bool addListener(FsmStructureListenerType type, FsmStructureListener *listener, bool autoclean=true)
Add the listener.
bool addListener(PreFsmActionListenerType type, PreFsmActionListener *listener, bool autoclean=true)
Add the listener.
bool addListener(FsmProfileListenerType type, FsmProfileListener *listener, bool autoclean=true)
Add the listener.
bool removeListener(PreFsmActionListenerType type, PreFsmActionListener *listener)
Remove the listener.
bool removeListener(FsmStructureListenerType type, FsmStructureListener *listener)
Remove the listener.
FsmProfileListener holder class.
Definition: FsmActionListener.h:1241
void addListener(FsmProfileListener *listener, bool autoclean)
Add the listener.
void removeListener(FsmProfileListener *listener)
Remove the listener.
void notify(RTC::FsmProfile &profile)
Notify listeners.
FsmProfileListenerHolder()
Constructor.
virtual ~FsmProfileListenerHolder()
Destructor.
FsmProfileListener class.
Definition: FsmActionListener.h:723
virtual ~FsmProfileListener()
Destructor.
virtual void operator()(const ::RTC::FsmProfile &fsmprof)=0
Virtual Callback function.
static const char * toString(FsmProfileListenerType type)
Convert FsmProfileListenerType into the string.
Definition: FsmActionListener.h:746
FsmStructureListener holder class.
Definition: FsmActionListener.h:1344
FsmStructureListenerHolder()
Constructor.
void removeListener(FsmStructureListener *listener)
Remove the listener.
void notify(RTC::FsmStructure &structure)
Notify listeners.
virtual ~FsmStructureListenerHolder()
Destructor.
void addListener(FsmStructureListener *listener, bool autoclean)
Add the listener.
FsmStructureListener class.
Definition: FsmActionListener.h:942
static const char * toString(FsmStructureListenerType type)
Convert FsmStructureListenerType into the string.
Definition: FsmActionListener.h:967
virtual void operator()(::RTC::FsmStructure &pprof)=0
Virtual Callback function.
virtual ~FsmStructureListener()
Destructor.
PostFsmActionListener holder class.
Definition: FsmActionListener.h:1134
void removeListener(PostFsmActionListener *listener)
Remove the listener.
virtual ~PostFsmActionListenerHolder()
Destructor.
void addListener(PostFsmActionListener *listener, bool autoclean)
Add the listener.
PostFsmActionListenerHolder()
Constructor.
void notify(const char *state, ReturnCode_t ret)
Notify listeners.
PostFsmActionListener class.
Definition: FsmActionListener.h:475
virtual void operator()(const char *state, ReturnCode_t ret)=0
Virtual Callback function.
static const char * toString(PostFsmActionListenerType type)
Convert PostFsmActionListenerType into the string.
Definition: FsmActionListener.h:500
virtual ~PostFsmActionListener()
Destructor.
PreFsmActionListener holder class.
Definition: FsmActionListener.h:1029
void addListener(PreFsmActionListener *listener, bool autoclean)
Add the listener.
PreFsmActionListenerHolder()
Constructor.
void removeListener(PreFsmActionListener *listener)
Remove the listener.
virtual ~PreFsmActionListenerHolder()
Destructor.
void notify(const char *state)
Notify listeners.
PreFsmActionListener class.
Definition: FsmActionListener.h:232
virtual ~PreFsmActionListener()
Destructor.
virtual void operator()(const char *)=0
Virtual Callback function.
static const char * toString(PreFsmActionListenerType type)
Convert PreFsmActionListenerType into the string.
Definition: FsmActionListener.h:257
RT-Component.
FsmStructureListenerType
The types of FsmStructureListener.
Definition: FsmActionListener.h:812
PreFsmActionListenerType
The types of PreFsmActionListener.
Definition: FsmActionListener.h:90
PostFsmActionListenerType
The types of PostFsmActionListener.
Definition: FsmActionListener.h:333
FsmProfileListenerType
The types of FsmProfileListener.
Definition: FsmActionListener.h:575