modules_inner.h 9.16 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1 2 3 4
/*****************************************************************************
 * modules_inner.h : Macros used from within a module.
 *****************************************************************************
 * Copyright (C) 2001 VideoLAN
5
 * $Id: modules_inner.h,v 1.36 2003/01/06 00:37:29 garf Exp $
Sam Hocevar's avatar
 
Sam Hocevar committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * Authors: Samuel Hocevar <sam@zoy.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
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
25
 * If we are not within a module, assume we're in the vlc core.
Sam Hocevar's avatar
 
Sam Hocevar committed
26
 *****************************************************************************/
27 28
#if !defined( __PLUGIN__ ) && !defined( __BUILTIN__ )
#   define MODULE_NAME main
Sam Hocevar's avatar
 
Sam Hocevar committed
29 30 31 32 33 34 35 36 37 38 39
#endif

/*****************************************************************************
 * Add a few defines. You do not want to read this section. Really.
 *****************************************************************************/

/* Explanation:
 *
 * if user has #defined MODULE_NAME foo, then we will need:
 * #define MODULE_STRING "foo"
 *
40
 * and, if __BUILTIN__ is set, we will also need:
Sam Hocevar's avatar
 
Sam Hocevar committed
41
 * #define MODULE_FUNC( zog ) module_foo_zog
Sam Hocevar's avatar
 
Sam Hocevar committed
42 43 44 45 46
 *
 * this can't easily be done with the C preprocessor, thus a few ugly hacks.
 */

/* I can't believe I need to do this to change  foo  to  "foo"  */
Sam Hocevar's avatar
 
Sam Hocevar committed
47 48
#define STRINGIFY( z )   UGLY_KLUDGE( z )
#define UGLY_KLUDGE( z ) #z
Sam Hocevar's avatar
 
Sam Hocevar committed
49
/* And I need to do _this_ to change  foo bar  to  module_foo_bar  ! */
Sam Hocevar's avatar
 
Sam Hocevar committed
50
#define CONCATENATE( y, z ) CRUDE_HACK( y, z )
51
#define CRUDE_HACK( y, z )  y##__##z
Sam Hocevar's avatar
 
Sam Hocevar committed
52 53 54

/* If the module is built-in, then we need to define foo_InitModule instead
 * of InitModule. Same for Activate- and DeactivateModule. */
55
#if defined( __BUILTIN__ )
56 57
#   define E_( function )          CONCATENATE( function, MODULE_NAME )
#   define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
58 59
#   define DECLARE_SYMBOLS         struct _u_n_u_s_e_d_
#   define STORE_SYMBOLS           struct _u_n_u_s_e_d_
60
#elif defined( __PLUGIN__ )
61
#   define E_( function )          function
Sam Hocevar's avatar
 
Sam Hocevar committed
62
#   define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL )
63 64
#   define DECLARE_SYMBOLS         module_symbols_t* p_symbols
#   define STORE_SYMBOLS           p_symbols = p_module->p_symbols
Sam Hocevar's avatar
 
Sam Hocevar committed
65 66
#endif

67 68 69 70 71 72 73 74
#if defined( __PLUGIN__ ) && ( defined( WIN32 ) || defined( UNDER_CE ) )
#   define DLL_SYMBOL              __declspec(dllexport)
#   define CDECL_SYMBOL            __cdecl
#else
#   define DLL_SYMBOL
#   define CDECL_SYMBOL
#endif

75 76 77 78 79 80
#if defined( __cplusplus )
#   define EXTERN_SYMBOL           extern "C"
#else
#   define EXTERN_SYMBOL
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
81
#define MODULE_STRING STRINGIFY( MODULE_NAME )
Sam Hocevar's avatar
 
Sam Hocevar committed
82

Sam Hocevar's avatar
 
Sam Hocevar committed
83 84 85
/*
 * InitModule: this function is called once and only once, when the module
 * is looked at for the first time. We get the useful data from it, for
gbazin's avatar
 
gbazin committed
86 87
 * 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.
Sam Hocevar's avatar
 
Sam Hocevar committed
88
 */
89
#define vlc_module_begin( )                                                   \
gbazin's avatar
 
gbazin committed
90
    DECLARE_SYMBOLS;                                                          \
91 92
    EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL                                 \
    __VLC_SYMBOL(vlc_entry) ( module_t *p_module )                            \
Sam Hocevar's avatar
 
Sam Hocevar committed
93
    {                                                                         \
94 95
        int i_shortcut = 1, i_config = 0;                                     \
        module_config_t p_config[ 100 ];                                      \
96
        STORE_SYMBOLS;                                                        \
97
        p_module->b_submodule = VLC_FALSE;                                    \
98 99
        p_module->b_unloadable = VLC_TRUE;                                    \
        p_module->b_reentrant = VLC_TRUE;                                     \
100
        p_module->psz_object_name = MODULE_STRING;                            \
101
        p_module->psz_longname = MODULE_STRING;                               \
102
        p_module->pp_shortcuts[ 0 ] = MODULE_STRING;                          \
103 104 105 106 107 108 109 110
        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;                                       \
        {                                                                     \
            module_t *p_submodule = p_module /* the ; gets added */
Sam Hocevar's avatar
 
Sam Hocevar committed
111

112 113
#define vlc_module_end( )                                                     \
            p_submodule->pp_shortcuts[ i_shortcut ] = NULL;                   \
114 115
        }                                                                     \
        {                                                                     \
116
	    static module_config_t tmp = { CONFIG_HINT_END, NULL, NULL, '\0', \
117
                                           NULL, NULL, NULL, 0, 0.0, 0, 0, 0.0, 0.0, NULL,NULL, NULL, VLC_FALSE };                                            \
118 119
            p_config[ i_config ] = tmp;                                       \
        }                                                                     \
120
        config_Duplicate( p_module, p_config );                               \
gbazin's avatar
 
gbazin committed
121 122
        if( p_module->p_config == NULL )                                      \
        {                                                                     \
123
            return -1;                                                        \
Sam Hocevar's avatar
 
Sam Hocevar committed
124
        }                                                                     \
125 126
        return 0 && i_shortcut;                                               \
    }                                                                         \
127
    struct _u_n_u_s_e_d_ /* the ; gets added */
128 129 130


#define add_submodule( )                                                      \
131 132 133
    p_submodule->pp_shortcuts[ i_shortcut ] = NULL;                           \
    p_submodule =                                                             \
            (module_t *)vlc_object_create( p_module, VLC_OBJECT_MODULE );     \
134 135 136 137 138 139
    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 ] =                             \
140
                                p_module->pp_shortcuts[ i_shortcut ];         \
141 142
    }                                                                         \
    p_submodule->psz_object_name = p_module->psz_object_name;                 \
143
    p_submodule->psz_longname = p_module->psz_longname;                       \
144 145 146 147
    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;                                     \
148
    p_submodule->pf_activate = NULL;                                          \
149
    p_submodule->pf_deactivate = NULL
150
    
151 152 153 154 155 156 157 158
#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 )                                               \
159
    p_submodule->psz_longname = desc
160 161 162 163 164 165 166 167 168 169 170

#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
Sam Hocevar's avatar
 
Sam Hocevar committed
171

172 173 174
#define linked_with_a_crap_library_which_uses_atexit( )                       \
    p_module->b_unloadable = VLC_FALSE