|
a/libupnpp/control/service.cxx |
|
b/libupnpp/control/service.cxx |
|
... |
|
... |
63 |
subscribe();
|
63 |
subscribe();
|
64 |
}
|
64 |
}
|
65 |
|
65 |
|
66 |
Service::~Service()
|
66 |
Service::~Service()
|
67 |
{
|
67 |
{
|
68 |
LOGDEB("Service::~Service: unregister " << m_SID << endl);
|
68 |
LOGDEB1("Service::~Service: unregister " << m_SID << endl);
|
|
|
69 |
if (m_SID[0]) {
|
69 |
unSubscribe();
|
70 |
unSubscribe();
|
70 |
o_calls.erase(m_SID);
|
71 |
o_calls.erase(m_SID);
|
|
|
72 |
}
|
71 |
}
|
73 |
}
|
72 |
|
74 |
|
73 |
int Service::runAction(const SoapEncodeInput& args, SoapDecodeOutput& data)
|
75 |
int Service::runAction(const SoapEncodeInput& args, SoapDecodeOutput& data)
|
74 |
{
|
76 |
{
|
75 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
77 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
|
... |
|
... |
86 |
if ((request = buildSoapBody(args, false)) == 0) {
|
88 |
if ((request = buildSoapBody(args, false)) == 0) {
|
87 |
LOGINF("Service::runAction: buildSoapBody failed" << endl);
|
89 |
LOGINF("Service::runAction: buildSoapBody failed" << endl);
|
88 |
return UPNP_E_OUTOF_MEMORY;
|
90 |
return UPNP_E_OUTOF_MEMORY;
|
89 |
}
|
91 |
}
|
90 |
|
92 |
|
|
|
93 |
LOGDEB1("Service::runAction: rqst: [" <<
|
91 |
LOGDEB("Action xml: [" << ixmlPrintDocument(request) << "]" << endl);
|
94 |
ixmlPrintDocument(request) << "]" << endl);
|
92 |
|
95 |
|
93 |
int ret = UpnpSendAction(hdl, m_actionURL.c_str(), m_serviceType.c_str(),
|
96 |
int ret = UpnpSendAction(hdl, m_actionURL.c_str(), m_serviceType.c_str(),
|
94 |
0 /*devUDN*/, request, &response);
|
97 |
0 /*devUDN*/, request, &response);
|
95 |
|
98 |
|
96 |
if (ret != UPNP_E_SUCCESS) {
|
99 |
if (ret != UPNP_E_SUCCESS) {
|
97 |
LOGINF("Service::runAction: UpnpSendAction failed: " << ret <<
|
100 |
LOGINF("Service::runAction: UpnpSendAction failed: " << ret <<
|
98 |
" : " << UpnpGetErrorMessage(ret) << endl);
|
101 |
" : " << UpnpGetErrorMessage(ret) << endl);
|
99 |
return ret;
|
102 |
return ret;
|
100 |
}
|
103 |
}
|
101 |
LOGDEB("Service::runAction: Result xml: [" << ixmlPrintDocument(response) << "]" << endl);
|
104 |
LOGDEB1("Service::runAction: rslt: [" <<
|
|
|
105 |
ixmlPrintDocument(response) << "]" << endl);
|
102 |
|
106 |
|
103 |
if (!decodeSoapBody(args.name.c_str(), response, &data)) {
|
107 |
if (!decodeSoapBody(args.name.c_str(), response, &data)) {
|
104 |
LOGERR("Service::runAction: Could not decode response: " <<
|
108 |
LOGERR("Service::runAction: Could not decode response: " <<
|
105 |
ixmlPrintDocument(response) << endl);
|
109 |
ixmlPrintDocument(response) << endl);
|
106 |
return UPNP_E_BAD_RESPONSE;
|
110 |
return UPNP_E_BAD_RESPONSE;
|
|
... |
|
... |
112 |
static PTMutexInit cblock;
|
116 |
static PTMutexInit cblock;
|
113 |
int Service::srvCB(Upnp_EventType et, void* vevp, void*)
|
117 |
int Service::srvCB(Upnp_EventType et, void* vevp, void*)
|
114 |
{
|
118 |
{
|
115 |
PTMutexLocker lock(cblock);
|
119 |
PTMutexLocker lock(cblock);
|
116 |
|
120 |
|
117 |
//LOGDEB("Service:srvCB: " << LibUPnP::evTypeAsString(et) << endl);
|
121 |
LOGDEB1("Service:srvCB: " << LibUPnP::evTypeAsString(et) << endl);
|
118 |
|
122 |
|
119 |
switch (et) {
|
123 |
switch (et) {
|
120 |
case UPNP_EVENT_RENEWAL_COMPLETE:
|
124 |
case UPNP_EVENT_RENEWAL_COMPLETE:
|
121 |
case UPNP_EVENT_SUBSCRIBE_COMPLETE:
|
125 |
case UPNP_EVENT_SUBSCRIBE_COMPLETE:
|
122 |
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
|
126 |
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
|
123 |
case UPNP_EVENT_AUTORENEWAL_FAILED:
|
127 |
case UPNP_EVENT_AUTORENEWAL_FAILED:
|
124 |
{
|
128 |
{
|
125 |
const char *ff = (const char *)vevp;
|
129 |
const char *ff = (const char *)vevp;
|
126 |
LOGDEB("Service:srvCB: subs event: " << ff << endl);
|
130 |
LOGDEB1("Service:srvCB: subs event: " << ff << endl);
|
127 |
break;
|
131 |
break;
|
128 |
}
|
132 |
}
|
129 |
|
133 |
|
130 |
case UPNP_EVENT_RECEIVED:
|
134 |
case UPNP_EVENT_RECEIVED:
|
131 |
{
|
135 |
{
|
|
... |
|
... |
165 |
}
|
169 |
}
|
166 |
|
170 |
|
167 |
// This is called once per process.
|
171 |
// This is called once per process.
|
168 |
bool Service::initEvents()
|
172 |
bool Service::initEvents()
|
169 |
{
|
173 |
{
|
170 |
LOGDEB("Service::initEvents" << endl);
|
174 |
LOGDEB1("Service::initEvents" << endl);
|
171 |
|
175 |
|
172 |
PTMutexLocker lock(cblock);
|
176 |
PTMutexLocker lock(cblock);
|
173 |
static bool eventinit(false);
|
177 |
static bool eventinit(false);
|
174 |
if (eventinit)
|
178 |
if (eventinit)
|
175 |
return true;
|
179 |
return true;
|
|
... |
|
... |
194 |
// LOGDEB("Service::evtCallback!! service: " << m_serviceType << endl);
|
198 |
// LOGDEB("Service::evtCallback!! service: " << m_serviceType << endl);
|
195 |
//}
|
199 |
//}
|
196 |
|
200 |
|
197 |
bool Service::subscribe()
|
201 |
bool Service::subscribe()
|
198 |
{
|
202 |
{
|
199 |
//LOGDEB("Service::subscribe" << endl);
|
203 |
LOGDEB1("Service::subscribe" << endl);
|
200 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
204 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
201 |
if (lib == 0) {
|
205 |
if (lib == 0) {
|
202 |
LOGINF("Service::subscribe: no lib" << endl);
|
206 |
LOGINF("Service::subscribe: no lib" << endl);
|
203 |
return UPNP_E_OUTOF_MEMORY;
|
207 |
return UPNP_E_OUTOF_MEMORY;
|
204 |
}
|
208 |
}
|
|
... |
|
... |
208 |
if (ret != UPNP_E_SUCCESS) {
|
212 |
if (ret != UPNP_E_SUCCESS) {
|
209 |
LOGERR("Service:subscribe: failed: " << ret << " : " <<
|
213 |
LOGERR("Service:subscribe: failed: " << ret << " : " <<
|
210 |
UpnpGetErrorMessage(ret) << endl);
|
214 |
UpnpGetErrorMessage(ret) << endl);
|
211 |
return false;
|
215 |
return false;
|
212 |
}
|
216 |
}
|
213 |
//LOGDEB("Service::subscribe: sid: " << m_SID << endl);
|
217 |
LOGDEB1("Service::subscribe: sid: " << m_SID << endl);
|
214 |
return true;
|
218 |
return true;
|
215 |
}
|
219 |
}
|
216 |
|
220 |
|
217 |
bool Service::unSubscribe()
|
221 |
bool Service::unSubscribe()
|
218 |
{
|
222 |
{
|
219 |
//LOGDEB("Service::unSubscribe" << endl);
|
223 |
LOGDEB1("Service::unSubscribe" << endl);
|
220 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
224 |
LibUPnP* lib = LibUPnP::getLibUPnP();
|
221 |
if (lib == 0) {
|
225 |
if (lib == 0) {
|
222 |
LOGINF("Service::unSubscribe: no lib" << endl);
|
226 |
LOGINF("Service::unSubscribe: no lib" << endl);
|
223 |
return UPNP_E_OUTOF_MEMORY;
|
227 |
return UPNP_E_OUTOF_MEMORY;
|
224 |
}
|
228 |
}
|
|
... |
|
... |
232 |
}
|
236 |
}
|
233 |
|
237 |
|
234 |
void Service::registerCallback(evtCBFunc c)
|
238 |
void Service::registerCallback(evtCBFunc c)
|
235 |
{
|
239 |
{
|
236 |
PTMutexLocker lock(cblock);
|
240 |
PTMutexLocker lock(cblock);
|
237 |
LOGDEB("Service::registerCallback: " << m_SID << endl);
|
241 |
LOGDEB1("Service::registerCallback: " << m_SID << endl);
|
238 |
o_calls[m_SID] = c;
|
242 |
o_calls[m_SID] = c;
|
239 |
}
|
243 |
}
|
240 |
|
244 |
|
241 |
std::unordered_map<std::string, evtCBFunc> Service::o_calls;
|
245 |
std::unordered_map<std::string, evtCBFunc> Service::o_calls;
|
242 |
|
246 |
|