From 38e64d08f8cd47d2deca7fdd90c16daf1f4116bb Mon Sep 17 00:00:00 2001
From: Fabio Ritrovato <exsephiroth87@gmail.com>
Date: Sat, 28 Mar 2009 16:52:19 +0100
Subject: [PATCH] GSoC: MTP - Expand SD functionalities

---
 include/vlc_events.h              |   19 +++++++++++++++++--
 include/vlc_playlist.h            |    2 ++
 include/vlc_services_discovery.h  |    2 ++
 src/libvlccore.sym                |    1 +
 src/misc/events.c                 |   14 ++++++++------
 src/playlist/services_discovery.c |   29 +++++++++++++++++++++++++----
 6 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/include/vlc_events.h b/include/vlc_events.h
index cba7fb9..2bf1397 100644
--- a/include/vlc_events.h
+++ b/include/vlc_events.h
@@ -129,7 +129,10 @@ typedef enum vlc_event_type_t {
     vlc_ServicesDiscoveryItemAdded,
     vlc_ServicesDiscoveryItemRemoved,
     vlc_ServicesDiscoveryStarted,
-    vlc_ServicesDiscoveryEnded
+    vlc_ServicesDiscoveryEnded,
+    vlc_ServicesDiscoveryItemPut,
+    vlc_ServicesDiscoveryItemGet,
+    vlc_ServicesDiscoveryItemDelete
 } vlc_event_type_t;
 
 /* Event definition */
@@ -197,7 +200,19 @@ typedef struct vlc_event_t
         {
             void * unused;
         } services_discovery_ended;
-
+        struct vlc_services_discovery_item_put
+        {
+            char *psz_string;
+        } services_discovery_item_put;
+        struct vlc_services_discovery_item_get
+        {
+            input_item_t *p_item;
+            char *psz_string;
+        } services_discovery_item_get;
+        struct vlc_services_discovery_item_delete
+        {
+            input_item_t *p_item;
+        } services_discovery_item_delete;
     } u;
 } vlc_event_t;
 
diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index fc2b808..5e35abd 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -314,6 +314,8 @@ VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
 VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
 /** Check whether a given SD is loaded */
 VLC_EXPORT( bool, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
+/** Return a service discovery module by his playlist Id */
+VLC_EXPORT( services_discovery_t *, playlist_ServiceDiscoveryGetById, ( playlist_t *, int ) );
 
 
 
diff --git a/include/vlc_services_discovery.h b/include/vlc_services_discovery.h
index d647b61..51c98c3 100644
--- a/include/vlc_services_discovery.h
+++ b/include/vlc_services_discovery.h
@@ -48,6 +48,8 @@ struct services_discovery_t
     vlc_event_manager_t event_manager;      /* Accessed through Setters for non class function */
 
     services_discovery_sys_t *p_sys;
+
+    bool b_read_only;
 };
 
 /***********************************************************************
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 49be4e6..f5deba0 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -303,6 +303,7 @@ playlist_NodeRemoveItem
 playlist_PreparseEnqueue
 playlist_RecursiveNodeSort
 playlist_ServicesDiscoveryAdd
+playlist_ServiceDiscoveryGetById
 playlist_ServicesDiscoveryRemove
 playlist_Status
 playlist_TreeMove
diff --git a/src/misc/events.c b/src/misc/events.c
index 9d7602a..79cc74c 100644
--- a/src/misc/events.c
+++ b/src/misc/events.c
@@ -66,7 +66,7 @@ typedef struct vlc_event_listeners_group_t
       Correctly when vlc_event_detach was called during
       a callback */
     bool          b_sublistener_removed;
-                                         
+
 } vlc_event_listeners_group_t;
 
 #ifdef DEBUG_EVENT
@@ -86,7 +86,10 @@ static const char ppsz_event_type_to_name[][40] =
     [vlc_ServicesDiscoveryItemAdded]    = "vlc_ServicesDiscoveryItemAdded",
     [vlc_ServicesDiscoveryItemRemoved]  = "vlc_ServicesDiscoveryItemRemoved",
     [vlc_ServicesDiscoveryStarted]      = "vlc_ServicesDiscoveryStarted",
-    [vlc_ServicesDiscoveryEnded]        = "vlc_ServicesDiscoveryEnded"
+    [vlc_ServicesDiscoveryEnded]        = "vlc_ServicesDiscoveryEnded",
+    [vlc_ServicesDiscoveryPut]          = "vlc_ServicesDiscoveryPut",
+    [vlc_ServicesDiscoveryGet]          = "vlc_ServicesDiscoveryGet",
+    [vlc_ServicesDiscoveryDelete]       = "vlc_ServicesDiscoveryDelete",
 };
 #endif
 
@@ -175,7 +178,7 @@ int vlc_event_manager_register_event_type(
 
     listeners_group->event_type = event_type;
     ARRAY_INIT( listeners_group->listeners );
- 
+
     vlc_mutex_lock( &p_em->object_lock );
     ARRAY_APPEND( p_em->listeners_groups, listeners_group );
     vlc_mutex_unlock( &p_em->object_lock );
@@ -228,7 +231,7 @@ void vlc_event_send( vlc_event_manager_t * p_em,
         }
     FOREACH_END()
     vlc_mutex_unlock( &p_em->object_lock );
- 
+
     /* Call the function attached */
     cached_listener = array_of_cached_listeners;
 
@@ -292,7 +295,7 @@ int __vlc_event_attach( vlc_event_manager_t * p_em,
     listener = malloc(sizeof(vlc_event_listener_t));
     if( !listener )
         return VLC_ENOMEM;
- 
+
     listener->p_user_data = p_user_data;
     listener->pf_callback = pf_callback;
 #ifdef DEBUG_EVENT
@@ -377,4 +380,3 @@ int vlc_event_detach( vlc_event_manager_t *p_em,
 
     return VLC_EGENERIC;
 }
-
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index ab69fb5..8dd5221 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -61,6 +61,8 @@ services_discovery_t *vlc_sd_Create( vlc_object_t *p_super )
     if( !p_sd )
         return NULL;
 
+    p_sd->b_read_only = true;
+
     vlc_event_manager_init( &p_sd->event_manager, p_sd, (vlc_object_t *)p_sd );
     vlc_event_manager_register_event_type( &p_sd->event_manager,
             vlc_ServicesDiscoveryItemAdded );
@@ -90,14 +92,14 @@ bool vlc_sd_Start ( services_discovery_t * p_sd, const char *module )
         msg_Err( p_sd, "no suitable services discovery module" );
         return false;
     }
-        
+
     vlc_event_t event = {
         .type = vlc_ServicesDiscoveryStarted
     };
     vlc_event_send( &p_sd->event_manager, &event );
     return true;
 }
-                          
+
 /***********************************************************************
  * Stop
  ***********************************************************************/
@@ -106,7 +108,7 @@ void vlc_sd_Stop ( services_discovery_t * p_sd )
     vlc_event_t event = {
         .type = vlc_ServicesDiscoveryEnded
     };
-    
+
     vlc_event_send( &p_sd->event_manager, &event );
 
     module_unneed( p_sd, p_sd->p_module );
@@ -264,7 +266,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, const char *psz_modul
     vlc_event_attach( services_discovery_EventManager( p_sd ),
                       vlc_ServicesDiscoveryItemAdded,
                       playlist_sd_item_added, p_one );
-        
+
     vlc_event_attach( services_discovery_EventManager( p_sd ),
                       vlc_ServicesDiscoveryItemAdded,
                       playlist_sd_item_added, p_cat );
@@ -380,6 +382,25 @@ bool playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
     return false;
 }
 
+services_discovery_t * playlist_ServiceDiscoveryGetById( playlist_t *p_playlist,
+                                                       int i_id )
+{
+    int i;
+    PL_LOCK;
+
+    for( i = 0 ; i< pl_priv(p_playlist)->i_sds ; i ++ )
+    {
+        if( i_id == pl_priv(p_playlist)->pp_sds[i]->p_cat->i_id ||
+            i_id == pl_priv(p_playlist)->pp_sds[i]->p_one->i_id )
+        {
+            PL_UNLOCK;
+            return pl_priv(p_playlist)->pp_sds[i]->p_sd;
+        }
+    }
+    PL_UNLOCK;
+    return NULL;
+}
+
 void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist )
 {
     while( pl_priv(p_playlist)->i_sds > 0 )
-- 
1.5.4.3

