smf/smfservermodule/smfserver/pluginmgr/smfpluginmanager.cpp
changeset 14 a469c0e6e7fb
parent 10 77a56c951f86
child 18 013a02bf2bb0
equal deleted inserted replaced
13:b5d63d5fc252 14:a469c0e6e7fb
    16  * The Plugin Manager class manages the loading and unloading of plug-ins
    16  * The Plugin Manager class manages the loading and unloading of plug-ins
    17  *
    17  *
    18  */
    18  */
    19 
    19 
    20 #include <QDir>
    20 #include <QDir>
       
    21 #include <QDebug>
    21 #include <QLibraryInfo>
    22 #include <QLibraryInfo>
    22 #include <QFileSystemWatcher>
    23 #include <QFileSystemWatcher>
    23 #include <QPluginLoader>
    24 #include <QPluginLoader>
    24 #include <QList>
    25 #include <QList>
    25 #include <smfpluginbase.h>
    26 #include <smfpluginbase.h>
    26 #include <smfpluginutil.h>
    27 #include <smfpluginutil.h>
    27 #include <smfprovider.h>
    28 #include <smfprovider.h>
    28 
    29 
    29 #include "smfpluginutil.h"
       
    30 #include "smfpluginmanager.h"
    30 #include "smfpluginmanager.h"
    31 #include "smfpluginmanagerutil.h"
    31 #include "smfpluginmanagerutil.h"
    32 #include "smftransportmanagerutil.h"
    32 #include "smftransportmanagerutil.h"
    33 
    33 
    34 // Static data initialisation
    34 // Static data initialisation
    55 SmfPluginManager::SmfPluginManager ( SmfServer *aServer )
    55 SmfPluginManager::SmfPluginManager ( SmfServer *aServer )
    56 	{
    56 	{
    57 	// Save the server instance
    57 	// Save the server instance
    58 	m_server = aServer;
    58 	m_server = aServer;
    59 	
    59 	
    60 	m_server->writeLog("Inside SmfPluginManager::SmfPluginManager()");
    60 	qDebug()<<"Inside SmfPluginManager::SmfPluginManager()";
    61 	
    61 	
    62 	// initialize the file watcher to monitor plugin addition/upgradation/removal
    62 	// initialize the file watcher to monitor plugin addition/upgradation/removal
    63 	initializeFileWatcher ( );
    63 	initializeFileWatcher ( );
    64 	
    64 	
    65 	// create a database to store the folder structure of the path "c://resource//qt//plugins"
    65 	// create a database to store the folder structure of the path "c://resource//qt//plugins"
    76 /**
    76 /**
    77  * Destructor
    77  * Destructor
    78  */
    78  */
    79 SmfPluginManager::~SmfPluginManager ( )
    79 SmfPluginManager::~SmfPluginManager ( )
    80 	{
    80 	{
    81 	m_server->writeLog("Inside SmfPluginManager::~SmfPluginManager()");
    81 	qDebug()<<"Inside SmfPluginManager::~SmfPluginManager()";
       
    82 	
       
    83 	// delete file watcher
    82 	if(m_fileWatcher)
    84 	if(m_fileWatcher)
    83 		delete m_fileWatcher;
    85 		delete m_fileWatcher;
    84 	
    86 	
    85 	if(m_tempStruct)
    87 	if(m_tempStruct)
    86 		delete m_tempStruct;
    88 		delete m_tempStruct;
    87 	
    89 	
       
    90 	// delete the plugin information hash
    88 	if(m_waitingPluginHash.count() > 0)
    91 	if(m_waitingPluginHash.count() > 0)
    89 		{
    92 		{
    90 		foreach(SmfWaitingPluginInfoStruc *str, m_waitingPluginHash.values())
    93 		foreach(SmfWaitingPluginInfoStruc *str, m_waitingPluginHash.values())
    91 			delete str;
    94 			delete str;
    92 		}
    95 		}
    93 	
    96 	
       
    97 	// delete the SmfPluginManagerUtil class instance
    94 	if(m_util)
    98 	if(m_util)
    95 		delete m_util;
    99 		delete m_util;
    96 	
   100 	
       
   101 	// Close the database
    97 	if(m_pluginDataBase.isOpen())
   102 	if(m_pluginDataBase.isOpen())
    98 		{
   103 		{
    99 		m_pluginDataBase.close();
   104 		m_pluginDataBase.close();
   100 		m_pluginDataBase.removeDatabase("SmfPluginsInfoDatabase");
   105 		m_pluginDataBase.removeDatabase("SmfPluginsInfoDatabase");
       
   106 		QFile::remove("SmfPluginsInfoDatabase");
   101 		}
   107 		}
   102 	
   108 	
   103 	// unload all loaded plugins
   109 	// unload all loaded plugins
   104 	unload(m_pluginLoaderHash.keys());
   110 	unload(m_pluginLoaderHash.keys());
   105 	
   111 	
       
   112 	// Finally remove the existing singleton instance of plugin manager itself
   106 	if(m_myInstance)
   113 	if(m_myInstance)
   107 		delete m_myInstance;
   114 		delete m_myInstance;
   108 	}
   115 	}
   109 
   116 
   110 
   117 
   116  * Manager to send the network request.
   123  * Manager to send the network request.
   117  * @param aSessionID The session ID provided by Smf Server
   124  * @param aSessionID The session ID provided by Smf Server
   118  * @param aPluginID The plugin ID that need to perform this operation
   125  * @param aPluginID The plugin ID that need to perform this operation
   119  * @param aOperation The type of operation to be performed
   126  * @param aOperation The type of operation to be performed
   120  * @param aInputData The data required to create the web query
   127  * @param aInputData The data required to create the web query
   121  * @return SmfPluginManagerResult The result of the operation
   128  * @return SmfError The result of the operation. It can be :-
   122  * @see smfglobal.h
   129  * SmfPluginNoError (if the request is sent successfully) or 
   123  */
   130  * SmfPluginLoadError (if plugin could not be loaded) or
   124 SmfPluginManagerResult SmfPluginManager::createRequest ( const quint32& aSessionID, 
   131  * SmfPluginNotAuthorised (if the plugin is not authorised) or
       
   132  * SmfPluginUnknownPluginService (if the requested service is not known or unsupported) or
       
   133  * SmfPluginRequestCreationFailed (if request creation has failed) or
       
   134  * SmfPluginSOPCheckFailed (if plugins request doesnot comply to the Same Origin Policy) or
       
   135  * SmfPluginRequestSendingFailed (if request could not be sent) or 
       
   136  * SmfPluginUnknownHttpService (if the plugin requested any unknown http 
       
   137  * method other than get, post, put, head or delete)  
       
   138  */
       
   139 SmfError SmfPluginManager::createRequest ( const quint32& aSessionID, 
   125 		const QString& aPluginID, 
   140 		const QString& aPluginID, 
   126 		const SmfRequestTypeID& aOperation, 
   141 		const SmfRequestTypeID& aOperation, 
   127 		QByteArray& aInputData )
   142 		QByteArray& aInputData )
   128 	{
   143 	{
   129 	m_server->writeLog("Inside SmfPluginManager::createRequest()");
   144 	qDebug()<<"Inside SmfPluginManager::createRequest()";
   130 	
   145 	
   131 	SmfPluginManagerResult result = SmfPluginUnknownError;
   146 	SmfError result = SmfUnknownError;
   132 
   147 
   133 	// Load the plugin
   148 	// Load the plugin
   134 	QObject *plugin = load(aPluginID, result);
   149 	QObject *plugin = load(aPluginID, result);
   135 	
   150 	
   136 	// Check if plugin is loaded
   151 	// Check if plugin is loaded
   137 	if(plugin && (SmfPluginLoaded == result))
   152 	if(plugin && (SmfNoError == result))
   138 		{
   153 		{
   139 		m_server->writeLog("Plugin loaded");
       
   140 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(plugin);
   154 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(plugin);
   141 		
   155 		
   142 		if(instance)
   156 		if(instance)
   143 		{
   157 		{
   144 		// Get the registration token of the plugin
   158 		// Get the registration token of the plugin
   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 
   340  * Method called to initialize the file watcher watching the file  
   327  * Method called to initialize the file watcher watching the file  
   341  * system for adition/upgradation/removal of plugins
   328  * system for adition/upgradation/removal of plugins
   342  */
   329  */
   343 void SmfPluginManager::initializeFileWatcher ( )
   330 void SmfPluginManager::initializeFileWatcher ( )
   344 	{
   331 	{
   345 	m_server->writeLog("Inside SmfPluginManager::initializeFileWatcher()");
   332 	qDebug()<<"Inside SmfPluginManager::initializeFileWatcher()";
   346 	
   333 	
   347 	// Create the file watcher for the plugins in /Smf folder of the Qt plugin directory
   334 	// Create the file watcher for the plugins in /Smf folder of the Qt plugin directory
   348 	m_fileWatcher = new QFileSystemWatcher(this);
   335 	m_fileWatcher = new QFileSystemWatcher(this);
   349 	
   336 	
   350 	// Get the directory having the Qt plugin stubs
   337 	// Get the directory having the Qt plugin stubs
   361 			dir.cdUp();
   348 			dir.cdUp();
   362 			}
   349 			}
   363 		}
   350 		}
   364 	else
   351 	else
   365 		m_fileWatcher->addPath(dir.absolutePath());
   352 		m_fileWatcher->addPath(dir.absolutePath());
       
   353 	
       
   354 	connect(m_fileWatcher, SIGNAL(directoryChanged(const QString&)), 
       
   355 			this, SLOT (directoryChanged(const QString&)));
       
   356 	
       
   357 	connect(m_fileWatcher, SIGNAL(fileChanged(const QString&)), 
       
   358 				this, SLOT (directoryChanged(const QString&)));
   366 	}
   359 	}
   367 
   360 
   368 
   361 
   369 
   362 
   370 /**
   363 /**
   371  * Method called to initialize the database holding the plugin 
   364  * Method called to initialize the database holding the plugin 
   372  * directory sructure information. This is called only once when 
   365  * directory sructure information. This is called only once when 
   373  * the Plugin Manager is instantiated.
   366  * the Plugin Manager is instantiated.
   374  * This method creates and updates m_pluginIdPathHash member 
   367  * This method creates and updates m_pluginIdPathHash member 
   375  * of this class
   368  * of this class
       
   369  * @return Returns true the database is successfully created and updated, 
       
   370  * else returns false
   376  */
   371  */
   377 bool SmfPluginManager::initializeSmfPluginDataBase ( )
   372 bool SmfPluginManager::initializeSmfPluginDataBase ( )
   378 	{
   373 	{
   379 	m_server->writeLog("Inside SmfPluginManager::initializeSmfPluginDataBase()");
   374 	qDebug()<<"Inside SmfPluginManager::initializeSmfPluginDataBase()";
   380 	
   375 	
   381 	// Find QSQLite driver and create a connection to database
   376 	// Find QSQLite driver and create a connection to database
   382 	m_pluginDataBase.removeDatabase("SmfPluginsInfoDatabase");
   377 	QFile::remove("SmfPluginsInfoDatabase");
   383 	m_pluginDataBase = QSqlDatabase::addDatabase("QSQLITE");
   378 	m_pluginDataBase = QSqlDatabase::addDatabase("QSQLITE");
   384 	m_pluginDataBase.setDatabaseName("SmfPluginsInfoDatabase");
   379 	m_pluginDataBase.setDatabaseName("SmfPluginsInfoDatabase");
   385 	
   380 	
   386 	// Open the database
   381 	// Open the database
   387 	bool opened = m_pluginDataBase.open();
   382 	bool opened = m_pluginDataBase.open();
   388 	if(!opened)
   383 	if(!opened)
       
   384 		{
       
   385 		qDebug()<<"Database could not be opened, returning !!!";	
   389 		return false;
   386 		return false;
   390 	
   387 		}
   391 	m_server->writeLog("Database opened");
   388 	
       
   389 	qDebug()<<"Database opened";
   392 	
   390 	
   393 	// Create a query to create the DB table for Plugin Manager (if it doesn't exists)
   391 	// Create a query to create the DB table for Plugin Manager (if it doesn't exists)
   394 	QSqlQuery query;
   392 	QSqlQuery query;
   395 	bool tableCreated = false;
   393 	bool tableCreated = false;
   396 
   394 
   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
   470 						bool rowInserted = rowInsertQuery.exec(QString("INSERT INTO pluginDetails VALUES ('%1', "
   470 						bool rowInserted = rowInsertQuery.exec(QString("INSERT INTO pluginDetails VALUES ('%1', "
   471 								"'%2', '%3', '%4', '%5', '%6')").arg(id).arg(intfImplemented).arg(serProv)
   471 								"'%2', '%3', '%4', '%5', '%6')").arg(id).arg(intfImplemented).arg(serProv)
   472 								.arg(desc).arg(servURL).arg(authAppId));
   472 								.arg(desc).arg(servURL).arg(authAppId));
   473 						
   473 						
   474 						if(rowInserted)
   474 						if(rowInserted)
   475 							m_server->writeLog("This Plugin's information is added to database : "+id+""
   475 							qDebug()<<QString("This Plugin's information is added to database : '%1' '%2' '%3'")
   476 									", "+intfImplemented+", "+serProv);
   476 											.arg(id).arg(intfImplemented).arg(serProv);
   477 						else
   477 						else
   478 							m_server->writeLog("plugins data not written to database, error = "+query.lastError().text());
   478 							if(0 != query.lastError().text().size())
       
   479 								qDebug()<<"plugins data not written to database!!!, error = "<<query.lastError().text();
   479 				    	}
   480 				    	}
   480 				    else
   481 				    else
   481 				    	{
   482 				    	{
   482 						m_server->writeLog("Plugin could not be converted to SmfpluginBase* - returning");
   483 						qDebug()<<"Plugin could not be converted to SmfpluginBase* - returning!!!";
   483 						
   484 						
   484 						// Close the database
   485 						// Close the database
   485 						m_pluginDataBase.close();
   486 						m_pluginDataBase.close();
   486 						
   487 						
   487 				    	return false;
   488 				    	return false;
   489 				    
   490 				    
   490 				    pluginLoader.unload();
   491 				    pluginLoader.unload();
   491 					}
   492 					}
   492 				else
   493 				else
   493 					{
   494 					{
   494 					m_server->writeLog("Plugin could not be loaded - returning");
   495 					qDebug()<<"Plugin could not be loaded - returning!!!, error = "<<pluginLoader.errorString();
   495 					
   496 					
   496 					// Close the database
   497 					// Close the database
   497 					m_pluginDataBase.close();
   498 					m_pluginDataBase.close();
   498 										
   499 										
   499 					return false;
   500 					return false;
   500 				}
   501 					}
   501 				}
   502 				}
   502 			dir.cdUp();
   503 			dir.cdUp();
   503 			}
   504 			}
   504 		}
   505 		}
   505 	else
   506 	else
   506 		m_server->writeLog("No Smf plugins installed!!!");
   507 		qDebug()<<"No Smf plugins installed!!!";
   507 	
   508 	
   508 	// Close the database
   509 	// Close the database
   509 	m_pluginDataBase.close();
   510 	m_pluginDataBase.close();
   510 	
   511 	
   511 	return true;
   512 	return true;
   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 
   746 
   787 
   747 /**
   788 /**
   748  * Method to serialize the result of parsing (which is done by the 
   789  * Method to serialize the result of parsing (which is done by the 
   749  * plugins) to QByteArray to be sent to Smf server.
   790  * plugins) to QByteArray to be sent to Smf server.
   750  * @param aOperation The type of operation to be performed
   791  * @param aOperation The type of operation to be performed
   751  * @param aResult The data to be serialized
   792  * @param aResult The data to be serialized (should not be NULL)
   752  * @param aDataStream Stream to be written
   793  * @param aDataStream Stream to be written to
   753  */
   794  */
   754 void SmfPluginManager::serializeResult ( 
   795 void SmfPluginManager::serializeResult ( 
   755 		const SmfRequestTypeID &aOperation, 
   796 		const SmfRequestTypeID &aOperation, 
   756 		QVariant* aResult,
   797 		QVariant* aResult,
   757 		QDataStream &aDataStream )
   798 		QDataStream &aDataStream )
   758 	{
   799 	{
   759 	m_server->writeLog("Inside SmfPluginManager::serializeResult()");
   800 	qDebug()<<"Inside SmfPluginManager::serializeResult()";
   760 	
   801 	
   761 	// Call the utlity class method to serialize the result
   802 	// Call the utlity class method to serialize the result
   762 	m_util->serializeResult(aOperation, aResult, aDataStream);
   803 	m_util->serializeResult(aOperation, aResult, aDataStream);
   763 	}
   804 	}
   764 
   805 
   769  * Information List.
   810  * Information List.
   770  * @param aPath The path of the directory that has changed
   811  * @param aPath The path of the directory that has changed
   771  */
   812  */
   772 void SmfPluginManager::directoryChanged ( const QString &aPath )
   813 void SmfPluginManager::directoryChanged ( const QString &aPath )
   773 	{
   814 	{
   774 	m_server->writeLog("Inside SmfPluginManager::directoryChanged()");
   815 	qDebug()<<"Inside SmfPluginManager::directoryChanged()";
       
   816 	qDebug()<<"Changed path = "<<aPath;
   775 	
   817 	
   776 	// Create a QDir instance with the given path
   818 	// Create a QDir instance with the given path
   777 	QDir dir(aPath);
   819 	QDir dir(aPath);
   778 	QString pluginId;
   820 	QString pluginId;
   779 	QString oldpluginId;
   821 	QString oldpluginId;
   783 
   825 
   784 	// Get all the files in the directory at a specified path(sorted)
   826 	// Get all the files in the directory at a specified path(sorted)
   785 	QStringList newPlugins = dir.entryList(QDir::Files, QDir::Name);
   827 	QStringList newPlugins = dir.entryList(QDir::Files, QDir::Name);
   786 	QStringList::const_iterator newListIterator = newPlugins.constBegin();
   828 	QStringList::const_iterator newListIterator = newPlugins.constBegin();
   787 	
   829 	
       
   830 	foreach(QString name, newPlugins)
       
   831 		qDebug()<<"New plugin = "<<name;
       
   832 	
   788 	// Get all plugins who were in this path, before this directory was changed
   833 	// Get all plugins who were in this path, before this directory was changed
   789 	QStringList availablePlugins = m_pluginIdPathHash.keys(aPath);
   834 	QStringList availablePlugins = m_pluginIdPathHash.keys(aPath);
   790 	availablePlugins.sort();
   835 	availablePlugins.sort();
   791 	QStringList::const_iterator oldListIterator = availablePlugins.constBegin();
   836 	QStringList::const_iterator oldListIterator = availablePlugins.constBegin();
   792 	
   837 	
       
   838 	foreach(QString name, availablePlugins)
       
   839 		qDebug()<<"Old plugin = "<<name;
       
   840 	
   793 	// Open the database
   841 	// Open the database
   794 	bool opened = m_pluginDataBase.open();
   842 	bool opened = m_pluginDataBase.open();
   795 	if(!opened)
   843 	if(!opened)
   796         {}//return;
   844 		return;
   797 	
   845 	
   798 	// If plugin is changed
   846 	// If plugin is changed
   799 	if( newPlugins.count() == availablePlugins.count() )
   847 	if( newPlugins.count() == availablePlugins.count() )
   800 		{
   848 		{
       
   849 		qDebug()<<"Plugin upgraded...";
   801 		// Check for equality
   850 		// Check for equality
   802 		while( newListIterator != newPlugins.constEnd() )
   851 		while( newListIterator != newPlugins.constEnd() )
   803 			{
   852 			{
   804 			if( *newListIterator == *oldListIterator )
   853 			if( *newListIterator == *oldListIterator )
   805 				{
   854 				{
   818 	    QSqlQuery updateQuery;
   867 	    QSqlQuery updateQuery;
   819 	    
   868 	    
   820 	    bool updated = updateQuery.exec(QString("UPDATE pluginDetails SET pluginId = '%1' "
   869 	    bool updated = updateQuery.exec(QString("UPDATE pluginDetails SET pluginId = '%1' "
   821 	    		"WHERE pluginId = '%2'").arg(*newListIterator).arg(*oldListIterator));
   870 	    		"WHERE pluginId = '%2'").arg(*newListIterator).arg(*oldListIterator));
   822 	    if (!updated)
   871 	    if (!updated)
   823 	    	m_server->writeLog("Database table not updated, error = "+updateQuery.lastError().text());
   872 	    	if(0 != updateQuery.lastError().text().size())
   824 		
   873 	    		qDebug()<<"Database table not updated, error = "<<updateQuery.lastError().text();
   825 		
   874 		
   826 		// Get the new and old plugin Ids
   875 		// Get the new and old plugin Ids
   827 		pluginId = *newListIterator;
   876 		pluginId = *newListIterator;
   828 		oldpluginId = *oldListIterator;
   877 		oldpluginId = *oldListIterator;
   829 		
   878 		
   830 		// Load the plugin and get its service provider name
   879 		// Load the plugin and get its service provider name
   831 		SmfPluginManagerResult result;
   880 		SmfError result;
   832 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(load(pluginId, result));
   881 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(load(pluginId, result));
   833 		
   882 		
   834 		if(instance && (SmfPluginLoaded == result))
   883 		if(instance && (SmfNoError == result))
   835 			{
   884 			{
   836 			instance->initialize(SmfPluginUtil::getInstance());
   885 			instance->initialize(SmfPluginUtil::getInstance());
   837 			serviceProv = instance->getProviderInfo()->serviceName();
   886 			serviceProv = instance->getProviderInfo()->serviceName();
   838 			interfaceName = dir.dirName();
   887 			interfaceName = dir.dirName();
   839 			}
   888 			}
   840 		
   889 		
   841 		unload(instance);
   890 		unload(instance);
       
   891 		
       
   892 		qDebug()<<QString("Upgraded plugin details are : '%1' '%2' '%3' '%4'").arg(oldpluginId)
       
   893 				.arg(pluginId).arg(interfaceName).arg(serviceProv);
       
   894 		
   842 		// Inform server that plugin has been changed
   895 		// Inform server that plugin has been changed
   843 #ifdef CSM_INTEGRATED
   896 #ifdef CSM_INTEGRATED
   844 		//Remove after Server Integration
   897 		//Remove after Server Integration
   845 		m_server->pluginChanged(oldPluginId, newPluginId, interfaceName, serviceProv);
   898 		m_server->pluginChanged(oldPluginId, pluginId, interfaceName, serviceProv);
   846 #endif
   899 #endif
   847 		}
   900 		}
   848 		
   901 		
   849 	// If plugin is added
   902 	// If plugin is added
   850 	else if(newPlugins.count() > availablePlugins.count())
   903 	else if(newPlugins.count() > availablePlugins.count())
   851 		{
   904 		{
       
   905 		qDebug()<<"Plugin Added...";
   852 		// Check for equality
   906 		// Check for equality
   853 		while( oldListIterator != availablePlugins.constEnd() )
   907 		while( oldListIterator != availablePlugins.constEnd() )
   854 			{
   908 			{
   855 			if( *newListIterator == *oldListIterator )
   909 			if( *newListIterator == *oldListIterator )
   856 				{
   910 				{
   865 		
   919 		
   866 		// Get the plugin Id
   920 		// Get the plugin Id
   867 		pluginId = *newListIterator;
   921 		pluginId = *newListIterator;
   868 		
   922 		
   869 		// Load the plugin and get its service provider name
   923 		// Load the plugin and get its service provider name
   870 		SmfPluginManagerResult result;
   924 		SmfError result;
   871 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(load(pluginId, result));
   925 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(load(pluginId, result));
   872 		
   926 		
   873 		if(instance && (SmfPluginLoaded == result))
   927 		if(instance && (SmfNoError == result))
   874 			{
   928 			{
   875 			instance->initialize(SmfPluginUtil::getInstance());
   929 			instance->initialize(SmfPluginUtil::getInstance());
   876 			serviceProv = instance->getProviderInfo()->serviceName();
   930 			serviceProv = instance->getProviderInfo()->serviceName();
   877 			interfaceName = dir.dirName();
   931 			interfaceName = dir.dirName();
   878 			interfaceName.prepend("org.symbian.smf.plugin.");
   932 			interfaceName.prepend("org.symbian.smf.plugin.");
   888 		bool rowInserted = insertRowQuery.exec(QString("INSERT INTO pluginDetails VALUES "
   942 		bool rowInserted = insertRowQuery.exec(QString("INSERT INTO pluginDetails VALUES "
   889 				"('%1', '%2', '%3', '%4')").arg(pluginId).arg(interfaceName).arg(serviceProv).arg(authAppId));
   943 				"('%1', '%2', '%3', '%4')").arg(pluginId).arg(interfaceName).arg(serviceProv).arg(authAppId));
   890 
   944 
   891 		 // Error
   945 		 // Error
   892 		if (!rowInserted)
   946 		if (!rowInserted)
   893 			m_server->writeLog("Database table not inserted, error = "+insertRowQuery.lastError().text());
   947 			qDebug()<<"Database table not inserted, error = "<<insertRowQuery.lastError().text();
       
   948 		
       
   949 		qDebug()<<QString("Added plugin detailes are : '%1' '%2' '%3'").arg(pluginId)
       
   950 				.arg(interfaceName).arg(serviceProv);
   894 		
   951 		
   895 		// Inform server that plugin has been added
   952 		// Inform server that plugin has been added
   896 #ifdef CSM_INTEGRATED
   953 #ifdef CSM_INTEGRATED
   897 		//Remove after Server Integration
   954 		//Remove after Server Integration
   898 		m_server->pluginAdded(pluginId, interfaceName, serviceProv);
   955 		m_server->pluginAdded(pluginId, interfaceName, serviceProv);
   900 		}
   957 		}
   901 	
   958 	
   902 	// If plugin is removed
   959 	// If plugin is removed
   903 	else //for newPlugins.count() < availablePlugins.count()
   960 	else //for newPlugins.count() < availablePlugins.count()
   904 		{
   961 		{
       
   962 		qDebug()<<"Plugin removed...";
       
   963 		
   905 		// Check for equality
   964 		// Check for equality
   906 		while( newListIterator != newPlugins.constEnd() )
   965 		while( newListIterator != newPlugins.constEnd() )
   907 			{
   966 			{
   908 			if( *newListIterator == *oldListIterator )
   967 			if( *newListIterator == *oldListIterator )
   909 				{
   968 				{
   921 		bool rowDeleted = deleteRowQuery.exec(QString("DELETE FROM pluginDetails WHERE pluginId = '%1'")
   980 		bool rowDeleted = deleteRowQuery.exec(QString("DELETE FROM pluginDetails WHERE pluginId = '%1'")
   922 				.arg(*oldListIterator));
   981 				.arg(*oldListIterator));
   923 		 
   982 		 
   924 		// Error
   983 		// Error
   925 		if (!rowDeleted)
   984 		if (!rowDeleted)
   926 			m_server->writeLog("Database table row not deleted, error = "+deleteRowQuery.lastError().text());
   985 			qDebug()<<"Database table row not deleted, error = "<<deleteRowQuery.lastError().text();
   927 		
   986 		
   928 		// Get the plugin Id
   987 		// Get the plugin Id
   929 		pluginId = *oldListIterator;
   988 		pluginId = *oldListIterator;
   930 		
   989 		
   931 		// Load the plugin and get its service provider name
   990 		// Load the plugin and get its service provider name
   932 		SmfPluginManagerResult result;
   991 		SmfError result;
   933 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(load(pluginId, result));
   992 		SmfPluginBase* instance = qobject_cast<SmfPluginBase *>(load(pluginId, result));
   934 		
   993 		
   935 		if(instance && (SmfPluginLoaded == result))
   994 		if(instance && (SmfNoError == result))
   936 			{
   995 			{
   937 			instance->initialize(SmfPluginUtil::getInstance());
   996 			instance->initialize(SmfPluginUtil::getInstance());
   938 			serviceProv = instance->getProviderInfo()->serviceName();
   997 			serviceProv = instance->getProviderInfo()->serviceName();
   939 			interfaceName = dir.dirName();
   998 			interfaceName = dir.dirName();
   940 			}
   999 			}
   941 		
  1000 		
   942 		unload(instance);
  1001 		unload(instance);
       
  1002 		
       
  1003 		qDebug()<<QString("Added plugin detailes are : '%1' '%2' '%3'").arg(pluginId)
       
  1004 				.arg(interfaceName).arg(serviceProv);
       
  1005 		
   943 		// Inform server that plugin has removed
  1006 		// Inform server that plugin has removed
   944 #ifdef CSM_INTEGRATED
  1007 #ifdef CSM_INTEGRATED
   945 		//Remove after Server Integration
  1008 		//Remove after Server Integration
   946 		m_server->pluginRemoved(pluginId, interfaceName, serviceProv);
  1009 		m_server->pluginRemoved(pluginId, interfaceName, serviceProv);
   947 #endif
  1010 #endif
   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 	}