1 /*****************************************************************************
2 * entry.c : Callbacks for module entry point
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
5 * Copyright © 2007-2008 Rémi Denis-Courmont
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
30 #include "modules/modules.h"
31 #include "config/configuration.h"
34 static const char default_name[] = "unnamed";
36 module_t *vlc_module_create (vlc_object_t *obj)
39 (module_t *)vlc_custom_create (obj, sizeof (module_t),
40 VLC_OBJECT_MODULE, "module");
44 module->b_reentrant = module->b_unloadable = true;
45 module->psz_object_name = strdup( default_name );
46 module->psz_longname = default_name;
47 module->psz_capability = (char*)"";
49 module->i_config_items = module->i_bool_items = 0;
55 module_t *vlc_submodule_create (module_t *module)
57 assert (module != NULL);
58 assert (!module->b_submodule); // subsubmodules are not supported
61 (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
62 VLC_OBJECT_MODULE, "submodule");
63 if (submodule == NULL)
66 vlc_object_attach (submodule, module);
67 submodule->b_submodule = true;
69 /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
70 memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
71 sizeof (submodule->pp_shortcuts));
73 submodule->psz_object_name = strdup( module->psz_object_name );
74 submodule->psz_shortname = module->psz_shortname;
75 submodule->psz_longname = module->psz_longname;
76 submodule->psz_capability = module->psz_capability;
77 submodule->i_score = module->i_score;
78 submodule->i_cpu = module->i_cpu;
83 int vlc_module_set (module_t *module, int propid, ...)
86 int ret = VLC_SUCCESS;
88 va_start (ap, propid);
91 case VLC_MODULE_CPU_REQUIREMENT:
92 assert (!module->b_submodule);
93 module->i_cpu |= va_arg (ap, int);
96 case VLC_MODULE_SHORTCUT:
99 for (i = 0; module->pp_shortcuts[i] != NULL; i++);
100 if (i >= (MODULE_SHORTCUT_MAX - 1))
106 module->pp_shortcuts[i] = va_arg (ap, char *);
110 case VLC_MODULE_SHORTNAME:
111 module->psz_shortname = va_arg (ap, char *);
114 case VLC_MODULE_DESCRIPTION:
115 module->psz_longname = va_arg (ap, char *);
118 case VLC_MODULE_HELP:
119 module->psz_help = va_arg (ap, char *);
122 case VLC_MODULE_CAPABILITY:
123 module->psz_capability = va_arg (ap, char *);
126 case VLC_MODULE_SCORE:
127 module->i_score = va_arg (ap, int);
130 case VLC_MODULE_CB_OPEN:
131 module->pf_activate = va_arg (ap, int (*) (vlc_object_t *));
134 case VLC_MODULE_CB_CLOSE:
135 module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *));
138 case VLC_MODULE_NO_UNLOAD:
139 module->b_unloadable = false;
142 case VLC_MODULE_NAME:
144 const char *value = va_arg (ap, const char *);
145 free( module->psz_object_name );
146 module->psz_object_name = strdup( value );
147 module->pp_shortcuts[0] = value;
148 if (module->psz_longname == default_name)
149 module->psz_longname = value;
153 case VLC_MODULE_PROGRAM:
154 msg_Warn (module, "deprecated module property %d", propid);
158 msg_Err (module, "unknown module property %d", propid);
159 msg_Err (module, "LibVLC might be too old to use this module.");
167 module_config_t *vlc_config_create (module_t *module, int type)
169 unsigned confsize = module->confsize;
170 module_config_t *tab = module->p_config;
172 if ((confsize & 0xf) == 0)
174 tab = realloc (tab, (confsize + 17) * sizeof (*tab));
178 module->p_config = tab;
181 memset (tab + confsize, 0, sizeof (tab[confsize]));
182 tab[confsize].i_type = type;
183 tab[confsize].p_lock = &module->object_lock;
185 if (type & CONFIG_ITEM)
187 module->i_config_items++;
188 if (type == CONFIG_ITEM_BOOL)
189 module->i_bool_items++;
193 return tab + confsize;
196 int vlc_config_set (module_config_t *restrict item, int id, ...)
201 assert (item != NULL);
206 case VLC_CONFIG_NAME:
208 const char *name = va_arg (ap, const char *);
209 vlc_callback_t cb = va_arg (ap, vlc_callback_t);
211 assert (name != NULL);
212 item->psz_name = strdup (name);
213 item->pf_callback = cb;
218 case VLC_CONFIG_DESC:
220 const char *text = va_arg (ap, const char *);
221 const char *longtext = va_arg (ap, const char *);
223 item->psz_text = text ? strdup ( _(text)) : NULL;
224 item->psz_longtext = longtext ? strdup ( _(longtext)) : NULL;
229 case VLC_CONFIG_VALUE:
231 if (IsConfigIntegerType (item->i_type))
233 item->orig.i = item->saved.i =
234 item->value.i = va_arg (ap, int);
238 if (IsConfigFloatType (item->i_type))
240 item->orig.f = item->saved.f =
241 item->value.f = va_arg (ap, double);
245 if (IsConfigStringType (item->i_type))
247 const char *value = va_arg (ap, const char *);
248 item->value.psz = value ? strdup (value) : NULL;
249 item->orig.psz = value ? strdup (value) : NULL;
250 item->saved.psz = value ? strdup (value) : NULL;
256 case VLC_CONFIG_RANGE:
258 if (IsConfigIntegerType (item->i_type))
260 item->min.i = va_arg (ap, int);
261 item->max.i = va_arg (ap, int);
265 if (IsConfigFloatType (item->i_type))
267 item->min.f = va_arg (ap, double);
268 item->max.f = va_arg (ap, double);
274 case VLC_CONFIG_ADVANCED:
275 item->b_advanced = true;
279 case VLC_CONFIG_VOLATILE:
280 item->b_unsaveable = true;
284 case VLC_CONFIG_PERSISTENT:
285 item->b_autosave = true;
289 case VLC_CONFIG_RESTART:
290 item->b_restart = true;
294 case VLC_CONFIG_PRIVATE:
295 item->b_internal = true;
299 case VLC_CONFIG_REMOVED:
300 item->b_removed = true;
304 case VLC_CONFIG_CAPABILITY:
306 const char *cap = va_arg (ap, const char *);
307 item->psz_type = cap ? strdup (cap) : NULL;
312 case VLC_CONFIG_SHORTCUT:
313 item->i_short = va_arg (ap, int);
317 case VLC_CONFIG_LIST:
319 size_t len = va_arg (ap, size_t);
320 char **dtext = malloc (sizeof (char *) * (len + 1));
326 if (IsConfigIntegerType (item->i_type))
328 const int *src = va_arg (ap, const int *);
329 int *dst = malloc (sizeof (int) * (len + 1));
333 memcpy (dst, src, sizeof (int) * len);
340 if (IsConfigFloatType (item->i_type))
342 const float *src = va_arg (ap, const float *);
343 float *dst = malloc (sizeof (float) * (len + 1));
347 memcpy (dst, src, sizeof (float) * len);
354 if (IsConfigStringType (item->i_type))
356 const char *const *src = va_arg (ap, const char *const *);
357 char **dst = malloc (sizeof (char *) * (len + 1));
361 for (size_t i = 0; i < len; i++)
362 dst[i] = src[i] ? strdup (src[i]) : NULL;
365 item->ppsz_list = dst;
370 /* Copy textual descriptions */
371 const char *const *text = va_arg (ap, const char *const *);
374 for (size_t i = 0; i < len; i++)
375 dtext[i] = text[i] ? strdup ( _(text[i])) : NULL;
378 item->ppsz_list_text = dtext;
383 item->ppsz_list_text = NULL;
387 item->pf_update_list = va_arg (ap, vlc_callback_t);
392 case VLC_CONFIG_ADD_ACTION:
394 vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb;
395 const char *name = va_arg (ap, const char *);
398 tabcb = realloc (item->ppf_action,
399 (item->i_action + 2) * sizeof (cb));
402 item->ppf_action = tabcb;
403 tabcb[item->i_action] = cb;
404 tabcb[item->i_action + 1] = NULL;
406 tabtext = realloc (item->ppsz_action_text,
407 (item->i_action + 2) * sizeof (name));
410 item->ppsz_action_text = tabtext;
413 tabtext[item->i_action] = strdup ( _(name));
415 tabtext[item->i_action] = NULL;
416 tabtext[item->i_action + 1] = NULL;
423 case VLC_CONFIG_OLDNAME:
425 const char *oldname = va_arg (ap, const char *);
426 item->psz_oldname = oldname ? strdup (oldname) : NULL;
431 case VLC_CONFIG_SAFE: