oups
[vlc.git] / src / modules / entry.c
blob8637987b2aba4a4df76e544825f5cc2d157ebcd6
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 *****************************************************************************/
21 #include <vlc/vlc.h>
22 #include <assert.h>
24 #include "modules/modules.h"
25 #include "libvlc.h"
27 static const char default_name[] = "unnamed";
29 module_t *vlc_module_create (vlc_object_t *obj)
31 module_t *module =
32 (module_t *)vlc_custom_create (obj, sizeof (module_t),
33 VLC_OBJECT_MODULE, "module");
34 if (module == NULL)
35 return NULL;
37 #ifndef HAVE_SHARED_LIBVLC
38 module->p_symbols = &obj->p_libvlc_global->p_module_bank->symbols;
39 #endif
40 module->b_reentrant = module->b_unloadable = VLC_TRUE;
41 module->psz_object_name = module->psz_longname = default_name;
42 module->pp_shortcuts[0] = default_name;
43 module->i_cpu = 0;
44 module->psz_capability = "";
45 module->i_score = 1;
46 return module;
50 module_t *vlc_submodule_create (module_t *module)
52 assert (module != NULL);
53 assert (!module->b_submodule); // subsubmodules are not supported
55 module_t *submodule =
56 (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
57 VLC_OBJECT_MODULE, "submodule");
58 if (submodule == NULL)
59 return NULL;
61 vlc_object_attach (submodule, module);
62 submodule->b_submodule = VLC_TRUE;
64 /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
65 memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
66 sizeof (submodule->pp_shortcuts));
68 submodule->psz_object_name = module->psz_object_name;
69 submodule->psz_shortname = module->psz_shortname;
70 submodule->psz_longname = module->psz_longname;
71 submodule->psz_program = module->psz_program;
72 submodule->psz_capability = module->psz_capability;
73 submodule->i_score = module->i_score;
74 submodule->i_cpu = module->i_cpu;
75 return submodule;
79 int vlc_module_set (module_t *module, int propid, void *value)
81 switch (propid)
83 case VLC_MODULE_CPU_REQUIREMENT:
84 assert (!module->b_submodule);
85 module->i_cpu |= (int)value;
86 break;
88 case VLC_MODULE_SHORTCUT:
90 unsigned i;
91 for (i = 0; module->pp_shortcuts[i] != NULL; i++);
92 if (i >= MODULE_SHORTCUT_MAX)
93 return VLC_ENOMEM;
95 module->pp_shortcuts[i] = (char *)value;
96 break;
99 case VLC_MODULE_SHORTNAME:
100 module->psz_shortname = (char *)value;
101 break;
103 case VLC_MODULE_DESCRIPTION:
104 module->psz_longname = (char *)value;
105 break;
107 case VLC_MODULE_HELP:
108 module->psz_help = (char *)value;
109 break;
111 case VLC_MODULE_CAPABILITY:
112 module->psz_capability = (char *)value;
113 break;
115 case VLC_MODULE_SCORE:
116 module->i_score = (int)value;
117 break;
119 case VLC_MODULE_PROGRAM:
120 module->psz_program = (char *)value;
121 break;
123 case VLC_MODULE_CB_OPEN:
124 module->pf_activate = (int (*) (vlc_object_t *))value;
125 break;
127 case VLC_MODULE_CB_CLOSE:
128 module->pf_deactivate = (void (*) (vlc_object_t *))value;
129 break;
131 case VLC_MODULE_UNLOADABLE:
132 module->b_unloadable = (value != NULL);
133 break;
135 case VLC_MODULE_NAME:
136 module->pp_shortcuts[0] = module->psz_object_name = (char *)value;
137 if (module->psz_longname == default_name)
138 module->psz_longname = (char *)value;
139 break;
141 default:
142 msg_Err (module, "unknown module property %d", propid);
143 msg_Err (module, "LibVLC might be too old to use this module.");
144 return VLC_EGENERIC;
146 return 0;