147 SmfPluginRequestData reqData; |
161 SmfPluginRequestData reqData; |
148 |
162 |
149 // check if the plugin is authorised (with CSM) |
163 // check if the plugin is authorised (with CSM) |
150 if( authorisePlugin(regToken, urlList )) |
164 if( authorisePlugin(regToken, urlList )) |
151 { |
165 { |
152 m_server->writeLog("Plugin authorised"); |
166 qDebug()<<"Plugin authorised"; |
153 |
167 |
154 // call the utility method to create plugin specific request |
168 // call the utility method to create plugin specific request |
|
169 result = SmfUnknownError; |
155 m_util->createRequest(plugin, aOperation, aInputData, reqData, result); |
170 m_util->createRequest(plugin, aOperation, aInputData, reqData, result); |
156 |
171 |
157 // If the request is created successfully, call the TM method to send the request |
172 // If the request is created successfully, call the TM method to send the request |
158 if( SmfPluginRequestCreated == result ) |
173 if( SmfNoError == result ) |
159 { |
174 { |
160 m_server->writeLog("Plugin request creation successful"); |
175 qDebug()<<"Plugin request creation successful"; |
161 m_tempStruct = new SmfWaitingPluginInfoStruc(); |
176 m_tempStruct = new SmfWaitingPluginInfoStruc(); |
162 m_tempStruct->iSessionID = aSessionID; |
177 m_tempStruct->iSessionID = aSessionID; |
163 m_tempStruct->iPluginId = aPluginID; |
178 m_tempStruct->iPluginId = aPluginID; |
164 m_tempStruct->iInstance = instance; |
179 m_tempStruct->iInstance = instance; |
165 m_tempStruct->iOperation = aOperation; |
180 m_tempStruct->iOperation = aOperation; |
166 m_tempStruct->iInputData = aInputData; |
181 m_tempStruct->iInputData = aInputData; |
167 m_tempStruct->iUrlList = urlList; |
|
168 |
182 |
169 // send the request |
183 // send the request |
170 sendRequest ( reqData, result, urlList ); |
184 sendRequest ( reqData, result, urlList ); |
171 } |
185 } |
|
186 else |
|
187 qDebug()<<"Plugin request creation failed!!!, error = "<<result; |
172 } |
188 } |
173 |
189 |
174 else |
190 else |
175 { |
191 { |
176 // plugin not authorised, so unload |
192 // plugin not authorised, so unload |
177 m_server->writeLog("Plugin not authorised!!!"); |
193 qDebug()<<"Plugin not authorised!!!"; |
178 unload(instance); |
194 unload(instance); |
179 result = SmfPluginNotAuthorised; |
195 result = SmfPMPluginNotAuthorised; |
180 } |
196 } |
181 } |
197 } |
182 else |
198 else |
183 { |
199 { |
184 // plugin instance cannot be casted, so unload |
200 // plugin instance cannot be casted, so unload |
185 m_server->writeLog("Plugin instance cannot be casted to SmfPluginBase*!!!"); |
201 qDebug()<<"Plugin instance cannot be casted to SmfPluginBase*!!!"; |
186 unload(instance); |
202 unload(instance); |
187 result = SmfPluginLoadError; |
203 result = SmfPMPluginLoadError; |
188 } |
204 } |
189 } |
205 } |
190 |
206 |
191 else |
207 else |
192 { |
208 { |
193 // plugin not loaded |
209 // plugin not loaded |
194 m_server->writeLog("Plugin not loaded!!!"); |
210 qDebug()<<"Plugin not loaded!!!"; |
195 result = SmfPluginLoadError; |
|
196 } |
211 } |
197 |
212 |
198 return result; |
213 return result; |
199 } |
214 } |
200 |
215 |
209 void SmfPluginManager::responseAvailable ( |
224 void SmfPluginManager::responseAvailable ( |
210 const SmfTransportResult &aTransportResult, |
225 const SmfTransportResult &aTransportResult, |
211 QNetworkReply *aReply, |
226 QNetworkReply *aReply, |
212 QByteArray *aResponse ) |
227 QByteArray *aResponse ) |
213 { |
228 { |
214 m_server->writeLog("Inside SmfPluginManager::responseAvailable()"); |
229 qDebug()<<"Inside SmfPluginManager::responseAvailable()"; |
215 |
230 |
216 // For request success or For request cancellation |
231 // get the details of the plugin which made this request |
217 if((SmfTransportOpNoError == aTransportResult) || |
232 SmfWaitingPluginInfoStruc* info = NULL; |
218 (SmfTransportOpOperationCanceledError == aTransportResult)) |
233 info = m_waitingPluginHash.value(aReply); |
219 { |
234 |
220 m_server->writeLog("no transport error/ cancellation"); |
235 if(info) |
221 |
236 { |
222 // get the details of the plugin which made this request |
|
223 SmfWaitingPluginInfoStruc* info = m_waitingPluginHash.value(aReply); |
|
224 quint32 sessionId = m_waitingPluginHash.value(aReply)->iSessionID; |
237 quint32 sessionId = m_waitingPluginHash.value(aReply)->iSessionID; |
225 QString pluginId = m_waitingPluginHash.value(aReply)->iPluginId; |
238 QString pluginId = m_waitingPluginHash.value(aReply)->iPluginId; |
226 SmfRequestTypeID operation = m_waitingPluginHash.value(aReply)->iOperation; |
239 SmfRequestTypeID operation = m_waitingPluginHash.value(aReply)->iOperation; |
227 QByteArray inputData = m_waitingPluginHash.value(aReply)->iInputData; |
240 QByteArray inputData = m_waitingPluginHash.value(aReply)->iInputData; |
228 |
241 |
229 QVariant result; |
242 QVariant result; |
230 SmfPluginRetType retType = SmfRequestError; |
243 SmfPluginRetType retType = SmfRequestError; |
231 SmfResultPage pageResult; |
244 SmfResultPage pageResult; |
232 |
245 |
233 m_server->writeLog("Before m_util->responseAvailable"); |
|
234 |
|
235 // call the utility method to send response to appropriate plugins |
246 // call the utility method to send response to appropriate plugins |
236 SmfPluginManagerResult retValue = m_util->responseAvailable( info->iInstance, operation, |
247 SmfError retValue = m_util->responseAvailable( info->iInstance, operation, |
237 aTransportResult, aResponse, &result, retType, pageResult ); |
248 aTransportResult, aResponse, &result, retType, pageResult ); |
238 |
249 |
|
250 qDebug()<<"m_util->responseAvailable() return = "<<retValue; |
|
251 |
239 // remove the plugin from the waiting list |
252 // remove the plugin from the waiting list |
240 delete m_waitingPluginHash.value(aReply); |
253 delete m_waitingPluginHash.value(aReply); |
241 m_waitingPluginHash.remove(aReply); |
254 m_waitingPluginHash.remove(aReply); |
242 |
255 |
243 QByteArray arr; |
256 QByteArray arr; |
244 QDataStream stream(&arr, QIODevice::ReadWrite); |
257 QDataStream stream(&arr, QIODevice::ReadWrite); |
245 if( SmfPluginResponseParsed == retValue ) |
258 |
|
259 if( SmfNoError == retValue ) |
246 { |
260 { |
247 m_server->writeLog("Parsing successful"); |
261 qDebug()<<"Parsing of response is successful"; |
248 |
262 |
249 // serialize the response to suitable class and pass the data to server |
263 // serialize the response to suitable class and pass the data to server |
250 serializeResult(operation, &result, stream); |
264 serializeResult(operation, &result, stream); |
251 |
265 |
252 ////TODO:- send error in enums-by manasij |
|
253 // Send the response data to the server |
266 // Send the response data to the server |
254 m_server->resultsAvailable(sessionId, &arr, SmfNoError); |
267 m_server->resultsAvailable(sessionId, &arr, retValue); |
255 } |
268 } |
256 |
269 |
257 // Send the request again |
270 // Send the request again |
258 else if( SmfPluginSendRequestAgain == retValue ) |
271 else if( SmfPMPluginSendRequestAgain == retValue ) |
259 { |
272 { |
260 m_server->writeLog("Send request again"); |
273 qDebug()<<"Send request again"; |
261 |
|
262 // create the request again (with same paramaters) |
|
263 retValue = createRequest( sessionId, pluginId, operation, inputData ); |
274 retValue = createRequest( sessionId, pluginId, operation, inputData ); |
264 } |
275 } |
265 |
276 |
266 // Error |
277 // Error |
267 else |
278 else |
268 { |
279 { |
269 m_server->writeLog("Parsing failed!!"); |
280 qDebug()<<"Plugin responseAvailable() failed!!!, error = "<<retValue; |
270 |
281 |
271 // Error in parsing, sent to server |
282 // Error in parsing, sent to server |
272 m_server->resultsAvailable(sessionId, &arr, SmfpluginResponseParseFailure); |
283 // ToDo :- For testing:- |
273 } |
284 stream<<result.toString(); |
274 |
285 m_server->resultsAvailable(sessionId, &arr, retValue); |
275 // delete aReply later, when event loop is re-entered |
286 } |
276 aReply->deleteLater(); |
287 } |
277 } |
|
278 |
|
279 // Any other error |
|
280 else |
288 else |
281 { |
289 qDebug()<<"No outstanding requests for this QNetworkReply!!!"; |
282 m_server->writeLog("Error in SmfPluginManager::responseAvailable, Transport failure code : "); |
290 |
283 QString err = QString::number(aTransportResult); |
291 // delete aReply later, when event loop is re-entered |
284 m_server->writeLog(err); |
292 aReply->deleteLater(); |
285 |
293 } |
286 //Added by manasij, send all kind of errors to the server |
294 |
287 //TODO:- to be refined by PM owner |
|
288 quint32 sessionId = m_waitingPluginHash.value(aReply)->iSessionID; |
|
289 QByteArray arr; |
|
290 m_server->resultsAvailable(sessionId, &arr, SmftransportInitNetworkNotAvailable); |
|
291 } |
|
292 } |
|
293 |
|
294 |
295 |
295 /** |
296 /** |
296 * Method to cancel the service request |
297 * Method to cancel the service request |
297 * @param aPluginId The plugin whose current operation |
298 * @param aPluginId The plugin whose current operation is to be cancelled. |
298 * is to be cancelled |
299 * If the plugin is not loaded currently, this method just returns true. |
|
300 * @return Returns true if the plugin operation could be cancelled |
|
301 * else returns false. |
299 */ |
302 */ |
300 bool SmfPluginManager::cancelRequest ( const QString& aPluginId ) |
303 bool SmfPluginManager::cancelRequest ( const QString& aPluginId ) |
301 { |
304 { |
302 bool retValue = false; |
305 bool retValue = true; |
303 m_server->writeLog("Inside SmfPluginManager::cancelRequest()"); |
306 qDebug()<<"Inside SmfPluginManager::cancelRequest()"; |
304 |
307 |
305 // Get the plugin for which cancel is requested |
308 // Get the plugin for which cancel is requested |
306 foreach(SmfWaitingPluginInfoStruc* iPluginInfo, m_waitingPluginHash.values()) |
309 foreach(SmfWaitingPluginInfoStruc* iPluginInfo, m_waitingPluginHash.values()) |
307 { |
310 { |
308 if( 0 == iPluginInfo->iPluginId.compare(aPluginId)) |
311 if( 0 == iPluginInfo->iPluginId.compare(aPluginId)) |
309 { |
312 { |
310 m_server->writeLog("Plugin to be cancelled found in the waiting list"); |
313 qDebug()<<"Plugin to be cancelled found in the waiting list"; |
311 |
314 |
312 // Notify Transport Manager |
315 // Notify Transport Manager |
313 m_transMngrUtil->cancelRequest(m_waitingPluginHash.key(iPluginInfo)); |
316 m_transMngrUtil->cancelRequest(m_waitingPluginHash.key(iPluginInfo)); |
314 |
317 |
315 // Notify the plugin that the request has been cancelled |
318 } |
316 SmfPluginRetType retType; |
|
317 SmfResultPage pageResult; |
|
318 SmfPluginError ret = iPluginInfo->iInstance->responseAvailable( SmfTransportOpCancelled, |
|
319 NULL, NULL, retType, pageResult ); |
|
320 |
|
321 // Remove that plugin from the waiting list |
|
322 delete (m_waitingPluginHash.value(m_waitingPluginHash.key(iPluginInfo))); |
|
323 m_waitingPluginHash.remove(m_waitingPluginHash.key(iPluginInfo)); |
|
324 |
|
325 if(SmfPluginErrNone == ret) |
|
326 retValue = true; |
|
327 } |
|
328 //else , cancel requested for a plugin which is not loaded, do nothing |
|
329 else |
319 else |
330 { |
320 retValue = true; |
331 m_server->writeLog("Plugin to be cancelled not found in the waiting list!!! - do nothing"); |
|
332 retValue = false; |
|
333 } |
|
334 } |
321 } |
335 return retValue; |
322 return retValue; |
336 } |
323 } |
337 |
324 |
338 |
325 |
399 "description TEXT, serviceUrl TEXT, authAppId TEXT)"); |
397 "description TEXT, serviceUrl TEXT, authAppId TEXT)"); |
400 |
398 |
401 // Error - table not created, Plugin Manager might not work properly |
399 // Error - table not created, Plugin Manager might not work properly |
402 if(!tableCreated) |
400 if(!tableCreated) |
403 { |
401 { |
404 m_server->writeLog("Table not created, error = "+query.lastError().text()); |
402 qDebug()<<"Table not created!!!, error = "<<query.lastError().text(); |
|
403 |
|
404 // Close the database |
|
405 m_pluginDataBase.close(); |
405 return false; |
406 return false; |
406 } |
407 } |
407 |
408 |
408 m_server->writeLog("Table created"); |
409 qDebug()<<"Table created"; |
409 |
410 |
410 // Get the directory having the Qt plugin stubs |
411 // Get the directory having the Qt plugin stubs |
411 QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath)); |
412 QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath)); |
412 |
413 |
413 // If Smf folder exists |
414 // If Smf folder exists |
414 if(dir.cd("smf/plugin")) |
415 if(dir.cd("smf/plugin")) |
415 { |
416 { |
416 m_server->writeLog("Smf/plugin folder exists"); |
417 qDebug()<<"Smf/plugin folder exists"; |
417 // Get each interface folders names |
418 // Get each interface folders names |
418 foreach(QString intfName, dir.entryList(QDir::AllDirs)) |
419 foreach(QString intfName, dir.entryList(QDir::AllDirs)) |
419 { |
420 { |
420 dir.cd(intfName); |
421 dir.cd(intfName); |
421 m_server->writeLog("Interface name : "+dir.dirName()); |
422 qDebug()<<"Interface name : "<<dir.dirName(); |
422 |
423 |
423 // Get each plugin in this folder |
424 // Get each plugin in this folder |
424 foreach(QString pluginName, dir.entryList(QDir::Files)) |
425 foreach(QString pluginName, dir.entryList(QDir::Files)) |
425 { |
426 { |
426 m_server->writeLog("plugins for this Interface : "+pluginName); |
427 qDebug()<<"plugins for this Interface : "<<pluginName; |
427 |
428 |
428 // load this plugin |
429 // load this plugin |
429 QPluginLoader pluginLoader(dir.absoluteFilePath(pluginName)); |
430 QPluginLoader pluginLoader(dir.absoluteFilePath(pluginName)); |
430 QObject *instance = pluginLoader.instance(); |
431 QObject *instance = pluginLoader.instance(); |
431 if (instance) |
432 if (instance) |
432 { |
433 { |
433 m_server->writeLog("instance found"); |
434 qDebug()<<"instance found"; |
434 SmfPluginBase* plugin = qobject_cast<SmfPluginBase *>(instance); |
435 SmfPluginBase* plugin = qobject_cast<SmfPluginBase *>(instance); |
435 if (plugin) |
436 if (plugin) |
436 { |
437 { |
437 m_server->writeLog("SmfPluginBase found"); |
438 qDebug()<<"SmfPluginBase found"; |
438 plugin->initialize(SmfPluginUtil::getInstance()); |
439 plugin->initialize(SmfPluginUtil::getInstance()); |
439 |
440 |
440 // get the plugin id |
441 // get the plugin id |
441 QString id = plugin->getProviderInfo()->pluginId(); |
442 QString id = plugin->getProviderInfo()->pluginId(); |
442 |
443 |
443 // get the interface implemented by the plugin |
444 // get the interface implemented by the plugin |
444 QString intfImplemented = dir.dirName(); |
445 QString intfImplemented = dir.dirName(); |
445 intfImplemented.prepend("org.symbian.smf.plugin."); |
446 intfImplemented.prepend("org.symbian.smf.plugin."); |
446 m_server->writeLog("intfImplemented="); |
447 qDebug()<<"intfImplemented = "<<intfImplemented; |
447 m_server->writeLog(intfImplemented); |
|
448 |
448 |
449 // get the service provider |
449 // get the service provider |
450 QString serProv = plugin->getProviderInfo()->serviceName(); |
450 QString serProv = plugin->getProviderInfo()->serviceName(); |
451 |
451 |
452 //get the description |
452 //get the description |
515 |
516 |
516 /** |
517 /** |
517 * Method to load a plugin using its Plugin Id. |
518 * Method to load a plugin using its Plugin Id. |
518 * @param aPluginId The unique ID of the plugin |
519 * @param aPluginId The unique ID of the plugin |
519 * @param aLoadResult [out] Output paramater indicating the result |
520 * @param aLoadResult [out] Output paramater indicating the result |
520 * of the loading |
521 * of the loading. It can be:- |
|
522 * SmfPluginNoError (if plugin was loaded successfully) or |
|
523 * SmfPluginNotFound (if plugin with the given id could not be found) |
|
524 * SmfPluginNotLoaded (if plugin could not be loaded) or |
521 * @return The instance of the loaded plugin if loaded, else NULL |
525 * @return The instance of the loaded plugin if loaded, else NULL |
522 */ |
526 */ |
523 QObject* SmfPluginManager::load ( const QString &aPluginId, |
527 QObject* SmfPluginManager::load ( const QString &aPluginId, |
524 SmfPluginManagerResult &aLoadResult) |
528 SmfError &aLoadResult) |
525 { |
529 { |
526 m_server->writeLog("Inside SmfPluginManager::load()"); |
530 qDebug()<<"Inside SmfPluginManager::load()"; |
527 |
|
528 QPluginLoader *pluginLoader = 0; |
|
529 |
531 |
530 // Find the plugin Path |
532 // Find the plugin Path |
531 QString pluginPath = m_pluginIdPathHash.value(aPluginId); |
533 QString pluginPath = m_pluginIdPathHash.value(aPluginId); |
532 |
534 |
533 if(!pluginPath.isEmpty()) |
535 if(!pluginPath.isEmpty()) |
534 { |
536 { |
535 // create the plugin loader and load the plugin |
537 // create the plugin loader and load the plugin |
|
538 QPluginLoader *pluginLoader = NULL; |
536 pluginLoader = new QPluginLoader(pluginPath); |
539 pluginLoader = new QPluginLoader(pluginPath); |
|
540 if(!pluginLoader) |
|
541 { |
|
542 // Plugin loader could not be created, error |
|
543 qDebug()<<"QPluginLoader allocation failed!!!"; |
|
544 aLoadResult = SmfPMPluginNotLoaded; |
|
545 return NULL; |
|
546 } |
|
547 |
537 SmfPluginBase *plugin = qobject_cast<SmfPluginBase *>(pluginLoader->instance()); |
548 SmfPluginBase *plugin = qobject_cast<SmfPluginBase *>(pluginLoader->instance()); |
538 |
549 |
539 // If the plugin is loaded |
550 // If the plugin is loaded |
540 if( pluginLoader->isLoaded() && plugin ) |
551 if( pluginLoader->isLoaded() && plugin ) |
541 { |
552 { |
542 // Initialize the plugin |
553 // Initialize the plugin |
543 plugin->initialize(SmfPluginUtil::getInstance()); |
554 plugin->initialize(SmfPluginUtil::getInstance()); |
544 |
555 |
545 // update the plugin loader and the loaded plugin lists |
556 // update the plugin loader and the loaded plugin lists |
546 m_pluginLoaderHash.insertMulti(plugin, pluginLoader); |
557 m_pluginLoaderHash.insertMulti(plugin, pluginLoader); |
547 aLoadResult = SmfPluginLoaded; |
558 aLoadResult = SmfNoError; |
548 m_server->writeLog("Plugin loaded"); |
559 qDebug()<<"Plugin loaded"; |
|
560 return pluginLoader->instance(); |
549 } |
561 } |
550 else |
562 else |
551 { |
563 { |
552 m_server->writeLog("Plugin not loaded"); |
|
553 |
|
554 // Plugin could not be loaded, error |
564 // Plugin could not be loaded, error |
555 aLoadResult = SmfPluginNotLoaded; |
565 qDebug()<<"Plugin not loaded!!!, error = "<<pluginLoader->errorString(); |
|
566 aLoadResult = SmfPMPluginNotLoaded; |
|
567 return NULL; |
556 } |
568 } |
557 } |
569 } |
558 else |
570 else |
559 { |
571 { |
560 m_server->writeLog("Plugin not found"); |
572 // plugin could not be found in the hash maintained by PM |
561 |
573 qDebug()<<"Plugin not found!!!"; |
562 // plugin not found in hash |
574 aLoadResult = SmfPMPluginNotFound; |
563 aLoadResult = SmfPluginNotFound; |
575 return NULL; |
564 } |
576 } |
565 |
|
566 return pluginLoader->instance(); |
|
567 } |
577 } |
568 |
578 |
569 |
579 |
570 /** |
580 /** |
571 * Method to unload a loaded plugin. Returns true if success, else |
581 * Method to unload a loaded plugin. Returns true if success, else |
572 * returns false. |
582 * returns false. |
573 * @param aPlugin The plugin instance to be unloaded |
583 * @param aPlugin The plugin instance to be unloaded |
574 * @return Returns true if success, else returns false |
584 * @return Returns true if the mentioned plugin could be unloaded. Returns |
|
585 * false, if the plugin instance is NULL, or if it could not be unloaded. |
575 */ |
586 */ |
576 bool SmfPluginManager::unload ( SmfPluginBase *aPlugin ) |
587 bool SmfPluginManager::unload ( SmfPluginBase *aPlugin ) |
577 { |
588 { |
578 m_server->writeLog("Inside SmfPluginManager::unload()"); |
589 qDebug()<<"Inside SmfPluginManager::unload()"; |
579 |
590 bool unloadResult = true; |
580 // Get all the loaders for this plugin |
591 |
581 QList<QPluginLoader*> loaderList = m_pluginLoaderHash.values(aPlugin); |
592 if(aPlugin) |
|
593 { |
|
594 // Get all the loaders for this plugin |
|
595 QList<QPluginLoader*> loaderList = m_pluginLoaderHash.values(aPlugin); |
|
596 if(loaderList.size()) |
|
597 { |
|
598 foreach(QPluginLoader *loader, loaderList) |
|
599 { |
|
600 // for each loader unload the plugin |
|
601 unloadResult = loader->unload(); |
|
602 |
|
603 // delete the instance of the loader |
|
604 delete loader; |
|
605 loader = NULL; |
|
606 } |
|
607 |
|
608 // Remove the plugin and its associated loaders from the Hash |
|
609 m_pluginLoaderHash.remove(aPlugin); |
|
610 return unloadResult; |
|
611 } |
|
612 } |
|
613 else |
|
614 { |
|
615 qDebug()<<"Plugin instance is NULL!!!"; |
|
616 unloadResult = false; |
|
617 } |
|
618 |
|
619 return unloadResult; |
|
620 } |
|
621 |
|
622 |
|
623 /** |
|
624 * Method to unload the list of loaded plugins. Returns true if all unload |
|
625 * are success, else returns false if any one fails. |
|
626 * @param aPluginList The list of instances for all plugins that are |
|
627 * to be unloaded. This method does nothing and returns false if the list is empty. |
|
628 * @return Returns true if all are success, else returns false if any |
|
629 * one fails. Also returns false if the input list is empty. |
|
630 */ |
|
631 bool SmfPluginManager::unload ( const QList<SmfPluginBase *> &aPluginList) |
|
632 { |
|
633 qDebug()<<"Inside SmfPluginManager::unload() - overloaded fn"; |
582 bool unloaded = false; |
634 bool unloaded = false; |
583 |
635 |
584 foreach(QPluginLoader *loader, loaderList) |
636 if(aPluginList.size()) |
585 { |
637 { |
586 // for each loader unload the plugin |
638 //unload all the required plugins |
587 unloaded = loader->unload(); |
639 foreach(SmfPluginBase *plugin, aPluginList) |
588 |
640 { |
589 // delete the instance of the loader |
641 // unload individual plugins in the list |
590 delete loader; |
642 bool ret = unload(plugin); |
591 loader = NULL; |
643 |
592 } |
644 // indicate error if any one of the plugin failed to unload |
593 |
645 if(!ret) |
594 // Remove the plugin and its associated loaders from the Hash |
646 unloaded = ret; |
595 m_pluginLoaderHash.remove(aPlugin); |
647 } |
596 return unloaded; |
|
597 } |
|
598 |
|
599 |
|
600 /** |
|
601 * Method to unload the list of loaded plugins. Returns true if all are |
|
602 * success, else returns false if any one fails. |
|
603 * @param aPluginList The list of instances for all plugins that are |
|
604 * to be unloaded |
|
605 * @return Returns true if all are success, else returns false if any |
|
606 * one fails. |
|
607 */ |
|
608 bool SmfPluginManager::unload ( const QList<SmfPluginBase *> &aPluginList) |
|
609 { |
|
610 m_server->writeLog("Inside SmfPluginManager::unload() - overloaded fn"); |
|
611 //unload all the required plugins |
|
612 bool unloaded = true; |
|
613 |
|
614 foreach(SmfPluginBase *plugin, aPluginList) |
|
615 { |
|
616 // unload individual plugins in the list |
|
617 bool ret = unload(plugin); |
|
618 |
|
619 // indicate error if any one of the plugin failed to unload |
|
620 if(!ret) |
|
621 unloaded = ret; |
|
622 } |
648 } |
623 return unloaded; |
649 return unloaded; |
624 } |
650 } |
625 |
651 |
626 |
652 |
627 /** |
653 /** |
628 * Method that calls the Transport Manager Utility class method to |
654 * Method that calls the Transport Manager Utility class method to |
629 * send the request created by the plugins over the network |
655 * send the request created by the plugins over the network |
630 * @param aReqData The request data created by the plugin |
656 * @param aReqData The request data created by the plugin |
631 * @param aResult [out] The output parameter indicating the result |
657 * @param aResult [out] The output parameter indicating the result |
632 * of this method |
658 * of this method. This can be :- |
|
659 * SmfPluginNoError (if the request is sent successfully) or |
|
660 * SmfPluginSOPCheckFailed (if plugins request doesnot comply to |
|
661 * the Same Origin Policy) or |
|
662 * SmfPluginRequestSendingFailed (if request could not be sent) or |
|
663 * SmfPluginUnknownHttpService (if the plugin requested any unknown http |
|
664 * method other than get, post, put, head or delete) |
633 * @param aUrlList The list of accessible Urls for this plugin |
665 * @param aUrlList The list of accessible Urls for this plugin |
634 * @see smfglobal.h |
|
635 */ |
666 */ |
636 void SmfPluginManager::sendRequest ( SmfPluginRequestData &aReqData, |
667 void SmfPluginManager::sendRequest ( SmfPluginRequestData &aReqData, |
637 SmfPluginManagerResult &aResult, |
668 SmfError &aResult, |
638 const QList<QUrl> &aUrlList ) |
669 const QList<QUrl> &aUrlList ) |
639 { |
670 { |
640 m_server->writeLog("Inside SmfPluginManager::sendRequest()"); |
671 qDebug()<<"Inside SmfPluginManager::sendRequest()"; |
641 |
672 |
642 QNetworkReply* reply; |
673 QNetworkReply* reply; |
643 bool sopCompliant = false; |
674 bool sopCompliant = false; |
644 |
675 |
645 // Check the type of Http operation to be performed |
676 // Check the type of Http operation to be performed |
646 switch(aReqData.iHttpOperationType) |
677 switch(aReqData.iHttpOperationType) |
647 { |
678 { |
648 // Http HEAD |
679 // Http HEAD |
649 case QNetworkAccessManager::HeadOperation: |
680 case QNetworkAccessManager::HeadOperation: |
|
681 qDebug()<<"http::head Operation requested"; |
650 reply = m_transMngrUtil->head(aReqData.iNetworkRequest, aUrlList, sopCompliant); |
682 reply = m_transMngrUtil->head(aReqData.iNetworkRequest, aUrlList, sopCompliant); |
651 break; |
683 break; |
652 |
684 |
653 // Http GET |
685 // Http GET |
654 case QNetworkAccessManager::GetOperation: |
686 case QNetworkAccessManager::GetOperation: |
|
687 qDebug()<<"http::get Operation requested"; |
655 reply = m_transMngrUtil->get(aReqData.iNetworkRequest, aUrlList, sopCompliant); |
688 reply = m_transMngrUtil->get(aReqData.iNetworkRequest, aUrlList, sopCompliant); |
656 break; |
689 break; |
657 |
690 |
658 // Http PUT |
691 // Http PUT |
659 case QNetworkAccessManager::PutOperation: |
692 case QNetworkAccessManager::PutOperation: |
|
693 qDebug()<<"http::put Operation requested"; |
660 reply = m_transMngrUtil->put(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant); |
694 reply = m_transMngrUtil->put(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant); |
|
695 delete aReqData.iPostData; |
661 break; |
696 break; |
662 |
697 |
663 // Http POST |
698 // Http POST |
664 case QNetworkAccessManager::PostOperation: |
699 case QNetworkAccessManager::PostOperation: |
|
700 qDebug()<<"http::post Operation requested"; |
665 reply = m_transMngrUtil->post(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant); |
701 reply = m_transMngrUtil->post(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant); |
|
702 delete aReqData.iPostData; |
666 break; |
703 break; |
667 |
704 |
668 // Http DELETE |
705 // Http DELETE |
669 case QNetworkAccessManager::DeleteOperation: |
706 case QNetworkAccessManager::DeleteOperation: |
|
707 qDebug()<<"http::delete Operation requested"; |
670 reply = m_transMngrUtil->deleteResource(aReqData.iNetworkRequest, aUrlList, sopCompliant); |
708 reply = m_transMngrUtil->deleteResource(aReqData.iNetworkRequest, aUrlList, sopCompliant); |
671 break; |
709 break; |
672 |
710 |
673 default: |
711 default: |
674 aResult = SmfPluginUnknownService; |
712 qDebug()<<"unknown http Operation requested!!!"; |
|
713 aResult = SmfPMPluginUnknownHttpService; |
675 return; |
714 return; |
676 } |
715 } |
677 |
716 |
678 if( sopCompliant ) |
717 if( sopCompliant ) |
679 { |
718 { |
680 if( reply ) |
719 if( reply ) |
681 { |
720 { |
682 // SOP compliant, sending successful |
721 // SOP compliant, sending successful |
|
722 qDebug()<<"No error, request sent"; |
683 m_waitingPluginHash.insert(reply, m_tempStruct); |
723 m_waitingPluginHash.insert(reply, m_tempStruct); |
684 m_tempStruct = NULL; |
724 m_tempStruct = NULL; |
685 aResult = SmfPluginNoError; |
725 aResult = SmfNoError; |
686 |
726 } |
687 m_server->writeLog("No error, request sent"); |
|
688 |
|
689 } |
|
690 // reply is NULL, sending failed |
|
691 else |
727 else |
692 { |
728 { |
693 m_server->writeLog("QNEtrworkReply returned error - not sent"); |
729 // reply is NULL, sending failed |
694 aResult = SmfPluginRequestSendingFailed; |
730 qDebug()<<"QNetworkReply returned NULL - request not sent"; |
695 } |
731 aResult = SmfPMPluginRequestSendingFailed; |
696 } |
732 } |
697 |
733 } |
698 // SOP violation |
734 |
699 else |
735 else |
700 { |
736 { |
701 m_server->writeLog("SOP checking failed"); |
737 // SOP violation |
702 aResult = SmfPluginSOPCheckFailed; |
738 qDebug()<<"SOP checking failed"; |
703 } |
739 aResult = SmfPMPluginSOPCheckFailed; |
|
740 } |
704 } |
741 } |
705 |
742 |
706 |
743 |
707 /** |
744 /** |
708 * Method that checks if a plugin is authorised to make a request. |
745 * Method that checks if a plugin is authorised to make a request. |
709 * This method communicates with Credential and Settings Manager |
746 * This method communicates with Credential and Settings Manager |
710 * through Smf server, giving the registration token and getting |
747 * through Smf server, giving the registration token and getting |
711 * the valid url list if available for this plugin. |
748 * the valid url list if available for this plugin. |
712 * @param aRegToken The registration token given by the plugin |
749 * @param aRegToken The registration token given by the plugin |
713 * @param aUrlList [out] The list of Urls that the plugin can send |
750 * @param aUrlList [out] The list of Urls that the plugin can send |
714 * request to (to be filled by CSM) |
751 * request to (to be filled by CSM). This list will be empty if |
|
752 * aRegToken is empty |
715 * @return Returns true if plugin is authorised, else returns false. |
753 * @return Returns true if plugin is authorised, else returns false. |
|
754 * Also returns false if aRegToken is empty. |
716 */ |
755 */ |
717 bool SmfPluginManager::authorisePlugin( const QString &aRegToken, |
756 bool SmfPluginManager::authorisePlugin( const QString &aRegToken, |
718 QList<QUrl> &aUrlList ) |
757 QList<QUrl> &aUrlList ) |
719 { |
758 { |
720 Q_UNUSED(aRegToken) |
759 Q_UNUSED(aRegToken) |
721 m_server->writeLog("Inside SmfPluginManager::authorisePlugin()"); |
760 qDebug()<<"Inside SmfPluginManager::authorisePlugin()"; |
722 |
761 |
723 #ifdef CSM_INTEGRATED |
762 #ifdef CSM_INTEGRATED |
|
763 aUrlList.clear(); |
|
764 |
724 // Get the valid URL list from CSM, giving the reg token |
765 // Get the valid URL list from CSM, giving the reg token |
725 if(m_server->authorisePlugin(aRegToken, aUrlList)) |
766 if(aRegToken.size()) |
726 return true; |
767 return m_server->authorisePlugin(aRegToken, aUrlList); |
727 else |
768 else |
728 return false; |
769 return false; |
729 |
|
730 #else |
770 #else |
|
771 |
731 // CSM STUBBING - start |
772 // CSM STUBBING - start |
732 QUrl url1 ("http://www.example.com"); |
773 QUrl url1 ("http://www.example.com"); |
733 QUrl url2 ("http://api.facebook.com"); |
774 QUrl url2 ("http://api.facebook.com"); |
734 QUrl url3 ("http://api.flickr.com"); |
775 QUrl url3 ("http://api.flickr.com"); |
735 |
776 |
953 |
1016 |
954 /** |
1017 /** |
955 * Method to get the list of the SmfProvider for all the plugins that implement |
1018 * Method to get the list of the SmfProvider for all the plugins that implement |
956 * the mentioned Interface |
1019 * the mentioned Interface |
957 * @param aInterface The interface for which list of plugins is required |
1020 * @param aInterface The interface for which list of plugins is required |
958 * @param aMap The map of pluginID and its corresponding SmfProvider |
1021 * @param aMap The map of pluginID and its corresponding SmfProvider. The Map |
|
1022 * will be empty if no plugins for the given interface could be found. |
959 */ |
1023 */ |
960 void SmfPluginManager::getPlugins(const QString& aInterface, QMap<QString,SmfProvider>& aMap) |
1024 void SmfPluginManager::getPlugins(const QString& aInterface, QMap<QString,SmfProvider>& aMap) |
961 { |
1025 { |
962 m_server->writeLog("Inside SmfPluginManager::getPlugins()"); |
1026 qDebug()<<"Inside SmfPluginManager::getPlugins()"; |
|
1027 qDebug()<<"Argument, intf name = "<<aInterface; |
|
1028 |
|
1029 aMap.clear(); |
|
1030 |
|
1031 if(aInterface.isEmpty()) |
|
1032 { |
|
1033 qDebug()<<"Interface name is empty!!!"; |
|
1034 return; |
|
1035 } |
963 |
1036 |
964 // Open the database |
1037 // Open the database |
965 bool opened = m_pluginDataBase.open(); |
1038 bool opened = m_pluginDataBase.open(); |
966 if(!opened) |
1039 if(!opened) |
967 { |
1040 { |
968 m_server->writeLog("Data base not opened, exiting getplugins()"); |
1041 qDebug()<<"Data base not opened, exiting getplugins()!!!"; |
969 return; |
1042 return; |
970 } |
1043 } |
971 |
1044 |
972 m_server->writeLog("Data base opened"); |
1045 qDebug()<<"Data base opened"; |
973 |
1046 |
974 // Query the database for all pluginIDs that implement the given interface |
1047 // Query the database for all pluginIDs that implement the given interface |
975 QSqlQuery query(QString("SELECT pluginId, interfaceName, serviceProvider, description, " |
1048 QSqlQuery query(QString("SELECT pluginId, interfaceName, serviceProvider, description, " |
976 "serviceUrl FROM pluginDetails where interfaceName = '%1'").arg(aInterface)); |
1049 "serviceUrl FROM pluginDetails where interfaceName = '%1'").arg(aInterface)); |
977 |
1050 |
978 if (query.next()) |
1051 while(query.next()) |
979 { |
1052 { |
980 m_server->writeLog("Query is success"); |
1053 qDebug()<<"Query is success"; |
981 |
1054 |
982 SmfProvider prov; |
1055 SmfProvider prov; |
983 |
1056 |
984 // get the pluginId |
1057 // get the pluginId |
985 QString pluginId = query.value(0).toString(); |
1058 QString pluginId = query.value(0).toString(); |
|
1059 qDebug()<<"Found Plugin Id = "<<pluginId; |
986 |
1060 |
987 // get the service type / interface name |
1061 // get the service type / interface name |
988 QStringList servicetypes; |
1062 QStringList servicetypes; |
989 servicetypes.insert(0, query.value(1).toString()); |
1063 servicetypes.insert(0, query.value(1).toString()); |
990 prov.serviceTypes(servicetypes); |
1064 prov.setSupportedInterfaces(servicetypes); |
|
1065 qDebug()<<" Its interface = "<<servicetypes.at(0); |
991 |
1066 |
992 // Get the serv provider |
1067 // Get the serv provider |
993 QString servName = query.value(2).toString(); |
1068 QString servName = query.value(2).toString(); |
994 prov.serviceName(servName); |
1069 prov.setServiceName(servName); |
|
1070 qDebug()<<" Its serv prov = "<<servName; |
995 |
1071 |
996 // Get the description |
1072 // Get the description |
997 QString desc = query.value(3).toString(); |
1073 QString desc = query.value(3).toString(); |
998 prov.description(desc); |
1074 prov.setDescription(desc); |
|
1075 qDebug()<<" Its description = "<<desc; |
999 |
1076 |
1000 // Get the service URL |
1077 // Get the service URL |
1001 QUrl url(query.value(4).toString()); |
1078 QUrl url(query.value(4).toString()); |
1002 prov.serviceUrl(url); |
1079 prov.setServiceUrl(url); |
|
1080 qDebug()<<" Its url = "<<url.toString(); |
1003 |
1081 |
1004 aMap.insert(pluginId, prov); |
1082 aMap.insert(pluginId, prov); |
1005 } |
1083 } |
|
1084 |
|
1085 if(0 != query.lastError().text().size()) |
|
1086 qDebug()<<"Data base query->next() exited, error = "<<query.lastError().text(); |
1006 else |
1087 else |
1007 m_server->writeLog("Data base query->next() returned false, error = "+query.lastError().text()); |
1088 qDebug()<<"Data base query->next() exited"; |
|
1089 |
|
1090 qDebug()<<"Count of SmfProvider returned = "<<aMap.count(); |
1008 |
1091 |
1009 // Close the database |
1092 // Close the database |
1010 m_pluginDataBase.close(); |
1093 m_pluginDataBase.close(); |
1011 } |
1094 } |
1012 |
1095 |
1013 |
1096 |
1014 /** |
1097 /** |
1015 * Method to get the pluginID for the mentioned interface and service provider |
1098 * Method to get the pluginID for the mentioned interface and service provider |
1016 * @param aInterface The interface implemented by the plugin |
1099 * @param aInterface The interface implemented by the plugin |
1017 * @param aProv The plugin's service provider |
1100 * @param aProv The plugin's service provider |
1018 * @param aPluginId The required pluginID |
1101 * @param aPluginId The required pluginID. This argument will be empty if no plugin |
|
1102 * for the given interface and service provider could be found. |
1019 */ |
1103 */ |
1020 void SmfPluginManager::getPluginId(const QString& aInterface, const SmfProvider& aProv, QString& aPluginId) |
1104 void SmfPluginManager::getPluginId(const QString& aInterface, const SmfProvider& aProv, QString& aPluginId) |
1021 { |
1105 { |
1022 m_server->writeLog("SmfPluginManager::getPluginId"); |
1106 qDebug()<<"SmfPluginManager::getPluginId()"; |
|
1107 aPluginId.clear(); |
|
1108 |
|
1109 if(aInterface.isEmpty()) |
|
1110 { |
|
1111 qDebug()<<"Interface name is empty!!!"; |
|
1112 return; |
|
1113 } |
1023 |
1114 |
1024 // Open the database |
1115 // Open the database |
1025 bool opened = m_pluginDataBase.open(); |
1116 bool opened = m_pluginDataBase.open(); |
1026 if(!opened) |
1117 if(!opened) |
1027 { |
1118 { |
1028 m_server->writeLog("Data base not opened, exiting"); |
1119 qDebug()<<"Data base not opened, exiting!!!"; |
1029 return; |
1120 return; |
1030 } |
1121 } |
1031 |
1122 |
1032 m_server->writeLog("Data base opened"); |
1123 qDebug()<<"Data base opened"; |
1033 |
1124 |
1034 // Query the database for a pluginID with given interface name and service provider |
1125 // Query the database for a pluginID with given interface name and service provider |
1035 QSqlQuery query(QString("SELECT pluginId FROM pluginDetails where interfaceName = '%1' AND " |
1126 QSqlQuery query(QString("SELECT pluginId FROM pluginDetails where interfaceName = '%1' AND " |
1036 "serviceProvider = '%2'").arg(aInterface).arg(aProv.serviceName())); |
1127 "serviceProvider = '%2'").arg(aInterface).arg(aProv.serviceName())); |
1037 |
1128 |
1038 if (query.next()) |
1129 if (query.next()) |
1039 { |
1130 { |
1040 m_server->writeLog("Query is success"); |
1131 qDebug()<<"Query is success"; |
1041 |
1132 |
1042 // get the pluginId |
1133 // get the pluginId |
1043 aPluginId = query.value(0).toString(); |
1134 aPluginId = query.value(0).toString(); |
|
1135 qDebug()<<"returned pluginID = "<<aPluginId; |
1044 } |
1136 } |
1045 else |
1137 else |
1046 m_server->writeLog("Data base query->next() returned false, error = "+query.lastError().text()); |
1138 { |
1047 |
1139 if(0 != query.lastError().text().size()) |
1048 m_server->writeLog("returned pluginID = "+aPluginId); |
1140 qDebug()<<"Data base query->next() returned false, error = "<<query.lastError().text(); |
|
1141 else |
|
1142 qDebug()<<"Data base query->next() returned false"; |
|
1143 } |
1049 |
1144 |
1050 // Close the database |
1145 // Close the database |
1051 m_pluginDataBase.close(); |
1146 m_pluginDataBase.close(); |
1052 } |
1147 } |