1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: This class implements an extended wrapper for the ECOM framework. |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "xqpluginloader.h" |
|
23 #include "xqpluginloaderprivate.h" |
|
24 |
|
25 #include <qfileinfo.h> |
|
26 #include "qdebug.h" |
|
27 |
|
28 /*! |
|
29 Constructs plugin loader with the given parent. |
|
30 @param parent - address of class instance parent |
|
31 */ |
|
32 XQPluginLoader::XQPluginLoader(QObject* parent) |
|
33 : |
|
34 QObject(parent), |
|
35 d(0), |
|
36 did_load( false ) |
|
37 { |
|
38 } |
|
39 |
|
40 /*! |
|
41 Constructs plugin loader with the given parent and plugin implementation UID. |
|
42 @param uid - UID of plugin that should be loaded |
|
43 @param parent - address of class instance parent |
|
44 */ |
|
45 XQPluginLoader::XQPluginLoader(int requestedUid, QObject* parent) |
|
46 : |
|
47 QObject(parent), |
|
48 d(XQPluginLoaderPrivate::findOrCreate(requestedUid)), |
|
49 did_load( false ) |
|
50 { |
|
51 } |
|
52 |
|
53 /*! |
|
54 Destroys plugin loader. Unless unload() was called explicitly, plugins still stays in memory. |
|
55 */ |
|
56 XQPluginLoader::~XQPluginLoader() |
|
57 { |
|
58 if(d) { |
|
59 d->release(); |
|
60 } |
|
61 } |
|
62 |
|
63 /*! |
|
64 List available plugins which implement requested interface. Plugins are resolved using interface name. |
|
65 |
|
66 @param interfaceName - requested interface name |
|
67 @param impls - destination list where resolved plugins info will be stored |
|
68 @return true on success, false on any error |
|
69 */ |
|
70 bool XQPluginLoader::listImplementations( |
|
71 const QString &interfaceName, |
|
72 QList< XQPluginInfo > &impls) |
|
73 { |
|
74 RImplInfoPtrArray infoArr; |
|
75 TRAPD( errCode, XQPluginLoaderPrivate::listImplementationsL( infoArr, interfaceName, impls ) ); |
|
76 infoArr.ResetAndDestroy(); |
|
77 return ( KErrNone == errCode ); |
|
78 } |
|
79 |
|
80 /*! |
|
81 Returns UID of requested plugin. |
|
82 */ |
|
83 int XQPluginLoader::uid()const |
|
84 { |
|
85 return ( d ? d->uid : KNullUid.iUid ); |
|
86 } |
|
87 |
|
88 /*! |
|
89 Return pointer to plugin root-component instance |
|
90 @return instance address on success, 0 otherwise |
|
91 */ |
|
92 QObject* XQPluginLoader::instance() |
|
93 { |
|
94 if (!load()) |
|
95 return 0; |
|
96 #ifndef Q_OS_SYMBIAN |
|
97 if (d->instance) |
|
98 return d->instance(); |
|
99 else |
|
100 return 0; |
|
101 #else |
|
102 return d->instance(); |
|
103 #endif |
|
104 |
|
105 } |
|
106 |
|
107 /*! |
|
108 Return information if plugin have been loaded |
|
109 @return true if plugin have been loaded, false otherwise |
|
110 */ |
|
111 bool XQPluginLoader::isLoaded() const |
|
112 { |
|
113 return d && d->pHnd |
|
114 #ifndef Q_OS_SYMBIAN |
|
115 && d->instance; |
|
116 #else |
|
117 ; |
|
118 #endif |
|
119 } |
|
120 |
|
121 /*! |
|
122 Load requested plugin. |
|
123 @return true on success, false otherwise |
|
124 */ |
|
125 bool XQPluginLoader::load() |
|
126 { |
|
127 if (!d) |
|
128 return false; |
|
129 if (did_load) |
|
130 return d->pHnd; |
|
131 did_load = true; |
|
132 return d->loadPlugin(); |
|
133 } |
|
134 |
|
135 /*! |
|
136 Unloads the plugin and returns true if plugin could be unloaded. All plugins are unloaded at aplication exit |
|
137 so calling this method is not mandatory. |
|
138 Actual unloading will succed only when all instances of given plugin loaders calls unload. |
|
139 @return true on success, false otherwise |
|
140 */ |
|
141 bool XQPluginLoader::unload() |
|
142 { |
|
143 if (did_load) { |
|
144 did_load = false; |
|
145 return d->unload(); |
|
146 } |
|
147 if (d) // Ouch |
|
148 d->errorString = tr("The plugin was not loaded."); |
|
149 return false; |
|
150 } |
|
151 |
|
152 /*! |
|
153 Setter for UID of plugin. It is the same UID that may be specified in constructor. |
|
154 */ |
|
155 void XQPluginLoader::setUid ( int uid ) |
|
156 { |
|
157 if (d) { |
|
158 d->release(); |
|
159 d = 0; |
|
160 did_load = false; |
|
161 } |
|
162 d = XQPluginLoaderPrivate::findOrCreate( uid ); |
|
163 } |
|
164 |
|
165 /*! |
|
166 Return string.with description of last error that occured. |
|
167 @return error description |
|
168 */ |
|
169 QString XQPluginLoader::errorString () const |
|
170 { |
|
171 return (!d || d->errorString.isEmpty()) ? tr("Unknown error") : d->errorString; |
|
172 } |
|