1 /*****************************************************************************
2 * modules.c : Builtin and plugin modules management functions
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: modules.c,v 1.115 2003/03/03 16:49:14 gbazin Exp $
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Ethan C. Baldridge <BaldridgeE@cadmus.com>
9 * Hans-Peter Jansen <hpj@urpla.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /* Some faulty libcs have a broken struct dirent when _FILE_OFFSET_BITS
27 * is set to 64. Don't try to be cleverer. */
28 #ifdef _FILE_OFFSET_BITS
29 #undef _FILE_OFFSET_BITS
32 #include <stdlib.h> /* free(), strtol() */
33 #include <stdio.h> /* sprintf() */
34 #include <string.h> /* strdup() */
40 #elif defined( UNDER_CE )
41 # include <windows.h> /* GetFileAttributes() */
43 # include "../extras/dirent.h"
46 #ifdef HAVE_SYS_TYPES_H
47 # include <sys/types.h>
49 #ifdef HAVE_SYS_STAT_H
50 # include <sys/stat.h>
56 #if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
57 # include <dlfcn.h> /* dlopen(), dlsym(), dlclose() */
58 # define HAVE_DYNAMIC_PLUGINS
59 #elif defined(HAVE_IMAGE_H) /* BeOS */
61 # define HAVE_DYNAMIC_PLUGINS
62 #elif defined(UNDER_CE)
63 # define HAVE_DYNAMIC_PLUGINS
65 # define HAVE_DYNAMIC_PLUGINS
67 # undef HAVE_DYNAMIC_PLUGINS
73 #include "interface.h"
74 #include "vlc_playlist.h"
75 #include "intf_eject.h"
77 #include "stream_control.h"
78 #include "input_ext-intf.h"
79 #include "input_ext-dec.h"
80 #include "input_ext-plugins.h"
83 #include "video_output.h"
85 #include "audio_output.h"
86 #include "aout_internal.h"
88 #include "stream_output.h"
92 #if defined( UNDER_CE )
93 # define MYCHAR wchar_t
98 #ifdef HAVE_DYNAMIC_PLUGINS
99 # include "modules_plugin.h"
102 #if defined( UNDER_CE )
103 # include "modules_builtin_evc.h"
104 #elif defined( _MSC_VER )
105 # include "modules_builtin_msvc.h"
107 # include "modules_builtin.h"
110 /*****************************************************************************
112 *****************************************************************************/
113 #ifdef HAVE_DYNAMIC_PLUGINS
114 static void AllocateAllPlugins ( vlc_object_t * );
115 static void AllocatePluginDir ( vlc_object_t *, const MYCHAR *, int );
116 static int AllocatePluginFile ( vlc_object_t *, MYCHAR * );
118 static int AllocateBuiltinModule( vlc_object_t *, int ( * ) ( module_t * ) );
119 static int DeleteModule ( module_t * );
120 #ifdef HAVE_DYNAMIC_PLUGINS
121 static void DupModule ( module_t * );
122 static void UndupModule ( module_t * );
123 static int CallEntry ( module_t * );
126 /*****************************************************************************
127 * module_InitBank: create the module bank.
128 *****************************************************************************
129 * This function creates a module bank structure which will be filled later
130 * on with all the modules found.
131 *****************************************************************************/
132 void __module_InitBank( vlc_object_t *p_this )
134 module_bank_t *p_bank;
136 p_bank = vlc_object_create( p_this, sizeof(module_bank_t) );
137 p_bank->psz_object_name = "module bank";
140 * Store the symbols to be exported
142 #ifdef HAVE_DYNAMIC_PLUGINS
143 STORE_SYMBOLS( &p_bank->symbols );
146 /* Everything worked, attach the object */
147 p_this->p_libvlc->p_module_bank = p_bank;
148 vlc_object_attach( p_bank, p_this->p_libvlc );
153 /*****************************************************************************
154 * module_ResetBank: reset the module bank.
155 *****************************************************************************
156 * This function resets the module bank by unloading all unused plugin
158 *****************************************************************************/
159 void __module_ResetBank( vlc_object_t *p_this )
161 msg_Err( p_this, "FIXME: module_ResetBank unimplemented" );
165 /*****************************************************************************
166 * module_EndBank: empty the module bank.
167 *****************************************************************************
168 * This function unloads all unused plugin modules and empties the module
169 * bank in case of success.
170 *****************************************************************************/
171 void __module_EndBank( vlc_object_t *p_this )
175 vlc_object_detach( p_this->p_libvlc->p_module_bank );
177 while( p_this->p_libvlc->p_module_bank->i_children )
179 p_next = (module_t *)p_this->p_libvlc->p_module_bank->pp_children[0];
181 if( DeleteModule( p_next ) )
183 /* Module deletion failed */
184 msg_Err( p_this, "module \"%s\" can't be removed, trying harder",
185 p_next->psz_object_name );
187 /* We just free the module by hand. Niahahahahaha. */
188 vlc_object_detach( p_next );
189 vlc_object_destroy( p_next );
193 vlc_object_destroy( p_this->p_libvlc->p_module_bank );
198 /*****************************************************************************
199 * module_LoadMain: load the main program info into the module bank.
200 *****************************************************************************
201 * This function fills the module bank structure with the main module infos.
202 * This is very useful as it will allow us to consider the main program just
203 * as another module, and for instance the configuration options of main will
204 * be available in the module bank structure just as for every other module.
205 *****************************************************************************/
206 void __module_LoadMain( vlc_object_t *p_this )
208 AllocateBuiltinModule( p_this, vlc_entry__main );
211 /*****************************************************************************
212 * module_LoadBuiltins: load all modules which we built with.
213 *****************************************************************************
214 * This function fills the module bank structure with the builtin modules.
215 *****************************************************************************/
216 void __module_LoadBuiltins( vlc_object_t * p_this )
218 msg_Dbg( p_this, "checking builtin modules" );
219 ALLOCATE_ALL_BUILTINS();
222 /*****************************************************************************
223 * module_LoadPlugins: load all plugin modules we can find.
224 *****************************************************************************
225 * This function fills the module bank structure with the plugin modules.
226 *****************************************************************************/
227 void __module_LoadPlugins( vlc_object_t * p_this )
229 #ifdef HAVE_DYNAMIC_PLUGINS
230 msg_Dbg( p_this, "checking plugin modules" );
231 AllocateAllPlugins( p_this );
235 /*****************************************************************************
236 * module_Need: return the best module function, given a capability list.
237 *****************************************************************************
238 * This function returns the module that best fits the asked capabilities.
239 *****************************************************************************/
240 module_t * __module_Need( vlc_object_t *p_this, const char *psz_capability,
241 const char *psz_name )
243 typedef struct module_list_t module_list_t;
249 module_list_t *p_next;
252 module_list_t *p_list, *p_first, *p_tmp;
255 int i_which_module, i_index = 0;
256 vlc_bool_t b_intf = VLC_FALSE;
261 char *psz_shortcuts = NULL, *psz_var = NULL;
263 msg_Dbg( p_this, "looking for %s module", psz_capability );
265 /* Deal with variables */
266 if( psz_name && psz_name[0] == '$' )
268 psz_var = config_GetPsz( p_this, psz_name + 1 );
272 /* Count how many different shortcuts were asked for */
273 if( psz_name && *psz_name )
277 /* If the user wants none, give him none. */
278 if( !strcmp( psz_name, "none" ) )
280 if( psz_var ) free( psz_var );
285 psz_shortcuts = strdup( psz_name );
287 for( psz_parser = psz_shortcuts; *psz_parser; psz_parser++ )
289 if( *psz_parser == ',' )
297 /* Sort the modules and test them */
298 p_all = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
299 p_list = malloc( p_all->i_count * sizeof( module_list_t ) );
302 /* Parse the module list for capabilities and probe each of them */
303 for( i_which_module = 0; i_which_module < p_all->i_count; i_which_module++ )
305 module_t * p_submodule = NULL;
306 int i_shortcut_bonus = 0, i_submodule;
308 p_module = (module_t *)p_all->p_values[i_which_module].p_object;
310 /* Test that this module can do what we need */
311 if( strcmp( p_module->psz_capability, psz_capability ) )
313 for( i_submodule = 0;
314 i_submodule < p_module->i_children;
317 if( !strcmp( ((module_t*)p_module->pp_children[ i_submodule ])
318 ->psz_capability, psz_capability ) )
321 (module_t*)p_module->pp_children[ i_submodule ];
326 if( p_submodule == NULL )
331 p_module = p_submodule;
334 /* Test if we have the required CPU */
335 if( (p_module->i_cpu & p_this->p_libvlc->i_cpu) != p_module->i_cpu )
340 /* If we required a shortcut, check this plugin provides it. */
343 vlc_bool_t b_trash = VLC_TRUE;
344 int i_dummy, i_short = i_shortcuts;
345 char *psz_name = psz_shortcuts;
350 b_trash && p_module->pp_shortcuts[i_dummy];
353 b_trash = ( strcmp(psz_name, "any") || !p_module->i_score )
354 && strcmp( psz_name, p_module->pp_shortcuts[i_dummy] );
359 i_shortcut_bonus = i_short * 10000;
363 /* Go to the next shortcut... This is so lame! */
377 /* If we didn't require a shortcut, trash zero-scored plugins */
378 else if( !p_module->i_score )
383 /* Special case: test if we requested a particular intf plugin */
384 if( p_module->psz_program
385 && !strcmp( p_module->psz_program,
386 p_this->p_vlc->psz_object_name ) )
390 /* Remove previous non-matching plugins */
397 /* This one doesn't match */
401 /* Store this new module */
402 p_list[ i_index ].p_module = p_module;
403 p_list[ i_index ].i_score = p_module->i_score + i_shortcut_bonus;
405 /* Add it to the modules-to-probe list */
408 p_list[ 0 ].p_next = NULL;
413 /* Ok, so at school you learned that quicksort is quick, and
414 * bubble sort sucks raw eggs. But that's when dealing with
415 * thousands of items. Here we have barely 50. */
416 module_list_t *p_newlist = p_first;
418 if( p_first->i_score < p_list[ i_index ].i_score )
420 p_list[ i_index ].p_next = p_first;
421 p_first = &p_list[ i_index ];
425 while( p_newlist->p_next != NULL &&
426 p_newlist->p_next->i_score >= p_list[ i_index ].i_score )
428 p_newlist = p_newlist->p_next;
431 p_list[ i_index ].p_next = p_newlist->p_next;
432 p_newlist->p_next = &p_list[ i_index ];
439 msg_Dbg( p_this, "probing %i candidate%s",
440 i_index, i_index == 1 ? "" : "s" );
442 /* Lock all candidate modules */
444 while( p_tmp != NULL )
446 vlc_object_yield( p_tmp->p_module );
447 p_tmp = p_tmp->p_next;
450 /* We can release the list, interesting modules were yielded */
451 vlc_list_release( p_all );
453 /* Parse the linked list and use the first successful module */
455 while( p_tmp != NULL )
457 if( p_tmp->p_module->pf_activate
458 && p_tmp->p_module->pf_activate( p_this ) == VLC_SUCCESS )
463 vlc_object_release( p_tmp->p_module );
464 p_tmp = p_tmp->p_next;
467 /* Store the locked module value */
470 p_module = p_tmp->p_module;
471 p_tmp = p_tmp->p_next;
478 /* Unlock the remaining modules */
479 while( p_tmp != NULL )
481 vlc_object_release( p_tmp->p_module );
482 p_tmp = p_tmp->p_next;
487 if( p_module != NULL )
489 msg_Dbg( p_module, "using %s module \"%s\"",
490 psz_capability, p_module->psz_object_name );
492 else if( p_first == NULL )
494 msg_Err( p_this, "no %s module matched \"%s\"",
495 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
497 else if( psz_name != NULL && *psz_name )
499 msg_Warn( p_this, "no %s module matching \"%s\" could be loaded",
500 psz_capability, (psz_name && *psz_name) ? psz_name : "any" );
505 free( psz_shortcuts );
513 /* Don't forget that the module is still locked */
517 /*****************************************************************************
518 * module_Unneed: decrease the usage count of a module.
519 *****************************************************************************
520 * This function must be called by the thread that called module_Need, to
521 * decrease the reference count and allow for hiding of modules.
522 *****************************************************************************/
523 void __module_Unneed( vlc_object_t * p_this, module_t * p_module )
525 /* Use the close method */
526 if( p_module->pf_deactivate )
528 p_module->pf_deactivate( p_this );
531 msg_Dbg( p_module, "unlocking module \"%s\"", p_module->psz_object_name );
533 vlc_object_release( p_module );
538 /*****************************************************************************
539 * Following functions are local.
540 *****************************************************************************/
542 /*****************************************************************************
543 * AllocateAllPlugins: load all plugin modules we can find.
544 *****************************************************************************/
545 #ifdef HAVE_DYNAMIC_PLUGINS
546 static void AllocateAllPlugins( vlc_object_t *p_this )
548 /* Yes, there are two NULLs because we replace one with "plugin-path". */
549 char * path[] = { "modules", PLUGIN_PATH, "plugins", NULL,
552 char ** ppsz_path = path;
554 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
555 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
556 int i_vlclen = strlen( p_this->p_libvlc->psz_vlcpath );
557 vlc_bool_t b_notinroot;
560 #if defined( UNDER_CE )
561 wchar_t psz_dir[MAX_PATH];
564 /* If the user provided a plugin path, we add it to the list */
565 path[ sizeof(path)/sizeof(char*) - 2 ] = config_GetPsz( p_this,
568 #if defined( WIN32 ) && !defined( UNDER_CE ) && !defined( _MSC_VER )
569 /* If there is no 'plugins' nor 'modules' subdirectory, the user may have
570 * screwed up the unzipping stage, so we look into '.' instead */
571 if( !opendir( "plugins" ) && !opendir( "modules" )
572 && !strcmp( *ppsz_path, "modules" ) )
578 for( ; *ppsz_path != NULL ; ppsz_path++ )
580 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) \
581 || ( defined( WIN32 ) && !defined( UNDER_CE ) )
582 /* Store strlen(*ppsz_path) for later use. */
583 int i_dirlen = strlen( *ppsz_path );
585 b_notinroot = VLC_FALSE;
586 /* Under BeOS, we need to add beos_GetProgramPath() to access
587 * files under the current directory */
589 if( i_dirlen < 3 || ppsz_path[3] != '\\' )
591 if( ppsz_path[0] != '/' )
594 i_dirlen += i_vlclen + 2;
595 b_notinroot = VLC_TRUE;
597 psz_fullpath = malloc( i_dirlen );
598 if( psz_fullpath == NULL )
603 sprintf( psz_fullpath, "%s\\%s",
604 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
606 sprintf( psz_fullpath, "%s/%s",
607 p_this->p_libvlc->psz_vlcpath, *ppsz_path );
613 psz_fullpath = *ppsz_path;
616 msg_Dbg( p_this, "recursively browsing `%s'", psz_fullpath );
618 /* Don't go deeper than 5 subdirectories */
619 #if defined( UNDER_CE )
620 MultiByteToWideChar( CP_ACP, 0, psz_fullpath, -1, psz_dir, MAX_PATH );
621 AllocatePluginDir( p_this, psz_dir, 5 );
623 AllocatePluginDir( p_this, psz_fullpath, 5 );
626 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
629 free( psz_fullpath );
634 /* Free plugin-path */
635 free( path[ sizeof(path)/sizeof(char*) - 2 ] );
636 path[ sizeof(path)/sizeof(char*) - 2 ] = NULL;
639 /*****************************************************************************
640 * AllocatePluginDir: recursively parse a directory to look for plugins
641 *****************************************************************************/
642 static void AllocatePluginDir( vlc_object_t *p_this, const MYCHAR *psz_dir,
645 #if defined( UNDER_CE ) || defined( _MSC_VER )
647 MYCHAR psz_path[MAX_PATH + 256];
649 char psz_path[MAX_PATH + 256];
651 WIN32_FIND_DATA finddata;
658 struct dirent * file;
666 #if defined( UNDER_CE ) || defined( _MSC_VER )
667 rc = GetFileAttributes( psz_dir );
668 if( !(rc & FILE_ATTRIBUTE_DIRECTORY) )
670 /* Not a directory */
674 /* Parse all files in the directory */
676 swprintf( psz_path, L"%s\\*.*", psz_dir );
678 sprintf( psz_path, "%s\\*.*", psz_dir );
680 handle = FindFirstFile( psz_path, &finddata );
681 if( handle == INVALID_HANDLE_VALUE )
683 /* Empty directory */
687 /* Parse the directory and try to load all files it contains. */
691 unsigned int i_len = wcslen( finddata.cFileName );
692 swprintf( psz_path, L"%s\\%s", psz_dir, finddata.cFileName );
694 unsigned int i_len = strlen( finddata.cFileName );
695 /* Skip ".", ".." and anything starting with "." */
696 if( !*finddata.cFileName || *finddata.cFileName == '.' )
698 if( !FindNextFile( handle, &finddata ) ) break;
701 sprintf( psz_path, "%s\\%s", psz_dir, finddata.cFileName );
704 if( GetFileAttributes( psz_path ) & FILE_ATTRIBUTE_DIRECTORY )
706 AllocatePluginDir( p_this, psz_path, i_maxdepth - 1 );
708 else if( i_len > strlen( LIBEXT )
712 /* We only load files ending with LIBEXT */
713 && !strncasecmp( psz_path + strlen( psz_path)
715 LIBEXT, strlen( LIBEXT ) ) )
718 AllocatePluginFile( p_this, psz_path );
721 while( FindNextFile( handle, &finddata ) );
723 /* Close the directory */
727 dir = opendir( psz_dir );
733 i_dirlen = strlen( psz_dir );
735 /* Parse the directory and try to load all files it contains. */
736 while( (file = readdir( dir )) )
741 /* Skip ".", ".." and anything starting with "." */
742 if( !*file->d_name || *file->d_name == '.' )
747 i_len = strlen( file->d_name );
748 psz_file = malloc( i_dirlen + 1 + i_len + 1 );
750 sprintf( psz_file, "%s\\%s", psz_dir, file->d_name );
752 sprintf( psz_file, "%s/%s", psz_dir, file->d_name );
755 if( !stat( psz_file, &statbuf ) && statbuf.st_mode & S_IFDIR )
757 AllocatePluginDir( p_this, psz_file, i_maxdepth - 1 );
759 else if( i_len > strlen( LIBEXT )
760 /* We only load files ending with LIBEXT */
761 && !strncasecmp( file->d_name + i_len - strlen( LIBEXT ),
762 LIBEXT, strlen( LIBEXT ) ) )
764 AllocatePluginFile( p_this, psz_file );
770 /* Close the directory */
776 /*****************************************************************************
777 * AllocatePluginFile: load a module into memory and initialize it.
778 *****************************************************************************
779 * This function loads a dynamically loadable module and allocates a structure
780 * for its information data. The module can then be handled by module_Need
781 * and module_Unneed. It can be removed by DeleteModule.
782 *****************************************************************************/
783 static int AllocatePluginFile( vlc_object_t * p_this, MYCHAR * psz_file )
786 module_handle_t handle;
789 char psz_filename[MAX_PATH];
790 WideCharToMultiByte( CP_ACP, WC_DEFAULTCHAR, psz_file, -1,
791 psz_filename, MAX_PATH, NULL, NULL );
793 char * psz_filename = psz_file;
796 /* Try to dynamically load the module. */
797 if( module_load( psz_file, &handle ) )
799 char psz_buffer[256];
801 /* The plugin module couldn't be opened */
802 msg_Warn( p_this, "cannot open `%s' (%s)",
803 psz_filename, module_error( psz_buffer ) );
807 /* Now that we have successfully loaded the module, we can
808 * allocate a structure for it */
809 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
810 if( p_module == NULL )
812 msg_Err( p_this, "out of memory" );
813 module_unload( handle );
817 /* We need to fill these since they may be needed by CallEntry() */
818 p_module->psz_filename = psz_filename;
819 p_module->handle = handle;
820 p_module->p_symbols = &p_this->p_libvlc->p_module_bank->symbols;
822 /* Initialize the module: fill p_module->psz_object_name, default config */
823 if( CallEntry( p_module ) != 0 )
825 /* We couldn't call module_init() */
826 vlc_object_destroy( p_module );
827 module_unload( handle );
831 DupModule( p_module );
832 p_module->psz_filename = strdup( p_module->psz_filename );
833 p_module->psz_longname = strdup( p_module->psz_longname );
835 /* Everything worked fine ! The module is ready to be added to the list. */
836 p_module->b_builtin = VLC_FALSE;
838 /* msg_Dbg( p_this, "plugin \"%s\", %s",
839 p_module->psz_object_name, p_module->psz_longname ); */
841 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
846 /*****************************************************************************
847 * DupModule: make a plugin module standalone.
848 *****************************************************************************
849 * This function duplicates all strings in the module, so that the dynamic
850 * object can be unloaded. It acts recursively on submodules.
851 *****************************************************************************/
852 static void DupModule( module_t *p_module )
857 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
859 *pp_shortcut = strdup( *pp_shortcut );
862 /* We strdup() these entries so that they are still valid when the
863 * module is unloaded. */
864 p_module->psz_object_name = strdup( p_module->psz_object_name );
865 p_module->psz_capability = strdup( p_module->psz_capability );
867 if( p_module->psz_program != NULL )
869 p_module->psz_program = strdup( p_module->psz_program );
872 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
874 DupModule( (module_t*)p_module->pp_children[ i_submodule ] );
878 /*****************************************************************************
879 * UndupModule: free a duplicated module.
880 *****************************************************************************
881 * This function frees the allocations done in DupModule().
882 *****************************************************************************/
883 static void UndupModule( module_t *p_module )
888 for( i_submodule = 0; i_submodule < p_module->i_children; i_submodule++ )
890 UndupModule( (module_t*)p_module->pp_children[ i_submodule ] );
893 for( pp_shortcut = p_module->pp_shortcuts ; *pp_shortcut ; pp_shortcut++ )
895 free( *pp_shortcut );
898 free( p_module->psz_object_name );
899 free( p_module->psz_capability );
901 if( p_module->psz_program != NULL )
903 free( p_module->psz_program );
907 #endif /* HAVE_DYNAMIC_PLUGINS */
909 /*****************************************************************************
910 * AllocateBuiltinModule: initialize a builtin module.
911 *****************************************************************************
912 * This function registers a builtin module and allocates a structure
913 * for its information data. The module can then be handled by module_Need
914 * and module_Unneed. It can be removed by DeleteModule.
915 *****************************************************************************/
916 static int AllocateBuiltinModule( vlc_object_t * p_this,
917 int ( *pf_entry ) ( module_t * ) )
921 /* Now that we have successfully loaded the module, we can
922 * allocate a structure for it */
923 p_module = vlc_object_create( p_this, VLC_OBJECT_MODULE );
924 if( p_module == NULL )
926 msg_Err( p_this, "out of memory" );
930 /* Initialize the module : fill p_module->psz_object_name, etc. */
931 if( pf_entry( p_module ) != 0 )
933 /* With a well-written module we shouldn't have to print an
934 * additional error message here, but just make sure. */
935 msg_Err( p_this, "failed calling entry point in builtin module" );
936 vlc_object_destroy( p_module );
940 /* Everything worked fine ! The module is ready to be added to the list. */
941 p_module->b_builtin = VLC_TRUE;
943 /* msg_Dbg( p_this, "builtin \"%s\", %s",
944 p_module->psz_object_name, p_module->psz_longname ); */
946 vlc_object_attach( p_module, p_this->p_libvlc->p_module_bank );
951 /*****************************************************************************
952 * DeleteModule: delete a module and its structure.
953 *****************************************************************************
954 * This function can only be called if the module isn't being used.
955 *****************************************************************************/
956 static int DeleteModule( module_t * p_module )
958 vlc_object_detach( p_module );
960 /* We free the structures that we strdup()ed in Allocate*Module(). */
961 #ifdef HAVE_DYNAMIC_PLUGINS
962 if( !p_module->b_builtin )
964 if( p_module->b_unloadable )
966 module_unload( p_module->handle );
968 UndupModule( p_module );
969 free( p_module->psz_filename );
970 free( p_module->psz_longname );
974 /* Free and detach the object's children */
975 while( p_module->i_children )
977 vlc_object_t *p_this = p_module->pp_children[0];
978 vlc_object_detach( p_this );
979 vlc_object_destroy( p_this );
982 config_Free( p_module );
983 vlc_object_destroy( p_module );
988 #ifdef HAVE_DYNAMIC_PLUGINS
989 /*****************************************************************************
990 * CallEntry: call an entry point.
991 *****************************************************************************
992 * This function calls a symbol given its name and a module structure. The
993 * symbol MUST refer to a function returning int and taking a module_t* as
995 *****************************************************************************/
996 static int CallEntry( module_t * p_module )
998 static char *psz_name = "vlc_entry" MODULE_SUFFIX;
999 int (* pf_symbol) ( module_t * p_module );
1001 /* Try to resolve the symbol */
1002 pf_symbol = (int (*)(module_t *)) module_getsymbol( p_module->handle,
1005 if( pf_symbol == NULL )
1007 char psz_buffer[256];
1009 /* We couldn't load the symbol */
1010 msg_Warn( p_module, "cannot find symbol \"%s\" in file `%s' (%s)",
1011 psz_name, p_module->psz_filename,
1012 module_error( psz_buffer ) );
1016 /* We can now try to call the symbol */
1017 if( pf_symbol( p_module ) != 0 )
1019 /* With a well-written module we shouldn't have to print an
1020 * additional error message here, but just make sure. */
1021 msg_Err( p_module, "failed calling symbol \"%s\" in file `%s'",
1022 psz_name, p_module->psz_filename );
1026 /* Everything worked fine, we can return */
1029 #endif /* HAVE_DYNAMIC_PLUGINS */