]> git.sesse.net Git - vlc/blobdiff - include/modules_inner.h
* ./modules/audio_output/oss.c: compilation fixes.
[vlc] / include / modules_inner.h
index 1f602d59821b71c781d405bad2be20f1a372ff0b..40e17703573fc27a703d9537d64f9dec0c973abc 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.28 2002/08/08 00:35:10 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
  *****************************************************************************/
 
 /*****************************************************************************
- * Check that we are within a module.
+ * If we are not within a module, assume we're in the vlc core.
  *****************************************************************************/
-#if !( defined( MODULE_NAME ) || defined( MAKE_DEP ) )
-#  error "You must define MODULE_NAME before using modules_inner.h !"
+#if !defined( __PLUGIN__ ) && !defined( __BUILTIN__ )
+#   define MODULE_NAME main
 #endif
 
 /*****************************************************************************
@@ -36,7 +36,6 @@
  *
  * if user has #defined MODULE_NAME foo, then we will need:
  * #define MODULE_STRING "foo"
- * #define MODULE_VAR(blah) "VLC_MODULE_foo_blah"
  *
  * and, if __BUILTIN__ is set, we will also need:
  * #define MODULE_FUNC( zog ) module_foo_zog
 #define UGLY_KLUDGE( z ) #z
 /* And I need to do _this_ to change « foo bar » to « module_foo_bar » ! */
 #define CONCATENATE( y, z ) CRUDE_HACK( y, z )
-#define CRUDE_HACK( y, z )  y##__MODULE_##z
-
-#define MODULE_VAR( z ) "VLC_MODULE_" #z
+#define CRUDE_HACK( y, z )  y##__##z
 
 /* If the module is built-in, then we need to define foo_InitModule instead
  * of InitModule. Same for Activate- and DeactivateModule. */
-#ifdef __BUILTIN__
-#   define _M( function )          CONCATENATE( function, MODULE_NAME )
+#if defined( __BUILTIN__ )
+#   define E_( function )          CONCATENATE( function, MODULE_NAME )
 #   define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
-#   define DECLARE_SYMBOLS         ;
-#   define STORE_SYMBOLS           ;
-#else
-#   define _M( function )          function
+#   define DECLARE_SYMBOLS         struct _u_n_u_s_e_d_
+#   define STORE_SYMBOLS           struct _u_n_u_s_e_d_
+#elif defined( __PLUGIN__ )
+#   define E_( function )          function
 #   define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL )
-#   define DECLARE_SYMBOLS         module_symbols_t* p_symbols;
-#   define STORE_SYMBOLS           p_symbols = p_module->p_symbols;
+#   define DECLARE_SYMBOLS         module_symbols_t* p_symbols
+#   define STORE_SYMBOLS           p_symbols = p_module->p_symbols
+#endif
+
+#if defined( __cplusplus )
+#   define EXTERN_SYMBOL           extern "C"
+#else
+#   define EXTERN_SYMBOL
 #endif
 
 #define MODULE_STRING STRINGIFY( MODULE_NAME )
  * instance the module name, its shortcuts, its capabilities... we also create
  * a copy of its config because the module can be unloaded at any time.
  */
-#define MODULE_INIT_START                                                     \
+#define vlc_module_begin( )                                                   \
     DECLARE_SYMBOLS;                                                          \
-    int __VLC_SYMBOL( InitModule ) ( module_t *p_module )                     \
+    EXTERN_SYMBOL int __VLC_SYMBOL(vlc_entry) ( module_t *p_module )          \
     {                                                                         \
-        int i_shortcut = 1;                                                   \
-        struct module_config_s* p_item;                                       \
-        p_module->psz_name = MODULE_STRING;                                   \
+        int i_shortcut = 1, i_config = 0;                                     \
+        module_config_t p_config[ 100 ];                                      \
+        STORE_SYMBOLS;                                                        \
+        p_module->b_submodule = VLC_FALSE;                                    \
+        p_module->psz_object_name = MODULE_STRING;                            \
         p_module->psz_longname = MODULE_STRING;                               \
-        p_module->psz_program = NULL;                                         \
         p_module->pp_shortcuts[ 0 ] = MODULE_STRING;                          \
-        p_module->i_capabilities = 0;                                         \
-        p_module->i_cpu_capabilities = 0;
-
-#define MODULE_INIT_STOP                                                      \
-        STORE_SYMBOLS;                                                        \
-        p_module->pp_shortcuts[ i_shortcut ] = NULL;                          \
-        p_module->i_config_items = 0;                                         \
-        for( p_item = p_config;                                               \
-             p_item->i_type != MODULE_CONFIG_HINT_END;                        \
-             p_item++ )                                                       \
+        p_module->i_cpu = 0;                                                  \
+        p_module->psz_program = NULL;                                         \
+        p_module->psz_capability = "";                                        \
+        p_module->i_score = 1;                                                \
+        p_module->pf_activate = NULL;                                         \
+        p_module->pf_deactivate = NULL;                                       \
         {                                                                     \
-            if( p_item->i_type & MODULE_CONFIG_ITEM )                         \
-                p_module->i_config_items++;                                   \
+            module_t *p_submodule = p_module /* the ; gets added */
+
+#define vlc_module_end( )                                                     \
+            p_submodule->pp_shortcuts[ i_shortcut ] = NULL;                   \
         }                                                                     \
-        vlc_mutex_init( &p_module->config_lock );                             \
-        p_module->p_config = config_Duplicate( p_config );                    \
-        if( p_module->p_config == NULL )                                      \
         {                                                                     \
-            intf_ErrMsg( MODULE_STRING                                        \
-                         " InitModule error: can't duplicate p_config" );     \
-            return( -1 );                                                     \
+           module_config_t tmp = { CONFIG_HINT_END, NULL, NULL, '\0' };      \
+            p_config[ i_config ] = tmp;                                       \
         }                                                                     \
-        for( p_item = p_module->p_config;                                     \
-             p_item->i_type != MODULE_CONFIG_HINT_END;                        \
-             p_item++ )                                                       \
+        config_Duplicate( p_module, p_config );                               \
+        if( p_module->p_config == NULL )                                      \
         {                                                                     \
-            p_item->p_lock = &p_module->config_lock;                          \
+            return -1;                                                        \
         }                                                                     \
-        return( 0 );                                                          \
-    }
-
-#define ADD_CAPABILITY( cap, score )                                          \
-    p_module->i_capabilities |= 1 << MODULE_CAPABILITY_##cap;                 \
-    p_module->pi_score[ MODULE_CAPABILITY_##cap ] = score;
-
-#define ADD_REQUIREMENT( cap )                                                \
-    p_module->i_cpu_capabilities |= CPU_CAPABILITY_##cap;
-
-#define ADD_PROGRAM( program )                                                \
-    p_module->psz_program = program;
-
-#define ADD_SHORTCUT( shortcut )                                              \
-    p_module->pp_shortcuts[ i_shortcut ] = shortcut;                          \
-    i_shortcut++;
-
-#define SET_DESCRIPTION( desc )                                               \
-    p_module->psz_longname = desc;
+        return 0 && i_shortcut;                                               \
+    }                                                                         \
+    int __VLC_SYMBOL(vlc_entry) ( module_t * ) /* the ; gets added */
+
+
+#define add_submodule( )                                                      \
+    p_submodule->pp_shortcuts[ i_shortcut ] = NULL;                           \
+    p_submodule =                                                             \
+            (module_t *)vlc_object_create( p_module, VLC_OBJECT_MODULE );     \
+    vlc_object_attach( p_submodule, p_module );                               \
+    p_submodule->b_submodule = VLC_TRUE;                                      \
+    /* Nuahahaha! Heritage! Polymorphism! Ugliness!! */                       \
+    for( i_shortcut = 0; p_module->pp_shortcuts[ i_shortcut ]; i_shortcut++ ) \
+    {                                                                         \
+        p_submodule->pp_shortcuts[ i_shortcut ] =                             \
+                                p_module->pp_shortcuts[ i_shortcut ];         \
+    }                                                                         \
+    p_submodule->psz_object_name = p_module->psz_object_name;                 \
+    p_submodule->psz_program = p_module->psz_program;                         \
+    p_submodule->psz_capability = p_module->psz_capability;                   \
+    p_submodule->i_score = p_module->i_score;                                 \
+    p_submodule->i_cpu = p_module->i_cpu;                                     \
+    p_submodule->pf_activate = NULL;                                          \
+    p_submodule->pf_deactivate = NULL
+    
+#define add_requirement( cap )                                                \
+    p_module->i_cpu |= CPU_CAPABILITY_##cap
+
+#define add_shortcut( shortcut )                                              \
+    p_submodule->pp_shortcuts[ i_shortcut ] = shortcut;                       \
+    i_shortcut++
+
+#define set_description( desc )                                               \
+    p_module->psz_longname = desc
+
+#define set_capability( cap, score )                                          \
+    p_submodule->psz_capability = cap;                                        \
+    p_submodule->i_score = score
+
+#define set_program( program )                                                \
+    p_submodule->psz_program = program
+
+#define set_callbacks( activate, deactivate )                                 \
+    p_submodule->pf_activate = activate;                                      \
+    p_submodule->pf_deactivate = deactivate
 
 /*
- * ActivateModule: this function is called before functions can be accessed,
+ * module_activate: this function is called before functions can be accessed,
  * we do allocation tasks here, and maybe additional stuff such as large
  * table allocation. Once ActivateModule is called we are almost sure the
  * module will be used.
  */
-#define MODULE_ACTIVATE_START                                                 \
-    int __VLC_SYMBOL( ActivateModule ) ( module_t *p_module )                 \
+#define module_activate( prototype )                                          \
+    __module_activate( prototype );                                           \
+    int __VLC_SYMBOL( module_activate ) ( module_t *p_module )                \
     {                                                                         \
-        p_module->p_functions =                                               \
-          ( module_functions_t * )malloc( sizeof( module_functions_t ) );     \
-        if( p_module->p_functions == NULL )                                   \
-        {                                                                     \
-            return( -1 );                                                     \
-        }                                                                     \
-        STORE_SYMBOLS;
-
-#define MODULE_ACTIVATE_STOP                                                  \
-        return( 0 );                                                          \
-    }
+        STORE_SYMBOLS;                                                        \
+        config_SetCallbacks( p_module->p_config, p_config );                  \
+        return __module_activate( p_module );                                 \
+    }                                                                         \
+                                                                              \
+    static int __module_activate( prototype )
 
 /*
  * DeactivateModule: this function is called after we are finished with the
  * module. Everything that has been done in ActivateModule needs to be undone
  * here.
  */
-#define MODULE_DEACTIVATE_START                                               \
-    int __VLC_SYMBOL( DeactivateModule )( module_t *p_module )                \
+#define module_deactivate( prototype )                                        \
+    __module_deactivate( prototype );                                         \
+    int __VLC_SYMBOL( module_deactivate )( module_t *p_module )               \
     {                                                                         \
-        free( p_module->p_functions );
+        int i_ret = __module_deactivate( p_module );                          \
+        config_UnsetCallbacks( p_module->p_config );                          \
+        return i_ret;                                                         \
+    }                                                                         \
+                                                                              \
+    static int __module_deactivate( prototype )
 
-#define MODULE_DEACTIVATE_STOP                                                \
-        return( 0 );                                                          \
-    }