os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/LddAsyncRequest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 #include "mmcldd.h"
    20 #include "d_mmcsdif.h"
    21 #include "LddAsyncRequest.h"
    22 
    23 /**
    24  * DLddAsyncRequest constructor
    25  *
    26  * @param TInt aFunctionId - functionId 
    27  * @param TRequestStatus* aStatus	for signalling upon completion
    28  * @param MAsyncRequestObserver& aObserver	- observer recieves notification upon completion 
    29  *
    30  * @return N/A
    31  *
    32  * @leave N/A					
    33  */
    34 DLddAsyncRequest::DLddAsyncRequest(TInt aFunctionId, TRequestStatus* aStatus, MAsyncRequestObserver& aObserver) 
    35 : iFunctionId(aFunctionId)
    36 , iStatus(aStatus)
    37 , iObserver(aObserver)
    38 , iError(KErrNone) 
    39 	{
    40 	}
    41 
    42 /**
    43  * Destructor 
    44  *
    45  * @return N/A
    46  *
    47  * @leave	N/A				
    48  */
    49 DLddAsyncRequest::~DLddAsyncRequest()
    50 	{
    51 	}
    52 
    53 /**
    54  * Get the error code for this request 
    55  *
    56  *
    57  * @return TInt the error code
    58  *
    59  * @leave	 N/A				
    60  */
    61 TInt DLddAsyncRequest::Error() 
    62 	{ 
    63 	return iError; 
    64 	}
    65 
    66 /**
    67  * Get the function Id for this request
    68  *
    69  * @return TInt the function Id
    70  *
    71  * @leave N/A					
    72  */
    73 TInt DLddAsyncRequest::FunctionId() 
    74 	{ 
    75 	return iFunctionId; 
    76 	}
    77 
    78 /**
    79  * Get the status of this request 
    80  *
    81  *
    82  * @return TRequestStatus status of the request
    83  *
    84  * @leave N/A					 
    85  */
    86 TRequestStatus* DLddAsyncRequest::Status()
    87 	{
    88 	return iStatus;
    89 	}
    90 
    91 
    92 ///////////////////////////////////////////////////////////////////////
    93 //////////////////// DMmcSessionAsyncRequest //////////////////////////
    94 ///////////////////////////////////////////////////////////////////////
    95 
    96 /**
    97  * DMmcSessionAsyncRequest Constructor  
    98  *
    99  * @param TInt aFunctionId - functionId 
   100  * @param TRequestStatus* aStatus	for signalling upon completion
   101  * @param MAsyncRequestObserver& aObserver	- observer recieves notification upon completion 
   102  * @param TDynamicDfcQue* aDfcQ - pointer to dfc queue,  	 
   103  * @param DMMCStack& aStack	stack upon which this request will operate
   104  * @param TMMCard& aCard multimedia card upon which this request will operate
   105  *
   106  * 
   107  * @return N/A
   108  *
   109  * @leave N/A					
   110  */
   111 DMmcSessionAsyncRequest::DMmcSessionAsyncRequest(TInt aFunctionId, TRequestStatus* aStatus, 
   112 		MAsyncRequestObserver& aObserver, TDynamicDfcQue* aDfcQ, DMMCStack& aStack, TMMCard& aCard)
   113 : DLddAsyncRequest(aFunctionId, aStatus, aObserver)
   114 , iSession(NULL)
   115 , iSessionEndCallBack(DMmcSessionAsyncRequest::SessionEndCallBack, this)
   116 , iSessionEndDfc(DMmcSessionAsyncRequest::SessionEndDfc, this, 1)
   117 , iClientDesPtr(NULL)
   118 , iBlkOffet(0)
   119 , iBuf(NULL)
   120 	{
   121 	TInt bufLen;
   122 	TInt minorBufLen;
   123 	aStack.BufferInfo(iBuf, bufLen, minorBufLen);
   124 	
   125 	iSession = aStack.AllocSession(iSessionEndCallBack);
   126 	iSession->SetStack(&aStack);
   127 	iSession->SetCard(&aCard);
   128 
   129 	iSessionEndDfc.SetDfcQ(aDfcQ);
   130 	
   131 	Reset();
   132 	}
   133 
   134 /**
   135  * Destructor
   136  *
   137  * @return N/A
   138  *
   139  * @leave N/A					
   140  */
   141 DMmcSessionAsyncRequest::~DMmcSessionAsyncRequest()
   142 	{
   143 	Reset();
   144 	delete iSession;
   145 	}
   146 
   147 void DMmcSessionAsyncRequest::Reset()
   148 {
   149 	MMCSDLOG("iSessionEndDfc.Cancel() called");	
   150 	iSessionEndDfc.Cancel();
   151 }
   152 
   153 
   154 /**
   155  * Gets the async requests DMMCSession 
   156  *
   157  * @return reference to the DMMCSession
   158  *
   159  * @leave N/A					
   160  */
   161 DMMCSession& DMmcSessionAsyncRequest::Session()
   162 	{
   163 	return *iSession;
   164 	}
   165 
   166 /**
   167  * The session end callback (static)- called when and engaged session completes 
   168  *
   169  * @param 	TAny* in this case this will be a pointer to the DMmcSessionAsyncRequest 			
   170  *
   171  * @return void
   172  *
   173  * @leave	N/A				
   174  */
   175 void DMmcSessionAsyncRequest::SessionEndCallBack(TAny *aPtr)
   176 	{
   177 	((DMmcSessionAsyncRequest*)aPtr)->SessionEndCallBack();
   178 	}
   179 
   180 
   181 /**
   182  * Utility function called from static overload SessionEndCallBack(TAny*)
   183  *
   184  * @return void
   185  *
   186  * @leave		N/A			
   187  */
   188 void DMmcSessionAsyncRequest::SessionEndCallBack()
   189 	{
   190 	MMCSDLOG("DMmcSessionAsyncRequest::SessionEndCallBack called");
   191 	iError = iSession->EpocErrorCode();
   192 
   193 	if (NKern::CurrentContext()==NKern::EInterrupt)
   194 		{
   195 		iSessionEndDfc.Add();
   196 		}
   197 	else
   198 		{
   199 		// Signal request complete using DFC
   200 		if (!iSessionEndDfc.Queued())
   201 			{
   202 			iSessionEndDfc.Enque();
   203 			}
   204 		}
   205 	}
   206 
   207 
   208 /**
   209  * Session deferred function call (static)
   210  *
   211  * @param 	TAny* in this case this will be a pointer to the DMmcSessionAsyncRequest 			
   212  *
   213  * @return void
   214  *
   215  * @leave	N/A				
   216  */
   217 void DMmcSessionAsyncRequest::SessionEndDfc(TAny *aPtr)
   218 	{
   219 	((DMmcSessionAsyncRequest*) aPtr)->SessionEndDfc();
   220 	}
   221 
   222 
   223 /**
   224  * Utility function called from static overload SessionEndDfc(TAny*)
   225  *
   226  * @return void
   227  *
   228  * @leave		N/A			
   229  */
   230 void DMmcSessionAsyncRequest::SessionEndDfc()
   231 	{
   232 	MMCSDLOG2("DLddAsyncRequest::SessionEndDfc called err(%d)", iError);	
   233 	iObserver.Notify(*this);
   234 	MMCSDLOG("DLddAsyncRequest::SessionEndDfc finished");
   235 	}
   236 
   237 
   238 
   239 /**
   240  * DBusEventRequest constructor
   241  *
   242  * @param TInt aFunctionId - Function ID
   243  * @param TRequestStatus* aStatus - Request Status
   244  * @param MAsyncRequestObserver& aObserver - Asynchronous Request observer interface
   245  * @param TInt aUnit - Socket ID
   246  *
   247  * @return N/A
   248  *
   249  * @leave N/A
   250  */
   251 DBusEventRequest::DBusEventRequest(TInt aFunctionId, TRequestStatus* aStatus, MAsyncRequestObserver& aObserver, TInt aUnit,
   252 									TDynamicDfcQue* aDfcQ, DMMCStack& aStack, TMMCard& aCard) 
   253 : DMmcSessionAsyncRequest(aFunctionId, aStatus, aObserver, aDfcQ, aStack, aCard)
   254 , iBusEventCallBack(DBusEventRequest::BusEventCallBack, this)
   255 	{
   256 	iBusEventCallBack.SetSocket(aUnit);
   257 	iBusEventCallBack.Add();
   258 	
   259 	}
   260 /**
   261  * Destructor
   262  *
   263  * @return N/A
   264  *
   265  * @leave N/A
   266  */
   267 DBusEventRequest::~DBusEventRequest()
   268 	{
   269 	iBusEventCallBack.Remove();
   270 	}
   271 
   272 /**
   273  * Callback when request has completed
   274  *
   275  * @param TAny* aPtr - Pointer to the bus event request
   276  * @param TInt aReason - Completion error code
   277  * @param TAny* a1 - Given parameter
   278  * @param TAny* a2 - Given parameter
   279  *
   280  * @return N/A
   281  *
   282  * @leave N/A
   283  */
   284 void DBusEventRequest::BusEventCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2)
   285 	{	
   286 	((DBusEventRequest*)aPtr)->BusEventCallBack(aReason, a1, a2);	
   287 	}
   288 
   289 /**
   290  * Callback when request has completed
   291  *
   292  * @param TInt aReason - Completion error code
   293  * @param TAny* a1 - Given parameter
   294  * @param TAny* a2 - Given parameter
   295  *
   296  * @return N/A
   297  *
   298  * @leave N/A
   299  */
   300 void DBusEventRequest::BusEventCallBack(TInt aReason, TAny* a1, TAny* a2)
   301 	{
   302 	
   303 	MMCSDLOG("DBusEventRequest::BusEventCallBack called");
   304 	iError = aReason;
   305 	iBusState = (TPBusState)((TInt) a1);
   306 	iBusError = (TInt) a2;
   307 	MMCSDLOG4("DBusEventRequest::BusEventCallBack iBusState(%d) iBusError(%d) iError(%d)", iBusState, iBusError, iError);
   308 	iObserver.Notify(*this);
   309 	MMCSDLOG("DBusEventRequest::BusEventCallBack finished");
   310 	}