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_post.cpp
|
sl@0
|
15 |
// Demand paging migration example device driver d_pagingexample_1_post: a DLogicalChannel-dervied
|
sl@0
|
16 |
// driver, post-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 TInt SendMsg(TMessageBase* aMsg);
|
sl@0
|
41 |
TInt SendControl(TMessageBase* aMsg);
|
sl@0
|
42 |
TInt SendRequest(TMessageBase* aMsg);
|
sl@0
|
43 |
virtual void HandleMsg(TMessageBase* aMsg);
|
sl@0
|
44 |
TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
|
sl@0
|
45 |
void DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny* a2);
|
sl@0
|
46 |
TInt DoCancel(TUint aMask);
|
sl@0
|
47 |
private:
|
sl@0
|
48 |
TDfcQue* DfcQ();
|
sl@0
|
49 |
void Shutdown();
|
sl@0
|
50 |
void SetConfig(const TConfigData&);
|
sl@0
|
51 |
TInt PreNotify(TRequestStatus* aStatus);
|
sl@0
|
52 |
void StartNotify();
|
sl@0
|
53 |
TInt PreAsyncGetValue(TInt* aValue, TRequestStatus* aStatus);
|
sl@0
|
54 |
void StartAsyncGetValue();
|
sl@0
|
55 |
TInt PreAsyncGetValue2(TInt* aValue1, TInt* aValue2, TRequestStatus* aStatus);
|
sl@0
|
56 |
void StartAsyncGetValue2();
|
sl@0
|
57 |
TInt PreRead(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus);
|
sl@0
|
58 |
void StartRead();
|
sl@0
|
59 |
TInt PreReadDes(TDes8* aDesOut, TRequestStatus* aStatus);
|
sl@0
|
60 |
void StartReadDes();
|
sl@0
|
61 |
TInt PreWrite(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus);
|
sl@0
|
62 |
void StartWrite();
|
sl@0
|
63 |
TInt PreWriteDes(const TDesC8* aDesIn, TRequestStatus* aStatus);
|
sl@0
|
64 |
void StartWriteDes();
|
sl@0
|
65 |
void ReceiveToReadBuffer();
|
sl@0
|
66 |
void SendFromWriteBuffer();
|
sl@0
|
67 |
static void AsyncGetValueCompleteDfcFunc(TAny* aPtr);
|
sl@0
|
68 |
static void AsyncGetValue2CompleteDfcFunc(TAny* aPtr);
|
sl@0
|
69 |
static void ReceiveCompleteDfcFunc(TAny* aPtr);
|
sl@0
|
70 |
static void SendCompleteDfcFunc(TAny* aPtr);
|
sl@0
|
71 |
void CompleteNotify();
|
sl@0
|
72 |
void CompleteAsyncGetValue();
|
sl@0
|
73 |
void CompleteAsyncGetValue2();
|
sl@0
|
74 |
void CompleteRead();
|
sl@0
|
75 |
void CompleteWrite();
|
sl@0
|
76 |
private:
|
sl@0
|
77 |
TDynamicDfcQue* iDynamicDfcQ;
|
sl@0
|
78 |
TConfigData iConfig;
|
sl@0
|
79 |
DThread* iClient;
|
sl@0
|
80 |
|
sl@0
|
81 |
// Notify
|
sl@0
|
82 |
TClientRequest* iNotifyRequest;
|
sl@0
|
83 |
|
sl@0
|
84 |
// Async get value
|
sl@0
|
85 |
TClientDataRequest<TValueStruct>* iAsyncGetValueRequest;
|
sl@0
|
86 |
NTimer iAsyncGetValueTimer;
|
sl@0
|
87 |
TDfc iAsyncGetValueDfc;
|
sl@0
|
88 |
|
sl@0
|
89 |
// Async get value 2
|
sl@0
|
90 |
TClientDataRequest2<TInt,TInt>* iAsyncGetValue2Request;
|
sl@0
|
91 |
NTimer iAsyncGetValue2Timer;
|
sl@0
|
92 |
TDfc iAsyncGetValue2Dfc;
|
sl@0
|
93 |
|
sl@0
|
94 |
// Read
|
sl@0
|
95 |
TClientBufferRequest* iReadRequest;
|
sl@0
|
96 |
NTimer iReadTimer;
|
sl@0
|
97 |
TClientBuffer* iClientReadBuffer;
|
sl@0
|
98 |
TDfc iCompleteReadDfc;
|
sl@0
|
99 |
|
sl@0
|
100 |
// Write
|
sl@0
|
101 |
TClientBufferRequest* iWriteRequest;
|
sl@0
|
102 |
NTimer iWriteTimer;
|
sl@0
|
103 |
TClientBuffer* iClientWriteBuffer;
|
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 |
iAsyncGetValueTimer(NULL, this),
|
sl@0
|
110 |
iAsyncGetValueDfc(AsyncGetValueCompleteDfcFunc, this, 0),
|
sl@0
|
111 |
iAsyncGetValue2Timer(NULL, this),
|
sl@0
|
112 |
iAsyncGetValue2Dfc(AsyncGetValue2CompleteDfcFunc, this, 0),
|
sl@0
|
113 |
iReadTimer(NULL, this),
|
sl@0
|
114 |
iCompleteReadDfc(ReceiveCompleteDfcFunc, this, 0),
|
sl@0
|
115 |
iWriteTimer(NULL, this),
|
sl@0
|
116 |
iCompleteWriteDfc(SendCompleteDfcFunc, this, 0)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
iClient = &Kern::CurrentThread();
|
sl@0
|
119 |
iClient->Open();
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
DExampleChannel::~DExampleChannel()
|
sl@0
|
123 |
{
|
sl@0
|
124 |
Kern::SafeClose((DObject*&)iClient, NULL);
|
sl@0
|
125 |
if (iDynamicDfcQ)
|
sl@0
|
126 |
iDynamicDfcQ->Destroy();
|
sl@0
|
127 |
Kern::DestroyClientRequest(iNotifyRequest);
|
sl@0
|
128 |
Kern::DestroyClientRequest(iAsyncGetValueRequest);
|
sl@0
|
129 |
Kern::DestroyClientRequest(iAsyncGetValue2Request);
|
sl@0
|
130 |
Kern::DestroyClientBufferRequest(iReadRequest);
|
sl@0
|
131 |
Kern::DestroyClientBufferRequest(iWriteRequest);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
TDfcQue* DExampleChannel::DfcQ()
|
sl@0
|
135 |
{
|
sl@0
|
136 |
return iDynamicDfcQ;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
TInt DExampleChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
TInt r;
|
sl@0
|
142 |
|
sl@0
|
143 |
r = Kern::CreateClientRequest(iNotifyRequest);
|
sl@0
|
144 |
if (r != KErrNone)
|
sl@0
|
145 |
return r;
|
sl@0
|
146 |
r = Kern::CreateClientDataRequest(iAsyncGetValueRequest);
|
sl@0
|
147 |
if (r != KErrNone)
|
sl@0
|
148 |
return r;
|
sl@0
|
149 |
r = Kern::CreateClientDataRequest2(iAsyncGetValue2Request);
|
sl@0
|
150 |
if (r != KErrNone)
|
sl@0
|
151 |
return r;
|
sl@0
|
152 |
r = Kern::CreateClientBufferRequest(iReadRequest, 1, TClientBufferRequest::EPinVirtual);
|
sl@0
|
153 |
if (r != KErrNone)
|
sl@0
|
154 |
return r;
|
sl@0
|
155 |
r = Kern::CreateClientBufferRequest(iWriteRequest, 1, TClientBufferRequest::EPinVirtual);
|
sl@0
|
156 |
if (r != KErrNone)
|
sl@0
|
157 |
return r;
|
sl@0
|
158 |
|
sl@0
|
159 |
// create a dynamic DFC queue, which is used for handling client messages and for our own DFCs
|
sl@0
|
160 |
r = Kern::DynamicDfcQCreate(iDynamicDfcQ, KDfcQThreadPriority, KPagingExample1PostLdd);
|
sl@0
|
161 |
if (r != KErrNone)
|
sl@0
|
162 |
return r;
|
sl@0
|
163 |
|
sl@0
|
164 |
// todo: this will be the default anyway
|
sl@0
|
165 |
iDynamicDfcQ->SetRealtimeState(ERealtimeStateOn);
|
sl@0
|
166 |
|
sl@0
|
167 |
SetDfcQ(DfcQ());
|
sl@0
|
168 |
iAsyncGetValueDfc.SetDfcQ(DfcQ());
|
sl@0
|
169 |
iAsyncGetValue2Dfc.SetDfcQ(DfcQ());
|
sl@0
|
170 |
iCompleteReadDfc.SetDfcQ(DfcQ());
|
sl@0
|
171 |
iCompleteWriteDfc.SetDfcQ(DfcQ());
|
sl@0
|
172 |
iMsgQ.Receive();
|
sl@0
|
173 |
return KErrNone;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
// override SendMsg method to allow pinning data in the context of the client thread
|
sl@0
|
177 |
TInt DExampleChannel::SendMsg(TMessageBase* aMsg)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
TThreadMessage& m=*(TThreadMessage*)aMsg;
|
sl@0
|
180 |
TInt id = m.iValue;
|
sl@0
|
181 |
|
sl@0
|
182 |
// we only support one client
|
sl@0
|
183 |
if (id != (TInt)ECloseMsg && m.Client() != iClient)
|
sl@0
|
184 |
return KErrAccessDenied;
|
sl@0
|
185 |
|
sl@0
|
186 |
TInt r = KErrNone;
|
sl@0
|
187 |
if (id != (TInt)ECloseMsg && id != KMaxTInt)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
if (id<0)
|
sl@0
|
190 |
{
|
sl@0
|
191 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
|
sl@0
|
192 |
r = SendRequest(aMsg);
|
sl@0
|
193 |
if (r != KErrNone)
|
sl@0
|
194 |
Kern::RequestComplete(pS,r);
|
sl@0
|
195 |
}
|
sl@0
|
196 |
else
|
sl@0
|
197 |
r = SendControl(aMsg);
|
sl@0
|
198 |
}
|
sl@0
|
199 |
else
|
sl@0
|
200 |
r = DLogicalChannel::SendMsg(aMsg);
|
sl@0
|
201 |
|
sl@0
|
202 |
return r;
|
sl@0
|
203 |
}
|
sl@0
|
204 |
|
sl@0
|
205 |
void DExampleChannel::HandleMsg(TMessageBase* aMsg)
|
sl@0
|
206 |
{
|
sl@0
|
207 |
TThreadMessage& m=*(TThreadMessage*)aMsg;
|
sl@0
|
208 |
TInt id=m.iValue;
|
sl@0
|
209 |
|
sl@0
|
210 |
if (id==(TInt)ECloseMsg)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
Shutdown();
|
sl@0
|
213 |
m.Complete(KErrNone,EFalse);
|
sl@0
|
214 |
return;
|
sl@0
|
215 |
}
|
sl@0
|
216 |
else if (id==KMaxTInt)
|
sl@0
|
217 |
{
|
sl@0
|
218 |
// DoCancel
|
sl@0
|
219 |
DoCancel(m.Int0());
|
sl@0
|
220 |
m.Complete(KErrNone,ETrue);
|
sl@0
|
221 |
return;
|
sl@0
|
222 |
}
|
sl@0
|
223 |
else if (id<0)
|
sl@0
|
224 |
{
|
sl@0
|
225 |
// DoRequest
|
sl@0
|
226 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
|
sl@0
|
227 |
DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
|
sl@0
|
228 |
m.Complete(KErrNone,ETrue);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
else
|
sl@0
|
231 |
{
|
sl@0
|
232 |
// DoControl
|
sl@0
|
233 |
TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
|
sl@0
|
234 |
m.Complete(r,ETrue);
|
sl@0
|
235 |
}
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
TInt DExampleChannel::SendControl(TMessageBase* aMsg)
|
sl@0
|
239 |
{
|
sl@0
|
240 |
TThreadMessage& m=*(TThreadMessage*)aMsg;
|
sl@0
|
241 |
TInt id=m.iValue;
|
sl@0
|
242 |
|
sl@0
|
243 |
// thread-local copy of configuration data
|
sl@0
|
244 |
TConfigData kernelConfigBuffer;
|
sl@0
|
245 |
TAny* userConfigPtr = m.Ptr0();
|
sl@0
|
246 |
|
sl@0
|
247 |
switch (id)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
case RPagingExample::ESetConfig:
|
sl@0
|
250 |
// copy config from client to local buffer in context of client thread
|
sl@0
|
251 |
umemget32(&kernelConfigBuffer, userConfigPtr, sizeof(TConfigData));
|
sl@0
|
252 |
// update message to point to kernel-side buffer
|
sl@0
|
253 |
m.iArg[0] = &kernelConfigBuffer;
|
sl@0
|
254 |
break;
|
sl@0
|
255 |
|
sl@0
|
256 |
case RPagingExample::EGetConfig:
|
sl@0
|
257 |
// update message to point to kernel-side buffer
|
sl@0
|
258 |
m.iArg[0] = &kernelConfigBuffer;
|
sl@0
|
259 |
break;
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
TInt r = DLogicalChannel::SendMsg(aMsg);
|
sl@0
|
263 |
if (r != KErrNone)
|
sl@0
|
264 |
return r;
|
sl@0
|
265 |
|
sl@0
|
266 |
switch (id)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
case RPagingExample::EGetConfig:
|
sl@0
|
269 |
// copy config from local bufferto client in context of client thread
|
sl@0
|
270 |
umemput32(userConfigPtr, &kernelConfigBuffer, sizeof(TConfigData));
|
sl@0
|
271 |
break;
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
return r;
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
TInt DExampleChannel::DoControl(TInt aFunction,TAny* a1,TAny* /*a2*/)
|
sl@0
|
278 |
{
|
sl@0
|
279 |
TInt r = KErrNone;
|
sl@0
|
280 |
TConfigData* configBuffer = (TConfigData*)a1;
|
sl@0
|
281 |
switch (aFunction)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
case RPagingExample::EGetConfig:
|
sl@0
|
284 |
// copy current config into local buffer in context of DFC thread to avoid potential race conditions
|
sl@0
|
285 |
*configBuffer = iConfig;
|
sl@0
|
286 |
break;
|
sl@0
|
287 |
|
sl@0
|
288 |
case RPagingExample::ESetConfig:
|
sl@0
|
289 |
// set config from copy in local buffer in context of DFC thread to avoid potential race conditions
|
sl@0
|
290 |
SetConfig(*configBuffer);
|
sl@0
|
291 |
break;
|
sl@0
|
292 |
|
sl@0
|
293 |
default:
|
sl@0
|
294 |
r = KErrNotSupported;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
return r;
|
sl@0
|
297 |
}
|
sl@0
|
298 |
|
sl@0
|
299 |
TInt DExampleChannel::SendRequest(TMessageBase* aMsg)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
TThreadMessage& m=*(TThreadMessage*)aMsg;
|
sl@0
|
302 |
TInt function = ~m.iValue;
|
sl@0
|
303 |
TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
|
sl@0
|
304 |
TAny* a1 = m.Ptr1();
|
sl@0
|
305 |
TAny* a2 = m.Ptr2();
|
sl@0
|
306 |
|
sl@0
|
307 |
TInt r = KErrNotSupported;
|
sl@0
|
308 |
switch (function)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
case RPagingExample::ERequestNotify:
|
sl@0
|
311 |
r = PreNotify(pS);
|
sl@0
|
312 |
break;
|
sl@0
|
313 |
|
sl@0
|
314 |
case RPagingExample::ERequestAsyncGetValue:
|
sl@0
|
315 |
r = PreAsyncGetValue((TInt*)a1, pS);
|
sl@0
|
316 |
break;
|
sl@0
|
317 |
|
sl@0
|
318 |
case RPagingExample::ERequestAsyncGetValue2:
|
sl@0
|
319 |
r = PreAsyncGetValue2((TInt*)a1, (TInt*)a2, pS);
|
sl@0
|
320 |
break;
|
sl@0
|
321 |
|
sl@0
|
322 |
case RPagingExample::ERequestRead:
|
sl@0
|
323 |
r = PreRead(a1, (TInt)a2, pS);
|
sl@0
|
324 |
break;
|
sl@0
|
325 |
|
sl@0
|
326 |
case RPagingExample::ERequestReadDes:
|
sl@0
|
327 |
r = PreReadDes((TDes8*)a1, pS);
|
sl@0
|
328 |
break;
|
sl@0
|
329 |
|
sl@0
|
330 |
case RPagingExample::ERequestWrite:
|
sl@0
|
331 |
r = PreWrite(a1, (TInt)a2, pS);
|
sl@0
|
332 |
break;
|
sl@0
|
333 |
|
sl@0
|
334 |
case RPagingExample::ERequestWriteDes:
|
sl@0
|
335 |
r = PreWriteDes((TDes8*)a1, pS);
|
sl@0
|
336 |
break;
|
sl@0
|
337 |
}
|
sl@0
|
338 |
|
sl@0
|
339 |
if (r == KErrNone)
|
sl@0
|
340 |
r = DLogicalChannel::SendMsg(aMsg);
|
sl@0
|
341 |
return r;
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
void DExampleChannel::DoRequest(TInt aFunction, TRequestStatus* /*aStatus*/, TAny* /*a1*/, TAny* /*a2*/)
|
sl@0
|
345 |
{
|
sl@0
|
346 |
switch (aFunction)
|
sl@0
|
347 |
{
|
sl@0
|
348 |
case RPagingExample::ERequestNotify:
|
sl@0
|
349 |
StartNotify();
|
sl@0
|
350 |
break;
|
sl@0
|
351 |
|
sl@0
|
352 |
case RPagingExample::ERequestAsyncGetValue:
|
sl@0
|
353 |
StartAsyncGetValue();
|
sl@0
|
354 |
break;
|
sl@0
|
355 |
|
sl@0
|
356 |
case RPagingExample::ERequestAsyncGetValue2:
|
sl@0
|
357 |
StartAsyncGetValue2();
|
sl@0
|
358 |
break;
|
sl@0
|
359 |
|
sl@0
|
360 |
case RPagingExample::ERequestRead:
|
sl@0
|
361 |
StartRead();
|
sl@0
|
362 |
break;
|
sl@0
|
363 |
|
sl@0
|
364 |
case RPagingExample::ERequestReadDes:
|
sl@0
|
365 |
StartReadDes();
|
sl@0
|
366 |
break;
|
sl@0
|
367 |
|
sl@0
|
368 |
case RPagingExample::ERequestWrite:
|
sl@0
|
369 |
StartWrite();
|
sl@0
|
370 |
break;
|
sl@0
|
371 |
|
sl@0
|
372 |
case RPagingExample::ERequestWriteDes:
|
sl@0
|
373 |
StartWriteDes();
|
sl@0
|
374 |
break;
|
sl@0
|
375 |
|
sl@0
|
376 |
default:
|
sl@0
|
377 |
__NK_ASSERT_ALWAYS(EFalse); // we already validated the request number
|
sl@0
|
378 |
}
|
sl@0
|
379 |
}
|
sl@0
|
380 |
|
sl@0
|
381 |
TInt DExampleChannel::DoCancel(TUint /*aMask*/)
|
sl@0
|
382 |
{
|
sl@0
|
383 |
if (iAsyncGetValueRequest->IsReady())
|
sl@0
|
384 |
{
|
sl@0
|
385 |
iAsyncGetValueTimer.Cancel();
|
sl@0
|
386 |
iAsyncGetValueDfc.Cancel();
|
sl@0
|
387 |
Kern::QueueRequestComplete(iClient, iAsyncGetValueRequest, KErrCancel);
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
if (iAsyncGetValue2Request->IsReady())
|
sl@0
|
391 |
{
|
sl@0
|
392 |
iAsyncGetValue2Timer.Cancel();
|
sl@0
|
393 |
iAsyncGetValue2Dfc.Cancel();
|
sl@0
|
394 |
Kern::QueueRequestComplete(iClient, iAsyncGetValue2Request, KErrCancel);
|
sl@0
|
395 |
}
|
sl@0
|
396 |
|
sl@0
|
397 |
if (iReadRequest->IsReady())
|
sl@0
|
398 |
{
|
sl@0
|
399 |
iReadTimer.Cancel();
|
sl@0
|
400 |
iCompleteReadDfc.Cancel();
|
sl@0
|
401 |
Kern::QueueBufferRequestComplete(iClient, iReadRequest, KErrCancel);
|
sl@0
|
402 |
}
|
sl@0
|
403 |
|
sl@0
|
404 |
if (iWriteRequest->IsReady())
|
sl@0
|
405 |
{
|
sl@0
|
406 |
iWriteTimer.Cancel();
|
sl@0
|
407 |
iCompleteWriteDfc.Cancel();
|
sl@0
|
408 |
Kern::QueueBufferRequestComplete(iClient, iWriteRequest, KErrCancel);
|
sl@0
|
409 |
}
|
sl@0
|
410 |
|
sl@0
|
411 |
return KErrNone;
|
sl@0
|
412 |
}
|
sl@0
|
413 |
|
sl@0
|
414 |
void DExampleChannel::Shutdown()
|
sl@0
|
415 |
{
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
void DExampleChannel::SetConfig(const TConfigData& aNewConfig)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
iConfig = aNewConfig;
|
sl@0
|
421 |
}
|
sl@0
|
422 |
|
sl@0
|
423 |
TInt DExampleChannel::PreNotify(TRequestStatus* aStatus)
|
sl@0
|
424 |
{
|
sl@0
|
425 |
return iNotifyRequest->SetStatus(aStatus);
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
void DExampleChannel::StartNotify()
|
sl@0
|
429 |
{
|
sl@0
|
430 |
CompleteNotify(); // example implementation completes the request immediately
|
sl@0
|
431 |
}
|
sl@0
|
432 |
|
sl@0
|
433 |
void DExampleChannel::CompleteNotify()
|
sl@0
|
434 |
{
|
sl@0
|
435 |
Kern::QueueRequestComplete(iClient, iNotifyRequest, KErrNone);
|
sl@0
|
436 |
}
|
sl@0
|
437 |
|
sl@0
|
438 |
TInt DExampleChannel::PreAsyncGetValue(TInt* aValue, TRequestStatus* aStatus)
|
sl@0
|
439 |
{
|
sl@0
|
440 |
TInt r = iAsyncGetValueRequest->SetStatus(aStatus);
|
sl@0
|
441 |
if (r != KErrNone)
|
sl@0
|
442 |
return r;
|
sl@0
|
443 |
iAsyncGetValueRequest->SetDestPtr(aValue);
|
sl@0
|
444 |
return KErrNone;
|
sl@0
|
445 |
}
|
sl@0
|
446 |
|
sl@0
|
447 |
void DExampleChannel::StartAsyncGetValue()
|
sl@0
|
448 |
{
|
sl@0
|
449 |
// queue a timer to simulate an asynchronous operation
|
sl@0
|
450 |
iAsyncGetValueTimer.OneShot(KAsyncDelay, iAsyncGetValueDfc);
|
sl@0
|
451 |
}
|
sl@0
|
452 |
|
sl@0
|
453 |
void DExampleChannel::AsyncGetValueCompleteDfcFunc(TAny* aPtr)
|
sl@0
|
454 |
{
|
sl@0
|
455 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
456 |
self->CompleteAsyncGetValue();
|
sl@0
|
457 |
}
|
sl@0
|
458 |
|
sl@0
|
459 |
void DExampleChannel::CompleteAsyncGetValue()
|
sl@0
|
460 |
{
|
sl@0
|
461 |
iAsyncGetValueRequest->Data().iValue1 = 1;
|
sl@0
|
462 |
iAsyncGetValueRequest->Data().iValue2 = _L8("shrt");
|
sl@0
|
463 |
Kern::QueueRequestComplete(iClient, iAsyncGetValueRequest, KErrNone);
|
sl@0
|
464 |
}
|
sl@0
|
465 |
|
sl@0
|
466 |
TInt DExampleChannel::PreAsyncGetValue2(TInt* aValue1, TInt* aValue2, TRequestStatus* aStatus)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
TInt r = iAsyncGetValue2Request->SetStatus(aStatus);
|
sl@0
|
469 |
if (r != KErrNone)
|
sl@0
|
470 |
return r;
|
sl@0
|
471 |
iAsyncGetValue2Request->SetDestPtr1(aValue1);
|
sl@0
|
472 |
iAsyncGetValue2Request->SetDestPtr2(aValue2);
|
sl@0
|
473 |
return KErrNone;
|
sl@0
|
474 |
}
|
sl@0
|
475 |
|
sl@0
|
476 |
void DExampleChannel::StartAsyncGetValue2()
|
sl@0
|
477 |
{
|
sl@0
|
478 |
// queue a timer to simulate an asynchronous operation
|
sl@0
|
479 |
iAsyncGetValue2Timer.OneShot(KAsyncDelay, iAsyncGetValue2Dfc);
|
sl@0
|
480 |
}
|
sl@0
|
481 |
|
sl@0
|
482 |
void DExampleChannel::AsyncGetValue2CompleteDfcFunc(TAny* aPtr)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
485 |
self->CompleteAsyncGetValue2();
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
void DExampleChannel::CompleteAsyncGetValue2()
|
sl@0
|
489 |
{
|
sl@0
|
490 |
iAsyncGetValue2Request->Data1() = 1;
|
sl@0
|
491 |
iAsyncGetValue2Request->Data2() = 2;
|
sl@0
|
492 |
Kern::QueueRequestComplete(iClient, iAsyncGetValue2Request, KErrNone);
|
sl@0
|
493 |
}
|
sl@0
|
494 |
|
sl@0
|
495 |
TInt DExampleChannel::PreRead(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
// check length argument first
|
sl@0
|
498 |
if (aLength < 1 || aLength > KBufferSize)
|
sl@0
|
499 |
return KErrArgument;
|
sl@0
|
500 |
|
sl@0
|
501 |
// start request setup
|
sl@0
|
502 |
TInt r = iReadRequest->StartSetup(aStatus);
|
sl@0
|
503 |
if (r != KErrNone)
|
sl@0
|
504 |
return r;
|
sl@0
|
505 |
|
sl@0
|
506 |
// add client buffer, this does pinning in context of client thread
|
sl@0
|
507 |
r = iReadRequest->AddBuffer(iClientReadBuffer, (TLinAddr)aBuffer, aLength, ETrue);
|
sl@0
|
508 |
if (r != KErrNone)
|
sl@0
|
509 |
return KErrNoMemory;
|
sl@0
|
510 |
|
sl@0
|
511 |
iReadRequest->EndSetup();
|
sl@0
|
512 |
return KErrNone;
|
sl@0
|
513 |
}
|
sl@0
|
514 |
|
sl@0
|
515 |
void DExampleChannel::StartRead()
|
sl@0
|
516 |
{
|
sl@0
|
517 |
ReceiveToReadBuffer(); // called in DFC thread as may require serialised access to hardware
|
sl@0
|
518 |
}
|
sl@0
|
519 |
|
sl@0
|
520 |
TInt DExampleChannel::PreReadDes(TDes8* aDesOut, TRequestStatus* aStatus)
|
sl@0
|
521 |
{
|
sl@0
|
522 |
// start request setup
|
sl@0
|
523 |
TInt r = iReadRequest->StartSetup(aStatus);
|
sl@0
|
524 |
if (r != KErrNone)
|
sl@0
|
525 |
return r;
|
sl@0
|
526 |
|
sl@0
|
527 |
// add client descriptor, this does pinning in context of client thread
|
sl@0
|
528 |
r = iReadRequest->AddBuffer(iClientReadBuffer, aDesOut);
|
sl@0
|
529 |
if (r != KErrNone)
|
sl@0
|
530 |
return r;
|
sl@0
|
531 |
|
sl@0
|
532 |
// can check length argument here
|
sl@0
|
533 |
TInt length = iClientReadBuffer->MaxLength();
|
sl@0
|
534 |
if (length < 1 || length > KBufferSize)
|
sl@0
|
535 |
{
|
sl@0
|
536 |
// need to reset object so it can be reused
|
sl@0
|
537 |
iReadRequest->Reset();
|
sl@0
|
538 |
return KErrArgument;
|
sl@0
|
539 |
}
|
sl@0
|
540 |
|
sl@0
|
541 |
iReadRequest->EndSetup();
|
sl@0
|
542 |
return KErrNone;
|
sl@0
|
543 |
}
|
sl@0
|
544 |
|
sl@0
|
545 |
void DExampleChannel::StartReadDes()
|
sl@0
|
546 |
{
|
sl@0
|
547 |
ReceiveToReadBuffer(); // called in DFC thread as may require serialised access to hardware
|
sl@0
|
548 |
}
|
sl@0
|
549 |
|
sl@0
|
550 |
TInt DExampleChannel::PreWrite(TAny* aBuffer, TInt aLength, TRequestStatus* aStatus)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
// check length argument first
|
sl@0
|
553 |
if (aLength < 1 || aLength > KBufferSize)
|
sl@0
|
554 |
return KErrArgument;
|
sl@0
|
555 |
|
sl@0
|
556 |
// demonstrate use the single-buffer version of Setup
|
sl@0
|
557 |
return iWriteRequest->Setup(iClientWriteBuffer, aStatus, (TLinAddr)aBuffer, aLength);
|
sl@0
|
558 |
}
|
sl@0
|
559 |
|
sl@0
|
560 |
void DExampleChannel::StartWrite()
|
sl@0
|
561 |
{
|
sl@0
|
562 |
SendFromWriteBuffer(); // called in DFC thread as may require serialised access to hardware
|
sl@0
|
563 |
}
|
sl@0
|
564 |
|
sl@0
|
565 |
TInt DExampleChannel::PreWriteDes(const TDesC8* aDesIn, TRequestStatus* aStatus)
|
sl@0
|
566 |
{
|
sl@0
|
567 |
// demonstrate use the single-buffer version of Setup
|
sl@0
|
568 |
TInt r = iWriteRequest->Setup(iClientWriteBuffer, aStatus, (TAny*)aDesIn);
|
sl@0
|
569 |
if (r != KErrNone)
|
sl@0
|
570 |
return r;
|
sl@0
|
571 |
|
sl@0
|
572 |
// can check length argument here
|
sl@0
|
573 |
TInt length = iClientWriteBuffer->Length();
|
sl@0
|
574 |
if (length < 1 || length > KBufferSize)
|
sl@0
|
575 |
{
|
sl@0
|
576 |
// need to reset object so it can be reused
|
sl@0
|
577 |
iWriteRequest->Reset();
|
sl@0
|
578 |
return KErrArgument;
|
sl@0
|
579 |
}
|
sl@0
|
580 |
|
sl@0
|
581 |
return KErrNone;
|
sl@0
|
582 |
}
|
sl@0
|
583 |
|
sl@0
|
584 |
void DExampleChannel::StartWriteDes()
|
sl@0
|
585 |
{
|
sl@0
|
586 |
SendFromWriteBuffer(); // called in DFC thread as may require serialised access to hardware
|
sl@0
|
587 |
}
|
sl@0
|
588 |
|
sl@0
|
589 |
void DExampleChannel::ReceiveToReadBuffer()
|
sl@0
|
590 |
{
|
sl@0
|
591 |
// just queue a timer to simulate an asynchronous receive operation
|
sl@0
|
592 |
// actually will return the previous contents of the buffer
|
sl@0
|
593 |
iReadTimer.OneShot(KAsyncDelay, iCompleteReadDfc);
|
sl@0
|
594 |
}
|
sl@0
|
595 |
|
sl@0
|
596 |
void DExampleChannel::SendFromWriteBuffer()
|
sl@0
|
597 |
{
|
sl@0
|
598 |
// just queue a timer to simulate an asynchronous send operation
|
sl@0
|
599 |
iWriteTimer.OneShot(KAsyncDelay, iCompleteWriteDfc);
|
sl@0
|
600 |
}
|
sl@0
|
601 |
|
sl@0
|
602 |
void DExampleChannel::ReceiveCompleteDfcFunc(TAny* aPtr)
|
sl@0
|
603 |
{
|
sl@0
|
604 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
605 |
self->CompleteRead();
|
sl@0
|
606 |
}
|
sl@0
|
607 |
|
sl@0
|
608 |
void DExampleChannel::SendCompleteDfcFunc(TAny* aPtr)
|
sl@0
|
609 |
{
|
sl@0
|
610 |
DExampleChannel* self = (DExampleChannel*)aPtr;
|
sl@0
|
611 |
self->CompleteWrite();
|
sl@0
|
612 |
}
|
sl@0
|
613 |
|
sl@0
|
614 |
void DExampleChannel::CompleteRead()
|
sl@0
|
615 |
{
|
sl@0
|
616 |
TPtrC8 des(iBuffer, iClientReadBuffer->MaxLength());
|
sl@0
|
617 |
TInt r = Kern::ThreadBufWrite(iClient, iClientReadBuffer, des, 0, KChunkShiftBy0, iClient);
|
sl@0
|
618 |
Kern::QueueBufferRequestComplete(iClient, iReadRequest, r);
|
sl@0
|
619 |
}
|
sl@0
|
620 |
|
sl@0
|
621 |
void DExampleChannel::CompleteWrite()
|
sl@0
|
622 |
{
|
sl@0
|
623 |
TPtr8 des(iBuffer, iClientWriteBuffer->Length());
|
sl@0
|
624 |
TInt r = Kern::ThreadBufRead(iClient, iClientWriteBuffer, des, 0, KChunkShiftBy0);
|
sl@0
|
625 |
Kern::QueueBufferRequestComplete(iClient, iWriteRequest, r);
|
sl@0
|
626 |
}
|
sl@0
|
627 |
|
sl@0
|
628 |
//
|
sl@0
|
629 |
// Logical device
|
sl@0
|
630 |
//
|
sl@0
|
631 |
|
sl@0
|
632 |
class DExampleFactory : public DLogicalDevice
|
sl@0
|
633 |
{
|
sl@0
|
634 |
public:
|
sl@0
|
635 |
DExampleFactory();
|
sl@0
|
636 |
virtual TInt Install();
|
sl@0
|
637 |
virtual void GetCaps(TDes8& aDes) const;
|
sl@0
|
638 |
virtual TInt Create(DLogicalChannelBase*& aChannel);
|
sl@0
|
639 |
};
|
sl@0
|
640 |
|
sl@0
|
641 |
DExampleFactory::DExampleFactory()
|
sl@0
|
642 |
{
|
sl@0
|
643 |
iParseMask = 0;
|
sl@0
|
644 |
iVersion = TVersion(1, 0, 0);
|
sl@0
|
645 |
}
|
sl@0
|
646 |
|
sl@0
|
647 |
TInt DExampleFactory::Install()
|
sl@0
|
648 |
{
|
sl@0
|
649 |
return SetName(&KPagingExample1PostLdd);
|
sl@0
|
650 |
}
|
sl@0
|
651 |
|
sl@0
|
652 |
void DExampleFactory::GetCaps(TDes8& /*aDes*/) const
|
sl@0
|
653 |
{
|
sl@0
|
654 |
// not used but required as DLogicalDevice::GetCaps is pure virtual
|
sl@0
|
655 |
}
|
sl@0
|
656 |
|
sl@0
|
657 |
TInt DExampleFactory::Create(DLogicalChannelBase*& aChannel)
|
sl@0
|
658 |
{
|
sl@0
|
659 |
aChannel = new DExampleChannel;
|
sl@0
|
660 |
return aChannel ? KErrNone : KErrNoMemory;
|
sl@0
|
661 |
}
|
sl@0
|
662 |
|
sl@0
|
663 |
DECLARE_STANDARD_LDD()
|
sl@0
|
664 |
{
|
sl@0
|
665 |
return new DExampleFactory;
|
sl@0
|
666 |
}
|