smf/smfservermodule/smfserver/server/smfserversymbian.cpp
changeset 14 a469c0e6e7fb
parent 10 77a56c951f86
child 18 013a02bf2bb0
--- a/smf/smfservermodule/smfserver/server/smfserversymbian.cpp	Mon Jun 07 11:43:45 2010 +0100
+++ b/smf/smfservermodule/smfserver/server/smfserversymbian.cpp	Wed Jun 23 19:51:49 2010 +0530
@@ -23,7 +23,7 @@
 #include <QDataStream>
 #include <QStringList>
 #include <QString>
-
+#include <smfrelationmgr.h>
 #include "smfserversymbian_p.h"
 
 
@@ -35,23 +35,17 @@
 	CleanupStack::Pop(); // self
 	return self;
 	}
-
 void SmfServerSymbian::ConstructL()
 	{
 	}
-
-
 SmfServerSymbian::SmfServerSymbian( CActive::TPriority aActiveObjectPriority,SmfServer* aWrapper )
 : CPolicyServer(0,myPolicy, ESharableSessions), iWrapper(aWrapper)
 	{
-	Q_UNUSED(aActiveObjectPriority);
+	Q_UNUSED(aActiveObjectPriority)
 	}
-
-
-
 TInt SmfServerSymbian::addToSessionMap(SmfServerSymbianSession* aSession,const RMessage2& aMsg)
 	{
-	writeLog("SmfServerSymbian::addToSessionMap");
+	qDebug()<<("SmfServerSymbian::addToSessionMap");
 	if(iSessionCount)
 		{
 		//The key generation 
@@ -72,17 +66,16 @@
 	
 	return (-1);
 	}
-
-
 TInt SmfServerSymbian::removeFromSessionMap(SmfServerSymbianSession* aSession,RMessage2& aMsg)
 	{
-	Q_UNUSED(aSession);
-	Q_UNUSED(aMsg);
+	Q_UNUSED(aSession)
+Q_UNUSED(aMsg)
+//To be implemented
 	return 0;
 	}
 
 //TODO - change this to a macro using qdebug  to avoid file opening and closing
-void SmfServerSymbian::writeLog(QString log) const
+/*void SmfServerSymbian::writeLog(QString log) const
 	{
 #ifdef WRITE_LOG
 	QFile file("c:\\data\\SmfServerLogs.txt");
@@ -94,53 +87,45 @@
 #else
 	Q_UNUSED(log)
 #endif
-	}
-
-
+	}*/
 SmfServerSymbian::~SmfServerSymbian()
 	{
 
 	}
-
 SmfServer* SmfServerSymbian::wrapper()
 	{
 	return iWrapper;
 	}
-
-
 CSession2* SmfServerSymbian::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const
 	{
-
+	Q_UNUSED(aVersion)
 	// Check that the version is OK
 	//    TVersion v( 0, 1, 0 );
 	//    if (!User::QueryVersionSupported( v, aVersion ))
 	//        User::Leave( KErrNotSupported );  
 	// Create the session.
-	Q_UNUSED(aVersion);
 	QString log("New session created");
-	writeLog(log);
+	qDebug()<<(log);
 	return new (ELeave) SmfServerSymbianSession( const_cast<SmfServerSymbian*>(this) );
 	}
-
 SmfServerSymbianSession* SmfServerSymbian::findSession(TInt id)
 	{
-	writeLog("SmfServerSymbian::findSession");
+	qDebug()<<("SmfServerSymbian::findSession");
 	CSessionStruct* sessionStruct = iMap.Find(id);	
 	if(sessionStruct)
 		{
-		writeLog("Session id found");
+		qDebug()<<("Session id found");
 		return sessionStruct->iSession;
 		}
 	else
 		{
-		writeLog("Session id not found");
+		qDebug()<<("Session id not found");
 		return NULL;
 		}
 	}
-
 TInt SmfServerSymbian::findAndServiceclient(TInt requestID,QByteArray* parsedData,SmfError error)
 	{
-	writeLog("SmfServerSymbian::findAndServiceclient");
+	qDebug()<<("SmfServerSymbian::findAndServiceclient");
 	SmfServerSymbianSession* sessionToservice = findSession(requestID);
 	if(sessionToservice)
 		{
@@ -148,13 +133,14 @@
 		}
 	return 0;
 	}
-
 SmfServerSymbianSession::SmfServerSymbianSession(SmfServerSymbian* aServer):
-			iServer(aServer),iPtrToBuf(NULL,0) ,iIntfNmaeSymbian(NULL,0), iProviderSymbian(NULL,0),iIntfNameSymbian16(NULL,0)     
+			iServer(aServer),iPtrToBuf(NULL,0) ,
+			iIntfNmaeSymbian(NULL,0), iProviderSymbian(NULL,0),
+			iIntfNameSymbian16(NULL,0) ,iXtraDataPtr(NULL,0),
+			iPtrToDataForClient(NULL,0) ,iPtrDataForDSM(NULL,0),iPtrDataFromDSM(NULL,0)  
 	{
 	iServer->iSessionCount++;
 	}
-
 SmfServerSymbianSession::~SmfServerSymbianSession()
 	{
 	//cleanup of client resources
@@ -162,7 +148,7 @@
 	}
 
 
-void SmfServerSymbianSession::clientAuthorizationFinished(bool success)
+void SmfServerSymbianSession::clientathorizationFinished(bool success)
 	{
 	//Client authorization failed
 	if(!success)
@@ -175,64 +161,51 @@
 		HandleClientMessageL(iMessage);
 		}
 	}
-
-
 void SmfServerSymbianSession::resultsAvailable(QByteArray* parsedData,SmfError error)
 	{
 
 	//Note:- The order of serialization of parsedData - Error value followed by the data
 	//parsedData is already serialized by PM
-	iServer->writeLog("SmfServerSymbianSession::resultsAvailable");
+	qDebug()<<("SmfServerSymbianSession::resultsAvailable");
 	//We should remove the request from the map as soon its no longer outstanding
 	iServer->removeFromSessionMap(this,iMessage);
 	
-	byteArrayToClnt.clear();
-	byteArrayToClnt.append(*(parsedData));
-	iPtrToBuf.Copy(reinterpret_cast<TUint8*>(byteArrayToClnt.data()),byteArrayToClnt.length());
+	//Note:- Session must take the ownership of the data being passed to the client session
+	if(iDataForClient)
+		{
+		delete iDataForClient;
+		iDataForClient = NULL;
+		}
+	iDataForClient = HBufC8::NewL(parsedData->size());
+	iPtrToDataForClient.Set(iDataForClient->Des());
+	iPtrToDataForClient.Copy(reinterpret_cast<const TText8*>(parsedData->constData()),parsedData->length());
 
-	TInt writeErr = iMessage.Write(2,iPtrToBuf);
-	
-	iServer->writeLog("Write=");
+	TInt writeErr = iMessage.Write(2,iPtrToDataForClient);
+	qDebug()<<("Write=");
 	QString wrErr = QString::number(writeErr);
-	iServer->writeLog(wrErr);
-	
+	qDebug()<<(wrErr);
 	//signal completion for the last request
 	iMessage.Complete(error);
 	}
-
-
 void SmfServerSymbianSession::ServiceL(const RMessage2& aMessage)
 	{    
 
-	iServer->writeLog("SmfServerSymbianSession::ServiceL=");
+	qDebug()<<("SmfServerSymbianSession::ServiceL=");
 	iMessage = aMessage ;
-	
 	QString log;
 	log = QString::number(iMessage.Function());
-	iServer->writeLog(log);
-	
+	qDebug()<<(log);
+	//construct the client auth id
 	SmfClientAuthID clientAuthID;
 	clientAuthID.pid = aMessage.SecureId();
 	clientAuthID.session = this;
-	//check whether the client is authorized
-	if(!iServer->wrapper()->isClientAuthorized(clientAuthID))
-		{
-		//Client is yet to be authorized
-		//It should start authorization or simply return err value is yet TBD, so the following code may change
-		//start authorization of client, session will be blocked untill its authorized
-		//HandleclientMessageL will be called in that fn
-		iServer->wrapper()->authorizeClient(clientAuthID);
-		}
-	else
-		{
-		//client is authorized, so proceed
-		HandleClientMessageL(iMessage);		
-		}
+	//TODO:- No client pid checking?No capability? So why symbian client-server?
+	HandleClientMessageL(iMessage);
+
 	}
-
 void SmfServerSymbianSession::HandleClientMessageL(const RMessage2& aMessage)
 	{
-	iServer->writeLog("HandleClientMessageL");
+	qDebug()<<("HandleClientMessageL");
 	iLastRequest = aMessage.Function();
 	
 	
@@ -251,33 +224,137 @@
 		{
 		HandleGetService(aMessage);
 		}
+	else if(iLastRequest == SmfRelationCreate ||
+			iLastRequest == SmfRelationAssociate || 
+			iLastRequest == SmfRelationSearchById ||
+			iLastRequest == SmfRelationSearchByContact ||
+			iLastRequest == SmfRelationCount ||
+			iLastRequest == SmfRelationGet ||
+			iLastRequest == SmfRelationGetAll ||
+			iLastRequest == SmfRelationGetAllRelations
+			)
+		{
+		HandleDSMServiceL(aMessage);
+		}
 	else
 		{
 		HandleCommonServiceL(aMessage);
 		}
 	}
+void SmfServerSymbianSession::HandleDSMServiceL(const RMessage2 & aMessage)
+	{
+	//TODO:-If DSM takes care of deserialization and formation of User and social 
+	//profile from the params then switch case can be removed
+	if(iDataForDSM)
+		{
+		delete iDataForDSM;
+		iDataForDSM = NULL;
+		}
+	
+	switch(iLastRequest)
+		{
+		case SmfRelationCreate:
+			{
+			iDataForDSM = HBufC8::New(maxSmfRelationIdSize);
+			iPtrDataForDSM.Set(iDataForDSM->Des());
+			TInt readerr0 = aMessage.Read(0,iPtrDataForDSM); 
 
+			}
+			break;
+		case SmfRelationAssociate:
+			{
+			int maxAlloc = 100;
+			iDataForDSM = HBufC8::New(maxAlloc);
+			iPtrDataForDSM.Set(iDataForDSM->Des());
+			TInt readerr0 = aMessage.Read(0,iPtrDataForDSM); 
+			}
+			break;
+		case SmfRelationSearchById:
+			{
+			int maxAlloc = MaxSmfContactSize;
+			iDataForDSM = HBufC8::New(maxAlloc);
+			iPtrDataForDSM.Set(iDataForDSM->Des());
+			TInt readerr0 = aMessage.Read(0,iPtrDataForDSM); 
+			}
+			break;
+		case SmfRelationCount:
+			{
+			int maxAlloc = 100;
+			iDataForDSM = HBufC8::New(maxAlloc);
+			iPtrDataForDSM.Set(iDataForDSM->Des());
+			TInt readerr0 = aMessage.Read(0,iPtrDataForDSM);
+			}
+			break;
+		case SmfRelationGet:
+			{
+			int maxAlloc = maxSmfRelationItemSize*maxRelationItems;
+			iDataForDSM = HBufC8::New(maxAlloc);
+			iPtrDataForDSM.Set(iDataForDSM->Des());
+			TInt readerr0 = aMessage.Read(0,iPtrDataForDSM); 
+			}
+			break;
+		case SmfRelationGetAll:
+			{
+			int maxAlloc = maxSmfRelationItemSize*maxRelationItems;
+			iDataForDSM = HBufC8::New(maxAlloc);
+			iPtrDataForDSM.Set(iDataForDSM->Des());
+			TInt readerr0 = aMessage.Read(0,iPtrDataForDSM); 
+			}
+			break;
+		default:
+			break;
+		}
+	//Convert into QByteArray
+	QByteArray qtdataForDSM(reinterpret_cast<const char*>(iPtrDataForDSM.Ptr()),iPtrDataForDSM.Length()) ;
+	QByteArray qtdataFromDSM;
+	SmfRequestTypeID opcode = (SmfRequestTypeID)iLastRequest;
+	SmfError dsmErr = iServer->wrapper()->sendToDSM(qtdataForDSM,opcode,qtdataFromDSM);
+	if(dsmErr == SmfNoError)
+		{
+		if(qtdataFromDSM.size())
+			{
+			if(iDataFromDSM)
+				{
+				delete iDataFromDSM;
+				iDataFromDSM = NULL;
+				}
+			iDataFromDSM = HBufC8::NewL(qtdataFromDSM.size());
+			iPtrDataFromDSM.Set(iDataFromDSM->Des());
+			iPtrDataFromDSM.Copy(reinterpret_cast<const TText8*>(qtdataFromDSM.constData()),qtdataFromDSM.length());
+			TInt writeErr = aMessage.Write(1,iPtrDataFromDSM);
+			}
+		}
+	else
+		{
+		iDSMErr.Zero();
+		TInt errInt = dsmErr;
+		iDSMErr.AppendNum(errInt);
+		TInt writeErr = aMessage.Write(2,iDSMErr);
+		}
+	}
 void SmfServerSymbianSession::HandleGetService(const RMessage2 & aMessage)
 	{
-	iServer->writeLog("SmfServerSymbianSession::HandleGetService");
+	qDebug()<<("SmfServerSymbianSession::HandleGetService");
+	
 	/**
 	 * Note:- client sends message for this opcode in the following format,-
 	 * Slot 0:- Interface Name buffer
 	 * Slot 1:- Ptr to data block to be filled with SmfProvideList* serialized into QByteArray
+	 * Slot 2:- Max data size allocated in the client side
+	 * TODO:- What if size of SmfProviderList to be passed to client is greater than
+	 * this size???
 	 */
+	
 	iInterfaceNametbuf.Zero();
-
 	TInt readerr = aMessage.Read(0,iInterfaceNametbuf);
-	
-	iServer->writeLog(QString::number(readerr));
-	
+	qDebug()<<(QString::number(readerr));
 	QByteArray bytearray(reinterpret_cast<const char*>(iInterfaceNametbuf.Ptr()),iInterfaceNametbuf.Length()) ;
 	QDataStream stream3(&bytearray,QIODevice::ReadOnly);
 	stream3>>iInterfaceID;
-	
-	iServer->writeLog("iInterfaceID=");
-	iServer->writeLog(iInterfaceID);
-	
+	qDebug()<<("iInterfaceID=");
+	qDebug()<<(iInterfaceID);
+	//Interface names are diff in client and plugin, replacing *.client.* with *.plugin.*
+	iInterfaceID.replace(QString(".client"),QString(".plugin"));
 	iServer->wrapper()->getPlugins(iInterfaceID,iPluginIDMap);
 	//form the plugin id list from the map
 	QMapIterator<SmfPluginID, SmfProvider> iter(iPluginIDMap);
@@ -287,7 +364,6 @@
 	iter.next();
 	iPluginIDList<<iter.key();
 		}
-	
 	//iAuthList will be filled by credential manager
 	iServer->wrapper()->getAuthorizedPlugins(iPluginIDList,iAuthList);
 
@@ -295,7 +371,6 @@
 	//No need to add this to session map, as we are not requesting PM for this
 	QMap<SmfPluginID, SmfProvider> tempMap;
 	QMapIterator<SmfPluginID, SmfProvider> i(iPluginIDMap);
-	
 	while (i.hasNext()) 
 		{
 		i.next();
@@ -304,10 +379,9 @@
 			tempMap.insert(i.key(),i.value());
 			}
 		}
-
+	//now tempMapcontains the info to be passed to the client
 	iPluginIDMap.clear();
 	iPluginIDMap = tempMap;
-	
 	//form list of smfprovider from this map,-
 	QList<SmfProvider> providerList;
 	i = iPluginIDMap;
@@ -316,47 +390,52 @@
 		i.next();
 		providerList.append(i.value());
 		}
-
+	//now serialize this list into bytearray
 	byteArrayToClnt.clear();
 	QDataStream stream(&byteArrayToClnt,QIODevice::WriteOnly);
 	stream<<providerList;
-
-	iPtrToBuf.Copy(reinterpret_cast<TUint8*>(byteArrayToClnt.data()),byteArrayToClnt.length());
-	TInt writeErr = aMessage.Write(1,iPtrToBuf);
-	
-	iServer->writeLog("Write=");
+	qDebug()<<("providerList.count()=");
+	qDebug()<<(QString::number(providerList.count()));
+	qDebug()<<("Before providerListSymbian");
+	//now convert it into TPtr8
+	TPtrC8 providerListSymbian(reinterpret_cast<const TText8*>(byteArrayToClnt.constData()),byteArrayToClnt.length());
+	qDebug()<<("After providerListSymbian");
+	TInt writeErr = aMessage.Write(1,providerListSymbian);
+	qDebug()<<("Write=");
 	QString wrErr = QString::number(writeErr);
-	iServer->writeLog(wrErr);
+	qDebug()<<(wrErr);
 	//signal completion
-	
 	TInt completion = SmfGetServiceComplete ;
 	aMessage.Complete(completion);
 	}
-
 void SmfServerSymbianSession::HandleCommonServiceL(const RMessage2& aMessage)
 	{
 	/**
 	 * Note:- client sends message in the following format,-
-	 * Slot 0:- SmfProvider* serialized
+	 * Slot 0:- SmfProvider* serialized+Page info flag+page number+per page (if page info flag)+xtra info flag
 	 * Slot 1:- Interface Name buffer
 	 * Slot 2:- Ptr to data block to be filled
+	 * Slot 3 :- Xtra Data if xtra data flag
 	 */
+	//TODO:- Use macro instead, shared betn client-server
+	TInt maxProvidersize = 1000;
+	TInt maxOtherInfoSize = 300;
 	TInt providerSize = aMessage.GetDesLength(0);
 	if(iProviderBuf)
 		{
-	delete iProviderBuf;
-	iProviderBuf = NULL;
+		delete iProviderBuf;
+		iProviderBuf = NULL;
 		}
-	iProviderBuf = HBufC8::NewL(providerSize);
+	iProviderBuf = HBufC8::NewL(maxProvidersize + maxOtherInfoSize);
 	iProviderSymbian.Set(iProviderBuf->Des());
 
 	TInt intfNameSize = aMessage.GetDesLength(1);
 	if(iIntfNameBuf)
 		{
-	delete iIntfNameBuf;
-	iIntfNameBuf = NULL;
+		delete iIntfNameBuf;
+		iIntfNameBuf = NULL;
 		}
-	iIntfNameBuf = HBufC8::NewL(intfNameSize*2);//for safeside
+	iIntfNameBuf = HBufC8::NewL(1000);//for safeside
 	iIntfNmaeSymbian.Set(iIntfNameBuf->Des());
 
 
@@ -364,33 +443,55 @@
 	aMessage.ReadL(0,iProviderSymbian);
 	//read it into iIntfNmaeSymbian
 	aMessage.ReadL(1,iIntfNmaeSymbian);
-
+	
 	//convert SmfProvider info from Symbian into bytearray
 	QByteArray providerBufQt(reinterpret_cast<const char*>(iProviderSymbian.Ptr()),iProviderSymbian.Length());
-	iServer->writeLog("After providerBufQt");
+	qDebug()<<("providerBufQt.size=");
+	qDebug()<<(QString::number(providerBufQt.size()));
 
 	//now de-serialize it
 	QDataStream stream(&providerBufQt,QIODevice::ReadOnly);
 	SmfProvider provider;
 	stream>>provider ;
+	TInt pageinfoFlag=0;
+	stream>>pageinfoFlag;
+	TInt pageNo=-1;
+	TInt perpage=-1;
+	if(pageinfoFlag)
+		{
+		stream>>pageNo;
+		stream>>perpage;
+		qDebug()<<("pageNo=");
+		qDebug()<<(QString::number(pageNo));
+		qDebug()<<("perpage=");
+		qDebug()<<(QString::number(perpage));
+		}
+	TInt XtraInfoFlag = 0;
+	TBool isXtraData = EFalse;
+	stream>>XtraInfoFlag;
+	if(XtraInfoFlag)
+		{
+		isXtraData = ETrue;
+		qDebug()<<("XtraInfoFlag=");
+		qDebug()<<(QString::number(XtraInfoFlag));
+		}
+	qDebug()<<("iIntfNmaeSymbian.Size=");
+	qDebug()<<(QString::number(iIntfNmaeSymbian.Size()));
 	QByteArray bytearray(reinterpret_cast<const char*>(iIntfNmaeSymbian.Ptr()),iIntfNmaeSymbian.Length()) ;
 	QDataStream intfNameStream(&bytearray,QIODevice::ReadOnly);
 	iInterfaceID.clear();
 	intfNameStream>>iInterfaceID;
-
-	iServer->writeLog("After de-serializing into iInterfaceID=");
-	iServer->writeLog(iInterfaceID);
-	
+	qDebug()<<("After de-serializing into iInterfaceID=");
+	qDebug()<<(iInterfaceID);
+	//Interface names are diff in client and plugin, replacing *.client.* with *.plugin.*
+	iInterfaceID.replace(QString(".client"),QString(".plugin"));
 	//Get the plugin ID who matches provider info for a given intf name
 	SmfPluginID pluginID = iServer->wrapper()->getPlugin(iInterfaceID,provider);
-	
-	iServer->writeLog("pluginID from PM=");
-	iServer->writeLog(pluginID);
-	
+	qDebug()<<("pluginID from PM=");
+	qDebug()<<(pluginID);
 	iPluginIDList.clear();
-	//we need to check only this pluginID is authorized
+	//we need to check only this pluginID is authorized?
 	iPluginIDList<<pluginID;
-	
 	//iAuthList will contain pluginID for a successfull case
 	iAuthList.clear();
 	iServer->wrapper()->getAuthorizedPlugins(iPluginIDList,iAuthList);
@@ -401,10 +502,32 @@
 		TInt id = iServer->addToSessionMap(this,aMessage);
 		//request PM to get the data
 		SmfRequestTypeID opcode = (SmfRequestTypeID)iLastRequest;
-		iServer->wrapper()->getRequestedData(id,pluginID,iInterfaceID,opcode,providerBufQt);
+		if(isXtraData)
+			{
+			if(iXtraDataBuf)
+				{
+				delete iXtraDataBuf;
+				iXtraDataBuf = NULL;	
+				}
+			iXtraDataBuf = HBufC8::NewL(XtraInfoFlag);
+			iXtraDataPtr.Set(iXtraDataBuf->Des());
+			QByteArray XtraBufQt(reinterpret_cast<const char*>(iXtraDataPtr.Ptr()),iXtraDataPtr.Length());
+			qDebug()<<("XtraBufQt size=");
+			qDebug()<<(QString::number(XtraBufQt.size()));
+			iServer->wrapper()->sendToPluginManager(id,pluginID,iInterfaceID,opcode,XtraBufQt);
+			}
+		else
+			{
+			iServer->wrapper()->sendToPluginManager(id,pluginID,iInterfaceID,opcode);
+			}
 		}
 	else
 		{
-		//TODO:-Plugin ID is not authorized, throw some error
+		SmfError err = SmfNoAuthorizedPlugin;
+		iErrBuf.Zero();
+		iErrBuf.AppendNum(err);
+		iMessage.Write(2,iErrBuf);
 		}
+
+
 	}