smf/smfservermodule/smfserver/server/smfserversymbian.cpp
changeset 25 a180113055cb
parent 18 013a02bf2bb0
child 26 83d6a149c755
equal deleted inserted replaced
24:1cee9f1b95e0 25:a180113055cb
    19 
    19 
    20 #include <QDataStream>
    20 #include <QDataStream>
    21 #include <QDebug>
    21 #include <QDebug>
    22 #include <smfrelationmgr.h>
    22 #include <smfrelationmgr.h>
    23 
    23 
       
    24 #include "smfpluginmanager.h"
    24 #include "smfserversymbian_p.h"
    25 #include "smfserversymbian_p.h"
    25 
    26 
    26 
    27 
    27 SmfServerSymbian* SmfServerSymbian::NewL(CActive::TPriority aActiveObjectPriority,SmfServer* aWrapper)
    28 SmfServerSymbian* SmfServerSymbian::NewL(CActive::TPriority aActiveObjectPriority,SmfServer* aWrapper)
    28 	{
    29 	{
   134 			iServer(aServer),iPtrToBuf(NULL,0) ,
   135 			iServer(aServer),iPtrToBuf(NULL,0) ,
   135 			iIntfNameSymbian8(NULL,0), iProviderSymbian8(NULL,0),
   136 			iIntfNameSymbian8(NULL,0), iProviderSymbian8(NULL,0),
   136 			iIntfNameSymbian(NULL,0) ,iXtraDataPtr8(NULL,0),
   137 			iIntfNameSymbian(NULL,0) ,iXtraDataPtr8(NULL,0),
   137 			iPtrToDataForClient(NULL,0) ,iPtr8DataForDSM(NULL,0),iPtr8DataFromDSM(NULL,0)  
   138 			iPtrToDataForClient(NULL,0) ,iPtr8DataForDSM(NULL,0),iPtr8DataFromDSM(NULL,0)  
   138 	{
   139 	{
   139 	qDebug()<<"Inside SmfServerSymbianSession::SmfServerSymbianSession()";
       
   140 	iServer->iSessionCount++;
   140 	iServer->iSessionCount++;
   141 	}
   141 	}
   142 
   142 
   143 SmfServerSymbianSession::~SmfServerSymbianSession()
   143 SmfServerSymbianSession::~SmfServerSymbianSession()
   144 	{
   144 	{
   204 	}
   204 	}
   205 
   205 
   206 void SmfServerSymbianSession::HandleClientMessageL(const RMessage2& aMessage)
   206 void SmfServerSymbianSession::HandleClientMessageL(const RMessage2& aMessage)
   207 	{
   207 	{
   208 	qDebug()<<"Inside SmfServerSymbianSession::HandleClientMessageL() = "<<aMessage.Function();
   208 	qDebug()<<"Inside SmfServerSymbianSession::HandleClientMessageL() = "<<aMessage.Function();
   209 	iLastRequest = aMessage.Function();
       
   210 	
   209 	
   211 	/**Note:- Only ESmfGetService needs to be taken care separately as it doesn't involve createrequest for PM
   210 	/**Note:- Only ESmfGetService needs to be taken care separately as it doesn't involve createrequest for PM
   212 	 *See SmfRequestTypeID for list of opcodes
   211 	 *See SmfRequestTypeID for list of opcodes
   213 	 *
   212 	 *
   214 	 *Two cases,-
   213 	 *Two cases,-
   217 	 *so it seems PM needs to provide two overloaded getPlugins API But for every client intf instanciation
   216 	 *so it seems PM needs to provide two overloaded getPlugins API But for every client intf instanciation
   218 	 *we would execute the same things twice.
   217 	 *we would execute the same things twice.
   219 	 *TODO:- to be changed after GetServices returns SmfProvider+pluginID 
   218 	 *TODO:- to be changed after GetServices returns SmfProvider+pluginID 
   220 	 * 
   219 	 * 
   221 	 */
   220 	 */
   222 	if( (SmfGetService == iLastRequest) 			||
   221 	if( (SmfGetService == aMessage.Function()) 			||
   223 		(SmfPostGetMaxCharsInPost == iLastRequest)	||
   222 		(SmfPostGetMaxCharsInPost == aMessage.Function())	||
   224 		(SmfPostGetMaxItems == iLastRequest)		||
   223 		(SmfPostGetMaxItems == aMessage.Function())		||
   225 		(SmfPostGetSupportedFormats == iLastRequest)||
   224 		(SmfPostGetSupportedFormats == aMessage.Function())||
   226 		(SmfPostGetAppearanceSupport == iLastRequest) )
   225 		(SmfPostGetAppearanceSupport == aMessage.Function()))
   227 			
   226 			
   228 		{
   227 		{
   229 		HandleSyncServiceL(aMessage);
   228 		HandleSyncServiceL(aMessage);
   230 		}
   229 		}
   231 	else if(iLastRequest == SmfRelationCreate ||
   230 	else if (SmfCancelRequest == aMessage.Function())
   232 			iLastRequest == SmfRelationAssociate || 
   231 		{
   233 			iLastRequest == SmfRelationSearchById ||
   232 		HandleCancelRequest(aMessage);
   234 			iLastRequest == SmfRelationSearchByContact ||
   233 		}
   235 			iLastRequest == SmfRelationCount ||
   234 	else if(aMessage.Function() == SmfRelationCreate ||
   236 			iLastRequest == SmfRelationGet ||
   235 			aMessage.Function() == SmfRelationAssociate || 
   237 			iLastRequest == SmfRelationGetAll ||
   236 			aMessage.Function() == SmfRelationSearchById ||
   238 			iLastRequest == SmfRelationGetAllRelations ||
   237 			aMessage.Function() == SmfRelationSearchByContact ||
   239 			iLastRequest == SmfRelationDeleteRelation
   238 			aMessage.Function() == SmfRelationCount ||
       
   239 			aMessage.Function() == SmfRelationGet ||
       
   240 			aMessage.Function() == SmfRelationGetAll ||
       
   241 			aMessage.Function() == SmfRelationGetAllRelations ||
       
   242 			aMessage.Function() == SmfRelationDeleteRelation ||
       
   243 			aMessage.Function() == SmfRelationRemove
   240 			)
   244 			)
   241 		{
   245 		{
   242 		HandleDSMServiceL(aMessage);
   246 		HandleDSMServiceL(aMessage);
   243 		}
   247 		}
   244 	else
   248 	else
   245 		{
   249 		{
   246 		HandleCommonServiceL(aMessage);
   250 		HandleCommonServiceL(aMessage);
   247 		}
   251 		}
   248 	}
   252 	}
   249 
   253 
       
   254 void SmfServerSymbianSession::HandleCancelRequest(const RMessage2 & aMessage)
       
   255 	{
       
   256 	SmfError err = SmfNoError;
       
   257 	// iLastRequest contains the last operations opcode, cwhich is to be cancelled.
       
   258 	bool ret = SmfPluginManager::getInstance(iServer->wrapper())->cancelRequest(iLastRequest);
       
   259 	
       
   260 	iErrBuf.Zero();
       
   261 	iErrBuf.AppendNum(err);
       
   262 	iMessage.Write(2,iErrBuf);
       
   263 	aMessage.Complete(iLastRequest);
       
   264 	
       
   265 	}
       
   266 
   250 void SmfServerSymbianSession::HandleDSMServiceL(const RMessage2 & aMessage)
   267 void SmfServerSymbianSession::HandleDSMServiceL(const RMessage2 & aMessage)
   251 	{
   268 	{
   252 	qDebug()<<"Inside SmfServerSymbianSession::HandleDSMServiceL()";
   269 	qDebug()<<"Inside SmfServerSymbianSession::HandleDSMServiceL()";
       
   270 	iLastRequest = aMessage.Function();
   253 	//TODO:-If DSM takes care of deserialization and formation of User and social 
   271 	//TODO:-If DSM takes care of deserialization and formation of User and social 
   254 	//profile from the params then switch case can be removed
   272 	//profile from the params then switch case can be removed
   255 	if(iData8ForDSM)
   273 	if(iData8ForDSM)
   256 		{
   274 		{
   257 		delete iData8ForDSM;
   275 		delete iData8ForDSM;
   267 			TInt readerr0 = aMessage.Read(0,iPtr8DataForDSM); 
   285 			TInt readerr0 = aMessage.Read(0,iPtr8DataForDSM); 
   268 			}
   286 			}
   269 			break;
   287 			break;
   270 		case SmfRelationAssociate:
   288 		case SmfRelationAssociate:
   271 			{
   289 			{
   272 			int maxAlloc = 100;
   290 			int maxAlloc = 1000;
   273 			iData8ForDSM = HBufC8::New(maxAlloc);
   291 			iData8ForDSM = HBufC8::New(maxAlloc);
   274 			iPtr8DataForDSM.Set(iData8ForDSM->Des());
   292 			iPtr8DataForDSM.Set(iData8ForDSM->Des());
   275 			TInt readerr0 = aMessage.Read(0,iPtr8DataForDSM); 
   293 			TInt readerr0 = aMessage.Read(0,iPtr8DataForDSM); 
   276 			}
   294 			}
   277 			break;
   295 			break;
   353 			if(iData8FromDSM)
   371 			if(iData8FromDSM)
   354 				{
   372 				{
   355 				delete iData8FromDSM;
   373 				delete iData8FromDSM;
   356 				iData8FromDSM = NULL;
   374 				iData8FromDSM = NULL;
   357 				}
   375 				}
       
   376 			int siz = qtdataFromDSM.size();
       
   377 			qDebug()<<"Size of Data to be sent back thru DSM Create : "<<siz;
   358 			iData8FromDSM = HBufC8::NewL(qtdataFromDSM.size());
   378 			iData8FromDSM = HBufC8::NewL(qtdataFromDSM.size());
   359 			iPtr8DataFromDSM.Set(iData8FromDSM->Des());
   379 			iPtr8DataFromDSM.Set(iData8FromDSM->Des());
   360 			iPtr8DataFromDSM.Copy(reinterpret_cast<const TText8*>(qtdataFromDSM.constData()),qtdataFromDSM.length());
   380 			iPtr8DataFromDSM.Copy(reinterpret_cast<const TText8*>(qtdataFromDSM.constData()),qtdataFromDSM.length());
   361 			TInt writeErr = aMessage.Write(1,iPtr8DataFromDSM);
   381 			TInt writeErr = aMessage.Write(1,iPtr8DataFromDSM);
   362 			}
   382 			}
   366 		iDSMErr.Zero();
   386 		iDSMErr.Zero();
   367 		TInt errInt = dsmErr;
   387 		TInt errInt = dsmErr;
   368 		iDSMErr.AppendNum(errInt);
   388 		iDSMErr.AppendNum(errInt);
   369 		TInt writeErr = aMessage.Write(2,iDSMErr);
   389 		TInt writeErr = aMessage.Write(2,iDSMErr);
   370 		}
   390 		}
       
   391 	aMessage.Complete(iLastRequest);
   371 	}
   392 	}
   372 
   393 
   373 
   394 
   374 void SmfServerSymbianSession::HandleSyncServiceL(const RMessage2 & aMessage)
   395 void SmfServerSymbianSession::HandleSyncServiceL(const RMessage2 & aMessage)
   375 	{
   396 	{
   376 	qDebug()<<"Inside SmfServerSymbianSession::HandleSyncServiceL()";
   397 	qDebug()<<"Inside SmfServerSymbianSession::HandleSyncServiceL()";
       
   398 	
       
   399 	iLastRequest = aMessage.Function();
   377 	
   400 	
   378 	// Following is the data format sent by client
   401 	// Following is the data format sent by client
   379 	// 1. SmfProvider +PageInfo flag+ aPageNum + aPerPage (if pageinfoflag is set) + XtraInfo flag(size of xtra data) Serialized 
   402 	// 1. SmfProvider +PageInfo flag+ aPageNum + aPerPage (if pageinfoflag is set) + XtraInfo flag(size of xtra data) Serialized 
   380 	// 2. Interface name as string ("org.symbian.smf.client.gallery")
   403 	// 2. Interface name as string ("org.symbian.smf.client.gallery")
   381 	// 3. Data pointer to be filled by serialized data(eg: QList<smfProvider>)
   404 	// 3. Data pointer to be filled by serialized data(eg: QList<smfProvider>)
   534 	}
   557 	}
   535 
   558 
   536 void SmfServerSymbianSession::HandleCommonServiceL(const RMessage2& aMessage)
   559 void SmfServerSymbianSession::HandleCommonServiceL(const RMessage2& aMessage)
   537 	{
   560 	{
   538 	qDebug()<<"Inside SmfServerSymbianSession::HandleCommonServiceL() = "<<aMessage.Function();
   561 	qDebug()<<"Inside SmfServerSymbianSession::HandleCommonServiceL() = "<<aMessage.Function();
       
   562 	iLastRequest = aMessage.Function();
   539 	/**
   563 	/**
   540 	 * Note:- client sends message in the following format,-
   564 	 * Note:- client sends message in the following format,-
   541 	 * Slot 0:- SmfProvider* serialized+Page info flag+page number+per page (if page info flag)+xtra info flag
   565 	 * Slot 0:- SmfProvider* serialized+Page info flag+page number+per page (if page info flag)+xtra info flag
   542 	 * Slot 1:- Interface Name buffer
   566 	 * Slot 1:- Interface Name buffer
   543 	 * Slot 2:- Ptr to data block to be filled
   567 	 * Slot 2:- Ptr to data block to be filled
   550 		delete iProviderBuf8;
   574 		delete iProviderBuf8;
   551 		iProviderBuf8 = NULL;
   575 		iProviderBuf8 = NULL;
   552 		}
   576 		}
   553 	iProviderBuf8 = HBufC8::NewL(providerSize);
   577 	iProviderBuf8 = HBufC8::NewL(providerSize);
   554 	iProviderSymbian8.Set(iProviderBuf8->Des());
   578 	iProviderSymbian8.Set(iProviderBuf8->Des());
       
   579 	qDebug()<<"data info (0) size = "<<iProviderSymbian8.Size();
   555 	
   580 	
   556 	//read it into iProviderSymbian8
   581 	//read it into iProviderSymbian8
   557 	aMessage.ReadL(0,iProviderSymbian8);
   582 	aMessage.ReadL(0,iProviderSymbian8);
   558 	
   583 	
   559 	//convert SmfProvider info from Symbian into bytearray
   584 	//convert SmfProvider info from Symbian into bytearray
   576 	iIntfNameBuf8 = HBufC8::NewL(intfNameSize);
   601 	iIntfNameBuf8 = HBufC8::NewL(intfNameSize);
   577 	iIntfNameSymbian8.Set(iIntfNameBuf8->Des());
   602 	iIntfNameSymbian8.Set(iIntfNameBuf8->Des());
   578 
   603 
   579 	//read it into iIntfNameSymbian8
   604 	//read it into iIntfNameSymbian8
   580 	aMessage.ReadL(1,iIntfNameSymbian8);
   605 	aMessage.ReadL(1,iIntfNameSymbian8);
   581 	qDebug()<<"iIntfNameSymbian8.Size = "<<iIntfNameSymbian8.Size();
   606 	qDebug()<<"iIntfNameSymbian8 (1) .Size = "<<iIntfNameSymbian8.Size();
   582 
   607 
   583 	QByteArray bytearray(reinterpret_cast<const char*>(iIntfNameSymbian8.Ptr()),iIntfNameSymbian8.Length()) ;
   608 	QByteArray bytearray(reinterpret_cast<const char*>(iIntfNameSymbian8.Ptr()),iIntfNameSymbian8.Length()) ;
   584 	QDataStream intfNameStream(&bytearray,QIODevice::ReadOnly);
   609 	QDataStream intfNameStream(&bytearray,QIODevice::ReadOnly);
   585 	iInterfaceID.clear();
   610 	iInterfaceID.clear();
   586 	intfNameStream>>iInterfaceID;
   611 	intfNameStream>>iInterfaceID;
   606 		//Gnerate request id only if the plugin ID is authorised
   631 		//Gnerate request id only if the plugin ID is authorised
   607 		TInt id = iServer->addToSessionMap(this,aMessage);
   632 		TInt id = iServer->addToSessionMap(this,aMessage);
   608 		//request PM to get the data
   633 		//request PM to get the data
   609 		SmfRequestTypeID opcode = (SmfRequestTypeID)iLastRequest;
   634 		SmfRequestTypeID opcode = (SmfRequestTypeID)iLastRequest;
   610 		
   635 		
   611 		iServer->wrapper()->sendToPluginManager(id,pluginID,iInterfaceID,opcode,XtraBufQt);
   636 		SmfError err = iServer->wrapper()->sendToPluginManager(id,pluginID,iInterfaceID,opcode,XtraBufQt);
       
   637 		if(SmfNoError != err)
       
   638 			{
       
   639 			iErrBuf.Zero();
       
   640 			iErrBuf.AppendNum(err);
       
   641 			iMessage.Write(2,iErrBuf);
       
   642 			
       
   643 			//signal completion for the last request
       
   644 			iMessage.Complete(err);
       
   645 			}
   612 		}
   646 		}
   613 	else
   647 	else
   614 		{
   648 		{
   615 		SmfError err = SmfNoAuthorizedPlugin;
   649 		SmfError err = SmfNoAuthorizedPlugin;
   616 		iErrBuf.Zero();
   650 		iErrBuf.Zero();
   617 		iErrBuf.AppendNum(err);
   651 		iErrBuf.AppendNum(err);
   618 		iMessage.Write(2,iErrBuf);
   652 		iMessage.Write(2,iErrBuf);
   619 		}
   653 		
   620 	}
   654 		//signal completion for the last request
       
   655 		iMessage.Complete(err);
       
   656 		}
       
   657 	}