vlc_module_set: use vararg, more flexible

This commit is contained in:
Rémi Denis-Courmont 2008-05-08 18:12:56 +03:00
parent c3b55fa92c
commit d2a0694d90
4 changed files with 75 additions and 63 deletions

View File

@ -391,8 +391,6 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
* Plug-in stuff * Plug-in stuff
*****************************************************************************/ *****************************************************************************/
#include "vlc_modules_macros.h"
#if defined (WIN32) && defined (DLL_EXPORT) #if defined (WIN32) && defined (DLL_EXPORT)
# ifdef __cplusplus # ifdef __cplusplus
# define VLC_PUBLIC_API extern "C" __declspec(dllexport) # define VLC_PUBLIC_API extern "C" __declspec(dllexport)
@ -432,6 +430,8 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
# endif # endif
#endif #endif
#include "vlc_modules_macros.h"
/***************************************************************************** /*****************************************************************************
* OS-specific headers and thread types * OS-specific headers and thread types
*****************************************************************************/ *****************************************************************************/

View File

@ -52,28 +52,6 @@ VLC_EXPORT(char **, __module_GetModulesNamesForCapability,
( vlc_object_t *p_this, const char * psz_capability, ( vlc_object_t *p_this, const char * psz_capability,
char ***psz_longname ) ); char ***psz_longname ) );
VLC_EXPORT( module_t *, vlc_module_create, ( vlc_object_t * ) );
VLC_EXPORT( module_t *, vlc_submodule_create, ( module_t * ) );
VLC_EXPORT( int, vlc_module_set, (module_t *module, int propid, void *value) );
enum vlc_module_properties
{
/* DO NOT EVER REMOVE, INSERT OR REPLACE ANY ITEM! It would break the ABI!
* Append new items at the end ONLY. */
VLC_MODULE_CPU_REQUIREMENT,
VLC_MODULE_SHORTCUT,
VLC_MODULE_SHORTNAME,
VLC_MODULE_DESCRIPTION,
VLC_MODULE_HELP,
VLC_MODULE_CAPABILITY,
VLC_MODULE_SCORE,
VLC_MODULE_PROGRAM,
VLC_MODULE_CB_OPEN,
VLC_MODULE_CB_CLOSE,
VLC_MODULE_UNLOADABLE,
VLC_MODULE_NAME,
};
VLC_EXPORT( bool, module_IsCapable, ( const module_t *m, const char *cap ) ); VLC_EXPORT( bool, module_IsCapable, ( const module_t *m, const char *cap ) );
VLC_EXPORT( const char *, module_GetObjName, ( const module_t *m ) ); VLC_EXPORT( const char *, module_GetObjName, ( const module_t *m ) );
VLC_EXPORT( const char *, module_GetName, ( const module_t *m, bool long_name ) ); VLC_EXPORT( const char *, module_GetName, ( const module_t *m, bool long_name ) );

View File

@ -2,7 +2,7 @@
* modules_macros.h : Macros used from within a module. * modules_macros.h : Macros used from within a module.
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2006 the VideoLAN team * Copyright (C) 2001-2006 the VideoLAN team
* $Id$ * Copyright © 2007-2008 Rémi Denis-Courmont
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
@ -21,9 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#if !defined( __LIBVLC__ ) #ifndef LIBVLC_MODULES_MACROS_H
#error You are not libvlc or one of its plugins. You cannot include this file # define LIBVLC_MODULES_MACROS_H 1
#endif
/***************************************************************************** /*****************************************************************************
* If we are not within a module, assume we're in the vlc core. * If we are not within a module, assume we're in the vlc core.
@ -62,7 +61,7 @@
/* If the module is built-in, then we need to define foo_InitModule instead /* If the module is built-in, then we need to define foo_InitModule instead
* of InitModule. Same for Activate- and DeactivateModule. */ * of InitModule. Same for Activate- and DeactivateModule. */
#if defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) #ifdef __PLUGIN__
# define E_( function ) CONCATENATE( function, MODULE_SYMBOL ) # define E_( function ) CONCATENATE( function, MODULE_SYMBOL )
# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_SYMBOL ) # define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_SYMBOL )
#else #else
@ -112,7 +111,7 @@ E_(vlc_entry) ( module_t *p_module );
{ \ { \
module_config_t *p_config = NULL; \ module_config_t *p_config = NULL; \
if (vlc_module_set (p_module, VLC_MODULE_NAME, \ if (vlc_module_set (p_module, VLC_MODULE_NAME, \
(void *)(MODULE_STRING))) \ (const char *)(MODULE_STRING))) \
goto error; \ goto error; \
{ \ { \
module_t *p_submodule = p_module /* the ; gets added */ module_t *p_submodule = p_module /* the ; gets added */
@ -123,8 +122,6 @@ E_(vlc_entry) ( module_t *p_module );
return VLC_SUCCESS; \ return VLC_SUCCESS; \
\ \
error: \ error: \
/* FIXME: config_Free( p_module ); */ \
/* FIXME: cleanup submodules objects ??? */ \
return VLC_EGENERIC; \ return VLC_EGENERIC; \
} \ } \
struct _u_n_u_s_e_d_ /* the ; gets added */ struct _u_n_u_s_e_d_ /* the ; gets added */
@ -135,36 +132,60 @@ E_(vlc_entry) ( module_t *p_module );
#define add_requirement( cap ) \ #define add_requirement( cap ) \
if (vlc_module_set (p_module, VLC_MODULE_CPU_REQUIREMENT, \ if (vlc_module_set (p_module, VLC_MODULE_CPU_REQUIREMENT, \
(void *)(intptr_t)(CPU_CAPABILITY_##cap))) goto error (int)(CPU_CAPABILITY_##cap))) \
goto error
#define add_shortcut( shortcut ) \ #define add_shortcut( shortcut ) \
if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (void*)(shortcut))) \ if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (int)(shortcut))) \
goto error goto error
#define set_shortname( shortname ) \ #define set_shortname( shortname ) \
if (vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, \ if (vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, \
(void*)(shortname))) goto error; (const char *)(shortname))) \
goto error
#define set_description( desc ) \ #define set_description( desc ) \
if (vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, (void*)(desc))) \ if (vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, \
(const char *)(desc))) \
goto error goto error
#define set_help( help ) \ #define set_help( help ) \
if (vlc_module_set (p_submodule, VLC_MODULE_HELP, (void*)(help))) \ if (vlc_module_set (p_submodule, VLC_MODULE_HELP, (const char *)(help))) \
goto error goto error
#define set_capability( cap, score ) \ #define set_capability( cap, score ) \
if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (void *)(cap)) \ if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (int)(cap)) \
|| vlc_module_set (p_submodule, VLC_MODULE_SCORE, \ || vlc_module_set (p_submodule, VLC_MODULE_SCORE, (int)(score))) \
(void *)(intptr_t)(score))) \
goto error goto error
#define set_callbacks( activate, deactivate ) \ #define set_callbacks( activate, deactivate ) \
if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(activate)) \ if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, activate) \
|| vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, \ || vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, deactivate)) \
(void *)(deactivate))) \
goto error goto error
#define linked_with_a_crap_library_which_uses_atexit( ) \ #define linked_with_a_crap_library_which_uses_atexit( ) \
if (vlc_module_set (p_submodule, VLC_MODULE_UNLOADABLE, NULL)) goto error if (vlc_module_set (p_submodule, VLC_MODULE_NO_UNLOAD)) \
goto error
VLC_EXPORT( module_t *, vlc_module_create, ( vlc_object_t * ) );
VLC_EXPORT( module_t *, vlc_submodule_create, ( module_t * ) );
VLC_EXPORT( int, vlc_module_set, (module_t *module, int propid, ...) );
enum vlc_module_properties
{
/* DO NOT EVER REMOVE, INSERT OR REPLACE ANY ITEM! It would break the ABI!
* Append new items at the end ONLY. */
VLC_MODULE_CPU_REQUIREMENT,
VLC_MODULE_SHORTCUT,
VLC_MODULE_SHORTNAME,
VLC_MODULE_DESCRIPTION,
VLC_MODULE_HELP,
VLC_MODULE_CAPABILITY,
VLC_MODULE_SCORE,
VLC_MODULE_PROGRAM,
VLC_MODULE_CB_OPEN,
VLC_MODULE_CB_CLOSE,
VLC_MODULE_NO_UNLOAD,
VLC_MODULE_NAME,
};
#endif

View File

@ -1,7 +1,8 @@
/***************************************************************************** /*****************************************************************************
* entry.c : Callbacks for module entry point * entry.c : Callbacks for module entry point
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2007 the VideoLAN team * Copyright (C) 2007 the VideoLAN team
* Copyright © 2007-2008 Rémi Denis-Courmont
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -79,13 +80,17 @@ module_t *vlc_submodule_create (module_t *module)
} }
int vlc_module_set (module_t *module, int propid, void *value) int vlc_module_set (module_t *module, int propid, ...)
{ {
va_list ap;
int ret = VLC_SUCCESS;
va_start (ap, propid);
switch (propid) switch (propid)
{ {
case VLC_MODULE_CPU_REQUIREMENT: case VLC_MODULE_CPU_REQUIREMENT:
assert (!module->b_submodule); assert (!module->b_submodule);
module->i_cpu |= (intptr_t)value; module->i_cpu |= va_arg (ap, int);
break; break;
case VLC_MODULE_SHORTCUT: case VLC_MODULE_SHORTCUT:
@ -93,51 +98,57 @@ int vlc_module_set (module_t *module, int propid, void *value)
unsigned i; unsigned i;
for (i = 0; module->pp_shortcuts[i] != NULL; i++); for (i = 0; module->pp_shortcuts[i] != NULL; i++);
if (i >= (MODULE_SHORTCUT_MAX - 1)) if (i >= (MODULE_SHORTCUT_MAX - 1))
return VLC_ENOMEM; {
ret = VLC_ENOMEM;
break;
}
module->pp_shortcuts[i] = (char *)value; module->pp_shortcuts[i] = va_arg (ap, char *);
break; break;
} }
case VLC_MODULE_SHORTNAME: case VLC_MODULE_SHORTNAME:
module->psz_shortname = (char *)value; module->psz_shortname = va_arg (ap, char *);
break; break;
case VLC_MODULE_DESCRIPTION: case VLC_MODULE_DESCRIPTION:
module->psz_longname = (char *)value; module->psz_longname = va_arg (ap, char *);
break; break;
case VLC_MODULE_HELP: case VLC_MODULE_HELP:
module->psz_help = (char *)value; module->psz_help = va_arg (ap, char *);
break; break;
case VLC_MODULE_CAPABILITY: case VLC_MODULE_CAPABILITY:
module->psz_capability = (char *)value; module->psz_capability = va_arg (ap, char *);
break; break;
case VLC_MODULE_SCORE: case VLC_MODULE_SCORE:
module->i_score = (intptr_t)value; module->i_score = va_arg (ap, int);
break; break;
case VLC_MODULE_CB_OPEN: case VLC_MODULE_CB_OPEN:
module->pf_activate = (int (*) (vlc_object_t *))value; module->pf_activate = va_arg (ap, int (*) (vlc_object_t *));
break; break;
case VLC_MODULE_CB_CLOSE: case VLC_MODULE_CB_CLOSE:
module->pf_deactivate = (void (*) (vlc_object_t *))value; module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *));
break; break;
case VLC_MODULE_UNLOADABLE: case VLC_MODULE_NO_UNLOAD:
module->b_unloadable = (value != NULL); module->b_unloadable = false;
break; break;
case VLC_MODULE_NAME: case VLC_MODULE_NAME:
{
const char *value = va_arg (ap, const char *);
free( module->psz_object_name ); free( module->psz_object_name );
module->psz_object_name = strdup( (char *)value ); module->psz_object_name = strdup( value );
module->pp_shortcuts[0] = (char *)value; module->pp_shortcuts[0] = value;
if (module->psz_longname == default_name) if (module->psz_longname == default_name)
module->psz_longname = (char *)value; module->psz_longname = value;
break; break;
}
case VLC_MODULE_PROGRAM: case VLC_MODULE_PROGRAM:
msg_Warn (module, "deprecated module property %d", propid); msg_Warn (module, "deprecated module property %d", propid);
@ -146,9 +157,11 @@ int vlc_module_set (module_t *module, int propid, void *value)
default: default:
msg_Err (module, "unknown module property %d", propid); msg_Err (module, "unknown module property %d", propid);
msg_Err (module, "LibVLC might be too old to use this module."); msg_Err (module, "LibVLC might be too old to use this module.");
return VLC_EGENERIC; ret = VLC_EGENERIC;
break;
} }
return 0; va_end (ap);
return ret;
} }
module_config_t *vlc_config_create (module_t *module, int type) module_config_t *vlc_config_create (module_t *module, int type)