| 1 |
public class Foo.PluginModule : TypeModule { |
| 2 |
|
| 3 |
[CCode (has_target = false)] |
| 4 |
private delegate Type PluginInit (TypeModule type_module); |
| 5 |
|
| 6 |
public string? directory { get; construct; default = null; } |
| 7 |
|
| 8 |
public string name { get; construct; } |
| 9 |
|
| 10 |
public string path { get; construct; } |
| 11 |
|
| 12 |
public Type plugin_type { get; private set; } |
| 13 |
|
| 14 |
private Module? module = null; |
| 15 |
|
| 16 |
public PluginModule (string? directory, string name) { |
| 17 |
Object (directory: directory, name: name); |
| 18 |
} |
| 19 |
|
| 20 |
construct { |
| 21 |
path = Module.build_path (directory, name); |
| 22 |
} |
| 23 |
|
| 24 |
public override bool load () { |
| 25 |
module = Module.open (path, ModuleFlags.BIND_LAZY); |
| 26 |
|
| 27 |
if (module == null) { |
| 28 |
critical (Module.error ()); |
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
void* plugin_init; |
| 33 |
if (!module.symbol ("plugin_init", out plugin_init)){ |
| 34 |
critical (Module.error ()); |
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
if (plugin_init == null) { |
| 39 |
return false; |
| 40 |
} |
| 41 |
|
| 42 |
plugin_type = ((PluginInit) plugin_init) (this); |
| 43 |
|
| 44 |
if (!plugin_type.is_a (typeof (Plugin))) { |
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
public override void unload () { |
| 52 |
module = null; |
| 53 |
} |
| 54 |
} |