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