Compare commits
26 Commits
Author | SHA1 | Date |
---|---|---|
Kolan Sh | e73cf2d921 | |
Kolan Sh | 097e41f370 | |
Kolan Sh | 8f213ec8f1 | |
Kolan Sh | b15a77a189 | |
Kolan Sh | f9fea4fe13 | |
Kolan Sh | 7f822a0b6a | |
Kolan Sh | 94cbc852ec | |
Kolan Sh | f63c847401 | |
Kolan Sh | ae0f0e3153 | |
Kolan Sh | ee8c6209db | |
Kolan Sh | 9b11bca35b | |
Kolan Sh | a8a1e2c66b | |
Kolan Sh | d93eb17d31 | |
Kolan Sh | c2640021cf | |
Kolan Sh | e19b314c05 | |
Kolan Sh | 6fa1e6c1ed | |
Kolan Sh | f8cda52102 | |
Kolan Sh | b17a728b52 | |
Kolan Sh | 16373e6e3c | |
Kolan Sh | 2d30aff257 | |
Kolan Sh | 8de8b0eb4d | |
Kolan Sh | cc44d12d93 | |
Kolan Sh | 463dc96bb5 | |
Kolan Sh | 52d8626c30 | |
Kolan Sh | dcbf50cb96 | |
Kolan Sh | d5f982970e |
|
@ -1,6 +1,6 @@
|
|||
[submodule "cmake"]
|
||||
path = cmake/backbone
|
||||
url = git@git.backbone.ws:cmake/backbone.git
|
||||
url = https://git.backbone.ws/kolan/cmake.backbone.git
|
||||
[submodule "util/backbone"]
|
||||
path = util/backbone
|
||||
url = git@git.backbone.ws:cmake/backbone-utils.git
|
||||
url = https://git.backbone.ws/kolan/cmake.backbone-utils.git
|
||||
|
|
|
@ -7,7 +7,7 @@ SET (PROJECT_DESCRIPTION "Host/Plugin Interfaces for GObject Based Applications/
|
|||
|
||||
SET (MAJOR 0)
|
||||
SET (MINOR 1)
|
||||
SET (PATCH 12)
|
||||
SET (PATCH 13)
|
||||
|
||||
LIST (APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/backbone)
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 02f3a0f7d969534872799b45a95d3c5a6fef14c3
|
||||
Subproject commit 206751e1f4814716d716f6bc297c280d4bf1dcf7
|
|
@ -1,6 +1,6 @@
|
|||
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 (LibPackages posix gee-0.8 gmodule-2.0 gio-2.0)
|
||||
SET (LibCustomVapis ${CMAKE_BINARY_DIR}/src/iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi)
|
||||
SET (LibInstall ON)
|
||||
SET (LibExtraSources ${CMAKE_CURRENT_BINARY_DIR}/library_constructor.c)
|
||||
|
@ -8,4 +8,9 @@ SET (LC_RELATIVE_PREFIX "..")
|
|||
CONFIGURE_FILE ( "${CMAKE_SOURCE_DIR}/cmake/backbone/templates/library_constructor.c.in" "${LibExtraSources}")
|
||||
SET (LibLinkLibs ${PROJECT_LOWERCASE_NAME}-iface gmodule-2.0)
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/iface")
|
||||
IF (WIN32)
|
||||
SET (LibValaOpts -D WINDOWS)
|
||||
ELSE (WIN32)
|
||||
SET (LibValaOpts -D UNIX)
|
||||
ENDIF (WIN32)
|
||||
INCLUDE (ValaLibCommonRules)
|
||||
|
|
|
@ -34,15 +34,15 @@ namespace GObject {
|
|||
* Loads the module.
|
||||
*/
|
||||
public override bool load () {
|
||||
module = GLib.Module.open (path, GLib.ModuleFlags.BIND_LAZY);
|
||||
module = GLib.Module.open (path, GLib.ModuleFlags.LAZY);
|
||||
if (null == module) {
|
||||
message ("Module '%s' not found", path);
|
||||
stderr.printf("Cannot load module %s\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
void * plugin_init = null;
|
||||
if (! module.symbol ("plugin_init", out plugin_init)) {
|
||||
message ("No such symbol: plugin_init in module " + path);
|
||||
stderr.printf("No such symbol: plugin_init in %s\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,69 @@ namespace GObject {
|
|||
}
|
||||
}
|
||||
|
||||
void sort_modules (Gee.ArrayList<Module> modules) {
|
||||
modules.sort ((a, b) => {
|
||||
var a_name = a.get_plugin_type ().name ();
|
||||
var b_name = b.get_plugin_type ().name ();
|
||||
if (a_name < b_name) return -1;
|
||||
if (a_name > b_name) return 1;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads modules in the specific directory.
|
||||
*
|
||||
* @param dir_path path to the directory.
|
||||
* @param modules where to save list of modules.
|
||||
*
|
||||
* @return are the modules loaded correctly or not.
|
||||
*/
|
||||
public bool load_modules (string dir_path, ref Gee.ArrayList<Module>? modules) {
|
||||
|
||||
modules = new Gee.ArrayList<Module> ();
|
||||
#if (WINDOWS)
|
||||
var paths = new Gee.HashSet<string> ();
|
||||
#endif
|
||||
|
||||
try {
|
||||
var libPath = File.new_for_path (dir_path);
|
||||
#if (WINDOWS)
|
||||
for (var i = 0; i < 32; ++i) {
|
||||
var saved_length = modules.size;
|
||||
#endif
|
||||
var lib_enumerator = libPath.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
|
||||
FileInfo file_info = null;
|
||||
while ((file_info = lib_enumerator.next_file (null)) != null) {
|
||||
if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) {
|
||||
var path = GLib.Module.build_path (dir_path, file_info.get_name ());
|
||||
#if (WINDOWS)
|
||||
if (paths.contains(path)) continue;
|
||||
#endif
|
||||
var module = new Module (path);
|
||||
if (module.load ()) {
|
||||
modules.add (module);
|
||||
#if (WINDOWS)
|
||||
paths.add(path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#if (WINDOWS)
|
||||
if (modules.size == saved_length) break;
|
||||
}
|
||||
#endif
|
||||
} catch (Error e) {
|
||||
message (e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
sort_modules (modules);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads modules in the 2-depth directory tree path.
|
||||
*
|
||||
|
@ -83,42 +146,55 @@ namespace GObject {
|
|||
*
|
||||
* @return are the modules loaded correctly or not.
|
||||
*/
|
||||
public bool load_modules (string dir_path, ref Gee.ArrayList<Module>? modules) {
|
||||
public bool load_modules_depth2 (string dir_path, ref Gee.ArrayList<Module>? modules) {
|
||||
|
||||
modules = new Gee.ArrayList<Module> ();
|
||||
#if (WINDOWS)
|
||||
var paths = new Gee.HashSet<string> ();
|
||||
#endif
|
||||
|
||||
try {
|
||||
var libPath = File.new_for_path (dir_path);
|
||||
var dir_enumerator = libPath.enumerate_children ("standard::*",
|
||||
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
||||
FileInfo dir_info = null;
|
||||
while ((dir_info = dir_enumerator.next_file (null)) != null ) {
|
||||
if (dir_info.get_file_type () == FileType.DIRECTORY) {
|
||||
File subdir = libPath.resolve_relative_path (dir_info.get_name ());
|
||||
var lib_enumerator = subdir.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
|
||||
FileInfo file_info = null;
|
||||
while ((file_info = lib_enumerator.next_file (null)) != null) {
|
||||
if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) {
|
||||
var path = Path.build_path (Path.DIR_SEPARATOR_S, dir_path, dir_info.get_name ());
|
||||
var module = new Module (GLib.Module.build_path (path, file_info.get_name ()));
|
||||
if (module.load ())
|
||||
modules.add (module);
|
||||
#if (WINDOWS)
|
||||
for (var i = 0; i < 32; ++i) {
|
||||
var saved_length = modules.size;
|
||||
#endif
|
||||
var dir_enumerator = libPath.enumerate_children ("standard::*",
|
||||
FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
|
||||
FileInfo dir_info = null;
|
||||
while ((dir_info = dir_enumerator.next_file (null)) != null ) {
|
||||
if (dir_info.get_file_type () == FileType.DIRECTORY) {
|
||||
File subdir = libPath.resolve_relative_path (dir_info.get_name ());
|
||||
var lib_enumerator = subdir.enumerate_children (FileAttribute.STANDARD_NAME, 0, null);
|
||||
FileInfo file_info = null;
|
||||
while ((file_info = lib_enumerator.next_file (null)) != null) {
|
||||
if (Regex.match_simple ("^.*\\.(so|dll)$", file_info.get_name ())) {
|
||||
var path = Path.build_path (Path.DIR_SEPARATOR_S, dir_path, dir_info.get_name ());
|
||||
path = GLib.Module.build_path (path, file_info.get_name ());
|
||||
#if (WINDOWS)
|
||||
if (paths.contains(path)) continue;
|
||||
#endif
|
||||
var module = new Module (path);
|
||||
if (module.load ()) {
|
||||
modules.add (module);
|
||||
#if (WINDOWS)
|
||||
paths.add(path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if (WINDOWS)
|
||||
if (modules.size == saved_length) break;
|
||||
}
|
||||
#endif
|
||||
} catch (Error e) {
|
||||
message (e.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
modules.sort ((a, b) => {
|
||||
var a_name = a.get_plugin_type ().name ();
|
||||
var b_name = b.get_plugin_type ().name ();
|
||||
if (a_name < b_name) return -1;
|
||||
if (a_name > b_name) return 1;
|
||||
return 0;
|
||||
});
|
||||
sort_modules (modules);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@ int main (string [] args) {
|
|||
|
||||
var h = new LoaderTestHost ();
|
||||
|
||||
GObject.Plugins.load_modules (
|
||||
GObject.Plugins.load_modules_depth2 (
|
||||
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 (
|
||||
GObject.Plugins.load_modules_depth2 (
|
||||
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
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
SET (PluginName type_a1)
|
||||
FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeA1.vala)
|
||||
SET (PluginCustomVapis
|
||||
SET (LibName type_a1)
|
||||
SET (LibIsPlugin ON)
|
||||
SET (LibNoApi ON)
|
||||
FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeA1.vala)
|
||||
SET (LibCustomVapis
|
||||
${CMAKE_BINARY_DIR}/src/iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi
|
||||
${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi
|
||||
)
|
||||
SET (PluginLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
SET (LibLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/iface"
|
||||
"${CMAKE_BINARY_DIR}/test/loader_test-iface"
|
||||
)
|
||||
INCLUDE (ValaPluginCommonRules)
|
||||
INCLUDE (ValaLibCommonRules)
|
||||
|
|
|
@ -25,11 +25,12 @@ public class TypeA1 : 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 ();
|
||||
var test = host as IHostLoaderTest;
|
||||
if (test != null) test.method_host ();
|
||||
}
|
||||
}
|
||||
|
||||
[ModuleInit]
|
||||
Type plugin_init (GLib.TypeModule type_module) {
|
||||
public Type plugin_init (GLib.TypeModule type_module) {
|
||||
return typeof (TypeA1);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
SET (PluginName type_a2)
|
||||
FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeA2.vala)
|
||||
SET (PluginCustomVapis
|
||||
SET (LibName type_a2)
|
||||
SET (LibIsPlugin ON)
|
||||
SET (LibNoApi ON)
|
||||
FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeA2.vala)
|
||||
SET (LibCustomVapis
|
||||
${CMAKE_BINARY_DIR}/src/iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi
|
||||
${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi
|
||||
)
|
||||
SET (PluginLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
SET (LibLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/iface"
|
||||
"${CMAKE_BINARY_DIR}/test/loader_test-iface"
|
||||
)
|
||||
INCLUDE (ValaPluginCommonRules)
|
||||
INCLUDE (ValaLibCommonRules)
|
||||
|
|
|
@ -28,6 +28,6 @@ public class TypeA2 : PluginTypeA {
|
|||
}
|
||||
|
||||
[ModuleInit]
|
||||
Type plugin_init (GLib.TypeModule type_module) {
|
||||
public Type plugin_init (GLib.TypeModule type_module) {
|
||||
return typeof (TypeA2);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
SET (PluginName type_b1)
|
||||
FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeB1.vala)
|
||||
SET (PluginCustomVapis
|
||||
SET (LibName type_b1)
|
||||
SET (LibIsPlugin ON)
|
||||
SET (LibNoApi ON)
|
||||
FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeB1.vala)
|
||||
SET (LibCustomVapis
|
||||
${CMAKE_BINARY_DIR}/src/iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi
|
||||
${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi
|
||||
)
|
||||
SET (PluginLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
SET (LibLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/iface"
|
||||
"${CMAKE_BINARY_DIR}/test/loader_test-iface"
|
||||
)
|
||||
INCLUDE (ValaPluginCommonRules)
|
||||
INCLUDE (ValaLibCommonRules)
|
||||
|
|
|
@ -29,6 +29,6 @@ public class TypeB1 : PluginTypeB {
|
|||
}
|
||||
|
||||
[ModuleInit]
|
||||
Type plugin_init (GLib.TypeModule type_module) {
|
||||
public Type plugin_init (GLib.TypeModule type_module) {
|
||||
return typeof (TypeB1);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
SET (PluginName type_b2)
|
||||
FILE (GLOB_RECURSE PluginSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeB2.vala)
|
||||
SET (PluginCustomVapis
|
||||
SET (LibName type_b2)
|
||||
SET (LibIsPlugin ON)
|
||||
SET (LibNoApi ON)
|
||||
FILE (GLOB_RECURSE LibSources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} TypeB2.vala)
|
||||
SET (LibCustomVapis
|
||||
${CMAKE_BINARY_DIR}/src/iface/${PROJECT_LOWERCASE_NAME}-iface-${MAJOR}.vapi
|
||||
${CMAKE_BINARY_DIR}/test/loader_test-iface/loader_test-iface-${MAJOR}.vapi
|
||||
)
|
||||
SET (PluginLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
SET (LibLinkLibs gobject-plugin-iface loader_test-iface)
|
||||
INCLUDE_DIRECTORIES ("${CMAKE_BINARY_DIR}/src/iface"
|
||||
"${CMAKE_BINARY_DIR}/test/loader_test-iface"
|
||||
)
|
||||
INCLUDE (ValaPluginCommonRules)
|
||||
INCLUDE (ValaLibCommonRules)
|
||||
|
|
|
@ -29,6 +29,6 @@ public class TypeB2 : PluginTypeB {
|
|||
}
|
||||
|
||||
[ModuleInit]
|
||||
Type plugin_init (GLib.TypeModule type_module) {
|
||||
public Type plugin_init (GLib.TypeModule type_module) {
|
||||
return typeof (TypeB2);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d4e233ae72412f4dfef9b7c39ae7a1b6667fb446
|
||||
Subproject commit 11c998aca2aa1b787286b336e579e5a4e31f471a
|
Loading…
Reference in New Issue