multimediacommsengine/tsrc/testdriver/testclient/watcher/src/CTcAppLauncher.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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 "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:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <apgcli.h>
       
    19 #include <apacmdln.h>
       
    20 #include <w32std.h>
       
    21 
       
    22 #include "CTcAppLauncher.h"
       
    23 #include "WatcherConstants.h"
       
    24 
       
    25 #include "debuglog.h"
       
    26 
       
    27 CTcAppLauncher* CTcAppLauncher::NewLC( const TDesC& aAppName,
       
    28 									   TBool aDismissDialog,
       
    29 									   CArrayPtr< CTcAppLauncher >& aOwner )
       
    30 	{
       
    31 	CTcAppLauncher* self = new( ELeave ) CTcAppLauncher( aAppName,
       
    32 														 aDismissDialog,
       
    33 														 aOwner );
       
    34 
       
    35 	CleanupStack::PushL( self );
       
    36 	self->ConstructL();
       
    37 
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 CTcAppLauncher::~CTcAppLauncher()
       
    42 	{
       
    43 	Cancel();
       
    44 	iTimer.Close();
       
    45 	TInt count = iOwner.Count();
       
    46 	for( TInt i = 0; i < count; i++ )
       
    47 		{
       
    48 		if( iOwner[ i ] == this )
       
    49 			{
       
    50 			iOwner.Delete( i );
       
    51 			break;
       
    52 			}
       
    53 		}
       
    54 	}
       
    55 
       
    56 CTcAppLauncher::CTcAppLauncher( const TDesC& aAppName,
       
    57 								TBool aDismissDialog,
       
    58 								CArrayPtr< CTcAppLauncher >& aOwner )
       
    59 	: CActive( EPriorityHigh ),
       
    60 	  iAppName( aAppName ),
       
    61 	  iOwner( aOwner ),
       
    62 	  iDismissDialog( aDismissDialog )
       
    63 	{
       
    64 	CActiveScheduler::Add( this );
       
    65 	}
       
    66 
       
    67 void CTcAppLauncher::ConstructL()
       
    68 	{
       
    69 	// Create and start timer
       
    70 	User::LeaveIfError( iTimer.CreateLocal() );
       
    71 	iTimer.After( iStatus, KSecondAsMicroseconds );
       
    72 	SetActive();
       
    73 	}
       
    74 
       
    75 void CTcAppLauncher::DoCancel()
       
    76 	{
       
    77 	iTimer.Cancel();
       
    78 	}
       
    79 
       
    80 void CTcAppLauncher::RunL()
       
    81 	{
       
    82 	// Fatal error occurred, report
       
    83 	User::LeaveIfError( iStatus.Int() );
       
    84 
       
    85 	if( iDismissDialog )
       
    86 		{
       
    87 		TKeyEvent event;
       
    88 		event.iCode = EKeyDevice3;
       
    89 		RWsSession wsSession;
       
    90 		User::LeaveIfError( wsSession.Connect() );
       
    91 		wsSession.SimulateKeyEvent( event );
       
    92 		wsSession.Close();
       
    93 		}
       
    94 
       
    95 	RApaLsSession apparc;
       
    96 	User::LeaveIfError( apparc.Connect() );
       
    97 	CleanupClosePushL( apparc );
       
    98 
       
    99 	CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
       
   100 	cmdLine->SetExecutableNameL( iAppName );
       
   101 	cmdLine->SetCommandL( EApaCommandRun );
       
   102 
       
   103 	User::LeaveIfError( apparc.StartApp( *cmdLine ) );
       
   104 	CleanupStack::PopAndDestroy( 2 );
       
   105 
       
   106 	// Write log entry
       
   107 	LOG( _L("[APPLAUNCHER] Client restarted.") );
       
   108 	delete this;
       
   109 	}
       
   110