Commit d2a0694d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

vlc_module_set: use vararg, more flexible

parent c3b55fa9
......@@ -391,8 +391,6 @@ typedef int ( * vlc_callback_t ) ( vlc_object_t *, /* variable's object */
* Plug-in stuff
*****************************************************************************/
#include "vlc_modules_macros.h"
#if defined (WIN32) && defined (DLL_EXPORT)
# ifdef __cplusplus
# 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
#include "vlc_modules_macros.h"
/*****************************************************************************
* OS-specific headers and thread types
*****************************************************************************/
......
......@@ -52,28 +52,6 @@ VLC_EXPORT(char **, __module_GetModulesNamesForCapability,
( vlc_object_t *p_this, const char * psz_capability,
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( const char *, module_GetObjName, ( const module_t *m ) );
VLC_EXPORT( const char *, module_GetName, ( const module_t *m, bool long_name ) );
......
......@@ -2,7 +2,7 @@
* modules_macros.h : Macros used from within a module.
*****************************************************************************
* Copyright (C) 2001-2006 the VideoLAN team
* $Id$
* Copyright © 2007-2008 Rémi Denis-Courmont
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
......@@ -21,9 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#if !defined( __LIBVLC__ )
#error You are not libvlc or one of its plugins. You cannot include this file
#endif
#ifndef LIBVLC_MODULES_MACROS_H
# define LIBVLC_MODULES_MACROS_H 1
/*****************************************************************************
* 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
* of InitModule. Same for Activate- and DeactivateModule. */
#if defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
#ifdef __PLUGIN__
# define E_( function ) CONCATENATE( function, MODULE_SYMBOL )
# define __VLC_SYMBOL( symbol ) CONCATENATE( symbol, MODULE_SYMBOL )
#else
......@@ -112,7 +111,7 @@ E_(vlc_entry) ( module_t *p_module );
{ \
module_config_t *p_config = NULL; \
if (vlc_module_set (p_module, VLC_MODULE_NAME, \
(void *)(MODULE_STRING))) \
(const char *)(MODULE_STRING))) \
goto error; \
{ \
module_t *p_submodule = p_module /* the ; gets added */
......@@ -123,8 +122,6 @@ E_(vlc_entry) ( module_t *p_module );
return VLC_SUCCESS; \
\
error: \
/* FIXME: config_Free( p_module ); */ \
/* FIXME: cleanup submodules objects ??? */ \
return VLC_EGENERIC; \
} \
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 ) \
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 ) \
if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (void*)(shortcut))) \
if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (int)(shortcut))) \
goto error
#define set_shortname( shortname ) \
if (vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, \
(void*)(shortname))) goto error;
(const char *)(shortname))) \
goto error
#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
#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
#define set_capability( cap, score ) \
if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (void *)(cap)) \
|| vlc_module_set (p_submodule, VLC_MODULE_SCORE, \
(void *)(intptr_t)(score))) \
if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (int)(cap)) \
|| vlc_module_set (p_submodule, VLC_MODULE_SCORE, (int)(score))) \
goto error
#define set_callbacks( activate, deactivate ) \
if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(activate)) \
|| vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, \
(void *)(deactivate))) \
if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, activate) \
|| vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, deactivate)) \
goto error
#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
/*****************************************************************************
* 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
* 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)
{
case VLC_MODULE_CPU_REQUIREMENT:
assert (!module->b_submodule);
module->i_cpu |= (intptr_t)value;
module->i_cpu |= va_arg (ap, int);
break;
case VLC_MODULE_SHORTCUT:
......@@ -93,51 +98,57 @@ int vlc_module_set (module_t *module, int propid, void *value)
unsigned i;
for (i = 0; module->pp_shortcuts[i] != NULL; i++);
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;
}
case VLC_MODULE_SHORTNAME:
module->psz_shortname = (char *)value;
module->psz_shortname = va_arg (ap, char *);
break;
case VLC_MODULE_DESCRIPTION:
module->psz_longname = (char *)value;
module->psz_longname = va_arg (ap, char *);
break;
case VLC_MODULE_HELP:
module->psz_help = (char *)value;
module->psz_help = va_arg (ap, char *);
break;
case VLC_MODULE_CAPABILITY:
module->psz_capability = (char *)value;
module->psz_capability = va_arg (ap, char *);
break;
case VLC_MODULE_SCORE:
module->i_score = (intptr_t)value;
module->i_score = va_arg (ap, int);
break;
case VLC_MODULE_CB_OPEN:
module->pf_activate = (int (*) (vlc_object_t *))value;
module->pf_activate = va_arg (ap, int (*) (vlc_object_t *));
break;
case VLC_MODULE_CB_CLOSE:
module->pf_deactivate = (void (*) (vlc_object_t *))value;
module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *));
break;
case VLC_MODULE_UNLOADABLE:
module->b_unloadable = (value != NULL);
case VLC_MODULE_NO_UNLOAD:
module->b_unloadable = false;
break;
case VLC_MODULE_NAME:
{
const char *value = va_arg (ap, const char *);
free( module->psz_object_name );
module->psz_object_name = strdup( (char *)value );
module->pp_shortcuts[0] = (char *)value;
module->psz_object_name = strdup( value );
module->pp_shortcuts[0] = value;
if (module->psz_longname == default_name)
module->psz_longname = (char *)value;
module->psz_longname = value;
break;
}
case VLC_MODULE_PROGRAM:
msg_Warn (module, "deprecated module property %d", propid);
......@@ -146,9 +157,11 @@ int vlc_module_set (module_t *module, int propid, void *value)
default:
msg_Err (module, "unknown module property %d", propid);
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment