Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

modules_inner.h

00001 /*****************************************************************************
00002  * modules_inner.h : Macros used from within a module.
00003  *****************************************************************************
00004  * Copyright (C) 2001 the VideoLAN team
00005  * $Id: modules_inner.h 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * If we are not within a module, assume we're in the vlc core.
00026  *****************************************************************************/
00027 #if !defined( __PLUGIN__ ) && !defined( __BUILTIN__ )
00028 #   define MODULE_NAME main
00029 #endif
00030 
00031 /*****************************************************************************
00032  * Add a few defines. You do not want to read this section. Really.
00033  *****************************************************************************/
00034 
00035 /* Explanation:
00036  *
00037  * if user has #defined MODULE_NAME foo, then we will need:
00038  * #define MODULE_STRING "foo"
00039  *
00040  * and, if __BUILTIN__ is set, we will also need:
00041  * #define MODULE_FUNC( zog ) module_foo_zog
00042  *
00043  * this can't easily be done with the C preprocessor, thus a few ugly hacks.
00044  */
00045 
00046 /* I can't believe I need to do this to change « foo » to « "foo" » */
00047 #define STRINGIFY( z )   UGLY_KLUDGE( z )
00048 #define UGLY_KLUDGE( z ) #z
00049 /* And I need to do _this_ to change « foo bar » to « module_foo_bar » ! */
00050 #define CONCATENATE( y, z ) CRUDE_HACK( y, z )
00051 #define CRUDE_HACK( y, z )  y##__##z
00052 
00053 /* If the module is built-in, then we need to define foo_InitModule instead
00054  * of InitModule. Same for Activate- and DeactivateModule. */
00055 #if defined( __BUILTIN__ )
00056 #   define E_( function )          CONCATENATE( function, MODULE_NAME )
00057 #   define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
00058 #   define DECLARE_SYMBOLS         struct _u_n_u_s_e_d_
00059 #   define STORE_SYMBOLS           struct _u_n_u_s_e_d_
00060 #elif defined( __PLUGIN__ )
00061 #   define E_( function )          CONCATENATE( function, MODULE_SYMBOL )
00062 #   define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL )
00063 #   define DECLARE_SYMBOLS         module_symbols_t* p_symbols
00064 #   define STORE_SYMBOLS           p_symbols = p_module->p_symbols
00065 #endif
00066 
00067 #if defined( __PLUGIN__ ) && ( defined( WIN32 ) || defined( UNDER_CE ) )
00068 #   define DLL_SYMBOL              __declspec(dllexport)
00069 #   define CDECL_SYMBOL            __cdecl
00070 #else
00071 #   define DLL_SYMBOL
00072 #   define CDECL_SYMBOL
00073 #endif
00074 
00075 #if defined( __cplusplus )
00076 #   define EXTERN_SYMBOL           extern "C"
00077 #else
00078 #   define EXTERN_SYMBOL
00079 #endif
00080 
00081 #if defined( USE_DLL )
00082 #   define IMPORT_SYMBOL __declspec(dllimport)
00083 #else
00084 #   define IMPORT_SYMBOL
00085 #endif
00086 
00087 #define MODULE_STRING STRINGIFY( MODULE_NAME )
00088 
00089 /*
00090  * InitModule: this function is called once and only once, when the module
00091  * is looked at for the first time. We get the useful data from it, for
00092  * instance the module name, its shortcuts, its capabilities... we also create
00093  * a copy of its config because the module can be unloaded at any time.
00094  */
00095 #define vlc_module_begin( )                                                   \
00096     DECLARE_SYMBOLS;                                                          \
00097     EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL                                 \
00098     __VLC_SYMBOL(vlc_entry) ( module_t *p_module )                            \
00099     {                                                                         \
00100         int i_shortcut = 1, i_config = -1;                                    \
00101         module_config_t *p_config = NULL;                                     \
00102         static module_config_t config_end = {CONFIG_HINT_END};            \
00103         STORE_SYMBOLS;                                                        \
00104         p_module->b_submodule = VLC_FALSE;                                    \
00105         p_module->b_unloadable = VLC_TRUE;                                    \
00106         p_module->b_reentrant = VLC_TRUE;                                     \
00107         p_module->psz_object_name = MODULE_STRING;                            \
00108         p_module->psz_shortname = NULL;                                       \
00109         p_module->psz_longname = MODULE_STRING;                               \
00110         p_module->pp_shortcuts[ 0 ] = MODULE_STRING;                          \
00111         p_module->i_cpu = 0;                                                  \
00112         p_module->psz_program = NULL;                                         \
00113         p_module->psz_capability = "";                                        \
00114         p_module->i_score = 1;                                                \
00115         p_module->pf_activate = NULL;                                         \
00116         p_module->pf_deactivate = NULL;                                       \
00117         {                                                                     \
00118             module_t *p_submodule = p_module /* the ; gets added */
00119 
00120 #define vlc_module_end( )                                                     \
00121             p_submodule->pp_shortcuts[ i_shortcut ] = NULL;                   \
00122         }                                                                     \
00123         if( p_config )                                                        \
00124         {                                                                     \
00125             p_config[ ++i_config ] = config_end;                              \
00126             config_Duplicate( p_module, p_config );                           \
00127             free( p_config );                                                 \
00128         }                                                                     \
00129         else config_Duplicate( p_module, &config_end );                       \
00130         if( p_module->p_config == NULL )                                      \
00131         {                                                                     \
00132             return VLC_EGENERIC;                                              \
00133         }                                                                     \
00134         return VLC_SUCCESS && i_shortcut;                                     \
00135     }                                                                         \
00136     struct _u_n_u_s_e_d_ /* the ; gets added */
00137 
00138 
00139 #define add_submodule( )                                                      \
00140     p_submodule->pp_shortcuts[ i_shortcut ] = NULL;                           \
00141     p_submodule =                                                             \
00142             (module_t *)vlc_object_create( p_module, VLC_OBJECT_MODULE );     \
00143     vlc_object_attach( p_submodule, p_module );                               \
00144     p_submodule->b_submodule = VLC_TRUE;                                      \
00145     /* Nuahahaha! Heritage! Polymorphism! Ugliness!! */                       \
00146     for( i_shortcut = 0; p_module->pp_shortcuts[ i_shortcut ]; i_shortcut++ ) \
00147     {                                                                         \
00148         p_submodule->pp_shortcuts[ i_shortcut ] =                             \
00149                                 p_module->pp_shortcuts[ i_shortcut ];         \
00150     }                                                                         \
00151     p_submodule->psz_object_name = p_module->psz_object_name;                 \
00152     p_submodule->psz_shortname = p_module->psz_shortname;                     \
00153     p_submodule->psz_longname = p_module->psz_longname;                       \
00154     p_submodule->psz_program = p_module->psz_program;                         \
00155     p_submodule->psz_capability = p_module->psz_capability;                   \
00156     p_submodule->i_score = p_module->i_score;                                 \
00157     p_submodule->i_cpu = p_module->i_cpu;                                     \
00158     p_submodule->pf_activate = NULL;                                          \
00159     p_submodule->pf_deactivate = NULL
00160 
00161 #define add_requirement( cap )                                                \
00162     p_module->i_cpu |= CPU_CAPABILITY_##cap
00163 
00164 #define add_shortcut( shortcut )                                              \
00165     p_submodule->pp_shortcuts[ i_shortcut ] = shortcut;                       \
00166     i_shortcut++
00167 
00168 #define set_shortname( desc )                                                 \
00169     p_submodule->psz_shortname = desc
00170 
00171 #define set_description( desc )                                               \
00172     p_submodule->psz_longname = desc
00173 
00174 #define set_capability( cap, score )                                          \
00175     p_submodule->psz_capability = cap;                                        \
00176     p_submodule->i_score = score
00177 
00178 #define set_program( program )                                                \
00179     p_submodule->psz_program = program
00180 
00181 #define set_callbacks( activate, deactivate )                                 \
00182     p_submodule->pf_activate = activate;                                      \
00183     p_submodule->pf_deactivate = deactivate
00184 
00185 #define linked_with_a_crap_library_which_uses_atexit( )                       \
00186     p_module->b_unloadable = VLC_FALSE
00187 

Generated on Tue Dec 20 10:14:19 2005 for vlc-0.8.4a by  doxygen 1.4.2