installationservices/swi/test/tsishelper/tsishelperstepbase.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file tsishelperstep.cpp
       
    21 */
       
    22 #include "tsishelperstep.h"
       
    23 #include <test/testexecutelog.h>
       
    24 #include <e32math.h>
       
    25 #include "sishelperclient.h"
       
    26 #include "sishelper.h"
       
    27 #include "swi/launcher.h"
       
    28 
       
    29 CTSISHelperStepBase::CTSISHelperStepBase()
       
    30 	{
       
    31 	}
       
    32 
       
    33 TVerdict CTSISHelperStepBase::doTestStepPreambleL()
       
    34 	{
       
    35 	User::LeaveIfError(iFs.Connect());
       
    36 	SetTestStepResult(EPass);
       
    37 	return TestStepResult();
       
    38 	}
       
    39 	
       
    40 TVerdict CTSISHelperStepBase::doTestStepPostambleL()
       
    41 	{
       
    42 	iFs.Close();
       
    43 	return TestStepResult();
       
    44 	}
       
    45 
       
    46 TInt CTSISHelperStepBase::startSisHelper(Swi::TSisHelperStartParams& aParams)
       
    47 	{
       
    48 	// To deal with the unique thread (+semaphore!) naming in Symbian OS, and
       
    49 	// that we may be trying to restart a server that has just exited we 
       
    50 	// attempt to create a unique thread name for the server
       
    51 	TName name(Swi::KSisHelperServerName);
       
    52 	name.AppendNum(Math::Random(), EHex);
       
    53 	RThread server;
       
    54 	const TInt KSisHelperServerStackSize=0x2000;
       
    55 	const TInt KSisHelperServerInitHeapSize=0x1000;
       
    56 	const TInt KSisHelperServerMaxHeapSize=0x1000000;
       
    57 	TInt err=server.Create(name, sisHelperThreadFunction, 
       
    58 		KSisHelperServerStackSize, KSisHelperServerInitHeapSize, 
       
    59 		KSisHelperServerMaxHeapSize, static_cast<TAny*>(&aParams), 
       
    60 		EOwnerProcess);
       
    61 	if (err!=KErrNone)
       
    62 		return err;
       
    63 	
       
    64 	// The following code is the same whether the server runs in a new thread 
       
    65 	// or process
       
    66 	TRequestStatus stat;
       
    67 	server.Rendezvous(stat);
       
    68 	if (stat!=KRequestPending)
       
    69 		server.Kill(0); // abort startup
       
    70 	else
       
    71 		server.Resume(); // logon OK, start the server
       
    72 	User::WaitForRequest(stat); // wait for start or death
       
    73 	
       
    74 	// we can't use the 'exit reason' if the server panicked as this is the 
       
    75 	// panic 'reason' and may be 0 which cannot be distinguished from KErrNone
       
    76 	err=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    77 	server.Close();
       
    78 	return err;
       
    79 	}
       
    80 
       
    81 TInt CTSISHelperStepBase::sisHelperThreadFunction(TAny *aPtr)
       
    82 	{
       
    83 	if (aPtr==NULL)
       
    84 		{
       
    85 		return KErrArgument;
       
    86 		}
       
    87 		
       
    88 	__UHEAP_MARK;
       
    89 	CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
       
    90 	
       
    91 	Swi::TSisHelperStartParams* params=
       
    92 		static_cast<Swi::TSisHelperStartParams*>(aPtr);
       
    93 
       
    94 	CActiveScheduler* scheduler=new CActiveScheduler;
       
    95 
       
    96 	CActiveScheduler::Install(scheduler);
       
    97 	Swi::CSisHelperServer* server=NULL;
       
    98 	
       
    99 	TRAPD(err, server=Swi::CSisHelperServer::NewL(*params));
       
   100 
       
   101 	if (err==KErrNone)
       
   102 		{
       
   103 		// only continue launching the server if no error
       
   104 		RThread::Rendezvous(KErrNone);
       
   105 		scheduler->Start();
       
   106 		CActiveScheduler::Install(NULL);
       
   107 		}
       
   108 
       
   109 	delete server;
       
   110 	delete scheduler;
       
   111 	delete cleanup; // destroy clean-up stack
       
   112 	__UHEAP_MARKEND;
       
   113 
       
   114 	return err;
       
   115 	}