diff options
Diffstat (limited to 'src/lib/upnp')
-rw-r--r-- | src/lib/upnp/Action.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Callback.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/ClientInit.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/ClientInit.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/ContentDirectoryService.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/ContentDirectoryService.hxx | 5 | ||||
-rw-r--r-- | src/lib/upnp/Device.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Device.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Discovery.cxx | 59 | ||||
-rw-r--r-- | src/lib/upnp/Discovery.hxx | 29 | ||||
-rw-r--r-- | src/lib/upnp/Domain.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Domain.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Init.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Init.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Util.cxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/Util.hxx | 2 | ||||
-rw-r--r-- | src/lib/upnp/WorkQueue.hxx | 9 |
17 files changed, 62 insertions, 66 deletions
diff --git a/src/lib/upnp/Action.hxx b/src/lib/upnp/Action.hxx index 28c88be92..bad398e1a 100644 --- a/src/lib/upnp/Action.hxx +++ b/src/lib/upnp/Action.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Callback.hxx b/src/lib/upnp/Callback.hxx index 85daf0a7e..4d86c0b53 100644 --- a/src/lib/upnp/Callback.hxx +++ b/src/lib/upnp/Callback.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/ClientInit.cxx b/src/lib/upnp/ClientInit.cxx index 77d9cf03d..50fcbdb16 100644 --- a/src/lib/upnp/ClientInit.cxx +++ b/src/lib/upnp/ClientInit.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/ClientInit.hxx b/src/lib/upnp/ClientInit.hxx index 645e64ca6..f49f255ee 100644 --- a/src/lib/upnp/ClientInit.hxx +++ b/src/lib/upnp/ClientInit.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/ContentDirectoryService.cxx b/src/lib/upnp/ContentDirectoryService.cxx index 0e5d2d955..0636505ab 100644 --- a/src/lib/upnp/ContentDirectoryService.cxx +++ b/src/lib/upnp/ContentDirectoryService.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/ContentDirectoryService.hxx b/src/lib/upnp/ContentDirectoryService.hxx index 0b03df2e7..bf6ab913a 100644 --- a/src/lib/upnp/ContentDirectoryService.hxx +++ b/src/lib/upnp/ContentDirectoryService.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -62,7 +62,8 @@ public: /** * Construct by copying data from device and service objects. * - * The discovery service does this: use getDirServices() + * The discovery service does this: use + * UPnPDeviceDirectory::GetDirectories() */ ContentDirectoryService(const UPnPDevice &device, const UPnPService &service); diff --git a/src/lib/upnp/Device.cxx b/src/lib/upnp/Device.cxx index 26bffd0f0..402a39166 100644 --- a/src/lib/upnp/Device.cxx +++ b/src/lib/upnp/Device.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Device.hxx b/src/lib/upnp/Device.hxx index dd7ecac2d..cdb065434 100644 --- a/src/lib/upnp/Device.hxx +++ b/src/lib/upnp/Device.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 1539e1512..f6a3ba122 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -107,12 +107,12 @@ UPnPDeviceDirectory::LockRemove(const std::string &id) } inline void -UPnPDeviceDirectory::discoExplorer() +UPnPDeviceDirectory::Explore() { for (;;) { DiscoveredTask *tsk = 0; - if (!discoveredQueue.take(tsk)) { - discoveredQueue.workerExit(); + if (!queue.take(tsk)) { + queue.workerExit(); return; } @@ -128,7 +128,7 @@ UPnPDeviceDirectory::discoExplorer() } // Update or insert the device - ContentDirectoryDescriptor d(std::move(tsk->deviceId), + ContentDirectoryDescriptor d(std::move(tsk->device_id), MonotonicClockS(), tsk->expires); { @@ -148,10 +148,10 @@ UPnPDeviceDirectory::discoExplorer() } void * -UPnPDeviceDirectory::discoExplorer(void *ctx) +UPnPDeviceDirectory::Explore(void *ctx) { UPnPDeviceDirectory &directory = *(UPnPDeviceDirectory *)ctx; - directory.discoExplorer(); + directory.Explore(); return (void*)1; } @@ -161,7 +161,7 @@ UPnPDeviceDirectory::OnAlive(Upnp_Discovery *disco) if (isMSDevice(disco->DeviceType) || isCDService(disco->ServiceType)) { DiscoveredTask *tp = new DiscoveredTask(disco); - if (discoveredQueue.put(tp)) + if (queue.put(tp)) return UPNP_E_FINISH; } @@ -210,9 +210,8 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, void *evp) } bool -UPnPDeviceDirectory::expireDevices(Error &error) +UPnPDeviceDirectory::ExpireDevices(Error &error) { - const ScopeLock protect(mutex); const unsigned now = MonotonicClockS(); bool didsomething = false; @@ -227,7 +226,7 @@ UPnPDeviceDirectory::expireDevices(Error &error) } if (didsomething) - return search(error); + return Search(error); return true; } @@ -236,8 +235,8 @@ UPnPDeviceDirectory::UPnPDeviceDirectory(UpnpClient_Handle _handle, UPnPDiscoveryListener *_listener) :handle(_handle), listener(_listener), - discoveredQueue("DiscoveredQueue"), - m_searchTimeout(2), m_lastSearch(0) + queue("DiscoveredQueue"), + search_timeout(2), last_search(0) { } @@ -249,24 +248,24 @@ UPnPDeviceDirectory::~UPnPDeviceDirectory() bool UPnPDeviceDirectory::Start(Error &error) { - if (!discoveredQueue.start(1, discoExplorer, this)) { + if (!queue.start(1, Explore, this)) { error.Set(upnp_domain, "Discover work queue start failed"); return false; } - return search(error); + return Search(error); } bool -UPnPDeviceDirectory::search(Error &error) +UPnPDeviceDirectory::Search(Error &error) { const unsigned now = MonotonicClockS(); - if (now - m_lastSearch < 10) + if (now - last_search < 10) return true; - m_lastSearch = now; + last_search = now; // We search both for device and service just in case. - int code = UpnpSearchAsync(handle, m_searchTimeout, + int code = UpnpSearchAsync(handle, search_timeout, ContentDirectorySType, GetUpnpCookie()); if (code != UPNP_E_SUCCESS) { error.Format(upnp_domain, code, @@ -275,7 +274,7 @@ UPnPDeviceDirectory::search(Error &error) return false; } - code = UpnpSearchAsync(handle, m_searchTimeout, + code = UpnpSearchAsync(handle, search_timeout, MediaServerDType, GetUpnpCookie()); if (code != UPNP_E_SUCCESS) { error.Format(upnp_domain, code, @@ -288,15 +287,14 @@ UPnPDeviceDirectory::search(Error &error) } bool -UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out, +UPnPDeviceDirectory::GetDirectories(std::vector<ContentDirectoryService> &out, Error &error) { - // Has locking, do it before our own lock - if (!expireDevices(error)) - return false; - const ScopeLock protect(mutex); + if (!ExpireDevices(error)) + return false; + for (auto dit = directories.begin(); dit != directories.end(); dit++) { for (const auto &service : dit->device.services) { @@ -310,20 +308,19 @@ UPnPDeviceDirectory::getDirServices(std::vector<ContentDirectoryService> &out, } bool -UPnPDeviceDirectory::getServer(const char *friendlyName, +UPnPDeviceDirectory::GetServer(const char *friendly_name, ContentDirectoryService &server, Error &error) { - // Has locking, do it before our own lock - if (!expireDevices(error)) - return false; - const ScopeLock protect(mutex); + if (!ExpireDevices(error)) + return false; + for (const auto &i : directories) { const auto &device = i.device; - if (device.friendlyName != friendlyName) + if (device.friendlyName != friendly_name) continue; for (const auto &service : device.services) { diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 767811840..1cf82b77e 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -55,13 +55,13 @@ class UPnPDeviceDirectory final : UpnpCallback { */ struct DiscoveredTask { std::string url; - std::string deviceId; + std::string device_id; unsigned expires; // Seconds valid DiscoveredTask(const Upnp_Discovery *disco) :url(disco->Location), - deviceId(disco->DeviceId), - expires(disco->Expires) {} + device_id(disco->DeviceId), + expires(disco->Expires) {} }; /** @@ -97,19 +97,19 @@ class UPnPDeviceDirectory final : UpnpCallback { Mutex mutex; std::list<ContentDirectoryDescriptor> directories; - WorkQueue<DiscoveredTask *> discoveredQueue; + WorkQueue<DiscoveredTask *> queue; /** * The UPnP device search timeout, which should actually be * called delay because it's the base of a random delay that * the devices apply to avoid responding all at the same time. */ - int m_searchTimeout; + int search_timeout; /** * The MonotonicClockS() time stamp of the last search. */ - unsigned m_lastSearch; + unsigned last_search; public: UPnPDeviceDirectory(UpnpClient_Handle _handle, @@ -122,24 +122,26 @@ public: bool Start(Error &error); /** Retrieve the directory services currently seen on the network */ - bool getDirServices(std::vector<ContentDirectoryService> &, Error &); + bool GetDirectories(std::vector<ContentDirectoryService> &, Error &); /** * Get server by friendly name. */ - bool getServer(const char *friendlyName, + bool GetServer(const char *friendly_name, ContentDirectoryService &server, Error &error); private: - bool search(Error &error); + bool Search(Error &error); /** * Look at the devices and get rid of those which have not * been seen for too long. We do this when listing the top * directory. + * + * Caller must lock #mutex. */ - bool expireDevices(Error &error); + bool ExpireDevices(Error &error); void LockAdd(ContentDirectoryDescriptor &&d); void LockRemove(const std::string &id); @@ -149,12 +151,11 @@ private: * devices appearing and disappearing, and update the * directory pool accordingly. */ - static void *discoExplorer(void *); - void discoExplorer(); + static void *Explore(void *); + void Explore(); int OnAlive(Upnp_Discovery *disco); int OnByeBye(Upnp_Discovery *disco); - int cluCallBack(Upnp_EventType et, void *evp); /* virtual methods from class UpnpCallback */ virtual int Invoke(Upnp_EventType et, void *evp) override; diff --git a/src/lib/upnp/Domain.cxx b/src/lib/upnp/Domain.cxx index 010d4c7c2..d7700a067 100644 --- a/src/lib/upnp/Domain.cxx +++ b/src/lib/upnp/Domain.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Domain.hxx b/src/lib/upnp/Domain.hxx index ec01ef735..ff0cd9b85 100644 --- a/src/lib/upnp/Domain.hxx +++ b/src/lib/upnp/Domain.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Init.cxx b/src/lib/upnp/Init.cxx index 4fc606de9..1b471f53d 100644 --- a/src/lib/upnp/Init.cxx +++ b/src/lib/upnp/Init.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Init.hxx b/src/lib/upnp/Init.hxx index b23f8e2ab..796251862 100644 --- a/src/lib/upnp/Init.hxx +++ b/src/lib/upnp/Init.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Util.cxx b/src/lib/upnp/Util.cxx index 79cfb111c..912d993b4 100644 --- a/src/lib/upnp/Util.cxx +++ b/src/lib/upnp/Util.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/Util.hxx b/src/lib/upnp/Util.hxx index a59f23521..d3b0b049f 100644 --- a/src/lib/upnp/Util.hxx +++ b/src/lib/upnp/Util.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify diff --git a/src/lib/upnp/WorkQueue.hxx b/src/lib/upnp/WorkQueue.hxx index fe8ce53f9..cd6b1161d 100644 --- a/src/lib/upnp/WorkQueue.hxx +++ b/src/lib/upnp/WorkQueue.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -66,10 +66,7 @@ class WorkQueue { public: /** Create a WorkQueue - * @param name for message printing - * @param hi number of tasks on queue before clients blocks. Default 0 - * meaning no limit. hi == -1 means that the queue is disabled. - * @param lo minimum count of tasks before worker starts. Default 1. + * @param _name for message printing */ WorkQueue(const char *_name) :name(_name), @@ -86,7 +83,7 @@ public: /** Start the worker threads. * * @param nworkers number of threads copies to start. - * @param start_routine thread function. It should loop + * @param workproc thread function. It should loop * taking (QueueWorker::take()) and executing tasks. * @param arg initial parameter to thread function. * @return true if ok. |