]> vaikene.ee Git - evaf/blob - src/libs/Plugins/pluginmanager.h
Changes to build the software with mingw on Windows.
[evaf] / src / libs / Plugins / pluginmanager.h
1 /**
2 * @file Plugins/pluginmanager.h
3 * @brief Manager for loadable modules (plugins)
4 *
5 * Copyright (c) 2011 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
29 namespace eVaf {
30
31 /**
32 * Library for managing loadable modules (plugins).
33 *
34 * The Plugins library adds loadable modules (plugins) support to the eVaf application. A module is one
35 * external library (.so or .dll file) that implements one or more plugins. A plugin is an individual object
36 * that is created and initialized as one entirety.
37 *
38 * Modules are loaded and plugins created by the plugin manager. Plugin manager uses the application's
39 * XML file to define which modules should be loaded and which plugins to be created.
40 */
41 namespace Plugins {
42
43 /**
44 * Internal implementation of the plugin manager library.
45 */
46 namespace Internal {
47 class PluginManagerPrivate;
48 }
49
50 /**
51 * Expands plugin names for the selected platform.
52 * @param name Name of the plugin
53 * @return Expanded plugin name
54 *
55 * This function expands the plugin name so that it becomes valid for the selected platform.
56 * For example, on Linux it adds the prefix "lib" to the beginning and extension ".so" to the end.
57 */
58 inline QString expandPluginName(QString const & name)
59 {
60 #ifdef Q_OS_WIN32
61 # ifdef Q_CC_MINGW
62 return "lib" + name + ".dll";
63 # else
64 return name + ".dll";
65 # endif
66 #elif defined Q_OS_LINUX
67 return "lib" + name + ".so";
68 #else
69 return name;
70 #endif
71 }
72
73 /**
74 * Plugin manager for eVaf applications.
75 */
76 class PLUGINS_EXPORT PluginManager : public QObject
77 {
78 Q_OBJECT
79
80 public:
81
82 /// Ctr.
83 PluginManager();
84
85 /// Dtr.
86 virtual ~PluginManager();
87
88 /**
89 * Returns the plugin manager's instance
90 */
91 static PluginManager * instance();
92
93 /**
94 * Initializes the plugin manager.
95 * @return True if ok; false if initialization failed.
96 *
97 * This function initializes the plugin manager. External modules are loaded and plugin objects
98 * created in this function.
99 */
100 bool init();
101
102 /**
103 * Finalizes the plugin manager.
104 *
105 * This function finalizes the plugin manager. Plugin objects are destroyed and external modules
106 * unloaded in this function.
107 */
108 void done();
109
110
111 signals:
112
113 /**
114 * Plugins loaded signal.
115 *
116 * This signal is emitted when all the modules are loaded and plugin objects created.
117 */
118 void pluginsLoaded();
119
120 /**
121 * Plugins unloaded signal.
122 *
123 * This signal is emitted when all the plugin objects are destroyed and modules unloaded.
124 */
125 void pluginsUnloaded();
126
127
128 private:
129
130 Internal::PluginManagerPrivate * d;
131
132 };
133
134 } // namespace eVaf::Plugins
135 } // namespace eVaf
136
137 #endif // pluginmanager.h