]> vaikene.ee Git - evaf/blob - src/libs/Plugins/pluginmanager_p.h
22a0de17258cd8e6833f19ad35dcb835c8045566
[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 * Loads the Qt plugin
96 * @param Name of the Qt plugin
97 * @return True; false if failed
98 */
99 bool loadQtPlugin(QString const & name) const;
100
101 };
102
103 /**
104 * One external module implementing the iPluginFactory or the iPlugin interfaces.
105 *
106 * This class is a wrapper around the external module.
107 */
108 class Module : public QSharedData
109 {
110 public:
111
112 /**
113 * Ctr.
114 * @param name Name of the module
115 */
116 Module(QString const & name);
117
118 /// Dtr.
119 ~Module();
120
121 /// Returns true if the module is loaded
122 bool isLoaded() const { return mLoader != 0; }
123
124 /// The name of the module
125 QString const & name() const { return mName; }
126
127 /**
128 * Loads the module
129 * @return True; false if failed
130 */
131 bool load();
132
133 /// Unloads the module
134 void unload();
135
136 /**
137 * Creates the requested iPlugin interface object
138 * @param name Name of the interface
139 * @return The iPlugin interface object or 0 if failed
140 */
141 iPlugin * create(QString const & name);
142
143
144 private: // Members
145
146 /// Name of the module
147 QString mName;
148
149 /// Plugin loader
150 QPluginLoader * mLoader;
151
152 /// Plugin's root component
153 QObject * mRoot;
154
155 /// The iPlugin interface object if the module implements only one iPlugin interface
156 iPlugin * mPlugin;
157
158 /// The iPluginFactory interface object if the module implements more than one iPluginFactory interface
159 iPluginFactory * mPluginFactory;
160
161 };
162
163 /**
164 * One iPlugin interface object.
165 *
166 * This class is a wrapper around the plugin.
167 */
168 class Plugin : public QSharedData
169 {
170 public:
171
172 /**
173 * Ctr.
174 * @param module The Module implementing this iPlugin interface
175 * @param name Name of the plugin
176 * @param args Arguments for the plugin initialization
177 */
178 Plugin(Module * module, QString const & name, QString const & args);
179
180 /// Dtr.
181 ~Plugin();
182
183 /// The iPlugin interface
184 iPlugin * plugin() const { return mPlugin; }
185
186 /// The name of the plugin
187 QString const & name() const { return mName; }
188
189 /**
190 * Loads the plugin
191 * @return True; false if failed
192 */
193 bool load();
194
195 /// Unloads the plugin
196 void unload();
197
198 /**
199 * Initializes the plugin
200 * @return True; false if failed
201 */
202 bool init();
203
204 /// Uninitializes the plugin
205 void done();
206
207
208 private: // Members
209
210 /// Module implementing this iPlugin interface
211 Module * mModule;
212
213 /// Name of the plugin
214 QString mName;
215
216 /// Arguments for the initialization
217 QString mArgs;
218
219 /// The iPlugin interface object
220 iPlugin * mPlugin;
221
222 };
223
224 } // namespace eVaf::Plugins::Internal
225 } // namespace eVaf::Plugins
226 } // namespace eVaf
227
228 #endif // pluginmanager_p.h