From 58a5565b6d840af2e6a0e74c1554018f75d689b0 Mon Sep 17 00:00:00 2001 From: Moritz Eberl Date: Mon, 11 Apr 2016 16:53:05 +0200 Subject: Added a mechanism to load c++ extensions dynamically. (bzr r14761.1.1) --- src/extension/system.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 6a95717f2..5a77ac28e 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -39,6 +39,7 @@ #include "io/sys.h" #include "inkscape.h" #include "document-undo.h" +#include "loader.h" namespace Inkscape { @@ -426,7 +427,7 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation enum { MODULE_EXTENSION, MODULE_XSLT, - /* MODULE_PLUGIN, */ + MODULE_PLUGIN, MODULE_UNKNOWN_IMP } module_implementation_type = MODULE_UNKNOWN_IMP; enum { @@ -465,10 +466,8 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation module_implementation_type = MODULE_EXTENSION; } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "xslt")) { module_implementation_type = MODULE_XSLT; -#if 0 - } else if (!strcmp(element_name, "plugin")) { + } else if (!strcmp(element_name, INKSCAPE_EXTENSION_NS "plugin")) { module_implementation_type = MODULE_PLUGIN; -#endif } //Inkscape::XML::Node *old_repr = child_repr; @@ -489,13 +488,15 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation imp = static_cast(xslt); break; } -#if 0 case MODULE_PLUGIN: { - Implementation::Plugin *plugin = new Implementation::Plugin(); - imp = static_cast(plugin); + Inkscape::Extension::Loader loader = Inkscape::Extension::Loader(); + loader.setBaseDirectory ( Inkscape::Application::profile_path("extensions")); + imp = loader.LoadImplementation(doc); + if( imp != NULL) { + return new Extension(repr, imp); + } break; } -#endif default: { imp = NULL; break; -- cgit v1.2.3 From d2a9d82cd79c61f44e2224dee38847d4113c7eda Mon Sep 17 00:00:00 2001 From: Moritz Eberl Date: Tue, 12 Apr 2016 11:43:56 +0200 Subject: fixed naming of methods. External extensions can now be other module types. (bzr r14761.1.2) --- src/extension/system.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 5a77ac28e..6b8e80d3c 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -490,11 +490,8 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation } case MODULE_PLUGIN: { Inkscape::Extension::Loader loader = Inkscape::Extension::Loader(); - loader.setBaseDirectory ( Inkscape::Application::profile_path("extensions")); - imp = loader.LoadImplementation(doc); - if( imp != NULL) { - return new Extension(repr, imp); - } + loader.set_base_directory ( Inkscape::Application::profile_path("extensions")); + imp = loader.load_implementation(doc); break; } default: { @@ -529,6 +526,7 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation break; } default: { + module = new Extension(repr, imp); break; } } -- cgit v1.2.3 From b8136b3cdbb75028e9eb815e69b735695453d70f Mon Sep 17 00:00:00 2001 From: Moritz Eberl Date: Wed, 27 Apr 2016 09:29:21 +0200 Subject: Fixed path resolution in plugin loader. (bzr r14862.1.1) --- src/extension/system.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/extension/system.cpp') diff --git a/src/extension/system.cpp b/src/extension/system.cpp index 6b8e80d3c..3c623455a 100644 --- a/src/extension/system.cpp +++ b/src/extension/system.cpp @@ -47,7 +47,7 @@ namespace Extension { static void open_internal(Inkscape::Extension::Extension *in_plug, gpointer in_data); static void save_internal(Inkscape::Extension::Extension *in_plug, gpointer in_data); -static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp); +static Extension *build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp, std::string* baseDir); /** * \return A new document created from the filename passed in @@ -422,7 +422,7 @@ get_print(gchar const *key) * case could apply to modules that are built in (like the SVG load/save functions). */ static Extension * -build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp) +build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation *in_imp, std::string* baseDir) { enum { MODULE_EXTENSION, @@ -490,7 +490,9 @@ build_from_reprdoc(Inkscape::XML::Document *doc, Implementation::Implementation } case MODULE_PLUGIN: { Inkscape::Extension::Loader loader = Inkscape::Extension::Loader(); - loader.set_base_directory ( Inkscape::Application::profile_path("extensions")); + if( baseDir != NULL){ + loader.set_base_directory ( *baseDir ); + } imp = loader.load_implementation(doc); break; } @@ -546,7 +548,8 @@ Extension * build_from_file(gchar const *filename) { Inkscape::XML::Document *doc = sp_repr_read_file(filename, INKSCAPE_EXTENSION_URI); - Extension *ext = build_from_reprdoc(doc, NULL); + std::string dir = Glib::path_get_dirname(filename); + Extension *ext = build_from_reprdoc(doc, NULL, &dir); if (ext != NULL) Inkscape::GC::release(doc); else @@ -568,7 +571,7 @@ build_from_mem(gchar const *buffer, Implementation::Implementation *in_imp) { Inkscape::XML::Document *doc = sp_repr_read_mem(buffer, strlen(buffer), INKSCAPE_EXTENSION_URI); g_return_val_if_fail(doc != NULL, NULL); - Extension *ext = build_from_reprdoc(doc, in_imp); + Extension *ext = build_from_reprdoc(doc, in_imp, NULL); Inkscape::GC::release(doc); return ext; } -- cgit v1.2.3