sl@0: /* sl@0: * Copyright (c) 2005-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 "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 "mmcldd.h" sl@0: #include "d_mmcsdif.h" sl@0: #include "LddAsyncRequest.h" sl@0: sl@0: /** sl@0: * DLddAsyncRequest constructor sl@0: * sl@0: * @param TInt aFunctionId - functionId sl@0: * @param TRequestStatus* aStatus for signalling upon completion sl@0: * @param MAsyncRequestObserver& aObserver - observer recieves notification upon completion sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DLddAsyncRequest::DLddAsyncRequest(TInt aFunctionId, TRequestStatus* aStatus, MAsyncRequestObserver& aObserver) sl@0: : iFunctionId(aFunctionId) sl@0: , iStatus(aStatus) sl@0: , iObserver(aObserver) sl@0: , iError(KErrNone) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Destructor sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DLddAsyncRequest::~DLddAsyncRequest() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: * Get the error code for this request sl@0: * sl@0: * sl@0: * @return TInt the error code sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: TInt DLddAsyncRequest::Error() sl@0: { sl@0: return iError; sl@0: } sl@0: sl@0: /** sl@0: * Get the function Id for this request sl@0: * sl@0: * @return TInt the function Id sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: TInt DLddAsyncRequest::FunctionId() sl@0: { sl@0: return iFunctionId; sl@0: } sl@0: sl@0: /** sl@0: * Get the status of this request sl@0: * sl@0: * sl@0: * @return TRequestStatus status of the request sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: TRequestStatus* DLddAsyncRequest::Status() sl@0: { sl@0: return iStatus; sl@0: } sl@0: sl@0: sl@0: /////////////////////////////////////////////////////////////////////// sl@0: //////////////////// DMmcSessionAsyncRequest ////////////////////////// sl@0: /////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: * DMmcSessionAsyncRequest Constructor sl@0: * sl@0: * @param TInt aFunctionId - functionId sl@0: * @param TRequestStatus* aStatus for signalling upon completion sl@0: * @param MAsyncRequestObserver& aObserver - observer recieves notification upon completion sl@0: * @param TDynamicDfcQue* aDfcQ - pointer to dfc queue, sl@0: * @param DMMCStack& aStack stack upon which this request will operate sl@0: * @param TMMCard& aCard multimedia card upon which this request will operate sl@0: * sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DMmcSessionAsyncRequest::DMmcSessionAsyncRequest(TInt aFunctionId, TRequestStatus* aStatus, sl@0: MAsyncRequestObserver& aObserver, TDynamicDfcQue* aDfcQ, DMMCStack& aStack, TMMCard& aCard) sl@0: : DLddAsyncRequest(aFunctionId, aStatus, aObserver) sl@0: , iSession(NULL) sl@0: , iSessionEndCallBack(DMmcSessionAsyncRequest::SessionEndCallBack, this) sl@0: , iSessionEndDfc(DMmcSessionAsyncRequest::SessionEndDfc, this, 1) sl@0: , iClientDesPtr(NULL) sl@0: , iBlkOffet(0) sl@0: , iBuf(NULL) sl@0: { sl@0: TInt bufLen; sl@0: TInt minorBufLen; sl@0: aStack.BufferInfo(iBuf, bufLen, minorBufLen); sl@0: sl@0: iSession = aStack.AllocSession(iSessionEndCallBack); sl@0: iSession->SetStack(&aStack); sl@0: iSession->SetCard(&aCard); sl@0: sl@0: iSessionEndDfc.SetDfcQ(aDfcQ); sl@0: sl@0: Reset(); sl@0: } sl@0: sl@0: /** sl@0: * Destructor sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DMmcSessionAsyncRequest::~DMmcSessionAsyncRequest() sl@0: { sl@0: Reset(); sl@0: delete iSession; sl@0: } sl@0: sl@0: void DMmcSessionAsyncRequest::Reset() sl@0: { sl@0: MMCSDLOG("iSessionEndDfc.Cancel() called"); sl@0: iSessionEndDfc.Cancel(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Gets the async requests DMMCSession sl@0: * sl@0: * @return reference to the DMMCSession sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DMMCSession& DMmcSessionAsyncRequest::Session() sl@0: { sl@0: return *iSession; sl@0: } sl@0: sl@0: /** sl@0: * The session end callback (static)- called when and engaged session completes sl@0: * sl@0: * @param TAny* in this case this will be a pointer to the DMmcSessionAsyncRequest sl@0: * sl@0: * @return void sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: void DMmcSessionAsyncRequest::SessionEndCallBack(TAny *aPtr) sl@0: { sl@0: ((DMmcSessionAsyncRequest*)aPtr)->SessionEndCallBack(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Utility function called from static overload SessionEndCallBack(TAny*) sl@0: * sl@0: * @return void sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: void DMmcSessionAsyncRequest::SessionEndCallBack() sl@0: { sl@0: MMCSDLOG("DMmcSessionAsyncRequest::SessionEndCallBack called"); sl@0: iError = iSession->EpocErrorCode(); sl@0: sl@0: if (NKern::CurrentContext()==NKern::EInterrupt) sl@0: { sl@0: iSessionEndDfc.Add(); sl@0: } sl@0: else sl@0: { sl@0: // Signal request complete using DFC sl@0: if (!iSessionEndDfc.Queued()) sl@0: { sl@0: iSessionEndDfc.Enque(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Session deferred function call (static) sl@0: * sl@0: * @param TAny* in this case this will be a pointer to the DMmcSessionAsyncRequest sl@0: * sl@0: * @return void sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: void DMmcSessionAsyncRequest::SessionEndDfc(TAny *aPtr) sl@0: { sl@0: ((DMmcSessionAsyncRequest*) aPtr)->SessionEndDfc(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: * Utility function called from static overload SessionEndDfc(TAny*) sl@0: * sl@0: * @return void sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: void DMmcSessionAsyncRequest::SessionEndDfc() sl@0: { sl@0: MMCSDLOG2("DLddAsyncRequest::SessionEndDfc called err(%d)", iError); sl@0: iObserver.Notify(*this); sl@0: MMCSDLOG("DLddAsyncRequest::SessionEndDfc finished"); sl@0: } sl@0: sl@0: sl@0: sl@0: /** sl@0: * DBusEventRequest constructor sl@0: * sl@0: * @param TInt aFunctionId - Function ID sl@0: * @param TRequestStatus* aStatus - Request Status sl@0: * @param MAsyncRequestObserver& aObserver - Asynchronous Request observer interface sl@0: * @param TInt aUnit - Socket ID sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DBusEventRequest::DBusEventRequest(TInt aFunctionId, TRequestStatus* aStatus, MAsyncRequestObserver& aObserver, TInt aUnit, sl@0: TDynamicDfcQue* aDfcQ, DMMCStack& aStack, TMMCard& aCard) sl@0: : DMmcSessionAsyncRequest(aFunctionId, aStatus, aObserver, aDfcQ, aStack, aCard) sl@0: , iBusEventCallBack(DBusEventRequest::BusEventCallBack, this) sl@0: { sl@0: iBusEventCallBack.SetSocket(aUnit); sl@0: iBusEventCallBack.Add(); sl@0: sl@0: } sl@0: /** sl@0: * Destructor sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: DBusEventRequest::~DBusEventRequest() sl@0: { sl@0: iBusEventCallBack.Remove(); sl@0: } sl@0: sl@0: /** sl@0: * Callback when request has completed sl@0: * sl@0: * @param TAny* aPtr - Pointer to the bus event request sl@0: * @param TInt aReason - Completion error code sl@0: * @param TAny* a1 - Given parameter sl@0: * @param TAny* a2 - Given parameter sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: void DBusEventRequest::BusEventCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2) sl@0: { sl@0: ((DBusEventRequest*)aPtr)->BusEventCallBack(aReason, a1, a2); sl@0: } sl@0: sl@0: /** sl@0: * Callback when request has completed sl@0: * sl@0: * @param TInt aReason - Completion error code sl@0: * @param TAny* a1 - Given parameter sl@0: * @param TAny* a2 - Given parameter sl@0: * sl@0: * @return N/A sl@0: * sl@0: * @leave N/A sl@0: */ sl@0: void DBusEventRequest::BusEventCallBack(TInt aReason, TAny* a1, TAny* a2) sl@0: { sl@0: sl@0: MMCSDLOG("DBusEventRequest::BusEventCallBack called"); sl@0: iError = aReason; sl@0: iBusState = (TPBusState)((TInt) a1); sl@0: iBusError = (TInt) a2; sl@0: MMCSDLOG4("DBusEventRequest::BusEventCallBack iBusState(%d) iBusError(%d) iError(%d)", iBusState, iBusError, iError); sl@0: iObserver.Notify(*this); sl@0: MMCSDLOG("DBusEventRequest::BusEventCallBack finished"); sl@0: }