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