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 = "";
47 module_t *vlc_submodule_create (module_t *module)
49 assert (module != NULL);
50 assert (!module->b_submodule); // subsubmodules are not supported
53 (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
54 VLC_OBJECT_MODULE, "submodule");
55 if (submodule == NULL)
58 vlc_object_attach (submodule, module);
59 submodule->b_submodule = VLC_TRUE;
61 /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
62 memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
63 sizeof (submodule->pp_shortcuts));
65 submodule->psz_object_name = module->psz_object_name;
66 submodule->psz_shortname = module->psz_shortname;
67 submodule->psz_longname = module->psz_longname;
68 submodule->psz_capability = module->psz_capability;
69 submodule->i_score = module->i_score;
70 submodule->i_cpu = module->i_cpu;
75 int vlc_module_set (module_t *module, int propid, void *value)
79 case VLC_MODULE_CPU_REQUIREMENT:
80 assert (!module->b_submodule);
81 module->i_cpu |= (intptr_t)value;
84 case VLC_MODULE_SHORTCUT:
87 for (i = 0; module->pp_shortcuts[i] != NULL; i++);
88 if (i >= (MODULE_SHORTCUT_MAX - 1))
91 module->pp_shortcuts[i] = (char *)value;
95 case VLC_MODULE_SHORTNAME:
96 module->psz_shortname = (char *)value;
99 case VLC_MODULE_DESCRIPTION:
100 module->psz_longname = (char *)value;
103 case VLC_MODULE_HELP:
104 module->psz_help = (char *)value;
107 case VLC_MODULE_CAPABILITY:
108 module->psz_capability = (char *)value;
111 case VLC_MODULE_SCORE:
112 module->i_score = (intptr_t)value;
115 case VLC_MODULE_CB_OPEN:
116 module->pf_activate = (int (*) (vlc_object_t *))value;
119 case VLC_MODULE_CB_CLOSE:
120 module->pf_deactivate = (void (*) (vlc_object_t *))value;
123 case VLC_MODULE_UNLOADABLE:
124 module->b_unloadable = (value != NULL);
127 case VLC_MODULE_NAME:
128 module->pp_shortcuts[0] = module->psz_object_name = (char *)value;
129 if (module->psz_longname == default_name)
130 module->psz_longname = (char *)value;
133 case VLC_MODULE_PROGRAM:
134 msg_Warn (module, "deprecated module property %d", propid);
138 msg_Err (module, "unknown module property %d", propid);
139 msg_Err (module, "LibVLC might be too old to use this module.");
145 module_config_t *vlc_config_create (module_t *module, int type)
147 unsigned confsize = module->confsize;
148 module_config_t *tab = module->p_config;
150 if ((confsize & 0xf) == 0)
152 tab = realloc (tab, (confsize + 17) * sizeof (*tab));
156 module->p_config = tab;
160 memset (tab + confsize, 0, sizeof (tab[confsize]));
161 return tab + confsize;
164 int vlc_config_set (module_config_t *restrict item, int id, ...)
169 assert (item != NULL);
174 case VLC_CONFIG_NAME:
176 const char *name = va_arg (ap, const char *);
177 vlc_callback_t cb = va_arg (ap, vlc_callback_t);
179 assert (name != NULL);
180 item->psz_name = strdup (name);
181 item->pf_callback = cb;
186 case VLC_CONFIG_DESC:
188 const char *text = va_arg (ap, const char *);
189 const char *longtext = va_arg (ap, const char *);
191 item->psz_text = text ? strdup (gettext (text)) : NULL;
192 item->psz_longtext = longtext ? strdup (gettext (text)) : NULL;
197 case VLC_CONFIG_VALUE:
199 if (IsConfigIntegerType (item->i_type))
201 item->orig.i = item->saved.i =
202 item->value.i = va_arg (ap, int);
206 if (IsConfigFloatType (item->i_type))
208 item->orig.f = item->saved.f =
209 item->value.f = va_arg (ap, double);
213 if (IsConfigStringType (item->i_type))
215 const char *value = va_arg (ap, const char *);
216 item->value.psz = value ? strdup (value) : NULL;
217 item->orig.psz = value ? strdup (value) : NULL;
218 item->saved.psz = value ? strdup (value) : NULL;
224 case VLC_CONFIG_RANGE:
226 if (IsConfigIntegerType (item->i_type))
228 item->min.i = va_arg (ap, int);
229 item->max.i = va_arg (ap, int);
233 if (IsConfigFloatType (item->i_type))
235 item->min.f = va_arg (ap, double);
236 item->max.f = va_arg (ap, double);
242 case VLC_CONFIG_ADVANCED:
243 item->b_advanced = VLC_TRUE;
247 case VLC_CONFIG_VOLATILE:
248 item->b_unsaveable = VLC_TRUE;
252 case VLC_CONFIG_PERSISTENT:
253 item->b_autosave = VLC_TRUE;
257 case VLC_CONFIG_RESTART:
258 item->b_restart = VLC_TRUE;
262 case VLC_CONFIG_PRIVATE:
263 item->b_internal = VLC_TRUE;
267 case VLC_CONFIG_REMOVED:
268 item->psz_current = "SUPPRESSED";
272 case VLC_CONFIG_CAPABILITY:
274 const char *cap = va_arg (ap, const char *);
275 item->psz_type = cap ? strdup (cap) : NULL;