]> git.sesse.net Git - vlc/blob - include/modules.h
. Added files needed for the forthcoming module management.
[vlc] / include / modules.h
1 /*****************************************************************************
2  * modules.h : Module management functions.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
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
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /* Number of tries before we unload an unused module */
24 #define MODULE_HIDE_DELAY 10
25
26 /* The module handle type. */
27 #ifdef SYS_BEOS
28 typedef int     module_handle_t;
29 #else
30 typedef void *  module_handle_t;
31 #endif
32
33 /*****************************************************************************
34  * Configuration structure
35  *****************************************************************************/
36 typedef struct module_config_s
37 {
38     int         i_type;                         /* Configuration widget type */
39     char *      psz_text;        /* Text commenting or describing the widget */
40     char *      psz_name;                                   /* Variable name */
41     void *      p_getlist;          /* Function to call to get a choice list */
42     void *      p_change;        /* Function to call when commiting a change */
43 } module_config_t;
44
45 /*****************************************************************************
46  * Bank and module description structures
47  *****************************************************************************/
48
49 /* The main module structure */
50 typedef struct module_s
51 {
52     boolean_t           b_builtin;  /* Set to true if the module is built in */
53
54     module_handle_t     handle;      /* Unique handle to refer to the module */
55     char *              psz_filename;                     /* Module filename */
56
57     char *              psz_name;                    /* Module _unique_ name */
58     char *              psz_longname;             /* Module descriptive name */
59     char *              psz_version;                       /* Module version */
60
61     int                 i_usage;                        /* Reference counter */
62     int                 i_unused_delay;    /* Delay until module is unloaded */
63
64     struct module_s *   next;                                 /* Next module */
65     struct module_s *   prev;                             /* Previous module */
66
67     u32                 i_capabilities;                   /* Capability list */
68
69     module_config_t *   p_config;    /* Module configuration structure table */
70
71 } module_t;
72
73 /* The module bank structure */
74 typedef struct module_bank_s
75 {
76     module_t *          first; /* First module of the bank */
77
78     vlc_mutex_t         lock;  /* Global lock -- you can't imagine how awful it
79                                   is to design thread-safe linked lists. */
80 } module_bank_t;
81
82 /*****************************************************************************
83  * Stuff for handling dynamic modules
84  *****************************************************************************/
85
86 /* Function to load a dynamic module, returns 0 if successful. */
87 static __inline__ int
88 module_load( char * psz_filename, module_handle_t * handle )
89 {
90 #ifdef SYS_BEOS
91     *handle = load_add_on( psz_filename );
92     return( *handle >= 0 );
93 #else
94     *handle = dlopen( psz_filename, RTLD_NOW | RTLD_GLOBAL );
95     return( *handle != NULL );
96 #endif
97 }
98
99 /* Unload a dynamic module. */
100 static __inline__ void
101 module_unload( module_handle_t handle )
102 {
103 #ifdef SYS_BEOS
104     unload_add_on( handle );
105 #else
106     dlclose( handle );
107 #endif
108     return;
109 }
110
111 /* Get a given symbol from a module. */
112 static __inline__ void *
113 module_getsymbol( module_handle_t handle, char * psz_function )
114 {
115 #ifdef SYS_BEOS
116     void * p_symbol;
117     get_image_symbol( handle, psz_function, B_SYMBOL_TYPE_TEXT, &p_symbol );
118     return( p_symbol );
119 #else
120     return( dlsym( handle, psz_function ) );
121 #endif
122 }
123
124 /* Wrapper to dlerror() for systems that don't have it. */
125 static __inline__ char *
126 module_error( void )
127 {
128 #ifdef SYS_BEOS
129     return( "failed" );
130 #else
131     return( dlerror() );
132 #endif
133 }
134
135 /*****************************************************************************
136  * Exported functions.
137  *****************************************************************************/
138 module_bank_t * module_InitBank     ( void );
139 int             module_DestroyBank  ( module_bank_t * p_bank );
140 int             module_ResetBank    ( module_bank_t * p_bank );
141 void            module_ManageBank   ( module_bank_t * p_bank );
142
143 int module_Need    ( module_t * p_module );
144 int module_Unneed  ( module_t * p_module );
145