lbs/internal/lbstestserver/src/cprocesslaunch.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // processlaunch.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include "cprocesslaunch.h"
       
    20 
       
    21 //----------------------------------------------------------------------------	
       
    22 
       
    23 /** called by the launcher! Launch the process by specified parameters
       
    24 find the process and launch it
       
    25 
       
    26 @param aParams A reference to TProcessStartParams object
       
    27 @return Symbian error code
       
    28 @see TProcessStartParams
       
    29 @internalTechnology
       
    30 @released
       
    31  */
       
    32 TInt CProcessLaunch::ProcessLaunch(TProcessStartParams& aParams)
       
    33 // now prevents multiple instances of the same image being launched!
       
    34 // So P&S servers now look like realCServer2 servers.
       
    35 	{
       
    36 	TFullName fullName;
       
    37 	_LIT(KStar, "*");
       
    38 	TParse parser;
       
    39 	parser.SetNoWild(aParams.GetProcessFileName(), NULL, NULL);
       
    40 	fullName.Append(parser.NameAndExt());
       
    41 	fullName.Append(KStar);
       
    42 	
       
    43 	TFindProcess processFinder(fullName);
       
    44 	TInt err = KErrNotFound;
       
    45 	while (err = processFinder.Next(fullName), err == KErrNone)
       
    46 		{
       
    47 		RProcess process;
       
    48 		TInt processOpenErr = process.Open(processFinder);
       
    49 		if (processOpenErr == KErrNone)
       
    50 			{
       
    51 			TExitType exitType = process.ExitType();
       
    52 			if (exitType == EExitPending)
       
    53 				{
       
    54 				// Found a running instance of the process,
       
    55 				// so return without starting another instance.
       
    56 				process.Close();
       
    57 				return KErrNone;
       
    58 				}
       
    59 			}
       
    60 			process.Close();		
       
    61 		}
       
    62 	
       
    63 	// No running instance found, so start one.
       
    64 	return (DoProcessLaunch(aParams));
       
    65 	}
       
    66 
       
    67 /** Create the process by specified parameters and wait for the request
       
    68 
       
    69 @param aParams A reference to TProcessStartParams object
       
    70 @return Symbian error code
       
    71 @see TProcessStartParams
       
    72 @internalTechnology
       
    73 @released
       
    74  */
       
    75 TInt CProcessLaunch::DoProcessLaunch(TProcessStartParams& aParams)
       
    76 	{
       
    77 	RProcess process;
       
    78  	
       
    79  	TInt r=process.Create(aParams.GetProcessFileName(),aParams.GetAsCommandLine());
       
    80 	if (r!=KErrNone)
       
    81 		{
       
    82 		return r;
       
    83 		}
       
    84 	// are we expecing to rendezvous with the process we have created above
       
    85 	if(aParams.GetRendezvousRequired())
       
    86 		{
       
    87 		TRequestStatus stat;
       
    88 		process.Rendezvous(stat);
       
    89 		if (stat!=KRequestPending)
       
    90 			{
       
    91 			process.Kill(0);
       
    92 			}
       
    93 		else
       
    94 			{
       
    95 			process.Resume();
       
    96 			}
       
    97 		User::WaitForRequest(stat);
       
    98 		r=(process.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    99 		}
       
   100 	process.Close();
       
   101 	return r;
       
   102 	}