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 *****************************************************************************/
26 #include <vlc_common.h>
27 #include <vlc_plugin.h>
31 #include "modules/modules.h"
32 #include "config/configuration.h"
35 # define dgettext(d, m) ((char *)(m))
38 static const char default_name[] = "unnamed";
40 module_t *vlc_module_create (vlc_object_t *obj)
43 (module_t *)vlc_custom_create (obj, sizeof (module_t),
44 VLC_OBJECT_MODULE, "module");
48 module->b_reentrant = module->b_unloadable = true;
49 module->psz_object_name = strdup( default_name );
50 module->psz_longname = default_name;
51 module->psz_capability = (char*)"";
53 module->i_config_items = module->i_bool_items = 0;
59 module_t *vlc_submodule_create (module_t *module)
61 assert (module != NULL);
62 assert (!module->b_submodule); // subsubmodules are not supported
65 (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
66 VLC_OBJECT_MODULE, "submodule");
67 if (submodule == NULL)
70 vlc_object_attach (submodule, module);
71 submodule->b_submodule = true;
73 /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
74 memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
75 sizeof (submodule->pp_shortcuts));
77 submodule->psz_object_name = strdup( module->psz_object_name );
78 submodule->psz_shortname = module->psz_shortname;
79 submodule->psz_longname = module->psz_longname;
80 submodule->psz_capability = module->psz_capability;
81 submodule->i_score = module->i_score;
82 submodule->i_cpu = module->i_cpu;
87 int vlc_module_set (module_t *module, int propid, ...)
90 int ret = VLC_SUCCESS;
92 va_start (ap, propid);
95 case VLC_MODULE_CPU_REQUIREMENT:
96 assert (!module->b_submodule);
97 module->i_cpu |= va_arg (ap, int);
100 case VLC_MODULE_SHORTCUT:
103 for (i = 0; module->pp_shortcuts[i] != NULL; i++);
104 if (i >= (MODULE_SHORTCUT_MAX - 1))
110 module->pp_shortcuts[i] = va_arg (ap, char *);
114 case VLC_MODULE_SHORTNAME_NODOMAIN:
116 const char *name = va_arg (ap, char *);
117 ret = vlc_module_set (module, VLC_MODULE_SHORTNAME, NULL, name);
121 case VLC_MODULE_DESCRIPTION_NODOMAIN:
123 const char *desc = va_arg (ap, char *);
124 ret = vlc_module_set (module, VLC_MODULE_DESCRIPTION, NULL, desc);
128 case VLC_MODULE_HELP_NODOMAIN:
130 const char *help = va_arg (ap, char *);
131 ret = vlc_module_set (module, VLC_MODULE_HELP, NULL, help);
135 case VLC_MODULE_CAPABILITY:
136 module->psz_capability = va_arg (ap, char *);
139 case VLC_MODULE_SCORE:
140 module->i_score = va_arg (ap, int);
143 case VLC_MODULE_PROGRAM:
144 msg_Warn (module, "deprecated module property %d", propid);
147 case VLC_MODULE_CB_OPEN:
148 module->pf_activate = va_arg (ap, int (*) (vlc_object_t *));
151 case VLC_MODULE_CB_CLOSE:
152 module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *));
155 case VLC_MODULE_NO_UNLOAD:
156 module->b_unloadable = false;
159 case VLC_MODULE_NAME:
161 const char *value = va_arg (ap, const char *);
162 free( module->psz_object_name );
163 module->psz_object_name = strdup( value );
164 module->pp_shortcuts[0] = value;
165 if (module->psz_longname == default_name)
166 module->psz_longname = value;
170 case VLC_MODULE_SHORTNAME:
172 const char *domain = va_arg (ap, const char *);
175 module->psz_shortname = dgettext (domain, va_arg (ap, char *));
179 case VLC_MODULE_DESCRIPTION:
181 const char *domain = va_arg (ap, const char *);
184 module->psz_longname = dgettext (domain, va_arg (ap, char *));
188 case VLC_MODULE_HELP:
190 const char *domain = va_arg (ap, const char *);
193 module->psz_help = dgettext (domain, va_arg (ap, char *));
198 msg_Err (module, "unknown module property %d", propid);
199 msg_Err (module, "LibVLC might be too old to use this module.");
207 module_config_t *vlc_config_create (module_t *module, int type)
209 unsigned confsize = module->confsize;
210 module_config_t *tab = module->p_config;
212 if ((confsize & 0xf) == 0)
214 tab = realloc (tab, (confsize + 17) * sizeof (*tab));
218 module->p_config = tab;
221 memset (tab + confsize, 0, sizeof (tab[confsize]));
222 tab[confsize].i_type = type;
223 tab[confsize].p_lock = &(vlc_internals(module)->lock);
225 if (type & CONFIG_ITEM)
227 module->i_config_items++;
228 if (type == CONFIG_ITEM_BOOL)
229 module->i_bool_items++;
233 return tab + confsize;
236 int vlc_config_set (module_config_t *restrict item, int id, ...)
241 assert (item != NULL);
246 case VLC_CONFIG_NAME:
248 const char *name = va_arg (ap, const char *);
249 vlc_callback_t cb = va_arg (ap, vlc_callback_t);
251 assert (name != NULL);
252 item->psz_name = strdup (name);
253 item->pf_callback = cb;
258 case VLC_CONFIG_DESC_NODOMAIN:
260 const char *text = va_arg (ap, const char *);
261 const char *longtext = va_arg (ap, const char *);
262 ret = vlc_config_set (item, VLC_CONFIG_DESC, NULL, text, longtext);
266 case VLC_CONFIG_VALUE:
268 if (IsConfigIntegerType (item->i_type))
270 item->orig.i = item->saved.i =
271 item->value.i = va_arg (ap, int);
275 if (IsConfigFloatType (item->i_type))
277 item->orig.f = item->saved.f =
278 item->value.f = va_arg (ap, double);
282 if (IsConfigStringType (item->i_type))
284 const char *value = va_arg (ap, const char *);
285 item->value.psz = value ? strdup (value) : NULL;
286 item->orig.psz = value ? strdup (value) : NULL;
287 item->saved.psz = value ? strdup (value) : NULL;
293 case VLC_CONFIG_RANGE:
295 if (IsConfigIntegerType (item->i_type))
297 item->min.i = va_arg (ap, int);
298 item->max.i = va_arg (ap, int);
302 if (IsConfigFloatType (item->i_type))
304 item->min.f = va_arg (ap, double);
305 item->max.f = va_arg (ap, double);
311 case VLC_CONFIG_ADVANCED:
312 item->b_advanced = true;
316 case VLC_CONFIG_VOLATILE:
317 item->b_unsaveable = true;
321 case VLC_CONFIG_PERSISTENT:
322 item->b_autosave = true;
326 case VLC_CONFIG_RESTART:
327 item->b_restart = true;
331 case VLC_CONFIG_PRIVATE:
332 item->b_internal = true;
336 case VLC_CONFIG_REMOVED:
337 item->b_removed = true;
341 case VLC_CONFIG_CAPABILITY:
343 const char *cap = va_arg (ap, const char *);
344 item->psz_type = cap ? strdup (cap) : NULL;
349 case VLC_CONFIG_SHORTCUT:
350 item->i_short = va_arg (ap, int);
354 case VLC_CONFIG_LIST_NODOMAIN:
356 size_t len = va_arg (ap, size_t);
357 if (IsConfigIntegerType (item->i_type))
359 const int *src = va_arg (ap, const int *);
360 const char *const *text = va_arg (ap, const char *const *);
361 ret = vlc_config_set (item, VLC_CONFIG_LIST, NULL, len, src,
365 if (IsConfigStringType (item->i_type))
367 const char *const *src = va_arg (ap, const char *const *);
368 const char *const *text = va_arg (ap, const char *const *);
369 ret = vlc_config_set (item, VLC_CONFIG_LIST, NULL, len, src,
375 case VLC_CONFIG_ADD_ACTION_NODOMAIN:
377 vlc_callback_t cb = va_arg (ap, vlc_callback_t);
378 const char *name = va_arg (ap, const char *);
379 ret = vlc_config_set (item, VLC_CONFIG_ADD_ACTION, NULL, cb, name);
383 case VLC_CONFIG_OLDNAME:
385 const char *oldname = va_arg (ap, const char *);
386 item->psz_oldname = oldname ? strdup (oldname) : NULL;
391 case VLC_CONFIG_SAFE:
396 case VLC_CONFIG_DESC:
398 const char *domain = va_arg (ap, const char *);
399 const char *text = va_arg (ap, const char *);
400 const char *longtext = va_arg (ap, const char *);
404 item->psz_text = text ? strdup (dgettext (domain, text)) : NULL;
406 longtext ? strdup (dgettext (domain, longtext)) : NULL;
411 case VLC_CONFIG_LIST:
413 const char *domain = va_arg (ap, const char *);
414 size_t len = va_arg (ap, size_t);
415 char **dtext = malloc (sizeof (char *) * (len + 1));
421 if (IsConfigIntegerType (item->i_type))
423 const int *src = va_arg (ap, const int *);
424 int *dst = malloc (sizeof (int) * (len + 1));
428 memcpy (dst, src, sizeof (int) * len);
435 if (IsConfigFloatType (item->i_type))
437 const float *src = va_arg (ap, const float *);
438 float *dst = malloc (sizeof (float) * (len + 1));
442 memcpy (dst, src, sizeof (float) * len);
449 if (IsConfigStringType (item->i_type))
451 const char *const *src = va_arg (ap, const char *const *);
452 char **dst = malloc (sizeof (char *) * (len + 1));
456 for (size_t i = 0; i < len; i++)
457 dst[i] = src[i] ? strdup (src[i]) : NULL;
460 item->ppsz_list = dst;
465 /* Copy textual descriptions */
469 const char *const *text = va_arg (ap, const char *const *);
472 for (size_t i = 0; i < len; i++)
474 text[i] ? strdup (dgettext (domain, text[i])) : NULL;
477 item->ppsz_list_text = dtext;
482 item->ppsz_list_text = NULL;
486 item->pf_update_list = va_arg (ap, vlc_callback_t);
491 case VLC_CONFIG_ADD_ACTION:
493 const char *domain = va_arg (ap, const char *);
494 vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb;
495 const char *name = va_arg (ap, const char *);
498 tabcb = realloc (item->ppf_action,
499 (item->i_action + 2) * sizeof (cb));
502 item->ppf_action = tabcb;
503 tabcb[item->i_action] = cb;
504 tabcb[item->i_action + 1] = NULL;
506 tabtext = realloc (item->ppsz_action_text,
507 (item->i_action + 2) * sizeof (name));
510 item->ppsz_action_text = tabtext;
515 tabtext[item->i_action] = strdup (dgettext (domain, name));
517 tabtext[item->i_action] = NULL;
518 tabtext[item->i_action + 1] = NULL;