smf/smfservermodule/smfserver/pluginmgr/smfpluginmanager.cpp
changeset 25 a180113055cb
parent 18 013a02bf2bb0
child 26 83d6a149c755
equal deleted inserted replaced
24:1cee9f1b95e0 25:a180113055cb
    55  */
    55  */
    56 SmfPluginManager::SmfPluginManager ( SmfServer *aServer )
    56 SmfPluginManager::SmfPluginManager ( SmfServer *aServer )
    57 	{
    57 	{
    58 	// Save the server instance
    58 	// Save the server instance
    59 	m_server = aServer;
    59 	m_server = aServer;
    60 	
       
    61 	qDebug()<<"Inside SmfPluginManager::SmfPluginManager()";
       
    62 	
    60 	
    63 	// initialize the file watcher to monitor plugin addition/upgradation/removal
    61 	// initialize the file watcher to monitor plugin addition/upgradation/removal
    64 	initializeFileWatcher ( );
    62 	initializeFileWatcher ( );
    65 	
    63 	
    66 	// create a database to store the folder structure of the path "c://resource//qt//plugins"
    64 	// create a database to store the folder structure of the path "c://resource//qt//plugins"
   371 	}
   369 	}
   372 	
   370 	
   373 
   371 
   374 /**
   372 /**
   375  * Method to cancel the service request
   373  * Method to cancel the service request
   376  * @param aPluginId The plugin whose current operation is to be cancelled.
   374  * @param aSessionID The session to be cancelled.
   377  * If the plugin is not loaded currently, this method just returns true.
   375  * If the plugin is not loaded currently, this method just returns true.
   378  * @return Returns true if the plugin operation could be cancelled 
   376  * @return Returns true if the plugin operation could be cancelled 
   379  * else returns false.
   377  * else returns false.
   380  */
   378  */
   381 bool SmfPluginManager::cancelRequest ( const QString& aPluginId )
   379 bool SmfPluginManager::cancelRequest (  const quint32& aSessionID )
   382 	{
   380 	{
   383 	bool retValue = true;
   381 	bool retValue = true;
   384 	qDebug()<<"Inside SmfPluginManager::cancelRequest()";
   382 	qDebug()<<"Inside SmfPluginManager::cancelRequest()";
   385 	
   383 	
   386 	// Get the plugin for which cancel is requested
   384 	// Get the plugin for which cancel is requested
   387 	foreach(SmfWaitingPluginInfoStruc* iPluginInfo, m_waitingPluginHash.values())
   385 	foreach(SmfWaitingPluginInfoStruc* iPluginInfo, m_waitingPluginHash.values())
   388 		{
   386 		{
   389 		if( 0 == iPluginInfo->iPluginId.compare(aPluginId))
   387 		if( aSessionID == iPluginInfo->iSessionID )
   390 			{
   388 			{
   391 			qDebug()<<"Plugin to be cancelled found in the waiting list";
   389 			qDebug()<<"Plugin to be cancelled found in the waiting list";
   392 			
   390 			
   393 			// Notify Transport Manager
   391 			// Notify Transport Manager
   394 			m_transMngrUtil->cancelRequest(m_waitingPluginHash.key(iPluginInfo));
   392 			m_transMngrUtil->cancelRequest(m_waitingPluginHash.key(iPluginInfo));
   461 	if(!opened)
   459 	if(!opened)
   462 		{
   460 		{
   463 		qDebug()<<"Database could not be opened, returning !!!";	
   461 		qDebug()<<"Database could not be opened, returning !!!";	
   464 		return false;
   462 		return false;
   465 		}
   463 		}
   466 	
   464 #ifdef DETAILEDDEBUGGING
   467 	qDebug()<<"Database opened";
   465 	qDebug()<<"Database opened";
       
   466 #endif
   468 	
   467 	
   469 	// Create a query to create the DB table for Plugin Manager (if it doesn't exists)
   468 	// Create a query to create the DB table for Plugin Manager (if it doesn't exists)
   470 	QSqlQuery query;
   469 	QSqlQuery query;
   471 	bool tableCreated = false;
   470 	bool tableCreated = false;
   472 
   471 
   481 		
   480 		
   482 		// Close the database
   481 		// Close the database
   483 		m_pluginDataBase.close();
   482 		m_pluginDataBase.close();
   484 		return false;
   483 		return false;
   485 		}
   484 		}
   486 	
   485 #ifdef DETAILEDDEBUGGING
   487 	qDebug()<<"Table created";
   486 	qDebug()<<"Table created";
       
   487 #endif
   488 	
   488 	
   489 	// Get the directory having the Qt plugin stubs
   489 	// Get the directory having the Qt plugin stubs
   490 	QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
   490 	QDir dir(QLibraryInfo::location(QLibraryInfo::PluginsPath));
   491 	
   491 	
   492 	// If Smf folder exists
   492 	// If Smf folder exists
   493 	if(dir.cd("smf/plugin"))
   493 	if(dir.cd("smf/plugin"))
   494 		{
   494 		{
       
   495 #ifdef DETAILEDDEBUGGING
   495 		qDebug()<<"Smf/plugin folder exists";
   496 		qDebug()<<"Smf/plugin folder exists";
       
   497 #endif
   496 		// Get each interface folders names
   498 		// Get each interface folders names
   497 		foreach(QString intfName, dir.entryList(QDir::AllDirs))
   499 		foreach(QString intfName, dir.entryList(QDir::AllDirs))
   498 			{
   500 			{
   499 			dir.cd(intfName);
   501 			dir.cd(intfName);
       
   502 #ifdef DETAILEDDEBUGGING
   500 			qDebug()<<"Interface name : "<<dir.dirName();
   503 			qDebug()<<"Interface name : "<<dir.dirName();
       
   504 #endif
   501 			
   505 			
   502 			// Get each plugin in this folder
   506 			// Get each plugin in this folder
   503 			foreach(QString pluginName, dir.entryList(QDir::Files))
   507 			foreach(QString pluginName, dir.entryList(QDir::Files))
   504 				{
   508 				{
       
   509 #ifdef DETAILEDDEBUGGING
   505 				qDebug()<<"plugins for this Interface : "<<pluginName;
   510 				qDebug()<<"plugins for this Interface : "<<pluginName;
       
   511 #endif
   506 				
   512 				
   507 				// load this plugin
   513 				// load this plugin
   508 				QPluginLoader pluginLoader(dir.absoluteFilePath(pluginName));
   514 				QPluginLoader pluginLoader(dir.absoluteFilePath(pluginName));
   509 				QObject *instance = pluginLoader.instance();
   515 				QObject *instance = pluginLoader.instance();
   510 				if (instance)
   516 				if (instance)
   511 					{
   517 					{
       
   518 #ifdef DETAILEDDEBUGGING
   512 					qDebug()<<"instance found";
   519 					qDebug()<<"instance found";
       
   520 #endif
   513 					SmfPluginBase* plugin = qobject_cast<SmfPluginBase *>(instance);
   521 					SmfPluginBase* plugin = qobject_cast<SmfPluginBase *>(instance);
   514 				    if (plugin)
   522 				    if (plugin)
   515 				    	{
   523 				    	{
       
   524 #ifdef DETAILEDDEBUGGING
   516 						qDebug()<<"SmfPluginBase found";
   525 						qDebug()<<"SmfPluginBase found";
       
   526 #endif
   517 						plugin->initialize();
   527 						plugin->initialize();
   518 				    
   528 				    
   519 						// get the plugin id
   529 						// get the plugin id
   520 						QString id = plugin->getProviderInfo()->pluginId();
   530 						QString id = plugin->getProviderInfo()->pluginId();
   521 						
   531 						
   522 						// get the interface implemented by the plugin
   532 						// get the interface implemented by the plugin
   523 						QString intfImplemented = dir.dirName();
   533 						QString intfImplemented = dir.dirName();
   524 						intfImplemented.prepend("org.symbian.smf.plugin.");
   534 						intfImplemented.prepend("org.symbian.smf.plugin.");
       
   535 #ifdef DETAILEDDEBUGGING
   525 						qDebug()<<"intfImplemented = "<<intfImplemented;
   536 						qDebug()<<"intfImplemented = "<<intfImplemented;
       
   537 #endif
   526 						
   538 						
   527 						// get the service provider
   539 						// get the service provider
   528 						QString serProv = plugin->getProviderInfo()->serviceName();
   540 						QString serProv = plugin->getProviderInfo()->serviceName();
   529 						
   541 						
   530 						//get the description
   542 						//get the description
   754 	// Check the type of Http operation to be performed
   766 	// Check the type of Http operation to be performed
   755 	switch(aReqData.iHttpOperationType)
   767 	switch(aReqData.iHttpOperationType)
   756 		{
   768 		{
   757 		// Http HEAD
   769 		// Http HEAD
   758 		case QNetworkAccessManager::HeadOperation:
   770 		case QNetworkAccessManager::HeadOperation:
       
   771 #ifdef DETAILEDDEBUGGING
   759 			qDebug()<<"http::head Operation requested";
   772 			qDebug()<<"http::head Operation requested";
       
   773 #endif
   760 			reply = m_transMngrUtil->head(aReqData.iNetworkRequest, aUrlList, sopCompliant);
   774 			reply = m_transMngrUtil->head(aReqData.iNetworkRequest, aUrlList, sopCompliant);
   761 			break;
   775 			break;
   762 		
   776 		
   763 		// Http GET
   777 		// Http GET
   764 		case QNetworkAccessManager::GetOperation:
   778 		case QNetworkAccessManager::GetOperation:
       
   779 #ifdef DETAILEDDEBUGGING
   765 			qDebug()<<"http::get Operation requested";
   780 			qDebug()<<"http::get Operation requested";
       
   781 #endif
   766 			reply = m_transMngrUtil->get(aReqData.iNetworkRequest, aUrlList, sopCompliant);
   782 			reply = m_transMngrUtil->get(aReqData.iNetworkRequest, aUrlList, sopCompliant);
   767 			break;
   783 			break;
   768 			
   784 			
   769 		// Http PUT	
   785 		// Http PUT	
   770 		case QNetworkAccessManager::PutOperation:
   786 		case QNetworkAccessManager::PutOperation:
       
   787 #ifdef DETAILEDDEBUGGING
   771 			qDebug()<<"http::put Operation requested";
   788 			qDebug()<<"http::put Operation requested";
       
   789 #endif
   772 			reply = m_transMngrUtil->put(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant);
   790 			reply = m_transMngrUtil->put(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant);
   773 			delete aReqData.iPostData;
   791 			delete aReqData.iPostData;
   774 			break;
   792 			break;
   775 			
   793 			
   776 		// Http POST
   794 		// Http POST
   777 		case QNetworkAccessManager::PostOperation:
   795 		case QNetworkAccessManager::PostOperation:
       
   796 #ifdef DETAILEDDEBUGGING
   778 			qDebug()<<"http::post Operation requested";
   797 			qDebug()<<"http::post Operation requested";
       
   798 #endif
   779 			reply = m_transMngrUtil->post(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant);
   799 			reply = m_transMngrUtil->post(aReqData.iNetworkRequest, aReqData.iPostData->buffer(), aUrlList, sopCompliant);
   780 			delete aReqData.iPostData;
   800 			delete aReqData.iPostData;
   781 			break;
   801 			break;
   782 			
   802 			
   783 		// Http DELETE
   803 		// Http DELETE
   784 		case QNetworkAccessManager::DeleteOperation:
   804 		case QNetworkAccessManager::DeleteOperation:
       
   805 #ifdef DETAILEDDEBUGGING
   785 			qDebug()<<"http::delete Operation requested";
   806 			qDebug()<<"http::delete Operation requested";
       
   807 #endif
   786 			reply = m_transMngrUtil->deleteResource(aReqData.iNetworkRequest, aUrlList, sopCompliant);
   808 			reply = m_transMngrUtil->deleteResource(aReqData.iNetworkRequest, aUrlList, sopCompliant);
   787 			break;
   809 			break;
   788 			
   810 			
   789 		default:
   811 		default:
       
   812 #ifdef DETAILEDDEBUGGING
   790 			qDebug()<<"unknown http Operation requested!!!";
   813 			qDebug()<<"unknown http Operation requested!!!";
       
   814 #endif
   791 			aResult = SmfPMPluginUnknownHttpService;
   815 			aResult = SmfPMPluginUnknownHttpService;
   792 			return;
   816 			return;
   793 		}
   817 		}
   794 	
   818 	
   795 	if( sopCompliant )
   819 	if( sopCompliant )
  1101 	if(!opened)
  1125 	if(!opened)
  1102 		{
  1126 		{
  1103 		qDebug()<<"Data base not opened, exiting getplugins()!!!";
  1127 		qDebug()<<"Data base not opened, exiting getplugins()!!!";
  1104 		return;
  1128 		return;
  1105 		}
  1129 		}
  1106 	
  1130 #ifdef DETAILEDDEBUGGING
  1107 	qDebug()<<"Data base opened";
  1131 	qDebug()<<"Data base opened";
       
  1132 #endif
  1108 	
  1133 	
  1109 	// Query the database for all pluginIDs that implement the given interface
  1134 	// Query the database for all pluginIDs that implement the given interface
  1110 	QSqlQuery query(QString("SELECT pluginId, interfaceName, serviceProvider, description, "
  1135 	QSqlQuery query(QString("SELECT pluginId, interfaceName, serviceProvider, description, "
  1111 			"serviceUrl FROM pluginDetails where interfaceName = '%1'").arg(aInterface));
  1136 			"serviceUrl FROM pluginDetails where interfaceName = '%1'").arg(aInterface));
  1112 	
  1137 	
  1113 	while(query.next())
  1138 	while(query.next())
  1114 		{
  1139 		{
       
  1140 #ifdef DETAILEDDEBUGGING
  1115 		qDebug()<<"Query is success";
  1141 		qDebug()<<"Query is success";
       
  1142 #endif
  1116 
  1143 
  1117 		SmfProvider prov;
  1144 		SmfProvider prov;
  1118 		
  1145 		
  1119 		// get the pluginId
  1146 		// get the pluginId
  1120 		QString pluginId = query.value(0).toString();
  1147 		QString pluginId = query.value(0).toString();
  1122 		
  1149 		
  1123 		// get the service type / interface name
  1150 		// get the service type / interface name
  1124 		QStringList servicetypes;
  1151 		QStringList servicetypes;
  1125 		servicetypes.insert(0, query.value(1).toString());
  1152 		servicetypes.insert(0, query.value(1).toString());
  1126 		prov.setSupportedInterfaces(servicetypes);
  1153 		prov.setSupportedInterfaces(servicetypes);
       
  1154 #ifdef DETAILEDDEBUGGING
  1127 		qDebug()<<"  Its interface = "<<servicetypes.at(0);
  1155 		qDebug()<<"  Its interface = "<<servicetypes.at(0);
       
  1156 #endif
  1128 		
  1157 		
  1129 		// Get the serv provider
  1158 		// Get the serv provider
  1130 		QString servName = query.value(2).toString();
  1159 		QString servName = query.value(2).toString();
  1131 		prov.setServiceName(servName);
  1160 		prov.setServiceName(servName);
       
  1161 #ifdef DETAILEDDEBUGGING
  1132 		qDebug()<<"  Its serv prov = "<<servName;
  1162 		qDebug()<<"  Its serv prov = "<<servName;
       
  1163 #endif
  1133 		
  1164 		
  1134 		// Get the description
  1165 		// Get the description
  1135 		QString desc = query.value(3).toString();
  1166 		QString desc = query.value(3).toString();
  1136 		prov.setDescription(desc);
  1167 		prov.setDescription(desc);
       
  1168 #ifdef DETAILEDDEBUGGING
  1137 		qDebug()<<"  Its description = "<<desc;
  1169 		qDebug()<<"  Its description = "<<desc;
       
  1170 #endif
  1138 		
  1171 		
  1139 		// Get the service URL
  1172 		// Get the service URL
  1140 		QUrl url(query.value(4).toString());
  1173 		QUrl url(query.value(4).toString());
  1141 		prov.setServiceUrl(url);
  1174 		prov.setServiceUrl(url);
       
  1175 #ifdef DETAILEDDEBUGGING
  1142 		qDebug()<<"  Its url = "<<url.toString();
  1176 		qDebug()<<"  Its url = "<<url.toString();
       
  1177 #endif
  1143 
  1178 
  1144 		aMap.insert(pluginId, prov);
  1179 		aMap.insert(pluginId, prov);
  1145 		}
  1180 		}
  1146 	
  1181 	
  1147 	if(0 != query.lastError().text().size())
  1182 	if(0 != query.lastError().text().size())
  1180 		{
  1215 		{
  1181 		qDebug()<<"Data base not opened, exiting!!!";
  1216 		qDebug()<<"Data base not opened, exiting!!!";
  1182 		return;
  1217 		return;
  1183 		}
  1218 		}
  1184 	
  1219 	
       
  1220 #ifdef DETAILEDDEBUGGING
  1185 	qDebug()<<"Data base opened";
  1221 	qDebug()<<"Data base opened";
       
  1222 #endif
  1186 
  1223 
  1187 	// Query the database for a pluginID with given interface name and service provider
  1224 	// Query the database for a pluginID with given interface name and service provider
  1188 	QSqlQuery query(QString("SELECT pluginId FROM pluginDetails where interfaceName = '%1' AND "
  1225 	QSqlQuery query(QString("SELECT pluginId FROM pluginDetails where interfaceName = '%1' AND "
  1189 			"serviceProvider = '%2'").arg(aInterface).arg(aProv.serviceName()));
  1226 			"serviceProvider = '%2'").arg(aInterface).arg(aProv.serviceName()));
  1190 	
  1227 	
  1191 	if (query.next())
  1228 	if (query.next())
  1192 		{
  1229 		{
       
  1230 #ifdef DETAILEDDEBUGGING
  1193 		qDebug()<<"Query is success";
  1231 		qDebug()<<"Query is success";
       
  1232 #endif
  1194 		
  1233 		
  1195 		// get the pluginId
  1234 		// get the pluginId
  1196 		aPluginId = query.value(0).toString();
  1235 		aPluginId = query.value(0).toString();
  1197 		qDebug()<<"returned pluginID = "<<aPluginId;
  1236 		qDebug()<<"returned pluginID = "<<aPluginId;
  1198 		}
  1237 		}