Task 0x34: fix plugin autoloading
Ethan C. Baldridge
BaldridgeE at cadmus.com
Thu Aug 24 15:42:24 CEST 2000
Here's a patch (unified diff) that should do the trick. It may need
some alteration, depending on your needs, but it should work. I don't
have access to a BeOS machine, so I had to guess at that portion of the
code, so check that out before applying.
Ethan Baldridge
-- Attached file included as plaintext by Listar --
-- File: plugins.c.patch
--- plugins.c.original Thu Aug 24 06:51:25 2000
+++ plugins.c Thu Aug 24 09:39:55 2000
@@ -27,9 +27,10 @@
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <errno.h> /* ENOMEM */
+#include <dirent.h> /* DIR, opendir(), readdir(), closedir() */
#if defined(HAVE_DLFCN_H) /* Linux, BSD, Hurd */
-#include <dlfcn.h> /* dlopen(), dlsym(), dlclose() */
+#include <dlfcn.h> /* dlopen(), dlsym(), dlclose(), dlerror() */
#elif defined(HAVE_IMAGE_H) /* BeOS */
#include <image.h>
@@ -77,41 +78,63 @@
}
void bank_Init( plugin_bank_t * p_bank )
+/* ECB: modified to search directories and load any plugins found there */
{
plugin_id_t tmp;
+ int i;
+ DIR * psz_directory;
+ struct dirent * psz_file;
char * psz_filename;
+ char * psz_plugin;
+ char * psz_plugin_path[ ] =
+ {
+ "/usr/share/vlc/plugins",
+ "$HOME/.vlc/plugins",
+ PLUGIN_PATH,
+ NULL
+ };
- /* FIXME: we should browse all directories to get plugins */
-#define SEEK_PLUGIN( name ) \
- psz_filename = TestPlugin( &tmp, name ); \
- if( psz_filename ) AllocatePlugin( tmp, p_bank, psz_filename );
-
- /* Arch plugins */
- SEEK_PLUGIN( "beos" );
-
- /* Low level Video */
- SEEK_PLUGIN( "x11" );
- SEEK_PLUGIN( "fb" );
- SEEK_PLUGIN( "glide" );
- SEEK_PLUGIN( "mga" );
-
- /* High level Video */
- SEEK_PLUGIN( "gnome" );
- SEEK_PLUGIN( "ggi" );
- SEEK_PLUGIN( "sdl" );
-
- /* Video calculus */
- SEEK_PLUGIN( "yuvmmx" );
- SEEK_PLUGIN( "yuv" );
-
- /* Audio pluins */
- SEEK_PLUGIN( "dsp" );
- SEEK_PLUGIN( "esd" );
-
- /* Dummy plugin */
- SEEK_PLUGIN( "dummy" );
-
-#undef SEEK_PLUGIN
+ for ( i = 0; psz_plugin_path[i]; i++ ) {
+ psz_directory = opendir(psz_plugin_path[i]);
+ if (psz_directory) {
+ psz_file = readdir(psz_directory);
+ psz_filename = psz_file->d_name;
+ if (memcmp(psz_filename, ".", 1) ) {
+ #ifdef SYS_BEOS
+ /* Unfortunately, I don't have access to a BeOS system.
+ I tried to guesstimate, but I have never developed for
+ BeOS, so it might not compile, link or work.
+ Please desk check it before using this patch on a
+ production BeOS system. Thanks, Ethan Baldridge
+ */
+ char * psz_program_path;
+
+ psz_program_path = beos_GetProgramPath();
+ psz_plugin = malloc( strlen(psz_plugin_path[i]) +
+ strlen(psz_program_path) +
+ strlen(psz_filename) + 5 );
+ sprintf( psz_plugin, "%s/%s/%s", psz_program_path,
+ psz_plugin_path[i], psz_filename );
+ tmp = load_add_on( psz_plugin );
+ if (tmp >= 0) {
+ AllocatePlugin( tmp, p_bank, psz_filename );
+ }
+ #else
+ psz_plugin = malloc( strlen(psz_plugin_path[i]) +
+ strlen(psz_filename) + 5 );
+ sprintf( psz_plugin, "%s%s", psz_plugin_path[i],
+ psz_filename );
+ tmp = dlopen( psz_plugin, RTLD_NOW | RTLD_GLOBAL );
+ if (tmp != NULL) {
+ AllocatePlugin( tmp, p_bank, psz_filename );
+ } else {
+ intf_DbgMsg( "%s\n", dlerror() );
+ }
+ #endif
+ }
+ }
+ closedir(psz_directory);
+ }
}
void bank_Destroy( plugin_bank_t * p_bank )
@@ -131,61 +154,6 @@
/*
* Following functions are local
*/
-
-char * TestPlugin ( plugin_id_t *p_plugin_id, char * psz_name )
-{
- int i_count, i_length;
- char * psz_plugin;
- char * psz_plugin_path[ ] =
- {
- ".",
- "lib", /* this one should disappear */
- PLUGIN_PATH,
- NULL
- };
-
- i_length = strlen( psz_name );
-
- for ( i_count = 0 ; psz_plugin_path[ i_count ] ; i_count++ )
- {
-#ifdef SYS_BEOS
- char * psz_program_path;
-
- psz_program_path = beos_GetProgramPath();
- psz_plugin = malloc( strlen(psz_plugin_path[i_count]) +
- strlen(psz_program_path) + i_length + 5 );
- sprintf( psz_plugin, "%s/%s/%s.so", psz_program_path,
- psz_plugin_path[i_count], psz_name );
-
- *p_plugin_id = load_add_on( psz_plugin );
-#else
- psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + i_length + 5 );
- sprintf( psz_plugin, "%s/%s.so", psz_plugin_path[i_count], psz_name );
-
- *p_plugin_id = dlopen( psz_plugin, RTLD_NOW | RTLD_GLOBAL );
-#endif
-
-#ifdef SYS_BEOS
- if( *p_plugin_id >= 0 )
-#else
- if( *p_plugin_id != NULL )
-#endif
- {
- /* plugin successfuly dlopened */
- return( psz_plugin );
- }
-#ifndef SYS_BEOS
- else
- {
- intf_DbgMsg( "%s\n", dlerror() );
- }
-#endif
-
- free( psz_plugin );
- }
-
- return( NULL );
-}
int AllocatePlugin( plugin_id_t plugin_id, plugin_bank_t * p_bank,
More information about the vlc
mailing list