Go to the documentation of this file.00001
00019 #include <rtm/PortConnectListener.h>
00020
00021 namespace RTC
00022 {
00023
00024
00032 const char*
00033 PortConnectListener::toString(PortConnectListenerType type)
00034 {
00035 static const char* typeString[] =
00036 {
00037 "ON_NOTIFY_CONNECT",
00038 "ON_NOTIFY_DISCONNECT",
00039 "ON_UNSUBSCRIBE_INTERFACES",
00040 ""
00041 };
00042 type = type < PORT_CONNECT_LISTENER_NUM ? type : PORT_CONNECT_LISTENER_NUM;
00043 return typeString[type];
00044 }
00045
00053 PortConnectListener::~PortConnectListener(){}
00054
00062 const char*
00063 PortConnectRetListener::toString(PortConnectRetListenerType type)
00064 {
00065 static const char* typeString[] =
00066 {
00067 "ON_PUBLISH_INTERFACES",
00068 "ON_CONNECT_NEXTPORT",
00069 "ON_SUBSCRIBE_INTERFACES",
00070 "ON_CONNECTED",
00071 "ON_DISCONNECT_NEXT",
00072 "ON_DISCONNECTED",
00073 ""
00074 };
00075 type = type < PORT_CONNECT_RET_LISTENER_NUM ?
00076 type : PORT_CONNECT_RET_LISTENER_NUM;
00077 return typeString[type];
00078 }
00079
00087 PortConnectRetListener::~PortConnectRetListener(){}
00088
00089
00097 PortConnectListenerHolder::PortConnectListenerHolder()
00098 {
00099 }
00100
00101
00102 PortConnectListenerHolder::~PortConnectListenerHolder()
00103 {
00104 Guard guard(m_mutex);
00105 for (int i(0), len(m_listeners.size()); i < len; ++i)
00106 {
00107 if (m_listeners[i].second)
00108 {
00109 delete m_listeners[i].first;
00110 }
00111 }
00112 }
00113
00114
00115 void PortConnectListenerHolder::addListener(PortConnectListener* listener,
00116 bool autoclean)
00117 {
00118 Guard guard(m_mutex);
00119 m_listeners.push_back(Entry(listener, autoclean));
00120 }
00121
00122
00123 void PortConnectListenerHolder::removeListener(PortConnectListener* listener)
00124 {
00125 Guard guard(m_mutex);
00126 std::vector<Entry>::iterator it(m_listeners.begin());
00127
00128 for (; it != m_listeners.end(); ++it)
00129 {
00130 if ((*it).first == listener)
00131 {
00132 if ((*it).second)
00133 {
00134 delete (*it).first;
00135 }
00136 m_listeners.erase(it);
00137 return;
00138 }
00139 }
00140
00141 }
00142
00143
00144 void PortConnectListenerHolder::notify(const char* portname,
00145 RTC::ConnectorProfile& profile)
00146 {
00147 Guard guard(m_mutex);
00148 for (int i(0), len(m_listeners.size()); i < len; ++i)
00149 {
00150 m_listeners[i].first->operator()(portname, profile);
00151 }
00152 }
00153
00154
00162 PortConnectRetListenerHolder::PortConnectRetListenerHolder()
00163 {
00164 }
00165
00166
00167 PortConnectRetListenerHolder::~PortConnectRetListenerHolder()
00168 {
00169 Guard guard(m_mutex);
00170 for (int i(0), len(m_listeners.size()); i < len; ++i)
00171 {
00172 if (m_listeners[i].second)
00173 {
00174 delete m_listeners[i].first;
00175 }
00176 }
00177 }
00178
00179
00180 void PortConnectRetListenerHolder::
00181 addListener(PortConnectRetListener* listener, bool autoclean)
00182 {
00183 Guard guard(m_mutex);
00184 m_listeners.push_back(Entry(listener, autoclean));
00185 }
00186
00187
00188 void PortConnectRetListenerHolder::
00189 removeListener(PortConnectRetListener* listener)
00190 {
00191 Guard guard(m_mutex);
00192 std::vector<Entry>::iterator it(m_listeners.begin());
00193 for (; it != m_listeners.end(); ++it)
00194 {
00195 if ((*it).first == listener)
00196 {
00197 if ((*it).second)
00198 {
00199 delete (*it).first;
00200 }
00201 m_listeners.erase(it);
00202 return;
00203 }
00204 }
00205
00206 }
00207
00208
00209 void PortConnectRetListenerHolder::notify(const char* portname,
00210 RTC::ConnectorProfile& profile,
00211 ReturnCode_t ret)
00212 {
00213 Guard guard(m_mutex);
00214 for (int i(0), len(m_listeners.size()); i < len; ++i)
00215 {
00216 m_listeners[i].first->operator()(portname, profile, ret);
00217 }
00218 }
00219
00220 };
00221
00222