[vlc-devel] [PATCH 1/3] Export services_discovery_RemoveAll

Edward Wang edward.c.wang at compdigitec.com
Wed Jan 11 01:12:16 CET 2012


---
 include/vlc_events.h              |    1 +
 include/vlc_services_discovery.h  |    2 +-
 lib/media_discoverer.c            |   24 ++++++++++++++++++++++++
 src/libvlccore.sym                |    1 +
 src/playlist/services_discovery.c |   28 ++++++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/include/vlc_events.h b/include/vlc_events.h
index 92193cc..9e37f7f 100644
--- a/include/vlc_events.h
+++ b/include/vlc_events.h
@@ -127,6 +127,7 @@ typedef enum vlc_event_type_t {
     /* Service Discovery event */
     vlc_ServicesDiscoveryItemAdded,
     vlc_ServicesDiscoveryItemRemoved,
+    vlc_ServicesDiscoveryItemRemoveAll,
     vlc_ServicesDiscoveryStarted,
     vlc_ServicesDiscoveryEnded
 } vlc_event_type_t;
diff --git a/include/vlc_services_discovery.h b/include/vlc_services_discovery.h
index 22df2fc..41be674 100644
--- a/include/vlc_services_discovery.h
+++ b/include/vlc_services_discovery.h
@@ -157,7 +157,7 @@ VLC_API vlc_event_manager_t * services_discovery_EventManager( services_discover
      * for more options, directly set the (meta) data on the input item */
 VLC_API void services_discovery_AddItem( services_discovery_t * p_this, input_item_t * p_item, const char * psz_category );
 VLC_API void services_discovery_RemoveItem( services_discovery_t * p_this, input_item_t * p_item );
-
+VLC_API void services_discovery_RemoveAll( services_discovery_t * p_sd );
 
 /* SD probing */
 
diff --git a/lib/media_discoverer.c b/lib/media_discoverer.c
index fcfb4b7..6fcefc5 100644
--- a/lib/media_discoverer.c
+++ b/lib/media_discoverer.c
@@ -129,6 +129,22 @@ static void services_discovery_item_removed( const vlc_event_t * p_event,
 }
 
 /**************************************************************************
+ *       services_discovery_removeall (Private) (VLC event callback)
+ **************************************************************************/
+static void services_discovery_removeall( const vlc_event_t * p_event,
+                                             void * user_data )
+{
+    libvlc_media_discoverer_t * p_mdis = user_data;
+
+    libvlc_media_list_lock( p_mdis->p_mlist );
+    for( int i = 0; i < libvlc_media_list_count( p_mdis->p_mlist ); i++ )
+    {
+        _libvlc_media_list_remove_index( p_mdis->p_mlist, i );
+    }
+    libvlc_media_list_unlock( p_mdis->p_mlist );
+}
+
+/**************************************************************************
  *       services_discovery_started (Private) (VLC event callback)
  **************************************************************************/
 
@@ -226,6 +242,10 @@ libvlc_media_discoverer_new_from_name( libvlc_instance_t * p_inst,
                       vlc_ServicesDiscoveryEnded,
                       services_discovery_ended,
                       p_mdis );
+    vlc_event_attach( services_discovery_EventManager( p_mdis->p_sd ),
+                      vlc_ServicesDiscoveryItemRemoveAll,
+                      services_discovery_removeall,
+                      p_mdis );
 
     /* Here we go */
     if( !vlc_sd_Start( p_mdis->p_sd ) )
@@ -265,6 +285,10 @@ libvlc_media_discoverer_release( libvlc_media_discoverer_t * p_mdis )
                      vlc_ServicesDiscoveryEnded,
                      services_discovery_ended,
                      p_mdis );
+    vlc_event_detach( services_discovery_EventManager( p_mdis->p_sd ),
+                     vlc_ServicesDiscoveryItemRemoveAll,
+                     services_discovery_removeall,
+                     p_mdis );
 
     libvlc_media_list_release( p_mdis->p_mlist );
 
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a2ea017..64f01fd 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -376,6 +376,7 @@ secstotimestr
 services_discovery_AddItem
 services_discovery_EventManager
 services_discovery_GetLocalizedName
+services_discovery_RemoveAll
 services_discovery_RemoveItem
 sout_AccessOutControl
 sout_AccessOutDelete
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index d8b93d6..c4229ce 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -120,6 +120,7 @@ services_discovery_t *vlc_sd_Create( vlc_object_t *p_super,
     vlc_event_manager_init( em, p_sd );
     vlc_event_manager_register_event_type(em, vlc_ServicesDiscoveryItemAdded);
     vlc_event_manager_register_event_type(em, vlc_ServicesDiscoveryItemRemoved);
+    vlc_event_manager_register_event_type(em, vlc_ServicesDiscoveryItemRemoveAll);
     vlc_event_manager_register_event_type(em, vlc_ServicesDiscoveryStarted);
     vlc_event_manager_register_event_type(em, vlc_ServicesDiscoveryEnded);
 
@@ -208,6 +209,19 @@ services_discovery_EventManager ( services_discovery_t * p_sd )
 }
 
 /*******************************************************************//**
+ * Remove all items from the Service Discovery listing
+ ***********************************************************************/
+void
+services_discovery_RemoveAll ( services_discovery_t * p_sd )
+{
+    vlc_event_t event;
+    event.type = vlc_ServicesDiscoveryItemRemoveAll;
+
+    vlc_event_send( &p_sd->event_manager, &event );
+    puts("Event sent");
+}
+
+/*******************************************************************//**
  * Add an item to the Service Discovery listing
  ***********************************************************************/
 void
@@ -306,6 +320,17 @@ static void playlist_sd_item_removed( const vlc_event_t * p_event, void * user_d
     PL_UNLOCK;
 }
 
+/* A request to remove all ideas from SD */
+static void playlist_sd_item_removeall( const vlc_event_t * p_event, void * user_data )
+{
+    playlist_item_t* p_sd_node = user_data;
+    if( p_sd_node == NULL ) return;
+    playlist_t* p_playlist = p_sd_node->p_playlist;
+    PL_LOCK;
+    playlist_NodeEmpty( p_playlist, p_sd_node, true );
+    PL_UNLOCK;
+}
+
 int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
                                    const char *psz_name )
 {
@@ -355,6 +380,9 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
     vlc_event_attach( em, vlc_ServicesDiscoveryItemRemoved,
                       playlist_sd_item_removed, p_node );
 
+    vlc_event_attach( em, vlc_ServicesDiscoveryItemRemoveAll,
+                      playlist_sd_item_removeall, p_node );
+
     if( !vlc_sd_Start( p_sd ) )
     {
         vlc_sd_Destroy( p_sd );
-- 
1.7.5.4




More information about the vlc-devel mailing list