1 /*****************************************************************************
2 * entry.c : Callbacks for module entry point
3 *****************************************************************************
4 * Copyright (C) 2001-2007 the VideoLAN team
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.
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.
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 *****************************************************************************/
25 #include "modules/modules.h"
26 #include "config/config.h"
29 static const char default_name[] = "unnamed";
31 module_t *vlc_module_create (vlc_object_t *obj)
34 (module_t *)vlc_custom_create (obj, sizeof (module_t),
35 VLC_OBJECT_MODULE, "module");
39 module->b_reentrant = module->b_unloadable = VLC_TRUE;
40 module->psz_object_name = module->psz_longname = default_name;
41 module->psz_capability = "";
43 module->i_config_items = module->i_bool_items = 0;
49 module_t *vlc_submodule_create (module_t *module)
51 assert (module != NULL);
52 assert (!module->b_submodule); // subsubmodules are not supported
55 (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
56 VLC_OBJECT_MODULE, "submodule");
57 if (submodule == NULL)
60 vlc_object_attach (submodule, module);
61 submodule->b_submodule = VLC_TRUE;
63 /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
64 memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
65 sizeof (submodule->pp_shortcuts));
67 submodule->psz_object_name = module->psz_object_name;
68 submodule->psz_shortname = module->psz_shortname;
69 submodule->psz_longname = module->psz_longname;
70 submodule->psz_capability = module->psz_capability;
71 submodule->i_score = module->i_score;
72 submodule->i_cpu = module->i_cpu;
77 int vlc_module_set (module_t *module, int propid, void *value)
81 case VLC_MODULE_CPU_REQUIREMENT:
82 assert (!module->b_submodule);
83 module->i_cpu |= (intptr_t)value;
86 case VLC_MODULE_SHORTCUT:
89 for (i = 0; module->pp_shortcuts[i] != NULL; i++);
90 if (i >= (MODULE_SHORTCUT_MAX - 1))
93 module->pp_shortcuts[i] = (char *)value;
97 case VLC_MODULE_SHORTNAME:
98 module->psz_shortname = (char *)value;
101 case VLC_MODULE_DESCRIPTION:
102 module->psz_longname = (char *)value;
105 case VLC_MODULE_HELP:
106 module->psz_help = (char *)value;
109 case VLC_MODULE_CAPABILITY:
110 module->psz_capability = (char *)value;
113 case VLC_MODULE_SCORE:
114 module->i_score = (intptr_t)value;
117 case VLC_MODULE_CB_OPEN:
118 module->pf_activate = (int (*) (vlc_object_t *))value;
121 case VLC_MODULE_CB_CLOSE:
122 module->pf_deactivate = (void (*) (vlc_object_t *))value;
125 case VLC_MODULE_UNLOADABLE:
126 module->b_unloadable = (value != NULL);
129 case VLC_MODULE_NAME:
130 module->pp_shortcuts[0] = module->psz_object_name = (char *)value;
131 if (module->psz_longname == default_name)
132 module->psz_longname = (char *)value;
135 case VLC_MODULE_PROGRAM:
136 msg_Warn (module, "deprecated module property %d", propid);
140 msg_Err (module, "unknown module property %d", propid);
141 msg_Err (module, "LibVLC might be too old to use this module.");
147 module_config_t *vlc_config_create (module_t *module, int type)
149 unsigned confsize = module->confsize;
150 module_config_t *tab = module->p_config;
152 if ((confsize & 0xf) == 0)
154 tab = realloc (tab, (confsize + 17) * sizeof (*tab));
158 module->p_config = tab;
161 memset (tab + confsize, 0, sizeof (tab[confsize]));
162 tab[confsize].i_type = type;
163 tab[confsize].p_lock = &module->object_lock;
165 if (type & CONFIG_ITEM)
167 module->i_config_items++;
168 if (type == CONFIG_ITEM_BOOL)
169 module->i_bool_items++;
173 return tab + confsize;
176 int vlc_config_set (module_config_t *restrict item, int id, ...)
181 assert (item != NULL);
186 case VLC_CONFIG_NAME:
188 const char *name = va_arg (ap, const char *);
189 vlc_callback_t cb = va_arg (ap, vlc_callback_t);
191 assert (name != NULL);
192 item->psz_name = strdup (name);
193 item->pf_callback = cb;
198 case VLC_CONFIG_DESC:
200 const char *text = va_arg (ap, const char *);
201 const char *longtext = va_arg (ap, const char *);
203 item->psz_text = text ? strdup ( _(text)) : NULL;
204 item->psz_longtext = longtext ? strdup ( _(longtext)) : NULL;
209 case VLC_CONFIG_VALUE:
211 if (IsConfigIntegerType (item->i_type))
213 item->orig.i = item->saved.i =
214 item->value.i = va_arg (ap, int);
218 if (IsConfigFloatType (item->i_type))
220 item->orig.f = item->saved.f =
221 item->value.f = va_arg (ap, double);
225 if (IsConfigStringType (item->i_type))
227 const char *value = va_arg (ap, const char *);
228 item->value.psz = value ? strdup (value) : NULL;
229 item->orig.psz = value ? strdup (value) : NULL;
230 item->saved.psz = value ? strdup (value) : NULL;
236 case VLC_CONFIG_RANGE:
238 if (IsConfigIntegerType (item->i_type))
240 item->min.i = va_arg (ap, int);
241 item->max.i = va_arg (ap, int);
245 if (IsConfigFloatType (item->i_type))
247 item->min.f = va_arg (ap, double);
248 item->max.f = va_arg (ap, double);
254 case VLC_CONFIG_ADVANCED:
255 item->b_advanced = VLC_TRUE;
259 case VLC_CONFIG_VOLATILE:
260 item->b_unsaveable = VLC_TRUE;
264 case VLC_CONFIG_PERSISTENT:
265 item->b_autosave = VLC_TRUE;
269 case VLC_CONFIG_RESTART:
270 item->b_restart = VLC_TRUE;
274 case VLC_CONFIG_PRIVATE:
275 item->b_internal = VLC_TRUE;
279 case VLC_CONFIG_REMOVED:
280 item->b_removed = VLC_TRUE;
284 case VLC_CONFIG_CAPABILITY:
286 const char *cap = va_arg (ap, const char *);
287 item->psz_type = cap ? strdup (cap) : NULL;
292 case VLC_CONFIG_SHORTCUT:
293 item->i_short = va_arg (ap, int);
297 case VLC_CONFIG_LIST:
299 size_t len = va_arg (ap, size_t);
300 char **dtext = malloc (sizeof (char *) * (len + 1));
306 if (IsConfigIntegerType (item->i_type))
308 const int *src = va_arg (ap, const int *);
309 int *dst = malloc (sizeof (int) * (len + 1));
313 memcpy (dst, src, sizeof (int) * len);
320 if (IsConfigFloatType (item->i_type))
322 const float *src = va_arg (ap, const float *);
323 float *dst = malloc (sizeof (float) * (len + 1));
327 memcpy (dst, src, sizeof (float) * len);
334 if (IsConfigStringType (item->i_type))
336 const char *const *src = va_arg (ap, const char *const *);
337 char **dst = malloc (sizeof (char *) * (len + 1));
341 for (size_t i = 0; i < len; i++)
342 dst[i] = src[i] ? strdup (src[i]) : NULL;
345 item->ppsz_list = dst;
350 /* Copy textual descriptions */
351 const char *const *text = va_arg (ap, const char *const *);
354 for (size_t i = 0; i < len; i++)
355 dtext[i] = text[i] ? strdup ( _(text[i])) : NULL;
358 item->ppsz_list_text = dtext;
363 item->ppsz_list_text = NULL;
371 case VLC_CONFIG_ADD_ACTION:
373 vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb;
374 const char *name = va_arg (ap, const char *);
377 tabcb = realloc (item->ppf_action,
378 (item->i_action + 2) * sizeof (cb));
381 item->ppf_action = tabcb;
382 tabcb[item->i_action] = cb;
383 tabcb[item->i_action + 1] = NULL;
385 tabtext = realloc (item->ppsz_action_text,
386 (item->i_action + 2) * sizeof (name));
389 item->ppsz_action_text = tabtext;
392 tabtext[item->i_action] = strdup ( _(name));
394 tabtext[item->i_action] = NULL;
395 tabtext[item->i_action + 1] = NULL;
402 case VLC_CONFIG_OLDNAME:
404 const char *oldname = va_arg (ap, const char *);
405 item->psz_oldname = oldname ? strdup (oldname) : NULL;
410 case VLC_CONFIG_SAFE:
411 item->b_safe = VLC_TRUE;