modules_inner.h 8.58 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
Gildas Bazin's avatar
 
Gildas Bazin committed
5
 * $Id: modules_inner.h,v 1.13 2002/03/11 07:23:09 gbazin 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 25 26
 *
 * 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.
 *****************************************************************************/

/*****************************************************************************
 * Check that we are within a module.
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
27
#if !( defined( MODULE_NAME ) || defined( MAKE_DEP ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41
#  error "You must define MODULE_NAME before using modules_inner.h !"
#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"
 * #define MODULE_VAR(blah) "VLC_MODULE_foo_blah"
 *
 * and, if BUILTIN is set, we will also need:
Sam Hocevar's avatar
 
Sam Hocevar committed
42
 * #define MODULE_FUNC( zog ) module_foo_zog
Sam Hocevar's avatar
 
Sam Hocevar committed
43 44 45 46 47
 *
 * 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
48 49
#define STRINGIFY( z )   UGLY_KLUDGE( z )
#define UGLY_KLUDGE( z ) #z
Sam Hocevar's avatar
 
Sam Hocevar committed
50
/* And I need to do _this_ to change  foo bar  to  module_foo_bar  ! */
Sam Hocevar's avatar
 
Sam Hocevar committed
51
#define CONCATENATE( y, z ) CRUDE_HACK( y, z )
Sam Hocevar's avatar
 
Sam Hocevar committed
52
#define CRUDE_HACK( y, z )  y##__MODULE_##z
Sam Hocevar's avatar
 
Sam Hocevar committed
53

Sam Hocevar's avatar
 
Sam Hocevar committed
54
#define MODULE_VAR( z ) "VLC_MODULE_" #z
Sam Hocevar's avatar
 
Sam Hocevar committed
55 56 57

/* If the module is built-in, then we need to define foo_InitModule instead
 * of InitModule. Same for Activate- and DeactivateModule. */
Sam Hocevar's avatar
 
Sam Hocevar committed
58
#ifdef BUILTIN
Sam Hocevar's avatar
 
Sam Hocevar committed
59 60 61 62
#   define _M( function )          CONCATENATE( function, MODULE_NAME )
#   define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
#   define DECLARE_SYMBOLS         ;
#   define STORE_SYMBOLS           ;
Sam Hocevar's avatar
 
Sam Hocevar committed
63
#else
Sam Hocevar's avatar
 
Sam Hocevar committed
64 65 66 67
#   define _M( 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;
Sam Hocevar's avatar
 
Sam Hocevar committed
68 69
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
70
#define MODULE_STRING STRINGIFY( MODULE_NAME )
Sam Hocevar's avatar
 
Sam Hocevar committed
71

Sam Hocevar's avatar
 
Sam Hocevar committed
72 73 74
/*
 * 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
Gildas Bazin's avatar
 
Gildas Bazin committed
75 76
 * 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
77 78
 */
#define MODULE_INIT_START                                                     \
Gildas Bazin's avatar
 
Gildas Bazin committed
79 80
    DECLARE_SYMBOLS;                                                          \
                                                                              \
Sam Hocevar's avatar
 
Sam Hocevar committed
81
    int __VLC_SYMBOL( InitModule ) ( module_t *p_module )                     \
Sam Hocevar's avatar
 
Sam Hocevar committed
82 83 84 85 86 87 88 89 90
    {                                                                         \
        int i_shortcut = 0;                                                   \
        p_module->psz_name = MODULE_STRING;                                   \
        p_module->psz_longname = MODULE_STRING;                               \
        p_module->psz_program = NULL;                                         \
        p_module->i_capabilities = 0;                                         \
        p_module->i_cpu_capabilities = 0;

#define MODULE_INIT_STOP                                                      \
Gildas Bazin's avatar
 
Gildas Bazin committed
91
        STORE_SYMBOLS;                                                        \
Sam Hocevar's avatar
 
Sam Hocevar committed
92
        p_module->pp_shortcuts[ i_shortcut ] = NULL;                          \
Gildas Bazin's avatar
 
Gildas Bazin committed
93 94 95 96 97 98 99 100 101 102 103 104 105
        p_module->i_config_items = 0;                                         \
        for( p_module->i_config_lines = 0;                                    \
             p_module->i_config_lines < (sizeof(p_config)/                    \
                                            sizeof(module_config_t));         \
             p_module->i_config_lines++ )                                     \
        {                                                                     \
            if( p_config[p_module->i_config_lines].i_type &                   \
                MODULE_CONFIG_ITEM )                                          \
                p_module->i_config_items++;                                   \
        }                                                                     \
        vlc_mutex_init( &p_module->config_lock );                             \
        p_module->p_config_orig = p_config;                                   \
        p_module->p_config = config_Duplicate( p_module );                    \
Gildas Bazin's avatar
 
Gildas Bazin committed
106 107 108 109 110 111
        if( p_module->p_config == NULL )                                      \
        {                                                                     \
            intf_ErrMsg( MODULE_STRING                                        \
                         " InitModule error: can't duplicate p_config" );     \
            return( -1 );                                                     \
        }                                                                     \
Sam Hocevar's avatar
 
Sam Hocevar committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
        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;

/*
 * ActivateModule: 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                                                 \
Sam Hocevar's avatar
 
Sam Hocevar committed
139
    int __VLC_SYMBOL( ActivateModule ) ( module_t *p_module )                 \
Sam Hocevar's avatar
 
Sam Hocevar committed
140 141 142
    {                                                                         \
        p_module->p_functions =                                               \
          ( module_functions_t * )malloc( sizeof( module_functions_t ) );     \
Gildas Bazin's avatar
 
Gildas Bazin committed
143
        p_module->p_config_orig = p_config;                                   \
Sam Hocevar's avatar
 
Sam Hocevar committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        if( p_module->p_functions == NULL )                                   \
        {                                                                     \
            return( -1 );                                                     \
        }                                                                     \
        STORE_SYMBOLS;

#define MODULE_ACTIVATE_STOP                                                  \
        return( 0 );                                                          \
    }

/*
 * 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                                               \
Sam Hocevar's avatar
 
Sam Hocevar committed
160
    int __VLC_SYMBOL( DeactivateModule )( module_t *p_module )                \
Sam Hocevar's avatar
 
Sam Hocevar committed
161
    {                                                                         \
Gildas Bazin's avatar
 
Gildas Bazin committed
162
        p_module->p_config_orig = NULL;                                       \
Sam Hocevar's avatar
 
Sam Hocevar committed
163 164 165 166 167
        free( p_module->p_functions );

#define MODULE_DEACTIVATE_STOP                                                \
        return( 0 );                                                          \
    }