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_1_pre.cpp
|
sl@0
|
15 |
// Demand paging migration example device driver d_pagingexample_1_pre: a DLogicalChannel-dervied
|
sl@0
|
16 |
// 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 KDfcQThreadPriority = 25;
|
sl@0
|
25 |
const TInt KBufferSize = KMaxTransferSize;
|
sl@0
|
26 |
|
sl@0
|
27 |
//
|
sl@0
|
28 |
// Logical channel
|
sl@0
|
29 |
//
|
sl@0
|
30 |
|
sl@0
|
31 |
class DExampleChannel : public DLogicalChannel
|
sl@0
|
32 |
{
|
sl@0
|
33 |
public:
|
sl@0
|
34 |
typedef RPagingExample::TConfigData TConfigData;
|
sl@0
|
35 |
typedef RPagingExample::TValueStruct TValueStruct;
|
sl@0
|
36 |
public:
|
sl@0
|
37 |
DExampleChannel();
|
sl@0
|
38 |
~DExampleChannel();
|
sl@0
|
39 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
sl@0
|
40 |
virtual void HandleMsg(TMessageBase* aMsg);
|
sl@0
|
41 |
TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
42 |
TInt DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2);
|
sl@0
|
43 |
TInt DoCancel(TUint aMask);
|
sl@0
|
44 |
private:
|
sl@0
|
45 |
TDfcQue* DfcQ();
|
sl@0
|
46 |
void Shutdown();
|
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 AsyncGetValueCompleteDfcFunc(TAny* aPtr);
|
sl@0
|
58 |
static void AsyncGetValue2CompleteDfcFunc(TAny* aPtr);
|
sl@0
|
59 |
static void ReceiveCompleteDfcFunc(TAny* aPtr);
|
sl@0
|
60 |
static void SendCompleteDfcFunc(TAny* aPtr);
|
sl@0
|
61 |
void CompleteNotify();
|
sl@0
|
62 |
void CompleteAsyncGetValue();
|
sl@0
|
63 |
void CompleteAsyncGetValue2();
|
sl@0
|
64 |
void CompleteRead();
|
sl@0
|
65 |
void CompleteWrite();
|
sl@0
|
66 |
private:
|
sl@0
|
67 |
TDynamicDfcQue* iDynamicDfcQ;
|
sl@0
|
68 |
TConfigData iConfig;
|
sl@0
|
69 |
DThread* iClient;
|
sl@0
|
70 |
|
sl@0
|
71 |
// Notify
|
sl@0
|
72 |
TRequestStatus* iNotifyStatus;
|
sl@0
|
73 |
|
sl@0
|
74 |
// Async get value
|
sl@0
|
75 |
TRequestStatus* iAsyncGetValueStatus;
|
sl@0
|
76 |
TInt* iAsyncGetValueDest;
|
sl@0
|
77 |
NTimer iAsyncGetValueTimer;
|
sl@0
|
78 |
TDfc iAsyncGetValueDfc;
|
sl@0
|
79 |
|
sl@0
|
80 |
// Async get value 2
|
sl@0
|
81 |
TRequestStatus* iAsyncGetValue2Status;
|
sl@0
|
82 |
TInt* iAsyncGetValue2Dest1;
|
sl@0
|
83 |
TInt* iAsyncGetValue2Dest2;
|
sl@0
|
84 |
NTimer iAsyncGetValue2Timer;
|
sl@0
|
85 |
TDfc iAsyncGetValue2Dfc;
|
sl@0
|
86 |
|
sl@0
|
87 |
// Read
|
sl@0
|
88 |
TRequestStatus* iReadStatus;
|
sl@0
|
89 |
NTimer iReadTimer;
|
sl@0
|
90 |
TAny* iReadDest;
|
sl@0
|
91 |
TInt iReadLength;
|
sl@0
|
92 |
TDes8* iReadDes;
|
sl@0
|
93 |
TDfc iCompleteReadDfc;
|
sl@0
|
94 |
|
sl@0
|
95 |
// Write
|
sl@0
|
96 |
TRequestStatus* iWriteStatus;
|
sl@0
|
97 |
NTimer iWriteTimer;
|
sl@0
|
98 |
TAny* iWriteSrc;
|
sl@0
|
99 |
TInt iWriteLength;
|
sl@0
|
100 |
const TDesC8* iWriteDes;
|
sl@0
|
101 |
TDfc iCompleteWriteDfc;
|
sl@0
|
102 |
TUint8 iBuffer[KBufferSize];
|
sl@0
|
103 |
};
|
sl@0
|
104 |
|
sl@0
|
105 |
DExampleChannel::DExampleChannel() :
|
sl@0
|
106 |
iAsyncGetValueTimer(NULL, this),
|
sl@0
|
107 |
iAsyncGetValueDfc(AsyncGetValueCompleteDfcFunc, this, 0),
|
sl@0
|
108 |
iAsyncGetValue2Timer(NULL, this),
|
sl@0
|
109 |
iAsyncGetValue2Dfc(AsyncGetValue2CompleteDfcFunc, this, 0),
|
sl@0
|
110 |
iReadTimer(NULL, this),
|
sl@0
|
111 |
iCompleteReadDfc(ReceiveCompleteDfcFunc, this, 0),
|
sl@0
|
112 |
iWriteTimer(NULL, this),
|
sl@0
|
113 |
iCompleteWriteDfc(SendCompleteDfcFunc, this, 0)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
iClient = &Kern::CurrentThread();
|
sl@0
|
116 |
iClient->Open();
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
DExampleChannel::~DExampleChannel()
|
sl@0
|
120 |
{
|
sl@0
|
121 |
Kern::SafeClose((DObject*&)iClient, NULL);
|
sl@0
|
122 |
if (iDynamicDfcQ)
|
sl@0
|
123 |
iDynamicDfcQ->Destroy();
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
TDfcQue* DExampleChannel::DfcQ()
|
sl@0
|
127 |
{
|
sl@0
|
128 |
return iDynamicDfcQ;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
TInt DExampleChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
// Existing drivers may use the kernel global DFC queue, but for testing purposes we actually
|
sl@0
|
134 |
// allocate our own so we can control its realtime state.
|
sl@0
|
135 |
TInt r = Kern::DynamicDfcQCreate(iDynamicDfcQ, KDfcQThreadPriority, KPagingExample1PreLdd);
|
sl@0
|
136 |
if (r != KErrNone)
|
sl@0
|
137 |
return r;
|
sl@0
|
138 |
iDynamicDfcQ->SetRealtimeState(ERealtimeStateWarn);
|
sl@0
|
139 |
|
sl@0
|
140 |
SetDfcQ(DfcQ());
|
sl@0
|
141 |
iAsyncGetValueDfc.SetDfcQ(DfcQ());
|
sl@0
|
142 |
iAsyncGetValue2Dfc.SetDfcQ(DfcQ());
|
sl@0
|
143 |
iCompleteReadDfc.SetDfcQ(DfcQ());
|
sl@0
|
144 |
iCompleteWriteDfc.SetDfcQ(DfcQ());
|
sl@0
|
145 |
iMsgQ.Receive();
|
sl@0
|
146 |
return KErrNone;
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
void DExampleChannel::HandleMsg(TMessageBase* aMsg)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TThreadMessage& m=*(TThreadMessage*)aMsg;
|
sl@0
|
152 |
TInt id=m.iValue;
|
sl@0
|
153 |
|
sl@0
|
154 |
if (id==(TInt)ECloseMsg)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
Shutdown();
|
sl@0
|
157 |
m.Complete(KErrNone,EFalse);
|
sl@0
|
158 |
return;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
// we only support one client
|
sl@0
|
162 |
if (m.Client() != iClient)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
m.Complete(KErrAccessDenied,ETrue);
|
sl@0
|
165 |
return;
|
sl@0
|
166 |
}
|
sl@0
|
167 |
|
sl@0
|
168 |
if (id==KMaxTInt)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
// DoCancel
|
sl@0
|
171 |
DoCancel(m.Int0());
|
sl@0
|
172 |
m.Complete(KErrNone,ETrue);
|
sl@0
|
173 |
return;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
else if (id<0)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
// DoRequest
|
sl@0
|
178 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
|
sl@0
|
179 |
TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
|
sl@0
|
180 |
if (r!=KErrNone)
|
sl@0
|
181 |
Kern::RequestComplete(m.Client(),pS,r);
|
sl@0
|
182 |
m.Complete(KErrNone,ETrue);
|
sl@0
|
183 |
}
|
sl@0
|
184 |
else
|
sl@0
|
185 |
{
|
sl@0
|
186 |
// DoControl
|
sl@0
|
187 |
TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
|
sl@0
|
188 |
m.Complete(r,ETrue);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
TInt DExampleChannel::DoControl(TInt aFunction,TAny* a1,TAny* /*a2*/)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
TInt r = KErrNone;
|
sl@0
|
195 |
switch (aFunction)
|
sl@0
|
196 |
{
|
sl@0
|
197 |
case RPagingExample::ESetRealtimeState:
|
sl@0
|
198 |
iDynamicDfcQ->SetRealtimeState(a1 ? ERealtimeStateOn : ERealtimeStateWarn);
|
sl@0
|
199 |
break;
|
sl@0
|
200 |
|
sl@0
|
201 |
case RPagingExample::EGetConfig:
|
sl@0
|
202 |
r = Kern::ThreadRawWrite(iClient, a1, (TAny*)&iConfig, sizeof(TConfigData), iClient);
|
sl@0
|
203 |
break;
|
sl@0
|
204 |
|
sl@0
|
205 |
case RPagingExample::ESetConfig:
|
sl@0
|
206 |
{
|
sl@0
|
207 |
TConfigData newConfig;
|
sl@0
|
208 |
r = Kern::ThreadRawRead(iClient, a1, &newConfig, sizeof(TConfigData));
|
sl@0
|
209 |
if (r == KErrNone)
|
sl@0
|
210 |
SetConfig(newConfig);
|
sl@0
|
211 |
}
|
sl@0
|
212 |
break;
|
sl@0
|
213 |
|
sl@0
|
214 |
default:
|
sl@0
|
215 |
r = KErrNotSupported;
|
sl@0
|
216 |
}
|
sl@0
|
217 |
return r;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
TInt DExampleChannel::DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
TInt r = KErrNotSupported;
|
sl@0
|
223 |
switch (aFunction)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
case RPagingExample::ERequestNotify:
|
sl@0
|
226 |
r = StartNotify(aStatus);
|
sl@0
|
227 |
break;
|
sl@0
|
228 |
|
sl@0
|
229 |
case RPagingExample::ERequestAsyncGetValue:
|
sl@0
|
230 |
r = StartAsyncGetValue((TInt*)a1, aStatus);
|
sl@0
|
231 |
break;
|
sl@0
|
232 |
|
sl@0
|
233 |
case RPagingExample::ERequestAsyncGetValue2:
|
sl@0
|
234 |
r = StartAsyncGetValue2((TInt*)a1, (TInt*)a2, aStatus);
|
sl@0
|
235 |
break;
|
sl@0
|
236 |
|
sl@0
|
237 |
case RPagingExample::ERequestRead:
|
sl@0
|
238 |
r = StartRead(a1, (TInt)a2, aStatus);
|
sl@0
|
239 |
break;
|
sl@0
|
240 |
|
sl@0
|
241 |
case RPagingExample::ERequestReadDes:
|
sl@0
|
242 |
r = StartReadDes((TDes8*)a1, aStatus);
|
sl@0
|
243 |
break;
|
sl@0
|
244 |
|
sl@0
|
245 |
case RPagingExample::ERequestWrite:
|
sl@0
|
246 |
r = StartWrite(a1, (TInt)a2, aStatus);
|
sl@0
|
247 |
break;
|
sl@0
|
248 |
|
sl@0
|
249 |
case RPagingExample::ERequestWriteDes:
|
sl@0
|
250 |
r = StartWriteDes((TDes8*)a1, aStatus);
|
sl@0
|
251 |
break;
|
sl@0
|
252 |
}
|
sl@0
|
253 |
return r;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
TInt DExampleChannel::DoCancel(TUint /*aMask*/)
|
sl@0
|
257 |
{
|
sl@0
|
258 |
if (iAsyncGetValueStatus)
|
sl@0
|
259 |
{
|
sl@0
|
260 |
iAsyncGetValueTimer.Cancel();
|
sl@0
|
261 |
iAsyncGetValueDfc.Cancel();
|
sl@0
|
262 |
Kern::RequestComplete(iClient, iAsyncGetValueStatus, KErrCancel);
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
if (iAsyncGetValue2Status)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
iAsyncGetValue2Timer.Cancel();
|
sl@0
|
268 |
iAsyncGetValue2Dfc.Cancel();
|
sl@0
|
269 |
Kern::RequestComplete(iClient, iAsyncGetValue2Status, KErrCancel);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
|
sl@0
|
272 |
if (iReadStatus)
|
sl@0
|
273 |
{
|
sl@0
|
274 |
iReadTimer.Cancel();
|
sl@0
|
275 |
iCompleteReadDfc.Cancel();
|
sl@0
|
276 |
Kern::RequestComplete(iClient, iReadStatus, KErrCancel);
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
if (iWriteStatus)
|
sl@0
|
280 |
{
|
sl@0
|
281 |
iWriteTimer.Cancel();
|
sl@0
|
282 |
iCompleteWriteDfc.Cancel();
|
sl@0
|
283 |
Kern::RequestComplete(iClient, iWriteStatus, KErrCancel);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
return KErrNone;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
void DExampleChannel::Shutdown()
|
sl@0
|
290 |
{
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
void DExampleChannel::SetConfig(const TConfigData& aNewConfig)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
iConfig = aNewConfig;
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
TInt DExampleChannel::StartNotify(TRequestStatus* aStatus)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
iNotifyStatus = aStatus;
|
sl@0
|
301 |
CompleteNotify(); // example implementation completes the request immediately
|
sl@0
|
302 |
return KErrNone;
|
sl@0
|
303 |
}
|
sl@0
|
304 |
|
sl@0
|
305 |
void DExampleChannel::CompleteNotify()
|
sl@0
|
306 |
{
|
sl@0
|
307 |
Kern::RequestComplete(iClient, iNotifyStatus, KErrNone);
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
TInt DExampleChannel::StartAsyncGetValue(TInt* aValue, TRequestStatus* aStatus)
|
sl@0
|
311 |
{
|
sl@0
|
312 |
iAsyncGetValueDest = aValue;
|
sl@0
|
313 |
iAsyncGetValueStatus = aStatus;
|
sl@0
|
314 |
|
sl@0
|
315 |
// queue a timer to simulate an asynchronous operation
|
sl@0
|
316 |
iAsyncGetValueTimer.OneShot(KAsyncDelay, iAsyncGetValueDfc);
|
sl@0
|
317 |
return KErrNone;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
|
sl@0
|
320 |
void DExampleChannel::AsyncGetValueCompleteDfcFunc(TAny* aPtr)
|
sl@0
|
321 |
{
|
sl@0
|
322 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
323 |
self->CompleteAsyncGetValue();
|
sl@0
|
324 |
}
|
sl@0
|
325 |
|
sl@0
|
326 |
void DExampleChannel::CompleteAsyncGetValue()
|
sl@0
|
327 |
{
|
sl@0
|
328 |
TValueStruct value;
|
sl@0
|
329 |
value.iValue1 = 1;
|
sl@0
|
330 |
value.iValue2 = _L8("shrt");
|
sl@0
|
331 |
TInt r = Kern::ThreadRawWrite(iClient, iAsyncGetValueDest, (TAny*)&value, sizeof(TValueStruct), iClient);
|
sl@0
|
332 |
Kern::RequestComplete(iClient, iAsyncGetValueStatus, r);
|
sl@0
|
333 |
}
|
sl@0
|
334 |
|
sl@0
|
335 |
TInt DExampleChannel::StartAsyncGetValue2(TInt* aValue1, TInt* aValue2, TRequestStatus* aStatus)
|
sl@0
|
336 |
{
|
sl@0
|
337 |
iAsyncGetValue2Dest1 = aValue1;
|
sl@0
|
338 |
iAsyncGetValue2Dest2 = aValue2;
|
sl@0
|
339 |
iAsyncGetValue2Status = aStatus;
|
sl@0
|
340 |
|
sl@0
|
341 |
// queue a timer to simulate an asynchronous operation
|
sl@0
|
342 |
iAsyncGetValue2Timer.OneShot(KAsyncDelay, iAsyncGetValue2Dfc);
|
sl@0
|
343 |
return KErrNone;
|
sl@0
|
344 |
}
|
sl@0
|
345 |
|
sl@0
|
346 |
void DExampleChannel::AsyncGetValue2CompleteDfcFunc(TAny* aPtr)
|
sl@0
|
347 |
{
|
sl@0
|
348 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
349 |
self->CompleteAsyncGetValue2();
|
sl@0
|
350 |
}
|
sl@0
|
351 |
|
sl@0
|
352 |
void DExampleChannel::CompleteAsyncGetValue2()
|
sl@0
|
353 |
{
|
sl@0
|
354 |
TInt value1 = 1;
|
sl@0
|
355 |
TInt value2 = 2;
|
sl@0
|
356 |
TInt r = Kern::ThreadRawWrite(iClient, iAsyncGetValue2Dest1, (TAny*)&value1, sizeof(TInt), iClient);
|
sl@0
|
357 |
if (r == KErrNone)
|
sl@0
|
358 |
r = Kern::ThreadRawWrite(iClient, iAsyncGetValue2Dest2, (TAny*)&value2, sizeof(TInt), iClient);
|
sl@0
|
359 |
Kern::RequestComplete(iClient, iAsyncGetValue2Status, r);
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|
sl@0
|
362 |
TInt DExampleChannel::StartRead(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
if (iReadStatus)
|
sl@0
|
365 |
return KErrInUse;
|
sl@0
|
366 |
if (aLength < 1 || aLength > KBufferSize)
|
sl@0
|
367 |
return KErrArgument;
|
sl@0
|
368 |
iReadStatus = aStatus;
|
sl@0
|
369 |
iReadDest = aBuffer;
|
sl@0
|
370 |
iReadLength = aLength;
|
sl@0
|
371 |
ReceiveToReadBuffer();
|
sl@0
|
372 |
return KErrNone;
|
sl@0
|
373 |
}
|
sl@0
|
374 |
|
sl@0
|
375 |
TInt DExampleChannel::StartReadDes(TDes8* aDesOut, TRequestStatus* aStatus)
|
sl@0
|
376 |
{
|
sl@0
|
377 |
if (iReadStatus)
|
sl@0
|
378 |
return KErrInUse;
|
sl@0
|
379 |
TInt r = Kern::ThreadGetDesMaxLength(iClient, aDesOut);
|
sl@0
|
380 |
if (r < 0)
|
sl@0
|
381 |
return r;
|
sl@0
|
382 |
TInt length = r;
|
sl@0
|
383 |
if (length < 1 || length > KBufferSize)
|
sl@0
|
384 |
return KErrArgument;
|
sl@0
|
385 |
iReadStatus = aStatus;
|
sl@0
|
386 |
iReadDes = aDesOut;
|
sl@0
|
387 |
iReadLength = length;
|
sl@0
|
388 |
ReceiveToReadBuffer();
|
sl@0
|
389 |
return KErrNone;
|
sl@0
|
390 |
}
|
sl@0
|
391 |
|
sl@0
|
392 |
TInt DExampleChannel::StartWrite(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus)
|
sl@0
|
393 |
{
|
sl@0
|
394 |
if (iWriteStatus)
|
sl@0
|
395 |
return KErrInUse;
|
sl@0
|
396 |
if (aLength < 1 || aLength > KBufferSize)
|
sl@0
|
397 |
return KErrArgument;
|
sl@0
|
398 |
iWriteStatus = aStatus;
|
sl@0
|
399 |
iWriteSrc = aBuffer;
|
sl@0
|
400 |
iWriteLength = aLength;
|
sl@0
|
401 |
SendFromWriteBuffer();
|
sl@0
|
402 |
return KErrNone;
|
sl@0
|
403 |
}
|
sl@0
|
404 |
|
sl@0
|
405 |
TInt DExampleChannel::StartWriteDes(const TDesC8* aDesIn, TRequestStatus* aStatus)
|
sl@0
|
406 |
{
|
sl@0
|
407 |
if (iWriteStatus)
|
sl@0
|
408 |
return KErrInUse;
|
sl@0
|
409 |
TInt r = Kern::ThreadGetDesLength(iClient, aDesIn);
|
sl@0
|
410 |
if (r < 0)
|
sl@0
|
411 |
return r;
|
sl@0
|
412 |
TInt length = r;
|
sl@0
|
413 |
if (length < 1 || length > KBufferSize)
|
sl@0
|
414 |
return KErrArgument;
|
sl@0
|
415 |
iWriteStatus = aStatus;
|
sl@0
|
416 |
iWriteLength = length;
|
sl@0
|
417 |
iWriteDes = aDesIn;
|
sl@0
|
418 |
SendFromWriteBuffer();
|
sl@0
|
419 |
return KErrNone;
|
sl@0
|
420 |
}
|
sl@0
|
421 |
|
sl@0
|
422 |
void DExampleChannel::ReceiveToReadBuffer()
|
sl@0
|
423 |
{
|
sl@0
|
424 |
// just queue a timer to simulate an asynchronous receive operation
|
sl@0
|
425 |
// actually will return the previous contents of the buffer
|
sl@0
|
426 |
iReadTimer.OneShot(KAsyncDelay, iCompleteReadDfc);
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
void DExampleChannel::SendFromWriteBuffer()
|
sl@0
|
430 |
{
|
sl@0
|
431 |
// just queue a timer to simulate an asynchronous send operation
|
sl@0
|
432 |
iWriteTimer.OneShot(KAsyncDelay, iCompleteWriteDfc);
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
void DExampleChannel::ReceiveCompleteDfcFunc(TAny* aPtr)
|
sl@0
|
436 |
{
|
sl@0
|
437 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
438 |
self->CompleteRead();
|
sl@0
|
439 |
}
|
sl@0
|
440 |
|
sl@0
|
441 |
void DExampleChannel::SendCompleteDfcFunc(TAny* aPtr)
|
sl@0
|
442 |
{
|
sl@0
|
443 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
444 |
self->CompleteWrite();
|
sl@0
|
445 |
}
|
sl@0
|
446 |
|
sl@0
|
447 |
void DExampleChannel::CompleteRead()
|
sl@0
|
448 |
{
|
sl@0
|
449 |
TInt r;
|
sl@0
|
450 |
if (iReadDest)
|
sl@0
|
451 |
{
|
sl@0
|
452 |
r = Kern::ThreadRawWrite(iClient, iReadDest, iBuffer, iReadLength, iClient);
|
sl@0
|
453 |
iReadDest = NULL;
|
sl@0
|
454 |
}
|
sl@0
|
455 |
else
|
sl@0
|
456 |
{
|
sl@0
|
457 |
TPtrC8 des(iBuffer, iReadLength);
|
sl@0
|
458 |
r = Kern::ThreadDesWrite(iClient, iReadDes, des, 0, KChunkShiftBy0, iClient);
|
sl@0
|
459 |
iReadDes = NULL;
|
sl@0
|
460 |
}
|
sl@0
|
461 |
|
sl@0
|
462 |
iReadLength = 0;
|
sl@0
|
463 |
Kern::RequestComplete(iClient, iReadStatus, r);
|
sl@0
|
464 |
}
|
sl@0
|
465 |
|
sl@0
|
466 |
void DExampleChannel::CompleteWrite()
|
sl@0
|
467 |
{
|
sl@0
|
468 |
TInt r;
|
sl@0
|
469 |
if (iWriteSrc)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
r = Kern::ThreadRawRead(iClient, iWriteSrc, iBuffer, iWriteLength);
|
sl@0
|
472 |
iWriteSrc = NULL;
|
sl@0
|
473 |
}
|
sl@0
|
474 |
else
|
sl@0
|
475 |
{
|
sl@0
|
476 |
TPtr8 des(iBuffer, iWriteLength);
|
sl@0
|
477 |
r = Kern::ThreadDesRead(iClient, iWriteDes, des, 0);
|
sl@0
|
478 |
iWriteDes = NULL;
|
sl@0
|
479 |
}
|
sl@0
|
480 |
|
sl@0
|
481 |
iWriteLength = 0;
|
sl@0
|
482 |
Kern::RequestComplete(iClient, iWriteStatus, r);
|
sl@0
|
483 |
}
|
sl@0
|
484 |
|
sl@0
|
485 |
//
|
sl@0
|
486 |
// Logical device
|
sl@0
|
487 |
//
|
sl@0
|
488 |
|
sl@0
|
489 |
class DExampleFactory : public DLogicalDevice
|
sl@0
|
490 |
{
|
sl@0
|
491 |
public:
|
sl@0
|
492 |
DExampleFactory();
|
sl@0
|
493 |
virtual TInt Install();
|
sl@0
|
494 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
495 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
496 |
};
|
sl@0
|
497 |
|
sl@0
|
498 |
DExampleFactory::DExampleFactory()
|
sl@0
|
499 |
{
|
sl@0
|
500 |
iParseMask = 0;
|
sl@0
|
501 |
iVersion = TVersion(1, 0, 0);
|
sl@0
|
502 |
}
|
sl@0
|
503 |
|
sl@0
|
504 |
TInt DExampleFactory::Install()
|
sl@0
|
505 |
{
|
sl@0
|
506 |
return SetName(&KPagingExample1PreLdd);
|
sl@0
|
507 |
}
|
sl@0
|
508 |
|
sl@0
|
509 |
void DExampleFactory::GetCaps(TDes8& /*aDes*/) const
|
sl@0
|
510 |
{
|
sl@0
|
511 |
// not used but required as DLogicalDevice::GetCaps is pure virtual
|
sl@0
|
512 |
}
|
sl@0
|
513 |
|
sl@0
|
514 |
TInt DExampleFactory::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
aChannel = new DExampleChannel;
|
sl@0
|
517 |
return aChannel ? KErrNone : KErrNoMemory;
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
DECLARE_STANDARD_LDD()
|
sl@0
|
521 |
{
|
sl@0
|
522 |
return new DExampleFactory;
|
sl@0
|
523 |
}
|