OpenRTM-aist  2.0.0
PortConnectListener.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_PORTCONNECTLISTENER_H
20 #define RTC_PORTCONNECTLISTENER_H
21 
22 #include <mutex>
23 #include <rtm/RTC.h>
24 #include <rtm/idl/RTCSkel.h>
25 
26 #include <vector>
27 #include <utility>
28 #include <array>
29 
30 namespace RTC
31 {
32  //============================================================
50  enum class PortConnectListenerType : uint8_t
51  {
56  };
57 
84  {
85  public:
109  static const char* toString(PortConnectListenerType type);
110 
118  virtual ~PortConnectListener();
119 
135  virtual void operator()(const char* portname,
136  RTC::ConnectorProfile& profile) = 0;
137  };
138 
139 
140  //============================================================
162  enum class PortConnectRetListenerType : uint8_t
163  {
167  ON_CONNECTED,
171  };
172 
204  {
205  public:
229  static const char* toString(PortConnectRetListenerType type);
230 
238  virtual ~PortConnectRetListener();
239 
255  virtual void operator()(const char* portname,
256  RTC::ConnectorProfile& profile,
257  ReturnCode_t ret) = 0;
258  };
259 
260  //============================================================
278  {
279  using Entry = std::pair<PortConnectListener*, bool>;
280  public:
289 
297  virtual ~PortConnectListenerHolder();
298 
320  void addListener(PortConnectListener* listener, bool autoclean);
321 
339  void removeListener(PortConnectListener* listener);
340 
358  void notify(const char* portname, RTC::ConnectorProfile& profile);
359 
360  private:
361  std::vector<Entry> m_listeners;
362  std::mutex m_mutex;
363  };
364 
365 
383  {
384  using Entry = std::pair<PortConnectRetListener*, bool>;
385  public:
394 
402  virtual ~PortConnectRetListenerHolder();
403 
425  void addListener(PortConnectRetListener* listener, bool autoclean);
426 
444  void removeListener(PortConnectRetListener* listener);
445 
465  void notify(const char* portname, RTC::ConnectorProfile& profile,
466  ReturnCode_t ret);
467 
468  private:
469  std::vector<Entry> m_listeners;
470  std::mutex m_mutex;
471  };
472 
487  {
488  public:
530  bool addListener(PortConnectListenerType type, PortConnectListener* listener, bool autoclean=true);
553  bool removeListener(PortConnectListenerType type, PortConnectListener* listener);
579  bool addListener(PortConnectRetListenerType type, PortConnectRetListener* listener, bool autoclean=true);
602  bool removeListener(PortConnectRetListenerType type, PortConnectRetListener* listener);
625  inline bool notify(PortConnectListenerType type, const char* portname, RTC::ConnectorProfile& profile)
626  {
627  if (static_cast<uint8_t>(type) < portconnect_.size())
628  {
629  portconnect_[static_cast<uint8_t>(type)].notify(portname, profile);
630  return true;
631  }
632  return false;
633  }
658  inline bool notify(PortConnectRetListenerType type, const char* portname, RTC::ConnectorProfile& profile,
659  ReturnCode_t ret)
660  {
661  if (static_cast<uint8_t>(type) < portconnret_.size())
662  {
663  portconnret_[static_cast<uint8_t>(type)].notify(portname, profile, ret);
664  return true;
665  }
666  return false;
667  }
668 
669  private:
679  std::array<PortConnectListenerHolder,
680  static_cast<uint8_t>
682  portconnect_;
692  std::array<PortConnectRetListenerHolder,
693  static_cast<uint8_t>
695  portconnret_;
696  };
697 
698 
699 } // namespace RTC
700 
701 #endif // RTC_PORTCONNECTLISTENER_H
PortConnectRetListener class.
Definition: PortConnectListener.h:203
RT-Component.
PortConnectRetListenerType
The types of PortConnectRetListenerType.
Definition: PortConnectListener.h:162
PortConnectListenerType
The types of ConnectorDataListener.
Definition: PortConnectListener.h:50
char const * toString(BufferStatus status)
Convert BufferStatus into the string.
Definition: BufferStatus.h:90
PortConnectListener class.
Definition: PortConnectListener.h:83
PortConnectListener holder class.
Definition: PortConnectListener.h:277
PortConnectListeners class.
Definition: PortConnectListener.h:486
PortConnectRetListener holder class.
Definition: PortConnectListener.h:382
bool notify(PortConnectRetListenerType type, const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Definition: PortConnectListener.h:658
RTComponent header.
bool notify(PortConnectListenerType type, const char *portname, RTC::ConnectorProfile &profile)
Definition: PortConnectListener.h:625