Changeset d2a0694d908f98db8b8dadbaaa2db07253344f16

Show
Ignore:
Timestamp:
05/08/08 18:20:19 (2 months ago)
Author:
Rémi Denis-Courmont <rem@videolan.org>
git-committer:
Rémi Denis-Courmont <rem@videolan.org> 1210263619 +0300
git-parent:

[c3b55fa92cbc1a37e1880a773ec264aecec52486]

git-author:
Rémi Denis-Courmont <rem@videolan.org> 1210259576 +0300
Message:

vlc_module_set: use vararg, more flexible

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_common.h

    rf802543 rd2a0694  
    391391 * Plug-in stuff 
    392392 *****************************************************************************/ 
    393  
    394 #include "vlc_modules_macros.h" 
    395393 
    396394#if defined (WIN32) && defined (DLL_EXPORT) 
     
    432430#  endif 
    433431#endif 
     432 
     433#include "vlc_modules_macros.h" 
    434434 
    435435/***************************************************************************** 
  • include/vlc_modules.h

    r449fd28 rd2a0694  
    5353                      char ***psz_longname ) ); 
    5454 
    55 VLC_EXPORT( module_t *, vlc_module_create, ( vlc_object_t * ) ); 
    56 VLC_EXPORT( module_t *, vlc_submodule_create, ( module_t * ) ); 
    57 VLC_EXPORT( int, vlc_module_set, (module_t *module, int propid, void *value) ); 
    58  
    59 enum vlc_module_properties 
    60 { 
    61     /* DO NOT EVER REMOVE, INSERT OR REPLACE ANY ITEM! It would break the ABI! 
    62      * Append new items at the end ONLY. */ 
    63     VLC_MODULE_CPU_REQUIREMENT, 
    64     VLC_MODULE_SHORTCUT, 
    65     VLC_MODULE_SHORTNAME, 
    66     VLC_MODULE_DESCRIPTION, 
    67     VLC_MODULE_HELP, 
    68     VLC_MODULE_CAPABILITY, 
    69     VLC_MODULE_SCORE, 
    70     VLC_MODULE_PROGRAM, 
    71     VLC_MODULE_CB_OPEN, 
    72     VLC_MODULE_CB_CLOSE, 
    73     VLC_MODULE_UNLOADABLE, 
    74     VLC_MODULE_NAME, 
    75 }; 
    76  
    7755VLC_EXPORT( bool, module_IsCapable, ( const module_t *m, const char *cap ) ); 
    7856VLC_EXPORT( const char *, module_GetObjName, ( const module_t *m ) ); 
  • include/vlc_modules_macros.h

    r7f68203 rd2a0694  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001-2006 the VideoLAN team 
    5  * $Id$ 
     5 * Copyright © 2007-2008 Rémi Denis-Courmont 
    66 * 
    77 * Authors: Samuel Hocevar <sam@zoy.org> 
     
    2222 *****************************************************************************/ 
    2323 
    24 #if !defined( __LIBVLC__ ) 
    25   #error You are not libvlc or one of its plugins. You cannot include this file 
    26 #endif 
     24#ifndef LIBVLC_MODULES_MACROS_H 
     25# define LIBVLC_MODULES_MACROS_H 1 
    2726 
    2827/***************************************************************************** 
     
    6362/* If the module is built-in, then we need to define foo_InitModule instead 
    6463 * of InitModule. Same for Activate- and DeactivateModule. */ 
    65 #if defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) 
     64#ifdef __PLUGIN__ 
    6665#   define E_( function )          CONCATENATE( function, MODULE_SYMBOL ) 
    6766#   define __VLC_SYMBOL( symbol  ) CONCATENATE( symbol, MODULE_SYMBOL ) 
     
    113112        module_config_t *p_config = NULL;                                     \ 
    114113        if (vlc_module_set (p_module, VLC_MODULE_NAME,                        \ 
    115                             (void *)(MODULE_STRING)))                         \ 
     114                            (const char *)(MODULE_STRING)))                   \ 
    116115            goto error;                                                       \ 
    117116        {                                                                     \ 
     
    124123                                                                              \ 
    125124    error:                                                                    \ 
    126         /* FIXME: config_Free( p_module ); */                                 \ 
    127         /* FIXME: cleanup submodules objects ??? */                           \ 
    128125        return VLC_EGENERIC;                                                  \ 
    129126    }                                                                         \ 
     
    136133#define add_requirement( cap ) \ 
    137134    if (vlc_module_set (p_module, VLC_MODULE_CPU_REQUIREMENT, \ 
    138                         (void *)(intptr_t)(CPU_CAPABILITY_##cap))) goto error 
     135                        (int)(CPU_CAPABILITY_##cap))) \ 
     136        goto error 
    139137 
    140138#define add_shortcut( shortcut ) \ 
    141     if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (void*)(shortcut))) \ 
     139    if (vlc_module_set (p_submodule, VLC_MODULE_SHORTCUT, (int)(shortcut))) \ 
    142140        goto error 
    143141 
    144142#define set_shortname( shortname ) \ 
    145143    if (vlc_module_set (p_submodule, VLC_MODULE_SHORTNAME, \ 
    146                         (void*)(shortname))) goto error; 
     144        (const char *)(shortname))) \ 
     145        goto error 
    147146 
    148147#define set_description( desc ) \ 
    149     if (vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, (void*)(desc))) \ 
     148    if (vlc_module_set (p_submodule, VLC_MODULE_DESCRIPTION, \ 
     149                        (const char *)(desc))) \ 
    150150        goto error 
    151151 
    152152#define set_help( help ) \ 
    153     if (vlc_module_set (p_submodule, VLC_MODULE_HELP, (void*)(help))) \ 
     153    if (vlc_module_set (p_submodule, VLC_MODULE_HELP, (const char *)(help))) \ 
    154154        goto error 
    155155 
    156156#define set_capability( cap, score ) \ 
    157     if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (void *)(cap)) \ 
    158      || vlc_module_set (p_submodule, VLC_MODULE_SCORE, \ 
    159                         (void *)(intptr_t)(score))) \ 
     157    if (vlc_module_set (p_submodule, VLC_MODULE_CAPABILITY, (int)(cap)) \ 
     158     || vlc_module_set (p_submodule, VLC_MODULE_SCORE, (int)(score))) \ 
    160159        goto error 
    161160 
    162161#define set_callbacks( activate, deactivate ) \ 
    163     if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, (void *)(activate)) \ 
    164      || vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, \ 
    165                         (void *)(deactivate))) \ 
     162    if (vlc_module_set (p_submodule, VLC_MODULE_CB_OPEN, activate) \ 
     163     || vlc_module_set (p_submodule, VLC_MODULE_CB_CLOSE, deactivate)) \ 
    166164        goto error 
    167165 
    168166#define linked_with_a_crap_library_which_uses_atexit( ) \ 
    169     if (vlc_module_set (p_submodule, VLC_MODULE_UNLOADABLE, NULL)) goto error 
     167    if (vlc_module_set (p_submodule, VLC_MODULE_NO_UNLOAD)) \ 
     168        goto error 
    170169 
     170VLC_EXPORT( module_t *, vlc_module_create, ( vlc_object_t * ) ); 
     171VLC_EXPORT( module_t *, vlc_submodule_create, ( module_t * ) ); 
     172VLC_EXPORT( int, vlc_module_set, (module_t *module, int propid, ...) ); 
     173 
     174enum vlc_module_properties 
     175{ 
     176    /* DO NOT EVER REMOVE, INSERT OR REPLACE ANY ITEM! It would break the ABI! 
     177     * Append new items at the end ONLY. */ 
     178    VLC_MODULE_CPU_REQUIREMENT, 
     179    VLC_MODULE_SHORTCUT, 
     180    VLC_MODULE_SHORTNAME, 
     181    VLC_MODULE_DESCRIPTION, 
     182    VLC_MODULE_HELP, 
     183    VLC_MODULE_CAPABILITY, 
     184    VLC_MODULE_SCORE, 
     185    VLC_MODULE_PROGRAM, 
     186    VLC_MODULE_CB_OPEN, 
     187    VLC_MODULE_CB_CLOSE, 
     188    VLC_MODULE_NO_UNLOAD, 
     189    VLC_MODULE_NAME, 
     190}; 
     191#endif 
  • src/modules/entry.c

    rf864df7 rd2a0694  
    22 * entry.c : Callbacks for module entry point 
    33 ***************************************************************************** 
    4  * Copyright (C) 2001-2007 the VideoLAN team 
     4 * Copyright (C) 2007 the VideoLAN team 
     5 * Copyright © 2007-2008 Rémi Denis-Courmont 
    56 * 
    67 * This program is free software; you can redistribute it and/or modify 
     
    8081 
    8182 
    82 int vlc_module_set (module_t *module, int propid, void *value
     83int vlc_module_set (module_t *module, int propid, ...
    8384{ 
     85    va_list ap; 
     86    int ret = VLC_SUCCESS; 
     87 
     88    va_start (ap, propid); 
    8489    switch (propid) 
    8590    { 
    8691        case VLC_MODULE_CPU_REQUIREMENT: 
    8792            assert (!module->b_submodule); 
    88             module->i_cpu |= (intptr_t)value
     93            module->i_cpu |= va_arg (ap, int)
    8994            break; 
    9095 
     
    9499            for (i = 0; module->pp_shortcuts[i] != NULL; i++); 
    95100            if (i >= (MODULE_SHORTCUT_MAX - 1)) 
    96                 return VLC_ENOMEM; 
    97  
    98             module->pp_shortcuts[i] = (char *)value; 
     101            { 
     102                ret = VLC_ENOMEM; 
     103                break; 
     104            } 
     105 
     106            module->pp_shortcuts[i] = va_arg (ap, char *); 
    99107            break; 
    100108        } 
    101109 
    102110        case VLC_MODULE_SHORTNAME: 
    103             module->psz_shortname = (char *)value
     111            module->psz_shortname = va_arg (ap, char *)
    104112            break; 
    105113 
    106114        case VLC_MODULE_DESCRIPTION: 
    107             module->psz_longname = (char *)value
     115            module->psz_longname = va_arg (ap, char *)
    108116            break; 
    109117 
    110118        case VLC_MODULE_HELP: 
    111             module->psz_help = (char *)value
     119            module->psz_help = va_arg (ap, char *)
    112120            break; 
    113121 
    114122        case VLC_MODULE_CAPABILITY: 
    115             module->psz_capability = (char *)value
     123            module->psz_capability = va_arg (ap, char *)
    116124            break; 
    117125 
    118126        case VLC_MODULE_SCORE: 
    119             module->i_score = (intptr_t)value
     127            module->i_score = va_arg (ap, int)
    120128            break; 
    121129 
    122130        case VLC_MODULE_CB_OPEN: 
    123             module->pf_activate = (int (*) (vlc_object_t *))value
     131            module->pf_activate = va_arg (ap, int (*) (vlc_object_t *))
    124132            break; 
    125133 
    126134        case VLC_MODULE_CB_CLOSE: 
    127             module->pf_deactivate = (void (*) (vlc_object_t *))value
    128             break; 
    129  
    130         case VLC_MODULE_UNLOADABLE
    131             module->b_unloadable = (value != NULL)
     135            module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *))
     136            break; 
     137 
     138        case VLC_MODULE_NO_UNLOAD
     139            module->b_unloadable = false
    132140            break; 
    133141 
    134142        case VLC_MODULE_NAME: 
     143        { 
     144            const char *value = va_arg (ap, const char *); 
    135145            free( module->psz_object_name ); 
    136             module->psz_object_name = strdup( (char *)value ); 
    137             module->pp_shortcuts[0] = (char *)value; 
     146            module->psz_object_name = strdup( value ); 
     147            module->pp_shortcuts[0] = value; 
    138148            if (module->psz_longname == default_name) 
    139                 module->psz_longname = (char *)value; 
    140             break; 
     149                module->psz_longname = value; 
     150            break; 
     151        } 
    141152 
    142153        case VLC_MODULE_PROGRAM: 
     
    147158            msg_Err (module, "unknown module property %d", propid); 
    148159            msg_Err (module, "LibVLC might be too old to use this module."); 
    149             return VLC_EGENERIC; 
     160            ret = VLC_EGENERIC; 
     161            break; 
    150162    } 
    151     return 0; 
     163    va_end (ap); 
     164    return ret; 
    152165} 
    153166