stif/TestServer/src/Testexecution.cpp
changeset 0 a03f92240627
child 16 8f8df8006c40
equal deleted inserted replaced
-1:000000000000 0:a03f92240627
       
     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 implementation of CTestExecution 
       
    15 * class member functions. CTestExecution class handles a test 
       
    16 * execution subsession specific operations.
       
    17 *
       
    18 */
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32std.h>
       
    22 #include <e32svr.h>
       
    23 #include "TestEngineClient.h"
       
    24 #include "StifTFwIfProt.h"
       
    25 #include <stifinternal/TestServerClient.h>
       
    26 #include "TestServer.h"
       
    27 #include "TestServerModuleIf.h"
       
    28 #include "TestServerCommon.h"
       
    29 #include "PrintQueue.h"
       
    30 #include "TestServerEvent.h"
       
    31 #include "TestThreadContainer.h"
       
    32 #include "STIFMeasurement.h"
       
    33 
       
    34 // EXTERNAL DATA STRUCTURES
       
    35 
       
    36 // EXTERNAL FUNCTION PROTOTYPES  
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // MACROS
       
    41 
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 
       
    44 // MODULE DATA STRUCTURES
       
    45 
       
    46 // LOCAL FUNCTION PROTOTYPES
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 
       
    50 // ==================== LOCAL FUNCTIONS =======================================
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =========================================
       
    53 
       
    54 /*
       
    55 -------------------------------------------------------------------------------
       
    56 
       
    57     Class: CTestExecution
       
    58 
       
    59     Method: NewL
       
    60 
       
    61     Description: Returns new CTestExecution instance.
       
    62 
       
    63     Parameters: CTestModule* aModuleSession   :in:  "Parent" module
       
    64                 TInt aCaseNumber              :in:  Test case number
       
    65                 const TFileName& aConfig      :in:  Configuration filename
       
    66 
       
    67     Return Values: CTestExecution*                  New instance
       
    68 
       
    69     Errors/Exceptions: Function leaves if memory allocation fails or
       
    70                        CTestExecution construction leaves.
       
    71                        Panics is aModuleSession is NULL.
       
    72 
       
    73     Status: Proposal
       
    74 
       
    75 -------------------------------------------------------------------------------
       
    76 */
       
    77 CTestExecution* CTestExecution::NewL( CTestModule* aModuleSession,
       
    78                                       TInt aCaseNumber, 
       
    79                                       const TFileName& aConfig )
       
    80     {
       
    81 
       
    82     __ASSERT_ALWAYS ( aModuleSession, 
       
    83                       CTestServer::PanicServer( ENullModuleSession ) );
       
    84 
       
    85     CTestExecution* self=new( ELeave ) CTestExecution;
       
    86     CleanupClosePushL( *self );
       
    87     self->ConstructL( aModuleSession, aCaseNumber, aConfig );
       
    88     CleanupStack::Pop();
       
    89 
       
    90     return self;
       
    91 
       
    92     }
       
    93 
       
    94 
       
    95 /*
       
    96 -------------------------------------------------------------------------------
       
    97 
       
    98     Class: CTestExecution
       
    99 
       
   100     Method: CTestExecution
       
   101 
       
   102     Description: Constructor.
       
   103     Initialises member variables whose default state is not zero or NULL.
       
   104 
       
   105     Parameters:  None
       
   106     
       
   107     Return Values: None
       
   108 
       
   109     Errors/Exceptions: None
       
   110 
       
   111     Status: Proposal
       
   112     
       
   113 -------------------------------------------------------------------------------
       
   114 */
       
   115 CTestExecution::CTestExecution() : 
       
   116     iConfig( 0, 0 ),
       
   117     iTestThreadOpen( EFalse ),
       
   118     iTestThreadFailure( ETestThreadOk )
       
   119     {
       
   120 
       
   121     iPrintNotifyAvailable = EFalse;
       
   122     iThreadState = ENotStarted;
       
   123     iRemoteSendAvailable = EFalse;
       
   124     iRemoteReceiveAvailable = EFalse;
       
   125     iEventNotifyAvailable = EFalse;
       
   126     iCommandNotifyAvailable = EFalse;
       
   127 
       
   128     }
       
   129 
       
   130 /*
       
   131 -------------------------------------------------------------------------------
       
   132 
       
   133     Class: CTestExecution
       
   134 
       
   135     Method: ~CTestExecution
       
   136 
       
   137     Description: Destructor
       
   138 
       
   139     Parameters: None
       
   140     
       
   141     Return Values: None
       
   142 
       
   143     Errors/Exceptions: Panics is threadmutex is taken.
       
   144 
       
   145     Status: Approved
       
   146     
       
   147 -------------------------------------------------------------------------------
       
   148 */
       
   149 CTestExecution::~CTestExecution()
       
   150     {
       
   151     // Thread must be stopped before CTestExecution can be deleted
       
   152     if( iThreadState == EOnGoing ) 
       
   153 		{
       
   154 			if( iModuleContainer != NULL )
       
   155 				{
       
   156 				iModuleContainer->KillThread( KErrCancel );
       
   157 				}
       
   158 			delete iModuleContainer;
       
   159 			iModuleContainer = NULL;
       
   160 			CTestServer::PanicServer( EClosingWhileTestRunning );
       
   161 		}
       
   162 
       
   163     delete iPrintHandler;
       
   164     iPrintHandler = NULL;
       
   165     delete iEventHandler;
       
   166     iEventHandler = NULL;
       
   167     delete iSndHandler;
       
   168     iSndHandler = NULL;
       
   169     delete iRcvHandler;
       
   170     iRcvHandler = NULL;
       
   171     delete iInterferenceHandler;
       
   172     iInterferenceHandler = NULL;
       
   173     delete iMeasurementHandler;
       
   174     iMeasurementHandler = NULL;
       
   175     delete iCommandHandler;
       
   176     iCommandHandler = NULL;
       
   177 
       
   178     // Test interference array(Needed cases when test interference thread is
       
   179     // needed to Kill())
       
   180     iSTIFTestInterferenceArray.Reset();
       
   181     iSTIFTestInterferenceArray.Close();
       
   182 
       
   183     // Reset test measurement array
       
   184     iMeasurementHandlingArray.Reset();
       
   185     iMeasurementHandlingArray.Close();
       
   186 
       
   187     // iPrintQueue must be emptied here, because it items are allocated from server heap
       
   188     delete iPrintQueue;
       
   189     iPrintQueue = NULL;
       
   190 
       
   191     // Delete name buffer
       
   192     delete iConfigNameBuffer;
       
   193     iConfigNameBuffer = NULL;
       
   194     
       
   195     iStateEvents.ResetAndDestroy();
       
   196     iStateEvents.Close();
       
   197 
       
   198     iEventArray.ResetAndDestroy();
       
   199     iEventArray.Close();
       
   200 
       
   201     // Close mutexes
       
   202     if ( iPrintMutex.Handle() != 0 ) iPrintMutex.Close();
       
   203     if ( iEventMutex.Handle() != 0 ) iEventMutex.Close();
       
   204     if ( iSndMutex.Handle() != 0 ) iSndMutex.Close();
       
   205     if ( iRcvMutex.Handle() != 0 ) iRcvMutex.Close();
       
   206     if ( iInterferenceMutex.Handle() != 0 ) iInterferenceMutex.Close();
       
   207     if ( iMeasurementMutex.Handle() != 0 ) iMeasurementMutex.Close();
       
   208     if ( iCommandMutex.Handle() != 0 ) iCommandMutex.Close();
       
   209 
       
   210     // Mutex for testcomplete and cancel operations. Close mutex
       
   211     if ( iTestThreadMutex.Handle() != 0 ) iTestThreadMutex.Close();
       
   212 
       
   213     // Close semaphores
       
   214     if ( iPrintSem.Handle() != 0 ) iPrintSem.Close();
       
   215     if ( iEventSem.Handle() != 0 ) iEventSem.Close();
       
   216     if ( iSndSem.Handle() != 0 ) iSndSem.Close();
       
   217     if ( iRcvSem.Handle() != 0 ) iRcvSem.Close();
       
   218     if ( iInterferenceSem.Handle() != 0 ) iInterferenceSem.Close();
       
   219     if ( iMeasurementSem.Handle() != 0 ) iMeasurementSem.Close();
       
   220     //if ( iReceiverSem.Handle() != 0 ) iReceiverSem.Close();
       
   221     if ( iCommandSem.Handle() != 0 ) iCommandSem.Close();
       
   222     
       
   223     iMessageQueue.Close();
       
   224     
       
   225     iTestThread.Close();
       
   226 
       
   227     delete iCommandDef;
       
   228     iCommandDef = NULL;
       
   229     }
       
   230 
       
   231 
       
   232 /*
       
   233 -------------------------------------------------------------------------------
       
   234 
       
   235     Class: CTestExecution
       
   236 
       
   237     Method: ConstructL
       
   238 
       
   239     Description: Second level constructor
       
   240 
       
   241     Parameters: CTestModule* aModuleSession   :in:  "Parent" module
       
   242                 TInt aCaseNumber ::           :in:  Test case number
       
   243                 const TFileName& aConfig      :in:  Configuration filename
       
   244 
       
   245     Return Values: None
       
   246 
       
   247     Errors/Exceptions: None
       
   248 
       
   249     Status: Approved
       
   250 
       
   251 -------------------------------------------------------------------------------
       
   252 */
       
   253 void CTestExecution::ConstructL( CTestModule *aModuleSession,
       
   254                                  TInt aCaseNumber,
       
   255                                  const TFileName& aConfig )
       
   256     {
       
   257 
       
   258     // Get the parameters
       
   259     iModuleSession = aModuleSession;
       
   260     iCaseNumber = aCaseNumber;
       
   261 
       
   262     // Construct heap buffer for configuration file
       
   263     iConfigNameBuffer = HBufC::NewL( aConfig.Length() );
       
   264     iConfig.Set ( iConfigNameBuffer->Des() );
       
   265     iConfig.Copy ( aConfig );
       
   266 
       
   267     // Create mutexes
       
   268     User::LeaveIfError( iPrintMutex.CreateLocal() );
       
   269     User::LeaveIfError( iEventMutex.CreateLocal() );
       
   270     User::LeaveIfError( iSndMutex.CreateLocal() );
       
   271     User::LeaveIfError( iRcvMutex.CreateLocal() );
       
   272     User::LeaveIfError( iInterferenceMutex.CreateLocal() );
       
   273     User::LeaveIfError( iMeasurementMutex.CreateLocal() );
       
   274     User::LeaveIfError( iCommandMutex.CreateLocal() );
       
   275 
       
   276     // Mutex for testcomplete and cancel operations. Create mutex
       
   277     User::LeaveIfError( iTestThreadMutex.CreateLocal() );
       
   278 
       
   279     // Create semaphores
       
   280     User::LeaveIfError( iPrintSem.CreateLocal( 0 ) );
       
   281     User::LeaveIfError( iEventSem.CreateLocal( 0 ) );
       
   282     User::LeaveIfError( iSndSem.CreateLocal( 0 ) );
       
   283     User::LeaveIfError( iRcvSem.CreateLocal( 0 ) );
       
   284     User::LeaveIfError( iInterferenceSem.CreateLocal( 0 ) );
       
   285     User::LeaveIfError( iMeasurementSem.CreateLocal( 0 ) );
       
   286     //User::LeaveIfError( iReceiverSem.CreateLocal( 0 ) );
       
   287     User::LeaveIfError( iCommandSem.CreateLocal( 0 ) );
       
   288 
       
   289     // Create handlers
       
   290     iPrintHandler = CPrintHandler::NewL( *this );
       
   291     iEventHandler = CEventHandler::NewL( *this );
       
   292     iSndHandler  = CSndHandler::NewL( *this );
       
   293     iRcvHandler  = CRcvHandler::NewL( *this );
       
   294     iInterferenceHandler = CInterferenceHandler::NewL( *this );
       
   295     iMeasurementHandler = CMeasurementHandler::NewL( *this );
       
   296     iCommandHandler = CCommandHandler::NewL( *this );
       
   297 
       
   298     // Create print queue
       
   299     iPrintQueue = CPrintQueue::NewL();
       
   300 
       
   301     // Start print handler   
       
   302     iPrintHandler->StartL();
       
   303     
       
   304     // Start rcv handler
       
   305     iRcvHandler->StartL();
       
   306 
       
   307     // Start interference handler
       
   308     iInterferenceHandler->StartL();
       
   309 
       
   310     // Start measurement handler
       
   311     iMeasurementHandler->StartL();
       
   312 
       
   313     iCommandDef = CCommandDef::NewL();
       
   314     }
       
   315 
       
   316 
       
   317 /*
       
   318 -------------------------------------------------------------------------------
       
   319 
       
   320     Class: CTestExecution
       
   321 
       
   322     Method: RunTestCase
       
   323 
       
   324     Description: Starts to execute test case in separate thread.
       
   325 
       
   326     Parameters: const RMessage& aMessage  :in:      Message from client.
       
   327 
       
   328     Return Values: TInt                             Error code
       
   329 
       
   330     Errors/Exceptions: None
       
   331 
       
   332     Status: Proposal
       
   333 
       
   334 -------------------------------------------------------------------------------
       
   335 */
       
   336 TInt CTestExecution::RunTestCase( const RMessage2& aMessage )
       
   337     {
       
   338 
       
   339     __TRACE ( KInit, ( _L( "CTestExecution::RunTestCase in" ) ) );
       
   340 
       
   341     // Store message to be completed when case is finished
       
   342     iTestExeMessage = aMessage;
       
   343 
       
   344     iFullResult.iStartTime.HomeTime();
       
   345 
       
   346     // Get a test module, which executes the test case.
       
   347     // The test module will be freed either when the test case
       
   348     // completes, or the test case is aborted.
       
   349     TInt ret = iModuleSession->GetTestModule( iModuleContainer, iConfig );
       
   350     if ( ret != KErrNone || iModuleContainer == NULL )
       
   351         {
       
   352         _LIT(KRunError,"Can't get test module");
       
   353         __TRACE ( KError, ( CStifLogger::ERed, KRunError() ) );
       
   354         CompleteTestExecution( KErrNone,
       
   355                                TFullTestResult::ECaseException,
       
   356                                ret,
       
   357                                KErrGeneral,
       
   358                                KRunError );
       
   359         return KErrNone;
       
   360         }
       
   361     
       
   362 
       
   363     // Thread is created, so all thread specific operations are possible, 
       
   364     // even if thread is not yet resumed, so mark thread to be "Running"
       
   365     SetThreadState ( EOnGoing );
       
   366 
       
   367     // Start the test
       
   368     iModuleContainer->SetExecutionSubSession( this );
       
   369     iModuleContainer->RunTestCase( iConfig, iCaseNumber, aMessage );
       
   370 
       
   371     __TRACE ( KRunTestCase, ( _L( "CTestExecution::RunTestCase out. Case ongoing" ) ) );
       
   372 
       
   373     return KErrNone;
       
   374 
       
   375     }
       
   376 
       
   377 
       
   378 /*
       
   379 -------------------------------------------------------------------------------
       
   380 
       
   381     Class: CTestExecution
       
   382 
       
   383     Method: NotifyPrint
       
   384 
       
   385     Description: Handles print request from engine. If print queue is empty,
       
   386                  message is stored to be used later when there is something to
       
   387                  print, otherwise the first queue item is returned and request
       
   388                  completes immediately.
       
   389 
       
   390     Parameters: const RMessage& aMessage      :in:  Message from client.
       
   391 
       
   392     Return Values: None
       
   393 
       
   394     Errors/Exceptions: None
       
   395 
       
   396     Status: Proposal
       
   397     
       
   398 -------------------------------------------------------------------------------
       
   399 */
       
   400 TInt CTestExecution::NotifyPrint( const RMessage2& aMessage )
       
   401     {
       
   402 
       
   403     __ASSERT_ALWAYS( iPrintNotifyAvailable == EFalse, 
       
   404                      CTestServer::PanicServer( EPrintQueueBroken ) );
       
   405 
       
   406     // Get first item from queue
       
   407     TPrintQueueItem *item = iPrintQueue->Pop();
       
   408 
       
   409     if ( item == NULL )
       
   410         {
       
   411 
       
   412         // If thread can't print anymore, and queue is empty, then 
       
   413         // complete with Eof, because there will not be any new prints
       
   414         if ( iThreadState == EFinished || iThreadState == ECancelled )
       
   415             {
       
   416             __TRACE ( KPrint, ( _L( "CTestExecution::NotifyPrint to finished thread" ) ) );
       
   417             aMessage.Complete ( KErrEof );
       
   418             }
       
   419         else
       
   420             {
       
   421             // Print request available, do not complete request
       
   422             iNotifyPrintMessage = aMessage;
       
   423             iPrintNotifyAvailable = ETrue;
       
   424             }
       
   425 
       
   426         }
       
   427     else
       
   428         {
       
   429         // Construct message
       
   430         TTestProgress progress;
       
   431         progress.iPosition = item->iPriority;
       
   432         progress.iDescription = item->iData1;
       
   433         progress.iText = item->iData2;
       
   434 
       
   435         iNotifyPrintMessage = aMessage;
       
   436         // Write message to client space and complete request
       
   437         WritePrint( progress );
       
   438 
       
   439         delete item; 
       
   440         }
       
   441 
       
   442 
       
   443     return KErrNone;
       
   444 
       
   445     }
       
   446 /*
       
   447 -------------------------------------------------------------------------------
       
   448 
       
   449     Class: CTestExecution
       
   450 
       
   451     Method: DoNotifyPrint
       
   452 
       
   453     Description: If print notification available, notification is copied to
       
   454                     client memory space and request is completed.
       
   455                  Else new print queue item is created and appended to print 
       
   456                     queue. If queue is full or memory can't be allocated,
       
   457                     then message will be discarded.
       
   458         
       
   459     Parameters: None
       
   460     
       
   461     Return Values: None
       
   462 
       
   463     Errors/Exceptions: None
       
   464 
       
   465     Status: Proposal
       
   466     
       
   467 -------------------------------------------------------------------------------
       
   468 */
       
   469 void CTestExecution::DoNotifyPrint()
       
   470     {    
       
   471 
       
   472     if ( iPrintNotifyAvailable )
       
   473         {
       
   474         // Write message to client space
       
   475         WritePrint( iProgress );
       
   476         }
       
   477     else
       
   478         {
       
   479 
       
   480         TPrintQueueItem *item = 
       
   481             new TPrintQueueItem( iProgress.iPosition, 
       
   482                                  iProgress.iDescription, 
       
   483                                  iProgress.iText );
       
   484 
       
   485         if ( item != NULL )
       
   486             {
       
   487             // Item constructed ok, add it to queue
       
   488             if ( iPrintQueue->Push( *item ) != KErrNone )
       
   489                 { 
       
   490                 // Queue is full, clean-up
       
   491                 delete item;
       
   492                 }
       
   493             }
       
   494         // else: Could not construct TPrintQueueItem, no free memory.
       
   495         // drop printing            
       
   496         }
       
   497     
       
   498     }
       
   499 
       
   500 /*
       
   501 -------------------------------------------------------------------------------
       
   502 
       
   503     Class: CTestExecution
       
   504 
       
   505     Method: DoNotifyInterference
       
   506 
       
   507     Description: Handles Test Interference thread append and remove operations.
       
   508         
       
   509     Parameters: None
       
   510     
       
   511     Return Values: None
       
   512 
       
   513     Errors/Exceptions: None
       
   514 
       
   515     Status: Proposal
       
   516     
       
   517 -------------------------------------------------------------------------------
       
   518 */
       
   519 void CTestExecution::DoNotifyInterference()
       
   520     {    
       
   521     // Information for this context => information is in this thread's heap and
       
   522     // if CUndertaker::RunL is called then test interface thread can called
       
   523     // with function call and kill() test interference thread
       
   524 
       
   525     // Take information from struct given in 
       
   526     // CTestThreadContainer::AddInterferenceThread or
       
   527     // CTestThreadContainer::RemoveInterferenceThread
       
   528     
       
   529     RThread thread;
       
   530     TInt ret = thread.Open ( iTestInterference.iThreadId );
       
   531     if( ret != KErrNone )
       
   532     	{
       
   533     	RDebug::Print( _L("CTestExecution::DoNotifyInterference %d"), ret );
       
   534         User::Panic( _L("CTestExecution::DoNotifyInterference"), ret );
       
   535     	}
       
   536     
       
   537     if ( iTestInterference.iOperation == TTestInterference::EAppend )
       
   538         {
       
   539         iSTIFTestInterferenceArray.Append( thread );
       
   540         }
       
   541     else if (iTestInterference.iOperation == TTestInterference::ERemove )
       
   542         {
       
   543         // Remove thread from Array.Test interference thread is stopped and killed
       
   544         // successfully
       
   545         for( TInt i = 0; i < iSTIFTestInterferenceArray.Count(); i++ )
       
   546             {
       
   547             if( iSTIFTestInterferenceArray[i].Id() == thread.Id() )
       
   548                 {
       
   549                 iSTIFTestInterferenceArray.Remove( i );
       
   550                 break;
       
   551                 }
       
   552             }
       
   553         }
       
   554     else
       
   555         {
       
   556         return;
       
   557         }
       
   558 
       
   559     }
       
   560 
       
   561 /*
       
   562 -------------------------------------------------------------------------------
       
   563 
       
   564     Class: CTestExecution
       
   565 
       
   566     Method: DoNotifyMeasurement
       
   567 
       
   568     Description: Handles test measurement operations: NewL, Start and Stop.
       
   569         
       
   570     Parameters: None
       
   571     
       
   572     Return Values: None
       
   573 
       
   574     Errors/Exceptions: None
       
   575 
       
   576     Status: Approved
       
   577     
       
   578 -------------------------------------------------------------------------------
       
   579 */
       
   580 TInt CTestExecution::DoNotifyMeasurement()
       
   581     {    
       
   582     // Information for this context => information is in this thread's heap:
       
   583     // From CUndertaker::RunL() or CTestModuleContainer::RunL() method can
       
   584     // handle stop and clean operations if these operations are not done 
       
   585     // before.
       
   586     // Erronous cases(CUndertaker::RunL will be called) or when test case is
       
   587     // executed(CTestModuleContainer::RunL() will be called) there can handle
       
   588     // test measurement stop and clean operation. 
       
   589 
       
   590     if( iTestMeasurement.iMeasurementStruct.iMeasurementOperation == 
       
   591                                         CSTIFTestMeasurement::KMeasurementNew)
       
   592         {
       
   593         // Check that same measurement module don't try to create several times
       
   594         // Only one measurement type per test is allowed
       
   595         for( TInt i = 0; i < iMeasurementHandlingArray.Count(); i++ )
       
   596             {
       
   597             if( iMeasurementHandlingArray[i]->iMeasurementModulePtr->MeasurementType() ==
       
   598                         iTestMeasurement.iMeasurementStruct.iMeasurementType )
       
   599                 {
       
   600                 return KErrAlreadyExists;
       
   601                 }
       
   602             }
       
   603 
       
   604         TMeasurementHandling* measurementHandling = NULL;
       
   605         measurementHandling = new TMeasurementHandling();
       
   606 
       
   607         TBuf<KStifMeasurementTypeLength> modulename;
       
   608         if( iTestMeasurement.iMeasurementStruct.iMeasurementType == 1 )
       
   609             {
       
   610             modulename.Copy( KStifMeasurement01 );
       
   611             }
       
   612         else if( iTestMeasurement.iMeasurementStruct.iMeasurementType == 2 )
       
   613             {
       
   614             modulename.Copy( KStifMeasurement02 );
       
   615             }
       
   616         else if( iTestMeasurement.iMeasurementStruct.iMeasurementType == 3 )
       
   617             {
       
   618             modulename.Copy( KStifMeasurement03 );
       
   619             }
       
   620         else if( iTestMeasurement.iMeasurementStruct.iMeasurementType == 4 )
       
   621             {
       
   622             modulename.Copy( KStifMeasurement04 );
       
   623             }
       
   624         else if( iTestMeasurement.iMeasurementStruct.iMeasurementType == 5 )
       
   625             {
       
   626             modulename.Copy( KStifMeasurement05 );
       
   627             }
       
   628         else if( iTestMeasurement.iMeasurementStruct.iMeasurementType == 6 )
       
   629             {
       
   630             modulename.Copy( KStifMeasurementBappea );
       
   631             }
       
   632         else
       
   633             {
       
   634             __TRACE( KError, (  _L("CTestExecution::DoNotifyMeasurement(): unknown measurement type" ) ) );
       
   635             return KErrArgument;
       
   636             }
       
   637 
       
   638         // Loading should work with and without '.dll' extension.
       
   639         TInt r = measurementHandling->iMeasurementModule.Load( modulename );
       
   640         if ( r != KErrNone )
       
   641             {
       
   642             __TRACE( KError, ( CStifLogger::EError, _L("Can't load test measurement module[%S], code = %d"),
       
   643                 &modulename, r ) );
       
   644             delete measurementHandling;
       
   645             return KErrNotFound;
       
   646             }
       
   647         else
       
   648             {
       
   649             //Print test measururement module name
       
   650             __TRACE( KInit, (  _L("Loaded test measurement module[%S]"),
       
   651                 &modulename ) );
       
   652             }
       
   653 
       
   654         // Get pointer to first exported function
       
   655         // Verify that there is function
       
   656         measurementHandling->iMeasurementLibEntry = (CTestMeasurementFactory) measurementHandling->iMeasurementModule.Lookup( 1 );
       
   657         if ( measurementHandling->iMeasurementLibEntry == NULL )
       
   658             {
       
   659             // New instance can't be created
       
   660             __TRACE( KInit, (_L( "Test measurement module instance cannot create." ) ) );
       
   661             measurementHandling->iMeasurementModule.Close();
       
   662             delete measurementHandling;
       
   663             return KErrNotFound;
       
   664             }
       
   665         else
       
   666             {
       
   667             __TRACE ( KInit, ( _L("Pointer to 1st exported received")));
       
   668             }
       
   669 
       
   670         CSTIFTestMeasurementImplementation* measurement;
       
   671         measurement = NULL;
       
   672 
       
   673         // initialize test measurement module
       
   674         __TRACE ( KVerbose, (_L("Calling 1st exported at 0x%x"), (TUint32) measurementHandling->iMeasurementLibEntry ));
       
   675         TRAPD ( err, measurement = (*measurementHandling->iMeasurementLibEntry)( 
       
   676                             iTestMeasurement.iMeasurementStruct.iConfigurationInfo, iTestMeasurement.iMeasurementStruct.iMeasurementType ) );
       
   677 
       
   678          // Handle leave from test module
       
   679         if ( err != KErrNone )
       
   680             {
       
   681             __TRACE (KError, ( CStifLogger::EError, _L( "Leave when calling 1st exported function, code %d"), err ) );
       
   682             delete measurementHandling;
       
   683             return err;
       
   684             }
       
   685         else if ( measurementHandling->iMeasurementLibEntry == NULL )     // Handle NULL from test measurement
       
   686             {
       
   687             __TRACE (KError, ( CStifLogger::EError, _L( "NULL pointer received when constructing test measurement module" ) ) );
       
   688             delete measurementHandling;
       
   689             // Set error codes
       
   690             return KErrNoMemory;
       
   691             }
       
   692         else
       
   693             {
       
   694             measurementHandling->iMeasurementModulePtr = measurement;
       
   695             __TRACE (KInit, (_L("Entrypoint successfully called, Measurement module instance at 0x%x"),
       
   696                 (TUint32)measurementHandling->iMeasurementLibEntry ) );
       
   697             }
       
   698         iMeasurementHandlingArray.Append( measurementHandling );
       
   699         } // End of NewL operations
       
   700 
       
   701     else if( iTestMeasurement.iMeasurementStruct.iMeasurementOperation == 
       
   702                                         CSTIFTestMeasurement::KMeasurementStart)
       
   703         {
       
   704         for( TInt i = 0; i < iMeasurementHandlingArray.Count(); i++ )
       
   705             {
       
   706             if( iMeasurementHandlingArray[i]->iMeasurementModulePtr->MeasurementType() == iTestMeasurement.iMeasurementStruct.iMeasurementType )
       
   707                 {
       
   708                 return iMeasurementHandlingArray[i]->iMeasurementModulePtr->Start();
       
   709                 }
       
   710             }
       
   711 
       
   712         }
       
   713     else if( iTestMeasurement.iMeasurementStruct.iMeasurementOperation == 
       
   714                                         CSTIFTestMeasurement::KMeasurementStop)
       
   715         {
       
   716         for( TInt i = 0; i < iMeasurementHandlingArray.Count(); i++ )
       
   717             {
       
   718             if( iMeasurementHandlingArray[i]->iMeasurementModulePtr->MeasurementType() == iTestMeasurement.iMeasurementStruct.iMeasurementType )
       
   719                 {
       
   720                 TInt stop_ret = iMeasurementHandlingArray[i]->iMeasurementModulePtr->Stop();
       
   721                 delete iMeasurementHandlingArray[i];
       
   722                 iMeasurementHandlingArray.Remove(i);
       
   723                 return stop_ret;
       
   724                 }
       
   725             }
       
   726         }
       
   727     else 
       
   728         {
       
   729         __TRACE (KError, ( CStifLogger::EError, _L("CTestExecution::DoNotifyMeasurement(): Not supported operation") ) );
       
   730         return KErrNotSupported;
       
   731         }
       
   732     
       
   733     return KErrNone;
       
   734 
       
   735     }
       
   736 
       
   737 /*
       
   738 -------------------------------------------------------------------------------
       
   739 
       
   740     Class: CTestExecution
       
   741 
       
   742     Method: WritePrint
       
   743 
       
   744     Description: Writes print notification to client memory space.                 
       
   745         
       
   746     Parameters: const TInt aPriority          :in:  Priority
       
   747                 const TStifInfoName& aDes         :in:  Description
       
   748                 const TName& aBuffer          :in:  Value
       
   749     
       
   750     Return Values: TInt                             Return value from message write
       
   751 
       
   752     Errors/Exceptions: None
       
   753 
       
   754     Status: Proposal
       
   755     
       
   756 -------------------------------------------------------------------------------
       
   757 */
       
   758 TInt CTestExecution::WritePrint( TTestProgress& aProgress )
       
   759     {
       
   760 
       
   761     TTestProgressPckg progressPckg( aProgress );
       
   762  
       
   763     // Write message to client space    
       
   764     TRAPD( res, iNotifyPrintMessage.WriteL( 0, progressPckg ) );
       
   765 
       
   766     iPrintNotifyAvailable = EFalse;
       
   767 
       
   768     // Complete request with possible error code
       
   769     iNotifyPrintMessage.Complete( res );
       
   770 
       
   771     return res;
       
   772 
       
   773     }
       
   774 
       
   775 /*
       
   776 -------------------------------------------------------------------------------
       
   777 
       
   778     Class: CTestExecution
       
   779 
       
   780     Method: NotifyEvent
       
   781 
       
   782     Description: Handles event request from engine. 
       
   783 
       
   784     ESetEvent and EUnsetEvent change event status. EEnable enables 
       
   785     event notify.
       
   786 
       
   787     Parameters: const RMessage& aMessage      :in:  Message from client.
       
   788                     
       
   789     Return Values: None
       
   790 
       
   791     Errors/Exceptions: None
       
   792 
       
   793     Status: Proposal
       
   794     
       
   795 -------------------------------------------------------------------------------
       
   796 */
       
   797 TInt CTestExecution::NotifyEvent( const RMessage2& aMessage )
       
   798     {   
       
   799 
       
   800     TEventIf event;
       
   801     TEventIfPckg eventPckg( event );
       
   802     
       
   803     TRAPD( res, aMessage.ReadL( 0, eventPckg ) );
       
   804 
       
   805     if( res != KErrNone )
       
   806         {
       
   807         __TRACE( KError, ( _L( "CTestExecution::NotifyEvent: ReadL failed" ) ));
       
   808         return res;
       
   809         }
       
   810     
       
   811     switch( event.Type() )
       
   812         {
       
   813         case TEventIf::ESetEvent: 
       
   814             {
       
   815             TInt ind = 0;
       
   816             TInt count = iEventArray.Count();
       
   817             for( ind=0; ind < count; ind++ )
       
   818                 {
       
   819                 if( iEventArray[ind]->Name() == event.Name() )
       
   820                     {
       
   821                     __TRACE( KMessage, ( _L( "CTestExecution::NotifyEvent(%d): SetEvent %S ( count %i )" ), 
       
   822                         this, &event.Name(), count ) );
       
   823                     TEventIf::TEventType etype = TEventIf::EIndication;
       
   824                     // To get state events working with testcombiner
       
   825                     if( ( event.EventType() == TEventIf::EState ) ||                            
       
   826                         ( iEventArray[ind]->EventType() == TEventIf::EState ) )
       
   827                         {
       
   828                         etype = TEventIf::EState;
       
   829                         }
       
   830                     iEventArray[ind]->Set( etype );
       
   831                     }
       
   832                 }
       
   833             }
       
   834             break;
       
   835         case TEventIf::EUnsetEvent:
       
   836             { 
       
   837             return UnsetEvent( event, aMessage );
       
   838             }
       
   839         case TEventIf::EEnable:
       
   840             {
       
   841             // Store event message
       
   842             iNotifyEventMessage = aMessage;
       
   843             iEventNotifyAvailable = ETrue;
       
   844             TInt errorFromPreviousCmd =  aMessage.Int1();
       
   845 
       
   846             __TRACE( KMessage, ( _L( "CTestExecution::NotifyEvent: enable (%d) notify %d" ), 
       
   847                 errorFromPreviousCmd, this ) );
       
   848 
       
   849             // Complete previous Event command
       
   850             CompleteEvent( errorFromPreviousCmd );    
       
   851             iEventHandler->StartL();
       
   852             
       
   853             // iNotifyEventMessage is completed from DoNotifyEvent
       
   854             return KErrNone; 
       
   855             }
       
   856         
       
   857         default:
       
   858             __TRACE( KError, ( _L( "CTestExecution::NotifyEvent: Unknown command %i" ), 
       
   859                 event.Type() ));
       
   860             return KErrArgument;
       
   861         }
       
   862 
       
   863     __TRACE( KMessage, ( _L( "CTestExecution::NotifyEvent(%d): Done" ), this ) );
       
   864 
       
   865     aMessage.Complete( KErrNone );
       
   866     //User::After(1000); //Stif-95 This pause is needed to let Info::TestFrameworkEngine thread
       
   867                        //get some processor time and run exactly at this moment (by calling
       
   868                        //CTestEventController::EventCallBack). When Stif is focused on the screen,
       
   869                        //there is no problem if this line is absent, however when another
       
   870                        //application (like screen saver) is focused this is required.
       
   871     return KErrNone;
       
   872 
       
   873     }
       
   874 
       
   875 /*
       
   876 -------------------------------------------------------------------------------
       
   877 
       
   878     Class: CTestExecution
       
   879 
       
   880     Method: DoNotifyEvent
       
   881 
       
   882     Description: Forward event request.
       
   883         
       
   884     Parameters: None
       
   885    
       
   886     Return Values: None
       
   887 
       
   888     Errors/Exceptions: Panics if event array can't be created
       
   889 
       
   890     Status: Proposal
       
   891     
       
   892 -------------------------------------------------------------------------------
       
   893 */
       
   894 TInt CTestExecution::DoNotifyEvent()
       
   895     {
       
   896     
       
   897     TInt ret = KErrNone;
       
   898         
       
   899     switch( iEventDef.iEvent.Type() )
       
   900         {
       
   901         case TEventIf::EReqEvent:
       
   902             {
       
   903             __TRACE( KMessage, 
       
   904                 ( _L( "CTestExecution::DoNotifyEvent(%d): ReqEvent %S" ), 
       
   905                     this, &iEventDef.iEvent.Name() ) );
       
   906             ret = RequestEvent( iEventDef.iEvent );
       
   907             // If error, return error, 
       
   908             // otherwise proceed with sending information to engine
       
   909             if( ret != KErrNone )
       
   910                 {
       
   911                 iEventHandler->StartL();
       
   912                 return ret;
       
   913                 }
       
   914             }
       
   915             break;
       
   916         case TEventIf::EWaitEvent:
       
   917         case TEventIf::ESetWaitPending:
       
   918             {
       
   919             __TRACE( KMessage, 
       
   920                 ( _L( "CTestExecution::DoNotifyEvent(%d): WaitEvent %S" ), 
       
   921                     this, &iEventDef.iEvent.Name() ) );
       
   922             // We return from here, i.e. nothing is sent to engine
       
   923             ret = WaitEvent( iEventDef.iEvent, iEventDef.iStatus );
       
   924             iEventHandler->StartL();
       
   925             return ret;
       
   926             }
       
   927         // Add state events to internal array  
       
   928         case TEventIf::ESetEvent: 
       
   929         case TEventIf::EUnsetEvent:
       
   930             {
       
   931             __TRACE( KMessage, 
       
   932                 ( _L( "CTestExecution::DoNotifyEvent(%d): Set/UnsetEvent %S" ), 
       
   933                     this, &iEventDef.iEvent.Name() ) );
       
   934             EventStateChange( iEventDef.iEvent );
       
   935             }
       
   936             break;
       
   937         case TEventIf::ERelEvent:
       
   938             // This is handled later
       
   939             __TRACE( KMessage, 
       
   940                 ( _L( "CTestExecution::DoNotifyEvent(%d): RelEvent %S" ), 
       
   941                     this, &iEventDef.iEvent.Name() ) );
       
   942             break;
       
   943         default:
       
   944             iEventHandler->StartL();
       
   945             return KErrArgument;
       
   946         }
       
   947     
       
   948     // Construct message
       
   949     TEventIfPckg eventPckg( iEventDef.iEvent );
       
   950 
       
   951     // Write message to client space
       
   952     TRAPD( res, iNotifyEventMessage.WriteL( 0, eventPckg ) );
       
   953 
       
   954     if( res != KErrNone )
       
   955         {
       
   956         __TRACE( KError, ( _L( "CTestExecution::DoNotifyEvent: WriteL failed" ) ) );
       
   957         ret = res;
       
   958         }
       
   959     // Complete request
       
   960     // Complete with WriteL result
       
   961     // MUST be done before ERelEvent
       
   962     iEventNotifyAvailable = EFalse;
       
   963     iNotifyEventMessage.Complete( res );
       
   964     User::After(1000); //Stif-95 This pause is needed to let Info::TestFrameworkEngine thread
       
   965                        //get some processor time and run exactly at this moment (by calling
       
   966                        //CTestEventNotifier::RunL). When Stif is focused on the screen,
       
   967                        //there is no problem if this line is absent, however when another
       
   968                        //application (like screen saver) is focused this is required.
       
   969 
       
   970     if( iEventDef.iEvent.Type() == TEventIf::ERelEvent )
       
   971         {
       
   972         ret = ReleaseEvent( iEventDef.iEvent );
       
   973         if( ret != KErrNone )
       
   974             {
       
   975             // If error, return immediately
       
   976             return ret;
       
   977             }
       
   978         }
       
   979 
       
   980     __TRACE( KMessage, ( _L( "CTestExecution::DoNotifyEvent(%d): Done" ), this ) );
       
   981 
       
   982     return ret;
       
   983 
       
   984     }
       
   985 
       
   986 /*
       
   987 -------------------------------------------------------------------------------
       
   988 
       
   989     Class: CTestExecution
       
   990 
       
   991     Method: RequestEvent
       
   992 
       
   993     Description: Handles TestModule event requests. 
       
   994         
       
   995     Parameters: const TEventIf& aEvent: in: Event requested  
       
   996     
       
   997     Return Values: TInt: Success/Error code
       
   998 
       
   999     Errors/Exceptions: None
       
  1000 
       
  1001     Status: Proposal
       
  1002     
       
  1003 -------------------------------------------------------------------------------
       
  1004 */    
       
  1005 TInt CTestExecution::RequestEvent( TEventIf& aEvent )
       
  1006     {
       
  1007 
       
  1008     // Requested events are added to iEventArray
       
  1009     // There can be multiple simultaneous requests for the same event                    
       
  1010     TEvent* event = new TEvent( iTestThreadId );    
       
  1011     if( !event )
       
  1012         {
       
  1013         return KErrNoMemory;
       
  1014         }
       
  1015     event->Copy( aEvent );
       
  1016     if( iEventArray.Append( event ) != KErrNone )
       
  1017         {
       
  1018         delete event;
       
  1019         return KErrNoMemory;
       
  1020         }
       
  1021         
       
  1022     __TRACE( KMessage,( _L( "CTestExecution::DoNotifyEvent: Req added %S ( count %i )" ), 
       
  1023          &aEvent.Name(), iEventArray.Count() ));
       
  1024     
       
  1025     return KErrNone;
       
  1026     }
       
  1027 
       
  1028 /*
       
  1029 -------------------------------------------------------------------------------
       
  1030 
       
  1031     Class: CTestExecution
       
  1032 
       
  1033     Method: WaitEvent
       
  1034 
       
  1035     Description: Handles TestModule event waits. Waiting is implemented here 
       
  1036                 and completed in NotifyEvent    
       
  1037 
       
  1038         
       
  1039     Parameters: const TEventIf& aEvent: in: Event wait  
       
  1040     
       
  1041     Return Values: TInt: Success/Error code
       
  1042 
       
  1043     Errors/Exceptions: None
       
  1044 
       
  1045     Status: Proposal
       
  1046     
       
  1047 -------------------------------------------------------------------------------
       
  1048 */    
       
  1049 TInt CTestExecution::WaitEvent( TEventIf& aEvent, TRequestStatus* aStatus )
       
  1050     {
       
  1051       
       
  1052     // Get first "free" event entry from requested events
       
  1053     TInt ind = 0;
       
  1054     TInt count = iEventArray.Count();
       
  1055     TEvent* event = NULL;
       
  1056     for( ind=0; ind < count; ind++ )
       
  1057         {
       
  1058         if( ( iEventArray[ind]->Name() == aEvent.Name() ) &&
       
  1059             ( iEventArray[ind]->WaitEventPending() == EFalse ) )
       
  1060             {
       
  1061             // Found event with correct name and one that is still free
       
  1062             // i.e. nobody is waiting for it.
       
  1063             event = iEventArray[ind];
       
  1064             if( aEvent.Type() == TEventIf::EWaitEvent )
       
  1065                 {
       
  1066                 // For EWaitEvent we complete immediately if event is pending
       
  1067                 if( event->EventPending() )
       
  1068                     {
       
  1069                     // Event was already pending, so we may return immediately
       
  1070                     if( aStatus )
       
  1071                         {
       
  1072                         TestThreadRequestComplete( aStatus, KErrNone );
       
  1073                         }
       
  1074                     return KErrNone;           
       
  1075                     }
       
  1076                 }
       
  1077             }
       
  1078         }
       
  1079     if( event == NULL )
       
  1080         {
       
  1081         // Event is not in the iEventArray, 
       
  1082         // so event is not currently requested
       
  1083         return KErrNotFound;
       
  1084         }
       
  1085         
       
  1086     __TRACE( KMessage,( _L( "CTestExecution::DoNotifyEvent: Waiting %S ( count %i )" ), 
       
  1087         &aEvent.Name(), count ));
       
  1088     
       
  1089     // Event is not pending so we have to wait for it
       
  1090     // Set wait pending            
       
  1091     TInt ret = event->SetWaitPending( aStatus );
       
  1092     // event cannot be freed by the test module, 
       
  1093     // because it is waiting the event, 
       
  1094 
       
  1095     if( ( aStatus == NULL ) &&
       
  1096         ( ret == KErrNone ) &&
       
  1097         ( aEvent.Type() == TEventIf::EWaitEvent ) ) 
       
  1098         {
       
  1099         // This is synchronous wait
       
  1100         // Go waiting, completed from set event            
       
  1101         event->Wait();
       
  1102         }
       
  1103 
       
  1104     return ret;
       
  1105     
       
  1106     } 
       
  1107     
       
  1108 /*
       
  1109 -------------------------------------------------------------------------------
       
  1110 
       
  1111     Class: CTestExecution
       
  1112 
       
  1113     Method: ReleaseEvent
       
  1114 
       
  1115     Description: Handles TestModule event releases. 
       
  1116         
       
  1117     Parameters: const TEventIf& aEvent: in: Event released  
       
  1118     
       
  1119     Return Values: TInt: Success/Error code
       
  1120 
       
  1121     Errors/Exceptions: None
       
  1122 
       
  1123     Status: Proposal
       
  1124     
       
  1125 -------------------------------------------------------------------------------
       
  1126 */   
       
  1127 TInt CTestExecution::ReleaseEvent( TEventIf& aEvent )
       
  1128     {
       
  1129     
       
  1130     // Get last event entry from requested events
       
  1131     TInt ind = 0;
       
  1132     TInt freeFound = 0;
       
  1133     TInt eventIndex = 0;
       
  1134     TInt count = iEventArray.Count();
       
  1135     for( ind=0; ind < count; ind++ )
       
  1136         {
       
  1137         if( iEventArray[ind]->Name() == aEvent.Name() )
       
  1138             {
       
  1139             if( iEventArray[ind]->WaitEventPending() == EFalse )
       
  1140                 {
       
  1141                 freeFound++;
       
  1142                 eventIndex = ind;
       
  1143                 }
       
  1144             }
       
  1145         }
       
  1146 
       
  1147     if( freeFound == 0 )
       
  1148         {
       
  1149         return KErrNotFound;
       
  1150         }
       
  1151     __TRACE( KMessage,( 
       
  1152         _L( "CTestExecution::DoNotifyEvent: Release event %S ( count %i )" ), 
       
  1153             &aEvent.Name(), iEventArray.Count() ));
       
  1154 
       
  1155     TEvent* event = iEventArray[eventIndex];
       
  1156     iEventArray.Remove( eventIndex );
       
  1157     // Release and free event entry
       
  1158     event->Release(); 
       
  1159 
       
  1160     // Delete used event entry
       
  1161     delete event;
       
  1162     
       
  1163     return KErrNone;
       
  1164 }
       
  1165 
       
  1166 /*
       
  1167 -------------------------------------------------------------------------------
       
  1168 
       
  1169     Class: CTestExecution
       
  1170 
       
  1171     Method: UnsetEvent
       
  1172 
       
  1173     Description: Handles TestModule event unsets. 
       
  1174         
       
  1175     Parameters: const TEventIf& aEvent: in: Event unset  
       
  1176     
       
  1177     Return Values: TInt: Success/Error code
       
  1178 
       
  1179     Errors/Exceptions: None
       
  1180 
       
  1181     Status: Proposal
       
  1182     
       
  1183 -------------------------------------------------------------------------------
       
  1184 */
       
  1185 TInt CTestExecution::UnsetEvent( TEventIf& aEvent, const RMessage2& aMessage )
       
  1186     {
       
  1187     
       
  1188     TInt ret = KErrNone;
       
  1189     TInt ind = 0;
       
  1190     TInt count = iEventArray.Count();
       
  1191     TBool activeEventReq = EFalse;
       
  1192     for( ind=0; ind < count; ind++ )
       
  1193         {
       
  1194         if( iEventArray[ind]->Name() == aEvent.Name() )
       
  1195             {
       
  1196              __TRACE( KMessage, ( 
       
  1197                 _L( "CTestExecution::NotifyEvent(%d): UnsetEvent %S ( count %i )" ), 
       
  1198                 this, &aEvent.Name(), count ) );
       
  1199                 
       
  1200             ret = iEventArray[ind]->Unset( aMessage, this );
       
  1201             if( ret == KErrNone )
       
  1202                 {
       
  1203                 activeEventReq = ETrue;
       
  1204                 }
       
  1205             break;
       
  1206             }
       
  1207         }
       
  1208     if( activeEventReq )
       
  1209         {
       
  1210         // Unset is completed by release   
       
  1211         return KErrNone;
       
  1212         }
       
  1213         
       
  1214     // No pending requests or error from unset
       
  1215     aMessage.Complete( ret );
       
  1216     
       
  1217     return KErrNone;
       
  1218     
       
  1219     }
       
  1220     
       
  1221 /*
       
  1222 -------------------------------------------------------------------------------
       
  1223 
       
  1224     Class: CTestExecution
       
  1225 
       
  1226     Method: EventStateChange
       
  1227 
       
  1228     Description: Handles event setting and unsetting. Saves status of
       
  1229                 state events to enable unsetting of set state events when 
       
  1230                 killing the testcase abnormally.
       
  1231         
       
  1232     Parameters: const TEventIf& aEvent: in: Event set/unset  
       
  1233     
       
  1234     Return Values: TInt: Success/Error code
       
  1235 
       
  1236     Errors/Exceptions: None
       
  1237 
       
  1238     Status: Proposal
       
  1239     
       
  1240 -------------------------------------------------------------------------------
       
  1241 */   
       
  1242 TInt CTestExecution::EventStateChange( TEventIf& aEvent )
       
  1243     {
       
  1244     
       
  1245     TInt ret = KErrNotFound;
       
  1246     if( aEvent.EventType() == TEventIf::EState )
       
  1247         {
       
  1248         
       
  1249         TInt count = iStateEvents.Count();
       
  1250         TInt index = 0;
       
  1251         for(; index < count; index++ )   
       
  1252             {
       
  1253             TPtrC name = *(iStateEvents[index]);
       
  1254             if( name == aEvent.Name() )
       
  1255                 {
       
  1256                 break;
       
  1257                 }
       
  1258             } 
       
  1259             
       
  1260                 
       
  1261         if( aEvent.Type() == TEventIf::ESetEvent )
       
  1262             {
       
  1263             if( index < count )
       
  1264                 {
       
  1265                 ret = KErrAlreadyExists;
       
  1266                 }
       
  1267             else
       
  1268                 {
       
  1269                 // add event to iStateEvents
       
  1270                 HBufC* name = aEvent.Name().Alloc();
       
  1271                 if( name == NULL )
       
  1272                     {
       
  1273                     ret = KErrNoMemory;
       
  1274                     }
       
  1275                 else if( iStateEvents.Append( name ) != KErrNone )
       
  1276                     {
       
  1277                     delete name;
       
  1278                     ret = KErrNoMemory;
       
  1279                     }
       
  1280                 else
       
  1281                     {
       
  1282                     ret = KErrNone;
       
  1283                     }
       
  1284                 }                
       
  1285             }
       
  1286         else if( aEvent.Type() == TEventIf::EUnsetEvent )
       
  1287             {
       
  1288             if( index == count )
       
  1289                 {
       
  1290                 ret = KErrNotFound;
       
  1291                 }
       
  1292             else
       
  1293                 {
       
  1294                 ret = KErrNone;
       
  1295                 delete iStateEvents[index];
       
  1296                 iStateEvents.Remove( index );
       
  1297                 }
       
  1298             }
       
  1299         }
       
  1300     
       
  1301     return ret;
       
  1302     
       
  1303     }
       
  1304 /*
       
  1305 -------------------------------------------------------------------------------
       
  1306 
       
  1307     Class: CTestExecution
       
  1308 
       
  1309     Method: CancelEvent
       
  1310 
       
  1311     Description: Cancels pending event request.
       
  1312         
       
  1313     Parameters: None
       
  1314     
       
  1315     Return Values: None
       
  1316 
       
  1317     Errors/Exceptions: None
       
  1318     
       
  1319     Status: Proposal
       
  1320     
       
  1321 -------------------------------------------------------------------------------
       
  1322 */
       
  1323 void CTestExecution::CancelEvent()
       
  1324     {
       
  1325     
       
  1326     TInt ret = KErrNotFound;
       
  1327 
       
  1328     __TRACE( KMessage, ( _L( "CTestThreadContainer::CancelEvent(%d): %S [%p]" ), 
       
  1329             iEventDef.iEvent.Type(), &iEventDef.iEvent.Name(), iEventDef.iStatus ) );
       
  1330 
       
  1331     switch( iEventDef.iEvent.Type() )
       
  1332         {
       
  1333         case TEventIf::EReqEvent:
       
  1334         case TEventIf::ERelEvent:
       
  1335         case TEventIf::ESetEvent:
       
  1336         case TEventIf::EUnsetEvent:   
       
  1337             CompleteEvent( KErrCancel );  
       
  1338             break;
       
  1339         case TEventIf::EWaitEvent:
       
  1340         case TEventIf::ESetWaitPending:
       
  1341             {
       
  1342             // Get waited event entry from requested events
       
  1343             TInt ind = 0;
       
  1344             TInt count = iEventArray.Count();
       
  1345             for( ind=0; ind < count; ind++ )
       
  1346                 {
       
  1347                 if( ( iEventArray[ind]->Name() == iEventDef.iEvent.Name() ) &&
       
  1348                     ( iEventArray[ind]->WaitEventPending() != EFalse ) &&
       
  1349                     ( iEventArray[ind]->RequestStatus() == iEventDef.iStatus ) )
       
  1350                     {
       
  1351                     TEvent* event = iEventArray[ind];
       
  1352                     // Found event with correct name and one that is waited.
       
  1353                     event->CompletePendingWait( KErrCancel ); 
       
  1354                     ret = KErrNone;
       
  1355                     break;
       
  1356                     }
       
  1357                 }
       
  1358             if( ret != KErrNone )
       
  1359                 {
       
  1360                 // Request has been already completed, not handled 
       
  1361                 // by ActiveScheduler yet.
       
  1362                 // DoCancel will do the job, don't worry.
       
  1363                 __TRACE( KError, ( _L( "CTestThreadContainer::CancelEvent(%d): %S, not found 2" ), 
       
  1364                     iEventDef.iEvent.Type(), &iEventDef.iEvent.Name() ) ); 
       
  1365                 }
       
  1366             }
       
  1367             break;
       
  1368         default:
       
  1369             CTestServer::PanicServer( EUnknownEventCmd );
       
  1370             break;
       
  1371         }
       
  1372         
       
  1373     // Synchonize
       
  1374     iEventHandler->StartL();
       
  1375         
       
  1376     }
       
  1377 
       
  1378 /*
       
  1379 -------------------------------------------------------------------------------
       
  1380 
       
  1381     Class: CTestExecution
       
  1382 
       
  1383     Method: NotifyRemoteCmd
       
  1384 
       
  1385     Description: Handles the first phase of the RemoteCmd request from engine.
       
  1386 
       
  1387     Parameters: const RMessage& aMessage: in: Message from client.
       
  1388                     
       
  1389     Return Values: Symbian OS error code.
       
  1390 
       
  1391     Errors/Exceptions: None
       
  1392 
       
  1393     Status: Proposal
       
  1394     
       
  1395 -------------------------------------------------------------------------------
       
  1396 */
       
  1397 TInt CTestExecution::NotifyRemoteCmd( const RMessage2& aMessage )
       
  1398     {   
       
  1399 
       
  1400     // Store RemoteCmd message
       
  1401     // and the length buffer address
       
  1402     iNotifyRemoteCmdMessage = aMessage;
       
  1403     iRemoteSendAvailable = ETrue;
       
  1404     iSndHandler->StartL();
       
  1405 
       
  1406     return KErrNone;
       
  1407 
       
  1408     }
       
  1409 
       
  1410 /*
       
  1411 -------------------------------------------------------------------------------
       
  1412 
       
  1413     Class: CTestExecution
       
  1414 
       
  1415     Method: DoRemoteReceive
       
  1416 
       
  1417     Description: Enable remote receive.
       
  1418     
       
  1419     Parameters: None 
       
  1420     
       
  1421     Return Values: None
       
  1422 
       
  1423     Errors/Exceptions: None
       
  1424 
       
  1425     Status: Proposal
       
  1426     
       
  1427 -------------------------------------------------------------------------------
       
  1428 */
       
  1429 void CTestExecution::DoRemoteReceive()
       
  1430     {    
       
  1431 
       
  1432     switch( iRcvCmdDef.iCommand )
       
  1433         {
       
  1434         case EStifCmdReceive:          // "Receive"
       
  1435             {
       
  1436             // @js If there's pointer in array, we'll send it down
       
  1437             if(iMessageQueue.Count() > 0)
       
  1438                 {
       
  1439                 HBufC8 * buf =  iMessageQueue[0];
       
  1440                 iRcvCmdDef.iParam.aRemoteMsgRef->Copy( iMessageQueue[0]->Des() );
       
  1441                 iMessageQueue.Remove(0);
       
  1442                 delete buf; 
       
  1443                 __TRACE( KMessage, 
       
  1444                         (_L("CTestExecution::ReadRemoteCmdInfo: complete receive 0x%x"), 
       
  1445                             iRcvCmdDef.iStatus ));
       
  1446                        
       
  1447                  // calls the TestCombiner's CRemoteReceiver::RunL()
       
  1448                  TestThreadRequestComplete( iRcvCmdDef.iStatus, KErrNone );
       
  1449                 }
       
  1450             else
       
  1451                 {
       
  1452                 iRemoteReceiveAvailable = ETrue;            
       
  1453                 }
       
  1454 
       
  1455             break;
       
  1456             }
       
  1457         case EStifCmdReceiveCancel:
       
  1458             if( iRemoteReceiveAvailable )
       
  1459                 {
       
  1460                 iRemoteReceiveAvailable = EFalse;
       
  1461                 TestThreadRequestComplete( iRcvCmdDef.iStatus, KErrCancel );
       
  1462                 }                
       
  1463             break;
       
  1464         default:
       
  1465             CTestServer::PanicServer( EUnknownRemoteCmd );
       
  1466             break;
       
  1467         }
       
  1468     // Signal test thread
       
  1469     iRcvHandler->StartL();
       
  1470 
       
  1471     }
       
  1472 
       
  1473 /*
       
  1474 -------------------------------------------------------------------------------
       
  1475 
       
  1476     Class: CTestExecution
       
  1477 
       
  1478     Method: DoRemoteSend
       
  1479 
       
  1480     Description: Send remote messages.
       
  1481     
       
  1482     Parameters: None 
       
  1483     
       
  1484     Return Values: None
       
  1485 
       
  1486     Errors/Exceptions: None
       
  1487 
       
  1488     Status: Approved
       
  1489     
       
  1490 -------------------------------------------------------------------------------
       
  1491 */
       
  1492 void CTestExecution::DoRemoteSend()
       
  1493     {  
       
  1494     switch( iCmdDef.iCommand )
       
  1495         {  
       
  1496         case EStifCmdSend:             // "Send"
       
  1497         case EStifCmdReboot:           // "Send"
       
  1498         case EStifCmdStoreState:       // "Send"
       
  1499         case EStifCmdGetStoredState:   // "Receive, this must be done with two phase"
       
  1500         case EStifCmdMeasurement:      // "Receive, this must be done with two phase"
       
  1501             {
       
  1502             if( iRemoteSendAvailable )
       
  1503                 {
       
  1504                 TInt ret = KErrNone;
       
  1505                 TPckg<TStifCommand> remoteCommandPckg( iCmdDef.iCommand );
       
  1506 
       
  1507                 // Start first phase of the writing message to client space
       
  1508                 TRAP( ret, 
       
  1509                     iNotifyRemoteCmdMessage.WriteL( 0, remoteCommandPckg ) );
       
  1510 
       
  1511                 if( ret != KErrNone )
       
  1512                     {
       
  1513                     __TRACE( KError, ( _L( "CTestExecution::DoRemoteSend: WriteL failed" ) ) );
       
  1514                     }
       
  1515                 TPckg<TInt> lenPckg( iCmdDef.iLen );
       
  1516 
       
  1517                 TRAP( ret, 
       
  1518                     iNotifyRemoteCmdMessage.WriteL( 1, lenPckg ) );
       
  1519 
       
  1520                 if( ret != KErrNone )
       
  1521                     {
       
  1522                     __TRACE( KError, ( _L( "CTestExecution::DoRemoteSend: WriteL failed" ) ) );
       
  1523                     }
       
  1524 
       
  1525                 // Complete request
       
  1526                 // Complete with WriteL result
       
  1527                 // CTestRemoteCmdNotifier::RunL() will called
       
  1528                 iRemoteSendAvailable = EFalse;
       
  1529                 iNotifyRemoteCmdMessage.Complete( ret );
       
  1530                 break;
       
  1531                 }
       
  1532             }
       
  1533             TestThreadRequestComplete( iCmdDef.iStatus, KErrNotSupported );
       
  1534             break;
       
  1535         default:
       
  1536             CTestServer::PanicServer( EUnknownRemoteCmd );
       
  1537             break;
       
  1538         }
       
  1539 
       
  1540     }
       
  1541 
       
  1542 
       
  1543 /*
       
  1544 -------------------------------------------------------------------------------
       
  1545 
       
  1546     Class: CTestExecution
       
  1547 
       
  1548     Method: ReadRemoteCmdInfo
       
  1549 
       
  1550     Description: Handles the second phase of the RemoteCmd request from engine.
       
  1551 
       
  1552     Parameters: const RMessage& aMessage: in: Message from client.
       
  1553                     
       
  1554     Return Values: Symbian OS error code.
       
  1555 
       
  1556     Errors/Exceptions: None
       
  1557 
       
  1558     Status: Proposal
       
  1559     
       
  1560 -------------------------------------------------------------------------------
       
  1561 */
       
  1562 TInt CTestExecution::ReadRemoteCmdInfo( const RMessage2& aMessage )
       
  1563     {   
       
  1564     
       
  1565     TInt ret( KErrNone );
       
  1566     TInt completeSend = EFalse;
       
  1567     TInt returnedErrorCode = KErrNone;
       
  1568     TInt len = 0;
       
  1569     TInt value( aMessage.Int2() );
       
  1570     if( value < 0 )
       
  1571         {
       
  1572         returnedErrorCode = value;
       
  1573         }
       
  1574     else
       
  1575         {
       
  1576         len = value;
       
  1577         }
       
  1578   
       
  1579     switch( aMessage.Int1() )
       
  1580         {
       
  1581         case EStifCmdReceive:              // "Receive"
       
  1582             {
       
  1583 
       
  1584                 if( len <= 0 )
       
  1585                     {
       
  1586                     __TRACE( KError, 
       
  1587                         (_L("CTestExecution::ReadRemoteCmdInfo: empty message")));
       
  1588                     ret = KErrGeneral;
       
  1589                     break;
       
  1590                     }
       
  1591                 if( iRcvCmdDef.iParam.aRemoteMsgRef->MaxLength() < len )
       
  1592                     {
       
  1593                     __TRACE( KError, 
       
  1594                         (_L("CTestExecution::ReadRemoteCmdInfo: message overflow")));
       
  1595                     ret = KErrGeneral;
       
  1596                     break;
       
  1597                     }
       
  1598 
       
  1599                 HBufC8* buf = HBufC8::New( len );
       
  1600                 if( buf == NULL )
       
  1601                     { 
       
  1602                     ret = KErrNoMemory;
       
  1603                     break;
       
  1604                     }
       
  1605                 TPtr8 tmp = buf->Des();
       
  1606                 // Read message from client space
       
  1607                 TRAP( ret, aMessage.ReadL( 0, tmp ) );
       
  1608 
       
  1609                 
       
  1610                 if( ret != KErrNone )
       
  1611                     {
       
  1612                     __TRACE( KError, 
       
  1613                         (_L("CTestExecution::ReadRemoteCmdInfo: ReadL failed")));
       
  1614                     break;
       
  1615                     }
       
  1616                     
       
  1617                 if( iRemoteReceiveAvailable )
       
  1618                 // @js Checking moved here
       
  1619                     {                                   
       
  1620                     iRcvCmdDef.iParam.aRemoteMsgRef->Copy( buf->Des() );
       
  1621                     delete buf;
       
  1622                 
       
  1623                     __TRACE( KMessage, 
       
  1624                         (_L("CTestExecution::ReadRemoteCmdInfo: complete receive 0x%x"), 
       
  1625                             iRcvCmdDef.iStatus ));
       
  1626                     // calls the TestCombiner's CRemoteReceiver::RunL()
       
  1627                     TestThreadRequestComplete( iRcvCmdDef.iStatus, ret );
       
  1628                     
       
  1629                     iRemoteReceiveAvailable = EFalse;
       
  1630                     }
       
  1631                 else
       
  1632                 // @js Adding buf to RPointerArray, handling it in DoRemoteReceive function
       
  1633                     {
       
  1634                    iMessageQueue.Append( buf );
       
  1635                     } 
       
  1636                 
       
  1637             break;
       
  1638             }
       
  1639         case EStifCmdSend:                 // "Send"
       
  1640             {
       
  1641             HBufC8* buf = HBufC8::New( iCmdDef.iParam.aRemoteMsgConstRef->Length() );
       
  1642             if( buf == NULL )
       
  1643                 { 
       
  1644                 ret = KErrNoMemory;
       
  1645                 break;
       
  1646                 }
       
  1647             TPtr8 tmp = buf->Des();
       
  1648             tmp.Copy( *iCmdDef.iParam.aRemoteMsgConstRef );
       
  1649             // Second phase of the writing. Write information to the Engine.
       
  1650             TRAP( ret, aMessage.WriteL( 0, tmp ) );
       
  1651 
       
  1652             delete buf;
       
  1653             
       
  1654             if( ret != KErrNone )
       
  1655                 {
       
  1656                 __TRACE( KError, ( _L( "CTestExecution::ReadRemoteCmdInfo: WriteL failed" ) ) );
       
  1657                 }
       
  1658             completeSend = ETrue;
       
  1659             break;
       
  1660             }
       
  1661         case EStifCmdReboot:               // "Send"
       
  1662             {
       
  1663             TRebootParamsPckg remoteTypePckg( *iCmdDef.iParam.aRebootType );
       
  1664 
       
  1665             // Second phase of the writing. Write information to the Engine.
       
  1666             TRAP( ret, aMessage.WriteL( 0, remoteTypePckg ) );
       
  1667 
       
  1668             if( ret != KErrNone )
       
  1669                 {
       
  1670                 __TRACE( KError, ( _L( "CTestExecution::ReadRemoteCmdInfo: WriteL failed" ) ) );
       
  1671                 }
       
  1672             // Because Reboot must block...Don't complete, so now we wait for
       
  1673             // ever phone booting operation !!!!!
       
  1674             break;
       
  1675             }
       
  1676         case EStifCmdStoreState:          // "Send"
       
  1677             {
       
  1678             TRebootStateParamsPckg remoteStatePckg( *iCmdDef.iParam.aRebootState );
       
  1679 
       
  1680             // Second phase of the writing. Write information to the Engine.
       
  1681             TRAP( ret, aMessage.WriteL( 0, remoteStatePckg ) );
       
  1682 
       
  1683             if( ret != KErrNone )
       
  1684                 {
       
  1685                 __TRACE( KError, ( _L( "CTestExecution::ReadRemoteCmdInfo: WriteL failed" ) ) );
       
  1686                 }
       
  1687             // Completed from EStifCmdRebootProceed
       
  1688             break;
       
  1689             }
       
  1690         case EStifCmdMeasurement:   // "Receive"
       
  1691             {
       
  1692             TGetMeasurementOptions getMeasurementOptions;
       
  1693             TGetMeasurementOptionsPckg measurementParamsPckg( getMeasurementOptions );
       
  1694 
       
  1695             // Read message from client space
       
  1696             TRAP( ret, aMessage.ReadL( 0, measurementParamsPckg ) );
       
  1697 
       
  1698             if( ret != KErrNone )
       
  1699                 {
       
  1700                 __TRACE( KError, ( _L( "CTestExecution::ReadRemoteCmdInfo: ReadL failed" ) ) );
       
  1701                 }
       
  1702             iCmdDef.iParam.aMeasurementOption->iOptions = getMeasurementOptions.iOptions;
       
  1703 
       
  1704             completeSend = ETrue;
       
  1705             break;
       
  1706             }
       
  1707         case EStifCmdGetStoredState:   // "Receive"
       
  1708             {
       
  1709             TGetRebootStoredParams getRebootStoredParams;
       
  1710             TGetRebootStoredParamsPckg rebootStoredParamsPckg( getRebootStoredParams );
       
  1711 
       
  1712             // Read message from client space
       
  1713             TRAP( ret, aMessage.ReadL( 0, rebootStoredParamsPckg ) );
       
  1714 
       
  1715             if( ret != KErrNone )
       
  1716                 {
       
  1717                 __TRACE( KError, ( _L( "CTestExecution::ReadRemoteCmdInfo: ReadL failed" ) ) );
       
  1718                 }
       
  1719             iCmdDef.iParam.aRebootStoredRef->iCode = getRebootStoredParams.aCode;
       
  1720             iCmdDef.iParam.aRebootStoredRef->iName = getRebootStoredParams.aName;
       
  1721 
       
  1722             completeSend = ETrue;
       
  1723             break;
       
  1724             }
       
  1725         case EStifCmdRebootProceed:          
       
  1726             {
       
  1727             completeSend = ETrue; // Complete EStifCmdStoreState
       
  1728             }
       
  1729             break;
       
  1730         default:
       
  1731             {
       
  1732             iModuleSession->PanicClient( EUnknownRemoteCmd, aMessage );
       
  1733             break;
       
  1734             }
       
  1735         }
       
  1736     // Complete request with ret
       
  1737     aMessage.Complete( ret ); 
       
  1738 
       
  1739     if( completeSend )
       
  1740         {
       
  1741         // Calls the TestCombiner's CRemoteReceiver::RunL() and
       
  1742         // returns error code to test module.
       
  1743         TestThreadRequestComplete( iCmdDef.iStatus, returnedErrorCode );
       
  1744         }
       
  1745         
       
  1746     return KErrNone;
       
  1747 
       
  1748     }
       
  1749 
       
  1750 /*
       
  1751 -------------------------------------------------------------------------------
       
  1752 
       
  1753     Class: CTestExecution
       
  1754 
       
  1755     Method: Pause
       
  1756 
       
  1757     Description: Pauses a test case
       
  1758 
       
  1759     Only ongoing tests can be paused. If test is not ongoing, then
       
  1760     function does nothing.
       
  1761 
       
  1762     Parameters: const RMessage& aMessage      :in:  Message from client.
       
  1763     
       
  1764     Return Values: TInt                             Always KErrNone
       
  1765 
       
  1766     Errors/Exceptions: None
       
  1767 
       
  1768     Status: Proposal
       
  1769 
       
  1770 -------------------------------------------------------------------------------
       
  1771 */
       
  1772 TInt CTestExecution::Pause( const RMessage2& aMessage )
       
  1773     {
       
  1774 
       
  1775     __TRACE ( KThreadOperation, ( _L( "CTestExecution::Pause" ) ) );
       
  1776 
       
  1777     TInt completionCode = KErrNone;
       
  1778 
       
  1779     // Note that it is allowed to suspend already suspended thread, so
       
  1780     // there is no need for states to verify that thread is really in
       
  1781     // resumed state.
       
  1782     switch ( iThreadState )
       
  1783         {
       
  1784         case EOnGoing:
       
  1785             completionCode = iModuleContainer->PauseThread();
       
  1786             break;
       
  1787 
       
  1788         case ENotStarted:
       
  1789             completionCode = KErrNotReady;
       
  1790             break;
       
  1791 
       
  1792         case EFinished:
       
  1793         case ECancelled:
       
  1794             completionCode = KErrCompletion;
       
  1795             break;
       
  1796 
       
  1797         default:
       
  1798             CTestServer::PanicServer( EInvalidThreadState );
       
  1799             break;
       
  1800         }
       
  1801 
       
  1802 
       
  1803     // Complete the request
       
  1804     aMessage.Complete( completionCode );
       
  1805 
       
  1806     return KErrNone;
       
  1807 
       
  1808     }
       
  1809 
       
  1810 
       
  1811 /*
       
  1812 -------------------------------------------------------------------------------
       
  1813 
       
  1814     Class: CTestExecution
       
  1815 
       
  1816     Method: Resume
       
  1817 
       
  1818     Description: Resumes a test case. If test is not ongoing,
       
  1819     then do not resume.
       
  1820 
       
  1821     Parameters: const RMessage& aMessage      :in:  Message from client.
       
  1822     
       
  1823     Return Values: TInt                             Always KErrNone
       
  1824 
       
  1825     Errors/Exceptions: None
       
  1826 
       
  1827     Status: Proposal
       
  1828 
       
  1829 -------------------------------------------------------------------------------
       
  1830 */
       
  1831 TInt CTestExecution::Resume( const RMessage2& aMessage )
       
  1832     {
       
  1833 
       
  1834     __TRACE ( KThreadOperation, ( _L( "CTestExecution::Resume" ) ) );
       
  1835 
       
  1836     TInt completionCode = KErrNone;
       
  1837 
       
  1838     // Note that it is allowed to resume already resumed thread, so
       
  1839     // there is no need for states to verify that thread is really in
       
  1840     // suspended state.
       
  1841     switch ( iThreadState )
       
  1842         {
       
  1843         case EOnGoing:
       
  1844             completionCode = iModuleContainer->ResumeThread();
       
  1845             break;
       
  1846 
       
  1847         case ENotStarted:
       
  1848             completionCode = KErrNotReady;
       
  1849             break;
       
  1850 
       
  1851         case EFinished:
       
  1852         case ECancelled:
       
  1853             completionCode = KErrCompletion;
       
  1854             break;
       
  1855 
       
  1856         default:
       
  1857             CTestServer::PanicServer( EInvalidThreadState );
       
  1858             break;
       
  1859         }
       
  1860 
       
  1861 
       
  1862     // Complete the request
       
  1863     aMessage.Complete( completionCode );
       
  1864 
       
  1865     return KErrNone;
       
  1866 
       
  1867     }
       
  1868 
       
  1869 /*
       
  1870 -------------------------------------------------------------------------------
       
  1871 
       
  1872     Class: CTestExecution
       
  1873 
       
  1874     Method: CloseTestExecution
       
  1875 
       
  1876     Description: Closes Test Execution subsession
       
  1877 
       
  1878     Parameters: const RMessage& aMessage      :in:  Message from client.
       
  1879     
       
  1880     Return Values: TInt                             Always KErrNone
       
  1881 
       
  1882     Errors/Exceptions: None
       
  1883 
       
  1884     Status: Proposal
       
  1885     
       
  1886 -------------------------------------------------------------------------------
       
  1887 */
       
  1888 TInt CTestExecution::CloseTestExecution( const RMessage2& aMessage )
       
  1889     {
       
  1890 
       
  1891     // Cancel test request
       
  1892     CancelTestRequest();
       
  1893 
       
  1894     // Cancel print request
       
  1895     CancelPrintRequest();
       
  1896     
       
  1897     // Cancel event request
       
  1898     CancelEventRequest();
       
  1899 
       
  1900     // Delete this subsession
       
  1901     const TUint subsession = aMessage.Int3();
       
  1902     iModuleSession->DeleteTestExecution( subsession, aMessage );
       
  1903 
       
  1904     // Complete the request
       
  1905     aMessage.Complete( KErrNone );
       
  1906 
       
  1907     return KErrNone;
       
  1908 
       
  1909     }
       
  1910 
       
  1911 
       
  1912 /*
       
  1913 -------------------------------------------------------------------------------
       
  1914 
       
  1915     Class: CTestExecution
       
  1916 
       
  1917     Method: CancelPrintRequest
       
  1918 
       
  1919     Description: Cancel print request. Completes ongoing print request
       
  1920     with KErrCancel.
       
  1921 
       
  1922     Parameters: None
       
  1923     
       
  1924     Return Values: TInt                             Always KErrNone
       
  1925 
       
  1926     Errors/Exceptions: None
       
  1927 
       
  1928     Status: Proposal
       
  1929     
       
  1930 -------------------------------------------------------------------------------
       
  1931 */
       
  1932 TInt CTestExecution::CancelPrintRequest()
       
  1933     {
       
  1934 
       
  1935     if ( iPrintNotifyAvailable )
       
  1936         {
       
  1937         iPrintHandler->Cancel();
       
  1938         
       
  1939         iPrintNotifyAvailable = EFalse;
       
  1940         iNotifyPrintMessage.Complete ( KErrCancel );
       
  1941         //@spe iPrintNotifyAvailable = EFalse;
       
  1942         }
       
  1943 
       
  1944     return KErrNone;
       
  1945 
       
  1946     }
       
  1947 
       
  1948 /*
       
  1949 -------------------------------------------------------------------------------
       
  1950 
       
  1951     Class: CTestExecution
       
  1952 
       
  1953     Method: CancelEventRequest
       
  1954 
       
  1955     Description: Cancel event request. Completes ongoing event request
       
  1956     with KErrCancel.
       
  1957 
       
  1958     Parameters: None
       
  1959     
       
  1960     Return Values: TInt                             Always KErrNone
       
  1961 
       
  1962     Errors/Exceptions: None
       
  1963 
       
  1964     Status: Proposal
       
  1965     
       
  1966 -------------------------------------------------------------------------------
       
  1967 */
       
  1968 TInt CTestExecution::CancelEventRequest()
       
  1969     {
       
  1970     iEventHandler->Cancel();
       
  1971 
       
  1972     if( iEventNotifyAvailable )
       
  1973         {
       
  1974         // Cancel request
       
  1975         iEventNotifyAvailable = EFalse;
       
  1976         iNotifyEventMessage.Complete ( KErrCancel );
       
  1977         }
       
  1978 
       
  1979     return KErrNone;
       
  1980 
       
  1981     }
       
  1982 
       
  1983 /*
       
  1984 -------------------------------------------------------------------------------
       
  1985 
       
  1986     Class: CTestExecution
       
  1987 
       
  1988     Method: CancelInterferenceRequest
       
  1989 
       
  1990     Description: Cancel print request. Completes ongoing print request
       
  1991     with KErrCancel.
       
  1992 
       
  1993     Parameters: None
       
  1994 
       
  1995     Return Values: TInt: Always KErrNone
       
  1996 
       
  1997     Errors/Exceptions: None
       
  1998 
       
  1999     Status: Proposal
       
  2000     
       
  2001 -------------------------------------------------------------------------------
       
  2002 */
       
  2003 TInt CTestExecution::CancelInterferenceRequest()
       
  2004     {
       
  2005 
       
  2006     if ( iInterferenceNotifyAvailable )
       
  2007         {
       
  2008         iInterferenceHandler->Cancel();
       
  2009         
       
  2010         iInterferenceNotifyAvailable = EFalse;
       
  2011         iNotifyInterferenceMessage.Complete ( KErrCancel );
       
  2012         }
       
  2013 
       
  2014     return KErrNone;
       
  2015 
       
  2016     }
       
  2017 
       
  2018 /*
       
  2019 -------------------------------------------------------------------------------
       
  2020 
       
  2021     Class: CTestExecution
       
  2022 
       
  2023     Method: CancelRemoteCmdRequest
       
  2024 
       
  2025     Description: Cancel RemoteCmd request. Completes ongoing RemoteCmd request
       
  2026         with KErrCancel.
       
  2027 
       
  2028     Parameters: None
       
  2029     
       
  2030     Return Values: TInt: Always KErrNone
       
  2031 
       
  2032     Errors/Exceptions: None
       
  2033 
       
  2034     Status: Proposal
       
  2035     
       
  2036 -------------------------------------------------------------------------------
       
  2037 */
       
  2038 TInt CTestExecution::CancelRemoteCmdRequest()
       
  2039     {
       
  2040     iSndHandler->Cancel();
       
  2041 
       
  2042     // Cancel request
       
  2043     if( iRemoteSendAvailable )
       
  2044         {
       
  2045         iRemoteSendAvailable = EFalse;
       
  2046         iNotifyRemoteCmdMessage.Complete ( KErrCancel );
       
  2047         }
       
  2048 
       
  2049     return KErrNone;
       
  2050 
       
  2051     }
       
  2052 
       
  2053 /*
       
  2054 -------------------------------------------------------------------------------
       
  2055 
       
  2056     Class: CTestExecution
       
  2057 
       
  2058     Method: NotifyCommand
       
  2059 
       
  2060     Description: Handles the first phase of the Command request from engine.
       
  2061 
       
  2062     Parameters: const RMessage& aMessage: in: Message from client.
       
  2063 
       
  2064     Return Values: Symbian OS error code.
       
  2065 
       
  2066     Errors/Exceptions: None
       
  2067 
       
  2068     Status: Proposal
       
  2069 
       
  2070 -------------------------------------------------------------------------------
       
  2071 */
       
  2072 TInt CTestExecution::NotifyCommand( const RMessage2& aMessage )
       
  2073     {
       
  2074     iNotifyCommandMessage = aMessage;
       
  2075     iCommandNotifyAvailable = ETrue;
       
  2076     iCommandHandler->StartL();
       
  2077 
       
  2078     return KErrNone;
       
  2079     }
       
  2080 
       
  2081 /*
       
  2082 -------------------------------------------------------------------------------
       
  2083 
       
  2084     Class: CTestExecution
       
  2085 
       
  2086     Method: CancelCommandRequest
       
  2087 
       
  2088     Description: Cancel Command request. Completes ongoing Command request
       
  2089         with KErrCancel.
       
  2090 
       
  2091     Parameters: None
       
  2092 
       
  2093     Return Values: TInt: Always KErrNone
       
  2094 
       
  2095     Errors/Exceptions: None
       
  2096 
       
  2097     Status: Proposal
       
  2098 
       
  2099 -------------------------------------------------------------------------------
       
  2100 */
       
  2101 TInt CTestExecution::CancelCommandRequest()
       
  2102     {
       
  2103     iCommandHandler->Cancel();
       
  2104 
       
  2105     // Cancel request
       
  2106     if(iCommandNotifyAvailable)
       
  2107         {
       
  2108         iCommandNotifyAvailable = EFalse;
       
  2109         iNotifyCommandMessage.Complete(KErrCancel);
       
  2110         }
       
  2111 
       
  2112     return KErrNone;
       
  2113     }
       
  2114 
       
  2115 /*
       
  2116 -------------------------------------------------------------------------------
       
  2117 
       
  2118     Class: CTestExecution
       
  2119 
       
  2120     Method: CancelTestRequest
       
  2121 
       
  2122     Description: Cancel test execution request.
       
  2123     If thread is not in OnGoing state, function does not do anything.
       
  2124 
       
  2125     Otherwise following operations are done:
       
  2126     1 ) Obtain access to both  PrintMutex and EventMutex to make sure that
       
  2127        thread can't be accessing print queue or events.
       
  2128     2 ) Kill the thread
       
  2129     3 ) Complete original "RunTestCase" request with KErrCancel
       
  2130     4 ) If print queue is empty, complete print request
       
  2131     5 ) Give up mutexes
       
  2132     6 ) Delete module container
       
  2133 
       
  2134     Parameters: None
       
  2135     
       
  2136     Return Values: TInt: Always KErrNone
       
  2137 
       
  2138     Errors/Exceptions: None
       
  2139 
       
  2140     Status: Approved
       
  2141     
       
  2142 -------------------------------------------------------------------------------
       
  2143 */
       
  2144 TInt CTestExecution::CancelTestRequest()
       
  2145     {
       
  2146     // This mutex block and make sure that cancel operation is done succesfully
       
  2147     // and test case e.g. cannot complete at the same time. Get mutex.
       
  2148     iTestThreadMutex.Wait();
       
  2149 
       
  2150     // iModuleContainer is an active object, check is active.
       
  2151     if ( iModuleContainer == NULL || ( iModuleContainer != NULL && !iModuleContainer->IsActive() ) )
       
  2152         {
       
  2153         // Test case is already ready, return.
       
  2154         iTestThreadMutex.Signal();
       
  2155         return KErrNone;
       
  2156         }
       
  2157 
       
  2158     if ( iThreadState == EOnGoing )
       
  2159         {
       
  2160         // Print mutex access is required to make sure that the dying thread
       
  2161         // does not have access to print queue. Same is true for event queue.
       
  2162 
       
  2163         // NOTE: iEventArrayMutex is now taken, so the ongoing thread
       
  2164         // can't set any events so queue will be empty.
       
  2165         iPrintHandler->Cancel();
       
  2166         iEventHandler->Cancel();
       
  2167         iInterferenceHandler->Cancel();
       
  2168         iCommandHandler->Cancel();
       
  2169 
       
  2170         // Kill the thread
       
  2171         iModuleContainer->KillThread( KErrCancel );
       
  2172 
       
  2173         // Complete the test execution request
       
  2174         CompleteTestExecution( KErrCancel, TFullTestResult::ECaseCancelled, 
       
  2175                                KErrCancel, KErrCancel, _L( "Cancelled" ) );
       
  2176         iThreadState = ECancelled;
       
  2177 
       
  2178        
       
  2179         /**        
       
  2180         * Removed, because may block in certain situations. Implemented now in
       
  2181         * TestCombiner instead.
       
  2182         // Unset all pending state events, 
       
  2183         // because we have killed the testcase abnormally
       
  2184         // UnsetStateEvents();
       
  2185         */
       
  2186         
       
  2187         // Complete print request if queue is empty
       
  2188         CompletePrintRequestIfQueueEmpty();
       
  2189         
       
  2190         // Delete the module containter
       
  2191         delete iModuleContainer;
       
  2192         iModuleContainer = NULL;
       
  2193         }
       
  2194         
       
  2195     // Relinquish mutex.
       
  2196     iTestThreadMutex.Signal();
       
  2197 
       
  2198     return KErrNone;
       
  2199 
       
  2200     }
       
  2201 
       
  2202 /*
       
  2203 -------------------------------------------------------------------------------
       
  2204 
       
  2205     Class: CTestExecution
       
  2206 
       
  2207     Method: CancelRequestL
       
  2208 
       
  2209     Description: Cancel asynchronous request
       
  2210 
       
  2211     Parameters: const RMessage& aMessage      :in:  Message from client.
       
  2212     
       
  2213     Return Values: TInt                             Error code from CancelXXX-
       
  2214                                                     function
       
  2215 
       
  2216     Errors/Exceptions: Function panics the client, if invalid message
       
  2217                        received.
       
  2218 
       
  2219     Status: Proposal
       
  2220     
       
  2221 -------------------------------------------------------------------------------
       
  2222 */
       
  2223 TInt CTestExecution::CancelRequestL( const RMessage2& aMessage )
       
  2224     {
       
  2225     TInt r = KErrNone;
       
  2226 
       
  2227     switch ( aMessage.Int0() )
       
  2228         {
       
  2229         case ETestExecutionRunTestCase:
       
  2230             {
       
  2231             r = CancelTestRequest();
       
  2232             break;
       
  2233             }
       
  2234         case ETestExecutionNotifyProgress:
       
  2235             {
       
  2236             r = CancelPrintRequest();
       
  2237             break;
       
  2238             }
       
  2239         case ETestExecutionNotifyEvent:
       
  2240             {
       
  2241             r = CancelEventRequest();
       
  2242             break;
       
  2243             }
       
  2244         case ETestExecutionNotifyRemoteCmd:
       
  2245             {
       
  2246             r = CancelRemoteCmdRequest();
       
  2247             break;
       
  2248             }
       
  2249         case ETestExecutionNotifyCommand:
       
  2250             {
       
  2251             r = CancelCommandRequest();
       
  2252             break;
       
  2253             }
       
  2254         default:
       
  2255             iModuleSession->PanicClient( EInvalidRequestCancel, aMessage );
       
  2256             break;
       
  2257         }
       
  2258 
       
  2259     aMessage.Complete( r );
       
  2260 
       
  2261     return r;
       
  2262 
       
  2263     }
       
  2264 
       
  2265 /*
       
  2266 -------------------------------------------------------------------------------
       
  2267 
       
  2268     Class: CTestExecution
       
  2269 
       
  2270     Method: SetThreadState
       
  2271 
       
  2272     Description: A multithread safe thread state modification function
       
  2273 
       
  2274     Parameters: const TTestState aState       :in:  New state
       
  2275     
       
  2276     Return Values: None
       
  2277 
       
  2278     Errors/Exceptions: None
       
  2279 
       
  2280     Status: Proposal
       
  2281     
       
  2282 -------------------------------------------------------------------------------
       
  2283 */
       
  2284 void CTestExecution::SetThreadState( const TTestState aState )
       
  2285     {
       
  2286 
       
  2287     iThreadState = aState;
       
  2288 
       
  2289     }
       
  2290 
       
  2291 /*
       
  2292 -------------------------------------------------------------------------------
       
  2293 
       
  2294     Class: CTestExecution
       
  2295 
       
  2296     Method: Complete event
       
  2297 
       
  2298     Description: Completes pending event request. Must be 
       
  2299         called with iEventSem taken.
       
  2300         
       
  2301     Parameters: None
       
  2302     
       
  2303     Return Values: None
       
  2304 
       
  2305     Errors/Exceptions: None
       
  2306     
       
  2307     Status: Proposal
       
  2308     
       
  2309 -------------------------------------------------------------------------------
       
  2310 */
       
  2311 void CTestExecution::CompleteEvent( TInt aError )
       
  2312     {
       
  2313     if( iEventDef.iStatus )
       
  2314         {
       
  2315         __TRACE( KMessage,(_L("Comp Stat %d, %x (error %d)"), 
       
  2316             this, iEventDef.iStatus, aError));
       
  2317         TestThreadRequestComplete( iEventDef.iStatus, aError );
       
  2318         
       
  2319         iEventDef.iStatus = NULL;
       
  2320         
       
  2321         }
       
  2322         
       
  2323     }
       
  2324     
       
  2325 /*
       
  2326 -------------------------------------------------------------------------------
       
  2327 
       
  2328     Class: CTestExecution
       
  2329 
       
  2330     Method: CompletePrintRequestIfQueueEmpty
       
  2331 
       
  2332     Description: Completes print request if queue is empty.
       
  2333 
       
  2334     Parameters: None
       
  2335     
       
  2336     Return Values: None
       
  2337 
       
  2338     Errors/Exceptions: None
       
  2339 
       
  2340     Status: Proposal
       
  2341     
       
  2342 -------------------------------------------------------------------------------
       
  2343 */
       
  2344 void CTestExecution::CompletePrintRequestIfQueueEmpty()
       
  2345     {
       
  2346 
       
  2347     if ( iPrintNotifyAvailable &&  iPrintQueue->Count() == 0 )
       
  2348         {
       
  2349         iNotifyPrintMessage.Complete ( KErrEof );
       
  2350         iPrintNotifyAvailable = EFalse;
       
  2351         }
       
  2352 
       
  2353     }
       
  2354 
       
  2355 /*
       
  2356 -------------------------------------------------------------------------------
       
  2357 
       
  2358     Class: CTestExecution
       
  2359 
       
  2360     Method: CleanupEvents
       
  2361 
       
  2362     Description: Cleanups Events.
       
  2363 
       
  2364     Parameters: None
       
  2365     
       
  2366     Return Values: None
       
  2367 
       
  2368     Errors/Exceptions: None
       
  2369 
       
  2370     Status: Proposal
       
  2371     
       
  2372 -------------------------------------------------------------------------------
       
  2373 */
       
  2374 void CTestExecution::CleanupEvents()
       
  2375     {
       
  2376     
       
  2377     iEventArray.ResetAndDestroy();
       
  2378     
       
  2379     }
       
  2380     
       
  2381 /*
       
  2382 -------------------------------------------------------------------------------
       
  2383 
       
  2384     Class: CTestExecution
       
  2385 
       
  2386     Method: GetRq
       
  2387 
       
  2388     Description: Get request pointers.
       
  2389 
       
  2390     Parameters: None
       
  2391 
       
  2392     Return Values: TRequestStatus*
       
  2393 
       
  2394     Errors/Exceptions: None
       
  2395 
       
  2396     Status: Approved
       
  2397     
       
  2398 -------------------------------------------------------------------------------
       
  2399 */
       
  2400 TRequestStatus* CTestExecution::GetRq( TRequestType aType )
       
  2401     {
       
  2402 
       
  2403     TRequestStatus* status = NULL;
       
  2404 
       
  2405     switch( aType )
       
  2406         {
       
  2407         case ERqPrint:
       
  2408             status = &iPrintHandler->iStatus;
       
  2409             break;
       
  2410         case ERqEvent:
       
  2411             status = &iEventHandler->iStatus;
       
  2412             break;
       
  2413         case ERqSnd:
       
  2414             status = &iSndHandler->iStatus;
       
  2415             break;
       
  2416         case ERqRcv:
       
  2417             status = &iRcvHandler->iStatus;
       
  2418             break;
       
  2419         case ERqInterference:
       
  2420             status = &iInterferenceHandler->iStatus;
       
  2421             break;
       
  2422         case ERqMeasurement:
       
  2423             status = &iMeasurementHandler->iStatus;
       
  2424             break;
       
  2425         case ERqCommand:
       
  2426             status = &iCommandHandler->iStatus;
       
  2427             break;
       
  2428         default:
       
  2429             break;
       
  2430         }
       
  2431 
       
  2432     return status;
       
  2433 
       
  2434     }
       
  2435 
       
  2436 
       
  2437 /*
       
  2438 -------------------------------------------------------------------------------
       
  2439 
       
  2440     Class: CTestExecution
       
  2441 
       
  2442     Method: CompleteTestExecution
       
  2443 
       
  2444     Description: Completes test execution
       
  2445 
       
  2446     Parameters: const TInt aCompletionCode    :in:  Request completion code
       
  2447                 const TInt aCaseExecutionCode  in:  Case execution code
       
  2448                 const TFullTestResult::TCaseExecutionResult aCaseExecutionType,
       
  2449                 const TInt aCaseResult        :in:  Case result
       
  2450                 const TDesC& aText            :in:  Completion text
       
  2451 
       
  2452     Return Values: None
       
  2453 
       
  2454     Errors/Exceptions: None
       
  2455 
       
  2456     Status: Proposal
       
  2457 
       
  2458 -------------------------------------------------------------------------------
       
  2459 */
       
  2460 void CTestExecution::CompleteTestExecution( const TInt aCompletionCode,
       
  2461     const TFullTestResult::TCaseExecutionResult aCaseExecutionType,
       
  2462     const TInt aCaseExecutionCode,
       
  2463     const TInt aCaseResult,
       
  2464     const TDesC& aText )
       
  2465     {
       
  2466     
       
  2467     TInt completionCode = aCompletionCode;
       
  2468     
       
  2469     if( iModuleContainer != NULL )
       
  2470         {
       
  2471         // Fill the description
       
  2472         iFullResult.iEndTime.HomeTime();
       
  2473         iFullResult.iCaseExecutionResultType = aCaseExecutionType;
       
  2474         iFullResult.iCaseExecutionResultCode = aCaseExecutionCode;
       
  2475         iFullResult.iTestResult.iResult = aCaseResult;
       
  2476         iFullResult.iTestResult.iResultDes = aText;
       
  2477         CompleteTestExecution( aCompletionCode );
       
  2478         return;
       
  2479         }
       
  2480     else
       
  2481         {   
       
  2482         completionCode = KErrGeneral;
       
  2483         __TRACE ( KError, ( CStifLogger::ERed, 
       
  2484             _L("CTestExecution::CompleteTestExecution: ModuleContainer NULL") ) );
       
  2485         }
       
  2486 
       
  2487     iTestExeMessage.Complete ( completionCode );
       
  2488 
       
  2489     }
       
  2490 
       
  2491 /*
       
  2492 -------------------------------------------------------------------------------
       
  2493 
       
  2494     Class: CTestExecution
       
  2495 
       
  2496     Method: CompleteTestExecution
       
  2497 
       
  2498     Description: Completes test execution
       
  2499 
       
  2500     Parameters: const TInt aCompletionCode: in: completion code
       
  2501                 TFullTestResult&: in: test case result
       
  2502 
       
  2503     Return Values: None
       
  2504 
       
  2505     Errors/Exceptions: None
       
  2506 
       
  2507     Status: Proposal
       
  2508 
       
  2509 -------------------------------------------------------------------------------
       
  2510 */
       
  2511 void CTestExecution::CompleteTestExecution( const TInt aCompletionCode )
       
  2512     {
       
  2513     
       
  2514     TInt completionCode = aCompletionCode;
       
  2515     
       
  2516     TFullTestResultPckg fullResultPckg( iFullResult );
       
  2517     TRAPD( res, iTestExeMessage.WriteL( 0, fullResultPckg ) );
       
  2518     if ( res != KErrNone )
       
  2519         {
       
  2520         completionCode = res;
       
  2521         }
       
  2522 
       
  2523     iTestExeMessage.Complete ( completionCode );
       
  2524     
       
  2525     // @js Now it returns completionCode, used to return res
       
  2526 
       
  2527     }
       
  2528 
       
  2529 /*
       
  2530 -------------------------------------------------------------------------------
       
  2531 
       
  2532     Class: CTestExecution
       
  2533 
       
  2534     Method: UnsetStateEvents
       
  2535 
       
  2536     Description: Unsets all state events. Must be done if testcase is exited 
       
  2537                 abnormally (i.e. aborted by the user).
       
  2538 
       
  2539     Parameters: None
       
  2540     
       
  2541     Return Values: None
       
  2542 
       
  2543     Errors/Exceptions: None
       
  2544 
       
  2545     Status: Proposal
       
  2546     
       
  2547 -------------------------------------------------------------------------------
       
  2548 */
       
  2549 void CTestExecution::UnsetStateEvents()
       
  2550     {
       
  2551 
       
  2552 
       
  2553     // Unset all state events that are set currently
       
  2554     TInt count = iStateEvents.Count();
       
  2555     TEventIf event;
       
  2556     for( TInt i = 0; i < count; i++ )   
       
  2557         {
       
  2558         TPtrC name = *(iStateEvents[i]);
       
  2559         event.Set( TEventIf::EUnsetEvent, name, TEventIf::EState );
       
  2560         
       
  2561         // Construct message
       
  2562         TEventIfPckg eventPckg( event );
       
  2563 
       
  2564         // Write message to client space
       
  2565         TRAPD( res, iNotifyEventMessage.WriteL( 0, eventPckg ) );
       
  2566 
       
  2567         // Complete with WriteL result
       
  2568         iEventNotifyAvailable = EFalse;
       
  2569         iNotifyEventMessage.Complete( res );
       
  2570         if( res != KErrNone )
       
  2571             {
       
  2572             __TRACE( KError,( _L( "CTestExecution::UnsetStateEvents: WriteL failed" ) ));
       
  2573             break;
       
  2574             } 
       
  2575         }
       
  2576     
       
  2577     }
       
  2578 
       
  2579 /*
       
  2580 -------------------------------------------------------------------------------
       
  2581 
       
  2582     Class: CTestExecution
       
  2583 
       
  2584     Method: TestThreadRequestComplete
       
  2585 
       
  2586     Description: Complete test thread request.
       
  2587 
       
  2588     Parameters: None
       
  2589     
       
  2590     Return Values: None
       
  2591 
       
  2592     Errors/Exceptions: None
       
  2593 
       
  2594     Status: Proposal
       
  2595     
       
  2596 -------------------------------------------------------------------------------
       
  2597 */
       
  2598 void CTestExecution::TestThreadRequestComplete( TRequestStatus* aStatus, 
       
  2599                                                 TInt aCode)
       
  2600     {                                        
       
  2601     
       
  2602     if( iThreadState != EOnGoing )
       
  2603         {
       
  2604         __TRACE( KError,
       
  2605             ( _L( "CTestExecution::TestThreadRequestComplete: test thread killed" ) ));
       
  2606         return;
       
  2607         }
       
  2608 
       
  2609     if( iTestThreadOpen == EFalse )
       
  2610         {        
       
  2611         if( iTestThread.Open( iTestThreadId ) != KErrNone )
       
  2612             {
       
  2613             __TRACE( KError,
       
  2614                 ( _L( "CTestExecution::TestThreadRequestComplete: test thread cannot be opened" ) ));
       
  2615             return;
       
  2616             }
       
  2617         iTestThreadOpen = ETrue;
       
  2618         }
       
  2619     if( iTestThread.ExitType() != EExitPending ) 
       
  2620         {
       
  2621         // test thread has died
       
  2622         __TRACE( KError,
       
  2623             ( _L( "CTestExecution::TestThreadRequestComplete: test thread has died" ) ));
       
  2624         return;
       
  2625         }    
       
  2626      
       
  2627     iTestThread.RequestComplete( aStatus, aCode );
       
  2628     
       
  2629     }
       
  2630 
       
  2631 /*
       
  2632 -------------------------------------------------------------------------------
       
  2633 
       
  2634     Class: CTestExecution
       
  2635 
       
  2636     Method: CancelTestExecution
       
  2637 
       
  2638     Description: Cancels test(s) execution in special cases e.g. timeout,
       
  2639                  exit etc.
       
  2640 
       
  2641     Parameters: None
       
  2642     
       
  2643     Return Values: TInt: Symbian error code.
       
  2644 
       
  2645     Errors/Exceptions: None
       
  2646 
       
  2647     Status: Approved
       
  2648     
       
  2649 -------------------------------------------------------------------------------
       
  2650 */
       
  2651 TInt CTestExecution::CancelTestExecution()
       
  2652     {
       
  2653     TInt ret( KErrNone );
       
  2654     ret = CancelTestRequest();
       
  2655 
       
  2656     return ret;
       
  2657 
       
  2658     }
       
  2659 
       
  2660 /*
       
  2661 -------------------------------------------------------------------------------
       
  2662 
       
  2663     Class: CTestExecution
       
  2664 
       
  2665     Method: KillTestinterferenceThread
       
  2666 
       
  2667     Description: Make sure that any of the test interference thread's won't
       
  2668                  stay to run if test case is crashed of test interference
       
  2669                  object is not deleted.
       
  2670 
       
  2671     Parameters: None
       
  2672 
       
  2673     Return Values: TInt: Symbian OS error code.
       
  2674 
       
  2675     Errors/Exceptions: None
       
  2676 
       
  2677     Status: Proposal
       
  2678 
       
  2679 -------------------------------------------------------------------------------
       
  2680 */
       
  2681 TInt CTestExecution::KillTestinterferenceThread()
       
  2682     {
       
  2683     for( TInt i = 0; i < iSTIFTestInterferenceArray.Count(); i++ )
       
  2684         {
       
  2685         RDebug::Print( 
       
  2686             _L( "Test interference's thread[%x] killed by STIF" ), (TInt)iSTIFTestInterferenceArray[i].Id() );
       
  2687         __TRACE( KInit,
       
  2688             ( _L( "Test interference's thread[%x] killed by STIF" ), (TInt)iSTIFTestInterferenceArray[i].Id() ) );
       
  2689         iSTIFTestInterferenceArray[i].Kill( KErrCancel );
       
  2690         //iSTIFTestInterferenceArray.Remove( i );
       
  2691         }
       
  2692 
       
  2693     iSTIFTestInterferenceArray.Reset();
       
  2694     iSTIFTestInterferenceArray.Close();
       
  2695 
       
  2696     return KErrNone;
       
  2697 
       
  2698     }
       
  2699 
       
  2700 /*
       
  2701 -------------------------------------------------------------------------------
       
  2702 
       
  2703     Class: CTestExecution
       
  2704 
       
  2705     Method: DoNotifyCommand
       
  2706 
       
  2707     Description: Completes command message.
       
  2708 
       
  2709     Parameters: None.
       
  2710 
       
  2711     Return Values: Symbian OS error code.
       
  2712 
       
  2713     Errors/Exceptions: None
       
  2714 
       
  2715     Status: Proposal
       
  2716 
       
  2717 -------------------------------------------------------------------------------
       
  2718 */
       
  2719 TInt CTestExecution::DoNotifyCommand()
       
  2720     {
       
  2721     if(!iCommandNotifyAvailable)
       
  2722     	{
       
  2723     	__TRACE(KPrint, (_L("CTestExecution::DoNotifyCommand(): unable to complete notification")))
       
  2724     	return KErrNone;
       
  2725     	}
       
  2726 
       
  2727     TInt ret = KErrNone;
       
  2728 
       
  2729     switch(iCommandDef->iCommand)
       
  2730         {
       
  2731         case EStopExecution:
       
  2732             {
       
  2733             //Unpack received parameters
       
  2734             TStopExecutionCommandParams par;
       
  2735             TStopExecutionCommandParamsPckg parPack(par);
       
  2736             parPack.Copy(iCommandDef->iParamsPckg);
       
  2737 
       
  2738             //Set test case handle
       
  2739             par.iTestCaseHandle = iNotifyCommandMessage.Int3();
       
  2740 
       
  2741             __TRACE(KPrint, (_L("CTestExecution::DoNotifyCommand(): command [%d] type [%d] code [%d] test handle [%d]"), TInt(iCommandDef->iCommand), TInt(par.iType), TInt(par.iCode), par.iTestCaseHandle));
       
  2742             iCommandDef->iParamsPckg.Copy(parPack);
       
  2743             break;
       
  2744             }
       
  2745         case ESendTestModuleVersion:
       
  2746         	{
       
  2747         	TSendTestModuleVesionCommandParams par;
       
  2748         	TSendTestModuleVesionCommandParamsPckg parPack(par);
       
  2749         	parPack.Copy(iCommandDef->iParamsPckg);
       
  2750         	
       
  2751         	__TRACE(KPrint, (_L("CTestExecution::DoNotifyCommand(): command ESendTestModuleVersion")));
       
  2752         	break;
       
  2753         	}
       
  2754         default:
       
  2755             __TRACE(KError, (_L("CTestExecution::DoNotifyCommand(): Unknown command [%d]"), TInt(iCommandDef->iCommand)));
       
  2756             return KErrNotFound;
       
  2757         }
       
  2758     // Construct message
       
  2759     TPckg<TCommand> commandPckg(iCommandDef->iCommand);
       
  2760 
       
  2761     // Start first phase of the writing message to client space
       
  2762     TRAP(ret, iNotifyCommandMessage.WriteL(0, commandPckg));
       
  2763     if(ret != KErrNone)
       
  2764        {
       
  2765        __TRACE(KError, (_L( "CTestExecution::DoNotifyCommand(): WriteL failed (0)")));
       
  2766        }
       
  2767 
       
  2768     TRAP(ret, iNotifyCommandMessage.WriteL(1, iCommandDef->iParamsPckg));
       
  2769     if(ret != KErrNone)
       
  2770        {
       
  2771        __TRACE(KError, (_L( "CTestExecution::DoNotifyCommand(): WriteL failed (1)")));
       
  2772        }
       
  2773 
       
  2774     // Complete request with WriteL result
       
  2775     iCommandNotifyAvailable = EFalse;
       
  2776     iNotifyCommandMessage.Complete(ret);
       
  2777 
       
  2778     return KErrNone;
       
  2779     }
       
  2780 
       
  2781 /*
       
  2782 -------------------------------------------------------------------------------
       
  2783 
       
  2784     Class: CTestExecution
       
  2785 
       
  2786     Method: KillTestMeasurement
       
  2787 
       
  2788     Description: Make sure that any of the test measurement operations won't
       
  2789                  stay to run if test case is crashed or test measurement object
       
  2790                  is not stopped by user.
       
  2791 
       
  2792     Parameters: None
       
  2793 
       
  2794     Return Values: TInt: Symbian OS error code.
       
  2795 
       
  2796     Errors/Exceptions: None
       
  2797 
       
  2798     Status: Approved
       
  2799 
       
  2800 -------------------------------------------------------------------------------
       
  2801 */
       
  2802 TInt CTestExecution::KillTestMeasurement()
       
  2803     {
       
  2804     for( TInt i = 0; i < iMeasurementHandlingArray.Count(); i++ )
       
  2805         {
       
  2806         iMeasurementHandlingArray[i]->iMeasurementModulePtr->Stop();
       
  2807         }
       
  2808 
       
  2809     iMeasurementHandlingArray.ResetAndDestroy();
       
  2810     iMeasurementHandlingArray.Close();
       
  2811 
       
  2812     return KErrNone;
       
  2813 
       
  2814     }
       
  2815 
       
  2816 /*
       
  2817 -------------------------------------------------------------------------------
       
  2818 
       
  2819     DESCRIPTION
       
  2820 
       
  2821     This module contains implementation of CPrintHandler class member functions.
       
  2822     CPrintHandler listens print notifications from test thread.
       
  2823 
       
  2824 -------------------------------------------------------------------------------
       
  2825 */
       
  2826 
       
  2827 // ================= MEMBER FUNCTIONS =========================================
       
  2828 
       
  2829 
       
  2830 /*
       
  2831 -------------------------------------------------------------------------------
       
  2832 
       
  2833     Class: CPrintHandler
       
  2834 
       
  2835     Method: NewL
       
  2836 
       
  2837     Description: Constructs a new CPrintHandler object.
       
  2838 
       
  2839     Parameters: CTestExecution& aExecution: in: "Parent"
       
  2840 
       
  2841     Return Values: CPrintHandler*: New undertaker
       
  2842 
       
  2843     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  2844 
       
  2845     Status: Proposal
       
  2846 
       
  2847 -------------------------------------------------------------------------------
       
  2848 */
       
  2849 CPrintHandler* CPrintHandler::NewL( CTestExecution& aExecution )
       
  2850     {
       
  2851 
       
  2852     CPrintHandler* self = new( ELeave ) CPrintHandler( aExecution );
       
  2853     CleanupStack::PushL( self );
       
  2854     self->ConstructL();
       
  2855     CleanupStack::Pop( self );
       
  2856     return self;
       
  2857 
       
  2858     }
       
  2859 
       
  2860 /*
       
  2861 -------------------------------------------------------------------------------
       
  2862 
       
  2863     Class: CPrintHandler
       
  2864 
       
  2865     Method: ConstructL
       
  2866 
       
  2867     Description: Second level constructor.
       
  2868 
       
  2869     Parameters: None
       
  2870 
       
  2871     Return Values: None
       
  2872 
       
  2873     Errors/Exceptions: None
       
  2874 
       
  2875     Status: Proposal
       
  2876 
       
  2877 -------------------------------------------------------------------------------
       
  2878 */
       
  2879 void CPrintHandler::ConstructL()
       
  2880     {
       
  2881 
       
  2882     }
       
  2883 
       
  2884 /*
       
  2885 -------------------------------------------------------------------------------
       
  2886 
       
  2887     Class: CPrintHandler
       
  2888 
       
  2889     Method: CPrintHandler
       
  2890 
       
  2891     Description: Constructor
       
  2892 
       
  2893     Parameters: CTestModuleContainer& aExecution :in:   "Parent"
       
  2894 
       
  2895     Return Values: None
       
  2896 
       
  2897     Errors/Exceptions: None
       
  2898 
       
  2899     Status: Proposal
       
  2900     
       
  2901 -------------------------------------------------------------------------------
       
  2902 */
       
  2903 CPrintHandler::CPrintHandler( CTestExecution& aExecution ) :
       
  2904     CActive( CActive::EPriorityStandard ),
       
  2905     iExecution( aExecution )
       
  2906     {
       
  2907     
       
  2908     CActiveScheduler::Add ( this );
       
  2909     
       
  2910     }
       
  2911 
       
  2912 /*
       
  2913 -------------------------------------------------------------------------------
       
  2914 
       
  2915     Class: CPrintHandler
       
  2916 
       
  2917     Method: ~CPrintHandler
       
  2918 
       
  2919     Description: Destructor. 
       
  2920     Cancels active request.
       
  2921 
       
  2922     Parameters: None
       
  2923 
       
  2924     Return Values: None
       
  2925 
       
  2926     Errors/Exceptions: None
       
  2927 
       
  2928     Status: Proposal
       
  2929     
       
  2930 -------------------------------------------------------------------------------
       
  2931 */
       
  2932 CPrintHandler::~CPrintHandler()
       
  2933     {
       
  2934 
       
  2935     Cancel();
       
  2936 
       
  2937     }
       
  2938 
       
  2939 
       
  2940 
       
  2941 
       
  2942 /*
       
  2943 -------------------------------------------------------------------------------
       
  2944 
       
  2945     Class: CPrintHandler
       
  2946 
       
  2947     Method: StartL
       
  2948 
       
  2949     Description: Starts to monitor thread.
       
  2950 
       
  2951     Parameters: None
       
  2952 
       
  2953     Return Values: TInt                             Always KErrNone
       
  2954 
       
  2955     Errors/Exceptions: None
       
  2956 
       
  2957     Status: Proposal
       
  2958     
       
  2959 -------------------------------------------------------------------------------
       
  2960 */
       
  2961 void CPrintHandler::StartL()
       
  2962     {
       
  2963     
       
  2964     __TRACE( KPrint, ( _L( "CPrintHandler::StartL" ) ) );
       
  2965     
       
  2966     if( IsActive() ) 
       
  2967         {
       
  2968         CTestServer::PanicServer( EAlreadyActive );
       
  2969         }
       
  2970 
       
  2971     iStatus = KRequestPending;
       
  2972     SetActive();
       
  2973     
       
  2974     // Signal test thread
       
  2975     iExecution.iPrintSem.Signal();
       
  2976 
       
  2977     }
       
  2978 
       
  2979 /*
       
  2980 -------------------------------------------------------------------------------
       
  2981 
       
  2982     Class: CPrintHandler
       
  2983 
       
  2984     Method: RunL
       
  2985 
       
  2986     Description: Handles thread death.
       
  2987     Function does:
       
  2988     1 ) Stops monitoring thread
       
  2989     1 ) Marks thread death
       
  2990     2 ) Completes ongoing requests
       
  2991     3 ) Cleans the memory
       
  2992 
       
  2993     Parameters: None
       
  2994 
       
  2995     Return Values: None
       
  2996 
       
  2997     Errors/Exceptions: None
       
  2998 
       
  2999     Status: Proposal
       
  3000 
       
  3001 -------------------------------------------------------------------------------
       
  3002 */
       
  3003 void CPrintHandler::RunL()
       
  3004     {
       
  3005 
       
  3006     __TRACE( KPrint, ( _L( "CPrintHandler::RunL [%d]" ), iStatus.Int() ) );
       
  3007     
       
  3008     iExecution.DoNotifyPrint();
       
  3009     
       
  3010     // enable print request
       
  3011     //@speiExecution.iPrintHandler->StartL();
       
  3012     StartL();
       
  3013     }
       
  3014 
       
  3015 
       
  3016 /*
       
  3017 -------------------------------------------------------------------------------
       
  3018 
       
  3019     Class: CPrintHandler
       
  3020 
       
  3021     Method: DoCancel
       
  3022 
       
  3023     Description: Stops print notification listening.
       
  3024 
       
  3025     Parameters: None
       
  3026 
       
  3027     Return Values: None
       
  3028 
       
  3029     Errors/Exceptions: None
       
  3030 
       
  3031     Status: Proposal
       
  3032     
       
  3033 -------------------------------------------------------------------------------
       
  3034 */
       
  3035 
       
  3036 void CPrintHandler::DoCancel()
       
  3037     {
       
  3038 
       
  3039     __TRACE( KPrint, ( _L( "CPrintHandler::DoCancel" ) ) );
       
  3040 
       
  3041     iExecution.iPrintMutex.Wait();  // Take mutex and check test case print
       
  3042                                     // operation. If pending take print semaphore
       
  3043                                     // and complete
       
  3044     if( iStatus == KRequestPending )
       
  3045         {
       
  3046         // Signal test thread
       
  3047         // @remove iExecution.iPrintSem.Wait();
       
  3048     
       
  3049         TRequestStatus* status = &iStatus;    
       
  3050         User::RequestComplete( status, KErrCancel );        
       
  3051         }
       
  3052 
       
  3053     iExecution.iPrintMutex.Signal();
       
  3054     }
       
  3055 
       
  3056 /*
       
  3057 -------------------------------------------------------------------------------
       
  3058 
       
  3059     Class: CPrintHandler
       
  3060 
       
  3061     Method: RunError
       
  3062 
       
  3063     Description: Handle errors. RunL function does not leave, so one should
       
  3064     never come here. 
       
  3065 
       
  3066     Print trace and let framework handle error( i.e to do Panic )
       
  3067 
       
  3068     Parameters: TInt aError:                  :in:  Error code
       
  3069 
       
  3070     Return Values:  TInt                            Error code
       
  3071 
       
  3072     Errors/Exceptions: None
       
  3073 
       
  3074     Status: Proposal
       
  3075 
       
  3076 -------------------------------------------------------------------------------
       
  3077 */
       
  3078 TInt CPrintHandler::RunError( TInt aError )
       
  3079     {
       
  3080     
       
  3081     __TRACE( KError,( _L( "CPrintHandler::RunError" ) ) );
       
  3082 
       
  3083     return aError;
       
  3084     
       
  3085     }
       
  3086 
       
  3087 /*
       
  3088 -------------------------------------------------------------------------------
       
  3089 
       
  3090     DESCRIPTION
       
  3091 
       
  3092     This module contains implementation of CEventHandler class member functions.
       
  3093     CEventHandler listens print notifications from test thread.
       
  3094 
       
  3095 -------------------------------------------------------------------------------
       
  3096 */
       
  3097 
       
  3098 // ================= MEMBER FUNCTIONS =========================================
       
  3099 
       
  3100 
       
  3101 /*
       
  3102 -------------------------------------------------------------------------------
       
  3103 
       
  3104     Class: CEventHandler
       
  3105 
       
  3106     Method: NewL
       
  3107 
       
  3108     Description: Constructs a new CEventHandler object.
       
  3109 
       
  3110     Parameters: CTestExecution& aExecution: in: "Parent"
       
  3111 
       
  3112     Return Values: CEventHandler*: New undertaker
       
  3113 
       
  3114     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  3115 
       
  3116     Status: Proposal
       
  3117 
       
  3118 -------------------------------------------------------------------------------
       
  3119 */
       
  3120 CEventHandler* CEventHandler::NewL( CTestExecution& aExecution )
       
  3121     {
       
  3122 
       
  3123     CEventHandler* self = new( ELeave ) CEventHandler( aExecution );
       
  3124     CleanupStack::PushL( self );
       
  3125     self->ConstructL();
       
  3126     CleanupStack::Pop( self );
       
  3127     return self;
       
  3128 
       
  3129     }
       
  3130 
       
  3131 /*
       
  3132 -------------------------------------------------------------------------------
       
  3133 
       
  3134     Class: CEventHandler
       
  3135 
       
  3136     Method: ConstructL
       
  3137 
       
  3138     Description: Second level constructor.
       
  3139 
       
  3140     Parameters: None
       
  3141 
       
  3142     Return Values: None
       
  3143 
       
  3144     Errors/Exceptions: None
       
  3145 
       
  3146     Status: Proposal
       
  3147 
       
  3148 -------------------------------------------------------------------------------
       
  3149 */
       
  3150 void CEventHandler::ConstructL()
       
  3151     {
       
  3152 
       
  3153     }
       
  3154 
       
  3155 /*
       
  3156 -------------------------------------------------------------------------------
       
  3157 
       
  3158     Class: CEventHandler
       
  3159 
       
  3160     Method: CEventHandler
       
  3161 
       
  3162     Description: Constructor
       
  3163 
       
  3164     Parameters: CTestModuleContainer& aExecution :in:   "Parent"
       
  3165 
       
  3166     Return Values: None
       
  3167 
       
  3168     Errors/Exceptions: None
       
  3169 
       
  3170     Status: Proposal
       
  3171     
       
  3172 -------------------------------------------------------------------------------
       
  3173 */
       
  3174 CEventHandler::CEventHandler( CTestExecution& aExecution ) :
       
  3175     CActive( CActive::EPriorityStandard ),
       
  3176     iExecution( aExecution )
       
  3177     {
       
  3178     
       
  3179     CActiveScheduler::Add ( this );
       
  3180     
       
  3181     }
       
  3182 
       
  3183 /*
       
  3184 -------------------------------------------------------------------------------
       
  3185 
       
  3186     Class: CEventHandler
       
  3187 
       
  3188     Method: ~CEventHandler
       
  3189 
       
  3190     Description: Destructor. 
       
  3191     Cancels active request.
       
  3192 
       
  3193     Parameters: None
       
  3194 
       
  3195     Return Values: None
       
  3196 
       
  3197     Errors/Exceptions: None
       
  3198 
       
  3199     Status: Proposal
       
  3200     
       
  3201 -------------------------------------------------------------------------------
       
  3202 */
       
  3203 CEventHandler::~CEventHandler()
       
  3204     {
       
  3205 
       
  3206     Cancel();
       
  3207 
       
  3208     }
       
  3209 
       
  3210 
       
  3211 
       
  3212 
       
  3213 /*
       
  3214 -------------------------------------------------------------------------------
       
  3215 
       
  3216     Class: CEventHandler
       
  3217 
       
  3218     Method: StartL
       
  3219 
       
  3220     Description: Starts to monitor thread.
       
  3221 
       
  3222     Parameters: None
       
  3223 
       
  3224     Return Values: TInt                             Always KErrNone
       
  3225 
       
  3226     Errors/Exceptions: None
       
  3227 
       
  3228     Status: Proposal
       
  3229     
       
  3230 -------------------------------------------------------------------------------
       
  3231 */
       
  3232 void CEventHandler::StartL()
       
  3233     {
       
  3234     
       
  3235     __TRACE( KPrint, ( _L( "CEventHandler::StartL" ) ) );
       
  3236 
       
  3237     if( IsActive() ) 
       
  3238         {
       
  3239         CTestServer::PanicServer( EAlreadyActive );
       
  3240         }
       
  3241     
       
  3242     iStatus = KRequestPending;
       
  3243     SetActive();
       
  3244     
       
  3245     // Signal test thread
       
  3246     iExecution.iEventSem.Signal();
       
  3247 
       
  3248     }
       
  3249 
       
  3250 /*
       
  3251 -------------------------------------------------------------------------------
       
  3252 
       
  3253     Class: CEventHandler
       
  3254 
       
  3255     Method: RunL
       
  3256 
       
  3257     Description: Handles thread death.
       
  3258     Function does:
       
  3259     1 ) Stops monitoring thread
       
  3260     1 ) Marks thread death
       
  3261     2 ) Completes ongoing requests
       
  3262     3 ) Cleans the memory
       
  3263 
       
  3264     Parameters: None
       
  3265 
       
  3266     Return Values: None
       
  3267 
       
  3268     Errors/Exceptions: None
       
  3269 
       
  3270     Status: Proposal
       
  3271 
       
  3272 -------------------------------------------------------------------------------
       
  3273 */
       
  3274 void CEventHandler::RunL()
       
  3275     {
       
  3276 
       
  3277     __TRACE( KPrint, ( _L( "CEventHandler::RunL [%d]" ), iStatus.Int() ) );
       
  3278 
       
  3279     switch( iExecution.EventDef().iType )
       
  3280         {
       
  3281         case TEventDef::EEventCmd:
       
  3282             iExecution.DoNotifyEvent();
       
  3283             break;
       
  3284         case TEventDef::EEventCmdCancel:
       
  3285             iExecution.CancelEvent();
       
  3286             break;
       
  3287         default:
       
  3288             CTestServer::PanicServer( EUnknownEventCmd );
       
  3289             break;  
       
  3290         }
       
  3291          
       
  3292     }
       
  3293 
       
  3294 
       
  3295 /*
       
  3296 -------------------------------------------------------------------------------
       
  3297 
       
  3298     Class: CEventHandler
       
  3299 
       
  3300     Method: DoCancel
       
  3301 
       
  3302     Description: Stops print notification listening.
       
  3303 
       
  3304     Parameters: None
       
  3305 
       
  3306     Return Values: None
       
  3307 
       
  3308     Errors/Exceptions: None
       
  3309 
       
  3310     Status: Proposal
       
  3311     
       
  3312 -------------------------------------------------------------------------------
       
  3313 */
       
  3314 
       
  3315 void CEventHandler::DoCancel()
       
  3316     {
       
  3317 
       
  3318     __TRACE( KPrint, ( _L( "CEventHandler::DoCancel" ) ) );
       
  3319     
       
  3320     iExecution.iEventMutex.Wait();  // Take mutex and check test case event
       
  3321                                     // operation. If pending take event
       
  3322                                     // semaphore and complete
       
  3323     if( iStatus == KRequestPending )
       
  3324         {
       
  3325         // Signal test thread
       
  3326         // @remove iExecution.iEventSem.Wait();
       
  3327 
       
  3328         TRequestStatus* status = &iStatus;    
       
  3329         User::RequestComplete( status, KErrCancel );
       
  3330 
       
  3331         }
       
  3332 
       
  3333     iExecution.iEventMutex.Signal();
       
  3334 
       
  3335     }
       
  3336 
       
  3337 /*
       
  3338 -------------------------------------------------------------------------------
       
  3339 
       
  3340     Class: CEventHandler
       
  3341 
       
  3342     Method: RunError
       
  3343 
       
  3344     Description: Handle errors. RunL function does not leave, so one should
       
  3345     never come here. 
       
  3346 
       
  3347     Print trace and let framework handle error( i.e to do Panic )
       
  3348 
       
  3349     Parameters: TInt aError:                  :in:  Error code
       
  3350 
       
  3351     Return Values:  TInt                            Error code
       
  3352 
       
  3353     Errors/Exceptions: None
       
  3354 
       
  3355     Status: Proposal
       
  3356 
       
  3357 -------------------------------------------------------------------------------
       
  3358 */
       
  3359 TInt CEventHandler::RunError( TInt aError )
       
  3360     {
       
  3361     
       
  3362     __TRACE( KError,( _L( "CEventHandler::RunError" ) ) );
       
  3363 
       
  3364     return aError;
       
  3365     
       
  3366     }
       
  3367 
       
  3368 /*
       
  3369 -------------------------------------------------------------------------------
       
  3370 
       
  3371     DESCRIPTION
       
  3372 
       
  3373     This module contains implementation of CSndHandler class member functions.
       
  3374     CSndHandler listens print notifications from test thread.
       
  3375 
       
  3376 -------------------------------------------------------------------------------
       
  3377 */
       
  3378 
       
  3379 // ================= MEMBER FUNCTIONS =========================================
       
  3380 
       
  3381 
       
  3382 /*
       
  3383 -------------------------------------------------------------------------------
       
  3384 
       
  3385     Class: CSndHandler
       
  3386 
       
  3387     Method: NewL
       
  3388 
       
  3389     Description: Constructs a new CSndHandler object.
       
  3390 
       
  3391     Parameters: CTestExecution& aExecution: in: "Parent"
       
  3392 
       
  3393     Return Values: CSndHandler*: New undertaker
       
  3394 
       
  3395     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  3396 
       
  3397     Status: Proposal
       
  3398 
       
  3399 -------------------------------------------------------------------------------
       
  3400 */
       
  3401 CSndHandler* CSndHandler::NewL( CTestExecution& aExecution )
       
  3402     {
       
  3403 
       
  3404     CSndHandler* self = new( ELeave ) CSndHandler( aExecution );
       
  3405     CleanupStack::PushL( self );
       
  3406     self->ConstructL();
       
  3407     CleanupStack::Pop( self );
       
  3408     return self;
       
  3409 
       
  3410     }
       
  3411 
       
  3412 /*
       
  3413 -------------------------------------------------------------------------------
       
  3414 
       
  3415     Class: CSndHandler
       
  3416 
       
  3417     Method: ConstructL
       
  3418 
       
  3419     Description: Second level constructor.
       
  3420 
       
  3421     Parameters: None
       
  3422 
       
  3423     Return Values: None
       
  3424 
       
  3425     Errors/Exceptions: None
       
  3426 
       
  3427     Status: Proposal
       
  3428 
       
  3429 -------------------------------------------------------------------------------
       
  3430 */
       
  3431 void CSndHandler::ConstructL()
       
  3432     {
       
  3433 
       
  3434     }
       
  3435 
       
  3436 /*
       
  3437 -------------------------------------------------------------------------------
       
  3438 
       
  3439     Class: CSndHandler
       
  3440 
       
  3441     Method: CSndHandler
       
  3442 
       
  3443     Description: Constructor
       
  3444 
       
  3445     Parameters: CTestModuleContainer& aExecution :in:   "Parent"
       
  3446 
       
  3447     Return Values: None
       
  3448 
       
  3449     Errors/Exceptions: None
       
  3450 
       
  3451     Status: Proposal
       
  3452     
       
  3453 -------------------------------------------------------------------------------
       
  3454 */
       
  3455 CSndHandler::CSndHandler( CTestExecution& aExecution ) :
       
  3456     CActive( CActive::EPriorityStandard ),
       
  3457     iExecution( aExecution )
       
  3458     {
       
  3459     
       
  3460     CActiveScheduler::Add ( this );
       
  3461     
       
  3462     }
       
  3463 
       
  3464 /*
       
  3465 -------------------------------------------------------------------------------
       
  3466 
       
  3467     Class: CSndHandler
       
  3468 
       
  3469     Method: ~CSndHandler
       
  3470 
       
  3471     Description: Destructor. 
       
  3472     Cancels active request.
       
  3473 
       
  3474     Parameters: None
       
  3475 
       
  3476     Return Values: None
       
  3477 
       
  3478     Errors/Exceptions: None
       
  3479 
       
  3480     Status: Proposal
       
  3481     
       
  3482 -------------------------------------------------------------------------------
       
  3483 */
       
  3484 CSndHandler::~CSndHandler()
       
  3485     {
       
  3486 
       
  3487     Cancel();
       
  3488 
       
  3489     }
       
  3490 
       
  3491 
       
  3492 
       
  3493 
       
  3494 /*
       
  3495 -------------------------------------------------------------------------------
       
  3496 
       
  3497     Class: CSndHandler
       
  3498 
       
  3499     Method: StartL
       
  3500 
       
  3501     Description: Starts to monitor thread.
       
  3502 
       
  3503     Parameters: None
       
  3504 
       
  3505     Return Values: TInt                             Always KErrNone
       
  3506 
       
  3507     Errors/Exceptions: None
       
  3508 
       
  3509     Status: Proposal
       
  3510     
       
  3511 -------------------------------------------------------------------------------
       
  3512 */
       
  3513 void CSndHandler::StartL()
       
  3514     {
       
  3515     
       
  3516     __TRACE( KPrint, ( _L( "CSndHandler::StartL" ) ) );
       
  3517 
       
  3518     if( IsActive() ) 
       
  3519         {
       
  3520         CTestServer::PanicServer( EAlreadyActive );
       
  3521         }
       
  3522     
       
  3523     iStatus = KRequestPending;
       
  3524     SetActive();
       
  3525     
       
  3526     // Signal test thread
       
  3527     iExecution.iSndSem.Signal();
       
  3528 
       
  3529     }
       
  3530 
       
  3531 /*
       
  3532 -------------------------------------------------------------------------------
       
  3533 
       
  3534     Class: CSndHandler
       
  3535 
       
  3536     Method: RunL
       
  3537 
       
  3538     Description: Handles thread death.
       
  3539     Function does:
       
  3540     1 ) Stops monitoring thread
       
  3541     1 ) Marks thread death
       
  3542     2 ) Completes ongoing requests
       
  3543     3 ) Cleans the memory
       
  3544 
       
  3545     Parameters: None
       
  3546 
       
  3547     Return Values: None
       
  3548 
       
  3549     Errors/Exceptions: None
       
  3550 
       
  3551     Status: Proposal
       
  3552 
       
  3553 -------------------------------------------------------------------------------
       
  3554 */
       
  3555 void CSndHandler::RunL()
       
  3556     {
       
  3557 
       
  3558     __TRACE( KPrint, ( _L( "CSndHandler::RunL [%d]" ), iStatus.Int() ) );
       
  3559     
       
  3560     iExecution.DoRemoteSend();
       
  3561        
       
  3562     }
       
  3563 
       
  3564 
       
  3565 /*
       
  3566 -------------------------------------------------------------------------------
       
  3567 
       
  3568     Class: CSndHandler
       
  3569 
       
  3570     Method: DoCancel
       
  3571 
       
  3572     Description: Stops print notification listening.
       
  3573 
       
  3574     Parameters: None
       
  3575 
       
  3576     Return Values: None
       
  3577 
       
  3578     Errors/Exceptions: None
       
  3579 
       
  3580     Status: Proposal
       
  3581     
       
  3582 -------------------------------------------------------------------------------
       
  3583 */
       
  3584 
       
  3585 void CSndHandler::DoCancel()
       
  3586     {
       
  3587 
       
  3588     __TRACE( KPrint, ( _L( "CSndHandler::DoCancel" ) ) );
       
  3589 
       
  3590     iExecution.iSndMutex.Wait();  // Take mutex and check test case send
       
  3591                                   // operation. If pending take send
       
  3592                                   // semaphore and complete
       
  3593     if( iStatus == KRequestPending )
       
  3594         {
       
  3595         // Signal test thread
       
  3596         // @remove iExecution.iSndSem.Wait();
       
  3597 
       
  3598         TRequestStatus* status = &iStatus;    
       
  3599         User::RequestComplete( status, KErrCancel );
       
  3600 
       
  3601         }
       
  3602 
       
  3603     iExecution.iSndMutex.Signal();
       
  3604     
       
  3605     }
       
  3606 
       
  3607 /*
       
  3608 -------------------------------------------------------------------------------
       
  3609 
       
  3610     Class: CSndHandler
       
  3611 
       
  3612     Method: RunError
       
  3613 
       
  3614     Description: Handle errors. RunL function does not leave, so one should
       
  3615     never come here. 
       
  3616 
       
  3617     Print trace and let framework handle error( i.e to do Panic )
       
  3618 
       
  3619     Parameters: TInt aError:                  :in:  Error code
       
  3620 
       
  3621     Return Values:  TInt                            Error code
       
  3622 
       
  3623     Errors/Exceptions: None
       
  3624 
       
  3625     Status: Proposal
       
  3626 
       
  3627 -------------------------------------------------------------------------------
       
  3628 */
       
  3629 TInt CSndHandler::RunError( TInt aError )
       
  3630     {
       
  3631     
       
  3632     __TRACE( KError,( _L( "CSndHandler::RunError" ) ) );
       
  3633 
       
  3634     return aError;
       
  3635     
       
  3636     }
       
  3637 
       
  3638 /*
       
  3639 -------------------------------------------------------------------------------
       
  3640 
       
  3641     DESCRIPTION
       
  3642 
       
  3643     This module contains implementation of CSndHandler class member functions.
       
  3644     CRcvHandler listens print notifications from test thread.
       
  3645 
       
  3646 -------------------------------------------------------------------------------
       
  3647 */
       
  3648 
       
  3649 // ================= MEMBER FUNCTIONS =========================================
       
  3650 
       
  3651 
       
  3652 /*
       
  3653 -------------------------------------------------------------------------------
       
  3654 
       
  3655     Class: CRcvHandler
       
  3656 
       
  3657     Method: NewL
       
  3658 
       
  3659     Description: Constructs a new CRcvHandler object.
       
  3660 
       
  3661     Parameters: CTestExecution& aExecution: in: "Parent"
       
  3662 
       
  3663     Return Values: CRcvHandler*: New undertaker
       
  3664 
       
  3665     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  3666 
       
  3667     Status: Proposal
       
  3668 
       
  3669 -------------------------------------------------------------------------------
       
  3670 */
       
  3671 CRcvHandler* CRcvHandler::NewL( CTestExecution& aExecution )
       
  3672     {
       
  3673 
       
  3674     CRcvHandler* self = new( ELeave ) CRcvHandler( aExecution );
       
  3675     CleanupStack::PushL( self );
       
  3676     self->ConstructL();
       
  3677     CleanupStack::Pop( self );
       
  3678     return self;
       
  3679 
       
  3680     }
       
  3681 
       
  3682 /*
       
  3683 -------------------------------------------------------------------------------
       
  3684 
       
  3685     Class: CRcvHandler
       
  3686 
       
  3687     Method: ConstructL
       
  3688 
       
  3689     Description: Second level constructor.
       
  3690 
       
  3691     Parameters: None
       
  3692 
       
  3693     Return Values: None
       
  3694 
       
  3695     Errors/Exceptions: None
       
  3696 
       
  3697     Status: Proposal
       
  3698 
       
  3699 -------------------------------------------------------------------------------
       
  3700 */
       
  3701 void CRcvHandler::ConstructL()
       
  3702     {
       
  3703 
       
  3704     }
       
  3705 
       
  3706 /*
       
  3707 -------------------------------------------------------------------------------
       
  3708 
       
  3709     Class: CRcvHandler
       
  3710 
       
  3711     Method: CRcvHandler
       
  3712 
       
  3713     Description: Constructor
       
  3714 
       
  3715     Parameters: CTestModuleContainer& aExecution :in:   "Parent"
       
  3716 
       
  3717     Return Values: None
       
  3718 
       
  3719     Errors/Exceptions: None
       
  3720 
       
  3721     Status: Proposal
       
  3722     
       
  3723 -------------------------------------------------------------------------------
       
  3724 */
       
  3725 CRcvHandler::CRcvHandler( CTestExecution& aExecution ) :
       
  3726     CActive( CActive::EPriorityStandard ),
       
  3727     iExecution( aExecution )
       
  3728     {
       
  3729     
       
  3730     CActiveScheduler::Add ( this );
       
  3731     
       
  3732     }
       
  3733 
       
  3734 /*
       
  3735 -------------------------------------------------------------------------------
       
  3736 
       
  3737     Class: CRcvHandler
       
  3738 
       
  3739     Method: ~CRcvHandler
       
  3740 
       
  3741     Description: Destructor. 
       
  3742     Cancels active request.
       
  3743 
       
  3744     Parameters: None
       
  3745 
       
  3746     Return Values: None
       
  3747 
       
  3748     Errors/Exceptions: None
       
  3749 
       
  3750     Status: Proposal
       
  3751     
       
  3752 -------------------------------------------------------------------------------
       
  3753 */
       
  3754 CRcvHandler::~CRcvHandler()
       
  3755     {
       
  3756 
       
  3757     Cancel();
       
  3758 
       
  3759     }
       
  3760 
       
  3761 
       
  3762 
       
  3763 
       
  3764 /*
       
  3765 -------------------------------------------------------------------------------
       
  3766 
       
  3767     Class: CRcvHandler
       
  3768 
       
  3769     Method: StartL
       
  3770 
       
  3771     Description: Starts to monitor thread.
       
  3772 
       
  3773     Parameters: None
       
  3774 
       
  3775     Return Values: TInt                             Always KErrNone
       
  3776 
       
  3777     Errors/Exceptions: None
       
  3778 
       
  3779     Status: Proposal
       
  3780     
       
  3781 -------------------------------------------------------------------------------
       
  3782 */
       
  3783 void CRcvHandler::StartL()
       
  3784     {
       
  3785     
       
  3786     __TRACE( KPrint, ( _L( "CRcvHandler::StartL" ) ) );
       
  3787     
       
  3788     if( IsActive() ) 
       
  3789         {
       
  3790         CTestServer::PanicServer( EAlreadyActive );
       
  3791         }
       
  3792     iStatus = KRequestPending;
       
  3793     SetActive();
       
  3794     
       
  3795     // Signal test thread
       
  3796     iExecution.iRcvSem.Signal();
       
  3797 
       
  3798     }
       
  3799 
       
  3800 /*
       
  3801 -------------------------------------------------------------------------------
       
  3802 
       
  3803     Class: CRcvHandler
       
  3804 
       
  3805     Method: RunL
       
  3806 
       
  3807     Description: Handles thread death.
       
  3808     Function does:
       
  3809     1 ) Stops monitoring thread
       
  3810     1 ) Marks thread death
       
  3811     2 ) Completes ongoing requests
       
  3812     3 ) Cleans the memory
       
  3813 
       
  3814     Parameters: None
       
  3815 
       
  3816     Return Values: None
       
  3817 
       
  3818     Errors/Exceptions: None
       
  3819 
       
  3820     Status: Proposal
       
  3821 
       
  3822 -------------------------------------------------------------------------------
       
  3823 */
       
  3824 void CRcvHandler::RunL()
       
  3825     {
       
  3826 
       
  3827     __TRACE( KPrint, ( _L( "CRcvHandler::RunL [%d]" ), iStatus.Int() ) );
       
  3828     
       
  3829     iExecution.DoRemoteReceive();
       
  3830        
       
  3831     }
       
  3832 
       
  3833 
       
  3834 /*
       
  3835 -------------------------------------------------------------------------------
       
  3836 
       
  3837     Class: CRcvHandler
       
  3838 
       
  3839     Method: DoCancel
       
  3840 
       
  3841     Description: Stops print notification listening.
       
  3842 
       
  3843     Parameters: None
       
  3844 
       
  3845     Return Values: None
       
  3846 
       
  3847     Errors/Exceptions: None
       
  3848 
       
  3849     Status: Proposal
       
  3850     
       
  3851 -------------------------------------------------------------------------------
       
  3852 */
       
  3853 
       
  3854 void CRcvHandler::DoCancel()
       
  3855     {
       
  3856 
       
  3857     __TRACE( KPrint, ( _L( "CRcvHandler::DoCancel" ) ) );
       
  3858 
       
  3859     iExecution.iRcvMutex.Wait();  // Take mutex and check test case receive
       
  3860                                   // operation. If pending take reveive
       
  3861                                   // semaphore and complete
       
  3862     if( iStatus == KRequestPending )
       
  3863         {
       
  3864         // Signal test thread
       
  3865         // @remove iExecution.iRcvSem.Wait();
       
  3866 
       
  3867         TRequestStatus* status = &iStatus;    
       
  3868         User::RequestComplete( status, KErrCancel );
       
  3869         }
       
  3870         
       
  3871     iExecution.iRcvMutex.Signal();
       
  3872 
       
  3873     }
       
  3874 
       
  3875 /*
       
  3876 -------------------------------------------------------------------------------
       
  3877 
       
  3878     Class: CRcvHandler
       
  3879 
       
  3880     Method: RunError
       
  3881 
       
  3882     Description: Handle errors. RunL function does not leave, so one should
       
  3883     never come here. 
       
  3884 
       
  3885     Print trace and let framework handle error( i.e to do Panic )
       
  3886 
       
  3887     Parameters: TInt aError:                  :in:  Error code
       
  3888 
       
  3889     Return Values:  TInt                            Error code
       
  3890 
       
  3891     Errors/Exceptions: None
       
  3892 
       
  3893     Status: Proposal
       
  3894 
       
  3895 -------------------------------------------------------------------------------
       
  3896 */
       
  3897 TInt CRcvHandler::RunError( TInt aError )
       
  3898     {
       
  3899     
       
  3900     __TRACE( KError,( _L( "CRcvHandler::RunError" ) ) );
       
  3901 
       
  3902     return aError;
       
  3903     
       
  3904     }
       
  3905 
       
  3906 
       
  3907 /*
       
  3908 -------------------------------------------------------------------------------
       
  3909 
       
  3910     DESCRIPTION
       
  3911 
       
  3912     This module contains implementation of CTestInterferenceHandler class 
       
  3913     member functions. CTestInterferenceHandler listens print notifications from
       
  3914     test thread.
       
  3915 
       
  3916 -------------------------------------------------------------------------------
       
  3917 */
       
  3918 
       
  3919 // ================= MEMBER FUNCTIONS =========================================
       
  3920 
       
  3921 
       
  3922 /*
       
  3923 -------------------------------------------------------------------------------
       
  3924 
       
  3925     Class: CInterferenceHandler
       
  3926 
       
  3927     Method: NewL
       
  3928 
       
  3929     Description: Constructs a new CInterferenceHandler object.
       
  3930 
       
  3931     Parameters: CTestExecution& aExecution: in: "Parent"
       
  3932 
       
  3933     Return Values: CInterferenceHandler*: New undertaker
       
  3934 
       
  3935     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  3936 
       
  3937     Status: Proposal
       
  3938 
       
  3939 -------------------------------------------------------------------------------
       
  3940 */
       
  3941 CInterferenceHandler* CInterferenceHandler::NewL( 
       
  3942                                                 CTestExecution& aExecution )
       
  3943     {
       
  3944     CInterferenceHandler* self = 
       
  3945                         new( ELeave ) CInterferenceHandler( aExecution );
       
  3946     CleanupStack::PushL( self );
       
  3947     self->ConstructL();
       
  3948     CleanupStack::Pop( self );
       
  3949     return self;
       
  3950 
       
  3951     }
       
  3952 
       
  3953 /*
       
  3954 -------------------------------------------------------------------------------
       
  3955 
       
  3956     Class: CInterferenceHandler
       
  3957 
       
  3958     Method: ConstructL
       
  3959 
       
  3960     Description: Second level constructor.
       
  3961 
       
  3962     Parameters: None
       
  3963 
       
  3964     Return Values: None
       
  3965 
       
  3966     Errors/Exceptions: None
       
  3967 
       
  3968     Status: Proposal
       
  3969 
       
  3970 -------------------------------------------------------------------------------
       
  3971 */
       
  3972 void CInterferenceHandler::ConstructL()
       
  3973     {
       
  3974 
       
  3975     }
       
  3976 
       
  3977 /*
       
  3978 -------------------------------------------------------------------------------
       
  3979 
       
  3980     Class: CInterferenceHandler
       
  3981 
       
  3982     Method: CInterferenceHandler
       
  3983 
       
  3984     Description: Constructor
       
  3985 
       
  3986     Parameters: CTestModuleContainer& aExecution :in: "Parent"
       
  3987 
       
  3988     Return Values: None
       
  3989 
       
  3990     Errors/Exceptions: None
       
  3991 
       
  3992     Status: Proposal
       
  3993     
       
  3994 -------------------------------------------------------------------------------
       
  3995 */
       
  3996 CInterferenceHandler::CInterferenceHandler( CTestExecution& aExecution ) :
       
  3997     CActive( CActive::EPriorityStandard ),
       
  3998     iExecution( aExecution )
       
  3999     {
       
  4000     CActiveScheduler::Add ( this );
       
  4001     
       
  4002     }
       
  4003 
       
  4004 /*
       
  4005 -------------------------------------------------------------------------------
       
  4006 
       
  4007     Class: CInterferenceHandler
       
  4008 
       
  4009     Method: ~CInterferenceHandler
       
  4010 
       
  4011     Description: Destructor. 
       
  4012     Cancels active request.
       
  4013 
       
  4014     Parameters: None
       
  4015 
       
  4016     Return Values: None
       
  4017 
       
  4018     Errors/Exceptions: None
       
  4019 
       
  4020     Status: Proposal
       
  4021     
       
  4022 -------------------------------------------------------------------------------
       
  4023 */
       
  4024 CInterferenceHandler::~CInterferenceHandler()
       
  4025     {
       
  4026     Cancel();
       
  4027 
       
  4028     }
       
  4029 
       
  4030 /*
       
  4031 -------------------------------------------------------------------------------
       
  4032 
       
  4033     Class: CInterferenceHandler
       
  4034 
       
  4035     Method: StartL
       
  4036 
       
  4037     Description: Starts to monitor thread.
       
  4038 
       
  4039     Parameters: None
       
  4040 
       
  4041     Return Values: TInt: Always KErrNone
       
  4042 
       
  4043     Errors/Exceptions: None
       
  4044 
       
  4045     Status: Proposal
       
  4046     
       
  4047 -------------------------------------------------------------------------------
       
  4048 */
       
  4049 void CInterferenceHandler::StartL()
       
  4050     {
       
  4051     __TRACE( KPrint, ( _L( "CInterferenceHandler::StartL" ) ) );
       
  4052     
       
  4053     if( IsActive() ) 
       
  4054         {
       
  4055         CTestServer::PanicServer( EAlreadyActive );
       
  4056         }
       
  4057 
       
  4058     iStatus = KRequestPending;
       
  4059     SetActive();
       
  4060     
       
  4061     // Signal test thread, Notify test thread that operation is done.
       
  4062     iExecution.iInterferenceSem.Signal();
       
  4063 
       
  4064     }
       
  4065 
       
  4066 /*
       
  4067 -------------------------------------------------------------------------------
       
  4068 
       
  4069     Class: CInterferenceHandler
       
  4070 
       
  4071     Method: RunL
       
  4072 
       
  4073     Description: Handles thread death.
       
  4074     Function does:
       
  4075     1 ) Stops monitoring thread
       
  4076     1 ) Marks thread death
       
  4077     2 ) Completes ongoing requests
       
  4078     3 ) Cleans the memory
       
  4079 
       
  4080     Parameters: None
       
  4081 
       
  4082     Return Values: None
       
  4083 
       
  4084     Errors/Exceptions: None
       
  4085 
       
  4086     Status: Proposal
       
  4087 
       
  4088 -------------------------------------------------------------------------------
       
  4089 */
       
  4090 void CInterferenceHandler::RunL()
       
  4091     {
       
  4092     __TRACE( KPrint, ( _L( "CInterferenceHandler::RunL [%d]" ), iStatus.Int() ) );
       
  4093     
       
  4094     iExecution.DoNotifyInterference();
       
  4095     
       
  4096     StartL();
       
  4097 
       
  4098     }
       
  4099 
       
  4100 /*
       
  4101 -------------------------------------------------------------------------------
       
  4102 
       
  4103     Class: CInterferenceHandler
       
  4104 
       
  4105     Method: DoCancel
       
  4106 
       
  4107     Description: Stops interference notification listening.
       
  4108 
       
  4109     Parameters: None
       
  4110 
       
  4111     Return Values: None
       
  4112 
       
  4113     Errors/Exceptions: None
       
  4114 
       
  4115     Status: Proposal
       
  4116     
       
  4117 -------------------------------------------------------------------------------
       
  4118 */
       
  4119 void CInterferenceHandler::DoCancel()
       
  4120     {
       
  4121     __TRACE( KPrint, ( _L( "CInterferenceHandler::DoCancel" ) ) );
       
  4122 
       
  4123     iExecution.iInterferenceMutex.Wait();   // Take mutex and check test
       
  4124                                             // interference operation. If
       
  4125                                             // pending take interference
       
  4126                                             // semaphore and complete
       
  4127     if( iStatus == KRequestPending )
       
  4128         {
       
  4129     
       
  4130         TRequestStatus* status = &iStatus;    
       
  4131         User::RequestComplete( status, KErrCancel );
       
  4132         }
       
  4133 
       
  4134     iExecution.iInterferenceMutex.Signal();
       
  4135 
       
  4136     }
       
  4137 
       
  4138 /*
       
  4139 -------------------------------------------------------------------------------
       
  4140 
       
  4141     Class: CInterferenceHandler
       
  4142 
       
  4143     Method: RunError
       
  4144 
       
  4145     Description: Handle errors. RunL function does not leave, so one should
       
  4146     never come here. 
       
  4147 
       
  4148     Print trace and let framework handle error( i.e to do Panic )
       
  4149 
       
  4150     Parameters: TInt aError: in: Error code
       
  4151 
       
  4152     Return Values:  TInt: Error code
       
  4153 
       
  4154     Errors/Exceptions: None
       
  4155 
       
  4156     Status: Proposal
       
  4157 
       
  4158 -------------------------------------------------------------------------------
       
  4159 */
       
  4160 TInt CInterferenceHandler::RunError( TInt aError )
       
  4161     {
       
  4162     __TRACE( KError,( _L( "CTestInterferenceHandler::RunError" ) ) );
       
  4163 
       
  4164     return aError;
       
  4165 
       
  4166     }
       
  4167 
       
  4168 /*
       
  4169 -------------------------------------------------------------------------------
       
  4170 
       
  4171     DESCRIPTION
       
  4172 
       
  4173     This module contains implementation of CMeasurementHandler class 
       
  4174     member functions. CMeasurementHandler handles test measurement operations
       
  4175     that comes from test execution side to TestServer side.
       
  4176 
       
  4177 -------------------------------------------------------------------------------
       
  4178 */
       
  4179 
       
  4180 // ================= MEMBER FUNCTIONS =========================================
       
  4181 
       
  4182 
       
  4183 /*
       
  4184 -------------------------------------------------------------------------------
       
  4185 
       
  4186     Class: CMeasurementHandler
       
  4187 
       
  4188     Method: NewL
       
  4189 
       
  4190     Description: Constructs a new CMeasurementHandler object.
       
  4191 
       
  4192     Parameters: CTestExecution& aExecution: in: Pointer to test execution side.
       
  4193 
       
  4194     Return Values: CMeasurementHandler*: New undertaker
       
  4195 
       
  4196     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  4197 
       
  4198     Status: Approved
       
  4199 
       
  4200 -------------------------------------------------------------------------------
       
  4201 */
       
  4202 CMeasurementHandler* CMeasurementHandler::NewL( CTestExecution& aExecution )
       
  4203     {
       
  4204     CMeasurementHandler* self = 
       
  4205                         new( ELeave ) CMeasurementHandler( aExecution );
       
  4206     CleanupStack::PushL( self );
       
  4207     self->ConstructL();
       
  4208     CleanupStack::Pop( self );
       
  4209     return self;
       
  4210 
       
  4211     }
       
  4212 
       
  4213 /*
       
  4214 -------------------------------------------------------------------------------
       
  4215 
       
  4216     Class: CMeasurementHandler
       
  4217 
       
  4218     Method: ConstructL
       
  4219 
       
  4220     Description: Second level constructor.
       
  4221 
       
  4222     Parameters: None
       
  4223 
       
  4224     Return Values: None
       
  4225 
       
  4226     Errors/Exceptions: None
       
  4227 
       
  4228     Status: Approved
       
  4229 
       
  4230 -------------------------------------------------------------------------------
       
  4231 */
       
  4232 void CMeasurementHandler::ConstructL()
       
  4233     {
       
  4234 
       
  4235     }
       
  4236 
       
  4237 /*
       
  4238 -------------------------------------------------------------------------------
       
  4239 
       
  4240     Class: CMeasurementHandler
       
  4241 
       
  4242     Method: CMeasurementHandler
       
  4243 
       
  4244     Description: Constructor
       
  4245 
       
  4246     Parameters: CTestModuleContainer& aExecution :in: Pointer to test
       
  4247                 execution side.
       
  4248 
       
  4249     Return Values: None
       
  4250 
       
  4251     Errors/Exceptions: None
       
  4252 
       
  4253     Status: Approved
       
  4254 
       
  4255 -------------------------------------------------------------------------------
       
  4256 */
       
  4257 CMeasurementHandler::CMeasurementHandler( CTestExecution& aExecution ) :
       
  4258     CActive( CActive::EPriorityStandard ),
       
  4259     iExecution( aExecution )
       
  4260     {
       
  4261     CActiveScheduler::Add ( this );
       
  4262 
       
  4263     }
       
  4264 
       
  4265 /*
       
  4266 -------------------------------------------------------------------------------
       
  4267 
       
  4268     Class: CMeasurementHandler
       
  4269 
       
  4270     Method: ~CMeasurementHandler
       
  4271 
       
  4272     Description: Destructor. 
       
  4273     Cancels active request.
       
  4274 
       
  4275     Parameters: None
       
  4276 
       
  4277     Return Values: None
       
  4278 
       
  4279     Errors/Exceptions: None
       
  4280 
       
  4281     Status: Approved
       
  4282 
       
  4283 -------------------------------------------------------------------------------
       
  4284 */
       
  4285 CMeasurementHandler::~CMeasurementHandler()
       
  4286     {
       
  4287     Cancel();
       
  4288 
       
  4289     }
       
  4290 
       
  4291 /*
       
  4292 -------------------------------------------------------------------------------
       
  4293 
       
  4294     Class: CMeasurementHandler
       
  4295 
       
  4296     Method: StartL
       
  4297 
       
  4298     Description: Starts to monitor thread.
       
  4299 
       
  4300     Parameters: None
       
  4301 
       
  4302     Return Values: TInt: Always KErrNone
       
  4303 
       
  4304     Errors/Exceptions: None
       
  4305 
       
  4306     Status: Approved
       
  4307 
       
  4308 -------------------------------------------------------------------------------
       
  4309 */
       
  4310 void CMeasurementHandler::StartL()
       
  4311     {
       
  4312     __TRACE( KPrint, ( _L( "CMeasurementHandler::StartL" ) ) );
       
  4313 
       
  4314     if( IsActive() ) 
       
  4315         {
       
  4316         CTestServer::PanicServer( EAlreadyActive );
       
  4317         }
       
  4318 
       
  4319     iStatus = KRequestPending;
       
  4320     SetActive();
       
  4321 
       
  4322     // Do not Signal here because synchronous operations will be executed and we
       
  4323     // don't want to signal at first time: iExecution.iMeasurementSem.Signal();
       
  4324     // Signal() operation will be handled in RunL in this case.
       
  4325 
       
  4326     }
       
  4327 
       
  4328 /*
       
  4329 -------------------------------------------------------------------------------
       
  4330 
       
  4331     Class: CMeasurementHandler
       
  4332 
       
  4333     Method: RunL
       
  4334 
       
  4335     Description: Derived from CActive, handles test measurement execution.
       
  4336 
       
  4337     Parameters: None
       
  4338 
       
  4339     Return Values: None
       
  4340 
       
  4341     Errors/Exceptions: None
       
  4342 
       
  4343     Status: Approved
       
  4344 
       
  4345 -------------------------------------------------------------------------------
       
  4346 */
       
  4347 void CMeasurementHandler::RunL()
       
  4348     {
       
  4349     __TRACE( KPrint, ( _L( "CMeasurementHandler::RunL [%d]" ), iStatus.Int() ) );
       
  4350     
       
  4351     TInt ret( 0 );
       
  4352     ret = iExecution.DoNotifyMeasurement();
       
  4353 
       
  4354     // ret value is copied to struct so it can be handled later.
       
  4355     iExecution.iTestMeasurement.iMeasurementStruct.iOperationResult = ret;
       
  4356     
       
  4357     // SetActive again
       
  4358     StartL();
       
  4359 
       
  4360     // TestServer side operations are done, Signal that operation is done.
       
  4361     iExecution.iMeasurementSem.Signal();
       
  4362 
       
  4363     }
       
  4364 
       
  4365 /*
       
  4366 -------------------------------------------------------------------------------
       
  4367 
       
  4368     Class: CMeasurementHandler
       
  4369 
       
  4370     Method: DoCancel
       
  4371 
       
  4372     Description: Stops measurement notification listening.
       
  4373 
       
  4374     Parameters: None
       
  4375 
       
  4376     Return Values: None
       
  4377 
       
  4378     Errors/Exceptions: None
       
  4379 
       
  4380     Status: Approved
       
  4381     
       
  4382 -------------------------------------------------------------------------------
       
  4383 */
       
  4384 void CMeasurementHandler::DoCancel()
       
  4385     {
       
  4386     __TRACE( KPrint, ( _L( "CMeasurementHandler::DoCancel" ) ) );
       
  4387 
       
  4388     iExecution.iMeasurementMutex.Wait();    // Take mutex and check test
       
  4389                                             // measurement operation. If
       
  4390                                             // pending take measurement
       
  4391                                             // semaphore and complete
       
  4392     if( iStatus == KRequestPending )
       
  4393         {
       
  4394     
       
  4395         TRequestStatus* status = &iStatus;    
       
  4396         User::RequestComplete( status, KErrCancel );
       
  4397         }
       
  4398 
       
  4399     iExecution.iMeasurementMutex.Signal();
       
  4400 
       
  4401     }
       
  4402 
       
  4403 /*
       
  4404 -------------------------------------------------------------------------------
       
  4405 
       
  4406     Class: CMeasurementHandler
       
  4407 
       
  4408     Method: RunError
       
  4409 
       
  4410     Description: Handle errors. RunL function does not leave, so one should
       
  4411     never come here. 
       
  4412 
       
  4413     Print trace and let framework handle error( i.e to do Panic )
       
  4414 
       
  4415     Parameters: TInt aError: in: Error code
       
  4416 
       
  4417     Return Values:  TInt: Error code
       
  4418 
       
  4419     Errors/Exceptions: None
       
  4420 
       
  4421     Status: Approved
       
  4422 
       
  4423 -------------------------------------------------------------------------------
       
  4424 */
       
  4425 TInt CMeasurementHandler::RunError( TInt aError )
       
  4426     {
       
  4427     __TRACE( KError,( 
       
  4428         _L( "CMeasurementHandler::RunError with error: %d" ), aError ) );
       
  4429 
       
  4430     return aError;
       
  4431 
       
  4432     }
       
  4433 
       
  4434 /*
       
  4435 -------------------------------------------------------------------------------
       
  4436 
       
  4437     DESCRIPTION
       
  4438 
       
  4439     This module contains implementation of CCommandHandler class member functions.
       
  4440     CCommandHandler listens command notifications from test thread.
       
  4441 
       
  4442 -------------------------------------------------------------------------------
       
  4443 */
       
  4444 
       
  4445 // ================= MEMBER FUNCTIONS =========================================
       
  4446 
       
  4447 
       
  4448 /*
       
  4449 -------------------------------------------------------------------------------
       
  4450 
       
  4451     Class: CCommandHandler
       
  4452 
       
  4453     Method: NewL
       
  4454 
       
  4455     Description: Constructs a new CCommandHandler object.
       
  4456 
       
  4457     Parameters: CTestExecution& aExecution: in: "Parent"
       
  4458 
       
  4459     Return Values: CCommandHandler*: New object
       
  4460 
       
  4461     Errors/Exceptions: Leaves if memory allocation or ConstructL leaves.
       
  4462 
       
  4463     Status: Proposal
       
  4464 
       
  4465 -------------------------------------------------------------------------------
       
  4466 */
       
  4467 CCommandHandler* CCommandHandler::NewL(CTestExecution& aExecution)
       
  4468     {
       
  4469     CCommandHandler* self = new (ELeave) CCommandHandler(aExecution);
       
  4470     CleanupStack::PushL(self);
       
  4471     self->ConstructL();
       
  4472     CleanupStack::Pop(self);
       
  4473     return self;
       
  4474     }
       
  4475 
       
  4476 /*
       
  4477 -------------------------------------------------------------------------------
       
  4478 
       
  4479     Class: CCommandHandler
       
  4480 
       
  4481     Method: ConstructL
       
  4482 
       
  4483     Description: Second level constructor.
       
  4484 
       
  4485     Parameters: None
       
  4486 
       
  4487     Return Values: None
       
  4488 
       
  4489     Errors/Exceptions: None
       
  4490 
       
  4491     Status: Proposal
       
  4492 
       
  4493 -------------------------------------------------------------------------------
       
  4494 */
       
  4495 void CCommandHandler::ConstructL()
       
  4496     {
       
  4497     }
       
  4498 
       
  4499 /*
       
  4500 -------------------------------------------------------------------------------
       
  4501 
       
  4502     Class: CCommandHandler
       
  4503 
       
  4504     Method: CCommandHandler
       
  4505 
       
  4506     Description: Constructor
       
  4507 
       
  4508     Parameters: CTestExecution& aExecution :in:   "Parent"
       
  4509 
       
  4510     Return Values: None
       
  4511 
       
  4512     Errors/Exceptions: None
       
  4513 
       
  4514     Status: Proposal
       
  4515 
       
  4516 -------------------------------------------------------------------------------
       
  4517 */
       
  4518 CCommandHandler::CCommandHandler(CTestExecution& aExecution):
       
  4519     CActive(CActive::EPriorityStandard),
       
  4520     iExecution(aExecution)
       
  4521     {
       
  4522     CActiveScheduler::Add (this);
       
  4523     }
       
  4524 
       
  4525 /*
       
  4526 -------------------------------------------------------------------------------
       
  4527 
       
  4528     Class: CCommandHandler
       
  4529 
       
  4530     Method: ~CCommandHandler
       
  4531 
       
  4532     Description: Destructor.
       
  4533     Cancels active request.
       
  4534 
       
  4535     Parameters: None
       
  4536 
       
  4537     Return Values: None
       
  4538 
       
  4539     Errors/Exceptions: None
       
  4540 
       
  4541     Status: Proposal
       
  4542 
       
  4543 -------------------------------------------------------------------------------
       
  4544 */
       
  4545 CCommandHandler::~CCommandHandler()
       
  4546     {
       
  4547     Cancel();
       
  4548     }
       
  4549 
       
  4550 /*
       
  4551 -------------------------------------------------------------------------------
       
  4552 
       
  4553     Class: CCommandHandler
       
  4554 
       
  4555     Method: StartL
       
  4556 
       
  4557     Description: Starts to monitor thread.
       
  4558 
       
  4559     Parameters: None
       
  4560 
       
  4561     Return Values: None
       
  4562 
       
  4563     Errors/Exceptions: None
       
  4564 
       
  4565     Status: Proposal
       
  4566 
       
  4567 -------------------------------------------------------------------------------
       
  4568 */
       
  4569 void CCommandHandler::StartL()
       
  4570     {
       
  4571     __TRACE(KPrint, (_L( "CCommandHandler::StartL" )));
       
  4572 
       
  4573     if(IsActive())
       
  4574         {
       
  4575         CTestServer::PanicServer(EAlreadyActive);
       
  4576         }
       
  4577     iStatus = KRequestPending;
       
  4578     SetActive();
       
  4579 
       
  4580     // Signal test thread
       
  4581     iExecution.iCommandSem.Signal();
       
  4582     }
       
  4583 
       
  4584 /*
       
  4585 -------------------------------------------------------------------------------
       
  4586 
       
  4587     Class: CCommandHandler
       
  4588 
       
  4589     Method: RunL
       
  4590 
       
  4591     Description:
       
  4592 
       
  4593     Parameters: None
       
  4594 
       
  4595     Return Values: None
       
  4596 
       
  4597     Errors/Exceptions: None
       
  4598 
       
  4599     Status: Proposal
       
  4600 
       
  4601 -------------------------------------------------------------------------------
       
  4602 */
       
  4603 void CCommandHandler::RunL()
       
  4604     {
       
  4605     __TRACE(KPrint, (_L( "CCommandHandler::RunL [%d]"), iStatus.Int()));
       
  4606 
       
  4607     iExecution.DoNotifyCommand();
       
  4608 //    StartL();
       
  4609     }
       
  4610 
       
  4611 
       
  4612 /*
       
  4613 -------------------------------------------------------------------------------
       
  4614 
       
  4615     Class: CCommandHandler
       
  4616 
       
  4617     Method: DoCancel
       
  4618 
       
  4619     Description: Stops command notification listening.
       
  4620 
       
  4621     Parameters: None
       
  4622 
       
  4623     Return Values: None
       
  4624 
       
  4625     Errors/Exceptions: None
       
  4626 
       
  4627     Status: Proposal
       
  4628 
       
  4629 -------------------------------------------------------------------------------
       
  4630 */
       
  4631 
       
  4632 void CCommandHandler::DoCancel()
       
  4633     {
       
  4634     __TRACE(KPrint, (_L("CCommandHandler::DoCancel")));
       
  4635 
       
  4636     iExecution.iCommandMutex.Wait();  // Take mutex and check test case receive
       
  4637                                       // operation. If pending take reveive
       
  4638                                       // semaphore and complete
       
  4639     if(iStatus == KRequestPending)
       
  4640         {
       
  4641         TRequestStatus* status = &iStatus;
       
  4642         User::RequestComplete(status, KErrCancel);
       
  4643         }
       
  4644 
       
  4645     iExecution.iCommandMutex.Signal();
       
  4646     }
       
  4647 
       
  4648 /*
       
  4649 -------------------------------------------------------------------------------
       
  4650 
       
  4651     Class: CCommandHandler
       
  4652 
       
  4653     Method: RunError
       
  4654 
       
  4655     Description: Handle errors. RunL function does not leave, so one should
       
  4656     never come here.
       
  4657 
       
  4658     Print trace and let framework handle error( i.e to do Panic )
       
  4659 
       
  4660     Parameters: TInt aError:                  :in:  Error code
       
  4661 
       
  4662     Return Values:  TInt                            Error code
       
  4663 
       
  4664     Errors/Exceptions: None
       
  4665 
       
  4666     Status: Proposal
       
  4667 
       
  4668 -------------------------------------------------------------------------------
       
  4669 */
       
  4670 TInt CCommandHandler::RunError(TInt aError)
       
  4671     {
       
  4672     __TRACE(KError, (_L("CCommandHandler::RunError")));
       
  4673 
       
  4674     return aError;
       
  4675     }
       
  4676 
       
  4677 /*
       
  4678 -------------------------------------------------------------------------------
       
  4679 
       
  4680     Class: CCommandDef
       
  4681 
       
  4682     Method: CCommandDef
       
  4683 
       
  4684     Description: private constructor
       
  4685 
       
  4686     Return Values:  void
       
  4687 
       
  4688 -------------------------------------------------------------------------------
       
  4689 */
       
  4690 
       
  4691 CCommandDef::CCommandDef()
       
  4692 	{
       
  4693 	}
       
  4694 
       
  4695 /*
       
  4696 -------------------------------------------------------------------------------
       
  4697 
       
  4698     Class: CCommandDef
       
  4699 
       
  4700     Method: ConstructL
       
  4701 
       
  4702     Description: Second phase constructor
       
  4703 
       
  4704     Return Values:  void
       
  4705 
       
  4706 -------------------------------------------------------------------------------
       
  4707 */
       
  4708 
       
  4709 void CCommandDef::ConstructL()
       
  4710 	{
       
  4711 
       
  4712 	}
       
  4713 
       
  4714 /*
       
  4715 -------------------------------------------------------------------------------
       
  4716 
       
  4717     Class: CCommandDef
       
  4718 
       
  4719     Method: NewL
       
  4720 
       
  4721     Description: First phase constructor
       
  4722 
       
  4723     Return Values:  void
       
  4724 
       
  4725 -------------------------------------------------------------------------------
       
  4726 */
       
  4727 
       
  4728 CCommandDef* CCommandDef::NewL()
       
  4729 	{
       
  4730 	CCommandDef* self = new(ELeave) CCommandDef;
       
  4731 	CleanupStack::PushL(self);
       
  4732 	self->ConstructL();
       
  4733 	CleanupStack::Pop(self);
       
  4734 	return self;
       
  4735 	}
       
  4736 
       
  4737 /*
       
  4738 -------------------------------------------------------------------------------
       
  4739 
       
  4740     Class: CCommandDef
       
  4741 
       
  4742     Method: ~CCommandDef
       
  4743 
       
  4744     Description: destructor
       
  4745 
       
  4746 -------------------------------------------------------------------------------
       
  4747 */
       
  4748 
       
  4749 CCommandDef::~CCommandDef()
       
  4750 	{
       
  4751 
       
  4752 	}
       
  4753 
       
  4754 //  End of File