Switch to unified view

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