sysstatemgmt/systemstarter/src/appstarter2.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2005-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 #include <f32file.h>
       
    18 #include <startupproperties.h>
       
    19 
       
    20 #include "appstarter2.h"
       
    21 #include <startup.hrh>
       
    22 #include "startuputilprovider.h"
       
    23 
       
    24 #include "SysStartDebug.h"
       
    25 #include "sysstartpanic.h"
       
    26 
       
    27 
       
    28 //
       
    29 // Standard Symbian factory functions
       
    30 //
       
    31 
       
    32 CAppStarter* CAppStarter::NewL(CStartupProperties* aAppInfo, CStartupUtilProvider& aProvider)
       
    33 	{
       
    34 	CAppStarter* self = CAppStarter::NewLC(aAppInfo, aProvider);
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 CAppStarter* CAppStarter::NewLC(CStartupProperties* aAppInfo, CStartupUtilProvider& aProvider)
       
    40 	{
       
    41 	__ASSERT_ALWAYS(aAppInfo != NULL, PanicNow(KPanicAppStart, ENULLPropertiesPassed));
       
    42 
       
    43 	CAppStarter* self = new (ELeave) CAppStarter(aAppInfo, aProvider);
       
    44 	CleanupStack::PushL(self);
       
    45 	return self;
       
    46 	}
       
    47 	
       
    48 CAppStarter::~CAppStarter()
       
    49 	{
       
    50 	delete iAppInfo;
       
    51 	iProcess.Close();
       
    52 	}
       
    53 	
       
    54 CAppStarter::CAppStarter(CStartupProperties* aAppInfo, CStartupUtilProvider& aProvider) 
       
    55 	:iProvider(aProvider), iAppInfo(aAppInfo) 
       
    56 	{
       
    57 	}
       
    58 	 	
       
    59 //
       
    60 // Public member functions
       
    61 //
       
    62 
       
    63 /** Implementation of MStartupCommand interface.
       
    64 
       
    65 @see MStartupCommand.
       
    66 */
       
    67 void CAppStarter::Execute(TRequestStatus& aCallerStatus)
       
    68 	{
       
    69 	aCallerStatus = KRequestPending;
       
    70 
       
    71 	TPtrC appFileName = iAppInfo->FileName();
       
    72 	TPtrC args = iAppInfo->Args();
       
    73 	TParsePtrC parser(iAppInfo->FileName());
       
    74 
       
    75 	DEBUGPRINT3(_L("SysStart: starting %S %S"), &appFileName, &args);
       
    76 
       
    77 	TInt err = KErrNone;		
       
    78 
       
    79 	TInt tried=0;
       
    80 		
       
    81 	if (iAppInfo->StartMethod() == EDeferredWaitForStart)
       
    82 		{
       
    83 		// Start process asynchronously, iCommandStatus will be checked at MultipleWait
       
    84 		// and monitoring will commence afterwards if required
       
    85 		TRAP(err, iProvider.StartSafe().StartL(*iAppInfo, iProcess, iCommandStatus));
       
    86 		DEBUGPRINT2(_L("SysStart: Attempted %S with StartMethod()==EDeferredWaitForStart"), &appFileName);
       
    87 		}		
       
    88 	else
       
    89 		{
       
    90 		// Start process synchronously for EWaitForStart and EFireAndForget case
       
    91 		TRAP(err, iProvider.StartSafe().StartL(*iAppInfo, iProcess, tried));
       
    92 		DEBUGPRINT4(_L("SysStart: Attempted %S %d times, result: %d"), &appFileName, (tried + 1), err);
       
    93 		
       
    94 		// Start monitor if required
       
    95 		if (KErrNone == err && iAppInfo->Monitored())
       
    96 			{
       
    97 			const TBool KEvenIfAlreadyDead = ETrue;
       
    98 			TRAP(err, iProvider.SysMonSessionL().MonitorL(*iAppInfo, iProcess, KEvenIfAlreadyDead));			
       
    99 			DEBUGPRINT3(_L("SysStart: Attempted to monitor %S, result: %d "), &appFileName, err);
       
   100 			}
       
   101 		}		
       
   102  	
       
   103 	TRequestStatus* callerStatus = &aCallerStatus;
       
   104 	User::RequestComplete(callerStatus, err);
       
   105 	}
       
   106 
       
   107 CStartupProperties& CAppStarter::AppInfo()
       
   108 	{
       
   109 	return *iAppInfo;
       
   110 	}
       
   111 
       
   112 RProcess& CAppStarter::Process()
       
   113 	{
       
   114 	return iProcess;
       
   115 	}
       
   116 
       
   117 TRequestStatus& CAppStarter::CommandStatus()
       
   118 	{
       
   119 	return iCommandStatus;
       
   120 	}
       
   121 
       
   122 void CAppStarter::Release() 
       
   123 	{
       
   124 	delete this;
       
   125 	}