sysstatemgmt/systemstatemgr/test/tsus/src/tsus_startserver.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 "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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "tsus_startserver.h"
       
    24 #include "susutilserver.h"
       
    25 #include "ssmdebug.h"
       
    26 
       
    27 
       
    28 
       
    29 //
       
    30 // Test-Server startup code
       
    31 //
       
    32 
       
    33 void RunTestSrvL(TSecureId aSid)
       
    34 	{
       
    35 	__UHEAP_MARK;
       
    36 	CActiveScheduler* sched = new(ELeave) CActiveScheduler();
       
    37     CleanupStack::PushL( sched );
       
    38     CActiveScheduler::Install( sched );
       
    39 
       
    40     CSusUtilServer* server = CSusUtilServer::NewLC(KTestServerName, aSid);
       
    41     RThread::Rendezvous( KErrNone );
       
    42     
       
    43     CActiveScheduler::Start();
       
    44 
       
    45     CleanupStack::PopAndDestroy( server );
       
    46     CleanupStack::PopAndDestroy( sched );
       
    47     __UHEAP_MARKEND;
       
    48 	} //lint !e1746 Suppress parameter 'aSid' could be made const reference
       
    49 
       
    50 /**
       
    51  This function is called when the TestServer's thread is resumed.
       
    52  */
       
    53 TInt TestSrvInitFunction( TAny* aSecureId )
       
    54 	{
       
    55     CTrapCleanup* cleanup=CTrapCleanup::New();
       
    56 	TInt err = KErrNoMemory;
       
    57 	if (cleanup)
       
    58 		{
       
    59 	    TRAP( err, RunTestSrvL((TUint32)aSecureId));
       
    60 	    delete cleanup;
       
    61 		}
       
    62     return err;
       
    63 	}
       
    64 
       
    65 /**
       
    66  */
       
    67 TInt StartServer(RThread& aServer, TUint32 aClientSecureId)
       
    68 	{
       
    69 	DEBUGPRINT2( _L("Starting test-server %S"), &KTestServerName );
       
    70 	
       
    71 	const TInt KMinHeapSize =  0x1000; // 4kB
       
    72 	const TInt KMaxHeapSize = 0x100000;// 1MB
       
    73 	TInt err = aServer.Create( KTestServerName, &TestSrvInitFunction, 
       
    74 								 KDefaultStackSize, KMinHeapSize, KMaxHeapSize, 
       
    75 								 (TAny*)aClientSecureId); //the secureid of the only process allowed to connect
       
    76 	if( KErrNone == err )
       
    77 		{
       
    78 		TRequestStatus trs;
       
    79 		aServer.Rendezvous( trs );
       
    80 		aServer.Resume();
       
    81 		
       
    82 		User::WaitForRequest( trs );	
       
    83 		
       
    84 		//We can't use the 'exit reason' if the server panicked as this is the 
       
    85 		//panic 'reason' and may be '0' which cannot be distinguished from KErrNone
       
    86 		err = (aServer.ExitType()==EExitPanic) ? KErrGeneral : trs.Int();
       
    87 		}
       
    88 
       
    89 	return err;
       
    90 	}