diff options
author | Max Kellermann <max@musicpd.org> | 2017-11-16 11:39:11 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-11-16 11:39:11 +0100 |
commit | 714011c81ed6053f7a35812071499356f337dd70 (patch) | |
tree | d2b9ad2b1eecfc1c7446fc7e8858f3889b1d0e20 | |
parent | 952ff4207bcbf9cd0a19c9b5fb438a3cac2cbd4c (diff) |
lib/upnp: adapt to libupnp 1.8 API changes
Closes #155
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | src/lib/upnp/ClientInit.cxx | 7 | ||||
-rw-r--r-- | src/lib/upnp/Compat.hxx | 69 | ||||
-rw-r--r-- | src/lib/upnp/Discovery.cxx | 18 | ||||
-rw-r--r-- | src/lib/upnp/Discovery.hxx | 17 |
6 files changed, 98 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am index f909647d8..1d47c613e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -243,6 +243,7 @@ CURL_SOURCES = \ src/lib/curl/Slist.hxx UPNP_SOURCES = \ + src/lib/upnp/Compat.hxx \ src/lib/upnp/Init.cxx src/lib/upnp/Init.hxx \ src/lib/upnp/ClientInit.cxx src/lib/upnp/ClientInit.hxx \ src/lib/upnp/Device.cxx src/lib/upnp/Device.hxx \ @@ -1,4 +1,6 @@ ver 0.20.12 (not yet released) +* database + - upnp: adapt to libupnp 1.8 API changes * input - cdio_paranoia, ffmpeg, file, smbclient: reduce lock contention, fixing lots of xrun problems diff --git a/src/lib/upnp/ClientInit.cxx b/src/lib/upnp/ClientInit.cxx index cfe03e388..fed42a7e0 100644 --- a/src/lib/upnp/ClientInit.cxx +++ b/src/lib/upnp/ClientInit.cxx @@ -33,7 +33,12 @@ static unsigned upnp_client_ref; static UpnpClient_Handle upnp_client_handle; static int -UpnpClientCallback(Upnp_EventType et, void *evp, void *cookie) +UpnpClientCallback(Upnp_EventType et, +#if UPNP_VERSION >= 10800 + const +#endif + void *evp, + void *cookie) { if (cookie == nullptr) /* this is the cookie passed to UpnpRegisterClient(); diff --git a/src/lib/upnp/Compat.hxx b/src/lib/upnp/Compat.hxx new file mode 100644 index 000000000..2e2d2f1de --- /dev/null +++ b/src/lib/upnp/Compat.hxx @@ -0,0 +1,69 @@ +/* + * Copyright 2003-2017 The Music Player Daemon Project + * http://www.musicpd.org + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_UPNP_COMPAT_HXX +#define MPD_UPNP_COMPAT_HXX + +#include <upnp/upnp.h> + +#if UPNP_VERSION < 10800 +#include "Compiler.h" + +/* emulate the libupnp 1.8 API with older versions */ + +using UpnpDiscovery = Upnp_Discovery; + +gcc_pure +static inline int +UpnpDiscovery_get_Expires(const UpnpDiscovery *disco) noexcept +{ + return disco->Expires; +} + +gcc_pure +static inline const char * +UpnpDiscovery_get_DeviceID_cstr(const UpnpDiscovery *disco) noexcept +{ + return disco->DeviceId; +} + +gcc_pure +static inline const char * +UpnpDiscovery_get_DeviceType_cstr(const UpnpDiscovery *disco) noexcept +{ + return disco->DeviceType; +} + +gcc_pure +static inline const char * +UpnpDiscovery_get_ServiceType_cstr(const UpnpDiscovery *disco) noexcept +{ + return disco->ServiceType; +} + +gcc_pure +static inline const char * +UpnpDiscovery_get_Location_cstr(const UpnpDiscovery *disco) noexcept +{ + return disco->Location; +} + +#endif + +#endif diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index 1dec2ed98..163f03bd6 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -153,10 +153,10 @@ UPnPDeviceDirectory::Explore(void *ctx) } inline int -UPnPDeviceDirectory::OnAlive(const Upnp_Discovery *disco) +UPnPDeviceDirectory::OnAlive(const UpnpDiscovery *disco) { - if (isMSDevice(disco->DeviceType) || - isCDService(disco->ServiceType)) { + if (isMSDevice(UpnpDiscovery_get_DeviceType_cstr(disco)) || + isCDService(UpnpDiscovery_get_ServiceType_cstr(disco))) { DiscoveredTask *tp = new DiscoveredTask(disco); if (queue.put(tp)) return UPNP_E_FINISH; @@ -166,12 +166,12 @@ UPnPDeviceDirectory::OnAlive(const Upnp_Discovery *disco) } inline int -UPnPDeviceDirectory::OnByeBye(const Upnp_Discovery *disco) +UPnPDeviceDirectory::OnByeBye(const UpnpDiscovery *disco) { - if (isMSDevice(disco->DeviceType) || - isCDService(disco->ServiceType)) { + if (isMSDevice(UpnpDiscovery_get_DeviceType_cstr(disco)) || + isCDService(UpnpDiscovery_get_ServiceType_cstr(disco))) { // Device signals it is going off. - LockRemove(disco->DeviceId); + LockRemove(UpnpDiscovery_get_DeviceID_cstr(disco)); } return UPNP_E_SUCCESS; @@ -188,13 +188,13 @@ UPnPDeviceDirectory::Invoke(Upnp_EventType et, const void *evp) case UPNP_DISCOVERY_SEARCH_RESULT: case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: { - auto *disco = (const Upnp_Discovery *)evp; + auto *disco = (const UpnpDiscovery *)evp; return OnAlive(disco); } case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: { - auto *disco = (const Upnp_Discovery *)evp; + auto *disco = (const UpnpDiscovery *)evp; return OnByeBye(disco); } diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 7f7ac8fa6..a768d14c0 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -20,6 +20,7 @@ #ifndef _UPNPPDISC_H_X_INCLUDED_ #define _UPNPPDISC_H_X_INCLUDED_ +#include "Compat.hxx" #include "Callback.hxx" #include "Device.hxx" #include "WorkQueue.hxx" @@ -34,6 +35,10 @@ #include <memory> #include <chrono> +#if UPNP_VERSION < 10800 +#define UpnpDiscovery Upnp_Discovery +#endif + class ContentDirectoryService; class UPnPDiscoveryListener { @@ -59,10 +64,10 @@ class UPnPDeviceDirectory final : UpnpCallback { std::string device_id; std::chrono::steady_clock::duration expires; - DiscoveredTask(const Upnp_Discovery *disco) - :url(disco->Location), - device_id(disco->DeviceId), - expires(std::chrono::seconds(disco->Expires)) {} + DiscoveredTask(const UpnpDiscovery *disco) + :url(UpnpDiscovery_get_Location_cstr(disco)), + device_id(UpnpDiscovery_get_DeviceID_cstr(disco)), + expires(std::chrono::seconds(UpnpDiscovery_get_Expires(disco))) {} }; /** @@ -153,8 +158,8 @@ private: static void *Explore(void *); void Explore(); - int OnAlive(const Upnp_Discovery *disco); - int OnByeBye(const Upnp_Discovery *disco); + int OnAlive(const UpnpDiscovery *disco); + int OnByeBye(const UpnpDiscovery *disco); /* virtual methods from class UpnpCallback */ virtual int Invoke(Upnp_EventType et, const void *evp) override; |