[vlc-commits] upnp: the callback is always SD::MediaServerList::Callback() when used

Steve Lhomme git at videolan.org
Wed Jun 1 17:42:21 CEST 2016


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Wed Jun  1 16:38:08 2016 +0200| [8196bc794466c9400e1f8f58ad374d133fa7fefb] | committer: Jean-Baptiste Kempf

upnp: the callback is always SD::MediaServerList::Callback() when used

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8196bc794466c9400e1f8f58ad374d133fa7fefb
---

 modules/services_discovery/upnp.cpp |   20 ++++++++------------
 modules/services_discovery/upnp.hpp |    7 +++----
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index 7e88c12..2a10d84 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -241,7 +241,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
 
-    p_sys->p_upnp = UpnpInstanceWrapper::get( p_this, SD::MediaServerList::Callback, p_sys->p_server_list );
+    p_sys->p_upnp = UpnpInstanceWrapper::get( p_this, p_sys->p_server_list );
     if ( !p_sys->p_upnp )
     {
         delete p_sys->p_server_list;
@@ -643,9 +643,8 @@ void MediaServerList::removeServer( const std::string& udn )
 /*
  * Handles servers listing UPnP events
  */
-int MediaServerList::Callback( Upnp_EventType event_type, void* p_event, void* p_user_data )
+int MediaServerList::Callback( Upnp_EventType event_type, void* p_event, MediaServerList* self )
 {
-    MediaServerList* self = static_cast<MediaServerList*>( p_user_data );
     services_discovery_t* p_sd = self->m_sd;
 
     switch( event_type )
@@ -1210,7 +1209,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
 
     p_access->p_sys = p_sys;
-    p_sys->p_upnp = UpnpInstanceWrapper::get( p_this, NULL, NULL );
+    p_sys->p_upnp = UpnpInstanceWrapper::get( p_this, NULL );
     if ( !p_sys->p_upnp )
     {
         delete p_sys;
@@ -1235,7 +1234,6 @@ static void Close( vlc_object_t* p_this )
 UpnpInstanceWrapper::UpnpInstanceWrapper()
     : m_handle( -1 )
     , m_opaque( NULL )
-    , m_callback( NULL )
     , m_refcount( 0 )
 {
     vlc_mutex_init( &m_callback_lock );
@@ -1248,7 +1246,7 @@ UpnpInstanceWrapper::~UpnpInstanceWrapper()
     vlc_mutex_destroy( &m_callback_lock );
 }
 
-UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, Upnp_FunPtr callback, SD::MediaServerList *opaque)
+UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, SD::MediaServerList *opaque)
 {
     vlc_mutex_locker lock( &s_lock );
     if ( s_instance == NULL )
@@ -1298,12 +1296,11 @@ UpnpInstanceWrapper *UpnpInstanceWrapper::get(vlc_object_t *p_obj, Upnp_FunPtr c
     }
     s_instance->m_refcount++;
     // This assumes a single UPNP SD instance
-    if (callback && opaque)
+    if (opaque)
     {
         vlc_mutex_locker lock( &s_instance->m_callback_lock );
-        assert(!s_instance->m_callback && !s_instance->m_opaque);
+        assert(!s_instance->m_opaque);
         s_instance->m_opaque = opaque;
-        s_instance->m_callback = callback;
     }
     return s_instance;
 }
@@ -1314,7 +1311,6 @@ void UpnpInstanceWrapper::release(bool isSd)
     if ( isSd )
     {
         vlc_mutex_locker lock( &m_callback_lock );
-        m_callback = NULL;
         m_opaque = NULL;
     }
     if (--s_instance->m_refcount == 0)
@@ -1333,8 +1329,8 @@ int UpnpInstanceWrapper::Callback(Upnp_EventType event_type, void *p_event, void
 {
     UpnpInstanceWrapper* self = static_cast<UpnpInstanceWrapper*>( p_user_data );
     vlc_mutex_locker lock( &self->m_callback_lock );
-    if ( !self->m_callback )
+    if ( !self->m_opaque )
         return 0;
-    self->m_callback( event_type, p_event, self->m_opaque );
+    SD::MediaServerList::Callback( event_type, p_event, self->m_opaque );
     return 0;
 }
diff --git a/modules/services_discovery/upnp.hpp b/modules/services_discovery/upnp.hpp
index 4b46c52..65f1072 100644
--- a/modules/services_discovery/upnp.hpp
+++ b/modules/services_discovery/upnp.hpp
@@ -58,7 +58,7 @@ class UpnpInstanceWrapper
 {
 public:
     // This increases the refcount before returning the instance
-    static UpnpInstanceWrapper* get(vlc_object_t* p_obj, Upnp_FunPtr callback, SD::MediaServerList *opaque);
+    static UpnpInstanceWrapper* get(vlc_object_t* p_obj, SD::MediaServerList *opaque);
     void release(bool isSd);
     UpnpClient_Handle handle() const;
 
@@ -72,9 +72,8 @@ private:
     static UpnpInstanceWrapper* s_instance;
     static vlc_mutex_t s_lock;
     UpnpClient_Handle m_handle;
-    vlc_mutex_t m_callback_lock; // protect opaque_ and callback_
+    vlc_mutex_t m_callback_lock; // protect m_opaque
     SD::MediaServerList* m_opaque;
-    Upnp_FunPtr m_callback;
     int m_refcount;
 };
 
@@ -105,7 +104,7 @@ public:
     bool addServer(MediaServerDesc *desc );
     void removeServer(const std::string &udn );
     MediaServerDesc* getServer( const std::string& udn );
-    static int Callback( Upnp_EventType event_type, void* p_event, void* p_user_data );
+    static int Callback( Upnp_EventType event_type, void* p_event, MediaServerList* self );
 
 private:
     void parseNewServer( IXML_Document* doc, const std::string& location );



More information about the vlc-commits mailing list