]> git.sesse.net Git - vlc/commitdiff
* ./include/modules_inner.h, ./src/misc/configuration.c: support for config
authorSam Hocevar <sam@videolan.org>
Fri, 3 May 2002 20:49:30 +0000 (20:49 +0000)
committerSam Hocevar <sam@videolan.org>
Fri, 3 May 2002 20:49:30 +0000 (20:49 +0000)
    options callbacks.

    They don't take any argument for the moment, but this will change when
    I'm finished with my other vlc changes. There is a little problem: the
    Gtk+ interface keeps calling Put***Variable each time we click on "Apply"
    or "Save". I think it should only call it once. Is there a way to fix
    this? Gildas? lool? :-)

include/common.h
include/configuration.h
include/modules_inner.h
src/misc/configuration.c
src/misc/modules_plugin.h

index e2e2bc4e73ab776c2a90759fa67bfa935ff0154f..76480003e531554bc628c4ce37404238def48adf 100644 (file)
@@ -3,7 +3,7 @@
  * Collection of useful common types and macros definitions
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: common.h,v 1.102 2002/04/27 22:11:22 gbazin Exp $
+ * $Id: common.h,v 1.103 2002/05/03 20:49:30 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@via.ecp.fr>
  *          Vincent Seguin <seguin@via.ecp.fr>
@@ -534,6 +534,9 @@ typedef struct module_symbols_s
     int    ( * config_SaveConfigFile )   ( const char * );
     struct module_config_s * ( * config_FindConfig ) ( const char * );
     struct module_config_s * ( * config_Duplicate ) ( struct module_config_s* );
+    void   ( * config_SetCallbacks )     ( struct module_config_s *,
+                                           struct module_config_s * );
+    void   ( * config_UnsetCallbacks )   ( struct module_config_s * );
 
     struct intf_subscription_s * ( * intf_MsgSub ) ( void );
     void ( * intf_MsgUnsub )   ( struct intf_subscription_s * );
index 31ed23e1536bb260efdb27df1b2f3125fdefd8f3..650fa1ab337d9f6099c6d0598003acd45a05c890 100644 (file)
@@ -4,7 +4,7 @@
  * It includes functions allowing to declare, get or set configuration options.
  *****************************************************************************
  * Copyright (C) 1999, 2000 VideoLAN
- * $Id: configuration.h,v 1.9 2002/04/24 00:36:24 sam Exp $
+ * $Id: configuration.h,v 1.10 2002/05/03 20:49:30 sam Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -73,13 +73,16 @@ void   config_PutIntVariable( const char *psz_name, int i_value );
 void   config_PutFloatVariable( const char *psz_name, float f_value );
 void   config_PutPszVariable( const char *psz_name, char *psz_value );
 
-int config_LoadConfigFile( const char *psz_module_name );
-int config_SaveConfigFile( const char *psz_module_name );
-module_config_t *config_FindConfig( const char *psz_name );
-module_config_t *config_Duplicate ( module_config_t * );
-char *config_GetHomeDir( void );
-int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
-                        boolean_t b_ignore_errors );
+int    config_LoadConfigFile( const char *psz_module_name );
+int    config_SaveConfigFile( const char *psz_module_name );
+char * config_GetHomeDir( void );
+int    config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
+                           boolean_t b_ignore_errors );
+
+module_config_t *config_Duplicate     ( module_config_t * );
+module_config_t *config_FindConfig    ( const char * );
+void             config_SetCallbacks  ( module_config_t *, module_config_t * );
+void             config_UnsetCallbacks( module_config_t * );
 
 #else
 #   define config_GetIntVariable p_symbols->config_GetIntVariable
@@ -88,10 +91,12 @@ int config_LoadCmdLine( int *pi_argc, char *ppsz_argv[],
 #   define config_PutFloatVariable p_symbols->config_PutFloatVariable
 #   define config_GetPszVariable p_symbols->config_GetPszVariable
 #   define config_PutPszVariable p_symbols->config_PutPszVariable
-#   define config_Duplicate      p_symbols->config_Duplicate
-#   define config_FindConfig     p_symbols->config_FindConfig
 #   define config_LoadConfigFile p_symbols->config_LoadConfigFile
 #   define config_SaveConfigFile p_symbols->config_SaveConfigFile
+#   define config_Duplicate      p_symbols->config_Duplicate
+#   define config_FindConfig     p_symbols->config_FindConfig
+#   define config_SetCallbacks   p_symbols->config_SetCallbacks
+#   define config_UnsetCallbacks p_symbols->config_UnsetCallbacks
 #endif
 
 /*****************************************************************************
index 1f602d59821b71c781d405bad2be20f1a372ff0b..f66dee6cc3565b0a0aaaded2fe6c342bcbe54b42 100644 (file)
@@ -2,7 +2,7 @@
  * modules_inner.h : Macros used from within a module.
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules_inner.h,v 1.17 2002/04/28 17:52:37 sam Exp $
+ * $Id: modules_inner.h,v 1.18 2002/05/03 20:49:30 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
         p_module->psz_program = NULL;                                         \
         p_module->pp_shortcuts[ 0 ] = MODULE_STRING;                          \
         p_module->i_capabilities = 0;                                         \
-        p_module->i_cpu_capabilities = 0;
+        p_module->i_cpu_capabilities = 0;                                     \
+        do {
 
 #define MODULE_INIT_STOP                                                      \
+        } while( 0 );                                                         \
         STORE_SYMBOLS;                                                        \
         p_module->pp_shortcuts[ i_shortcut ] = NULL;                          \
         p_module->i_config_items = 0;                                         \
 #define MODULE_ACTIVATE_START                                                 \
     int __VLC_SYMBOL( ActivateModule ) ( module_t *p_module )                 \
     {                                                                         \
+        config_SetCallbacks( p_module->p_config, p_config );                  \
         p_module->p_functions =                                               \
           ( module_functions_t * )malloc( sizeof( module_functions_t ) );     \
         if( p_module->p_functions == NULL )                                   \
         {                                                                     \
             return( -1 );                                                     \
         }                                                                     \
-        STORE_SYMBOLS;
+        STORE_SYMBOLS;                                                        \
+        do {
 
 #define MODULE_ACTIVATE_STOP                                                  \
+        } while( 0 );                                                         \
         return( 0 );                                                          \
     }
 
 #define MODULE_DEACTIVATE_START                                               \
     int __VLC_SYMBOL( DeactivateModule )( module_t *p_module )                \
     {                                                                         \
-        free( p_module->p_functions );
+        free( p_module->p_functions );                                        \
+        do {
 
 #define MODULE_DEACTIVATE_STOP                                                \
+        } while( 0 );                                                         \
+        config_UnsetCallbacks( p_module->p_config );                          \
         return( 0 );                                                          \
     }
index b9f1d6cc37b5e6108c2c5a24141f85b4d847b6b2..0aec10be6e7c615a0ff62388284cb0d07b2f1c9d 100644 (file)
@@ -2,7 +2,7 @@
  * configuration.c management of the modules configuration
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: configuration.c,v 1.21 2002/05/01 21:31:53 gbazin Exp $
+ * $Id: configuration.c,v 1.22 2002/05/03 20:49:30 sam Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -184,6 +184,10 @@ void config_PutPszVariable( const char *psz_name, char *psz_value )
 
     vlc_mutex_unlock( p_config->p_lock );
 
+    if( p_config->p_callback )
+    {
+        ((void(*)(void))p_config->p_callback)();
+    }
 }
 
 /*****************************************************************************
@@ -214,6 +218,11 @@ void config_PutIntVariable( const char *psz_name, int i_value )
     }
 
     p_config->i_value = i_value;
+
+    if( p_config->p_callback )
+    {
+        ((void(*)(void))p_config->p_callback)();
+    }
 }
 
 /*****************************************************************************
@@ -242,6 +251,11 @@ void config_PutFloatVariable( const char *psz_name, float f_value )
     }
 
     p_config->f_value = f_value;
+
+    if( p_config->p_callback )
+    {
+        ((void(*)(void))p_config->p_callback)();
+    }
 }
 
 /*****************************************************************************
@@ -326,6 +340,37 @@ module_config_t *config_Duplicate( module_config_t *p_orig )
     return p_config;
 }
 
+/*****************************************************************************
+ * config_SetCallbacks: sets callback functions in the duplicate p_config.
+ *****************************************************************************
+ * Unfortunatly we cannot work directly with the module's config data as
+ * this module might be unloaded from memory at any time (remember HideModule).
+ * This is why we need to duplicate callbacks each time we reload the module.
+ *****************************************************************************/
+void config_SetCallbacks( module_config_t *p_new, module_config_t *p_orig )
+{
+    while( p_new->i_type != MODULE_CONFIG_HINT_END )
+    {
+        p_new->p_callback = p_orig->p_callback;
+        p_new++;
+        p_orig++;
+    }
+}
+
+/*****************************************************************************
+ * config_UnsetCallbacks: unsets callback functions in the duplicate p_config.
+ *****************************************************************************
+ * We simply undo what we did in config_SetCallbacks.
+ *****************************************************************************/
+void config_UnsetCallbacks( module_config_t *p_new )
+{
+    while( p_new->i_type != MODULE_CONFIG_HINT_END )
+    {
+        p_new->p_callback = NULL;
+        p_new++;
+    }
+}
+
 /*****************************************************************************
  * config_LoadConfigFile: loads the configuration file.
  *****************************************************************************
index 570baeab986bbcce2e653e4ec3325ec79a5ce1f1..71ed054833247bdb292048a596f63561ee5d993f 100644 (file)
@@ -2,7 +2,7 @@
  * modules_plugin.h : Plugin management functions used by the core application.
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: modules_plugin.h,v 1.23 2002/04/30 12:56:11 gbazin Exp $
+ * $Id: modules_plugin.h,v 1.24 2002/05/03 20:49:30 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -197,6 +197,8 @@ module_error( char *psz_buffer )
     (p_symbols)->config_SaveConfigFile = config_SaveConfigFile; \
     (p_symbols)->config_Duplicate = config_Duplicate; \
     (p_symbols)->config_FindConfig = config_FindConfig; \
+    (p_symbols)->config_SetCallbacks = config_SetCallbacks; \
+    (p_symbols)->config_UnsetCallbacks = config_UnsetCallbacks; \
     (p_symbols)->intf_MsgSub = intf_MsgSub; \
     (p_symbols)->intf_MsgUnsub = intf_MsgUnsub; \
     (p_symbols)->intf_Msg = intf_Msg; \