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