vlc_modules_macros.h 7.35 KB
Newer Older
Sam Hocevar's avatar
 
Sam Hocevar committed
1 2 3
/*****************************************************************************
 * modules_inner.h : Macros used from within a module.
 *****************************************************************************
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
4
 * Copyright (C) 2001-2006 the VideoLAN team
5
 * $Id$
Sam Hocevar's avatar
 
Sam Hocevar committed
6 7 8 9 10 11 12
 *
 * 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.
13
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
14 15 16 17 18 19 20
 * 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
Antoine Cellerier's avatar
Antoine Cellerier committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Sam Hocevar's avatar
 
Sam Hocevar committed
22 23
 *****************************************************************************/

24 25 26 27
#if !defined( __LIBVLC__ )
  #error You are not libvlc or one of its plugins. You cannot include this file
#endif

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

35 36 37
/**
 * Current plugin ABI version
 */
38
# define MODULE_SYMBOL 0_9_0e
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
39
# define MODULE_SUFFIX "__0_9_0e"
40

Sam Hocevar's avatar
 
Sam Hocevar committed
41 42 43 44 45 46 47 48 49
/*****************************************************************************
 * 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"
 *
50
 * and, if HAVE_DYNAMIC_PLUGINS is NOT set, we will also need:
Sam Hocevar's avatar
 
Sam Hocevar committed
51
 * #define MODULE_FUNC( zog ) module_foo_zog
Sam Hocevar's avatar
 
Sam Hocevar committed
52 53 54 55
 *
 * this can't easily be done with the C preprocessor, thus a few ugly hacks.
 */

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
56
/* I can't believe I need to do this to change « foo » to « "foo" » */
Sam Hocevar's avatar
 
Sam Hocevar committed
57 58
#define STRINGIFY( z )   UGLY_KLUDGE( z )
#define UGLY_KLUDGE( z ) #z
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
59
/* And I need to do _this_ to change « foo bar » to « module_foo_bar » ! */
Sam Hocevar's avatar
 
Sam Hocevar committed
60
#define CONCATENATE( y, z ) CRUDE_HACK( y, z )
61
#define CRUDE_HACK( y, z )  y##__##z
Sam Hocevar's avatar
 
Sam Hocevar committed
62 63 64

/* If the module is built-in, then we need to define foo_InitModule instead
 * of InitModule. Same for Activate- and DeactivateModule. */
65
#if defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
66
#   define E_( function )          CONCATENATE( function, MODULE_SYMBOL )
Sam Hocevar's avatar
 
Sam Hocevar committed
67
#   define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL )
68 69 70
#else
#   define E_( function )          CONCATENATE( function, MODULE_NAME )
#   define __VLC_SYMBOL( symbol )  CONCATENATE( symbol, MODULE_NAME )
71 72
#endif

73 74 75
#if defined( __PLUGIN__ ) && ( defined( WIN32 ) || defined( UNDER_CE ) )
#   define DLL_SYMBOL              __declspec(dllexport)
#   define CDECL_SYMBOL            __cdecl
76 77 78
#elif HAVE_ATTRIBUTE_VISIBILITY
#   define DLL_SYMBOL __attribute__((visibility("default")))
#   define CDECL_SYMBOL
79 80 81 82 83
#else
#   define DLL_SYMBOL
#   define CDECL_SYMBOL
#endif

84 85 86 87 88 89
#if defined( __cplusplus )
#   define EXTERN_SYMBOL           extern "C"
#else
#   define EXTERN_SYMBOL
#endif

90 91 92 93 94 95
#if defined( USE_DLL )
#   define IMPORT_SYMBOL __declspec(dllimport)
#else
#   define IMPORT_SYMBOL
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
96
#define MODULE_STRING STRINGIFY( MODULE_NAME )
Sam Hocevar's avatar
 
Sam Hocevar committed
97

Sam Hocevar's avatar
 
Sam Hocevar committed
98 99 100
/*
 * 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
101 102
 * 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
103
 */
104 105 106 107 108
#if defined (__PLUGIN__) || defined (__BUILTIN__)
EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL
E_(vlc_entry) ( module_t *p_module );
#endif

109
#define vlc_module_begin( )                                                   \
110 111
    EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL                                 \
    __VLC_SYMBOL(vlc_entry) ( module_t *p_module )                            \
Sam Hocevar's avatar
 
Sam Hocevar committed
112
    {                                                                         \
113
        int res;                                                              \
114
        size_t i_config = (size_t)(-1);                                       \
Gildas Bazin's avatar
 
Gildas Bazin committed
115
        module_config_t *p_config = NULL;                                     \
116 117 118
        if (vlc_module_set (p_module, VLC_MODULE_NAME,                        \
                            (void *)(MODULE_STRING)))                         \
            goto error;                                                       \
119 120
        {                                                                     \
            module_t *p_submodule = p_module /* the ; gets added */
Sam Hocevar's avatar
 
Sam Hocevar committed
121

122
#define vlc_module_end( )                                                     \
123
        }                                                                     \
124
        res = config_Duplicate( p_module, p_config, ++i_config );             \
125
        free( p_config );                                                     \
126 127
        if (res)                                                              \
            return res;                                                       \
128
        return VLC_SUCCESS;                                                   \
129 130 131 132 133
                                                                              \
    error:                                                                    \
        free( p_config );                                                     \
        /* FIXME: cleanup submodules objects ??? */                           \
        return VLC_EGENERIC;                                                  \
134
    }                                                                         \
135
    struct _u_n_u_s_e_d_ /* the ; gets added */
136 137


138 139
#define add_submodule( ) \
    p_submodule = vlc_submodule_create( p_module )
140

141
#define add_requirement( cap ) \
142
    if (vlc_module_set (p_module, VLC_MODULE_CPU_REQUIREMENT, \
143
                        (void *)(intptr_t)(CPU_CAPABILITY_##cap))) goto error
144

145
#define add_shortcut( shortcut ) \
146 147
    if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (void*)(shortcut))) \
        goto error
148

149
#define set_shortname( shortname ) \
150 151
    if (vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, \
                        (void*)(shortname))) goto error;
152

153
#define set_description( desc ) \
154
    if (vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, (void*)(desc))) \
Rémi Denis-Courmont's avatar
Typo  
Rémi Denis-Courmont committed
155
        goto error
156

157
#define set_help( help ) \
158 159
    if (vlc_module_set (p_submodule, VLC_MODULE_HELP, (void*)(help))) \
        goto error
160

161
#define set_capability( cap, score ) \
162
    if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (void *)(cap)) \
163 164
     || vlc_module_set (p_submodule, VLC_MODULE_SCORE, \
                        (void *)(intptr_t)(score))) \
165
        goto error
166

167
#define set_callbacks( activate, deactivate ) \
168 169 170 171
    if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(activate)) \
     || vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, \
                        (void *)(deactivate))) \
        goto error
Sam Hocevar's avatar
 
Sam Hocevar committed
172

173
#define linked_with_a_crap_library_which_uses_atexit( ) \
174
    if (vlc_module_set (p_submodule, VLC_MODULE_UNLOADABLE, NULL)) goto error
175