sysstatemgmt/systemstatemgr/test/tssm/src/tssm_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 
       
    23 #include "ssmserver.h"
       
    24 #include "ssmdebug.h"
       
    25 
       
    26 #include "tssm_ssmclient.h"
       
    27 #include "tssm_statepolicy_simple.h"
       
    28 
       
    29 #include "tssm_startserver.h"
       
    30 
       
    31 
       
    32 
       
    33 //
       
    34 // Test-Server startup code
       
    35 //
       
    36 
       
    37 void RunTestSrvL()
       
    38 	{
       
    39 	CActiveScheduler* sched = new(ELeave) CActiveScheduler();
       
    40     CleanupStack::PushL( sched );
       
    41     CActiveScheduler::Install( sched );
       
    42 
       
    43     CSsmServer* server = CSsmServer::NewLC(KSsmServerNameTest, ESsmTestSimpleState);
       
    44     
       
    45     // Don't need to be critical during test-step, better to just log errors.
       
    46     User::SetCritical(User::ENotCritical);
       
    47     
       
    48     RThread::Rendezvous( KErrNone );
       
    49     
       
    50     CActiveScheduler::Start();
       
    51 
       
    52     CleanupStack::PopAndDestroy( server );
       
    53     CleanupStack::PopAndDestroy( sched );
       
    54 	}
       
    55 
       
    56 /**
       
    57  This function is called when the TestServer's thread is resumed.
       
    58  */
       
    59 TInt TestSrvInitFunction( TAny* /*aNothing*/ )
       
    60 	{
       
    61     CTrapCleanup* cleanup=CTrapCleanup::New();
       
    62 	TInt err = KErrNoMemory;
       
    63 	if (cleanup)
       
    64 		{
       
    65 	    TRAP( err, RunTestSrvL());
       
    66 	    delete cleanup;
       
    67 		}
       
    68     return err;
       
    69 	}
       
    70 
       
    71 /**
       
    72  */
       
    73 TInt StartServer(RThread& aServer)
       
    74 	{
       
    75 	DEBUGPRINT2( _L("Starting test-server %S"), &KSsmServerNameTest );
       
    76 	
       
    77 	const TInt KMinHeapSize =  0x1000; // 4kB
       
    78 	const TInt KMaxHeapSize = 0x100000;// 1MB
       
    79 	TInt err = aServer.Create( KSsmServerNameTest, &TestSrvInitFunction, 
       
    80 								 KDefaultStackSize, KMinHeapSize, KMaxHeapSize, 
       
    81 								 NULL); //NULL is the argument to TestSrvInitFunction
       
    82 	if( KErrNone == err )
       
    83 		{
       
    84 		TRequestStatus trs;
       
    85 		aServer.Rendezvous( trs );
       
    86 		aServer.Resume();
       
    87 		
       
    88 		User::WaitForRequest( trs );	
       
    89 		
       
    90 		//We can't use the 'exit reason' if the server panicked as this is the 
       
    91 		//panic 'reason' and may be '0' which cannot be distinguished from KErrNone
       
    92 		err = (aServer.ExitType()==EExitPanic) ? KErrGeneral : trs.Int();
       
    93 		}
       
    94 
       
    95 	return err;
       
    96 	}
       
    97 
       
    98