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