From bdd9ca27919744775ad8efd58ac6989329dfdcdc 2017-12-15 09:14:38 From: perrinel Date: 2017-12-15 09:14:38 Subject: [PATCH] Merge pull request #385 from SciQLop-IPSIS-fork StaticPlugins Added static plugin support --- diff --git a/app/src/Main.cpp b/app/src/Main.cpp index 30db0fe..9246498 100644 --- a/app/src/Main.cpp +++ b/app/src/Main.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -41,6 +42,13 @@ const auto PLUGIN_DIRECTORY_NAME = QStringLiteral("plugins"); int main(int argc, char *argv[]) { +#ifdef QT_STATICPLUGIN + Q_IMPORT_PLUGIN(MockPlugin) + Q_IMPORT_PLUGIN(AmdaPlugin) + Q_INIT_RESOURCE(amdaresources); +#endif + Q_INIT_RESOURCE(sqpguiresources); + SqpApplication a{argc, argv}; SqpApplication::setOrganizationName("LPP"); SqpApplication::setOrganizationDomain("lpp.fr"); @@ -75,6 +83,7 @@ int main(int argc, char *argv[]) pluginManager.loadPlugins(directory); } } + pluginManager.loadStaticPlugins(); return a.exec(); } diff --git a/core/include/Plugin/PluginManager.h b/core/include/Plugin/PluginManager.h index dd76163..025e42b 100644 --- a/core/include/Plugin/PluginManager.h +++ b/core/include/Plugin/PluginManager.h @@ -25,11 +25,16 @@ public: */ void loadPlugins(const QDir &pluginDir); + /** + * Loads static plugins into SciQlop. SciQLOP supports statically linked plugins. + */ + void loadStaticPlugins(); + /// @returns the number of plugins loaded int nbPluginsLoaded() const noexcept; private: - class PluginManagerPrivate; + struct PluginManagerPrivate; spimpl::unique_impl_ptr impl; }; diff --git a/core/src/Plugin/PluginManager.cpp b/core/src/Plugin/PluginManager.cpp index c1fa918..2f07645 100644 --- a/core/src/Plugin/PluginManager.cpp +++ b/core/src/Plugin/PluginManager.cpp @@ -95,6 +95,15 @@ struct PluginManager::PluginManagerPrivate { loadState.log(); } + void loadStaticPlugins() + { + for (QObject *plugin : QPluginLoader::staticInstances()) + { + qobject_cast(plugin)->initialize(); + m_RegisteredPlugins.insert(plugin->metaObject()->className(), "StaticPlugin"); + } + } + /// Registered plugins (key: plugin name, value: plugin path) QHash m_RegisteredPlugins; }; @@ -118,6 +127,11 @@ void PluginManager::loadPlugins(const QDir &pluginDir) } } +void PluginManager::loadStaticPlugins() +{ + impl->loadStaticPlugins(); +} + int PluginManager::nbPluginsLoaded() const noexcept { return impl->m_RegisteredPlugins.size();