sysstatemgmt/systemstatemgr/test/tss/src/testandstopper.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 #include "testandstopper.h"
       
    17 
       
    18 
       
    19 
       
    20 void CTestAndStopper::RunL()
       
    21 	{
       
    22 	if( !iRunning )
       
    23 		{
       
    24 		iRunning = ETrue;	
       
    25 		DoStartsL();	
       
    26 		SetActive();
       
    27 		
       
    28 		TRequestStatus* trs = &iStatus;
       
    29 		User::RequestComplete( trs, KErrNone );
       
    30 		}
       
    31 	else if( !iFinish )
       
    32 		{
       
    33 		iFinish = ETrue;
       
    34 		SetActive();
       
    35 		
       
    36 		iTimer.After( iStatus, iTimeout );
       
    37 		}
       
    38 	else
       
    39 		{
       
    40 		CActiveScheduler::Stop();
       
    41 		}
       
    42 	
       
    43 	}
       
    44 
       
    45 
       
    46 void CTestAndStopper::DoStartsL()
       
    47 	{
       
    48 
       
    49 	if( iStartupProperties.IsMonitoringRequired() )
       
    50 		{
       
    51 		iSsmStartSafe.StartAndMonitorL( iStartupProperties, iProcess );
       
    52 		}
       
    53 	else
       
    54 		{
       
    55 		iSsmStartSafe.StartL( iStartupProperties, iProcess );
       
    56 		}	
       
    57 	
       
    58 	}
       
    59 
       
    60 
       
    61 
       
    62 
       
    63 TInt CTestAndStopper::RunError( TInt aError )
       
    64 	{
       
    65 	if( iSsTestAsyncNotifier )
       
    66 		{
       
    67 		iSsTestAsyncNotifier->SsTestNotify( aError );
       
    68 		}
       
    69 	
       
    70 	if( !iFinish )
       
    71 		{
       
    72 		// Need to go round once more to stop the sched.
       
    73 		iFinish = ETrue;
       
    74 		SetActive();
       
    75 		
       
    76 		iTimer.After( iStatus, iTimeout );
       
    77 		}	
       
    78 	
       
    79 	return KErrNone;
       
    80 	}
       
    81 
       
    82 void CTestAndStopper::DoCancel()
       
    83 	{
       
    84 	iTimer.Close();
       
    85 	
       
    86 	iRunning = EFalse;
       
    87 	iFinish = EFalse;
       
    88 	}
       
    89 
       
    90 
       
    91 
       
    92 CTestAndStopper::CTestAndStopper( CSsmStartSafe& aSsmStartSafe, 
       
    93 								  const CSsmStartupProperties& aStartupProperties, 
       
    94 								  RProcess& aProcess,
       
    95 								  TInt aTimeout,
       
    96 								  MSsTestAsyncNotifier* aSsTestAsyncNotifier )
       
    97 : CActive( EPriorityStandard), 
       
    98   iSsmStartSafe( aSsmStartSafe ), 
       
    99   iStartupProperties( aStartupProperties ), 
       
   100   iProcess( aProcess ),
       
   101   iTimeout( aTimeout ),
       
   102   iSsTestAsyncNotifier( aSsTestAsyncNotifier )
       
   103 	{
       
   104 	CActiveScheduler::Add( this );
       
   105 	SetActive();
       
   106 	
       
   107 	iTimer.CreateLocal();
       
   108 	iTimer.After( iStatus, 1000000 ); // TKAS May not need this delay.
       
   109 	}
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 
       
   115 CTestAndStopper::~CTestAndStopper()
       
   116 	{
       
   117 	Cancel();
       
   118 	iTimer.Close();
       
   119 	}
       
   120 
       
   121 //
       
   122 // Similar to above n=but used for making duff starts to test errors
       
   123 //
       
   124 //
       
   125 void CDuffTestAndStopper::RunL()
       
   126 	{
       
   127 	if( !iRunning )
       
   128 		{
       
   129 		iRunning = ETrue;	
       
   130 		DoStartsL();	
       
   131 		SetActive();
       
   132 		
       
   133 		TRequestStatus* trs = &iStatus;
       
   134 		User::RequestComplete( trs, KErrNone );
       
   135 		}
       
   136 	else if( !iFinish )
       
   137 		{
       
   138 		iFinish = ETrue;
       
   139 		SetActive();
       
   140 		
       
   141 		iTimer.After( iStatus, iTimeout );
       
   142 		}
       
   143 	else
       
   144 		{
       
   145 		CActiveScheduler::Stop();
       
   146 		}
       
   147 	
       
   148 	}
       
   149 
       
   150 
       
   151 void CDuffTestAndStopper::DoStartsL()
       
   152 	{
       
   153 	// Call S&M even though monitoring may not be specified
       
   154 	iSsmStartSafe.StartAndMonitorL( iStartupProperties, iProcess );
       
   155 	}
       
   156 
       
   157 
       
   158 
       
   159 
       
   160 TInt CDuffTestAndStopper::RunError( TInt aError )
       
   161 	{
       
   162 	if( iSsTestAsyncNotifier )
       
   163 		{
       
   164 		iSsTestAsyncNotifier->SsTestNotify( aError );
       
   165 		}
       
   166 	
       
   167 	if( !iFinish )
       
   168 		{
       
   169 		// Need to go round once more to stop the sched.
       
   170 		iFinish = ETrue;
       
   171 		SetActive();
       
   172 		
       
   173 		iTimer.After( iStatus, iTimeout );
       
   174 		}	
       
   175 	
       
   176 	return KErrNone;
       
   177 	}
       
   178 
       
   179 void CDuffTestAndStopper::DoCancel()
       
   180 	{
       
   181 	iTimer.Close();
       
   182 	
       
   183 	iRunning = EFalse;
       
   184 	iFinish = EFalse;
       
   185 	}
       
   186 
       
   187 
       
   188 
       
   189 CDuffTestAndStopper::CDuffTestAndStopper( CSsmStartSafe& aSsmStartSafe, 
       
   190 								  const CSsmStartupProperties& aStartupProperties, 
       
   191 								  RProcess& aProcess,
       
   192 								  TInt aTimeout,
       
   193 								  MSsTestAsyncNotifier* aSsTestAsyncNotifier )
       
   194 : CActive( EPriorityStandard), 
       
   195   iSsmStartSafe( aSsmStartSafe ), 
       
   196   iStartupProperties( aStartupProperties ), 
       
   197   iProcess( aProcess ),
       
   198   iTimeout( aTimeout ),
       
   199   iSsTestAsyncNotifier( aSsTestAsyncNotifier )
       
   200 	{
       
   201 	CActiveScheduler::Add( this );
       
   202 	SetActive();
       
   203 	
       
   204 	iTimer.CreateLocal();
       
   205 	iTimer.After( iStatus, 1000000 ); // TKAS May not need this delay.
       
   206 	}
       
   207 
       
   208 
       
   209 
       
   210 
       
   211 
       
   212 CDuffTestAndStopper::~CDuffTestAndStopper()
       
   213 	{
       
   214 	Cancel();
       
   215 	iTimer.Close();
       
   216 	}
       
   217 
       
   218 
       
   219 
       
   220 //
       
   221 // Test two sync calls. Currently starts two of the same iStarupProperties
       
   222 //
       
   223 // Should give this an array of RProcess to start an arbitrary number of instances
       
   224 //
       
   225 
       
   226 void CTestTwoAndStopper::RunL()
       
   227 	{
       
   228 	if( !iRunning )
       
   229 		{
       
   230 		iRunning = ETrue;	
       
   231 		DoStartsL();	
       
   232 		SetActive();
       
   233 		
       
   234 		TRequestStatus* trs = &iStatus;
       
   235 		User::RequestComplete( trs, KErrNone );
       
   236 		}
       
   237 	else if( !iFinish )
       
   238 		{
       
   239 		iFinish = ETrue;
       
   240 		SetActive();
       
   241 		
       
   242 		iTimer.After( iStatus, iTimeout );
       
   243 		}
       
   244 	else
       
   245 		{
       
   246 		CActiveScheduler::Stop();
       
   247 		}
       
   248 	
       
   249 	}
       
   250 
       
   251 
       
   252 void CTestTwoAndStopper::DoStartsL()
       
   253 	{
       
   254 
       
   255 	if( iStartupProperties.IsMonitoringRequired() )
       
   256 		{
       
   257 		iSsmStartSafe.StartAndMonitorL( iStartupProperties, iProcess_0 );
       
   258 		iSsmStartSafe.StartAndMonitorL( iStartupProperties, iProcess_1 );
       
   259 		}
       
   260 	else
       
   261 		{
       
   262 		iSsmStartSafe.StartL( iStartupProperties, iProcess_0 );
       
   263 		iSsmStartSafe.StartL( iStartupProperties, iProcess_1 );
       
   264 		}	
       
   265 	
       
   266 	}
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 TInt CTestTwoAndStopper::RunError( TInt aError )
       
   272 	{
       
   273 	if( iSsTestAsyncNotifier )
       
   274 		{
       
   275 		iSsTestAsyncNotifier->SsTestNotify( aError );
       
   276 		}
       
   277 	
       
   278 	if( !iFinish )
       
   279 		{
       
   280 		// Need to go round once more to stop the sched.
       
   281 		iFinish = ETrue;
       
   282 		SetActive();
       
   283 		
       
   284 		iTimer.After( iStatus, iTimeout );
       
   285 		}	
       
   286 	
       
   287 	return KErrNone;
       
   288 	}
       
   289 
       
   290 void CTestTwoAndStopper::DoCancel()
       
   291 	{
       
   292 	iTimer.Close();
       
   293 	
       
   294 	iRunning = EFalse;
       
   295 	iFinish = EFalse;
       
   296 	}
       
   297 
       
   298 
       
   299 
       
   300 CTestTwoAndStopper::CTestTwoAndStopper( CSsmStartSafe& aSsmStartSafe, 
       
   301 								  const CSsmStartupProperties& aStartupProperties, 
       
   302 								  RProcess& aProcess_0, RProcess& aProcess_1,
       
   303 								  TInt aTimeout,
       
   304 								  MSsTestAsyncNotifier* aSsTestAsyncNotifier )
       
   305 : CActive( EPriorityStandard), 
       
   306   iSsmStartSafe( aSsmStartSafe ), 
       
   307   iStartupProperties( aStartupProperties ), 
       
   308   iProcess_0( aProcess_0 ),
       
   309   iProcess_1( aProcess_1 ),
       
   310   iTimeout( aTimeout ),
       
   311   iSsTestAsyncNotifier( aSsTestAsyncNotifier )
       
   312 	{
       
   313 	CActiveScheduler::Add( this );
       
   314 	SetActive();
       
   315 	
       
   316 	iTimer.CreateLocal();
       
   317 	iTimer.After( iStatus, 1000000 ); // TKAS May not need this delay.
       
   318 	}
       
   319 
       
   320 
       
   321 
       
   322 CTestTwoAndStopper::~CTestTwoAndStopper()
       
   323 	{
       
   324 	Cancel();
       
   325 	iTimer.Close();
       
   326 	}
       
   327