stif/TestServer/src/TestThreadContainerRunnerFactory.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 2009 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: This module contains the implementation of 
       
    15 * CTestthreadContainerRunnerFactory class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <stifinternal/TestThreadContainerRunnerFactory.h>
       
    21 #include "TestThreadContainerRunner.h"
       
    22 
       
    23 // EXTERNAL DATA STRUCTURES
       
    24 // None
       
    25 
       
    26 // EXTERNAL FUNCTION PROTOTYPES  
       
    27 // None
       
    28 
       
    29 // CONSTANTS
       
    30 // None
       
    31 
       
    32 // MACROS
       
    33 // None
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 // None
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 // None
       
    40 
       
    41 // LOCAL FUNCTION PROTOTYPES
       
    42 // None
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 // None
       
    46 
       
    47 
       
    48 // ================= MEMBER FUNCTIONS =========================================
       
    49 
       
    50 /*
       
    51 -------------------------------------------------------------------------------
       
    52 
       
    53      Class: CTestThreadContainerRunnerFactory
       
    54 
       
    55      Method: NewL
       
    56 
       
    57      Description: NewL is first phase of two-phased constructor.
       
    58 
       
    59 	 NewL is first phase of two-phased constructor.
       
    60 
       
    61      Parameters: TThreadId aThreadId: in: main thread id.
       
    62      			 CActiveScheduler* aScheduler: in: Pointer to main thread active scheduler.
       
    63      			 CUiEnvProxy* aUiEnvProxy: in: Pointer to UIEnvProxy.
       
    64      
       
    65      Return Values: Pointer to new CTestServerThreadStarter object.
       
    66 
       
    67      Errors/Exceptions: Leaves if new or ConstructL leaves.
       
    68 
       
    69      Status: Draft
       
    70     
       
    71 -------------------------------------------------------------------------------
       
    72 */
       
    73 EXPORT_C CTestThreadContainerRunnerFactory* 
       
    74 CTestThreadContainerRunnerFactory::NewL( TThreadId aThreadId, CActiveScheduler* aScheduler, CUiEnvProxy* aUiEnvProxy )
       
    75 	{
       
    76 	CTestThreadContainerRunnerFactory* self = 
       
    77 		new(ELeave)CTestThreadContainerRunnerFactory();
       
    78 	CleanupStack::PushL( self );
       
    79 	self->ConstructL( aThreadId, aScheduler, aUiEnvProxy );
       
    80 	CleanupStack::Pop( self );
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 /*
       
    85 -------------------------------------------------------------------------------
       
    86 
       
    87      Class: CTestThreadContainerRunnerFactory
       
    88 
       
    89      Method: CTestThreadContainerRunnerFactory
       
    90 
       
    91      Description: Default constructor.
       
    92 
       
    93 	 Default constructor.
       
    94 
       
    95      Parameters: None.
       
    96      
       
    97      Return Values: None.
       
    98 
       
    99      Errors/Exceptions: None.
       
   100 
       
   101      Status: Draft
       
   102     
       
   103 -------------------------------------------------------------------------------
       
   104 */
       
   105 CTestThreadContainerRunnerFactory::CTestThreadContainerRunnerFactory()
       
   106 :CActive( EPriorityNormal ),
       
   107 iTestThreadContainerRunner( NULL ),
       
   108 iOperation( ENone )
       
   109 	{
       
   110 	}
       
   111 
       
   112 /*
       
   113 -------------------------------------------------------------------------------
       
   114 
       
   115      Class: CTestThreadContainerRunnerFactory
       
   116 
       
   117      Method: ~CTestThreadContainerRunnerFactory
       
   118 
       
   119      Description: Default destructor.
       
   120 
       
   121 	 Default destructor.
       
   122 
       
   123      Parameters: None.
       
   124      
       
   125      Return Values: None.
       
   126 
       
   127      Errors/Exceptions: None.
       
   128 
       
   129      Status: Draft
       
   130     
       
   131 -------------------------------------------------------------------------------
       
   132 */
       
   133 CTestThreadContainerRunnerFactory::~CTestThreadContainerRunnerFactory()
       
   134 	{
       
   135 	Cancel();
       
   136 	iOperationEndSemaphore.Close();
       
   137 	}
       
   138 
       
   139 /*
       
   140 -------------------------------------------------------------------------------
       
   141 
       
   142      Class: CTestThreadContainerRunnerFactory
       
   143 
       
   144      Method: ConstructL
       
   145 
       
   146      Description: Second phase of two-phased constructor.
       
   147 
       
   148 	 Second phase of two-phased constructor.
       
   149 
       
   150      Parameters: TThreadId aThreadId: in: main thread id.
       
   151      			 CActiveScheduler* aScheduler: in: Pointer to main thread active scheduler.
       
   152      			 CUiEnvProxy* aUiEnvProxy: in: Pointer to UIEnvProxy.
       
   153      
       
   154      Return Values: None.
       
   155 
       
   156      Errors/Exceptions: None.
       
   157 
       
   158      Status: Draft
       
   159     
       
   160 -------------------------------------------------------------------------------
       
   161 */
       
   162 void CTestThreadContainerRunnerFactory::ConstructL( TThreadId aThreadId, CActiveScheduler* aScheduler, CUiEnvProxy* aUiEnvProxy )
       
   163 	{
       
   164 	User::LeaveIfNull( aScheduler );
       
   165 	iThreadId = aThreadId;
       
   166 	iScheduler = aScheduler;
       
   167 	iUiEnvProxy = aUiEnvProxy;
       
   168 	
       
   169 	TInt ret = iOperationEndSemaphore.CreateLocal( 0 );
       
   170 	if ( ret != KErrNone )
       
   171 		{
       
   172 		User::Leave( ret );
       
   173 		}
       
   174 	
       
   175 	iScheduler->Add( this );
       
   176 	}
       
   177 
       
   178 /*
       
   179 -------------------------------------------------------------------------------
       
   180 
       
   181      Class: CTestThreadContainerRunnerFactory
       
   182 
       
   183      Method: DeleteL
       
   184 
       
   185      Description: Performs creation of CTestThreadContainerRunner object.
       
   186 
       
   187 	 Performs creation of CTestThreadContainerRunner object.
       
   188 
       
   189      Parameters: CTestThreadContainerRunner* aTestThreadContainerRunner: in: Pointer to 
       
   190      				CTestThreadContainerRunner object which needs to be deleted.
       
   191      
       
   192      Return Values: None.
       
   193 
       
   194      Errors/Exceptions: Leaves if one of the called method leavs.
       
   195 
       
   196      Status: Draft
       
   197     
       
   198 -------------------------------------------------------------------------------
       
   199 */
       
   200 CTestThreadContainerRunner* CTestThreadContainerRunnerFactory::CreateL()
       
   201 	{
       
   202 	if ( IsActive() )
       
   203 		{
       
   204 		User::Panic( _L( "E32USER-CBase" ), 42 );
       
   205 		}
       
   206 
       
   207 	iOperation = ECreate;
       
   208 	iStatus = KRequestPending;
       
   209 	
       
   210 	RThread thread;
       
   211 	TInt ret = thread.Open( iThreadId );
       
   212 	if ( ret != KErrNone )
       
   213 		{
       
   214 		User::Leave( ret );
       
   215 		}
       
   216 	
       
   217 	SetActive();
       
   218 	TRequestStatus* statusPtr = &iStatus;
       
   219 	thread.RequestComplete( statusPtr, KErrNone );
       
   220 	thread.Close();
       
   221 	iOperationEndSemaphore.Wait();
       
   222 
       
   223 	return iTestThreadContainerRunner;
       
   224 	}
       
   225 
       
   226 /*
       
   227 -------------------------------------------------------------------------------
       
   228 
       
   229      Class: CTestThreadContainerRunnerFactory
       
   230 
       
   231      Method: DeleteL
       
   232 
       
   233      Description: Performs deletion of CTestThreadContainerRunner object.
       
   234 
       
   235 	 Performs deletion of CTestThreadContainerRunner object.
       
   236 
       
   237      Parameters: CTestThreadContainerRunner* aTestThreadContainerRunner: in: Pointer to 
       
   238      				CTestThreadContainerRunner object which needs to be deleted.
       
   239      
       
   240      Return Values: None.
       
   241 
       
   242      Errors/Exceptions: Leaves if one of the called method leavs.
       
   243 
       
   244      Status: Draft
       
   245     
       
   246 -------------------------------------------------------------------------------
       
   247 */
       
   248 void CTestThreadContainerRunnerFactory::DeleteL( CTestThreadContainerRunner* aTestThreadContainerRunner )
       
   249 	{
       
   250 	if ( IsActive() )
       
   251 		{
       
   252 		User::Panic( _L( "E32USER-CBase" ), 42 );
       
   253 		}
       
   254 	
       
   255 	iOperation = EDelete;
       
   256 	iStatus = KRequestPending;
       
   257 	
       
   258 	RThread thread;
       
   259 	TInt ret = thread.Open( iThreadId );
       
   260 	if ( ret != KErrNone )
       
   261 		{
       
   262 		User::Leave( ret );
       
   263 		}
       
   264 	
       
   265 	iTestThreadContainerRunner = aTestThreadContainerRunner;
       
   266 	SetActive();
       
   267 	TRequestStatus* statusPtr = &iStatus;
       
   268 	thread.RequestComplete( statusPtr, KErrNone );
       
   269 	thread.Close();
       
   270 	iOperationEndSemaphore.Wait();
       
   271 	}
       
   272 
       
   273 /*
       
   274 -------------------------------------------------------------------------------
       
   275 
       
   276      Class: CTestThreadContainerRunnerFactory
       
   277 
       
   278      Method: RunL
       
   279 
       
   280      Description: RunL derived from CActive handles the completed requests.
       
   281 
       
   282 	 RunL derived from CActive handles the completed requests.
       
   283 
       
   284      Parameters: None.
       
   285      
       
   286      Return Values: None.
       
   287 
       
   288      Errors/Exceptions: Leaves if one of the called method leavs.
       
   289 
       
   290      Status: Draft
       
   291     
       
   292 -------------------------------------------------------------------------------
       
   293 */
       
   294 void CTestThreadContainerRunnerFactory::RunL()
       
   295 	{
       
   296 	switch( iOperation )
       
   297 		{
       
   298 		case ECreate:
       
   299 			{
       
   300 			iTestThreadContainerRunner = CTestThreadContainerRunner::NewL( iThreadId, iScheduler );
       
   301 			}
       
   302 			break;
       
   303 		case EDelete:
       
   304 			{
       
   305 			delete iTestThreadContainerRunner;
       
   306 			iTestThreadContainerRunner = NULL;
       
   307 			}
       
   308 			break;
       
   309 		default:
       
   310 			{
       
   311 			User::Panic( _L("STIFInternalError"), KErrNotFound );
       
   312 			}			
       
   313 			break;
       
   314 		}
       
   315 	iOperation = ENone;
       
   316 	iOperationEndSemaphore.Signal();
       
   317 	}
       
   318 
       
   319 /*
       
   320 -------------------------------------------------------------------------------
       
   321 
       
   322      Class: CTestThreadContainerRunnerFactory
       
   323 
       
   324      Method: DoCancel
       
   325 
       
   326      Description: DoCancel derived from CActive handles the Cancel.
       
   327 
       
   328 	 DoCancel derived from CActive handles the Cancel.
       
   329 
       
   330      Parameters: None.
       
   331      
       
   332      Return Values: None.
       
   333 
       
   334      Errors/Exceptions: None.
       
   335 
       
   336      Status: Draft
       
   337     
       
   338 -------------------------------------------------------------------------------
       
   339 */
       
   340 void CTestThreadContainerRunnerFactory::DoCancel()
       
   341 	{	
       
   342 	}
       
   343 
       
   344 /*
       
   345 -------------------------------------------------------------------------------
       
   346 
       
   347      Class: CTestThreadContainerRunnerFactory
       
   348 
       
   349      Method: GetUiEnvProxy
       
   350 
       
   351      Description: Gets UIEnvProxy.
       
   352 
       
   353      Parameters: None.
       
   354      
       
   355      Return Values: Pointer to UIEnvProxy.
       
   356 
       
   357      Errors/Exceptions: None.
       
   358 
       
   359      Status: Draft
       
   360     
       
   361 -------------------------------------------------------------------------------
       
   362 */
       
   363 CUiEnvProxy* CTestThreadContainerRunnerFactory::GetUiEnvProxy()
       
   364 	{
       
   365 	return iUiEnvProxy;
       
   366 	}
       
   367 
       
   368 // End of File