1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
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.
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.
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/>.
19 public class PluginRegistrar<T> : Object {
20 public string path { get; construct; }
23 private Module module;
25 private delegate Type RegisterPluginFunction ();
28 assert (Module.supported ());
31 public PluginRegistrar (string _path) {
36 stdout.printf ("Loading plugin with path: '%s'\n", path);
38 module = Module.open (path, ModuleFlags.BIND_LAZY);
43 stdout.printf ("Loaded module: '%s'\n", module.name ());
46 module.symbol ("register_plugin", out function);
47 RegisterPluginFunction register_plugin = (RegisterPluginFunction) function;
49 type = register_plugin ();
50 stdout.printf ("Plugin type: %s\n\n", type.name ());
52 // So it doesn't vanish as soon as the registar goes
53 module.make_resident ();
58 public T new_object () {
59 return Object.new (type);