]> git.sesse.net Git - vlc/blob - src/modules/entry.c
b1ee2b5a9b2873773fbf921c8bf20c0ab2665c09
[vlc] / src / modules / entry.c
1 /*****************************************************************************
2  * entry.c : Callbacks for module entry point
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20
21 #include <vlc/vlc.h>
22 #include <assert.h>
23 #include <stdarg.h>
24
25 #include "modules.h"
26 #include "libvlc.h"
27
28 static const char default_name[] = "unnamed";
29
30 module_t *vlc_module_create (vlc_object_t *obj)
31 {
32     module_t *module =
33         (module_t *)vlc_custom_create (obj, sizeof (module_t),
34                                        VLC_OBJECT_MODULE, "module");
35     if (module == NULL)
36         return NULL;
37
38     module->b_reentrant = module->b_unloadable = VLC_TRUE;
39     module->psz_object_name = module->psz_longname = default_name;
40     module->psz_capability = "";
41     module->i_score = 1;
42     return module;
43 }
44
45
46 module_t *vlc_submodule_create (module_t *module)
47 {
48     assert (module != NULL);
49     assert (!module->b_submodule); // subsubmodules are not supported
50
51     module_t *submodule =
52         (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
53                                        VLC_OBJECT_MODULE, "submodule");
54     if (submodule == NULL)
55         return NULL;
56
57     vlc_object_attach (submodule, module);
58     submodule->b_submodule = VLC_TRUE;
59
60     /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
61     memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
62             sizeof (submodule->pp_shortcuts));
63
64     submodule->psz_object_name = module->psz_object_name;
65     submodule->psz_shortname = module->psz_shortname;
66     submodule->psz_longname = module->psz_longname;
67     submodule->psz_capability = module->psz_capability;
68     submodule->i_score = module->i_score;
69     submodule->i_cpu = module->i_cpu;
70     return submodule;
71 }
72
73
74 int vlc_module_set (module_t *module, int propid, void *value)
75 {
76     switch (propid)
77     {
78         case VLC_MODULE_CPU_REQUIREMENT:
79             assert (!module->b_submodule);
80             module->i_cpu |= (intptr_t)value;
81             break;
82
83         case VLC_MODULE_SHORTCUT:
84         {
85             unsigned i;
86             for (i = 0; module->pp_shortcuts[i] != NULL; i++);
87             if (i >= (MODULE_SHORTCUT_MAX - 1))
88                 return VLC_ENOMEM;
89
90             module->pp_shortcuts[i] = (char *)value;
91             break;
92         }
93
94         case VLC_MODULE_SHORTNAME:
95             module->psz_shortname = (char *)value;
96             break;
97
98         case VLC_MODULE_DESCRIPTION:
99             module->psz_longname = (char *)value;
100             break;
101
102         case VLC_MODULE_HELP:
103             module->psz_help = (char *)value;
104             break;
105
106         case VLC_MODULE_CAPABILITY:
107             module->psz_capability = (char *)value;
108             break;
109
110         case VLC_MODULE_SCORE:
111             module->i_score = (intptr_t)value;
112             break;
113
114         case VLC_MODULE_CB_OPEN:
115             module->pf_activate = (int (*) (vlc_object_t *))value;
116             break;
117
118         case VLC_MODULE_CB_CLOSE:
119             module->pf_deactivate = (void (*) (vlc_object_t *))value;
120             break;
121
122         case VLC_MODULE_UNLOADABLE:
123             module->b_unloadable = (value != NULL);
124             break;
125
126         case VLC_MODULE_NAME:
127             module->pp_shortcuts[0] = module->psz_object_name = (char *)value;
128             if (module->psz_longname == default_name)
129                 module->psz_longname = (char *)value;
130             break;
131
132         case VLC_MODULE_PROGRAM:
133             msg_Warn (module, "deprecated module property %d", propid);
134             return 0;
135
136         default:
137             msg_Err (module, "unknown module property %d", propid);
138             msg_Err (module, "LibVLC might be too old to use this module.");
139             return VLC_EGENERIC;
140     }
141     return 0;
142 }
143
144 int vlc_config_set (module_config_t *restrict item, vlc_config_t id, ...)
145 {
146     int ret = -1;
147     va_list ap;
148
149     assert (item != NULL);
150     va_start (ap, id);
151
152     switch (id)
153     {
154         case VLC_CONFIG_NAME:
155         {
156             const char *name = va_arg (ap, const char *);
157             vlc_callback_t cb = va_arg (ap, vlc_callback_t);
158
159             assert (name != NULL);
160             item->psz_name = strdup (name);
161             item->pf_callback = cb;
162             break;
163         }
164
165         case VLC_CONFIG_DESC:
166         {
167             const char *text = va_arg (ap, const char *);
168             const char *longtext = va_arg (ap, const char *);
169
170             item->psz_text = text ? strdup (gettext (text)) : NULL;
171             item->psz_longtext = longtext ? strdup (gettext (text)) : NULL;
172             ret = 0;
173             break;
174         }
175
176         case VLC_CONFIG_VALUE:
177         case VLC_CONFIG_RANGE:
178         case VLC_CONFIG_STEP:
179         case VLC_CONFIG_ADVANCED:
180         case VLC_CONFIG_VOLATILE:
181         case VLC_CONFIG_PRIVATE:
182             break;
183     }
184
185     va_end (ap);
186     return ret;
187 }