X-Git-Url: https://vaikene.ee/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Flibs%2FPlugins%2Fpluginmanager.cpp;h=5fea828802b894e6468da1037a9627f6bad3af90;hb=HEAD;hp=8ca6048f915eba56b5e7c9ed90936948e4ae6c9d;hpb=ad3c375c68b46edcb823ff3eb2dc12647da1db19;p=evaf diff --git a/src/libs/Plugins/pluginmanager.cpp b/src/libs/Plugins/pluginmanager.cpp index 8ca6048..5fea828 100644 --- a/src/libs/Plugins/pluginmanager.cpp +++ b/src/libs/Plugins/pluginmanager.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -36,7 +35,7 @@ namespace Plugins { namespace Internal { // Plugin manager interface implementation - static eVaf::Plugins::PluginManager * mPluginManager = 0; + static eVaf::Plugins::PluginManager * mPluginManager = nullptr; } // namespace eVaf::Plugins::Internal } // namespace eVaf::Plugins @@ -50,21 +49,20 @@ using namespace eVaf::Plugins; PluginManager::PluginManager() : QObject() + , d(new Internal::PluginManagerPrivate) { setObjectName(QString("%1-PluginManager").arg(VER_MODULE_NAME_STR)); Internal::mPluginManager = this; - d = new Internal::PluginManagerPrivate; - EVAF_INFO("%s created", qPrintable(objectName())); } PluginManager::~PluginManager() { - delete d; + d.reset(); - Internal::mPluginManager = 0; + Internal::mPluginManager = nullptr; EVAF_INFO("%s destroyed", qPrintable(objectName())); } @@ -145,7 +143,7 @@ void PluginManagerPrivate::done() bool PluginManagerPrivate::loadPlugins() { // Get the name of the application's XML file - QString xmlFileName = Common::iEnv::instance()->etcDir() + Common::iApp::instance()->xmlFileName(); + QString xmlFileName = Common::iApp::instance()->etcDir() + Common::iApp::instance()->xmlFileName(); // Open the XML file QFile xmlFile(xmlFileName); @@ -189,7 +187,7 @@ bool PluginManagerPrivate::loadPlugins() if (!isPlugins && !isQtPlugins) { if (xml.name() == "plugins") { // Check for windows and linux only sections -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) continue; #endif @@ -202,7 +200,7 @@ bool PluginManagerPrivate::loadPlugins() else if (xml.name() == "qtplugins") { // Check for windows and linux only sections -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) continue; #endif @@ -218,7 +216,7 @@ bool PluginManagerPrivate::loadPlugins() // An individual plugin? else if (isPlugins && xml.name() == "plugin") { // Check for windows and linux only plugins -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) { EVAF_INFO("Plugin '%s' is for Windows only", qPrintable(xml.attributes().value("name").toString())); continue; @@ -253,7 +251,7 @@ bool PluginManagerPrivate::loadPlugins() // An individual Qt plugin? else if (isQtPlugins && xml.name() == "plugin") { // Check for windows and linux only plugins -#ifdef Q_OS_LINUX +#if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) if (Common::isTrue(xml.attributes().value("windowsonly").toString())) { EVAF_INFO("Qt plugin '%s' is for Windows only", qPrintable(xml.attributes().value("name").toString())); continue; @@ -292,14 +290,8 @@ bool PluginManagerPrivate::loadPlugins() } // End element? } - // Load Qt plugins - int i; - for (i = 0; i < qtPlugins.size(); ++i) { - loadQtPlugin(qtPlugins.at(i)); - } - // Load eVaf plugins - i = 0; + int i = 0; while (i < mPlugins.size()) { if (!mPlugins.at(i)->load()) { EVAF_ERROR("Failed to load module '%s'", qPrintable(mPlugins.at(i)->name())); @@ -326,7 +318,7 @@ bool PluginManagerPrivate::loadPlugins() void PluginManagerPrivate::unloadPlugins() { // Finalize all the plugins - for (int i = 0; i < mPlugins.size(); ++i) + for (int i = mPlugins.size() - 1; i >= 0; --i) mPlugins.at(i)->done(); while (!mPlugins.isEmpty()) { QExplicitlySharedDataPointer p = mPlugins.takeLast(); @@ -346,49 +338,7 @@ Module * PluginManagerPrivate::moduleByName(QString const & name) const if (mModules.at(i)->name() == name) return mModules.at(i).data(); } - return 0; -} - -bool PluginManagerPrivate::loadQtPlugin(QString const & name) const -{ - // Get the Qt plugin file name with the full path - QString fileName; - -#ifdef Q_OS_LINUX - fileName = QString("%1libq%2.so").arg(Common::iEnv::instance()->qtPluginsDir()).arg(name); -# ifndef QT_NO_DEBUG - QString t = QString("%1libq%2.so.debug").arg(Common::iEnv::instance()->qtPluginsDir()).arg(name); - if (QFile::exists(t)) - fileName = t; -# endif -#endif - -#ifdef Q_OS_WIN32 - fileName = QString("%2q%2%3").arg(Common::iEnv::instance()->qtPluginsDir()).arg(name).arg("4.dll"); -# ifndef QT_NO_DEBUG - QString t = QString(%1q%2%3).arg(Common::iEnv::instance()->qtPluginsDir()).arg(name).arg(d4.dll); - if (!QFile::exists(t)) - fileName = t; -# endif -#endif - - if (fileName.isEmpty()) { - EVAF_ERROR("Don\'t know how to load Qt plugin '%s'", qPrintable(name)); - return false; - } - - EVAF_INFO("Loading Qt plugin '%s'", qPrintable(fileName)); - - QLibrary lib(fileName); - void * fn = lib.resolve("qt_plugin_instance"); - if (fn) { - qRegisterStaticPluginInstanceFunction(QtPluginInstanceFunction(fn)); - return true; - } - else { - EVAF_ERROR("Failed to load Qt plugin '%s' : %s", qPrintable(fileName), qPrintable(lib.errorString())); - return false; - } + return nullptr; } @@ -397,24 +347,23 @@ bool PluginManagerPrivate::loadQtPlugin(QString const & name) const Module::Module(QString const & name) : QSharedData() , mName(name) - , mLoader(0) - , mRoot(0) - , mPlugin(0) - , mPluginFactory(0) + , mRoot(nullptr) + , mPlugin(nullptr) + , mPluginFactory(nullptr) {} Module::~Module() { if (mLoader) { mLoader->unload(); - delete mLoader; + mLoader.reset(); } } bool Module::load() { // The real file name with path - QString fileName = Common::iEnv::instance()->binDir() + expandPluginName(mName); + QString fileName = Common::iApp::instance()->binDir() + expandPluginName(mName); // Try to load the module QScopedPointer p(new QPluginLoader(fileName)); @@ -427,29 +376,28 @@ bool Module::load() QObject * root = p->instance(); // Does the module implement the iPluginFactory interface? - if ((mPluginFactory = qobject_cast(root)) == 0) { + if ((mPluginFactory = qobject_cast(root)) == nullptr) { // If not, then it has to implement the iPlugin interface - if (qobject_cast(root) == 0) { + if (qobject_cast(root) == nullptr) { EVAF_FATAL_ERROR("Module '%s' is not a valid eVaf module", qPrintable(mName)); return false; } } mRoot = root; - mLoader = p.take(); + mLoader.reset(p.take()); return true; } void Module::unload() { - mRoot = 0; - mPluginFactory = 0; - mPlugin = 0; + mRoot = nullptr; + mPluginFactory = nullptr; + mPlugin = nullptr; if (mLoader) { mLoader->unload(); - delete mLoader; - mLoader = 0; + mLoader.reset(); } } @@ -458,18 +406,18 @@ iPlugin * Module::create(QString const & name) // If the module is not loaded, load it now if (!mLoader) { if (!load()) - return false; + return nullptr; } - iPlugin * i = 0; + iPlugin * i = nullptr; // Does the module implement the iPluginFactory interface? if (mPluginFactory) { // Use the iPluginFactory interface to create the requested interface i = qobject_cast(mPluginFactory->create(name)); - if (i == 0) { + if (i == nullptr) { EVAF_FATAL_ERROR("Module '%s' failed to create the iPlugin interface with name '%s'", qPrintable(mName), qPrintable(name)); - return 0; + return nullptr; } } @@ -478,13 +426,13 @@ iPlugin * Module::create(QString const & name) if (mPlugin) { EVAF_FATAL_ERROR("Module '%s' can implement only one iPlugin interface and one with the name '%s' is already created", qPrintable(mName), qPrintable(mPlugin->objectName())); - return 0; + return nullptr; } i = qobject_cast(mRoot); - if (i == 0) { + if (i == nullptr) { EVAF_FATAL_ERROR("Module '%s' does not implement the iPlugin interface", qPrintable(mName)); - return 0; + return nullptr; } mPlugin = i; @@ -501,7 +449,7 @@ Plugin::Plugin(Module * module, QString const & name, QString const & args) , mModule(module) , mName(name) , mArgs(args) - , mPlugin(0) + , mPlugin(nullptr) {} Plugin::~Plugin() @@ -513,12 +461,12 @@ bool Plugin::load() mPlugin = mModule->create(mName); if (mPlugin && !mPlugin->objectName().isEmpty()) mName = mPlugin->objectName(); - return mPlugin != 0; + return mPlugin != nullptr; } void Plugin::unload() { - mPlugin = 0; + mPlugin = nullptr; } bool Plugin::init()