Last active
September 30, 2016 17:22
-
-
Save arteymix/567d7726c8b419ffc533fbe006ca6a62 to your computer and use it in GitHub Desktop.
Layout for a typical GLib.TypeModule implementation (replace `Simple` by the name of your class/interface)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GLib; | |
[ModuleInit] | |
public Type simple_init (TypeModule type_module) | |
{ | |
return typeof (CustomSimple); | |
} | |
public class CustomSimple : Simple | |
{ | |
// TODO: implementation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GLib; | |
public delegate Type SimpleInitFunc (TypeModule type_module); | |
public class SimpleModule : TypeModule | |
{ | |
public string? directory { get; construct; } | |
public string name { get; construct; } | |
public string path { get; construct; } | |
public Type simple_type { get; private set; } | |
private Module? module; | |
public SimpleModule (string? directory, string name) | |
{ | |
Object (directory: directory, name: name); | |
} | |
construct | |
{ | |
path = Module.build_path (directory, "simple-%s".printf (name)); | |
} | |
public override bool load () | |
{ | |
module = Module.open (path, ModuleFlags.BIND_LAZY); | |
if (module == null) | |
{ | |
critical (Module.error ()); | |
return false; | |
} | |
void* func; | |
if (!module.symbol ("simple_init", out func)) | |
{ | |
critical (Module.error ()); | |
return false; | |
} | |
if (func == null) | |
{ | |
critical ("No registration function was found in '%s'.", path); | |
return false; | |
} | |
simple_type = ((SimpleInitFunc) func) (this); | |
if (!simple_type.is_a (typeof (Simple))) | |
{ | |
critical ("The registration function must return a type derived from '%s'", typeof (Simple).name ()); | |
return false; | |
} | |
return true; | |
} | |
public override void unload () | |
{ | |
module = null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Simple | |
{ | |
// TODO: interface | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment