]> vaikene.ee Git - evaf/blob - src/libs/Plugins/pluginmanager.h
e56092225030843e3a7be50e38f1ff8e2b207990
[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 #elif defined Q_OS_CYGWIN
69 return "cyg" + name + ".dll";
70 #else
71 return name;
72 #endif
73 }
74
75 /**
76 * Plugin manager for eVaf applications.
77 */
78 class PLUGINS_EXPORT PluginManager : public QObject
79 {
80 Q_OBJECT
81
82 public:
83
84 /// Ctr.
85 PluginManager();
86
87 /// Dtr.
88 virtual ~PluginManager();
89
90 /**
91 * Returns the plugin manager's instance
92 */
93 static PluginManager * instance();
94
95 /**
96 * Initializes the plugin manager.
97 * @return True if ok; false if initialization failed.
98 *
99 * This function initializes the plugin manager. External modules are loaded and plugin objects
100 * created in this function.
101 */
102 bool init();
103
104 /**
105 * Finalizes the plugin manager.
106 *
107 * This function finalizes the plugin manager. Plugin objects are destroyed and external modules
108 * unloaded in this function.
109 */
110 void done();
111
112
113 signals:
114
115 /**
116 * Plugins loaded signal.
117 *
118 * This signal is emitted when all the modules are loaded and plugin objects created.
119 */
120 void pluginsLoaded();
121
122 /**
123 * Plugins unloaded signal.
124 *
125 * This signal is emitted when all the plugin objects are destroyed and modules unloaded.
126 */
127 void pluginsUnloaded();
128
129
130 private:
131
132 Internal::PluginManagerPrivate * d;
133
134 };
135
136 } // namespace eVaf::Plugins
137 } // namespace eVaf
138
139 #endif // pluginmanager.h