Changeset 460a78baf1f189de5d4178df31dc229ac1e366ca
- 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
| rebd8003 |
r460a78b |
|
| 45 | 45 | VLC_EXPORT( void, module_PutConfig, ( module_config_t * ) ); |
|---|
| 46 | 46 | |
|---|
| | 47 | VLC_EXPORT( void, module_list_free, (module_t **) ); |
|---|
| | 48 | VLC_EXPORT( module_t **, module_list_get, (size_t *n) ); |
|---|
| | 49 | |
|---|
| 47 | 50 | /* Return a NULL terminated array with the names of the modules that have a |
|---|
| 48 | 51 | * certain capability. |
|---|
| r924a067 |
r460a78b |
|
| 58 | 58 | int i_cmd, i_index, i_opts, i_shortopts, flag, i_verbose = 0; |
|---|
| 59 | 59 | module_t *p_parser; |
|---|
| 60 | | vlc_list_t *p_list; |
|---|
| 61 | 60 | struct option *p_longopts; |
|---|
| 62 | 61 | int i_modules_index; |
|---|
| … | … | |
| 86 | 85 | |
|---|
| 87 | 86 | /* List all modules */ |
|---|
| 88 | | p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); |
|---|
| | 87 | module_t **list = module_list_get (NULL); |
|---|
| 89 | 88 | |
|---|
| 90 | 89 | /* |
|---|
| … | … | |
| 93 | 92 | |
|---|
| 94 | 93 | 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++) |
|---|
| 100 | 95 | /* count the number of exported configuration options (to allocate |
|---|
| 101 | 96 | * longopts). We also need to allocate space for two options when |
|---|
| 102 | 97 | * 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; |
|---|
| 106 | 99 | |
|---|
| 107 | 100 | p_longopts = malloc( sizeof(struct option) * (i_opts + 1) ); |
|---|
| 108 | 101 | if( p_longopts == NULL ) |
|---|
| 109 | 102 | { |
|---|
| 110 | | vlc_list_release( p_list ); |
|---|
| | 103 | module_list_free (list); |
|---|
| 111 | 104 | return -1; |
|---|
| 112 | 105 | } |
|---|
| … | … | |
| 116 | 109 | { |
|---|
| 117 | 110 | free( p_longopts ); |
|---|
| 118 | | vlc_list_release( p_list ); |
|---|
| | 111 | module_list_free (list); |
|---|
| 119 | 112 | return -1; |
|---|
| 120 | 113 | } |
|---|
| … | … | |
| 130 | 123 | free( psz_shortopts ); |
|---|
| 131 | 124 | free( p_longopts ); |
|---|
| 132 | | vlc_list_release( p_list ); |
|---|
| | 125 | module_list_free (list); |
|---|
| 133 | 126 | return -1; |
|---|
| 134 | 127 | } |
|---|
| … | … | |
| 145 | 138 | /* Fill the p_longopts and psz_shortopts structures */ |
|---|
| 146 | 139 | 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++) |
|---|
| 149 | 141 | { |
|---|
| 150 | 142 | module_config_t *p_item, *p_end; |
|---|
| 151 | | p_parser = (module_t *)p_list->p_values[i_modules_index].p_object ; |
|---|
| 152 | 143 | |
|---|
| 153 | 144 | if( !p_parser->i_config_items ) |
|---|
| … | … | |
| 227 | 218 | |
|---|
| 228 | 219 | /* We don't need the module list anymore */ |
|---|
| 229 | | vlc_list_release( p_list ); |
|---|
| | 220 | module_list_free( list ); |
|---|
| 230 | 221 | |
|---|
| 231 | 222 | /* Close the longopts and shortopts structures */ |
|---|
| rd666030 |
r460a78b |
|
| 410 | 410 | module_config_t *config_FindConfig( vlc_object_t *p_this, const char *psz_name ) |
|---|
| 411 | 411 | { |
|---|
| 412 | | vlc_list_t *p_list; |
|---|
| 413 | | int i_index; |
|---|
| | 412 | module_t *p_parser; |
|---|
| 414 | 413 | |
|---|
| 415 | 414 | if( !psz_name ) return NULL; |
|---|
| 416 | 415 | |
|---|
| 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++) |
|---|
| 420 | 421 | { |
|---|
| 421 | 422 | module_config_t *p_item, *p_end; |
|---|
| 422 | | module_t *p_parser = (module_t *)p_list->p_values[i_index].p_object; |
|---|
| 423 | 423 | |
|---|
| 424 | 424 | if( !p_parser->i_config_items ) |
|---|
| … | … | |
| 436 | 436 | && !strcmp( psz_name, p_item->psz_oldname ) ) ) |
|---|
| 437 | 437 | { |
|---|
| 438 | | vlc_list_release( p_list ); |
|---|
| | 438 | module_list_free (list); |
|---|
| 439 | 439 | return p_item; |
|---|
| 440 | 440 | } |
|---|
| … | … | |
| 442 | 442 | } |
|---|
| 443 | 443 | |
|---|
| 444 | | vlc_list_release( p_list ); |
|---|
| 445 | | |
|---|
| | 444 | module_list_free (list); |
|---|
| 446 | 445 | return NULL; |
|---|
| 447 | 446 | } |
|---|
| … | … | |
| 537 | 536 | libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); |
|---|
| 538 | 537 | int i_index; |
|---|
| 539 | | vlc_list_t *p_list; |
|---|
| 540 | 538 | module_t *p_module; |
|---|
| | 539 | module_t **list = module_list_get (NULL); |
|---|
| 541 | 540 | |
|---|
| 542 | 541 | /* Acquire config file lock */ |
|---|
| 543 | 542 | vlc_mutex_lock( &priv->config_lock ); |
|---|
| 544 | 543 | |
|---|
| 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 | { |
|---|
| 550 | 547 | if( p_module->b_submodule ) continue; |
|---|
| 551 | 548 | |
|---|
| … | … | |
| 567 | 564 | } |
|---|
| 568 | 565 | |
|---|
| 569 | | vlc_list_release( p_list ); |
|---|
| | 566 | module_list_free (list); |
|---|
| 570 | 567 | vlc_mutex_unlock( &priv->config_lock ); |
|---|
| 571 | 568 | } |
|---|
| r2320905 |
r460a78b |
|
| 159 | 159 | { |
|---|
| 160 | 160 | libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); |
|---|
| 161 | | vlc_list_t *p_list; |
|---|
| 162 | 161 | FILE *file; |
|---|
| 163 | 162 | |
|---|
| … | … | |
| 170 | 169 | |
|---|
| 171 | 170 | /* 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); |
|---|
| 173 | 172 | |
|---|
| 174 | 173 | /* Look for UTF-8 Byte Order Mark */ |
|---|
| … | … | |
| 216 | 215 | || (strcmp (psz_module_name, section) == 0)) |
|---|
| 217 | 216 | { |
|---|
| 218 | | for (int i = 0; i < p_list->i_count; i++) |
|---|
| | 217 | for (int i = 0; list[i]; i++) |
|---|
| 219 | 218 | { |
|---|
| 220 | | module_t *m = (module_t *)p_list->p_values[i].p_object; |
|---|
| | 219 | module_t *m = list[i]; |
|---|
| 221 | 220 | |
|---|
| 222 | 221 | if ((strcmp (section, m->psz_object_name) == 0) |
|---|
| … | … | |
| 318 | 317 | fclose (file); |
|---|
| 319 | 318 | |
|---|
| 320 | | vlc_list_release( p_list ); |
|---|
| | 319 | module_list_free (list); |
|---|
| 321 | 320 | if (loc != (locale_t)0) |
|---|
| 322 | 321 | { |
|---|
| … | … | |
| 417 | 416 | libvlc_priv_t *priv = libvlc_priv (p_this->p_libvlc); |
|---|
| 418 | 417 | module_t *p_parser; |
|---|
| 419 | | vlc_list_t *p_list; |
|---|
| 420 | 418 | FILE *file; |
|---|
| 421 | 419 | char p_line[1024], *p_index2; |
|---|
| … | … | |
| 461 | 459 | |
|---|
| 462 | 460 | /* 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); |
|---|
| 464 | 462 | |
|---|
| 465 | 463 | /* backup file into memory, we only need to backup the sections we won't |
|---|
| … | … | |
| 472 | 470 | |
|---|
| 473 | 471 | /* 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 | { |
|---|
| 478 | 474 | if( ((p_index2 - &p_line[1]) |
|---|
| 479 | 475 | == (int)strlen(p_parser->psz_object_name) ) |
|---|
| … | … | |
| 489 | 485 | } |
|---|
| 490 | 486 | |
|---|
| 491 | | if( i_index == p_list->i_count ) |
|---|
| | 487 | if( list[i_index] == NULL ) |
|---|
| 492 | 488 | { |
|---|
| 493 | 489 | /* we don't have this section in our list so we need to back |
|---|
| … | … | |
| 527 | 523 | if( !file ) |
|---|
| 528 | 524 | { |
|---|
| 529 | | vlc_list_release( p_list ); |
|---|
| | 525 | module_list_free (list); |
|---|
| 530 | 526 | free( p_bigbuffer ); |
|---|
| 531 | 527 | vlc_mutex_unlock( &priv->config_lock ); |
|---|
| … | … | |
| 541 | 537 | |
|---|
| 542 | 538 | /* 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++ ) |
|---|
| 544 | 540 | { |
|---|
| 545 | 541 | module_config_t *p_item, *p_end; |
|---|
| 546 | | p_parser = (module_t *)p_list->p_values[i_index].p_object ; |
|---|
| 547 | 542 | |
|---|
| 548 | 543 | if( psz_module_name && strcmp( psz_module_name, |
|---|
| … | … | |
| 645 | 640 | } |
|---|
| 646 | 641 | |
|---|
| 647 | | vlc_list_release( p_list ); |
|---|
| | 642 | module_list_free (list); |
|---|
| 648 | 643 | if (loc != (locale_t)0) |
|---|
| 649 | 644 | { |
|---|
| … | … | |
| 667 | 662 | { |
|---|
| 668 | 663 | 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; |
|---|
| 671 | 666 | |
|---|
| 672 | 667 | assert( p_this ); |
|---|
| … | … | |
| 674 | 669 | /* Check if there's anything to save */ |
|---|
| 675 | 670 | 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]; |
|---|
| 681 | 675 | module_config_t *p_item, *p_end; |
|---|
| 682 | 676 | |
|---|
| … | … | |
| 691 | 685 | if( p_item < p_end ) break; |
|---|
| 692 | 686 | } |
|---|
| 693 | | vlc_list_release( p_list ); |
|---|
| | 687 | done = list[i_index] == NULL; |
|---|
| | 688 | module_list_free (list); |
|---|
| 694 | 689 | vlc_mutex_unlock( &priv->config_lock ); |
|---|
| 695 | 690 | |
|---|
| 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 ); |
|---|
| 698 | 692 | } |
|---|
| 699 | 693 | |
|---|
| rcc2d7b4 |
r460a78b |
|
| 1425 | 1425 | # define OPTION_VALUE_SEP " " |
|---|
| 1426 | 1426 | #endif |
|---|
| 1427 | | vlc_list_t *p_list = NULL; |
|---|
| 1428 | 1427 | char psz_spaces_text[PADDING_SPACES+LINE_START+1]; |
|---|
| 1429 | 1428 | char psz_spaces_longtext[LINE_START+3]; |
|---|
| … | … | |
| 1432 | 1431 | char psz_buffer[10000]; |
|---|
| 1433 | 1432 | char psz_short[4]; |
|---|
| 1434 | | int i_index; |
|---|
| 1435 | 1433 | int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1); |
|---|
| 1436 | 1434 | int i_width_description = i_width + PADDING_SPACES - 1; |
|---|
| … | … | |
| 1467 | 1465 | |
|---|
| 1468 | 1466 | /* 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; |
|---|
| 1470 | 1470 | |
|---|
| 1471 | 1471 | /* Ugly hack to make sure that the help options always come first |
|---|
| … | … | |
| 1475 | 1475 | |
|---|
| 1476 | 1476 | /* 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++) |
|---|
| 1478 | 1478 | { |
|---|
| 1479 | 1479 | 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]; |
|---|
| 1481 | 1481 | module_config_t *p_item = NULL; |
|---|
| 1482 | 1482 | module_config_t *p_section = NULL; |
|---|
| … | … | |
| 1871 | 1871 | |
|---|
| 1872 | 1872 | /* Release the module list */ |
|---|
| 1873 | | vlc_list_release( p_list ); |
|---|
| | 1873 | module_list_free (list); |
|---|
| 1874 | 1874 | } |
|---|
| 1875 | 1875 | |
|---|
| … | … | |
| 1882 | 1882 | static void ListModules( libvlc_int_t *p_this, bool b_verbose ) |
|---|
| 1883 | 1883 | { |
|---|
| 1884 | | vlc_list_t *p_list = NULL; |
|---|
| 1885 | | module_t *p_parser = NULL; |
|---|
| | 1884 | module_t *p_parser; |
|---|
| 1886 | 1885 | char psz_spaces[22]; |
|---|
| 1887 | | int i_index; |
|---|
| 1888 | 1886 | |
|---|
| 1889 | 1887 | bool b_color = config_GetInt( p_this, "color" ) > 0; |
|---|
| … | … | |
| 1896 | 1894 | |
|---|
| 1897 | 1895 | /* List all modules */ |
|---|
| 1898 | | p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); |
|---|
| | 1896 | module_t **list = module_list_get (NULL); |
|---|
| 1899 | 1897 | |
|---|
| 1900 | 1898 | /* 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++) |
|---|
| 1902 | 1900 | { |
|---|
| 1903 | 1901 | int i; |
|---|
| 1904 | | |
|---|
| 1905 | | p_parser = (module_t *)p_list->p_values[i_index].p_object ; |
|---|
| 1906 | 1902 | |
|---|
| 1907 | 1903 | /* Nasty hack, but right now I'm too tired to think about a nice |
|---|
| … | … | |
| 1952 | 1948 | psz_spaces[i] = ' '; |
|---|
| 1953 | 1949 | } |
|---|
| 1954 | | |
|---|
| 1955 | | vlc_list_release( p_list ); |
|---|
| | 1950 | module_list_free (list); |
|---|
| 1956 | 1951 | |
|---|
| 1957 | 1952 | #ifdef WIN32 /* Pause the console because it's destroyed when we exit */ |
|---|
| rf0c76d5 |
r460a78b |
|
| 213 | 213 | module_GetObjName |
|---|
| 214 | 214 | module_IsCapable |
|---|
| | 215 | module_list_free |
|---|
| | 216 | module_list_get |
|---|
| 215 | 217 | __module_Need |
|---|
| 216 | 218 | module_Put |
|---|