]> vaikene.ee Git - evaf/blob - src/libs/Plugins/pluginmanager_p.h
Ported to Qt5
[evaf] / src / libs / Plugins / pluginmanager_p.h
1 /**
2 * @file Plugins/pluginmanager_p.h
3 * @brief Private implementation of the plugin manager
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_P_H
20 #define __PLUGINS_PLUGINMANAGER_P_H
21
22 #include <QObject>
23 #include <QSharedData>
24 #include <QExplicitlySharedDataPointer>
25 #include <QPluginLoader>
26
27 namespace eVaf {
28 namespace Plugins {
29
30 class iPlugin;
31 class iPluginFactory;
32
33 namespace Internal {
34
35 class Plugin;
36 class Module;
37
38 /**
39 * Internal implementation of the plugin manager
40 */
41 class PluginManagerPrivate : public QObject
42 {
43 Q_OBJECT
44
45 public:
46
47 /// Ctr.
48 PluginManagerPrivate();
49
50 /// Dtr.
51 virtual ~PluginManagerPrivate();
52
53 /**
54 * Initializes the private plugin manager object
55 * @return True; false if failed
56 */
57 bool init();
58
59 /**
60 * Finalizes the private plugin manager object
61 */
62 void done();
63
64 /**
65 * Loads and initializes plugins
66 * @return True; false if failed
67 */
68 bool loadPlugins();
69
70 /**
71 * Finalizes and unloads plugins
72 */
73 void unloadPlugins();
74
75
76 private: // Members
77
78 /// List of all the modules
79 QList<QExplicitlySharedDataPointer<Module> > mModules;
80
81 /// List of all the plugins
82 QList<QExplicitlySharedDataPointer<Plugin> > mPlugins;
83
84
85 private: // Methods
86
87 /**
88 * Returns the module object by its name
89 * @param name Name of the module
90 * @return Module object or 0 if not found
91 */
92 Module * moduleByName(QString const & name) const;
93
94 };
95
96 /**
97 * One external module implementing the iPluginFactory or the iPlugin interfaces.
98 *
99 * This class is a wrapper around the external module.
100 */
101 class Module : public QSharedData
102 {
103 public:
104
105 /**
106 * Ctr.
107 * @param name Name of the module
108 */
109 Module(QString const & name);
110
111 /// Dtr.
112 ~Module();
113
114 /// Returns true if the module is loaded
115 bool isLoaded() const { return mLoader != 0; }
116
117 /// The name of the module
118 QString const & name() const { return mName; }
119
120 /**
121 * Loads the module
122 * @return True; false if failed
123 */
124 bool load();
125
126 /// Unloads the module
127 void unload();
128
129 /**
130 * Creates the requested iPlugin interface object
131 * @param name Name of the interface
132 * @return The iPlugin interface object or 0 if failed
133 */
134 iPlugin * create(QString const & name);
135
136
137 private: // Members
138
139 /// Name of the module
140 QString mName;
141
142 /// Plugin loader
143 QPluginLoader * mLoader;
144
145 /// Plugin's root component
146 QObject * mRoot;
147
148 /// The iPlugin interface object if the module implements only one iPlugin interface
149 iPlugin * mPlugin;
150
151 /// The iPluginFactory interface object if the module implements more than one iPluginFactory interface
152 iPluginFactory * mPluginFactory;
153
154 };
155
156 /**
157 * One iPlugin interface object.
158 *
159 * This class is a wrapper around the plugin.
160 */
161 class Plugin : public QSharedData
162 {
163 public:
164
165 /**
166 * Ctr.
167 * @param module The Module implementing this iPlugin interface
168 * @param name Name of the plugin
169 * @param args Arguments for the plugin initialization
170 */
171 Plugin(Module * module, QString const & name, QString const & args);
172
173 /// Dtr.
174 ~Plugin();
175
176 /// The iPlugin interface
177 iPlugin * plugin() const { return mPlugin; }
178
179 /// The name of the plugin
180 QString const & name() const { return mName; }
181
182 /**
183 * Loads the plugin
184 * @return True; false if failed
185 */
186 bool load();
187
188 /// Unloads the plugin
189 void unload();
190
191 /**
192 * Initializes the plugin
193 * @return True; false if failed
194 */
195 bool init();
196
197 /// Uninitializes the plugin
198 void done();
199
200
201 private: // Members
202
203 /// Module implementing this iPlugin interface
204 Module * mModule;
205
206 /// Name of the plugin
207 QString mName;
208
209 /// Arguments for the initialization
210 QString mArgs;
211
212 /// The iPlugin interface object
213 iPlugin * mPlugin;
214
215 };
216
217 } // namespace eVaf::Plugins::Internal
218 } // namespace eVaf::Plugins
219 } // namespace eVaf
220
221 #endif // pluginmanager_p.h