ConnectorListener.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef RTC_CONNECTORLISTENER_H
21 #define RTC_CONNECTORLISTENER_H
22 
23 #include <vector>
24 #include <utility>
25 #include <coil/Mutex.h>
26 #include <coil/Guard.h>
27 #include <rtm/RTC.h>
28 #include <rtm/ConnectorBase.h>
29 
30 class cdrMemoryStream;
31 
32 namespace RTC
33 {
34  class ConnectorInfo;
35 
68  {
80  };
81 
189  {
190  public:
214  static const char* toString(ConnectorDataListenerType type)
215  {
216  static const char* typeString[] =
217  {
218  "ON_BUFFER_WRITE",
219  "ON_BUFFER_FULL",
220  "ON_BUFFER_WRITE_TIMEOUT",
221  "ON_BUFFER_OVERWRITE",
222  "ON_BUFFER_READ",
223  "ON_SEND",
224  "ON_RECEIVED",
225  "ON_RECEIVER_FULL",
226  "ON_RECEIVER_TIMEOUT",
227  "ON_RECEIVER_ERROR",
228  "CONNECTOR_DATA_LISTENER_NUM"
229  };
230  if (type < CONNECTOR_DATA_LISTENER_NUM) { return typeString[type]; }
231  return "";
232  }
233 
241  virtual ~ConnectorDataListener();
242 
259  virtual void operator()(const ConnectorInfo& info,
260  const cdrMemoryStream& data) = 0;
261  };
262 
289  template <class DataType>
291  : public ConnectorDataListener
292  {
293  public:
302 
326  virtual void operator()(const ConnectorInfo& info,
327  const cdrMemoryStream& cdrdata)
328  {
329  DataType data;
330  cdrMemoryStream cdr(cdrdata.bufPtr(), cdrdata.bufSize());
331 
332  // endian type check
333  std::string endian_type;
334  endian_type = info.properties.getProperty("serializer.cdr.endian",
335  "little");
336  coil::normalize(endian_type);
337  std::vector<std::string> endian(coil::split(endian_type, ","));
338  if (endian[0] == "little")
339  {
340  cdr.setByteSwapFlag(true);
341  }
342  else if (endian[0] == "big")
343  {
344  cdr.setByteSwapFlag(false);
345  }
346  data <<= cdr;
347  this->operator()(info, data);
348  }
349 
367  virtual void operator()(const ConnectorInfo& info,
368  const DataType& data) = 0;
369 
370  };
371 
372 
399  {
408  };
409 
517  {
518  public:
542  static const char* toString(ConnectorListenerType type)
543  {
544  static const char* typeStr[] =
545  {
546  "ON_BUFFER_EMPTY",
547  "ON_BUFFER_READ_TIMEOUT",
548  "ON_SENDER_EMPTY",
549  "ON_SENDER_TIMEOUT",
550  "ON_SENDER_ERROR",
551  "ON_CONNECT",
552  "ON_DISCONNECT",
553  "CONNECTOR_LISTENER_NUM"
554  };
555  if (type < CONNECTOR_LISTENER_NUM) { return typeStr[type]; }
556  return "";
557  }
558 
566  virtual ~ConnectorListener();
567 
585  virtual void operator()(const ConnectorInfo& info) = 0;
586  };
587 
588 
605  {
606  typedef std::pair<ConnectorDataListener*, bool> Entry;
608  public:
624  virtual ~ConnectorDataListenerHolder();
625 
647  void addListener(ConnectorDataListener* listener, bool autoclean);
648 
666  void removeListener(ConnectorDataListener* listener);
667 
687  void notify(const ConnectorInfo& info,
688  const cdrMemoryStream& cdrdata);
689 
690  private:
691  std::vector<Entry> m_listeners;
693  };
694 
695 
712  {
713  typedef std::pair<ConnectorListener*, bool> Entry;
715  public:
724 
732  virtual ~ConnectorListenerHolder();
733 
755  void addListener(ConnectorListener* listener, bool autoclean);
756 
774  void removeListener(ConnectorListener* listener);
775 
793  void notify(const ConnectorInfo& info);
794 
795  private:
796  std::vector<Entry> m_listeners;
798  };
799 
814  {
815  public:
836  };
837 };
838 
839 #endif // RTC_CONNECTORLISTENER_H
ConnectorListeners class.
std::string normalize(std::string &str)
Erase the head/tail blank and replace upper case to lower case.
Definition: stringutil.cpp:303
coil::Properties properties
Connection properties.
RT-Component.
ConnectorDataListener class.
Mutex class.
coil::Guard< coil::Mutex > Guard
virtual ~ConnectorDataListener()
Destructor.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:341
ConnectorDataListener holder class.
std::pair< ConnectorListener *, bool > Entry
ConnectorDataListenerType
The types of ConnectorDataListener.
static const char * toString(ConnectorListenerType type)
Convert ConnectorListenerType into the string.
Connector base class.
ConnectorDataListenerT class.
std::pair< ConnectorDataListener *, bool > Entry
coil::Guard< coil::Mutex > Guard
ConnectorListenerType
The types of ConnectorListener.
static const char * toString(ConnectorDataListenerType type)
Convert ConnectorDataListenerType into the string.
virtual void operator()(const ConnectorInfo &info, const cdrMemoryStream &data)=0
Virtual Callback method.
virtual ~ConnectorDataListenerT()
Destructor.
std::vector< Entry > m_listeners
RTComponent header.
ConnectorListener holder class.
virtual void operator()(const ConnectorInfo &info, const cdrMemoryStream &cdrdata)
Callback method.
const std::string & getProperty(const std::string &key) const
Search for the property with the specified key in this property.
Definition: Properties.cpp:156


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:50