[vlc-devel] [PATCH] sd_GetNames -> foo_PluginsGetNames ?

Francois Cartegnie fcvlcdev at free.fr
Sat Mar 30 17:54:41 CET 2013


I was looking for a way to list lua plugins (for UI and probably
also useful for an updater).

I've noticed that could be done just by refactoring sd_GetNames code.
Any opinion ?

Francois

---
 include/vlc_playlist.h            |    4 +++-
 modules/lua/vlc.c                 |   19 +++++++++++++++++--
 src/libvlccore.sym                |    1 +
 src/playlist/services_discovery.c |   26 +++++++++++++++++++++-----
 4 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index 10108cb..8afd402 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -332,7 +332,9 @@ VLC_API bool playlist_IsServicesDiscoveryLoaded( playlist_t *,const char *) VLC_
 /** Query a services discovery */
 VLC_API int playlist_ServicesDiscoveryControl( playlist_t *, const char *, int, ... );
 
-
+/* Get the available playlist modules names, in a null
+ * terminated string array. Array and string must be freed after use. */
+VLC_API char ** playlist_PluginsGetNames( vlc_object_t *, char ***, int ** ) VLC_USED;
 
 /********************************************************
  * Item management
diff --git a/modules/lua/vlc.c b/modules/lua/vlc.c
index 90ea73e..443f9d7 100644
--- a/modules/lua/vlc.c
+++ b/modules/lua/vlc.c
@@ -79,6 +79,7 @@
     "(\"telnet://0.0.0.0:4212\")" )
 
 static int vlc_sd_probe_Open( vlc_object_t * );
+static int vlc_playlist_probe_Open( vlc_object_t * );
 
 vlc_module_begin ()
         set_shortname( N_("Lua") )
@@ -172,6 +173,10 @@ vlc_module_begin ()
             change_volatile()
         set_callbacks( Open_LuaSD, Close_LuaSD )
 
+    add_submodule ()
+        set_capability( "playlist probe", 100 )
+        set_callbacks( vlc_playlist_probe_Open, NULL )
+
     VLC_SD_PROBE_SUBMODULE
 
 vlc_module_end ()
@@ -595,7 +600,7 @@ int vlclua_playlist_add_internal( vlc_object_t *p_this, lua_State *L,
     return i_count;
 }
 
-static int vlc_sd_probe_Open( vlc_object_t *obj )
+static int vlc_probe_Open( vlc_object_t *obj, const char *psz_type )
 {
     vlc_probe_t *probe = (vlc_probe_t *)obj;
     char **ppsz_filelist = NULL;
@@ -605,7 +610,7 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
     char **ppsz_dir_list = NULL;
     char **ppsz_dir;
     lua_State *L = NULL;
-    vlclua_dir_list( "sd", &ppsz_dir_list );
+    vlclua_dir_list( psz_type, &ppsz_dir_list );
     for( ppsz_dir = ppsz_dir_list; *ppsz_dir; ppsz_dir++ )
     {
         int i_files;
@@ -723,6 +728,16 @@ error:
     return VLC_ENOMEM;
 }
 
+static int vlc_sd_probe_Open( vlc_object_t *obj )
+{
+    return vlc_probe_Open( obj, "sd" );
+}
+
+static int vlc_playlist_probe_Open( vlc_object_t *obj )
+{
+    return vlc_probe_Open( obj, "playlist" );
+}
+
 static int vlclua_add_modules_path_inner( lua_State *L, const char *psz_path )
 {
     int count = 0;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 25d83c5..3af8bf4 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -326,6 +326,7 @@ playlist_NodeCreate
 playlist_NodeDelete
 playlist_NodeInsert
 playlist_NodeRemoveItem
+playlist_PluginsGetNames
 playlist_PreparseEnqueue
 playlist_RecursiveNodeSort
 playlist_ServicesDiscoveryAdd
diff --git a/src/playlist/services_discovery.c b/src/playlist/services_discovery.c
index e413f9b..e6093a4 100644
--- a/src/playlist/services_discovery.c
+++ b/src/playlist/services_discovery.c
@@ -58,13 +58,11 @@ int vlc_sd_probe_Add (vlc_probe_t *probe, const char *name,
 
 #undef vlc_sd_GetNames
 
-/**
- * Gets the list of available services discovery plugins.
- */
-char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_categories)
+static char **probe_plugins (vlc_object_t *obj, char ***pppsz_longnames,
+                             int **pp_categories, char *psz_type)
 {
     size_t count;
-    vlc_sd_probe_t *tab = vlc_probe (obj, "services probe", &count);
+    vlc_sd_probe_t *tab = vlc_probe (obj, psz_type, &count);
 
     if (count == 0)
     {
@@ -93,6 +91,22 @@ char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_cat
     return names;
 }
 
+/**
+ * Gets the list of available services discovery plugins.
+ */
+char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_categories)
+{
+    return probe_plugins( obj, pppsz_longnames, pp_categories, "services probe" );
+}
+
+/**
+ * Gets the list of playlist plugins.
+ */
+char **playlist_PluginsGetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_categories)
+{
+    return probe_plugins( obj, pppsz_longnames, pp_categories, "playlist probe" );
+}
+
 
 static void services_discovery_Destructor ( vlc_object_t *p_obj );
 
@@ -507,3 +521,5 @@ void playlist_ServicesDiscoveryKillAll( playlist_t *p_playlist )
         playlist_ServicesDiscoveryRemove( p_playlist,
                                           priv->pp_sds[0]->psz_name );
 }
+
+VLC_API char ** playlist_PluginsGetNames( vlc_object_t *, char ***, int ** ) VLC_USED;
-- 
1.7.9




More information about the vlc-devel mailing list