aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/upnp/Discovery.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-16 12:50:59 +0100
committerMax Kellermann <max@duempel.org>2014-01-17 10:13:04 +0100
commite2812f722d04ca2f338e00d59d2a649545863b03 (patch)
tree1874a9737e9559d32c2308696502b644f93bafc5 /src/db/upnp/Discovery.hxx
parentaa64a5328edb4fcafb53cd512d37f9ceed8ed1c5 (diff)
downloadmpd-e2812f722d04ca2f338e00d59d2a649545863b03.tar.gz
mpd-e2812f722d04ca2f338e00d59d2a649545863b03.tar.xz
mpd-e2812f722d04ca2f338e00d59d2a649545863b03.zip
db/upnp/Discovery: move callbacks and data structures into class
Eliminate global variables.
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Discovery.hxx55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/db/upnp/Discovery.hxx b/src/db/upnp/Discovery.hxx
index 412307fd7..c4704dc7e 100644
--- a/src/db/upnp/Discovery.hxx
+++ b/src/db/upnp/Discovery.hxx
@@ -20,9 +20,16 @@
#ifndef _UPNPPDISC_H_X_INCLUDED_
#define _UPNPPDISC_H_X_INCLUDED_
+#include "Device.hxx"
+#include "WorkQueue.hxx"
+#include "thread/Mutex.hxx"
#include "util/Error.hxx"
+#include <upnp/upnp.h>
+
+#include <map>
#include <vector>
+#include <string>
#include <time.h>
@@ -36,10 +43,46 @@ class ContentDirectoryService;
* for now, but this could be made more general, by removing the filtering.
*/
class UPnPDeviceDirectory {
+ /**
+ * Each appropriate discovery event (executing in a libupnp thread
+ * context) queues the following task object for processing by the
+ * discovery thread.
+ */
+ struct DiscoveredTask {
+ bool alive;
+ std::string url;
+ std::string deviceId;
+ int expires; // Seconds valid
+
+ DiscoveredTask(bool _alive, const Upnp_Discovery *disco)
+ : alive(_alive), url(disco->Location),
+ deviceId(disco->DeviceId),
+ expires(disco->Expires) {}
+ };
+
+ /**
+ * Descriptor for one device having a Content Directory
+ * service found on the network.
+ */
+ class ContentDirectoryDescriptor {
+ public:
+ ContentDirectoryDescriptor(const std::string &url,
+ const std::string &description,
+ time_t last, int exp)
+ :device(url, description), last_seen(last), expires(exp+20) {}
+ UPnPDevice device;
+ time_t last_seen;
+ int expires; // seconds valid
+ };
+
LibUPnP *const lib;
Error error;
+ Mutex mutex;
+ std::map<std::string, ContentDirectoryDescriptor> directories;
+ WorkQueue<DiscoveredTask *> discoveredQueue;
+
/**
* The UPnP device search timeout, which should actually be
* called delay because it's the base of a random delay that
@@ -85,6 +128,18 @@ private:
* directory.
*/
void expireDevices();
+
+ /**
+ * Worker routine for the discovery queue. Get messages about
+ * devices appearing and disappearing, and update the
+ * directory pool accordingly.
+ */
+ static void *discoExplorer(void *);
+ void discoExplorer();
+
+ int OnAlive(Upnp_Discovery *disco);
+ int OnByeBye(Upnp_Discovery *disco);
+ int cluCallBack(Upnp_EventType et, void *evp);
};