os/kernelhwsrv/kerneltest/e32test/demandpaging/d_pagingexample_2_pre.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\e32test\demandpaging\d_pagingexample_2_pre.cpp
sl@0
    15
// Demand paging migration example device driver d_pagingexample_2_pre: a
sl@0
    16
// DLogicalChannelBase-dervied driver, pre-migration
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#include "d_pagingexample.h"
sl@0
    21
#include <kernel/kernel.h>
sl@0
    22
#include <kernel/kern_priv.h>
sl@0
    23
sl@0
    24
const TInt KBufferSize = KMaxTransferSize;
sl@0
    25
sl@0
    26
//
sl@0
    27
// Logical channel
sl@0
    28
//
sl@0
    29
sl@0
    30
class DExampleChannel : public DLogicalChannelBase
sl@0
    31
	{
sl@0
    32
public:
sl@0
    33
	typedef RPagingExample::TConfigData TConfigData;
sl@0
    34
	typedef RPagingExample::TValueStruct TValueStruct;
sl@0
    35
public:
sl@0
    36
	DExampleChannel();
sl@0
    37
	~DExampleChannel();
sl@0
    38
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    39
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    40
	TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
sl@0
    41
	TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2);
sl@0
    42
	TInt DoCancel(TUint aMask);
sl@0
    43
private:
sl@0
    44
 	TDfcQue* DfcQ();
sl@0
    45
	void Shutdown();
sl@0
    46
	void GetConfig(TConfigData&);
sl@0
    47
	void SetConfig(const TConfigData&);
sl@0
    48
	TInt StartNotify(TRequestStatus* aStatus);
sl@0
    49
	TInt StartAsyncGetValue(TInt* aValue, TRequestStatus* aStatus);
sl@0
    50
	TInt StartAsyncGetValue2(TInt* aValue1, TInt* aValue2, TRequestStatus* aStatus);
sl@0
    51
	TInt StartRead(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus);
sl@0
    52
	TInt StartReadDes(TDes8* aDesOut, TRequestStatus* aStatus);
sl@0
    53
	TInt StartWrite(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus);
sl@0
    54
	TInt StartWriteDes(const TDesC8* aDesIn, TRequestStatus* aStatus);
sl@0
    55
	void ReceiveToReadBuffer();
sl@0
    56
	void SendFromWriteBuffer();
sl@0
    57
	static void CancelDfcFunc(TAny* aPtr);
sl@0
    58
	static void AsyncGetValueCompleteDfcFunc(TAny* aPtr);
sl@0
    59
	static void AsyncGetValue2CompleteDfcFunc(TAny* aPtr);
sl@0
    60
	static void ReceiveCompleteDfcFunc(TAny* aPtr);
sl@0
    61
	static void SendCompleteDfcFunc(TAny* aPtr);
sl@0
    62
	void CompleteNotify();
sl@0
    63
	void CompleteAsyncGetValue();
sl@0
    64
	void CompleteAsyncGetValue2();
sl@0
    65
	void CompleteRead();
sl@0
    66
	void CompleteWrite();
sl@0
    67
	void Cancel();
sl@0
    68
private:
sl@0
    69
	NFastMutex iLock;
sl@0
    70
	TConfigData iConfig;
sl@0
    71
	DThread* iClient;
sl@0
    72
	TDfc iCancelDfc;
sl@0
    73
	
sl@0
    74
	// Notify
sl@0
    75
	TRequestStatus* iNotifyStatus;
sl@0
    76
	
sl@0
    77
	// Async get value
sl@0
    78
	TRequestStatus* iAsyncGetValueStatus;
sl@0
    79
	TInt* iAsyncGetValueDest;
sl@0
    80
	NTimer iAsyncGetValueTimer;
sl@0
    81
	TDfc iAsyncGetValueDfc;
sl@0
    82
sl@0
    83
	// Async get value 2
sl@0
    84
	TRequestStatus* iAsyncGetValue2Status;
sl@0
    85
	TInt* iAsyncGetValue2Dest1;
sl@0
    86
	TInt* iAsyncGetValue2Dest2;
sl@0
    87
	NTimer iAsyncGetValue2Timer;
sl@0
    88
	TDfc iAsyncGetValue2Dfc;
sl@0
    89
	
sl@0
    90
	// Read
sl@0
    91
	TRequestStatus* iReadStatus;
sl@0
    92
	NTimer iReadTimer;
sl@0
    93
	TAny* iReadDest;
sl@0
    94
	TInt iReadLength;
sl@0
    95
	TDes8* iReadDes;
sl@0
    96
	TDfc iCompleteReadDfc;
sl@0
    97
	
sl@0
    98
	// Write
sl@0
    99
	TRequestStatus* iWriteStatus;
sl@0
   100
	NTimer iWriteTimer;
sl@0
   101
	TAny* iWriteSrc;
sl@0
   102
	TInt iWriteLength;
sl@0
   103
	const TDesC8* iWriteDes;
sl@0
   104
	TDfc iCompleteWriteDfc;
sl@0
   105
	TUint8 iBuffer[KBufferSize];
sl@0
   106
	};
sl@0
   107
sl@0
   108
DExampleChannel::DExampleChannel() :
sl@0
   109
	iCancelDfc(CancelDfcFunc, this, DfcQ(), 0),
sl@0
   110
	iAsyncGetValueTimer(NULL, this),
sl@0
   111
	iAsyncGetValueDfc(AsyncGetValueCompleteDfcFunc, this, DfcQ(), 0),
sl@0
   112
	iAsyncGetValue2Timer(NULL, this),
sl@0
   113
	iAsyncGetValue2Dfc(AsyncGetValue2CompleteDfcFunc, this, DfcQ(), 0),
sl@0
   114
	iReadTimer(NULL, this),
sl@0
   115
	iCompleteReadDfc(ReceiveCompleteDfcFunc, this, DfcQ(), 0),
sl@0
   116
	iWriteTimer(NULL, this),
sl@0
   117
	iCompleteWriteDfc(SendCompleteDfcFunc, this, DfcQ(), 0)
sl@0
   118
	{
sl@0
   119
	iClient = &Kern::CurrentThread();
sl@0
   120
	iClient->Open();
sl@0
   121
	}
sl@0
   122
sl@0
   123
DExampleChannel::~DExampleChannel()
sl@0
   124
	{
sl@0
   125
	Kern::SafeClose((DObject*&)iClient, NULL);
sl@0
   126
	}
sl@0
   127
sl@0
   128
TDfcQue* DExampleChannel::DfcQ()
sl@0
   129
	{
sl@0
   130
	return Kern::DfcQue0();
sl@0
   131
	}
sl@0
   132
sl@0
   133
TInt DExampleChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
sl@0
   134
	{
sl@0
   135
	return KErrNone;
sl@0
   136
	}
sl@0
   137
sl@0
   138
TInt DExampleChannel::Request(TInt aReqNo, TAny* a1, TAny* a2)
sl@0
   139
	{
sl@0
   140
	TInt r = KErrNone;	
sl@0
   141
	if (&Kern::CurrentThread() != iClient)
sl@0
   142
		r = KErrAccessDenied;  // we only support one client
sl@0
   143
	else if (aReqNo==KMaxTInt)
sl@0
   144
		{
sl@0
   145
		// DoCancel
sl@0
   146
		r = DoCancel((TInt)a1);
sl@0
   147
		}
sl@0
   148
    else if (aReqNo<0)
sl@0
   149
		{
sl@0
   150
		// DoRequest
sl@0
   151
		TRequestStatus* pS=(TRequestStatus*)a1;
sl@0
   152
		TAny* array[2] = { NULL, NULL };
sl@0
   153
		kumemget32(array, a2, 2 * sizeof(TAny*));
sl@0
   154
		r = DoRequest(~aReqNo, pS, array[0], array[1]);
sl@0
   155
		if(r != KErrNone)
sl@0
   156
			Kern::RequestComplete(pS, r);
sl@0
   157
		r = KErrNone;
sl@0
   158
		}
sl@0
   159
    else
sl@0
   160
		{
sl@0
   161
		// DoControl
sl@0
   162
		r = DoControl(aReqNo, a1, a2);
sl@0
   163
		}
sl@0
   164
	return r;
sl@0
   165
	}
sl@0
   166
sl@0
   167
TInt DExampleChannel::DoControl(TInt aFunction,TAny* a1,TAny* /*a2*/)
sl@0
   168
	{
sl@0
   169
	TInt r = KErrNone;
sl@0
   170
	TConfigData configBuffer;
sl@0
   171
	switch (aFunction)
sl@0
   172
		{
sl@0
   173
		case RPagingExample::EGetConfig:
sl@0
   174
			GetConfig(configBuffer);
sl@0
   175
			umemput32(a1, (TAny*)&configBuffer, sizeof(TConfigData));
sl@0
   176
			break;
sl@0
   177
sl@0
   178
		case RPagingExample::ESetConfig:
sl@0
   179
			umemget32(&configBuffer, a1, sizeof(TConfigData));
sl@0
   180
			SetConfig(configBuffer);
sl@0
   181
			break;
sl@0
   182
sl@0
   183
		default:
sl@0
   184
			r = KErrNotSupported;
sl@0
   185
		}
sl@0
   186
	return r;
sl@0
   187
	}
sl@0
   188
sl@0
   189
TInt DExampleChannel::DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2)
sl@0
   190
	{
sl@0
   191
	TInt r = KErrNotSupported;
sl@0
   192
	switch (aFunction)
sl@0
   193
		{
sl@0
   194
		case RPagingExample::ERequestNotify:
sl@0
   195
			r = StartNotify(aStatus);
sl@0
   196
			break;
sl@0
   197
			
sl@0
   198
		case RPagingExample::ERequestAsyncGetValue:
sl@0
   199
			r = StartAsyncGetValue((TInt*)a1, aStatus);
sl@0
   200
			break;
sl@0
   201
			
sl@0
   202
		case RPagingExample::ERequestAsyncGetValue2:
sl@0
   203
			r = StartAsyncGetValue2((TInt*)a1, (TInt*)a2, aStatus);
sl@0
   204
			break;
sl@0
   205
			
sl@0
   206
		case RPagingExample::ERequestRead:
sl@0
   207
			r = StartRead(a1, (TInt)a2, aStatus);
sl@0
   208
			break;
sl@0
   209
			
sl@0
   210
		case RPagingExample::ERequestReadDes:
sl@0
   211
			r = StartReadDes((TDes8*)a1, aStatus);
sl@0
   212
			break;
sl@0
   213
sl@0
   214
		case RPagingExample::ERequestWrite:
sl@0
   215
			r = StartWrite(a1, (TInt)a2, aStatus);
sl@0
   216
			break;
sl@0
   217
			
sl@0
   218
		case RPagingExample::ERequestWriteDes:
sl@0
   219
			r = StartWriteDes((TDes8*)a1, aStatus);
sl@0
   220
			break;
sl@0
   221
		}
sl@0
   222
	return r;
sl@0
   223
	}
sl@0
   224
sl@0
   225
TInt DExampleChannel::DoCancel(TUint /*aMask*/)
sl@0
   226
	{
sl@0
   227
	iCancelDfc.Enque();
sl@0
   228
	return KErrNone;
sl@0
   229
	}
sl@0
   230
sl@0
   231
void DExampleChannel::CancelDfcFunc(TAny* aPtr)
sl@0
   232
	{
sl@0
   233
	DExampleChannel* self = (DExampleChannel*)aPtr;
sl@0
   234
	self->Cancel();
sl@0
   235
	}
sl@0
   236
sl@0
   237
void DExampleChannel::Cancel()
sl@0
   238
	{
sl@0
   239
	if (iAsyncGetValueStatus)
sl@0
   240
		{
sl@0
   241
		iAsyncGetValueTimer.Cancel();
sl@0
   242
		iAsyncGetValueDfc.Cancel();
sl@0
   243
		Kern::RequestComplete(iClient, iAsyncGetValueStatus, KErrCancel);
sl@0
   244
		}
sl@0
   245
sl@0
   246
	if (iAsyncGetValue2Status)
sl@0
   247
		{
sl@0
   248
		iAsyncGetValue2Timer.Cancel();
sl@0
   249
		iAsyncGetValue2Dfc.Cancel();
sl@0
   250
		Kern::RequestComplete(iClient, iAsyncGetValue2Status, KErrCancel);
sl@0
   251
		}
sl@0
   252
sl@0
   253
	if (iReadStatus)
sl@0
   254
		{
sl@0
   255
		iReadTimer.Cancel();
sl@0
   256
		iCompleteReadDfc.Cancel();
sl@0
   257
		Kern::RequestComplete(iClient, iReadStatus, KErrCancel);
sl@0
   258
		}
sl@0
   259
sl@0
   260
	if (iWriteStatus)
sl@0
   261
		{
sl@0
   262
		iWriteTimer.Cancel();
sl@0
   263
		iCompleteWriteDfc.Cancel();
sl@0
   264
		Kern::RequestComplete(iClient, iWriteStatus, KErrCancel);
sl@0
   265
		}
sl@0
   266
	}
sl@0
   267
sl@0
   268
void DExampleChannel::Shutdown()
sl@0
   269
	{
sl@0
   270
	}
sl@0
   271
sl@0
   272
void DExampleChannel::GetConfig(TConfigData& aConfigOut)
sl@0
   273
	{
sl@0
   274
	NKern::FMWait(&iLock);
sl@0
   275
	aConfigOut = iConfig;
sl@0
   276
	NKern::FMSignal(&iLock);
sl@0
   277
	}
sl@0
   278
sl@0
   279
void DExampleChannel::SetConfig(const TConfigData& aNewConfig)
sl@0
   280
	{
sl@0
   281
	NKern::FMWait(&iLock);
sl@0
   282
	iConfig = aNewConfig;
sl@0
   283
	NKern::FMSignal(&iLock);
sl@0
   284
	}
sl@0
   285
sl@0
   286
TInt DExampleChannel::StartNotify(TRequestStatus* aStatus)
sl@0
   287
	{
sl@0
   288
	iNotifyStatus = aStatus;	
sl@0
   289
	CompleteNotify(); // example implementation completes the request immediately
sl@0
   290
	return KErrNone;
sl@0
   291
	}
sl@0
   292
sl@0
   293
void DExampleChannel::CompleteNotify()
sl@0
   294
	{
sl@0
   295
	Kern::RequestComplete(iClient, iNotifyStatus, KErrNone);
sl@0
   296
	}
sl@0
   297
sl@0
   298
TInt DExampleChannel::StartAsyncGetValue(TInt* aValue, TRequestStatus* aStatus)
sl@0
   299
	{
sl@0
   300
	iAsyncGetValueDest = aValue;
sl@0
   301
	iAsyncGetValueStatus = aStatus;
sl@0
   302
sl@0
   303
	// queue a timer to simulate an asynchronous operation
sl@0
   304
	iAsyncGetValueTimer.OneShot(KAsyncDelay, iAsyncGetValueDfc);
sl@0
   305
	return KErrNone;
sl@0
   306
	}
sl@0
   307
sl@0
   308
void DExampleChannel::AsyncGetValueCompleteDfcFunc(TAny* aPtr)
sl@0
   309
	{
sl@0
   310
	DExampleChannel* self = (DExampleChannel*)aPtr;
sl@0
   311
	self->CompleteAsyncGetValue();
sl@0
   312
	}
sl@0
   313
sl@0
   314
void DExampleChannel::CompleteAsyncGetValue()
sl@0
   315
	{
sl@0
   316
	TValueStruct value;
sl@0
   317
	value.iValue1 = 1;
sl@0
   318
	value.iValue2 = _L8("shrt");
sl@0
   319
	TInt r = Kern::ThreadRawWrite(iClient, iAsyncGetValueDest, (TAny*)&value, sizeof(TValueStruct), iClient);
sl@0
   320
	Kern::RequestComplete(iClient, iAsyncGetValueStatus, r);
sl@0
   321
	}
sl@0
   322
sl@0
   323
TInt DExampleChannel::StartAsyncGetValue2(TInt* aValue1, TInt* aValue2, TRequestStatus* aStatus)
sl@0
   324
	{
sl@0
   325
	iAsyncGetValue2Dest1 = aValue1;
sl@0
   326
	iAsyncGetValue2Dest2 = aValue2;
sl@0
   327
	iAsyncGetValue2Status = aStatus;
sl@0
   328
sl@0
   329
	// queue a timer to simulate an asynchronous operation
sl@0
   330
	iAsyncGetValue2Timer.OneShot(KAsyncDelay, iAsyncGetValue2Dfc);
sl@0
   331
	return KErrNone;
sl@0
   332
	}
sl@0
   333
sl@0
   334
void DExampleChannel::AsyncGetValue2CompleteDfcFunc(TAny* aPtr)
sl@0
   335
	{
sl@0
   336
	DExampleChannel* self = (DExampleChannel*)aPtr;
sl@0
   337
	self->CompleteAsyncGetValue2();
sl@0
   338
	}
sl@0
   339
sl@0
   340
void DExampleChannel::CompleteAsyncGetValue2()
sl@0
   341
	{
sl@0
   342
	TInt value1 = 1;
sl@0
   343
	TInt value2 = 2;
sl@0
   344
	TInt r = Kern::ThreadRawWrite(iClient, iAsyncGetValue2Dest1, (TAny*)&value1, sizeof(TInt), iClient);
sl@0
   345
	if (r == KErrNone)
sl@0
   346
		r = Kern::ThreadRawWrite(iClient, iAsyncGetValue2Dest2, (TAny*)&value2, sizeof(TInt), iClient);
sl@0
   347
	Kern::RequestComplete(iClient, iAsyncGetValue2Status, r);
sl@0
   348
	}
sl@0
   349
sl@0
   350
TInt DExampleChannel::StartRead(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus)
sl@0
   351
	{
sl@0
   352
	if (!NKern::CompareAndSwap(*(TAny**)&iReadStatus, NULL, aStatus))
sl@0
   353
		return KErrInUse;
sl@0
   354
	if (aLength < 1 || aLength > KBufferSize)
sl@0
   355
		{
sl@0
   356
		iReadStatus = NULL;
sl@0
   357
		return KErrArgument;
sl@0
   358
		}
sl@0
   359
	iReadDest = aBuffer;
sl@0
   360
	iReadLength = aLength;
sl@0
   361
	ReceiveToReadBuffer();
sl@0
   362
	return KErrNone;
sl@0
   363
	}
sl@0
   364
sl@0
   365
TInt DExampleChannel::StartReadDes(TDes8* aDesOut, TRequestStatus* aStatus)
sl@0
   366
	{
sl@0
   367
	if (!NKern::CompareAndSwap(*(TAny**)&iReadStatus, NULL, aStatus))
sl@0
   368
		return KErrInUse;
sl@0
   369
	TInt r = Kern::ThreadGetDesMaxLength(iClient, aDesOut);
sl@0
   370
	if (r < 0)
sl@0
   371
		{
sl@0
   372
		iReadStatus = NULL;
sl@0
   373
		return r;
sl@0
   374
		}
sl@0
   375
	TInt length = r;
sl@0
   376
	if (length < 1 || length > KBufferSize)
sl@0
   377
		{
sl@0
   378
		iReadStatus = NULL;
sl@0
   379
		return KErrArgument;
sl@0
   380
		}
sl@0
   381
	iReadDes = aDesOut;
sl@0
   382
	iReadLength = length;
sl@0
   383
	ReceiveToReadBuffer();
sl@0
   384
	return KErrNone;
sl@0
   385
	}
sl@0
   386
sl@0
   387
TInt DExampleChannel::StartWrite(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus)
sl@0
   388
	{
sl@0
   389
	if (!NKern::CompareAndSwap(*(TAny**)&iWriteStatus, NULL, aStatus))
sl@0
   390
		return KErrInUse;
sl@0
   391
	if (aLength < 1 || aLength > KBufferSize)
sl@0
   392
		{
sl@0
   393
		iWriteStatus = NULL;
sl@0
   394
		return KErrArgument;
sl@0
   395
		}
sl@0
   396
	iWriteSrc = aBuffer;
sl@0
   397
	iWriteLength = aLength;
sl@0
   398
	SendFromWriteBuffer();
sl@0
   399
	return KErrNone;
sl@0
   400
	}
sl@0
   401
sl@0
   402
TInt DExampleChannel::StartWriteDes(const TDesC8* aDesIn, TRequestStatus* aStatus)
sl@0
   403
	{
sl@0
   404
	if (!NKern::CompareAndSwap(*(TAny**)&iWriteStatus, NULL, aStatus))
sl@0
   405
		return KErrInUse;
sl@0
   406
	TInt r = Kern::ThreadGetDesLength(iClient, aDesIn);
sl@0
   407
	if (r < 0)
sl@0
   408
		return r;
sl@0
   409
	TInt length = r;
sl@0
   410
	if (length < 1 || length > KBufferSize)
sl@0
   411
		{
sl@0
   412
		iWriteStatus = NULL;
sl@0
   413
		return KErrArgument;
sl@0
   414
		}
sl@0
   415
	iWriteLength = length;
sl@0
   416
	iWriteDes = aDesIn;
sl@0
   417
	SendFromWriteBuffer();
sl@0
   418
	return KErrNone;
sl@0
   419
	}
sl@0
   420
sl@0
   421
void DExampleChannel::ReceiveToReadBuffer()
sl@0
   422
	{
sl@0
   423
	// just queue a timer to simulate an asynchronous receive operation
sl@0
   424
	// actually will return the previous contents of the buffer
sl@0
   425
	NKern::FMWait(&iLock);
sl@0
   426
	// The synchonisation is for illustrative purposes only - in a real driver we might make use of
sl@0
   427
	// the configution here, so this would need to be protected from concurrent modification.
sl@0
   428
	NKern::FMSignal(&iLock);
sl@0
   429
	iReadTimer.OneShot(KAsyncDelay, iCompleteReadDfc);
sl@0
   430
	}
sl@0
   431
sl@0
   432
void DExampleChannel::SendFromWriteBuffer()
sl@0
   433
	{
sl@0
   434
	// just queue a timer to simulate an asynchronous send operation
sl@0
   435
	NKern::FMWait(&iLock);
sl@0
   436
	// The synchonisation is for illustrative purposes only - in a real driver we might make use of
sl@0
   437
	// the configution here, so this would need to be protected from concurrent modification.
sl@0
   438
	NKern::FMSignal(&iLock);
sl@0
   439
	iWriteTimer.OneShot(KAsyncDelay, iCompleteWriteDfc);
sl@0
   440
	}
sl@0
   441
sl@0
   442
void DExampleChannel::ReceiveCompleteDfcFunc(TAny* aPtr)
sl@0
   443
	{
sl@0
   444
	DExampleChannel* self = (DExampleChannel*)aPtr;
sl@0
   445
	self->CompleteRead();
sl@0
   446
	}
sl@0
   447
sl@0
   448
void DExampleChannel::SendCompleteDfcFunc(TAny* aPtr)
sl@0
   449
	{
sl@0
   450
	DExampleChannel* self = (DExampleChannel*)aPtr;
sl@0
   451
	self->CompleteWrite();
sl@0
   452
	}
sl@0
   453
sl@0
   454
void DExampleChannel::CompleteRead()
sl@0
   455
	{
sl@0
   456
	TInt r;
sl@0
   457
	if (iReadDest)
sl@0
   458
		{
sl@0
   459
		r = Kern::ThreadRawWrite(iClient, iReadDest, iBuffer, iReadLength, iClient);
sl@0
   460
		iReadDest = NULL;
sl@0
   461
		}
sl@0
   462
	else
sl@0
   463
		{
sl@0
   464
		TPtrC8 des(iBuffer, iReadLength);
sl@0
   465
		r = Kern::ThreadDesWrite(iClient, iReadDes, des, 0, KChunkShiftBy0, iClient);
sl@0
   466
		iReadDes = NULL;
sl@0
   467
		}
sl@0
   468
	
sl@0
   469
	iReadLength = 0;
sl@0
   470
	Kern::RequestComplete(iClient, iReadStatus, r);
sl@0
   471
	}
sl@0
   472
sl@0
   473
void DExampleChannel::CompleteWrite()
sl@0
   474
	{
sl@0
   475
	TInt r;
sl@0
   476
	if (iWriteSrc)
sl@0
   477
		{
sl@0
   478
		r = Kern::ThreadRawRead(iClient, iWriteSrc, iBuffer, iWriteLength);
sl@0
   479
		iWriteSrc = NULL;
sl@0
   480
		}
sl@0
   481
	else
sl@0
   482
		{
sl@0
   483
		TPtr8 des(iBuffer, iWriteLength);
sl@0
   484
		r = Kern::ThreadDesRead(iClient, iWriteDes, des, 0);
sl@0
   485
		iWriteDes = NULL;
sl@0
   486
		}
sl@0
   487
	
sl@0
   488
	iWriteLength = 0;
sl@0
   489
	Kern::RequestComplete(iClient, iWriteStatus, r);
sl@0
   490
	}
sl@0
   491
sl@0
   492
//
sl@0
   493
// Logical device
sl@0
   494
//
sl@0
   495
sl@0
   496
class DExampleFactory : public DLogicalDevice
sl@0
   497
	{
sl@0
   498
public:
sl@0
   499
	DExampleFactory();
sl@0
   500
	virtual TInt Install();
sl@0
   501
	virtual void GetCaps(TDes8& aDes) const;
sl@0
   502
	virtual TInt Create(DLogicalChannelBase*& aChannel);
sl@0
   503
	};
sl@0
   504
sl@0
   505
DExampleFactory::DExampleFactory()
sl@0
   506
	{
sl@0
   507
	iParseMask = 0;
sl@0
   508
	iVersion = TVersion(1, 0, 0);
sl@0
   509
	}
sl@0
   510
sl@0
   511
TInt DExampleFactory::Install()
sl@0
   512
	{
sl@0
   513
	return SetName(&KPagingExample2PreLdd);
sl@0
   514
	}
sl@0
   515
sl@0
   516
void DExampleFactory::GetCaps(TDes8& /*aDes*/) const
sl@0
   517
	{
sl@0
   518
	// not used but required as DLogicalDevice::GetCaps is pure virtual
sl@0
   519
	}
sl@0
   520
sl@0
   521
TInt DExampleFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
   522
	{
sl@0
   523
	aChannel = new DExampleChannel;
sl@0
   524
	return aChannel ? KErrNone : KErrNoMemory;
sl@0
   525
	}
sl@0
   526
sl@0
   527
DECLARE_STANDARD_LDD()
sl@0
   528
	{
sl@0
   529
	return new DExampleFactory;
sl@0
   530
	}