sl@0: /* sl@0: * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "CFSClient.h" sl@0: #include "clientutils.h" sl@0: #include "clientsession.h" sl@0: sl@0: CFSClient::CFSClient(TInt aUID, sl@0: MCTToken& aToken, sl@0: RFileStoreClientSession& aClient) sl@0: : CActive(EPriorityNormal), sl@0: iToken(aToken), sl@0: iInterfaceUID(aUID), sl@0: iClient(aClient), sl@0: iRequestPtr(NULL, 0, 0) sl@0: { sl@0: } sl@0: sl@0: CFSClient::~CFSClient() sl@0: { sl@0: Cancel(); sl@0: delete iRequestDataBuf; sl@0: } sl@0: sl@0: CFSClient::TAsyncRequest::~TAsyncRequest() sl@0: { sl@0: __ASSERT_DEBUG(EIdle==iRequest, FSTokenPanic(ERequestOutstanding)); sl@0: } sl@0: sl@0: void CFSClient::TAsyncRequest::operator()(TFSTokenMessages aRequest, TRequestStatus* aStatus) sl@0: { sl@0: __ASSERT_DEBUG(EIdle==iRequest, FSTokenPanic(ERequestOutstanding)); sl@0: sl@0: iRequest = aRequest; sl@0: iClientStatus = aStatus; sl@0: *aStatus = KRequestPending; sl@0: } sl@0: sl@0: void CFSClient::TAsyncRequest::Complete(TInt aCompletionResult) sl@0: { sl@0: __ASSERT_DEBUG(EIdle!=iRequest, FSTokenPanic(ENoRequestOutstanding)); sl@0: User::RequestComplete(iClientStatus, aCompletionResult); sl@0: iRequest = EIdle; sl@0: } sl@0: sl@0: void CFSClient::TAsyncRequest::Cancel() sl@0: { sl@0: User::RequestComplete(iClientStatus, KErrCancel); sl@0: iRequest = EIdle; sl@0: } sl@0: sl@0: void CFSClient::FreeRequestBuffer() const sl@0: { sl@0: delete iRequestDataBuf; sl@0: iRequestDataBuf = NULL; sl@0: iRequestPtr.Set(NULL, 0, 0); sl@0: } sl@0: sl@0: TInt CFSClient::AllocRequestBuffer(TInt aReqdSize) const sl@0: { sl@0: ASSERT(aReqdSize > 0); sl@0: TInt result = KErrNoMemory; sl@0: sl@0: FreeRequestBuffer(); sl@0: iRequestDataBuf = HBufC8::NewMax(aReqdSize); sl@0: if (iRequestDataBuf) sl@0: { sl@0: iRequestPtr.Set(iRequestDataBuf->Des()); sl@0: iRequestPtr.FillZ(); sl@0: result = KErrNone; sl@0: } sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: * Execute a synchronous request that returns a buffer of indetermintate length. sl@0: * sl@0: * If the initial buffer is too short, the server leaves with KErrOverflow and sl@0: * passes us the required length - the reuest is then re-sent. sl@0: */ sl@0: void CFSClient::SendSyncRequestAndHandleOverflowL(TFSTokenMessages aMessage, sl@0: TInt aInitialBufSize, sl@0: const TIpcArgs& aArgs) const sl@0: { sl@0: User::LeaveIfError(AllocRequestBuffer(aInitialBufSize)); sl@0: sl@0: TInt err = iClient.SendRequest(aMessage, aArgs); sl@0: if (err == KErrOverflow) sl@0: { sl@0: TInt sizeReqd = 0; sl@0: TPckg<TInt> theSize(sizeReqd); sl@0: theSize.Copy(iRequestPtr); sl@0: User::LeaveIfError(AllocRequestBuffer(sizeReqd)); sl@0: err = iClient.SendRequest(aMessage, aArgs); sl@0: } sl@0: sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: // ********************************************************************************* sl@0: // CActive implementation sl@0: // ********************************************************************************* sl@0: sl@0: void CFSClient::DoCancel() sl@0: { sl@0: iCurrentRequest.Cancel(); sl@0: } sl@0: sl@0: TInt CFSClient::RunError(TInt aError) sl@0: { sl@0: iCurrentRequest.Complete(aError); sl@0: return KErrNone; // Handled sl@0: }