Parent: [fa708f] (diff)

Child: [db078e] (diff)

Download this file

discovery.hxx    83 lines (71 with data), 3.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Copyright (C) 2013 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _UPNPPDISC_H_X_INCLUDED_
#define _UPNPPDISC_H_X_INCLUDED_
#include <vector>
#include "cdirectory.hxx"
/**
* Manage UPnP discovery and maintain a directory of active devices. Singleton.
*
*/
class UPnPDeviceDirectory {
public:
/** Retrieve the singleton object for the discovery service,
* and possibly start it up if this is the first call.
*
* This initializes the discovery service on first call, starting
* the message-handling thread, registering our message handlers,
* and initiating an asynchronous UPnP device search.
*
* The search implies a timeout period (the specified interval
* over which the servers will send replies at random points). Any
* subsequent getDirServices() call will block until the timeout
* is expired, so that the client can choose to do something else
* to use the time before getDirServices() can be hoped to return
* immediate results. Use getRemainingDelay() to know the current
* state of things.
*
* We need a separate thread to process the messages coming up
* from libupnp, because some of them will in turn trigger other
* calls to libupnp, and this must not be done from the libupnp
* thread context which reported the initial message.
*/
static UPnPDeviceDirectory *getTheDir(time_t search_window = 1);
/** Clean up before exit. Do call this.*/
static void terminate();
/** Retrieve the directory services currently seen on the network */
bool getDirServices(std::vector<ContentDirectoryService>&);
/** Retrieve specific service designated by its friendlyName */
bool getServer(const string& friendlyName, ContentDirectoryService& server);
/** My health */
bool ok() {return m_ok;}
/** My diagnostic if health is bad */
const std::string getReason() {return m_reason;}
/** Remaining time until current search complete */
time_t getRemainingDelay();
private:
UPnPDeviceDirectory(time_t search_window);
UPnPDeviceDirectory(const UPnPDeviceDirectory &);
UPnPDeviceDirectory& operator=(const UPnPDeviceDirectory &);
bool search();
void expireDevices();
bool m_ok;
std::string m_reason;
int m_searchTimeout;
time_t m_lastSearch;
};
#endif /* _UPNPPDISC_H_X_INCLUDED_ */