|
a/libupnpp/device.cxx |
|
b/libupnpp/device.cxx |
|
... |
|
... |
51 |
//LOGDEB("Edata: " << cnames[i] << " -> " << cvalues[i] << endl);
|
51 |
//LOGDEB("Edata: " << cnames[i] << " -> " << cvalues[i] << endl);
|
52 |
}
|
52 |
}
|
53 |
return true;
|
53 |
return true;
|
54 |
}
|
54 |
}
|
55 |
|
55 |
|
|
|
56 |
static const int expiretime = 3600;
|
|
|
57 |
|
56 |
UpnpDevice::UpnpDevice(const string& deviceId,
|
58 |
UpnpDevice::UpnpDevice(const string& deviceId,
|
57 |
const unordered_map<string, string>& xmlfiles)
|
59 |
const unordered_map<string, string>& xmlfiles)
|
58 |
: m_deviceId(deviceId)
|
60 |
: m_deviceId(deviceId)
|
59 |
{
|
61 |
{
|
60 |
//LOGDEB("UpnpDevice::UpnpDevice(" << m_deviceId << ")" << endl);
|
62 |
//LOGDEB("UpnpDevice::UpnpDevice(" << m_deviceId << ")" << endl);
|
|
... |
|
... |
99 |
}
|
101 |
}
|
100 |
|
102 |
|
101 |
// Start up the web server for sending out description files
|
103 |
// Start up the web server for sending out description files
|
102 |
m_lib->setupWebServer(description);
|
104 |
m_lib->setupWebServer(description);
|
103 |
|
105 |
|
|
|
106 |
UpnpSendAdvertisement(m_lib->getdvh(), expiretime);
|
|
|
107 |
|
104 |
o_devices[m_deviceId] = this;
|
108 |
o_devices[m_deviceId] = this;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
UpnpDevice::~UpnpDevice()
|
|
|
112 |
{
|
|
|
113 |
UpnpUnRegisterRootDevice (m_lib->getdvh());
|
105 |
}
|
114 |
}
|
106 |
|
115 |
|
107 |
static PTMutexInit cblock;
|
116 |
static PTMutexInit cblock;
|
108 |
|
117 |
|
109 |
// Main libupnp callback: use the device id and call the right device
|
118 |
// Main libupnp callback: use the device id and call the right device
|
|
... |
|
... |
320 |
void UpnpDevice::eventloop()
|
329 |
void UpnpDevice::eventloop()
|
321 |
{
|
330 |
{
|
322 |
int count = 0;
|
331 |
int count = 0;
|
323 |
const int loopwait_ms = 1000; // Polling the services every 1 S
|
332 |
const int loopwait_ms = 1000; // Polling the services every 1 S
|
324 |
const int nloopstofull = 10; // Full state every 10 S
|
333 |
const int nloopstofull = 10; // Full state every 10 S
|
325 |
struct timespec wkuptime, earlytime;
|
334 |
struct timespec wkuptime, earlytime, lastadvert;
|
326 |
bool didearly = false;
|
335 |
bool didearly = false;
|
|
|
336 |
|
|
|
337 |
clock_gettime(CLOCK_REALTIME, &lastadvert);
|
327 |
|
338 |
|
328 |
for (;;) {
|
339 |
for (;;) {
|
329 |
clock_gettime(CLOCK_REALTIME, &wkuptime);
|
340 |
clock_gettime(CLOCK_REALTIME, &wkuptime);
|
|
|
341 |
|
|
|
342 |
if (wkuptime.tv_sec - lastadvert.tv_sec > (expiretime / 3)) {
|
|
|
343 |
UpnpSendAdvertisement (m_lib->getdvh(), expiretime);
|
|
|
344 |
lastadvert = wkuptime;
|
|
|
345 |
}
|
|
|
346 |
|
330 |
timespec_addnanos(&wkuptime, loopwait_ms * 1000 * 1000);
|
347 |
timespec_addnanos(&wkuptime, loopwait_ms * 1000 * 1000);
|
331 |
|
348 |
|
332 |
//LOGDEB("eventloop: now " << time(0) << " wkup at "<<
|
349 |
//LOGDEB("eventloop: now " << time(0) << " wkup at "<<
|
333 |
// wkuptime.tv_sec << " S " << wkuptime.tv_nsec << " ns" << endl);
|
350 |
// wkuptime.tv_sec << " S " << wkuptime.tv_nsec << " ns" << endl);
|
334 |
|
351 |
|