PortConnectListener.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 
21 namespace RTC
22 {
23 
24  //============================================================
32  const char*
34  {
35  static const char* typeString[] =
36  {
37  "ON_NOTIFY_CONNECT",
38  "ON_NOTIFY_DISCONNECT",
39  "ON_UNSUBSCRIBE_INTERFACES",
40  ""
41  };
43  return typeString[type];
44  }
45 
54 
62  const char*
64  {
65  static const char* typeString[] =
66  {
67  "ON_PUBLISH_INTERFACES",
68  "ON_CONNECT_NEXTPORT",
69  "ON_SUBSCRIBE_INTERFACES",
70  "ON_CONNECTED",
71  "ON_DISCONNECT_NEXT",
72  "ON_DISCONNECTED",
73  ""
74  };
75  type = type < PORT_CONNECT_RET_LISTENER_NUM ?
77  return typeString[type];
78  }
79 
88 
89  //============================================================
98  {
99  }
100 
101 
103  {
104  Guard guard(m_mutex);
105  for (int i(0), len(m_listeners.size()); i < len; ++i)
106  {
107  if (m_listeners[i].second)
108  {
109  delete m_listeners[i].first;
110  }
111  }
112  }
113 
114 
116  bool autoclean)
117  {
118  Guard guard(m_mutex);
119  m_listeners.push_back(Entry(listener, autoclean));
120  }
121 
122 
124  {
125  Guard guard(m_mutex);
126  std::vector<Entry>::iterator it(m_listeners.begin());
127 
128  for (; it != m_listeners.end(); ++it)
129  {
130  if ((*it).first == listener)
131  {
132  if ((*it).second)
133  {
134  delete (*it).first;
135  }
136  m_listeners.erase(it);
137  return;
138  }
139  }
140 
141  }
142 
143 
144  void PortConnectListenerHolder::notify(const char* portname,
145  RTC::ConnectorProfile& profile)
146  {
147  Guard guard(m_mutex);
148  for (int i(0), len(m_listeners.size()); i < len; ++i)
149  {
150  m_listeners[i].first->operator()(portname, profile);
151  }
152  }
153 
154  //============================================================
163  {
164  }
165 
166 
168  {
169  Guard guard(m_mutex);
170  for (int i(0), len(m_listeners.size()); i < len; ++i)
171  {
172  if (m_listeners[i].second)
173  {
174  delete m_listeners[i].first;
175  }
176  }
177  }
178 
179 
181  addListener(PortConnectRetListener* listener, bool autoclean)
182  {
183  Guard guard(m_mutex);
184  m_listeners.push_back(Entry(listener, autoclean));
185  }
186 
187 
190  {
191  Guard guard(m_mutex);
192  std::vector<Entry>::iterator it(m_listeners.begin());
193  for (; it != m_listeners.end(); ++it)
194  {
195  if ((*it).first == listener)
196  {
197  if ((*it).second)
198  {
199  delete (*it).first;
200  }
201  m_listeners.erase(it);
202  return;
203  }
204  }
205 
206  }
207 
208 
209  void PortConnectRetListenerHolder::notify(const char* portname,
210  RTC::ConnectorProfile& profile,
212  {
213  Guard guard(m_mutex);
214  for (int i(0), len(m_listeners.size()); i < len; ++i)
215  {
216  m_listeners[i].first->operator()(portname, profile, ret);
217  }
218  }
219 
220 };
221 
222 
PortConnectListenerType
The types of ConnectorDataListener.
PortConnectRetListener class.
RT-Component.
static const char * toString(PortConnectRetListenerType type)
Convert PortConnectRetListenerType into string.
ReturnCode_t
Definition: doil.h:53
void notify(const char *portname, RTC::ConnectorProfile &profile)
Notify listeners.
void removeListener(PortConnectRetListener *listener)
Remove the listener.
std::pair< PortConnectRetListener *, bool > Entry
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
void removeListener(PortConnectListener *listener)
Remove the listener.
PortConnectListener class.
virtual ~PortConnectListenerHolder()
Destructor.
static const char * toString(PortConnectListenerType type)
Convert PortConnectListenerType into the string.
virtual ~PortConnectRetListener()
Destructor.
PortConnectRetListenerType
The types of PortConnectRetListenerType.
virtual ~PortConnectRetListenerHolder()
Destructor.
void addListener(PortConnectListener *listener, bool autoclean)
Add the listener.
std::pair< PortConnectListener *, bool > Entry
void notify(const char *portname, RTC::ConnectorProfile &profile, ReturnCode_t ret)
Notify listeners.
port&#39;s internal action listener classes
virtual ~PortConnectListener()
Destructor.
void addListener(PortConnectRetListener *listener, bool autoclean)
Add the listener.


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