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