X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fmodules_inner.h;h=d7b5af1dccfd0d6827fe84513cd88974bc62e560;hb=368acbd75df9fdba6724fa779bfea6e918b869ea;hp=df635e3aa92c52e1aa841ba18bec2b4146466394;hpb=4f551c2bf0d189405e96cbbb8234ed3edd9d6d3e;p=vlc diff --git a/include/modules_inner.h b/include/modules_inner.h index df635e3aa9..d7b5af1dcc 100644 --- a/include/modules_inner.h +++ b/include/modules_inner.h @@ -2,7 +2,7 @@ * modules_inner.h : Macros used from within a module. ***************************************************************************** * Copyright (C) 2001 VideoLAN - * $Id: modules_inner.h,v 1.6 2001/03/21 13:42:33 sam Exp $ + * $Id: modules_inner.h,v 1.37 2003/01/19 03:16:24 sam Exp $ * * Authors: Samuel Hocevar * @@ -10,7 +10,7 @@ * 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 @@ -22,10 +22,10 @@ *****************************************************************************/ /***************************************************************************** - * Check that we are within a module. + * If we are not within a module, assume we're in the vlc core. *****************************************************************************/ -#ifndef MODULE_NAME -# error "You must define MODULE_NAME before using modules_inner.h !" +#if !defined( __PLUGIN__ ) && !defined( __BUILTIN__ ) +# define MODULE_NAME main #endif /***************************************************************************** @@ -36,9 +36,8 @@ * * 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: + * and, if __BUILTIN__ is set, we will also need: * #define MODULE_FUNC( zog ) module_foo_zog * * this can't easily be done with the C preprocessor, thus a few ugly hacks. @@ -49,61 +48,129 @@ #define UGLY_KLUDGE( z ) #z /* And I need to do _this_ to change « foo bar » to « module_foo_bar » ! */ #define CONCATENATE( y, z ) CRUDE_HACK( y, z ) -#define CRUDE_HACK( y, z ) module_##y##_##z - -#define MODULE_VAR( z ) "VLC_MODULE_" #z +#define CRUDE_HACK( y, z ) y##__##z /* If the module is built-in, then we need to define foo_InitModule instead * of InitModule. Same for Activate- and DeactivateModule. */ -#ifdef BUILTIN -# define _M( function ) CONCATENATE( MODULE_NAME, function ) -# define MODULE_INIT \ - int CONCATENATE( MODULE_NAME, InitModule ) ( module_t *p_module ) -# define MODULE_ACTIVATE \ - int CONCATENATE( MODULE_NAME, ActivateModule ) ( module_t *p_module ) -# define MODULE_DEACTIVATE \ - int CONCATENATE( MODULE_NAME, DeactivateModule )( module_t *p_module ) +#if defined( __BUILTIN__ ) +# define E_( function ) CONCATENATE( function, MODULE_NAME ) +# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_NAME ) +# define DECLARE_SYMBOLS struct _u_n_u_s_e_d_ +# define STORE_SYMBOLS struct _u_n_u_s_e_d_ +#elif defined( __PLUGIN__ ) +# define E_( 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 +#endif + +#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 + +#if defined( __cplusplus ) +# define EXTERN_SYMBOL extern "C" #else -# define _M( function ) function -# define MODULE_INIT int InitModule ( module_t *p_module ) -# define MODULE_ACTIVATE int ActivateModule ( module_t *p_module ) -# define MODULE_DEACTIVATE int DeactivateModule ( module_t *p_module ) +# define EXTERN_SYMBOL #endif -/* Now the real stuff */ #define MODULE_STRING STRINGIFY( MODULE_NAME ) -/***************************************************************************** - * Macros used to build the configuration structure. - *****************************************************************************/ -#define MODULE_CONFIG_START \ -static module_config_t p_config[] = { \ - { MODULE_CONFIG_ITEM_START, NULL, NULL, NULL, NULL }, - -#define MODULE_CONFIG_END \ - { MODULE_CONFIG_ITEM_END, NULL, NULL, NULL, NULL } \ -}; - -#define ADD_WINDOW( text ) \ - { MODULE_CONFIG_ITEM_WINDOW, text, NULL, NULL, NULL }, -#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 }, +/* + * 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 + * 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. + */ +#define vlc_module_begin( ) \ + DECLARE_SYMBOLS; \ + EXTERN_SYMBOL DLL_SYMBOL int CDECL_SYMBOL \ + __VLC_SYMBOL(vlc_entry) ( module_t *p_module ) \ + { \ + int i_shortcut = 1, i_config = 0; \ + module_config_t p_config[ 100 ]; \ + STORE_SYMBOLS; \ + p_module->b_submodule = VLC_FALSE; \ + p_module->b_unloadable = VLC_TRUE; \ + p_module->b_reentrant = VLC_TRUE; \ + p_module->psz_object_name = MODULE_STRING; \ + p_module->psz_longname = MODULE_STRING; \ + p_module->pp_shortcuts[ 0 ] = MODULE_STRING; \ + 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 */ + +#define vlc_module_end( ) \ + p_submodule->pp_shortcuts[ i_shortcut ] = NULL; \ + } \ + { \ + static module_config_t tmp = { CONFIG_HINT_END, NULL, NULL, '\0', \ + NULL, NULL, NULL, 0, 0.0, 0, 0, \ + 0.0, 0.0, NULL,NULL, NULL, \ + VLC_FALSE }; \ + p_config[ i_config ] = tmp; \ + } \ + config_Duplicate( p_module, p_config ); \ + if( p_module->p_config == NULL ) \ + { \ + return VLC_EGENERIC; \ + } \ + return VLC_SUCCESS && i_shortcut; \ + } \ + struct _u_n_u_s_e_d_ /* the ; gets added */ + + +#define add_submodule( ) \ + p_submodule->pp_shortcuts[ i_shortcut ] = NULL; \ + p_submodule = \ + (module_t *)vlc_object_create( p_module, VLC_OBJECT_MODULE ); \ + 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 ] = \ + p_module->pp_shortcuts[ i_shortcut ]; \ + } \ + p_submodule->psz_object_name = p_module->psz_object_name; \ + p_submodule->psz_longname = p_module->psz_longname; \ + 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; \ + p_submodule->pf_activate = NULL; \ + p_submodule->pf_deactivate = NULL + +#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 ) \ + p_submodule->psz_longname = desc + +#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 + +#define linked_with_a_crap_library_which_uses_atexit( ) \ + p_module->b_unloadable = VLC_FALSE