|
a/libupnpp/control/service.cxx |
|
b/libupnpp/control/service.cxx |
|
... |
|
... |
58 |
m_modelName(device.modelName)
|
58 |
m_modelName(device.modelName)
|
59 |
{
|
59 |
{
|
60 |
initEvents();
|
60 |
initEvents();
|
61 |
subscribe();
|
61 |
subscribe();
|
62 |
}
|
62 |
}
|
|
|
63 |
Service::~Service()
|
|
|
64 |
{
|
|
|
65 |
LOGDEB("Service::~Service: unregister " << m_SID << endl);
|
|
|
66 |
unSubscribe();
|
|
|
67 |
o_calls.erase(m_SID);
|
|
|
68 |
}
|
63 |
|
69 |
|
64 |
int Service::runAction(const SoapEncodeInput& args, SoapDecodeOutput& data)
|
70 |
int Service::runAction(const SoapEncodeInput& args, SoapDecodeOutput& data)
|
65 |
{
|
71 |
{
|
66 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
72 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
67 |
if (lib == 0) {
|
73 |
if (lib == 0) {
|
|
... |
|
... |
187 |
bool Service::subscribe()
|
193 |
bool Service::subscribe()
|
188 |
{
|
194 |
{
|
189 |
//LOGDEB("Service::subscribe" << endl);
|
195 |
//LOGDEB("Service::subscribe" << endl);
|
190 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
196 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
191 |
if (lib == 0) {
|
197 |
if (lib == 0) {
|
192 |
LOGINF("Service::runAction: no lib" << endl);
|
198 |
LOGINF("Service::subscribe: no lib" << endl);
|
193 |
return UPNP_E_OUTOF_MEMORY;
|
199 |
return UPNP_E_OUTOF_MEMORY;
|
194 |
}
|
200 |
}
|
195 |
int timeout = 1800;
|
201 |
int timeout = 1800;
|
196 |
int ret = UpnpSubscribe(lib->getclh(), m_eventURL.c_str(),
|
202 |
int ret = UpnpSubscribe(lib->getclh(), m_eventURL.c_str(),
|
197 |
&timeout, m_SID);
|
203 |
&timeout, m_SID);
|
|
... |
|
... |
202 |
}
|
208 |
}
|
203 |
//LOGDEB("Service::subscribe: sid: " << m_SID << endl);
|
209 |
//LOGDEB("Service::subscribe: sid: " << m_SID << endl);
|
204 |
return true;
|
210 |
return true;
|
205 |
}
|
211 |
}
|
206 |
|
212 |
|
|
|
213 |
bool Service::unSubscribe()
|
|
|
214 |
{
|
|
|
215 |
//LOGDEB("Service::unSubscribe" << endl);
|
|
|
216 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
|
|
217 |
if (lib == 0) {
|
|
|
218 |
LOGINF("Service::unSubscribe: no lib" << endl);
|
|
|
219 |
return UPNP_E_OUTOF_MEMORY;
|
|
|
220 |
}
|
|
|
221 |
int ret = UpnpUnSubscribe(lib->getclh(), m_SID);
|
|
|
222 |
if (ret != UPNP_E_SUCCESS) {
|
|
|
223 |
LOGERR("Service:unSubscribe: failed: " <<
|
|
|
224 |
UpnpGetErrorMessage(ret) << endl);
|
|
|
225 |
return false;
|
|
|
226 |
}
|
|
|
227 |
return true;
|
|
|
228 |
}
|
|
|
229 |
|
207 |
void Service::registerCallback(evtCBFunc c)
|
230 |
void Service::registerCallback(evtCBFunc c)
|
208 |
{
|
231 |
{
|
209 |
PTMutexLocker lock(cblock);
|
232 |
PTMutexLocker lock(cblock);
|
|
|
233 |
LOGDEB("Service::registerCallback: " << m_SID << endl);
|
210 |
o_calls[m_SID] = c;
|
234 |
o_calls[m_SID] = c;
|
211 |
}
|
235 |
}
|
212 |
|
236 |
|
213 |
std::unordered_map<std::string, evtCBFunc> Service::o_calls;
|
237 |
std::unordered_map<std::string, evtCBFunc> Service::o_calls;
|
214 |
|
238 |
|