1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/LddAsyncRequest.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,310 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "mmcldd.h"
1.23 +#include "d_mmcsdif.h"
1.24 +#include "LddAsyncRequest.h"
1.25 +
1.26 +/**
1.27 + * DLddAsyncRequest constructor
1.28 + *
1.29 + * @param TInt aFunctionId - functionId
1.30 + * @param TRequestStatus* aStatus for signalling upon completion
1.31 + * @param MAsyncRequestObserver& aObserver - observer recieves notification upon completion
1.32 + *
1.33 + * @return N/A
1.34 + *
1.35 + * @leave N/A
1.36 + */
1.37 +DLddAsyncRequest::DLddAsyncRequest(TInt aFunctionId, TRequestStatus* aStatus, MAsyncRequestObserver& aObserver)
1.38 +: iFunctionId(aFunctionId)
1.39 +, iStatus(aStatus)
1.40 +, iObserver(aObserver)
1.41 +, iError(KErrNone)
1.42 + {
1.43 + }
1.44 +
1.45 +/**
1.46 + * Destructor
1.47 + *
1.48 + * @return N/A
1.49 + *
1.50 + * @leave N/A
1.51 + */
1.52 +DLddAsyncRequest::~DLddAsyncRequest()
1.53 + {
1.54 + }
1.55 +
1.56 +/**
1.57 + * Get the error code for this request
1.58 + *
1.59 + *
1.60 + * @return TInt the error code
1.61 + *
1.62 + * @leave N/A
1.63 + */
1.64 +TInt DLddAsyncRequest::Error()
1.65 + {
1.66 + return iError;
1.67 + }
1.68 +
1.69 +/**
1.70 + * Get the function Id for this request
1.71 + *
1.72 + * @return TInt the function Id
1.73 + *
1.74 + * @leave N/A
1.75 + */
1.76 +TInt DLddAsyncRequest::FunctionId()
1.77 + {
1.78 + return iFunctionId;
1.79 + }
1.80 +
1.81 +/**
1.82 + * Get the status of this request
1.83 + *
1.84 + *
1.85 + * @return TRequestStatus status of the request
1.86 + *
1.87 + * @leave N/A
1.88 + */
1.89 +TRequestStatus* DLddAsyncRequest::Status()
1.90 + {
1.91 + return iStatus;
1.92 + }
1.93 +
1.94 +
1.95 +///////////////////////////////////////////////////////////////////////
1.96 +//////////////////// DMmcSessionAsyncRequest //////////////////////////
1.97 +///////////////////////////////////////////////////////////////////////
1.98 +
1.99 +/**
1.100 + * DMmcSessionAsyncRequest Constructor
1.101 + *
1.102 + * @param TInt aFunctionId - functionId
1.103 + * @param TRequestStatus* aStatus for signalling upon completion
1.104 + * @param MAsyncRequestObserver& aObserver - observer recieves notification upon completion
1.105 + * @param TDynamicDfcQue* aDfcQ - pointer to dfc queue,
1.106 + * @param DMMCStack& aStack stack upon which this request will operate
1.107 + * @param TMMCard& aCard multimedia card upon which this request will operate
1.108 + *
1.109 + *
1.110 + * @return N/A
1.111 + *
1.112 + * @leave N/A
1.113 + */
1.114 +DMmcSessionAsyncRequest::DMmcSessionAsyncRequest(TInt aFunctionId, TRequestStatus* aStatus,
1.115 + MAsyncRequestObserver& aObserver, TDynamicDfcQue* aDfcQ, DMMCStack& aStack, TMMCard& aCard)
1.116 +: DLddAsyncRequest(aFunctionId, aStatus, aObserver)
1.117 +, iSession(NULL)
1.118 +, iSessionEndCallBack(DMmcSessionAsyncRequest::SessionEndCallBack, this)
1.119 +, iSessionEndDfc(DMmcSessionAsyncRequest::SessionEndDfc, this, 1)
1.120 +, iClientDesPtr(NULL)
1.121 +, iBlkOffet(0)
1.122 +, iBuf(NULL)
1.123 + {
1.124 + TInt bufLen;
1.125 + TInt minorBufLen;
1.126 + aStack.BufferInfo(iBuf, bufLen, minorBufLen);
1.127 +
1.128 + iSession = aStack.AllocSession(iSessionEndCallBack);
1.129 + iSession->SetStack(&aStack);
1.130 + iSession->SetCard(&aCard);
1.131 +
1.132 + iSessionEndDfc.SetDfcQ(aDfcQ);
1.133 +
1.134 + Reset();
1.135 + }
1.136 +
1.137 +/**
1.138 + * Destructor
1.139 + *
1.140 + * @return N/A
1.141 + *
1.142 + * @leave N/A
1.143 + */
1.144 +DMmcSessionAsyncRequest::~DMmcSessionAsyncRequest()
1.145 + {
1.146 + Reset();
1.147 + delete iSession;
1.148 + }
1.149 +
1.150 +void DMmcSessionAsyncRequest::Reset()
1.151 +{
1.152 + MMCSDLOG("iSessionEndDfc.Cancel() called");
1.153 + iSessionEndDfc.Cancel();
1.154 +}
1.155 +
1.156 +
1.157 +/**
1.158 + * Gets the async requests DMMCSession
1.159 + *
1.160 + * @return reference to the DMMCSession
1.161 + *
1.162 + * @leave N/A
1.163 + */
1.164 +DMMCSession& DMmcSessionAsyncRequest::Session()
1.165 + {
1.166 + return *iSession;
1.167 + }
1.168 +
1.169 +/**
1.170 + * The session end callback (static)- called when and engaged session completes
1.171 + *
1.172 + * @param TAny* in this case this will be a pointer to the DMmcSessionAsyncRequest
1.173 + *
1.174 + * @return void
1.175 + *
1.176 + * @leave N/A
1.177 + */
1.178 +void DMmcSessionAsyncRequest::SessionEndCallBack(TAny *aPtr)
1.179 + {
1.180 + ((DMmcSessionAsyncRequest*)aPtr)->SessionEndCallBack();
1.181 + }
1.182 +
1.183 +
1.184 +/**
1.185 + * Utility function called from static overload SessionEndCallBack(TAny*)
1.186 + *
1.187 + * @return void
1.188 + *
1.189 + * @leave N/A
1.190 + */
1.191 +void DMmcSessionAsyncRequest::SessionEndCallBack()
1.192 + {
1.193 + MMCSDLOG("DMmcSessionAsyncRequest::SessionEndCallBack called");
1.194 + iError = iSession->EpocErrorCode();
1.195 +
1.196 + if (NKern::CurrentContext()==NKern::EInterrupt)
1.197 + {
1.198 + iSessionEndDfc.Add();
1.199 + }
1.200 + else
1.201 + {
1.202 + // Signal request complete using DFC
1.203 + if (!iSessionEndDfc.Queued())
1.204 + {
1.205 + iSessionEndDfc.Enque();
1.206 + }
1.207 + }
1.208 + }
1.209 +
1.210 +
1.211 +/**
1.212 + * Session deferred function call (static)
1.213 + *
1.214 + * @param TAny* in this case this will be a pointer to the DMmcSessionAsyncRequest
1.215 + *
1.216 + * @return void
1.217 + *
1.218 + * @leave N/A
1.219 + */
1.220 +void DMmcSessionAsyncRequest::SessionEndDfc(TAny *aPtr)
1.221 + {
1.222 + ((DMmcSessionAsyncRequest*) aPtr)->SessionEndDfc();
1.223 + }
1.224 +
1.225 +
1.226 +/**
1.227 + * Utility function called from static overload SessionEndDfc(TAny*)
1.228 + *
1.229 + * @return void
1.230 + *
1.231 + * @leave N/A
1.232 + */
1.233 +void DMmcSessionAsyncRequest::SessionEndDfc()
1.234 + {
1.235 + MMCSDLOG2("DLddAsyncRequest::SessionEndDfc called err(%d)", iError);
1.236 + iObserver.Notify(*this);
1.237 + MMCSDLOG("DLddAsyncRequest::SessionEndDfc finished");
1.238 + }
1.239 +
1.240 +
1.241 +
1.242 +/**
1.243 + * DBusEventRequest constructor
1.244 + *
1.245 + * @param TInt aFunctionId - Function ID
1.246 + * @param TRequestStatus* aStatus - Request Status
1.247 + * @param MAsyncRequestObserver& aObserver - Asynchronous Request observer interface
1.248 + * @param TInt aUnit - Socket ID
1.249 + *
1.250 + * @return N/A
1.251 + *
1.252 + * @leave N/A
1.253 + */
1.254 +DBusEventRequest::DBusEventRequest(TInt aFunctionId, TRequestStatus* aStatus, MAsyncRequestObserver& aObserver, TInt aUnit,
1.255 + TDynamicDfcQue* aDfcQ, DMMCStack& aStack, TMMCard& aCard)
1.256 +: DMmcSessionAsyncRequest(aFunctionId, aStatus, aObserver, aDfcQ, aStack, aCard)
1.257 +, iBusEventCallBack(DBusEventRequest::BusEventCallBack, this)
1.258 + {
1.259 + iBusEventCallBack.SetSocket(aUnit);
1.260 + iBusEventCallBack.Add();
1.261 +
1.262 + }
1.263 +/**
1.264 + * Destructor
1.265 + *
1.266 + * @return N/A
1.267 + *
1.268 + * @leave N/A
1.269 + */
1.270 +DBusEventRequest::~DBusEventRequest()
1.271 + {
1.272 + iBusEventCallBack.Remove();
1.273 + }
1.274 +
1.275 +/**
1.276 + * Callback when request has completed
1.277 + *
1.278 + * @param TAny* aPtr - Pointer to the bus event request
1.279 + * @param TInt aReason - Completion error code
1.280 + * @param TAny* a1 - Given parameter
1.281 + * @param TAny* a2 - Given parameter
1.282 + *
1.283 + * @return N/A
1.284 + *
1.285 + * @leave N/A
1.286 + */
1.287 +void DBusEventRequest::BusEventCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2)
1.288 + {
1.289 + ((DBusEventRequest*)aPtr)->BusEventCallBack(aReason, a1, a2);
1.290 + }
1.291 +
1.292 +/**
1.293 + * Callback when request has completed
1.294 + *
1.295 + * @param TInt aReason - Completion error code
1.296 + * @param TAny* a1 - Given parameter
1.297 + * @param TAny* a2 - Given parameter
1.298 + *
1.299 + * @return N/A
1.300 + *
1.301 + * @leave N/A
1.302 + */
1.303 +void DBusEventRequest::BusEventCallBack(TInt aReason, TAny* a1, TAny* a2)
1.304 + {
1.305 +
1.306 + MMCSDLOG("DBusEventRequest::BusEventCallBack called");
1.307 + iError = aReason;
1.308 + iBusState = (TPBusState)((TInt) a1);
1.309 + iBusError = (TInt) a2;
1.310 + MMCSDLOG4("DBusEventRequest::BusEventCallBack iBusState(%d) iBusError(%d) iError(%d)", iBusState, iBusError, iError);
1.311 + iObserver.Notify(*this);
1.312 + MMCSDLOG("DBusEventRequest::BusEventCallBack finished");
1.313 + }