]> git.sesse.net Git - vlc/blob - src/misc/modules_plugin.h
* ./include/modules_inner.h: replaced _X with __VLC_SYMBOL because _X was
[vlc] / src / misc / modules_plugin.h
1 /*****************************************************************************
2  * modules_plugin.h : Plugin management functions used by the core application.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: modules_plugin.h,v 1.4 2002/01/09 02:01:14 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Inline functions for handling dynamic modules
26  *****************************************************************************/
27
28 /*****************************************************************************
29  * module_load: load a dynamic library
30  *****************************************************************************
31  * This function loads a dynamically linked library using a system dependant
32  * method, and returns a non-zero value on error, zero otherwise.
33  *****************************************************************************/
34 static __inline__ int
35 module_load( char * psz_filename, module_handle_t * handle )
36 {
37 #ifdef SYS_BEOS
38     *handle = load_add_on( psz_filename );
39     return( *handle < 0 );
40
41 #elif defined(WIN32)
42     *handle = LoadLibrary( psz_filename );
43     return( *handle == NULL ); 
44
45 #elif defined(RTLD_NOW)
46     /* Do not open modules with RTLD_GLOBAL, or we are going to get namespace
47      * collisions when two modules have common public symbols */
48     *handle = dlopen( psz_filename, RTLD_NOW );
49     return( *handle == NULL );
50
51 #else
52     *handle = dlopen( psz_filename, DL_LAZY );
53     return( *handle == NULL );
54
55 #endif
56 }
57
58 /*****************************************************************************
59  * module_unload: unload a dynamic library
60  *****************************************************************************
61  * This function unloads a previously opened dynamically linked library
62  * using a system dependant method. No return value is taken in consideration,
63  * since some libraries sometimes refuse to close properly.
64  *****************************************************************************/
65 static __inline__ void
66 module_unload( module_handle_t handle )
67 {
68 #ifdef SYS_BEOS
69     unload_add_on( handle );
70
71 #elif defined(WIN32)
72     FreeLibrary( handle );
73
74 #else
75     dlclose( handle );
76
77 #endif
78     return;
79 }
80
81 /*****************************************************************************
82  * module_getsymbol: get a symbol from a dynamic library
83  *****************************************************************************
84  * This function queries a loaded library for a symbol specified in a
85  * string, and returns a pointer to it. We don't check for dlerror() or
86  * similar functions, since we want a non-NULL symbol anyway.
87  *****************************************************************************/
88 static __inline__ void *
89 module_getsymbol( module_handle_t handle, char * psz_function )
90 {
91 #ifdef SYS_BEOS
92     void * p_symbol;
93     if( B_OK == get_image_symbol( handle, psz_function,
94                                   B_SYMBOL_TYPE_TEXT, &p_symbol ) )
95     {
96         return( p_symbol );
97     }
98     else
99     {
100         return( NULL );
101     }
102
103 #elif defined( SYS_DARWIN )
104     /* MacOS X dl library expects symbols to begin with "_". That's
105      * really lame, but hey, what can we do ? */
106     char *  psz_call = malloc( strlen( psz_function ) + 2 );
107     void *  p_return;
108     strcpy( psz_call + 1, psz_function );
109     psz_call[ 0 ] = '_';
110
111     p_return = dlsym( handle, psz_call );
112
113     free( psz_call );
114     return( p_return );
115
116 #elif defined(WIN32)
117     return( (void *)GetProcAddress( handle, psz_function ) );
118
119 #else
120     return( dlsym( handle, psz_function ) );
121
122 #endif
123 }
124
125 /*****************************************************************************
126  * module_error: wrapper for dlerror()
127  *****************************************************************************
128  * This function returns the error message of the last module operation. It
129  * returns the string "failed" on systems which do not have the dlerror()
130  * function.
131  *****************************************************************************/
132 static __inline__ const char *
133 module_error( void )
134 {
135 #if defined(SYS_BEOS) || defined(WIN32)
136     return( "failed" );
137
138 #else
139     return( dlerror() );
140
141 #endif
142 }
143
144 /*****************************************************************************
145  * STORE_SYMBOLS: store known symbols into p_symbols for plugin access.
146  *****************************************************************************/
147 #ifdef TRACE
148 #   define STORE_TRACE_SYMBOLS( p_symbols ) \
149         (p_symbols)->intf_DbgMsg = _intf_DbgMsg; \
150         (p_symbols)->intf_DbgMsgImm = _intf_DbgMsgImm;
151 #else
152 #   define STORE_TRACE_SYMBOLS( p_symbols )
153 #endif
154
155 #define STORE_SYMBOLS( p_symbols ) \
156     STORE_TRACE_SYMBOLS( p_symbols ) \
157     (p_symbols)->p_main = p_main; \
158     (p_symbols)->p_input_bank = p_input_bank; \
159     (p_symbols)->p_aout_bank = p_aout_bank; \
160     (p_symbols)->p_vout_bank = p_vout_bank; \
161     (p_symbols)->main_GetIntVariable = main_GetIntVariable; \
162     (p_symbols)->main_GetPszVariable = main_GetPszVariable; \
163     (p_symbols)->main_PutIntVariable = main_PutIntVariable; \
164     (p_symbols)->main_PutPszVariable = main_PutPszVariable; \
165     (p_symbols)->intf_Msg = intf_Msg; \
166     (p_symbols)->intf_ErrMsg = intf_ErrMsg; \
167     (p_symbols)->intf_StatMsg = intf_StatMsg;\
168     (p_symbols)->intf_WarnMsg = intf_WarnMsg; \
169     (p_symbols)->intf_WarnMsgImm = intf_WarnMsgImm; \
170     (p_symbols)->intf_PlaylistAdd = intf_PlaylistAdd; \
171     (p_symbols)->intf_PlaylistDelete = intf_PlaylistDelete; \
172     (p_symbols)->intf_PlaylistNext = intf_PlaylistNext; \
173     (p_symbols)->intf_PlaylistPrev = intf_PlaylistPrev; \
174     (p_symbols)->intf_PlaylistDestroy = intf_PlaylistDestroy; \
175     (p_symbols)->intf_PlaylistJumpto = intf_PlaylistJumpto; \
176     (p_symbols)->intf_UrlDecode = intf_UrlDecode; \
177     (p_symbols)->intf_Eject = intf_Eject; \
178     (p_symbols)->msleep = msleep; \
179     (p_symbols)->mdate = mdate; \
180     (p_symbols)->network_ChannelCreate = network_ChannelCreate; \
181     (p_symbols)->network_ChannelJoin = network_ChannelJoin; \
182     (p_symbols)->input_SetProgram = input_SetProgram; \
183     (p_symbols)->input_SetStatus = input_SetStatus; \
184     (p_symbols)->input_Seek = input_Seek; \
185     (p_symbols)->input_DumpStream = input_DumpStream; \
186     (p_symbols)->input_OffsetToTime = input_OffsetToTime; \
187     (p_symbols)->input_ChangeES = input_ChangeES; \
188     (p_symbols)->input_ToggleES = input_ToggleES; \
189     (p_symbols)->input_ChangeArea = input_ChangeArea; \
190     (p_symbols)->input_FindES = input_FindES; \
191     (p_symbols)->input_AddES = input_AddES; \
192     (p_symbols)->input_DelES = input_DelES; \
193     (p_symbols)->input_SelectES = input_SelectES; \
194     (p_symbols)->input_UnselectES = input_UnselectES; \
195     (p_symbols)->input_AddProgram = input_AddProgram; \
196     (p_symbols)->input_DelProgram = input_DelProgram; \
197     (p_symbols)->input_AddArea = input_AddArea; \
198     (p_symbols)->input_DelArea = input_DelArea; \
199     (p_symbols)->InitBitstream = InitBitstream; \
200     (p_symbols)->DecoderError = DecoderError; \
201     (p_symbols)->input_InitStream = input_InitStream; \
202     (p_symbols)->input_EndStream = input_EndStream; \
203     (p_symbols)->input_ParsePES = input_ParsePES; \
204     (p_symbols)->input_GatherPES = input_GatherPES; \
205     (p_symbols)->input_DecodePES = input_DecodePES; \
206     (p_symbols)->input_ParsePS = input_ParsePS; \
207     (p_symbols)->input_DemuxPS = input_DemuxPS; \
208     (p_symbols)->input_DemuxTS = input_DemuxTS; \
209     (p_symbols)->input_DemuxPSI = input_DemuxPSI; \
210     (p_symbols)->input_ClockManageControl = input_ClockManageControl; \
211     (p_symbols)->aout_CreateFifo = aout_CreateFifo; \
212     (p_symbols)->aout_DestroyFifo = aout_DestroyFifo; \
213     (p_symbols)->vout_CreateThread = vout_CreateThread; \
214     (p_symbols)->vout_DestroyThread = vout_DestroyThread; \
215     (p_symbols)->vout_CreateSubPicture = vout_CreateSubPicture; \
216     (p_symbols)->vout_DestroySubPicture = vout_DestroySubPicture; \
217     (p_symbols)->vout_DisplaySubPicture = vout_DisplaySubPicture; \
218     (p_symbols)->vout_CreatePicture = vout_CreatePicture; \
219     (p_symbols)->vout_AllocatePicture = vout_AllocatePicture; \
220     (p_symbols)->vout_DisplayPicture = vout_DisplayPicture; \
221     (p_symbols)->vout_DestroyPicture = vout_DestroyPicture; \
222     (p_symbols)->vout_DatePicture = vout_DatePicture; \
223     (p_symbols)->vout_LinkPicture = vout_LinkPicture; \
224     (p_symbols)->vout_UnlinkPicture = vout_UnlinkPicture; \
225     (p_symbols)->vout_PlacePicture = vout_PlacePicture; \
226     (p_symbols)->UnalignedGetBits = UnalignedGetBits; \
227     (p_symbols)->UnalignedRemoveBits = UnalignedRemoveBits; \
228     (p_symbols)->UnalignedShowBits = UnalignedShowBits; \
229     (p_symbols)->DecodeLanguage = DecodeLanguage; \
230     (p_symbols)->module_Need = module_Need; \
231     (p_symbols)->module_Unneed = module_Unneed;
232     
233