0
|
1 |
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// t_shbuf_perfserver.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
* @file
|
|
20 |
*
|
|
21 |
* Test server used for Performance Testing of shared buffers.
|
|
22 |
*/
|
|
23 |
|
|
24 |
#include <e32std.h>
|
|
25 |
#include <e32debug.h>
|
|
26 |
#include <e32msgqueue.h>
|
|
27 |
#include <e32shbuf.h>
|
|
28 |
|
|
29 |
#include "t_shbuf_perfserver.h"
|
|
30 |
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Second phase constructor for sessions. Called by the CServer2 framework
|
|
34 |
* when a session is created (e.g. a connection is made to the server).
|
|
35 |
*/
|
|
36 |
void CShBufTestServerSession::CreateL()
|
|
37 |
{
|
|
38 |
Server().AddSessionL(this);
|
|
39 |
} // CShBufTestServerSession::CreateL()
|
|
40 |
|
|
41 |
|
|
42 |
/**
|
|
43 |
* Destructor for session classes. When this is called it indicates that
|
|
44 |
* a session is closing its connection with the server.
|
|
45 |
*/
|
|
46 |
CShBufTestServerSession::~CShBufTestServerSession()
|
|
47 |
{
|
|
48 |
Server().DropSession(this);
|
|
49 |
} // CShBufTestServerSession::~CShBufTestServerSession()
|
|
50 |
|
|
51 |
|
|
52 |
/**
|
|
53 |
* Handle message requests for this session. Leaving is handled by
|
|
54 |
* CShBufTestServer::RunError() which reports the error code to the client.
|
|
55 |
*
|
|
56 |
* @param aMessage RMessage2 reference which encapsulates a client request.
|
|
57 |
*/
|
|
58 |
void CShBufTestServerSession::ServiceL(const RMessage2& aMessage)
|
|
59 |
|
|
60 |
{
|
|
61 |
switch (aMessage.Function())
|
|
62 |
{
|
|
63 |
case EShBufServerShutdownServer:
|
|
64 |
{
|
|
65 |
ShutdownServerL(aMessage);
|
|
66 |
}
|
|
67 |
break;
|
|
68 |
|
|
69 |
case EShBufServerFromTPtr8ProcessAndReturn:
|
|
70 |
{
|
|
71 |
FromTPtr8ProcessAndReturnL(aMessage);
|
|
72 |
}
|
|
73 |
break;
|
|
74 |
|
|
75 |
case EShBufServerFromTPtr8ProcessAndRelease:
|
|
76 |
{
|
|
77 |
FromTPtr8ProcessAndReleaseL(aMessage);
|
|
78 |
}
|
|
79 |
break;
|
|
80 |
|
|
81 |
case EShBufServerOpenRShBufPool:
|
|
82 |
{
|
|
83 |
OpenRShBufPoolL(aMessage);
|
|
84 |
}
|
|
85 |
break;
|
|
86 |
|
|
87 |
case EShBufServerCloseRShBufPool:
|
|
88 |
{
|
|
89 |
CloseRShBufPoolL(aMessage);
|
|
90 |
}
|
|
91 |
break;
|
|
92 |
|
|
93 |
case EShBufServerFromRShBufProcessAndReturn:
|
|
94 |
{
|
|
95 |
FromRShBufProcessAndReturnL(aMessage);
|
|
96 |
}
|
|
97 |
break;
|
|
98 |
|
|
99 |
case EShBufServerFromRShBufProcessAndRelease:
|
|
100 |
{
|
|
101 |
FromRShBufProcessAndReleaseL(aMessage);
|
|
102 |
}
|
|
103 |
break;
|
|
104 |
|
|
105 |
case EShBufServerDbgMarkHeap:
|
|
106 |
{
|
|
107 |
DbgMarkHeapL(aMessage);
|
|
108 |
}
|
|
109 |
break;
|
|
110 |
|
|
111 |
case EShBufServerDbgCheckHeap:
|
|
112 |
{
|
|
113 |
DbgCheckHeapL(aMessage);
|
|
114 |
}
|
|
115 |
break;
|
|
116 |
|
|
117 |
case EShBufServerDbgMarkEnd:
|
|
118 |
{
|
|
119 |
DbgMarkEndL(aMessage);
|
|
120 |
}
|
|
121 |
break;
|
|
122 |
|
|
123 |
case EShBufServerDbgFailNext:
|
|
124 |
{
|
|
125 |
DbgFailNextL(aMessage);
|
|
126 |
}
|
|
127 |
break;
|
|
128 |
|
|
129 |
default:
|
|
130 |
{
|
|
131 |
aMessage.Panic(KRShBufTestServerName, 999);
|
|
132 |
}
|
|
133 |
break;
|
|
134 |
}
|
|
135 |
} // CShBufTestServerSession::ServiceL()
|
|
136 |
|
|
137 |
|
|
138 |
/**
|
|
139 |
* Completes a client request. This function provides a single point of
|
|
140 |
* message completion which benefits debugging and maintenance.
|
|
141 |
*
|
|
142 |
* @param aMessage The RMessage2 client request.
|
|
143 |
* @param aResult Result of the request.
|
|
144 |
*/
|
|
145 |
void CShBufTestServerSession::CompleteRequest(const RMessage2& aMessage,
|
|
146 |
TInt aResult) const
|
|
147 |
{
|
|
148 |
if (aMessage.IsNull() == EFalse)
|
|
149 |
{
|
|
150 |
aMessage.Complete(aResult);
|
|
151 |
}
|
|
152 |
} // CShBufTestServerSession::CompleteRequest()
|
|
153 |
|
|
154 |
|
|
155 |
/**
|
|
156 |
* Takes a buffer from the client, sends to the driver and back to the client.
|
|
157 |
*
|
|
158 |
* @param aMessage RMessage2 client request.
|
|
159 |
*/
|
|
160 |
void CShBufTestServerSession::FromTPtr8ProcessAndReturnL(const RMessage2& aMessage)
|
|
161 |
{
|
|
162 |
//
|
|
163 |
// Read the client buffer...
|
|
164 |
//
|
|
165 |
TPtr8 bufPtr(iSessionTempBuffer, sizeof(iSessionTempBuffer));
|
|
166 |
|
|
167 |
aMessage.ReadL(0, bufPtr);
|
|
168 |
|
|
169 |
TUint bufSize;
|
|
170 |
|
|
171 |
bufSize = aMessage.Int1();
|
|
172 |
|
|
173 |
//
|
|
174 |
// Pass to the server to pass to the driver and back...
|
|
175 |
//
|
|
176 |
TInt result;
|
|
177 |
|
|
178 |
result = Server().FromTPtr8ProcessAndReturn(bufPtr, bufSize);
|
|
179 |
|
|
180 |
//
|
|
181 |
// Write the client buffer back...
|
|
182 |
//
|
|
183 |
aMessage.WriteL(0, bufPtr);
|
|
184 |
|
|
185 |
//
|
|
186 |
// Complete the request...
|
|
187 |
//
|
|
188 |
CompleteRequest(aMessage, result);
|
|
189 |
} // CShBufTestServerSession::FromTPtr8ProcessAndReturnL
|
|
190 |
|
|
191 |
|
|
192 |
/**
|
|
193 |
* Takes a buffer from the client and sends to the driver.
|
|
194 |
*
|
|
195 |
* @param aMessage RMessage2 client request.
|
|
196 |
*/
|
|
197 |
void CShBufTestServerSession::FromTPtr8ProcessAndReleaseL(const RMessage2& aMessage)
|
|
198 |
{
|
|
199 |
//
|
|
200 |
// Read the client buffer...
|
|
201 |
//
|
|
202 |
TPtr8 bufPtr(iSessionTempBuffer, sizeof(iSessionTempBuffer));
|
|
203 |
|
|
204 |
aMessage.ReadL(0, bufPtr);
|
|
205 |
|
|
206 |
//
|
|
207 |
// Pass to the server to pass to the driver and back...
|
|
208 |
//
|
|
209 |
TInt result;
|
|
210 |
|
|
211 |
result = Server().FromTPtr8ProcessAndRelease(bufPtr);
|
|
212 |
|
|
213 |
//
|
|
214 |
// Complete the request...
|
|
215 |
//
|
|
216 |
CompleteRequest(aMessage, result);
|
|
217 |
} // CShBufTestServerSession::FromTPtr8ProcessAndReleaseL
|
|
218 |
|
|
219 |
|
|
220 |
/**
|
|
221 |
* Allows the client to ask the test server to open a buffer pool.
|
|
222 |
*
|
|
223 |
* @param aMessage RMessage2 client request.
|
|
224 |
*/
|
|
225 |
void CShBufTestServerSession::OpenRShBufPoolL(const RMessage2& aMessage)
|
|
226 |
{
|
|
227 |
//
|
|
228 |
// Read the handle...
|
|
229 |
//
|
|
230 |
TInt poolHandle = aMessage.Int0();
|
|
231 |
|
|
232 |
//
|
|
233 |
// Read the pool info...
|
|
234 |
//
|
|
235 |
TShPoolInfo shPoolInfo;
|
|
236 |
TPckg<TShPoolInfo> shPoolInfoPckg(shPoolInfo);
|
|
237 |
|
|
238 |
aMessage.ReadL(1, shPoolInfoPckg);
|
|
239 |
|
|
240 |
//
|
|
241 |
// Pass to the server to open the pool...
|
|
242 |
//
|
|
243 |
TInt result = Server().OpenRShBufPool(poolHandle, shPoolInfo);
|
|
244 |
|
|
245 |
//
|
|
246 |
// Complete the request...
|
|
247 |
//
|
|
248 |
CompleteRequest(aMessage, result);
|
|
249 |
} // CShBufTestServerSession::OpenRShBufPoolL
|
|
250 |
|
|
251 |
|
|
252 |
/**
|
|
253 |
* Allows the client to ask the test server to close a buffer pool.
|
|
254 |
*
|
|
255 |
* @param aMessage RMessage2 client request.
|
|
256 |
*/
|
|
257 |
void CShBufTestServerSession::CloseRShBufPoolL(const RMessage2& aMessage)
|
|
258 |
{
|
|
259 |
//
|
|
260 |
// Pass to the server to close the pool...
|
|
261 |
//
|
|
262 |
TInt result = Server().CloseRShBufPool();
|
|
263 |
|
|
264 |
//
|
|
265 |
// Complete the request...
|
|
266 |
//
|
|
267 |
CompleteRequest(aMessage, result);
|
|
268 |
} // CShBufTestServerSession::CloseRShBufPoolL
|
|
269 |
|
|
270 |
|
|
271 |
/**
|
|
272 |
* Takes a buffer from the client, sends to the driver and back to the client.
|
|
273 |
*
|
|
274 |
* @param aMessage RMessage2 client request.
|
|
275 |
*/
|
|
276 |
void CShBufTestServerSession::FromRShBufProcessAndReturnL(const RMessage2& aMessage)
|
|
277 |
{
|
|
278 |
//
|
|
279 |
// Read the client handle buffer...
|
|
280 |
//
|
|
281 |
RShBuf shBuf;
|
|
282 |
TUint bufSize;
|
|
283 |
|
|
284 |
bufSize = aMessage.Int1();
|
|
285 |
|
|
286 |
//
|
|
287 |
// Pass to the server to pass to the driver and back...
|
|
288 |
//
|
|
289 |
TInt result;
|
|
290 |
|
|
291 |
result = Server().FromRShBufProcessAndReturn(shBuf, bufSize);
|
|
292 |
|
|
293 |
//
|
|
294 |
// Write the client buffer handle back...
|
|
295 |
//
|
|
296 |
#ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
|
|
297 |
// TDBD aMessage.Complete(shbuf->Handle());
|
|
298 |
#else
|
|
299 |
TPckg<TInt> handlePckg(shBuf.Handle());
|
|
300 |
aMessage.WriteL(0, handlePckg);
|
|
301 |
#endif
|
|
302 |
|
|
303 |
//
|
|
304 |
// Complete the request...
|
|
305 |
//
|
|
306 |
CompleteRequest(aMessage, result);
|
|
307 |
} // CShBufTestServerSession::FromRShBufProcessAndReturnL
|
|
308 |
|
|
309 |
|
|
310 |
/**
|
|
311 |
* Takes a buffer from the client and sends to the driver.
|
|
312 |
*
|
|
313 |
* @param aMessage RMessage2 client request.
|
|
314 |
*/
|
|
315 |
void CShBufTestServerSession::FromRShBufProcessAndReleaseL(const RMessage2& aMessage)
|
|
316 |
{
|
|
317 |
//
|
|
318 |
// Read the client buffer handle...
|
|
319 |
//
|
|
320 |
|
|
321 |
RShBuf shBuf;
|
|
322 |
|
|
323 |
#ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
|
|
324 |
// TBD RShBuf.Open(aMessage, 0);
|
|
325 |
#else
|
|
326 |
shBuf.SetReturnedHandle(aMessage.Int0());
|
|
327 |
#endif
|
|
328 |
|
|
329 |
//
|
|
330 |
// Pass to the server to pass to the driver and back...
|
|
331 |
//
|
|
332 |
TInt result;
|
|
333 |
|
|
334 |
result = Server().FromRShBufProcessAndRelease(shBuf);
|
|
335 |
|
|
336 |
//
|
|
337 |
// Complete the request...
|
|
338 |
//
|
|
339 |
CompleteRequest(aMessage, result);
|
|
340 |
} // CShBufTestServerSession::FromRShBufProcessAndReleaseL
|
|
341 |
|
|
342 |
|
|
343 |
/**
|
|
344 |
* Requests the server to mark the start of checking the server's heap.
|
|
345 |
* This function only works in debug releases and is a synchronous request
|
|
346 |
* which will be completed when the procedure returns.
|
|
347 |
*
|
|
348 |
* @param aMessage RMessage2 client request.
|
|
349 |
*/
|
|
350 |
void CShBufTestServerSession::DbgMarkHeapL(const RMessage2& aMessage)
|
|
351 |
{
|
|
352 |
TInt result;
|
|
353 |
|
|
354 |
result = Server().DbgMarkHeap();
|
|
355 |
|
|
356 |
//
|
|
357 |
// Complete the request...
|
|
358 |
//
|
|
359 |
CompleteRequest(aMessage, result);
|
|
360 |
} // CShBufTestServerSession::DbgMarkHeapL()
|
|
361 |
|
|
362 |
|
|
363 |
/**
|
|
364 |
* Requests the server to check that the number of allocated cells at the
|
|
365 |
* current nested level on the server's heap is the same as the specified value.
|
|
366 |
* This function only works for debug builds and is a synchronous request
|
|
367 |
* which will be completed when the procedure returns.
|
|
368 |
*
|
|
369 |
* @param aMessage RMessage2 client request.
|
|
370 |
*/
|
|
371 |
void CShBufTestServerSession::DbgCheckHeapL(const RMessage2& aMessage)
|
|
372 |
{
|
|
373 |
TInt count = aMessage.Int0();
|
|
374 |
TInt result;
|
|
375 |
|
|
376 |
result = Server().DbgCheckHeap(count);
|
|
377 |
|
|
378 |
//
|
|
379 |
// Complete the request...
|
|
380 |
//
|
|
381 |
CompleteRequest(aMessage, result);
|
|
382 |
} // CShBufTestServerSession::DbgCheckHeapL()
|
|
383 |
|
|
384 |
|
|
385 |
/**
|
|
386 |
* Requests the server to mark the end of checking the server's heap. This
|
|
387 |
* function must match an earlier call to DbgMarkHeap() and only functions
|
|
388 |
* on debug releases. This is a synchronous request which will be completed
|
|
389 |
* when the procedure returns.
|
|
390 |
*
|
|
391 |
* @param aMessage RMessage2 client request.
|
|
392 |
*/
|
|
393 |
void CShBufTestServerSession::DbgMarkEndL(const RMessage2& aMessage)
|
|
394 |
{
|
|
395 |
TInt count = aMessage.Int0();
|
|
396 |
TInt result;
|
|
397 |
|
|
398 |
result = Server().DbgMarkEnd(count);
|
|
399 |
|
|
400 |
//
|
|
401 |
// Complete the request...
|
|
402 |
//
|
|
403 |
CompleteRequest(aMessage, result);
|
|
404 |
} // CShBufTestServerSession::DbgMarkEndL()
|
|
405 |
|
|
406 |
|
|
407 |
/**
|
|
408 |
* Simulates heap allocation failure for the sever. The failure occurs on
|
|
409 |
* the next call to new or any of the functions which allocate memory from
|
|
410 |
* the heap. This is defined only for debug builds and is a synchronous
|
|
411 |
* request which will be completed when the procedure returns.
|
|
412 |
*
|
|
413 |
* @param aMessage RMessage2 client request.
|
|
414 |
*/
|
|
415 |
void CShBufTestServerSession::DbgFailNextL(const RMessage2& aMessage)
|
|
416 |
{
|
|
417 |
TInt count = aMessage.Int0();
|
|
418 |
TInt result;
|
|
419 |
|
|
420 |
result = Server().DbgFailNext(count);
|
|
421 |
|
|
422 |
//
|
|
423 |
// Complete the request...
|
|
424 |
//
|
|
425 |
CompleteRequest(aMessage, result);
|
|
426 |
} // CShBufTestServerSession::DbgFailNextL()
|
|
427 |
|
|
428 |
|
|
429 |
/**
|
|
430 |
* Requests the server to shut down when it no longer has any connected
|
|
431 |
* sessions. This procedure is only premitted in debug builds for security
|
|
432 |
* reasons (e.g. to prevent a denial of service attack) and is provided
|
|
433 |
* for testing purposes. This is a synchronous request which will be
|
|
434 |
* completed when the procedure returns. The server will shutdown when the
|
|
435 |
* last session disconnects.
|
|
436 |
*
|
|
437 |
* @param aMessage RMessage2 client request.
|
|
438 |
*/
|
|
439 |
void CShBufTestServerSession::ShutdownServerL(const RMessage2& aMessage)
|
|
440 |
{
|
|
441 |
TInt result = Server().ShutdownServer();
|
|
442 |
|
|
443 |
//
|
|
444 |
// Complete the request...
|
|
445 |
//
|
|
446 |
CompleteRequest(aMessage, result);
|
|
447 |
} // CShBufTestServerSession::ShutdownServerL()
|
|
448 |
|
|
449 |
|
|
450 |
/**
|
|
451 |
* Static factory method used to create a CShBufTestServer object.
|
|
452 |
*
|
|
453 |
* @return Pointer to the created CShBufTestServer object, or NULL.
|
|
454 |
*/
|
|
455 |
CShBufTestServer* CShBufTestServer::NewL()
|
|
456 |
{
|
|
457 |
CShBufTestServer* self = new (ELeave) CShBufTestServer();
|
|
458 |
CleanupStack::PushL(self);
|
|
459 |
self->ConstructL();
|
|
460 |
CleanupStack::Pop(self);
|
|
461 |
|
|
462 |
return self;
|
|
463 |
} // CShBufTestServer::NewL
|
|
464 |
|
|
465 |
|
|
466 |
/**
|
|
467 |
* Standard constructor.
|
|
468 |
*/
|
|
469 |
CShBufTestServer::CShBufTestServer()
|
|
470 |
: CServer2(EPriorityNormal),
|
|
471 |
iShouldShutdownServer(EFalse)
|
|
472 |
{
|
|
473 |
__DECLARE_NAME(_L("CShBufTestServer"));
|
|
474 |
} // CShBufTestServer::CShBufTestServer
|
|
475 |
|
|
476 |
|
|
477 |
/**
|
|
478 |
* Second phase constructor. Ensures the server is created and ready to run.
|
|
479 |
*/
|
|
480 |
void CShBufTestServer::ConstructL()
|
|
481 |
{
|
|
482 |
//
|
|
483 |
// Open the driver...
|
|
484 |
//
|
|
485 |
TInt ret;
|
|
486 |
|
|
487 |
ret = User::LoadLogicalDevice(_L("D_SHBUF_CLIENT.LDD"));
|
|
488 |
if (ret != KErrAlreadyExists)
|
|
489 |
{
|
|
490 |
User::LeaveIfError(ret);
|
|
491 |
}
|
|
492 |
|
|
493 |
ret = User::LoadLogicalDevice(_L("D_SHBUF_OWN.LDD"));
|
|
494 |
if (ret != KErrAlreadyExists)
|
|
495 |
{
|
|
496 |
User::LeaveIfError(ret);
|
|
497 |
}
|
|
498 |
|
|
499 |
User::LeaveIfError(iShBufLdd.Open(RShBufTestChannel::EClientThread));
|
|
500 |
|
|
501 |
StartL(KRShBufTestServerName);
|
|
502 |
} // CShBufTestServer::ConstructL
|
|
503 |
|
|
504 |
|
|
505 |
/**
|
|
506 |
* Destructor.
|
|
507 |
*/
|
|
508 |
CShBufTestServer::~CShBufTestServer()
|
|
509 |
{
|
|
510 |
iSessionArray.Reset();
|
|
511 |
iShBufLdd.Close();
|
|
512 |
} // CShBufTestServer::~CShBufTestServer
|
|
513 |
|
|
514 |
|
|
515 |
/**
|
|
516 |
* Create a new client session.
|
|
517 |
*/
|
|
518 |
CSession2* CShBufTestServer::NewSessionL(const TVersion&, const RMessage2& /*aMessage*/) const
|
|
519 |
{
|
|
520 |
return new(ELeave) CShBufTestServerSession();
|
|
521 |
} // CShBufTestServer::NewSessionL
|
|
522 |
|
|
523 |
|
|
524 |
/**
|
|
525 |
* Called by the session class when it is being created.
|
|
526 |
*
|
|
527 |
* @param aSession Server side session.
|
|
528 |
*/
|
|
529 |
void CShBufTestServer::AddSessionL(CShBufTestServerSession* aSession)
|
|
530 |
{
|
|
531 |
//
|
|
532 |
// Store this session in the list of sessions...
|
|
533 |
//
|
|
534 |
iSessionArray.Append(aSession);
|
|
535 |
} // CShBufTestServer::AddSessionL
|
|
536 |
|
|
537 |
|
|
538 |
/**
|
|
539 |
* Called by the session class when it is being destroyed.
|
|
540 |
*
|
|
541 |
* @param aSession Server side session.
|
|
542 |
*/
|
|
543 |
void CShBufTestServer::DropSession(CShBufTestServerSession* aSession)
|
|
544 |
{
|
|
545 |
//
|
|
546 |
// Remove this session from the session array list...
|
|
547 |
//
|
|
548 |
TInt position;
|
|
549 |
|
|
550 |
position = iSessionArray.Find(aSession);
|
|
551 |
if (position != KErrNotFound)
|
|
552 |
{
|
|
553 |
iSessionArray.Remove(position);
|
|
554 |
}
|
|
555 |
|
|
556 |
//
|
|
557 |
// If we are shuting down then unconfigure and stop...
|
|
558 |
//
|
|
559 |
if (iSessionArray.Count() == 0 && iShouldShutdownServer)
|
|
560 |
{
|
|
561 |
CActiveScheduler::Stop();
|
|
562 |
}
|
|
563 |
} // CShBufTestServer::DropSession
|
|
564 |
|
|
565 |
|
|
566 |
TInt CShBufTestServer::FromTPtr8ProcessAndReturn(TDes8& aBuf, TUint aBufSize)
|
|
567 |
{
|
|
568 |
// clear cache
|
|
569 |
memset(iClearCache, 0xFF, sizeof(iClearCache));
|
|
570 |
|
|
571 |
return iShBufLdd.FromTPtr8ProcessAndReturn(aBuf, aBufSize);
|
|
572 |
} // CShBufTestServer::FromTPtr8ProcessAndReturn
|
|
573 |
|
|
574 |
|
|
575 |
TInt CShBufTestServer::FromTPtr8ProcessAndRelease(TDes8& aBuf)
|
|
576 |
{
|
|
577 |
return iShBufLdd.FromTPtr8ProcessAndRelease(aBuf);
|
|
578 |
} // CShBufTestServer::FromTPtr8ProcessAndRelease
|
|
579 |
|
|
580 |
|
|
581 |
TInt CShBufTestServer::OpenRShBufPool(TInt aHandle, const TShPoolInfo& aPoolInfo)
|
|
582 |
{
|
|
583 |
return iShBufLdd.OpenUserPool(aHandle, aPoolInfo);
|
|
584 |
} // CShBufTestServer::OpenRShBufPool
|
|
585 |
|
|
586 |
|
|
587 |
TInt CShBufTestServer::CloseRShBufPool()
|
|
588 |
{
|
|
589 |
return iShBufLdd.CloseUserPool();
|
|
590 |
} // CShBufTestServer::CloseRShBufPool
|
|
591 |
|
|
592 |
|
|
593 |
TInt CShBufTestServer::FromRShBufProcessAndReturn(RShBuf& aShBuf, TUint aBufSize)
|
|
594 |
{
|
|
595 |
TInt ret;
|
|
596 |
|
|
597 |
// clear cache
|
|
598 |
memset(iClearCache, 0xFF, sizeof(iClearCache));
|
|
599 |
|
|
600 |
ret = iShBufLdd.FromRShBufProcessAndReturn(aBufSize);
|
|
601 |
|
|
602 |
if (ret > 0)
|
|
603 |
{
|
|
604 |
aShBuf.SetReturnedHandle(ret);
|
|
605 |
return KErrNone;
|
|
606 |
}
|
|
607 |
|
|
608 |
return ret;
|
|
609 |
} // CShBufTestServer::FromRShBufProcessAndReturn
|
|
610 |
|
|
611 |
|
|
612 |
TInt CShBufTestServer::FromRShBufProcessAndRelease(RShBuf& aShBuf)
|
|
613 |
{
|
|
614 |
return iShBufLdd.FromRShBufProcessAndRelease(aShBuf.Handle());
|
|
615 |
} // CShBufTestServer::FromRShBufProcessAndRelease
|
|
616 |
|
|
617 |
|
|
618 |
/**
|
|
619 |
* Marks the start of checking the server's heap. This function only works
|
|
620 |
* in debug releases.
|
|
621 |
*
|
|
622 |
* Calls to this function can be nested but each call must be matched by
|
|
623 |
* corresponding DbgMarkEnd().
|
|
624 |
*
|
|
625 |
* @return KErrNone.
|
|
626 |
*/
|
|
627 |
TInt CShBufTestServer::DbgMarkHeap() const
|
|
628 |
{
|
|
629 |
#ifdef _DEBUG
|
|
630 |
__UHEAP_MARK;
|
|
631 |
#endif
|
|
632 |
|
|
633 |
return(KErrNone);
|
|
634 |
} // CShBufTestServer::DbgMarkHeap
|
|
635 |
|
|
636 |
|
|
637 |
/**
|
|
638 |
* Checks that the number of allocated cells at the current nested level on
|
|
639 |
* the server's heap is the same as the specified value. This function only
|
|
640 |
* works for debug builds.
|
|
641 |
*
|
|
642 |
* @param aCount The number of heap cells expected to be allocated at
|
|
643 |
* the current nest level.
|
|
644 |
*
|
|
645 |
* @return KErrNone.
|
|
646 |
*/
|
|
647 |
TInt CShBufTestServer::DbgCheckHeap(TInt aCount) const
|
|
648 |
{
|
|
649 |
#ifdef _DEBUG
|
|
650 |
__UHEAP_CHECK(aCount);
|
|
651 |
#else
|
|
652 |
(void) aCount;
|
|
653 |
#endif
|
|
654 |
|
|
655 |
return(KErrNone);
|
|
656 |
} // CShBufTestServer::DbgCheckHeap
|
|
657 |
|
|
658 |
|
|
659 |
/**
|
|
660 |
* Marks the end of checking the current server's heap.
|
|
661 |
*
|
|
662 |
* The function expects aCount heap cells to remain allocated at the
|
|
663 |
* current nest level. This function must match an earlier call to
|
|
664 |
* DbgMarkHeap() and only functions on debug releases.
|
|
665 |
*
|
|
666 |
* @param aCount The number of heap cells expected to remain allocated
|
|
667 |
* at the current nest level.
|
|
668 |
*
|
|
669 |
* @return KErrNone.
|
|
670 |
*/
|
|
671 |
TInt CShBufTestServer::DbgMarkEnd(TInt aCount) const
|
|
672 |
{
|
|
673 |
#ifdef _DEBUG
|
|
674 |
__UHEAP_MARKENDC(aCount);
|
|
675 |
#else
|
|
676 |
(void) aCount;
|
|
677 |
#endif
|
|
678 |
|
|
679 |
return(KErrNone);
|
|
680 |
} // CShBufTestServer::DbgMarkEnd
|
|
681 |
|
|
682 |
|
|
683 |
/**
|
|
684 |
* Simulates heap allocation failure for the server.
|
|
685 |
*
|
|
686 |
* The failure occurs on the next call to new or any of the functions which
|
|
687 |
* allocate memory from the heap. This is defined only for debug builds.
|
|
688 |
*
|
|
689 |
* @param aCount Determines when the allocation will fail.
|
|
690 |
*
|
|
691 |
* @return KErrNone.
|
|
692 |
*/
|
|
693 |
TInt CShBufTestServer::DbgFailNext(TInt aCount) const
|
|
694 |
{
|
|
695 |
#ifdef _DEBUG
|
|
696 |
if (aCount == 0)
|
|
697 |
{
|
|
698 |
__UHEAP_RESET;
|
|
699 |
}
|
|
700 |
else
|
|
701 |
{
|
|
702 |
__UHEAP_FAILNEXT(aCount);
|
|
703 |
}
|
|
704 |
#else
|
|
705 |
(void) aCount;
|
|
706 |
#endif
|
|
707 |
|
|
708 |
return(KErrNone);
|
|
709 |
} // CShBufTestServer::DbgFailNext
|
|
710 |
|
|
711 |
|
|
712 |
/**
|
|
713 |
* Requests the server to shut down when it no longer has any connected
|
|
714 |
* sessions. This procedure is only premitted in debug builds and is provided
|
|
715 |
* for testing purposes.
|
|
716 |
*
|
|
717 |
* The server will shutdown when the last session disconnects.
|
|
718 |
*
|
|
719 |
* @return KErrNone if the shutdown request was accepted, otherwise returns
|
|
720 |
* an error.
|
|
721 |
*/
|
|
722 |
TInt CShBufTestServer::ShutdownServer()
|
|
723 |
{
|
|
724 |
iShouldShutdownServer = ETrue;
|
|
725 |
|
|
726 |
return(KErrNone);
|
|
727 |
} // CShBufTestServer::ShutdownServer
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
/**
|
|
732 |
* Standard Active Object RunError() method, called when the RunL() method
|
|
733 |
* leaves, which will be when the CShBufTestServerSession::ServiceL() leaves.
|
|
734 |
*
|
|
735 |
* Find the current message and complete it before restarting the server.
|
|
736 |
*
|
|
737 |
* @param aError Leave code from CShBufTestServerSession::ServiceL().
|
|
738 |
*
|
|
739 |
* @return KErrNone
|
|
740 |
*/
|
|
741 |
TInt CShBufTestServer::RunError(TInt aError)
|
|
742 |
{
|
|
743 |
//
|
|
744 |
// Complete the request with the available error code.
|
|
745 |
//
|
|
746 |
if (Message().IsNull() == EFalse)
|
|
747 |
{
|
|
748 |
Message().Complete(aError);
|
|
749 |
}
|
|
750 |
|
|
751 |
//
|
|
752 |
// The leave will result in an early return from CServer::RunL(), skipping
|
|
753 |
// the call to request another message. So do that now in order to keep the
|
|
754 |
// server running.
|
|
755 |
//
|
|
756 |
ReStart();
|
|
757 |
|
|
758 |
return KErrNone;
|
|
759 |
} // CShBufTestServer::RunError
|
|
760 |
|
|
761 |
|
|
762 |
/**
|
|
763 |
* Perform all server initialisation, in particular creation of the
|
|
764 |
* scheduler and server and then run the scheduler.
|
|
765 |
*/
|
|
766 |
static void RunServerL()
|
|
767 |
{
|
|
768 |
//
|
|
769 |
// Naming the server thread after the server helps to debug panics.
|
|
770 |
//
|
|
771 |
User::LeaveIfError(User::RenameThread(KRShBufTestServerName));
|
|
772 |
|
|
773 |
//
|
|
774 |
// Increase priority so that requests are handled promptly...
|
|
775 |
//
|
|
776 |
RThread().SetPriority(EPriorityMuchMore);
|
|
777 |
|
|
778 |
//
|
|
779 |
// Create a new Active Scheduler...
|
|
780 |
//
|
|
781 |
CActiveScheduler* scheduler = new CActiveScheduler();
|
|
782 |
CleanupStack::PushL(scheduler);
|
|
783 |
CActiveScheduler::Install(scheduler);
|
|
784 |
|
|
785 |
//
|
|
786 |
// Create a new PhoneBookServer...
|
|
787 |
//
|
|
788 |
CShBufTestServer* server = CShBufTestServer::NewL();
|
|
789 |
CleanupStack::PushL(server);
|
|
790 |
|
|
791 |
//
|
|
792 |
// Initialisation complete, now signal the client thread...
|
|
793 |
//
|
|
794 |
#ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
|
|
795 |
RProcess::Rendezvous(KErrNone);
|
|
796 |
#else
|
|
797 |
RThread::Rendezvous(KErrNone);
|
|
798 |
#endif
|
|
799 |
|
|
800 |
//
|
|
801 |
// Run the server...
|
|
802 |
//
|
|
803 |
CActiveScheduler::Start();
|
|
804 |
|
|
805 |
CleanupStack::PopAndDestroy(2, scheduler);
|
|
806 |
} // RunServerL
|
|
807 |
|
|
808 |
|
|
809 |
/**
|
|
810 |
* Server process entry-point.
|
|
811 |
*
|
|
812 |
* @return KErrNone or a standard Symbian error code.
|
|
813 |
*/
|
|
814 |
#ifdef CAN_TRANSFER_SHBUF_TO_ANOTHER_PROCESS
|
|
815 |
TInt E32Main()
|
|
816 |
#else
|
|
817 |
TInt RShBufTestServerThread(TAny* /*aPtr*/)
|
|
818 |
#endif
|
|
819 |
{
|
|
820 |
__UHEAP_MARK;
|
|
821 |
|
|
822 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
|
823 |
TInt ret(KErrNoMemory);
|
|
824 |
|
|
825 |
if (cleanup)
|
|
826 |
{
|
|
827 |
TRAP(ret, RunServerL());
|
|
828 |
delete cleanup;
|
|
829 |
}
|
|
830 |
|
|
831 |
__UHEAP_MARKEND;
|
|
832 |
|
|
833 |
return ret;
|
|
834 |
} // E32Main
|
|
835 |
|
|
836 |
|
|
837 |
|