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