]> vaikene.ee Git - evaf/blob - src/libs/Plugins/pluginmanager.h
91a5b00947db662addc22238846e0dbd2e5fe00e
[evaf] / src / libs / Plugins / pluginmanager.h
1 /**
2 * @file Plugins/pluginmanager.h
3 * @brief Manager for loadable modules (plugins)
4 *
5 * Copyright (c) 2011-2019 Enar Vaikene
6 *
7 * This file is part of the eVaf C++ cross-platform application development framework.
8 *
9 * This file can be used under the terms of the GNU General Public License
10 * version 3.0 as published by the Free Software Foundation and appearing in
11 * the file LICENSE included in the packaging of this file. Please review the
12 * the following information to ensure the GNU General Public License version
13 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
14 *
15 * Alternatively, this file may be used in accordance with the Commercial License
16 * Agreement provided with the Software.
17 */
18
19 #ifndef __PLUGINS_PLUGINMANAGER_H
20 #define __PLUGINS_PLUGINMANAGER_H
21
22 #include "libplugins.h"
23
24 #include <version_rc.h>
25
26 #include <QObject>
27 #include <QString>
28 #include <QScopedPointer>
29
30 namespace eVaf {
31
32 /**
33 * Library for managing loadable modules (plugins).
34 *
35 * The Plugins library adds loadable modules (plugins) support to the eVaf application. A module is one
36 * external library (.so or .dll file) that implements one or more plugins. A plugin is an individual object
37 * that is created and initialized as one entirety.
38 *
39 * Modules are loaded and plugins created by the plugin manager. Plugin manager uses the application's
40 * XML file to define which modules should be loaded and which plugins to be created.
41 */
42 namespace Plugins {
43
44 /**
45 * Internal implementation of the plugin manager library.
46 */
47 namespace Internal {
48 class PluginManagerPrivate;
49 }
50
51 /**
52 * Expands plugin names for the selected platform.
53 * @param name Name of the plugin
54 * @return Expanded plugin name
55 *
56 * This function expands the plugin name so that it becomes valid for the selected platform.
57 * For example, on Linux it adds the prefix "lib" to the beginning and extension ".so" to the end.
58 */
59 inline QString expandPluginName(QString const & name)
60 {
61 #ifdef Q_OS_WIN32
62 # ifdef Q_CC_MINGW
63 return "lib" + name + ".dll";
64 # else
65 return name + ".dll";
66 # endif
67 #elif defined Q_OS_LINUX
68 return "lib" + name + ".so";
69 #elif defined Q_OS_CYGWIN
70 return "cyg" + name + ".dll";
71 #elif defined Q_OS_MACOS
72 return "lib" + name + ".dylib";
73 #else
74 return name;
75 #endif
76 }
77
78 /**
79 * Plugin manager for eVaf applications.
80 */
81 class PLUGINS_EXPORT PluginManager : public QObject
82 {
83 Q_OBJECT
84
85 public:
86
87 /// Ctr.
88 PluginManager();
89
90 /// Dtr.
91 virtual ~PluginManager();
92
93 /**
94 * Returns the plugin manager's instance
95 */
96 static PluginManager * instance();
97
98 /**
99 * Initializes the plugin manager.
100 * @return True if ok; false if initialization failed.
101 *
102 * This function initializes the plugin manager. External modules are loaded and plugin objects
103 * created in this function.
104 */
105 bool init();
106
107 /**
108 * Finalizes the plugin manager.
109 *
110 * This function finalizes the plugin manager. Plugin objects are destroyed and external modules
111 * unloaded in this function.
112 */
113 void done();
114
115
116 signals:
117
118 /**
119 * Plugins loaded signal.
120 *
121 * This signal is emitted when all the modules are loaded and plugin objects created.
122 */
123 void pluginsLoaded();
124
125 /**
126 * Plugins unloaded signal.
127 *
128 * This signal is emitted when all the plugin objects are destroyed and modules unloaded.
129 */
130 void pluginsUnloaded();
131
132
133 private:
134
135 QScopedPointer<Internal::PluginManagerPrivate> d;
136
137 };
138
139 } // namespace eVaf::Plugins
140 } // namespace eVaf
141
142 #endif // pluginmanager.h