modules_inner.h 6.35 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * modules_inner.h : Macros used from within a module.
 *****************************************************************************
 * Copyright (C) 2001 VideoLAN
5
 * $Id: modules_inner.h,v 1.7 2001/05/30 17:03:11 sam Exp $
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *
 * 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.
 *****************************************************************************/
#ifndef MODULE_NAME
#  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:
42
 * #define MODULE_FUNC( zog ) module_foo_zog
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"  */
48 49
#define STRINGIFY( z )   UGLY_KLUDGE( z )
#define UGLY_KLUDGE( z ) #z
50
/* And I need to do _this_ to change  foo bar  to  module_foo_bar  ! */
51 52
#define CONCATENATE( y, z ) CRUDE_HACK( y, z )
#define CRUDE_HACK( y, z )  module_##y##_##z
53

54
#define MODULE_VAR( z ) "VLC_MODULE_" #z
55 56 57

/* If the module is built-in, then we need to define foo_InitModule instead
 * of InitModule. Same for Activate- and DeactivateModule. */
58
#ifdef BUILTIN
59

60
#   define _M( function ) CONCATENATE( MODULE_NAME, function )
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

#   define MODULE_INIT_START \
        int CONCATENATE( MODULE_NAME, InitModule ) ( module_t *p_module ) \
        { \
            p_module->psz_name = MODULE_STRING; \
            p_module->psz_version = VERSION;

#   define MODULE_INIT_STOP \
            return( 0 ); \
        }

#   define MODULE_ACTIVATE_START \
        int CONCATENATE( MODULE_NAME, ActivateModule ) ( module_t *p_module ) \
        { \
            p_module->p_functions = \
              ( module_functions_t * )malloc( sizeof( module_functions_t ) ); \
            if( p_module->p_functions == NULL ) \
            { \
                return( -1 ); \
            } \
            p_module->p_config = p_config;

#   define MODULE_ACTIVATE_STOP \
            return( 0 ); \
        }

#   define MODULE_DEACTIVATE_START \
        int CONCATENATE( MODULE_NAME, DeactivateModule )( module_t *p_module ) \
        { \
            free( p_module->p_functions );

#   define MODULE_DEACTIVATE_STOP \
            return( 0 ); \
        }

96
#else
97

98
#   define _M( function )    function
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

#   define MODULE_INIT_START \
        int InitModule      ( module_t *p_module ) \
        { \
            p_module->psz_name = MODULE_STRING; \
            p_module->psz_version = VERSION;

#   define MODULE_INIT_STOP \
            return( 0 ); \
        }

#   define MODULE_ACTIVATE_START \
        int ActivateModule  ( module_t *p_module ) \
        { \
            p_module->p_functions = \
              ( module_functions_t * )malloc( sizeof( module_functions_t ) ); \
            if( p_module->p_functions == NULL ) \
            { \
                return( -1 ); \
            } \
            p_module->p_config = p_config; \
            p_symbols = p_module->p_symbols;

#   define MODULE_ACTIVATE_STOP \
            return( 0 ); \
        }

#   define MODULE_DEACTIVATE_START \
        int DeactivateModule( module_t *p_module ) \
        { \
            free( p_module->p_functions );

#   define MODULE_DEACTIVATE_STOP \
            return( 0 ); \
        }

135 136 137
#endif

/* Now the real stuff */
138
#define MODULE_STRING STRINGIFY( MODULE_NAME )
139 140 141 142

/*****************************************************************************
 * Macros used to build the configuration structure.
 *****************************************************************************/
143 144 145 146 147 148 149 150 151 152
#ifdef BUILTIN
#   define MODULE_CONFIG_START \
        static module_config_t p_config[] = { \
            { MODULE_CONFIG_ITEM_START, NULL, NULL, NULL, NULL },
#else
#   define MODULE_CONFIG_START \
        module_symbols_t* p_symbols; \
        static module_config_t p_config[] = { \
        { MODULE_CONFIG_ITEM_START, NULL, NULL, NULL, NULL },
#endif
153

154
#define MODULE_CONFIG_STOP \
155 156 157
    { MODULE_CONFIG_ITEM_END, NULL, NULL, NULL, NULL } \
};

158 159
#define ADD_WINDOW( text ) \
    { MODULE_CONFIG_ITEM_WINDOW, text, NULL, NULL, NULL },
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
#define ADD_FRAME( text ) \
    { MODULE_CONFIG_ITEM_FRAME, text, NULL, NULL, NULL },
#define ADD_PANE( text ) \
    { MODULE_CONFIG_ITEM_PANE, text, NULL, NULL, NULL },
#define ADD_COMMENT( text ) \
    { MODULE_CONFIG_ITEM_COMMENT, text, NULL, NULL, NULL },
#define ADD_STRING( text, name, p_update ) \
    { MODULE_CONFIG_ITEM_STRING, text, name, NULL, p_update },
#define ADD_FILE( text, name, p_update ) \
    { MODULE_CONFIG_ITEM_FILE, text, name, NULL, p_update },
#define ADD_CHECK( text, name, p_update ) \
    { MODULE_CONFIG_ITEM_CHECK, text, name, NULL, p_update },
#define ADD_CHOOSE( text, name, p_getlist, p_update ) \
    { MODULE_CONFIG_ITEM_CHOOSE, text, name, p_getlist, p_update },
#define ADD_RADIO( text, name, p_getlist, p_update ) \
    { MODULE_CONFIG_ITEM_RADIO, text, name, p_getlist, p_update },
#define ADD_SCALE( text, name, p_getlist, p_update ) \
    { MODULE_CONFIG_ITEM_SCALE, text, name, p_getlist, p_update },
#define ADD_SPIN( text, name, p_getlist, p_update ) \
    { MODULE_CONFIG_ITEM_SPIN, text, name, p_getlist, p_update },

181