]> git.sesse.net Git - vlc/commitdiff
* ALL: brought back module_EndBank() from the dead and fixed a few bugs in libvlc.c.
authorGildas Bazin <gbazin@videolan.org>
Tue, 1 Jun 2004 15:45:07 +0000 (15:45 +0000)
committerGildas Bazin <gbazin@videolan.org>
Tue, 1 Jun 2004 15:45:07 +0000 (15:45 +0000)
include/configuration.h
include/modules.h
src/libvlc.c
src/misc/configuration.c
src/misc/modules.c

index 664e5b1d96303dfb5acec570eb6193e9b6eab0c3..cafc3dd6a523657194382eb8e45ffc5b0ca24a8b 100644 (file)
@@ -4,9 +4,9 @@
  * It includes functions allowing to declare, get or set configuration options.
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: configuration.h,v 1.35 2004/01/29 17:04:01 gbazin Exp $
+ * $Id$
  *
- * Authors: Gildas Bazin <gbazin@netcourrier.com>
+ * Authors: Gildas Bazin <gbazin@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -130,6 +130,9 @@ VLC_EXPORT( void, config_UnsetCallbacks, ( module_config_t * ) );
 #define config_SaveConfigFile(a,b) __config_SaveConfigFile(VLC_OBJECT(a),b)
 #define config_ResetAll(a) __config_ResetAll(VLC_OBJECT(a))
 
+/* internal only */
+int config_CreateDir( vlc_object_t *, char * );
+
 /*****************************************************************************
  * Macros used to build the configuration structure.
  *
index e07f0cf9e779177e825173b3d41dc1c13538ee0f..e6f21e74efbeb2a3545d56a04c943b1a38c0e934 100644 (file)
@@ -54,6 +54,7 @@ struct module_bank_t
 {
     VLC_COMMON_MEMBERS
 
+    int              i_usage;
     module_symbols_t symbols;
 
     /* Plugins cache */
index cdcfd52c2e03a489129047005afe99fea6378bb5..badb6a27618bf01003e227a5a3a660f32a16f14f 100644 (file)
@@ -246,7 +246,6 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     vlc_t *      p_vlc = vlc_current_object( i_object );
     module_t    *p_help_module;
     playlist_t  *p_playlist;
-    vlc_value_t  lockval;
 
     if( !p_vlc )
     {
@@ -285,22 +284,13 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
      * main module. We need to do this at this stage to be able to display
      * a short help if required by the user. (short help == main module
      * options) */
-    var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
-    var_Get( p_libvlc, "libvlc", &lockval );
-    vlc_mutex_lock( lockval.p_address );
-    if( libvlc.p_module_bank == NULL )
-    {
-        module_InitBank( p_vlc );
-        module_LoadMain( p_vlc );
-    }
-    vlc_mutex_unlock( lockval.p_address );
-    var_Destroy( p_libvlc, "libvlc" );
+    module_InitBank( p_vlc );
 
     /* Hack: insert the help module here */
     p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
     if( p_help_module == NULL )
     {
-        /*module_EndBank( p_vlc );*/
+        module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_EGENERIC;
     }
@@ -315,7 +305,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         vlc_object_detach( p_help_module );
         config_Free( p_help_module );
         vlc_object_destroy( p_help_module );
-        /*module_EndBank( p_vlc );*/
+        module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_EGENERIC;
     }
@@ -354,7 +344,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     {
         config_Free( p_help_module );
         vlc_object_destroy( p_help_module );
-        /*module_EndBank( p_vlc );*/
+        module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_EEXIT;
     }
@@ -372,6 +362,8 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     psz_language = config_GetPsz( p_vlc, "language" );
     if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
     {
+        vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
+
         /* Reset the default domain */
         SetLanguage( psz_language );
 
@@ -386,8 +378,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
 
         module_EndBank( p_vlc );
         module_InitBank( p_vlc );
-        module_LoadMain( p_vlc );
+        config_LoadConfigFile( p_vlc, "main" );
         config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
+        libvlc.p_module_bank->b_cache_delete = b_cache_delete;
     }
     if( psz_language ) free( psz_language );
 #endif
@@ -458,7 +451,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
     {
         config_Free( p_help_module );
         vlc_object_destroy( p_help_module );
-        /*module_EndBank( p_vlc );*/
+        module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_EEXIT;
     }
@@ -487,7 +480,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         vlc_object_detach( p_help_module );
         config_Free( p_help_module );
         vlc_object_destroy( p_help_module );
-        /*module_EndBank( p_vlc );*/
+        module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_EGENERIC;
     }
@@ -598,7 +591,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
         {
             module_Unneed( p_vlc, p_vlc->p_memcpy_module );
         }
-        /*module_EndBank( p_vlc );*/
+        module_EndBank( p_vlc );
         if( i_object ) vlc_object_release( p_vlc );
         return VLC_EGENERIC;
     }
@@ -736,7 +729,7 @@ int VLC_Destroy( int i_object )
     }
 
     /*
-     * XXX: Free module bank !
+     * Free module bank !
      */
     module_EndBank( p_vlc );
 
index d06b7ac7b1f15665e8bb2788dce94daa4d86f129..0f7526e91a2dd118ade1cf1f2156152779b67a41 100644 (file)
@@ -910,7 +910,7 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
 }
 
 /*****************************************************************************
- * config_CreateConfigDir: Create configuration directory if it doesn't exist.
+ * config_CreateDir: Create configuration directory if it doesn't exist.
  *****************************************************************************/
 int config_CreateDir( vlc_object_t *p_this, char *psz_dirname )
 {
index 2f44dd560b90a88855cf7ed307580b1c910f6b9c..c29e884336513a6d47cbdad865087b5deeda46d5 100644 (file)
@@ -168,9 +168,24 @@ static char * GetWindowsError  ( void );
 void __module_InitBank( vlc_object_t *p_this )
 {
     module_bank_t *p_bank;
+    vlc_value_t  lockval;
+
+    var_Create( p_this->p_libvlc, "libvlc", VLC_VAR_MUTEX );
+    var_Get( p_this->p_libvlc, "libvlc", &lockval );
+    vlc_mutex_lock( lockval.p_address );
+    if( p_this->p_libvlc->p_module_bank )
+    {
+        p_this->p_libvlc->p_module_bank->i_usage++;
+        vlc_mutex_unlock( lockval.p_address );
+        var_Destroy( p_this->p_libvlc, "libvlc" );
+        return;
+    }
+    vlc_mutex_unlock( lockval.p_address );
+    var_Destroy( p_this->p_libvlc, "libvlc" );
 
     p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
     p_bank->psz_object_name = "module bank";
+    p_bank->i_usage = 1;
     p_bank->i_cache = p_bank->i_loaded_cache = 0;
     p_bank->pp_cache = p_bank->pp_loaded_cache = 0;
     p_bank->b_cache = p_bank->b_cache_dirty =
@@ -187,6 +202,8 @@ void __module_InitBank( vlc_object_t *p_this )
     p_this->p_libvlc->p_module_bank = p_bank;
     vlc_object_attach( p_bank, p_this->p_libvlc );
 
+    module_LoadMain( p_this );
+
     return;
 }
 
@@ -211,6 +228,25 @@ void __module_ResetBank( vlc_object_t *p_this )
 void __module_EndBank( vlc_object_t *p_this )
 {
     module_t * p_next;
+    vlc_value_t  lockval;
+
+    var_Create( p_this->p_libvlc, "libvlc", VLC_VAR_MUTEX );
+    var_Get( p_this->p_libvlc, "libvlc", &lockval );
+    vlc_mutex_lock( lockval.p_address );
+    if( !p_this->p_libvlc->p_module_bank )
+    {
+        vlc_mutex_unlock( lockval.p_address );
+        var_Destroy( p_this->p_libvlc, "libvlc" );
+        return;
+    }
+    if( --p_this->p_libvlc->p_module_bank->i_usage )
+    {
+        vlc_mutex_unlock( lockval.p_address );
+        var_Destroy( p_this->p_libvlc, "libvlc" );
+        return;
+    }
+    vlc_mutex_unlock( lockval.p_address );
+    var_Destroy( p_this->p_libvlc, "libvlc" );
 
 #ifdef HAVE_DYNAMIC_PLUGINS
     if( p_this->p_libvlc->p_module_bank->b_cache ) CacheSave( p_this );