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 *****************************************************************************/
29 #include "modules/modules.h"
30 #include "config/configuration.h"
33 static const char default_name[] = "unnamed";
35 module_t *vlc_module_create (vlc_object_t *obj)
38 (module_t *)vlc_custom_create (obj, sizeof (module_t),
39 VLC_OBJECT_MODULE, "module");
43 module->b_reentrant = module->b_unloadable = true;
44 module->psz_object_name = strdup( default_name );
45 module->psz_longname = default_name;
46 module->psz_capability = (char*)"";
48 module->i_config_items = module->i_bool_items = 0;
54 module_t *vlc_submodule_create (module_t *module)
56 assert (module != NULL);
57 assert (!module->b_submodule); // subsubmodules are not supported
60 (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
61 VLC_OBJECT_MODULE, "submodule");
62 if (submodule == NULL)
65 vlc_object_attach (submodule, module);
66 submodule->b_submodule = true;
68 /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
69 memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
70 sizeof (submodule->pp_shortcuts));
72 submodule->psz_object_name = strdup( module->psz_object_name );
73 submodule->psz_shortname = module->psz_shortname;
74 submodule->psz_longname = module->psz_longname;
75 submodule->psz_capability = module->psz_capability;
76 submodule->i_score = module->i_score;
77 submodule->i_cpu = module->i_cpu;
82 int vlc_module_set (module_t *module, int propid, void *value)
86 case VLC_MODULE_CPU_REQUIREMENT:
87 assert (!module->b_submodule);
88 module->i_cpu |= (intptr_t)value;
91 case VLC_MODULE_SHORTCUT:
94 for (i = 0; module->pp_shortcuts[i] != NULL; i++);
95 if (i >= (MODULE_SHORTCUT_MAX - 1))
98 module->pp_shortcuts[i] = (char *)value;
102 case VLC_MODULE_SHORTNAME:
103 module->psz_shortname = (char *)value;
106 case VLC_MODULE_DESCRIPTION:
107 module->psz_longname = (char *)value;
110 case VLC_MODULE_HELP:
111 module->psz_help = (char *)value;
114 case VLC_MODULE_CAPABILITY:
115 module->psz_capability = (char *)value;
118 case VLC_MODULE_SCORE:
119 module->i_score = (intptr_t)value;
122 case VLC_MODULE_CB_OPEN:
123 module->pf_activate = (int (*) (vlc_object_t *))value;
126 case VLC_MODULE_CB_CLOSE:
127 module->pf_deactivate = (void (*) (vlc_object_t *))value;
130 case VLC_MODULE_UNLOADABLE:
131 module->b_unloadable = (value != NULL);
134 case VLC_MODULE_NAME:
135 free( module->psz_object_name );
136 module->psz_object_name = strdup( (char *)value );
137 module->pp_shortcuts[0] = (char *)value;
138 if (module->psz_longname == default_name)
139 module->psz_longname = (char *)value;
142 case VLC_MODULE_PROGRAM:
143 msg_Warn (module, "deprecated module property %d", propid);
147 msg_Err (module, "unknown module property %d", propid);
148 msg_Err (module, "LibVLC might be too old to use this module.");
154 module_config_t *vlc_config_create (module_t *module, int type)
156 unsigned confsize = module->confsize;
157 module_config_t *tab = module->p_config;
159 if ((confsize & 0xf) == 0)
161 tab = realloc (tab, (confsize + 17) * sizeof (*tab));
165 module->p_config = tab;
168 memset (tab + confsize, 0, sizeof (tab[confsize]));
169 tab[confsize].i_type = type;
170 tab[confsize].p_lock = &module->object_lock;
172 if (type & CONFIG_ITEM)
174 module->i_config_items++;
175 if (type == CONFIG_ITEM_BOOL)
176 module->i_bool_items++;
180 return tab + confsize;
183 int vlc_config_set (module_config_t *restrict item, int id, ...)
188 assert (item != NULL);
193 case VLC_CONFIG_NAME:
195 const char *name = va_arg (ap, const char *);
196 vlc_callback_t cb = va_arg (ap, vlc_callback_t);
198 assert (name != NULL);
199 item->psz_name = strdup (name);
200 item->pf_callback = cb;
205 case VLC_CONFIG_DESC:
207 const char *text = va_arg (ap, const char *);
208 const char *longtext = va_arg (ap, const char *);
210 item->psz_text = text ? strdup ( _(text)) : NULL;
211 item->psz_longtext = longtext ? strdup ( _(longtext)) : NULL;
216 case VLC_CONFIG_VALUE:
218 if (IsConfigIntegerType (item->i_type))
220 item->orig.i = item->saved.i =
221 item->value.i = va_arg (ap, int);
225 if (IsConfigFloatType (item->i_type))
227 item->orig.f = item->saved.f =
228 item->value.f = va_arg (ap, double);
232 if (IsConfigStringType (item->i_type))
234 const char *value = va_arg (ap, const char *);
235 item->value.psz = value ? strdup (value) : NULL;
236 item->orig.psz = value ? strdup (value) : NULL;
237 item->saved.psz = value ? strdup (value) : NULL;
243 case VLC_CONFIG_RANGE:
245 if (IsConfigIntegerType (item->i_type))
247 item->min.i = va_arg (ap, int);
248 item->max.i = va_arg (ap, int);
252 if (IsConfigFloatType (item->i_type))
254 item->min.f = va_arg (ap, double);
255 item->max.f = va_arg (ap, double);
261 case VLC_CONFIG_ADVANCED:
262 item->b_advanced = true;
266 case VLC_CONFIG_VOLATILE:
267 item->b_unsaveable = true;
271 case VLC_CONFIG_PERSISTENT:
272 item->b_autosave = true;
276 case VLC_CONFIG_RESTART:
277 item->b_restart = true;
281 case VLC_CONFIG_PRIVATE:
282 item->b_internal = true;
286 case VLC_CONFIG_REMOVED:
287 item->b_removed = true;
291 case VLC_CONFIG_CAPABILITY:
293 const char *cap = va_arg (ap, const char *);
294 item->psz_type = cap ? strdup (cap) : NULL;
299 case VLC_CONFIG_SHORTCUT:
300 item->i_short = va_arg (ap, int);
304 case VLC_CONFIG_LIST:
306 size_t len = va_arg (ap, size_t);
307 char **dtext = malloc (sizeof (char *) * (len + 1));
313 if (IsConfigIntegerType (item->i_type))
315 const int *src = va_arg (ap, const int *);
316 int *dst = malloc (sizeof (int) * (len + 1));
320 memcpy (dst, src, sizeof (int) * len);
327 if (IsConfigFloatType (item->i_type))
329 const float *src = va_arg (ap, const float *);
330 float *dst = malloc (sizeof (float) * (len + 1));
334 memcpy (dst, src, sizeof (float) * len);
341 if (IsConfigStringType (item->i_type))
343 const char *const *src = va_arg (ap, const char *const *);
344 char **dst = malloc (sizeof (char *) * (len + 1));
348 for (size_t i = 0; i < len; i++)
349 dst[i] = src[i] ? strdup (src[i]) : NULL;
352 item->ppsz_list = dst;
357 /* Copy textual descriptions */
358 const char *const *text = va_arg (ap, const char *const *);
361 for (size_t i = 0; i < len; i++)
362 dtext[i] = text[i] ? strdup ( _(text[i])) : NULL;
365 item->ppsz_list_text = dtext;
370 item->ppsz_list_text = NULL;
374 item->pf_update_list = va_arg (ap, vlc_callback_t);
379 case VLC_CONFIG_ADD_ACTION:
381 vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb;
382 const char *name = va_arg (ap, const char *);
385 tabcb = realloc (item->ppf_action,
386 (item->i_action + 2) * sizeof (cb));
389 item->ppf_action = tabcb;
390 tabcb[item->i_action] = cb;
391 tabcb[item->i_action + 1] = NULL;
393 tabtext = realloc (item->ppsz_action_text,
394 (item->i_action + 2) * sizeof (name));
397 item->ppsz_action_text = tabtext;
400 tabtext[item->i_action] = strdup ( _(name));
402 tabtext[item->i_action] = NULL;
403 tabtext[item->i_action + 1] = NULL;
410 case VLC_CONFIG_OLDNAME:
412 const char *oldname = va_arg (ap, const char *);
413 item->psz_oldname = oldname ? strdup (oldname) : NULL;
418 case VLC_CONFIG_SAFE: