diff --git a/src/host-iface/CMakeLists.txt b/src/host-iface/CMakeLists.txt index e69de29..787d66f 100644 --- a/src/host-iface/CMakeLists.txt +++ b/src/host-iface/CMakeLists.txt @@ -0,0 +1,6 @@ +SET (LibName ${PROJECT_LOWERCASE_NAME}-host-iface) +FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} HostInterface.vala) +SET (LibPackages gee-0.8 gmodule-2.0 gio-2.0) +SET (LibExtraSources ${PROJECT_SOURCE_DIR}/src/library_constructor.c) +SET (LibInstall ON) +INCLUDE (ValaLibCommonRules) diff --git a/src/host-iface/HostInterface.vala b/src/host-iface/HostInterface.vala new file mode 100644 index 0000000..b73f0ef --- /dev/null +++ b/src/host-iface/HostInterface.vala @@ -0,0 +1,23 @@ +/** + * GObject Models. + */ +namespace GObject { + + /** + * Modules/Plugins. + */ + namespace Plugins { + + /** + * Host interface. + */ + public interface IHost : Object { + } + + /** + * Abstract Host. + */ + public abstract class Host : Object, IHost { + } + } +} diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt index ce15a24..777f917 100644 --- a/src/loader/CMakeLists.txt +++ b/src/loader/CMakeLists.txt @@ -1,9 +1,13 @@ SET (LibName ${PROJECT_LOWERCASE_NAME}-loader) FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} PluginLoader.vala) SET (LibPackages gee-0.8 gmodule-2.0 gio-2.0) -SET (LibCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi) +SET (LibCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi +) SET (LibExtraSources ${PROJECT_SOURCE_DIR}/src/library_constructor.c) SET (LibInstall ON) -SET (LibLinkLibs ${PROJECT_LOWERCASE_NAME}-iface) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface") +SET (LibLinkLibs ${PROJECT_LOWERCASE_NAME}-iface ${PROJECT_LOWERCASE_NAME}-host-iface) +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" +) INCLUDE (ValaLibCommonRules) diff --git a/src/loader/PluginLoader.vala b/src/loader/PluginLoader.vala index 8894b6e..781c403 100644 --- a/src/loader/PluginLoader.vala +++ b/src/loader/PluginLoader.vala @@ -68,8 +68,10 @@ namespace GObject { /** * Creates Plugin instance from the module. */ - public Plugin create_instance () { - return Object.new (type) as Plugin; + public Plugin create_instance (IHost ihost) { + var p = Object.new (type) as Plugin; + p.host = ihost; + return p; } } diff --git a/src/plugin-iface/CMakeLists.txt b/src/plugin-iface/CMakeLists.txt index da0f6a1..a897521 100644 --- a/src/plugin-iface/CMakeLists.txt +++ b/src/plugin-iface/CMakeLists.txt @@ -1,6 +1,9 @@ SET (LibName ${PROJECT_LOWERCASE_NAME}-iface) FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} PluginInterface.vala) SET (LibPackages gee-0.8 gmodule-2.0 gio-2.0) +SET (LibCustomVapis ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi) SET (LibExtraSources ${PROJECT_SOURCE_DIR}/src/library_constructor.c) SET (LibInstall ON) +SET (LibLinkLibs ${PROJECT_LOWERCASE_NAME}-host-iface) +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/host-iface") INCLUDE (ValaLibCommonRules) diff --git a/src/plugin-iface/PluginInterface.vala b/src/plugin-iface/PluginInterface.vala index a79e2d2..3e25a25 100644 --- a/src/plugin-iface/PluginInterface.vala +++ b/src/plugin-iface/PluginInterface.vala @@ -18,6 +18,11 @@ namespace GObject { * Abstract Plugin. */ public abstract class Plugin : Object, IPlugabble { + + /** + * Host Interface. + */ + public IHost host = null; } } } diff --git a/test/loader_test-iface/CMakeLists.txt b/test/loader_test-iface/CMakeLists.txt index 7d1e8a3..02b4fca 100644 --- a/test/loader_test-iface/CMakeLists.txt +++ b/test/loader_test-iface/CMakeLists.txt @@ -1,6 +1,10 @@ SET (LibName loader_test-iface) FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} LoaderTestInterface.vala) -SET (LibCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi) +SET (LibCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi +) SET (LibLinkLibs gobject-plugin-iface) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface") +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" +) INCLUDE (ValaLibCommonRules) diff --git a/test/loader_test-iface/LoaderTestInterface.vala b/test/loader_test-iface/LoaderTestInterface.vala index f11129b..ab347a4 100644 --- a/test/loader_test-iface/LoaderTestInterface.vala +++ b/test/loader_test-iface/LoaderTestInterface.vala @@ -1,15 +1,25 @@ using GObject.Plugins; +/** + * Loader Host Interface. + */ +public interface IHostLoaderTest : IHost { + + /** + * Any Host Method. + */ + public abstract void method_host (); +} + /** * Abstract plugin of type A. */ public abstract class PluginTypeA: Plugin { /** - * Any virtual method for PluginTypeA. + * Any abstract method for PluginTypeA. */ - [CCode (has_target = false)] - public virtual void method_a () { } + public abstract void method_a (); } /** @@ -18,7 +28,7 @@ public abstract class PluginTypeA: Plugin { public abstract class PluginTypeB : Plugin { /** - * Any virtual method for PluginTypeB. + * Any abstract method for PluginTypeB. */ - public virtual string method_b () { return ""; } + public abstract string method_b (); } diff --git a/test/loader_test/CMakeLists.txt b/test/loader_test/CMakeLists.txt index b1287f7..4624fed 100644 --- a/test/loader_test/CMakeLists.txt +++ b/test/loader_test/CMakeLists.txt @@ -4,11 +4,18 @@ SET (BinPackages gee-0.8 gio-2.0) SET (BinCustomVapis ${CMAKE_BINARY_DIR}/src/loader/${PROJECT_LOWERCASE_NAME}-loader-${MAJOR}.vapi ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi ${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi ) -SET (BinLinkLibs ${PROJECT_LOWERCASE_NAME}-loader ${PROJECT_LOWERCASE_NAME}-iface loader_test-iface +SET (BinLinkLibs ${PROJECT_LOWERCASE_NAME}-loader + ${PROJECT_LOWERCASE_NAME}-iface + ${PROJECT_LOWERCASE_NAME}-host-iface + loader_test-iface +) +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/loader" + "${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/test/loader_test-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" ) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/loader" "${CMAKE_BINARY_DIR}/src/plugin-iface" -"${CMAKE_BINARY_DIR}/test/loader_test-iface") INCLUDE (ValaBinCommonRules) # Plugin Loading Test @@ -21,17 +28,26 @@ ENDMACRO (plugin_loading_test) # Testing Plugin:[de]init() and Library unload() plugin_loading_test (SimpleLoaderTest -"Plugin Type Name = TypeA1 -Plugin Type Name = TypeA2 -Plugin Type Name = TypeB1 -Plugin Type Name = TypeB2 -TypeA1 init -TypeA1.method_a \\\\(\\\\) called -TypeA1 deinit -TypeB1 init -TypeB1.method_b \\\\(\\\\) called -TypeB1 returned string -TypeB1 deinit" +"List Plugins: + Name = TypeA1 + Name = TypeA2 + Name = TypeB1 + Name = TypeB2 +Creating PluginTypeA Object: + TypeA1 init \\\\(\\\\) called +Call a.method_a \\\\(\\\\) from main app: + TypeA1.method_a \\\\(\\\\) called +Call IHostLoaderTest.method_host \\\\(\\\\) from TypeA1: + LoaderTestHost.method_host \\\\(\\\\) called +Destroing PluginTypeA Object: + TypeA1 deinit \\\\(\\\\) called +Creating PluginTypeB Object: + TypeB1 init \\\\(\\\\) called +Call b.method_b \\\\(\\\\) from main app: + TypeB1.method_b \\\\(\\\\) called + Returned String: TypeB1 returned string +Destroing PluginTypeB Object: + TypeB1 deinit \\\\(\\\\) called" ) SET_TESTS_PROPERTIES(loader_test-SimpleLoaderTest PROPERTIES ENVIRONMENT "LANG=en") diff --git a/test/loader_test/LoaderTest.vala b/test/loader_test/LoaderTest.vala index 8cda1e7..7bdfbf3 100644 --- a/test/loader_test/LoaderTest.vala +++ b/test/loader_test/LoaderTest.vala @@ -3,8 +3,16 @@ using GObject.Plugins; static Gee.ArrayList type_a_modules = null; static Gee.ArrayList type_b_modules = null; +class LoaderTestHost : Object, IHost, IHostLoaderTest { + public void method_host () { + stdout.puts ("LoaderTestHost.method_host () called\n"); + } +} + int main (string [] args) { + var h = new LoaderTestHost (); + 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"), @@ -18,23 +26,32 @@ int main (string [] args) { ); // Show Modules List + stdout.puts ("List Plugins:\n"); foreach (var m in type_a_modules) { - stdout.printf ("Plugin Type Name = " + m.get_plugin_type ().name () + "\n"); + stdout.printf (" Name = " + m.get_plugin_type ().name () + "\n"); } foreach (var m in type_b_modules) { - stdout.printf ("Plugin Type Name = " + m.get_plugin_type ().name () + "\n"); + stdout.printf (" Name = " + m.get_plugin_type ().name () + "\n"); } // Create a new Plugin Instance by Object.new () method - var a = type_a_modules[0].create_instance () as PluginTypeA; + 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 "); a.method_a (); - a = null; // free last instance, plugin unload + stdout.puts ("Destroing PluginTypeA Object:\n "); + a = null; // Create a new Plugin Instance by Plugin Type + stdout.puts ("Creating PluginTypeB Object:\n "); var b = GLib.Object.new (Type.from_name (type_b_modules[0].get_plugin_type ().name ())) as PluginTypeB; - stdout.puts (b.method_b () + "\n"); - b = null; // free last instance, plugin unload + 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; + // Unload modules GObject.Plugins.unload_modules (type_a_modules); GObject.Plugins.unload_modules (type_b_modules); diff --git a/test/plugins/typeA/typeA1/CMakeLists.txt b/test/plugins/typeA/typeA1/CMakeLists.txt index 8d93ab9..5feec82 100644 --- a/test/plugins/typeA/typeA1/CMakeLists.txt +++ b/test/plugins/typeA/typeA1/CMakeLists.txt @@ -3,10 +3,13 @@ FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeA1.val SET (PluginCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi ${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi ) SET (PluginLinkLibs gobject-plugin-iface loader_test-iface) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface") -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/test/loader_test-iface") +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/test/loader_test-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" +) INCLUDE (ValaPluginCommonRules) #INSTALL (TARGETS ${PluginName} DESTINATION lib/${PROJECT_LOWERCASE_NAME}-${MAJOR}/plugins/${PluginName}) diff --git a/test/plugins/typeA/typeA1/TypeA1.vala b/test/plugins/typeA/typeA1/TypeA1.vala index a625d94..3ab1867 100644 --- a/test/plugins/typeA/typeA1/TypeA1.vala +++ b/test/plugins/typeA/typeA1/TypeA1.vala @@ -9,21 +9,23 @@ public class TypeA1 : PluginTypeA { * Constructs a new ``TypeA1``. */ construct { - stdout.puts ("TypeA1 init\n"); + stdout.puts ("TypeA1 init () called\n"); } /** * Destroys the ``TypeA1``. */ ~Test () { - stdout.puts ("TypeA1 deinit\n"); + stdout.puts ("TypeA1 deinit () called\n"); } /** - * Any virtual method for PluginTypeA. + * Any abstract method realization for PluginTypeA. */ public override void method_a () { stdout.puts ("TypeA1.method_a () called\n"); + stdout.puts ("Call IHostLoaderTest.method_host () from TypeA1:\n "); + (host as IHostLoaderTest).method_host (); } } diff --git a/test/plugins/typeA/typeA2/CMakeLists.txt b/test/plugins/typeA/typeA2/CMakeLists.txt index 11681d0..2c5767e 100644 --- a/test/plugins/typeA/typeA2/CMakeLists.txt +++ b/test/plugins/typeA/typeA2/CMakeLists.txt @@ -3,10 +3,13 @@ FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeA2.val SET (PluginCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi ${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi ) SET (PluginLinkLibs gobject-plugin-iface loader_test-iface) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface") -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/test/loader_test-iface") +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/test/loader_test-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" +) INCLUDE (ValaPluginCommonRules) #INSTALL (TARGETS ${PluginName} DESTINATION lib/${PROJECT_LOWERCASE_NAME}-${MAJOR}/plugins/${PluginName}) diff --git a/test/plugins/typeA/typeA2/TypeA2.vala b/test/plugins/typeA/typeA2/TypeA2.vala index 4f3d335..ede533e 100644 --- a/test/plugins/typeA/typeA2/TypeA2.vala +++ b/test/plugins/typeA/typeA2/TypeA2.vala @@ -9,18 +9,18 @@ public class TypeA2 : PluginTypeA { * Constructs a new ``TypeA2``. */ construct { - stdout.puts ("TypeA2 init\n"); + stdout.puts ("TypeA2 init () called\n"); } /** * Destroys the ``TypeA2``. */ ~Test () { - stdout.puts ("TypeA2 deinit\n"); + stdout.puts ("TypeA2 deinit () called\n"); } /** - * Any virtual method for PluginTypeA. + * Any abstract method realization for PluginTypeA. */ public override void method_a () { stdout.puts ("TypeA2.method_a () called\n"); diff --git a/test/plugins/typeB/typeB1/CMakeLists.txt b/test/plugins/typeB/typeB1/CMakeLists.txt index ab7393a..a587624 100644 --- a/test/plugins/typeB/typeB1/CMakeLists.txt +++ b/test/plugins/typeB/typeB1/CMakeLists.txt @@ -3,10 +3,13 @@ FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeB1.val SET (PluginCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi ${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi ) SET (PluginLinkLibs gobject-plugin-iface loader_test-iface) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface") -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/test/loader_test-iface") +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/test/loader_test-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" +) INCLUDE (ValaPluginCommonRules) #INSTALL (TARGETS ${PluginName} DESTINATION lib/${PROJECT_LOWERCASE_NAME}-${MAJOR}/plugins/${PluginName}) diff --git a/test/plugins/typeB/typeB1/TypeB1.vala b/test/plugins/typeB/typeB1/TypeB1.vala index e0e488a..59f18dd 100644 --- a/test/plugins/typeB/typeB1/TypeB1.vala +++ b/test/plugins/typeB/typeB1/TypeB1.vala @@ -9,18 +9,18 @@ public class TypeB1 : PluginTypeB { * Constructs a new ``TypeB1``. */ construct { - stdout.puts ("TypeB1 init\n"); + stdout.puts ("TypeB1 init () called\n"); } /** * Destroys the ``TypeB1``. */ ~Test () { - stdout.puts ("TypeB1 deinit\n"); + stdout.puts ("TypeB1 deinit () called\n"); } /** - * Any virtual method for PluginTypeB. + * Any abstract method realization for PluginTypeB. */ public override string method_b () { stdout.puts ("TypeB1.method_b () called\n"); diff --git a/test/plugins/typeB/typeB2/CMakeLists.txt b/test/plugins/typeB/typeB2/CMakeLists.txt index 2b74e06..bb4b067 100644 --- a/test/plugins/typeB/typeB2/CMakeLists.txt +++ b/test/plugins/typeB/typeB2/CMakeLists.txt @@ -3,10 +3,13 @@ FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeB2.val SET (PluginCustomVapis ${CMAKE_BINARY_DIR}/src/plugin-iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi ${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi + ${CMAKE_BINARY_DIR}/src/host-iface/${PROJECT_LOWERCASE_NAME}-host-iface-${MAJOR}.vapi ) SET (PluginLinkLibs gobject-plugin-iface loader_test-iface) -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface") -INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/test/loader_test-iface") +INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/plugin-iface" + "${CMAKE_BINARY_DIR}/test/loader_test-iface" + "${CMAKE_BINARY_DIR}/src/host-iface" +) INCLUDE (ValaPluginCommonRules) #INSTALL (TARGETS ${PluginName} DESTINATION lib/${PROJECT_LOWERCASE_NAME}-${MAJOR}/plugins/${PluginName}) diff --git a/test/plugins/typeB/typeB2/TypeB2.vala b/test/plugins/typeB/typeB2/TypeB2.vala index 9478a1c..585c68e 100644 --- a/test/plugins/typeB/typeB2/TypeB2.vala +++ b/test/plugins/typeB/typeB2/TypeB2.vala @@ -9,18 +9,18 @@ public class TypeB2 : PluginTypeB { * Constructs a new ``TypeB2``. */ construct { - stdout.puts ("TypeB2 init\n"); + stdout.puts ("TypeB2 init () called\n"); } /** * Destroys the ``TypeB2``. */ ~Test () { - stdout.puts ("TypeB2 deinit\n"); + stdout.puts ("TypeB2 deinit () called\n"); } /** - * Any virtual method for PluginTypeB. + * Any abstract method realization for PluginTypeB. */ public override string method_b () { stdout.puts ("TypeB2.method_b () called\n");