diff options
author | Max Kellermann <max@duempel.org> | 2014-01-26 15:04:56 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-26 15:04:56 +0100 |
commit | bcc1f933702770c276e7353d71cb0c5fff75bc4a (patch) | |
tree | a7251a557d441353fcc630a8eba67b1e1c695efe /src/lib/upnp/upnpplib.cxx | |
parent | b161d723269d851a2d237880b8f5149b58b736c2 (diff) | |
download | mpd-bcc1f933702770c276e7353d71cb0c5fff75bc4a.tar.gz mpd-bcc1f933702770c276e7353d71cb0c5fff75bc4a.tar.xz mpd-bcc1f933702770c276e7353d71cb0c5fff75bc4a.zip |
upnp: add class UpnpCallback
Each Upnp*Async() call passes a new cookie pointer, and the cookie
passed to UpnpRegisterClient() appears to be ignored. Using this
interface is a more elegant approach than having one single "handler"
function.
Diffstat (limited to '')
-rw-r--r-- | src/lib/upnp/upnpplib.cxx | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lib/upnp/upnpplib.cxx b/src/lib/upnp/upnpplib.cxx index 475447dee..452c033d5 100644 --- a/src/lib/upnp/upnpplib.cxx +++ b/src/lib/upnp/upnpplib.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "upnpplib.hxx" +#include "Callback.hxx" #include "Domain.hxx" #include "Log.hxx" @@ -37,7 +38,7 @@ LibUPnP::LibUPnP() UpnpSetMaxContentLength(2000*1024); - code = UpnpRegisterClient(o_callback, (void *)this, &m_clh); + code = UpnpRegisterClient(o_callback, nullptr, &m_clh); if (code != UPNP_E_SUCCESS) { init_error.Format(upnp_domain, code, "UpnpRegisterClient() failed: %s", @@ -52,12 +53,14 @@ LibUPnP::LibUPnP() int LibUPnP::o_callback(Upnp_EventType et, void* evp, void* cookie) { - LibUPnP *ulib = (LibUPnP *)cookie; + if (cookie == nullptr) + /* this is the cookie passed to UpnpRegisterClient(); + but can this ever happen? Will libupnp ever invoke + the registered callback without that cookie? */ + return UPNP_E_SUCCESS; - if (ulib->handler) - ulib->handler(et, evp); - - return UPNP_E_SUCCESS; + UpnpCallback &callback = UpnpCallback::FromUpnpCookie(cookie); + return callback.Invoke(et, evp); } LibUPnP::~LibUPnP() |