Changeset 460a78baf1f189de5d4178df31dc229ac1e366ca

Show
Ignore:
Timestamp:
21/09/08 12:30:48 (2 months ago)
Author:
Rémi Denis-Courmont <rdenis@simphalempin.com>
git-committer:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1221993048 +0300
git-parent:

[fd0f3ec33c7bdfb15217f7c3eaf171c6045135ee]

git-author:
Rémi Denis-Courmont <rdenis@simphalempin.com> 1221991648 +0300
Message:

New type-safe API for modules listing

module_list_get(): gets the list of modules
module_list_free(): releases the list

Files:

Legend:

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

    rebd8003 r460a78b  
    4545VLC_EXPORT( void, module_PutConfig, ( module_config_t * ) ); 
    4646 
     47VLC_EXPORT( void, module_list_free, (module_t **) ); 
     48VLC_EXPORT( module_t **, module_list_get, (size_t *n) ); 
     49 
    4750/* Return a NULL terminated array with the names of the modules that have a 
    4851 * certain capability. 
  • src/config/cmdline.c

    r924a067 r460a78b  
    5858    int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0; 
    5959    module_t *p_parser; 
    60     vlc_list_t *p_list; 
    6160    struct option *p_longopts; 
    6261    int i_modules_index; 
     
    8685 
    8786    /* List all modules */ 
    88     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
     87    module_t **list = module_list_get (NULL); 
    8988 
    9089    /* 
     
    9392 
    9493    i_opts = 0; 
    95     for( i_modules_index = 0; i_modules_index < p_list->i_count; 
    96          i_modules_index++ ) 
    97     { 
    98         p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; 
    99  
     94    for (size_t i = 0; (p_parser = list[i]) != NULL; i++) 
    10095        /* count the number of exported configuration options (to allocate 
    10196         * longopts). We also need to allocate space for two options when 
    10297         * dealing with boolean to allow for --foo and --no-foo */ 
    103         i_opts += p_parser->i_config_items 
    104                      + 2 * p_parser->i_bool_items; 
    105     } 
     98        i_opts += p_parser->i_config_items + 2 * p_parser->i_bool_items; 
    10699 
    107100    p_longopts = malloc( sizeof(struct option) * (i_opts + 1) ); 
    108101    if( p_longopts == NULL ) 
    109102    { 
    110         vlc_list_release( p_list ); 
     103        module_list_free (list); 
    111104        return -1; 
    112105    } 
     
    116109    { 
    117110        free( p_longopts ); 
    118         vlc_list_release( p_list ); 
     111        module_list_free (list); 
    119112        return -1; 
    120113    } 
     
    130123            free( psz_shortopts ); 
    131124            free( p_longopts ); 
    132             vlc_list_release( p_list ); 
     125            module_list_free (list); 
    133126            return -1; 
    134127        } 
     
    145138    /* Fill the p_longopts and psz_shortopts structures */ 
    146139    i_index = 0; 
    147     for( i_modules_index = 0; i_modules_index < p_list->i_count; 
    148          i_modules_index++ ) 
     140    for (size_t i = 0; (p_parser = list[i]) != NULL; i++) 
    149141    { 
    150142        module_config_t *p_item, *p_end; 
    151         p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; 
    152143 
    153144        if( !p_parser->i_config_items ) 
     
    227218 
    228219    /* We don't need the module list anymore */ 
    229     vlc_list_release( p_list ); 
     220    module_list_free( list ); 
    230221 
    231222    /* Close the longopts and shortopts structures */ 
  • src/config/core.c

    rd666030 r460a78b  
    410410module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name ) 
    411411{ 
    412     vlc_list_t *p_list; 
    413     int i_index; 
     412    module_t *p_parser; 
    414413 
    415414    if( !psz_name ) return NULL; 
    416415 
    417     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
    418  
    419     for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
     416    module_t **list = module_list_get (NULL); 
     417    if (list == NULL) 
     418        return NULL; 
     419 
     420    for (size_t i = 0; (p_parser = list[i]) != NULL; i++) 
    420421    { 
    421422        module_config_t *p_item, *p_end; 
    422         module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object; 
    423423 
    424424        if( !p_parser->i_config_items ) 
     
    436436              && !strcmp( psz_name, p_item->psz_oldname ) ) ) 
    437437            { 
    438                 vlc_list_release( p_list ); 
     438                module_list_free (list); 
    439439                return p_item; 
    440440            } 
     
    442442    } 
    443443 
    444     vlc_list_release( p_list ); 
    445  
     444    module_list_free (list); 
    446445    return NULL; 
    447446} 
     
    537536    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); 
    538537    int i_index; 
    539     vlc_list_t *p_list; 
    540538    module_t *p_module; 
     539    module_t **list = module_list_get (NULL); 
    541540 
    542541    /* Acquire config file lock */ 
    543542    vlc_mutex_lock( &priv->config_lock ); 
    544543 
    545     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
    546  
    547     for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
    548     { 
    549         p_module = (module_t *)p_list->p_values[i_index].p_object ; 
     544 
     545    for (size_t j = 0; (p_module = list[j]) != NULL; j++) 
     546    { 
    550547        if( p_module->b_submodule ) continue; 
    551548 
     
    567564    } 
    568565 
    569     vlc_list_release( p_list ); 
     566    module_list_free (list); 
    570567    vlc_mutex_unlock( &priv->config_lock ); 
    571568} 
  • src/config/file.c

    r2320905 r460a78b  
    159159{ 
    160160    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); 
    161     vlc_list_t *p_list; 
    162161    FILE *file; 
    163162 
     
    170169 
    171170    /* Look for the selected module, if NULL then save everything */ 
    172     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
     171    module_t **list = module_list_get (NULL); 
    173172 
    174173    /* Look for UTF-8 Byte Order Mark */ 
     
    216215             || (strcmp (psz_module_name, section) == 0)) 
    217216            { 
    218                 for (int i = 0; i < p_list->i_count; i++) 
     217                for (int i = 0; list[i]; i++) 
    219218                { 
    220                     module_t *m = (module_t *)p_list->p_values[i].p_object
     219                    module_t *m = list[i]
    221220 
    222221                    if ((strcmp (section, m->psz_object_name) == 0) 
     
    318317    fclose (file); 
    319318 
    320     vlc_list_release( p_list ); 
     319    module_list_free (list); 
    321320    if (loc != (locale_t)0) 
    322321    { 
     
    417416    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); 
    418417    module_t *p_parser; 
    419     vlc_list_t *p_list; 
    420418    FILE *file; 
    421419    char p_line[1024], *p_index2; 
     
    461459 
    462460    /* List all available modules */ 
    463     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
     461    module_t **list = module_list_get (NULL); 
    464462 
    465463    /* backup file into memory, we only need to backup the sections we won't 
     
    472470 
    473471            /* we found a section, check if we need to do a backup */ 
    474             for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
    475             { 
    476                 p_parser = (module_t *)p_list->p_values[i_index].p_object ; 
    477  
     472            for( i_index = 0; (p_parser = list[i_index]) != NULL; i_index++ ) 
     473            { 
    478474                if( ((p_index2 - &p_line[1]) 
    479475                       == (int)strlen(p_parser->psz_object_name) ) 
     
    489485            } 
    490486 
    491             if( i_index == p_list->i_count
     487            if( list[i_index] == NULL
    492488            { 
    493489                /* we don't have this section in our list so we need to back 
     
    527523    if( !file ) 
    528524    { 
    529         vlc_list_release( p_list ); 
     525        module_list_free (list); 
    530526        free( p_bigbuffer ); 
    531527        vlc_mutex_unlock( &priv->config_lock ); 
     
    541537 
    542538    /* Look for the selected module, if NULL then save everything */ 
    543     for( i_index = 0; i_index < p_list->i_count; i_index++ ) 
     539    for( i_index = 0; (p_parser = list[i_index]) != NULL; i_index++ ) 
    544540    { 
    545541        module_config_t *p_item, *p_end; 
    546         p_parser = (module_t *)p_list->p_values[i_index].p_object ; 
    547542 
    548543        if( psz_module_name && strcmp( psz_module_name, 
     
    645640    } 
    646641 
    647     vlc_list_release( p_list ); 
     642    module_list_free (list); 
    648643    if (loc != (locale_t)0) 
    649644    { 
     
    667662{ 
    668663    libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); 
    669     vlc_list_t *p_list
    670     int i_index, i_count
     664    size_t i_index
     665    bool done
    671666 
    672667    assert( p_this ); 
     
    674669    /* Check if there's anything to save */ 
    675670    vlc_mutex_lock( &priv->config_lock ); 
    676     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
    677     i_count = p_list->i_count; 
    678     for( i_index = 0; i_index < i_count; i_index++ ) 
    679     { 
    680         module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object ; 
     671    module_t **list = module_list_get (NULL); 
     672    for( i_index = 0; list[i_index]; i_index++ ) 
     673    { 
     674        module_t *p_parser = list[i_index]; 
    681675        module_config_t *p_item, *p_end; 
    682676 
     
    691685        if( p_item < p_end ) break; 
    692686    } 
    693     vlc_list_release( p_list ); 
     687    done = list[i_index] == NULL; 
     688    module_list_free (list); 
    694689    vlc_mutex_unlock( &priv->config_lock ); 
    695690 
    696     if( i_index == i_count ) return VLC_SUCCESS; 
    697     return SaveConfigFile( p_this, NULL, true ); 
     691    return done ? VLC_SUCCESS : SaveConfigFile( p_this, NULL, true ); 
    698692} 
    699693 
  • src/libvlc.c

    rcc2d7b4 r460a78b  
    14251425#   define OPTION_VALUE_SEP " " 
    14261426#endif 
    1427     vlc_list_t *p_list = NULL; 
    14281427    char psz_spaces_text[PADDING_SPACES+LINE_START+1]; 
    14291428    char psz_spaces_longtext[LINE_START+3]; 
     
    14321431    char psz_buffer[10000]; 
    14331432    char psz_short[4]; 
    1434     int i_index; 
    14351433    int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1); 
    14361434    int i_width_description = i_width + PADDING_SPACES - 1; 
     
    14671465 
    14681466    /* List all modules */ 
    1469     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
     1467    module_t **list = module_list_get (NULL); 
     1468    if (!list) 
     1469        return; 
    14701470 
    14711471    /* Ugly hack to make sure that the help options always come first 
     
    14751475 
    14761476    /* Enumerate the config for each module */ 
    1477     for( i_index = 0; i_index < p_list->i_count; i_index++
     1477    for (size_t i = 0; list[i]; i++
    14781478    { 
    14791479        bool b_help_module; 
    1480         module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object
     1480        module_t *p_parser = list[i]
    14811481        module_config_t *p_item = NULL; 
    14821482        module_config_t *p_section = NULL; 
     
    18711871 
    18721872    /* Release the module list */ 
    1873     vlc_list_release( p_list ); 
     1873    module_list_free (list); 
    18741874} 
    18751875 
     
    18821882static void ListModules( libvlc_int_t *p_this, bool b_verbose ) 
    18831883{ 
    1884     vlc_list_t *p_list = NULL; 
    1885     module_t *p_parser = NULL; 
     1884    module_t *p_parser; 
    18861885    char psz_spaces[22]; 
    1887     int i_index; 
    18881886 
    18891887    bool b_color = config_GetInt( p_this, "color" ) > 0; 
     
    18961894 
    18971895    /* List all modules */ 
    1898     p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); 
     1896    module_t **list = module_list_get (NULL); 
    18991897 
    19001898    /* Enumerate each module */ 
    1901     for( i_index = 0; i_index < p_list->i_count; i_index++
     1899    for (size_t j = 0; (p_parser = list[j]) != NULL; j++
    19021900    { 
    19031901        int i; 
    1904  
    1905         p_parser = (module_t *)p_list->p_values[i_index].p_object ; 
    19061902 
    19071903        /* Nasty hack, but right now I'm too tired to think about a nice 
     
    19521948        psz_spaces[i] = ' '; 
    19531949    } 
    1954  
    1955     vlc_list_release( p_list ); 
     1950    module_list_free (list); 
    19561951 
    19571952#ifdef WIN32        /* Pause the console because it's destroyed when we exit */ 
  • src/libvlccore.sym

    rf0c76d5 r460a78b  
    213213module_GetObjName 
    214214module_IsCapable 
     215module_list_free 
     216module_list_get 
    215217__module_Need 
    216218module_Put