lbs/internal/lbstestserver/src/cserverlaunch.cpp
author Maciej Seroka <maciejs@symbian.org>
Thu, 21 Jan 2010 12:53:44 +0000
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
permissions -rw-r--r--
Added Symbian2 smoketests from FBF at changeset bde28f2b1d99

// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of the License "Symbian Foundation License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// serverlaunch.cpp
// 
//

#include "cserverlaunch.h"
#include "tserverstartparams.h"

/** Launch the server by specified parameters
find the process and launch it

@param aParams A reference to TProcessStartParams object
@return Symbian error code
@see TProcessStartParams
@internalTechnology
@released
 */
TInt CServerLaunch::ServerLaunch(TServerStartParams& aParams)
	{
	TFindServer serverSearcher(aParams.GetServerName());
	TFileName matchingFileName;
	TInt error = serverSearcher.Next(matchingFileName); // we haev asked for a exact match, so the retunred filename can be ignored
	if(error==KErrNone)
		{
		return KErrNone; // found it, so some other kind process has just started the server for us
		}
	else
		{
		error = CreateServerProcess(aParams);		
		}
	return error;
	}

/** create server process by specified parameters
signal the clients and start the process, wait for any request.

@param aParams A reference to TProcessStartParams object
@return Symbian error code
@see TProcessStartParams
@internalTechnology
@released
 */
TInt CServerLaunch::CreateServerProcess(TServerStartParams& aParams)
	{
	RProcess server;
 	
 	TInt r=server.Create(aParams.GetServerFileName(),aParams.GetAsCommandLine());
	if (r!=KErrNone)
		return r;
	TRequestStatus stat;
	server.Rendezvous(stat);
	if (stat!=KRequestPending)
		{
		server.Kill(0);
		}
	else
		{
		server.Resume();
		}
	User::WaitForRequest(stat);
	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
	server.Close();
	return r;
	}