]> git.sesse.net Git - vlc/blobdiff - src/modules/modules.c
Add new module_FindName function to find a module when given it's name. Use this...
[vlc] / src / modules / modules.c
index 2b495924f80a3d190c251422b5bfd2f3cdc9b0e9..c4a235598905af937926f276022fb1b12c202a0d 100644 (file)
@@ -85,6 +85,7 @@
 #include "vlc_stream.h"
 #include "vlc_access.h"
 #include "vlc_demux.h"
+#include "vlc_codec.h"
 
 #include "vlc_vout.h"
 #include "vlc_vout_synchro.h"
@@ -170,7 +171,7 @@ void __module_InitBank( vlc_object_t *p_this )
 {
     module_bank_t *p_bank = NULL;
     vlc_value_t  lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -195,13 +196,6 @@ void __module_InitBank( vlc_object_t *p_this )
     p_bank->b_cache = p_bank->b_cache_dirty =
         p_bank->b_cache_delete = VLC_FALSE;
 
-    /*
-     * Store the symbols to be exported
-     */
-#if defined (HAVE_DYNAMIC_PLUGINS) && !defined (HAVE_SHARED_LIBVLC)
-    STORE_SYMBOLS( &p_bank->symbols );
-#endif
-
     /* Everything worked, attach the object */
     p_libvlc_global->p_module_bank = p_bank;
     vlc_object_attach( p_bank, p_libvlc_global );
@@ -220,7 +214,7 @@ void __module_EndBank( vlc_object_t *p_this )
 {
     module_t * p_next = NULL;
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -308,7 +302,7 @@ void __module_EndBank( vlc_object_t *p_this )
 static void module_LoadMain( vlc_object_t *p_this )
 {
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -334,7 +328,7 @@ static void module_LoadMain( vlc_object_t *p_this )
 void __module_LoadBuiltins( vlc_object_t * p_this )
 {
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -362,7 +356,7 @@ void __module_LoadPlugins( vlc_object_t * p_this )
 {
 #ifdef HAVE_DYNAMIC_PLUGINS
     vlc_value_t lockval;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     var_Create( p_libvlc_global, "libvlc", VLC_VAR_MUTEX );
     var_Get( p_libvlc_global, "libvlc", &lockval );
@@ -389,6 +383,38 @@ void __module_LoadPlugins( vlc_object_t * p_this )
 #endif
 }
 
+/*****************************************************************************
+ * module_IsCapable: checks whether a module implements a capability.
+ *****************************************************************************/
+vlc_bool_t module_IsCapable( const module_t *m, const char *cap )
+{
+    return !strcmp( m->psz_capability, cap );
+}
+
+/*****************************************************************************
+ * module_GetObjName: internal name of a module.
+ *****************************************************************************/
+const char *module_GetObjName( const module_t *m )
+{
+    return m->psz_object_name;
+}
+
+/*****************************************************************************
+ * module_GetName: human-friendly name of a module.
+ *****************************************************************************/
+const char *module_GetName( const module_t *m, vlc_bool_t long_name )
+{
+    if( long_name && ( m->psz_longname != NULL) )
+        return m->psz_longname;
+    
+    return m->psz_shortname ?: m->psz_object_name;
+}
+
+const char *module_GetHelp( const module_t *m )
+{
+    return m->psz_help;
+}
+
 /*****************************************************************************
  * module_Need: return the best module function, given a capability list.
  *****************************************************************************
@@ -485,7 +511,7 @@ module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
         p_module = (module_t *)p_all->p_values[i_which_module].p_object;
 
         /* Test that this module can do what we need */
-        if( strcmp( p_module->psz_capability, psz_capability ) )
+        if( !module_IsCapable( p_module, psz_capability ) )
         {
             /* Don't recurse through the sub-modules because vlc_list_find()
              * will list them anyway. */
@@ -740,27 +766,46 @@ void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
 }
 
 /*****************************************************************************
- * module_Exists: tell if a module exists.
- *****************************************************************************
- * This function is a boolean function that tells if a module exist or not.
+ * module_FindName: get a pointer to a module_t given it's name.
  *****************************************************************************/
-
-vlc_bool_t __module_Exists(  vlc_object_t *p_this, const char * psz_name )
+module_t *__module_FindName( vlc_object_t *p_this, const char * psz_name )
 {
     vlc_list_t *p_list;
     int i;
     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
     for( i = 0 ; i < p_list->i_count; i++)
     {
-        const char *psz_module_name =
-            ((module_t *) p_list->p_values[i].p_object)->psz_shortname;
+        module_t *p_module = ((module_t *) p_list->p_values[i].p_object);
+        const char *psz_module_name = p_module->psz_object_name;
         if( psz_module_name && !strcmp( psz_module_name, psz_name ) )
         {
             /* We can release the list, and return yes */
-            vlc_list_release( p_list ); return VLC_TRUE;
+            vlc_list_release( p_list );
+            vlc_object_yield( p_module );
+            return p_module;
         }
     }
-    vlc_list_release( p_list ); return VLC_FALSE;
+    vlc_list_release( p_list );
+    return NULL;
+}
+
+/*****************************************************************************
+ * module_Exists: tell if a module exists.
+ *****************************************************************************
+ * This function is a boolean function that tells if a module exist or not.
+ *****************************************************************************/
+vlc_bool_t __module_Exists(  vlc_object_t *p_this, const char * psz_name )
+{
+    module_t *p_module = __module_FindName( p_this, psz_name );
+    if( p_module )
+    {
+        vlc_object_release( p_module );
+        return VLC_TRUE;
+    }
+    else
+    {
+        return VLC_FALSE;
+    }
 }
 
 
@@ -804,7 +849,7 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
 #endif
         {
             if( 0>= asprintf( &psz_fullpath, "%s"DIR_SEP"%s",
-                              vlc_global( p_this )->psz_vlcpath, *ppsz_path) )
+                              vlc_global()->psz_vlcpath, *ppsz_path) )
                 psz_fullpath = NULL;
         }
         else
@@ -1066,7 +1111,7 @@ static int AllocatePluginFile( vlc_object_t * p_this, char * psz_file,
 
     if( p_module )
     {
-        libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+        libvlc_global_data_t *p_libvlc_global = vlc_global();
 
         /* Everything worked fine !
          * The module is ready to be added to the list. */
@@ -1205,7 +1250,7 @@ static void UndupModule( module_t *p_module )
     }
 
     free( (void*)p_module->psz_object_name );
-    free( (void*)p_module->psz_capability );
+    free( p_module->psz_capability );
     free( (void*)p_module->psz_shortname );
     free( (void*)p_module->psz_longname );
     free( (void*)p_module->psz_help );
@@ -1251,7 +1296,7 @@ static int AllocateBuiltinModule( vlc_object_t * p_this,
     /* msg_Dbg( p_this, "builtin \"%s\", %s",
                 p_module->psz_object_name, p_module->psz_longname ); */
 
-    vlc_object_attach( p_module, vlc_global( p_this )->p_module_bank );
+    vlc_object_attach( p_module, vlc_global()->p_module_bank );
 
     return 0;
 }
@@ -1627,7 +1672,7 @@ static void CacheLoad( vlc_object_t *p_this )
     int i_cache;
     module_cache_t **pp_cache = 0;
     int32_t i_file_size, i_marker;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     psz_homedir = p_this->p_libvlc->psz_homedir;
     if( !psz_homedir )
@@ -1636,8 +1681,8 @@ static void CacheLoad( vlc_object_t *p_this )
         return;
     }
 
-    i_size = asprintf( &psz_filename, "%s/%s/%s/%s", psz_homedir, CONFIG_DIR,
-                       PLUGINSCACHE_DIR, CacheName() );
+    i_size = asprintf( &psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s"DIR_SEP"%s",
+            psz_homedir, CONFIG_DIR, PLUGINSCACHE_DIR, CacheName() );
     if( i_size <= 0 )
     {
         msg_Err( p_this, "out of memory" );
@@ -1981,7 +2026,7 @@ static void CacheSave( vlc_object_t *p_this )
     int i, j, i_cache;
     module_cache_t **pp_cache;
     int32_t i_file_size = 0;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     psz_homedir = p_this->p_libvlc->psz_homedir;
     if( !psz_homedir )
@@ -1990,7 +2035,7 @@ static void CacheSave( vlc_object_t *p_this )
         return;
     }
     psz_filename =
-       (char *)malloc( sizeof("/" CONFIG_DIR "/" PLUGINSCACHE_DIR "/" ) +
+       (char *)malloc( sizeof(DIR_SEP CONFIG_DIR DIR_SEP PLUGINSCACHE_DIR DIR_SEP ) +
                        strlen(psz_homedir) + strlen(CacheName()) );
 
     if( !psz_filename )
@@ -1999,15 +2044,15 @@ static void CacheSave( vlc_object_t *p_this )
         return;
     }
 
-    sprintf( psz_filename, "%s/%s", psz_homedir, CONFIG_DIR );
+    sprintf( psz_filename, "%s"DIR_SEP"%s", psz_homedir, CONFIG_DIR );
 
     config_CreateDir( p_this, psz_filename );
 
-    strcat( psz_filename, "/" PLUGINSCACHE_DIR );
+    strcat( psz_filename, DIR_SEP PLUGINSCACHE_DIR );
 
     config_CreateDir( p_this, psz_filename );
 
-    strcat( psz_filename, "/CACHEDIR.TAG" );
+    strcat( psz_filename, DIR_SEP"CACHEDIR.TAG" );
 
     file = utf8_fopen( psz_filename, "wb" );
     if( file )
@@ -2016,7 +2061,7 @@ static void CacheSave( vlc_object_t *p_this )
         fclose( file );
     }
 
-    sprintf( psz_filename, "%s/%s/%s/%s", psz_homedir, CONFIG_DIR,
+    sprintf( psz_filename, "%s"DIR_SEP"%s"DIR_SEP"%s"DIR_SEP"%s", psz_homedir, CONFIG_DIR,
              PLUGINSCACHE_DIR, CacheName() );
 
     msg_Dbg( p_this, "saving plugins cache file %s", psz_filename );
@@ -2206,9 +2251,6 @@ static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
 
     p_cache->pf_activate = p_module->pf_activate;
     p_cache->pf_deactivate = p_module->pf_deactivate;
-#ifndef HAVE_SHARED_LIBVLC
-    p_cache->p_symbols = p_module->p_symbols;
-#endif
     p_cache->handle = p_module->handle;
 
     for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
@@ -2217,9 +2259,6 @@ static void CacheMerge( vlc_object_t *p_this, module_t *p_cache,
         module_t *p_cchild = (module_t*)p_cache->pp_children[i_submodule];
         p_cchild->pf_activate = p_child->pf_activate;
         p_cchild->pf_deactivate = p_child->pf_deactivate;
-#ifndef HAVE_SHARED_LIBVLC
-        p_cchild->p_symbols = p_child->p_symbols;
-#endif
     }
 
     p_cache->b_loaded = VLC_TRUE;
@@ -2234,7 +2273,7 @@ static module_cache_t *CacheFind( vlc_object_t *p_this, char *psz_file,
 {
     module_cache_t **pp_cache;
     int i_cache, i;
-    libvlc_global_data_t *p_libvlc_global = vlc_global( p_this );
+    libvlc_global_data_t *p_libvlc_global = vlc_global();
 
     pp_cache = p_libvlc_global->p_module_bank->pp_loaded_cache;
     i_cache = p_libvlc_global->p_module_bank->i_loaded_cache;