Switch to unified view

a/libupnpp/device/device.cxx b/libupnpp/device/device.cxx
...
...
27
#include <sstream>
27
#include <sstream>
28
#include <utility>
28
#include <utility>
29
#include <algorithm>
29
#include <algorithm>
30
#include <mutex>
30
#include <mutex>
31
#include <condition_variable>
31
#include <condition_variable>
32
#include <thread>
32
33
33
#include "libupnpp/log.hxx"
34
#include "libupnpp/log.hxx"
34
#include "libupnpp/ixmlwrap.hxx"
35
#include "libupnpp/ixmlwrap.hxx"
35
#include "libupnpp/upnpplib.hxx"
36
#include "libupnpp/upnpplib.hxx"
36
#include "libupnpp/upnpputils.hxx"
37
#include "libupnpp/upnpputils.hxx"
...
...
59
60
60
    UPnPP::LibUPnP *lib;
61
    UPnPP::LibUPnP *lib;
61
    std::string deviceId;
62
    std::string deviceId;
62
    std::string description;
63
    std::string description;
63
64
65
    // In case startloop has been called: the event loop thread.
66
    std::thread loopthread;
67
    
64
    // We keep the services in a map for easy access from id and in a
68
    // We keep the services in a map for easy access from id and in a
65
    // vector for ordered walking while fetching status. Order is
69
    // vector for ordered walking while fetching status. Order is
66
    // determine by addService() call sequence.
70
    // determine by addService() call sequence.
67
    std::unordered_map<std::string, UpnpService*> servicemap;
71
    std::unordered_map<std::string, UpnpService*> servicemap;
68
    std::vector<std::string> serviceids;
72
    std::vector<std::string> serviceids;
...
...
198
    }
202
    }
199
}
203
}
200
204
201
UpnpDevice::~UpnpDevice()
205
UpnpDevice::~UpnpDevice()
202
{
206
{
207
    shouldExit();
208
    if (m->loopthread.joinable())
209
        m->loopthread.join();
210
        
203
    if (!m->description.empty()) {
211
    if (!m->description.empty()) {
204
        UpnpUnRegisterRootDevice(m->dvh);
212
        UpnpUnRegisterRootDevice(m->dvh);
205
    }
213
    }
206
214
207
    std::unique_lock<std::mutex> lock(o->devices_lock);
215
    std::unique_lock<std::mutex> lock(o->devices_lock);
...
...
482
        LOGERR(lib->errAsString("UpnpDevice::notifyEvent: id", ret) <<
490
        LOGERR(lib->errAsString("UpnpDevice::notifyEvent: id", ret) <<
483
               " for " << serviceId << endl);
491
               " for " << serviceId << endl);
484
    }
492
    }
485
}
493
}
486
494
487
int timespec_diffms(const struct timespec& old, const struct timespec& recent)
495
static int timespec_diffms(const struct timespec& old,
496
                           const struct timespec& recent)
488
{
497
{
489
    return (recent.tv_sec - old.tv_sec) * 1000 +
498
    return (recent.tv_sec - old.tv_sec) * 1000 +
490
           (recent.tv_nsec - old.tv_nsec) / (1000 * 1000);
499
           (recent.tv_nsec - old.tv_nsec) / (1000 * 1000);
500
}
501
502
void UpnpDevice::startloop()
503
{
504
    m->loopthread = std::thread(&UpnpDevice::eventloop, this);
491
}
505
}
492
506
493
// Loop on services, and poll each for changed data. Generate event
507
// Loop on services, and poll each for changed data. Generate event
494
// only if changed data exists.
508
// only if changed data exists.
495
// We used to generate an artificial event with all the current state
509
// We used to generate an artificial event with all the current state