Switch to unified view

a/libupnpp/control/discovery.hxx b/libupnpp/control/discovery.hxx
...
...
25
namespace UPnPClient {
25
namespace UPnPClient {
26
26
27
/**
27
/**
28
 * Manage UPnP discovery and maintain a directory of active devices. Singleton.
28
 * Manage UPnP discovery and maintain a directory of active devices. Singleton.
29
 *
29
 *
30
 *
31
 * The service is initialize on the first call, starting
32
 * the message-handling thread, registering our message handlers, 
33
 * and initiating an asynchronous UPnP device search. 
34
 *
35
 * The search implies a timeout period (the specified interval
36
 * over which the servers will send replies at random points). Any
37
 * subsequent traverse() call will block until the timeout
38
 * is expired. Use getRemainingDelay() to know the current
39
 * remaining delay, and use it to do something else.
40
 *
41
 * We need a separate thread to process the messages coming up
42
 * from libupnp, because some of them will in turn trigger other
43
 * calls to libupnp, and this must not be done from the libupnp
44
 * thread context which reported the initial message.
45
 * So there are three threads in action:
46
 *  - the reporting thread from libupnp.
47
 *  - the discovery service processing thread, which also runs the callbacks.
48
 *  - the user thread (typically the main thread), which calls traverse.
30
 */
49
 */
31
class UPnPDeviceDirectory {
50
class UPnPDeviceDirectory {
32
public:
51
public:
33
    /** Retrieve the singleton object for the discovery service,
52
    /** Retrieve the singleton object for the discovery service,
34
     * and possibly start it up if this is the first call.
53
     * and possibly start it up if this is the first call. This does not wait
35
     *
54
     * significantly, a subsequent traverse() will wait until the
36
     * This initializes the discovery service on first call, starting
55
     * initial delay is consumed.
37
     * the message-handling thread, registering our message handlers, 
38
     * and initiating an asynchronous UPnP device search. 
39
     *
40
     * The search implies a timeout period (the specified interval
41
     * over which the servers will send replies at random points). Any
42
     * subsequent getDirServices() call will block until the timeout
43
     * is expired, so that the client can choose to do something else
44
     * to use the time before getDirServices() can be hoped to return
45
     * immediate results. Use getRemainingDelay() to know the current
46
     * state of things.
47
     *
48
     * We need a separate thread to process the messages coming up
49
     * from libupnp, because some of them will in turn trigger other
50
     * calls to libupnp, and this must not be done from the libupnp
51
     * thread context which reported the initial message.
52
     */
56
     */
53
    static UPnPDeviceDirectory *getTheDir(time_t search_window = 3);
57
    static UPnPDeviceDirectory *getTheDir(time_t search_window = 3);
54
58
55
    /** Clean up before exit. Do call this.*/
59
    /** Clean up before exit. Do call this.*/
56
    static void terminate();
60
    static void terminate();
...
...
59
                                const UPnPServiceDesc&)> Visitor;
63
                                const UPnPServiceDesc&)> Visitor;
60
64
61
    /** Traverse the directory and call Visitor for each device/service pair */
65
    /** Traverse the directory and call Visitor for each device/service pair */
62
    bool traverse(Visitor);
66
    bool traverse(Visitor);
63
67
68
    /** Remaining time until current search complete */
69
    time_t getRemainingDelay();
70
64
    /** My health */
71
    /** My health */
65
    bool ok() {return m_ok;}
72
    bool ok() {return m_ok;}
66
    /** My diagnostic if health is bad */
73
    /** My diagnostic if health is bad */
67
    const std::string getReason() {return m_reason;}
74
    const std::string getReason() {return m_reason;}
68
75
69
    /** Remaining time until current search complete */
70
    time_t getRemainingDelay();
71
72
private:
76
private:
73
    UPnPDeviceDirectory(time_t search_window);
77
    UPnPDeviceDirectory(time_t search_window);
74
    UPnPDeviceDirectory(const UPnPDeviceDirectory &);
78
    UPnPDeviceDirectory(const UPnPDeviceDirectory &) = delete;
75
    UPnPDeviceDirectory& operator=(const UPnPDeviceDirectory &);
79
    UPnPDeviceDirectory& operator=(const UPnPDeviceDirectory &) = delete;
76
    bool search();
80
    bool search();
77
    void expireDevices();
81
    void expireDevices();
78
82
79
    bool m_ok;
83
    bool m_ok;
80
    std::string m_reason;
84
    std::string m_reason;