GObject-Plugin/test/loader_test/LoaderTest.vala

60 lines
1.8 KiB
Vala
Raw Normal View History

2014-09-19 11:04:31 +04:00
using GObject.Plugins;
static Gee.ArrayList<Module> type_a_modules = null;
static Gee.ArrayList<Module> type_b_modules = null;
2014-10-16 16:11:28 +04:00
class LoaderTestHost : Object, IHost, IHostLoaderTest {
public void method_host () {
stdout.puts ("LoaderTestHost.method_host () called\n");
}
}
2014-09-19 11:04:31 +04:00
int main (string [] args) {
2014-10-16 16:11:28 +04:00
var h = new LoaderTestHost ();
2014-09-19 11:04:31 +04:00
GObject.Plugins.load_modules (
Path.build_path (Path.DIR_SEPARATOR_S, File.new_for_path (
args[0]).get_parent ().get_parent ().get_path (), "test/plugins/typeA"),
ref type_a_modules
);
GObject.Plugins.load_modules (
Path.build_path (Path.DIR_SEPARATOR_S, File.new_for_path (
args[0]).get_parent ().get_parent ().get_path (), "test/plugins/typeB"),
ref type_b_modules
);
// Show Modules List
2014-10-16 16:11:28 +04:00
stdout.puts ("List Plugins:\n");
2014-09-19 11:04:31 +04:00
foreach (var m in type_a_modules) {
2014-10-16 16:11:28 +04:00
stdout.printf (" Name = " + m.get_plugin_type ().name () + "\n");
2014-09-19 11:04:31 +04:00
}
foreach (var m in type_b_modules) {
2014-10-16 16:11:28 +04:00
stdout.printf (" Name = " + m.get_plugin_type ().name () + "\n");
2014-09-19 11:04:31 +04:00
}
// Create a new Plugin Instance by Object.new () method
2014-10-16 16:11:28 +04:00
stdout.puts ("Creating PluginTypeA Object:\n ");
var a = type_a_modules[0].create_instance (h) as PluginTypeA;
stdout.puts ("Call a.method_a () from main app:\n ");
2014-09-19 11:04:31 +04:00
a.method_a ();
2014-10-16 16:11:28 +04:00
stdout.puts ("Destroing PluginTypeA Object:\n ");
a = null;
2014-09-19 11:04:31 +04:00
// Create a new Plugin Instance by Plugin Type
2014-10-16 16:11:28 +04:00
stdout.puts ("Creating PluginTypeB Object:\n ");
2014-09-19 11:04:31 +04:00
var b = GLib.Object.new (Type.from_name (type_b_modules[0].get_plugin_type ().name ())) as PluginTypeB;
2014-10-16 16:11:28 +04:00
b.host = h;
stdout.puts ("Call b.method_b () from main app:\n ");
stdout.puts (" Returned String: " + b.method_b () + "\n");
stdout.puts ("Destroing PluginTypeB Object:\n ");
b = null;
2014-09-19 11:04:31 +04:00
2014-10-16 16:11:28 +04:00
// Unload modules
2014-09-19 11:04:31 +04:00
GObject.Plugins.unload_modules (type_a_modules);
GObject.Plugins.unload_modules (type_b_modules);
return 0;
}