]> git.sesse.net Git - vlc/blob - src/misc/plugins.c
Portage du client sous BeOS. Il manque encore l'audio mais �a marche.
[vlc] / src / misc / plugins.c
1 /*****************************************************************************
2  * plugins.c : Dynamic plugin management functions
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *****************************************************************************/
23 #include "defs.h"
24
25 #include <stdlib.h>                                      /* free(), strtol() */
26 #include <stdio.h>                                              /* sprintf() */
27
28 #if defined(HAVE_DLFCN_H)                                /* Linux, BSD, Hurd */
29 #include <dlfcn.h>                           /* dlopen(), dlsym(), dlclose() */
30
31 #elif defined(HAVE_IMAGE_H)                                          /* BeOS */
32 #include <image.h>
33
34 #else
35 #error no dynamic plugins available on your system !
36 #endif
37
38 #ifdef SYS_BEOS
39 #include "beos_specific.h"
40 #endif
41
42 #include "plugins.h"
43
44 #define PLUGIN_PATH_COUNT 5
45
46 int RequestPlugin ( plugin_id_t * p_plugin, char * psz_mask, char * psz_name )
47 {
48     int i_count, i_length;
49     char * psz_plugin;
50     char * psz_plugin_path[ PLUGIN_PATH_COUNT ] =
51     {
52         ".",
53         "plugins/aout", "plugins/vout", "plugins/intf", /* these ones should disappear */
54         PLUGIN_PATH
55     };
56
57     i_length = strlen( psz_mask ) + strlen( psz_name );
58
59     for ( i_count = 0 ; i_count < PLUGIN_PATH_COUNT ; i_count++ )
60     {
61 #ifdef SYS_BEOS
62         char * psz_program_path;
63         
64         psz_program_path = beos_GetProgramPath();
65         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + strlen(psz_program_path) + i_length + 6 );
66         sprintf( psz_plugin, "%s/%s/%s_%s.so", psz_program_path, psz_plugin_path[i_count], psz_mask, psz_name );        
67 #else
68         psz_plugin = malloc( strlen(psz_plugin_path[i_count]) + i_length + 6 );
69         sprintf( psz_plugin, "%s/%s_%s.so", psz_plugin_path[i_count], psz_mask, psz_name );
70 #endif
71
72 #if defined(HAVE_DLFCN_H)
73         *p_plugin = dlopen( psz_plugin, RTLD_NOW | RTLD_GLOBAL );
74 #elif defined(HAVE_IMAGE_H)
75         *p_plugin = load_add_on( psz_plugin );
76 #endif
77
78         free( psz_plugin );
79
80 #if defined(HAVE_DLFCN_H)
81         if( *p_plugin != NULL )
82             return( 0 );
83 #elif defined(HAVE_IMAGE_H)
84         if( *p_plugin >= 0 )
85             return( 0 );
86 #endif
87     }
88
89     return( -1 );
90 }
91
92 void TrashPlugin ( plugin_id_t plugin )
93 {
94 #if defined(HAVE_DLFCN_H)
95     dlclose( plugin );
96 #elif defined(HAVE_IMAGE_H)
97     unload_add_on( plugin );
98 #endif
99 }
100
101 void * GetPluginFunction ( plugin_id_t plugin, char *psz_name )
102 {
103 #if defined(HAVE_DLFCN_H)
104     return( dlsym(plugin, psz_name) );
105 #elif defined(HAVE_IMAGE_H)
106     void * p_func;   
107     if( get_image_symbol( plugin, psz_name, B_SYMBOL_TYPE_TEXT, &p_func ) )
108         return( NULL );
109     else
110         return( p_func );    
111 #endif
112 }
113