diff -r c39a6cfd1fb9 -r be09cf1f39dd smf/smfservermodule/smfclient/client/smfclientsymbian.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/smf/smfservermodule/smfclient/client/smfclientsymbian.cpp Tue May 18 17:37:12 2010 +0530 @@ -0,0 +1,471 @@ +/** + * Copyright (c) 2010 Sasken Communication Technologies Ltd. + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html" + * + * Initial Contributors: + * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution + * + * Contributors: + * Manasij Roy, Nalina Hariharan + */ + +#include "smfclientsymbian.h" +#include +#include +#include +#include +#include +#include "smfglobal.h" +#include "smfclientglobal.h" +//testing purpose +#include +#include +#include +//testing end +// For starting the server process +static TInt StartServerL(); +static TInt CreateServerProcessL(); + +CSmfClientSymbian::CSmfClientSymbian(smfObserver* aObserver) +: iObserver(aObserver),CActive( EPriorityStandard ),iDataPtr(NULL, 0, 0) + { + CActiveScheduler::Add(this); + } + +CSmfClientSymbian* CSmfClientSymbian::NewL(smfObserver* aObserver ) + { + CSmfClientSymbian* self = NewLC( aObserver ); + CleanupStack::Pop( self ); + return( self ) ; + } + +CSmfClientSymbian* CSmfClientSymbian::NewLC(smfObserver* aObserver ) + { + CSmfClientSymbian* self = + new ( ELeave ) CSmfClientSymbian( aObserver ); + CleanupStack::PushL( self ); + self->ConstructL(); + return self; + } + +void CSmfClientSymbian::ConstructL() + { + writeLog("CSmfClientSymbian::ConstructL"); + + User::LeaveIfError(iSession.connectToServer()); + } +void CSmfClientSymbian::writeLog(QString log) + { +#ifdef WRITE_LOG + QFile file("c:\\data\\SmfClientLogs.txt"); + if (!file.open(QIODevice::Append | QIODevice::Text)) + return; + QTextStream out(&file); + out << log << "\n"; + file.close(); +#endif + } + +void CSmfClientSymbian::DoCancel() + { + Cancel(); + } + +TInt CSmfClientSymbian::RunError(TInt aError) + { + QString log2("CSmfClientSymbian::RunError="); + + log2 += QString::number(aError); + writeLog(log2); + return KErrNone; + } + +void CSmfClientSymbian::RunL() + { + QString log2("CSmfClientSymbian::RunL="); + log2 += QString::number(iStatus.Int()); + writeLog(log2); + switch ( iStatus.Int() ) + { + case KErrCancel: + // The request was canceled + writeLog("KErrCancel"); + break ; + + case KErrNotReady: + writeLog("KErrNotReady"); + break; + + default: + { + writeLog("RunL:-SmfContactRetrievePostsComplete"); + //This contains error followed by actual data + QByteArray receivedData(reinterpret_cast(iSession.iDataPtr.Ptr()),iSession.iDataPtr.Length()); + QString errStr; + SmfError errVal; + int errInt; + QByteArray data; + QDataStream reader(&receivedData,QIODevice::ReadOnly); + reader>>errInt; + errVal = (SmfError)errInt; + reader>>data; + SmfRequestTypeID opcode = (SmfRequestTypeID)iSession.getLastRequest(); + iObserver->resultsAvailable(data,opcode,errVal); + } + break; + } + } + +QByteArray CSmfClientSymbian::sendRequest(QString aInterfaceName, + SmfRequestTypeID requestType) + { + //This will be a synchronous request + //note session is opened in ctor and closed in dtor + writeLog("CSmfClientSymbian::sendRequest="); + writeLog(aInterfaceName); + //Gets data synchronously from the server + TPtr8 symbianBuf(iSession.sendSyncRequest(aInterfaceName,requestType)); + //convert this into bytearray + QByteArray receivedData(reinterpret_cast(symbianBuf.Ptr()),symbianBuf.Length()); + return receivedData; + // + } + +TInt CSmfClientSymbian::sendRequest(QByteArray& aSerializedData, + QString aInterfaceName, + SmfRequestTypeID requestType) + { + //TODO:-testing puspose only, should be removed in the release + if(requestType == SmfTest) + { + QString log("Before iSesson.SendAsync"); + writeLog(log); + iSession.sendAsyncRequest(aSerializedData,aInterfaceName,requestType,iStatus); + SetActive(); + QString log2("After setactive"); + writeLog(log2); + } + else + { + //RSessionBase objects sendreceive is called + iSession.sendAsyncRequest(aSerializedData,aInterfaceName,requestType,iStatus); + SetActive(); + } + } + +TInt CSmfClientSymbian::sendDummyRequest(QByteArray* provider,QString aInterfaceName, + SmfRequestTypeID requestType) + { + switch(requestType) + { + case SmfTest: + { + + } + break; + default: + //should panic + break; + } + } + +CSmfClientSymbian::~CSmfClientSymbian() + { + writeLog("~CSmfClientSymbian"); + Cancel(); // Causes call to DoCancel() + iSession.Close(); + } + +RSmfClientSymbianSession::RSmfClientSymbianSession() +:iDataPtr(NULL, 0, 0),iDataPtr16(NULL,0),iIntfNamePtr(NULL,0),iIntfNamePtr8(NULL,0),iPtrProvider(NULL,0) + { + // No implementation required + } + +TInt RSmfClientSymbianSession::connectToServer() + { + writeLog("RSmfClientSymbianSession::connectToServer"); + TInt error = ::StartServerL(); + writeLog("StartServerL="); + QString err = QString::number(error); + writeLog(err); + if ( KErrNone == error ) + { + + error = CreateSession( KSmfServerName, + Version(), + 4 ); + QString crtSessionErr = QString::number(error); + writeLog(crtSessionErr); + } + return error; + } + +//testing +void RSmfClientSymbianSession::writeLog(QString log) const + { +#ifdef WRITE_LOG + QFile file("c:\\data\\SmfClientLogs.txt"); + if (!file.open(QIODevice::Append | QIODevice::Text)) + ; + QTextStream out(&file); + out << log << "\n"; + file.close(); +#endif + } + +TPtr8 RSmfClientSymbianSession::sendSyncRequest(QString aInterfaceName, + SmfRequestTypeID aRequestType) + { + iLastRequest = aRequestType; + /** + * The message body consists of.- + * 1. Interface name as string ("org.symbian.smf.client.gallery") + * 2. Data pointer to be filled by serialized data(QList) + */ + QString log("RSmfClientSymbianSession::sendSyncRequest-start-"); + writeLog(log); + writeLog(QString("aInterfaceName=")+aInterfaceName); + + iInterfaceNamebyte.clear(); + //Convert the interface name into TPtr + iInterfaceName.clear(); + iInterfaceName = aInterfaceName ; + writeLog(QString("iInterfaceName=")+iInterfaceName); + //lets pass serialized QString + QDataStream intfNameStream(&iInterfaceNamebyte,QIODevice::WriteOnly); + intfNameStream<Des()); + log.clear(); + log = QString("After iDataPtr.Set"); + writeLog(log); + + + TIpcArgs args; + + args.Set(0, &iInterfaceSymbian8); + args.Set(1, &iDataPtr); + + TInt err(KErrBadHandle); + writeLog("Before handle"); + log.clear(); + log = QString("iInterfaceSymbian8 size=")+QString::number(iInterfaceSymbian8.Size()); + writeLog(log); + if (Handle()) + { + err = KErrNone; + log.clear(); + log = QString("Before sendreceive"); + writeLog(log); + //synchronous request + TInt sendErr = SendReceive(aRequestType, args); + if(sendErr) + { + writeLog("SendReceive error="); + QString errStr = QString::number(sendErr); + writeLog(errStr); + } + return iDataPtr; + } + } + +/** + * Calls SendReceive() after converting into symbian descriptors + * + */ +void RSmfClientSymbianSession::sendAsyncRequest(QByteArray& aSerializedData, + QString aInterfaceName, + SmfRequestTypeID aRequestType, + TRequestStatus& aStatus) + { + iLastRequest = aRequestType; + /** + * The message body consists of.- + * 1. Provider Info(SmfProvider*)+ Other common class data + * (when applicable)-serialized + * 2. Interface name as string ("org.symbian.smf.client.gallery") + * 3. Data pointer to be filled by serialized data + */ + QString log("RSmfClientSymbianSession::sendAsyncRequest-start-"); + writeLog(log); + + iBaseProvider= aSerializedData; + iInterfaceName = aInterfaceName ; + + int size = aSerializedData.size(); + log.clear(); + log = QString("aSerializedData size=")+ QString::number(size); + + writeLog(log); + if(iProviderBuf) + { + delete iProviderBuf; + iProviderBuf = NULL; + } + //TODO:- KSmfProviderMaxSize + iProviderBuf = HBufC8::NewL(iBaseProvider.size()*2); + iPtrProvider.Set(iProviderBuf->Des()); + //convert the QByteArray into TPtr + iPtrProvider.Copy(reinterpret_cast(iBaseProvider.constData()),iBaseProvider.length()); + + + log.clear(); + log = QString("iPtrProvider.Copy"); + writeLog(log); + + //Convert the interface name into TPtr//////////////////////// + iInterfaceName.clear(); + iInterfaceName = aInterfaceName ; + writeLog(QString("iInterfaceName=")+iInterfaceName); + //Pass serialized QString for interface name + QDataStream intfNameStream(&iInterfaceNamebyte,QIODevice::WriteOnly); + intfNameStream<