]> git.sesse.net Git - vlc/blob - src/modules/entry.c
* add missing includes (trying to fix compilation errors in buildbot :D)
[vlc] / src / modules / entry.c
1 /*****************************************************************************
2  * entry.c : Callbacks for module entry point
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 #include <vlc/vlc.h>
22 #include <assert.h>
23
24 #include "modules/modules.h"
25 #include "libvlc.h"
26 #include "../libvlc.h"
27
28 static const char default_name[] = "unnamed";
29
30 module_t *vlc_module_create (vlc_object_t *obj)
31 {
32     module_t *module =
33         (module_t *)vlc_custom_create (obj, sizeof (module_t),
34                                        VLC_OBJECT_MODULE, "module");
35     if (module == NULL)
36         return NULL;
37
38 #ifndef HAVE_SHARED_LIBVLC
39     module->p_symbols = &vlc_global( obj )->p_module_bank->symbols;
40 #endif
41     module->b_reentrant = module->b_unloadable = VLC_TRUE;
42     module->psz_object_name = module->psz_longname = default_name;
43     module->pp_shortcuts[0] = default_name;
44     module->i_cpu = 0;
45     module->psz_capability = "";
46     module->i_score = 1;
47     return module;
48 }
49
50
51 module_t *vlc_submodule_create (module_t *module)
52 {
53     assert (module != NULL);
54     assert (!module->b_submodule); // subsubmodules are not supported
55
56     module_t *submodule =
57         (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t),
58                                        VLC_OBJECT_MODULE, "submodule");
59     if (submodule == NULL)
60         return NULL;
61
62     vlc_object_attach (submodule, module);
63     submodule->b_submodule = VLC_TRUE;
64
65     /* Muahahaha! Heritage! Polymorphism! Ugliness!! */
66     memcpy (submodule->pp_shortcuts, module->pp_shortcuts,
67             sizeof (submodule->pp_shortcuts));
68
69     submodule->psz_object_name = module->psz_object_name;
70     submodule->psz_shortname = module->psz_shortname;
71     submodule->psz_longname = module->psz_longname;
72     submodule->psz_program = module->psz_program;
73     submodule->psz_capability = module->psz_capability;
74     submodule->i_score = module->i_score;
75     submodule->i_cpu = module->i_cpu;
76     return submodule;
77 }
78
79
80 int vlc_module_set (module_t *module, int propid, void *value)
81 {
82     switch (propid)
83     {
84         case VLC_MODULE_CPU_REQUIREMENT:
85             assert (!module->b_submodule);
86             module->i_cpu |= (int)value;
87             break;
88
89         case VLC_MODULE_SHORTCUT:
90         {
91             unsigned i;
92             for (i = 0; module->pp_shortcuts[i] != NULL; i++);
93             if (i >= MODULE_SHORTCUT_MAX)
94                 return VLC_ENOMEM;
95
96             module->pp_shortcuts[i] = (char *)value;
97             break;
98         }
99
100         case VLC_MODULE_SHORTNAME:
101             module->psz_shortname = (char *)value;
102             break;
103
104         case VLC_MODULE_DESCRIPTION:
105             module->psz_longname = (char *)value;
106             break;
107
108         case VLC_MODULE_HELP:
109             module->psz_help = (char *)value;
110             break;
111
112         case VLC_MODULE_CAPABILITY:
113             module->psz_capability = (char *)value;
114             break;
115
116         case VLC_MODULE_SCORE:
117             module->i_score = (int)value;
118             break;
119
120         case VLC_MODULE_PROGRAM:
121             module->psz_program = (char *)value;
122             break;
123
124         case VLC_MODULE_CB_OPEN:
125             module->pf_activate = (int (*) (vlc_object_t *))value;
126             break;
127
128         case VLC_MODULE_CB_CLOSE:
129             module->pf_deactivate = (void (*) (vlc_object_t *))value;
130             break;
131
132         case VLC_MODULE_UNLOADABLE:
133             module->b_unloadable = (value != NULL);
134             break;
135
136         case VLC_MODULE_NAME:
137             module->pp_shortcuts[0] = module->psz_object_name = (char *)value;
138             if (module->psz_longname == default_name)
139                 module->psz_longname = (char *)value;
140             break;
141
142         default:
143             msg_Err (module, "unknown module property %d", propid);
144             msg_Err (module, "LibVLC might be too old to use this module.");
145             return VLC_EGENERIC;
146     }
147     return 0;
148 }