/** * @file Plugins/pluginmanager.h * @brief Manager for loadable modules (plugins) * * Copyright (c) 2011-2019 Enar Vaikene * * This file is part of the eVaf C++ cross-platform application development framework. * * This file can be used under the terms of the GNU General Public License * version 3.0 as published by the Free Software Foundation and appearing in * the file LICENSE included in the packaging of this file. Please review the * the following information to ensure the GNU General Public License version * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html. * * Alternatively, this file may be used in accordance with the Commercial License * Agreement provided with the Software. */ #ifndef __PLUGINS_PLUGINMANAGER_H #define __PLUGINS_PLUGINMANAGER_H #include "libplugins.h" #include #include #include #include namespace eVaf { /** * Library for managing loadable modules (plugins). * * The Plugins library adds loadable modules (plugins) support to the eVaf application. A module is one * external library (.so or .dll file) that implements one or more plugins. A plugin is an individual object * that is created and initialized as one entirety. * * Modules are loaded and plugins created by the plugin manager. Plugin manager uses the application's * XML file to define which modules should be loaded and which plugins to be created. */ namespace Plugins { /** * Internal implementation of the plugin manager library. */ namespace Internal { class PluginManagerPrivate; } /** * Expands plugin names for the selected platform. * @param name Name of the plugin * @return Expanded plugin name * * This function expands the plugin name so that it becomes valid for the selected platform. * For example, on Linux it adds the prefix "lib" to the beginning and extension ".so" to the end. */ inline QString expandPluginName(QString const & name) { #ifdef Q_OS_WIN32 # ifdef Q_CC_MINGW return "lib" + name + ".dll"; # else return name + ".dll"; # endif #elif defined Q_OS_LINUX return "lib" + name + ".so"; #elif defined Q_OS_CYGWIN return "cyg" + name + ".dll"; #elif defined Q_OS_MACOS return "lib" + name + ".dylib"; #else return name; #endif } /** * Plugin manager for eVaf applications. */ class PLUGINS_EXPORT PluginManager : public QObject { Q_OBJECT public: /// Ctr. PluginManager(); /// Dtr. virtual ~PluginManager(); /** * Returns the plugin manager's instance */ static PluginManager * instance(); /** * Initializes the plugin manager. * @return True if ok; false if initialization failed. * * This function initializes the plugin manager. External modules are loaded and plugin objects * created in this function. */ bool init(); /** * Finalizes the plugin manager. * * This function finalizes the plugin manager. Plugin objects are destroyed and external modules * unloaded in this function. */ void done(); signals: /** * Plugins loaded signal. * * This signal is emitted when all the modules are loaded and plugin objects created. */ void pluginsLoaded(); /** * Plugins unloaded signal. * * This signal is emitted when all the plugin objects are destroyed and modules unloaded. */ void pluginsUnloaded(); private: QScopedPointer d; }; } // namespace eVaf::Plugins } // namespace eVaf #endif // pluginmanager.h