Czech translation update (via transifex.net)
[cinaest] / src / plugin-registrar.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
5  * Cinaest is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Cinaest is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 public class PluginRegistrar<T> : GLibFix.TypeModule {
20         public string path { get; construct; }
21
22         private Type type;
23         private Module module;
24
25         private delegate Type RegisterPluginFunction (GLibFix.TypeModule module);
26
27         construct {
28                 assert (Module.supported ());
29         }
30
31         public PluginRegistrar (string _path) {
32                 Object (path: _path);
33         }
34
35         public override bool load () {
36                 stdout.printf ("Loading plugin with path: '%s'\n", path);
37
38                 module = Module.open (path, ModuleFlags.BIND_LAZY);
39                 if (module == null) {
40                         return false;
41                 }
42
43                 stdout.printf ("Loaded module: '%s'\n", module.name ());
44
45                 void* function;
46                 module.symbol ("register_plugin", out function);
47                 RegisterPluginFunction register_plugin = (RegisterPluginFunction) function;
48
49                 type = register_plugin (this);
50                 stdout.printf ("Plugin type: %s\n\n", type.name ());
51
52                 // So it doesn't vanish as soon as the registar goes
53                 module.make_resident ();
54
55                 return true;
56         }
57
58         public override void unload () {
59         }
60
61         public T new_object () {
62                 return Object.new (type);
63         }
64 }
65