testexecfw/stf/stfui/uiengine/src/UIEngineEvent.cpp
changeset 2 8bb370ba6d1d
equal deleted inserted replaced
1:bbd31066657e 2:8bb370ba6d1d
       
     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: CUIEngineEvent: This object executes test cases 
       
    15 * from STIF Test Framework.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32svr.h>
       
    22 #include <stifinternal/UIEngineContainer.h>
       
    23 #include "UIEngineEvent.h"
       
    24 #include "Logging.h"
       
    25 #include <stfeventsystem.h>
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 // None
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 // None
       
    32 
       
    33 // CONSTANTS
       
    34 // None
       
    35 
       
    36 // MACROS
       
    37 #ifdef LOGGER
       
    38 #undef LOGGER
       
    39 #endif
       
    40 #define LOGGER iUIEngine->iLogger
       
    41 
       
    42 
       
    43 // LOCAL CONSTANTS AND MACROS
       
    44 // None
       
    45 
       
    46 // MODULE DATA STRUCTURES
       
    47 // None
       
    48 
       
    49 // LOCAL FUNCTION PROTOTYPES
       
    50 // None
       
    51 
       
    52 // FORWARD DECLARATIONS
       
    53 // None
       
    54 
       
    55 
       
    56 // ==================== LOCAL FUNCTIONS ======================================= 
       
    57 // None
       
    58 
       
    59 // ================= MEMBER FUNCTIONS =========================================
       
    60 
       
    61 /*
       
    62 -------------------------------------------------------------------------------
       
    63 
       
    64     Class: CUIEngineEvent
       
    65 
       
    66     Method: CUIEngineEvent
       
    67 
       
    68     Description: Default constructor
       
    69 
       
    70     C++ default constructor can NOT contain any code, that
       
    71     might leave.
       
    72 
       
    73     Parameters: None
       
    74     
       
    75     Return Values: None
       
    76 
       
    77     Errors/Exceptions: None
       
    78 
       
    79     Status: Draft
       
    80 
       
    81 -------------------------------------------------------------------------------
       
    82 */
       
    83 CUIEngineEvent::CUIEngineEvent( CUIEngine* aUIEngine) :
       
    84     CActive( CActive::EPriorityStandard ),
       
    85     iState( EEventIdle ),
       
    86     iUIEngine( aUIEngine ),
       
    87     iEventPckg( iEvent )
       
    88     {
       
    89     __TRACE( KPrint, ( _L( "CUIEngineEvent::CUIEngineEvent") ) );
       
    90     __ASSERT_ALWAYS( aUIEngine, User::Panic( _L("Null pointer"), KErrGeneral ) );
       
    91 
       
    92     CActiveScheduler::Add( this );
       
    93     }
       
    94 
       
    95 
       
    96 /*
       
    97 -------------------------------------------------------------------------------
       
    98 
       
    99     Class: CUIEngineEvent
       
   100 
       
   101     Method: ConstructL
       
   102 
       
   103     Description: Symbian OS second phase constructor
       
   104 
       
   105     Symbian OS default constructor can leave.
       
   106 
       
   107     Parameters: None
       
   108 
       
   109     Return Values: None
       
   110 
       
   111     Errors/Exceptions: Leaves if called Open method returns error
       
   112 
       
   113     Status: Approved
       
   114 
       
   115 -------------------------------------------------------------------------------
       
   116 */
       
   117 void CUIEngineEvent::ConstructL()
       
   118     {
       
   119 
       
   120     }
       
   121 
       
   122 
       
   123 /*
       
   124 -------------------------------------------------------------------------------
       
   125 
       
   126     Class: CUIEngineEvent
       
   127 
       
   128     Method: NewL
       
   129 
       
   130     Description: Two-phased constructor.
       
   131     
       
   132     Parameters: CUIEngineContainer* CUIEngineContainer: in: Pointer to CUIEngineContainer Interface
       
   133                 TTestInfo& aTestInfo: in: Test info
       
   134 
       
   135     Return Values: CUIEngineEvent* : Pointer to created runner object
       
   136 
       
   137     Errors/Exceptions: Leaves if memory allocation for CUIEngineEvent fails
       
   138                        Leaves if ConstructL leaves
       
   139 
       
   140     Status: Draft
       
   141 
       
   142 -------------------------------------------------------------------------------
       
   143 */
       
   144 CUIEngineEvent* CUIEngineEvent::NewL( CUIEngine* aUIEngine )
       
   145     {
       
   146     CUIEngineEvent* self =  
       
   147         new ( ELeave ) CUIEngineEvent( aUIEngine );
       
   148     CleanupStack::PushL( self );
       
   149     self->ConstructL();
       
   150     CleanupStack::Pop();
       
   151     return self;
       
   152     }
       
   153 
       
   154 
       
   155 /*
       
   156 -------------------------------------------------------------------------------
       
   157 
       
   158     Class: CUIEngineEvent
       
   159 
       
   160     Method: ~CUIEngineEvent
       
   161 
       
   162     Description: Destructor
       
   163     
       
   164     Parameters: None
       
   165 
       
   166     Return Values: None
       
   167 
       
   168     Errors/Exceptions: None
       
   169 
       
   170     Status: Draft
       
   171 
       
   172 -------------------------------------------------------------------------------
       
   173 */
       
   174 CUIEngineEvent::~CUIEngineEvent()
       
   175     {
       
   176     
       
   177     __TRACE( KPrint, ( _L( "CUIEngineEvent::~CUIEngineEvent()") ) );
       
   178     Cancel();
       
   179     
       
   180     if( iState == EEventWaitCompleted )
       
   181         {
       
   182         // Release event
       
   183         Release();
       
   184         }
       
   185     
       
   186     if(iAsyncEventActive)
       
   187         {
       
   188         delete iAsyncEventActive;
       
   189         iAsyncEventActive = NULL;
       
   190         }
       
   191     }
       
   192 
       
   193 
       
   194 /*
       
   195 -------------------------------------------------------------------------------
       
   196 
       
   197     Class: CUIEngineEvent
       
   198 
       
   199     Method: Request
       
   200 
       
   201     Description: Request event.
       
   202 
       
   203     Parameters: RTestCase& aTestCase: in: Handle to test case
       
   204                 TFullTestResultPckg& aFullTestResultPckg: in: Handle to TFullTestResultPckg
       
   205 
       
   206     Return Values: None
       
   207 
       
   208     Errors/Exceptions: None
       
   209 
       
   210     Status: Draft
       
   211 
       
   212 -------------------------------------------------------------------------------
       
   213 */
       
   214 TInt CUIEngineEvent::Request( TDesC& aEventName, 
       
   215                                TUint32 aMaster, 
       
   216                                TUint32 aSlave )
       
   217     {
       
   218     
       
   219     __TRACE( KPrint, ( _L( "CUIEngineEvent::Request %S"), &aEventName ) );
       
   220     
       
   221     iState = EEventRequested;
       
   222     
       
   223     iMaster = aMaster;
       
   224     iSlave = aSlave; 
       
   225     iEvent.SetType( TEventIf::EReqEvent );
       
   226     iEvent.SetName( aEventName );
       
   227     
       
   228     // new implementation
       
   229     TInt err;
       
   230     REventSystem ev;
       
   231     RDebug::Print(_L("STF [ES]: CUIEngineEvent::Request() handling request event"));
       
   232     TRAP(err, ev.RequestEventL(aEventName, reinterpret_cast<TInt>(iUIEngine)));
       
   233 
       
   234     /* old event implementation    
       
   235     TRequestStatus status;
       
   236     iUIEngine->iTestEngine.Event( iEventPckg, status ); 
       
   237     User::WaitForRequest( status );
       
   238     */// old event impementation - end
       
   239     
       
   240     if(err == KErrNone )
       
   241         {
       
   242         __ASSERT_ALWAYS(iAsyncEventActive == NULL, User::Panic(_L("CUIEngineEvent::Request"), KErrAlreadyExists));
       
   243         TRAP(err, iAsyncEventActive = CAsyncEventActive::NewL(reinterpret_cast<TInt>(iUIEngine)));
       
   244         if(err != KErrNone)
       
   245             return err;
       
   246         // Enable event waiting
       
   247         iState = EEventWait;            
       
   248         iEvent.SetType( TEventIf::EWaitEvent );
       
   249         SetActive();
       
   250         RThread t;
       
   251         TRAP(err, iAsyncEventActive->StartL(&iStatus, t.Id(), aEventName, NULL));
       
   252         // old implementation iUIEngine->iTestEngine.Event( iEventPckg, iStatus ); 
       
   253         }
       
   254     //return status.Int();
       
   255     return err;
       
   256         
       
   257     }
       
   258     
       
   259 /*
       
   260 -------------------------------------------------------------------------------
       
   261 
       
   262     Class: CUIEngineEvent
       
   263 
       
   264     Method: Release
       
   265 
       
   266     Description: Release event.
       
   267 
       
   268     Parameters: RTestCase& aTestCase: in: Handle to test case
       
   269                 TFullTestResultPckg& aFullTestResultPckg: in: Handle to TFullTestResultPckg
       
   270 
       
   271     Return Values: None
       
   272 
       
   273     Errors/Exceptions: None
       
   274 
       
   275     Status: Draft
       
   276 
       
   277 -------------------------------------------------------------------------------
       
   278 */
       
   279 TInt CUIEngineEvent::Release()
       
   280     {
       
   281     
       
   282     __TRACE( KPrint, ( _L( "CUIEngineEvent::Release %S"), &iEvent.Name() ) );
       
   283     RDebug::Print(_L("STF [ES]: CUIEngineEvent::Release() handling release event"));
       
   284    
       
   285     // new implementation
       
   286     TInt err;
       
   287     REventSystem ev;
       
   288     TRAP(err, ev.ReleaseEventL(iEvent.Name(), reinterpret_cast<TInt>(iUIEngine)));
       
   289     
       
   290     Cancel();
       
   291 
       
   292     return err;
       
   293     
       
   294 /* old implementation
       
   295     TRequestStatus status;
       
   296     // Release event
       
   297     iState = EEventReleased;
       
   298     iEvent.SetType( TEventIf::ERelEvent );
       
   299     iUIEngine->iTestEngine.Event( iEventPckg, status ); 
       
   300     User::WaitForRequest( status ); 
       
   301     
       
   302     return status.Int();
       
   303 */// end old implementation
       
   304     }
       
   305     
       
   306 
       
   307 /*
       
   308 -------------------------------------------------------------------------------
       
   309 
       
   310     Class: CUIEngineEvent
       
   311 
       
   312     Method: RunL
       
   313 
       
   314     Description: RunL handles completed requests.
       
   315 
       
   316     Parameters: None
       
   317 
       
   318     Return Values: None
       
   319 
       
   320     Errors/Exceptions: Leaves if iStatus is not KErrNone, error is handled in
       
   321                        RunError called by CActiveObject
       
   322 
       
   323     Status: Draft
       
   324 
       
   325 -------------------------------------------------------------------------------
       
   326 */
       
   327 void CUIEngineEvent::RunL()
       
   328     {
       
   329     
       
   330     __TRACE( KPrint, ( _L( "CUIEngineEvent::RunL") ) );
       
   331 
       
   332     if(iAsyncEventActive)
       
   333         {
       
   334         delete iAsyncEventActive;
       
   335         iAsyncEventActive = NULL;
       
   336         }
       
   337 
       
   338     // Error handled in RunError
       
   339     User::LeaveIfError ( iStatus.Int() );
       
   340     
       
   341     switch( iState )
       
   342         {
       
   343         case EEventWait:
       
   344             {
       
   345             // Create response 
       
   346             CStifTFwIfProt* resp = CStifTFwIfProt::NewL();
       
   347             CleanupStack::PushL( resp );    
       
   348             
       
   349             resp->CreateL();
       
   350             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgResponse );
       
   351             resp->AppendId( iSlave );
       
   352             resp->AppendId( iMaster );
       
   353             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
   354             resp->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest );
       
   355             resp->Append( CStifTFwIfProt::EventStatus, 
       
   356                          CStifTFwIfProt::EEventSet );
       
   357             resp->Append( iEvent.Name() );
       
   358             if( iEvent.EventType() == TEventIf::EState )
       
   359                 {
       
   360                 resp->Append( CStifTFwIfProt::EventStatusParams, 
       
   361                              CStifTFwIfProt::EEventType,
       
   362                              CStifTFwIfProt::EventType, 
       
   363                              TEventIf::EState );
       
   364                 } 
       
   365             // Send response
       
   366             iUIEngine->RemoteMsg( NULL, resp->Message() );
       
   367             CleanupStack::PopAndDestroy( resp );    
       
   368             
       
   369             if( iEvent.EventType() == TEventIf::EIndication )
       
   370                 {            
       
   371                 // Enable indication event waiting again
       
   372                 iEvent.SetType( TEventIf::EWaitEvent );
       
   373                 SetActive();
       
   374                 // old implementation iUIEngine->iTestEngine.Event( iEventPckg, iStatus );
       
   375                 iAsyncEventActive = CAsyncEventActive::NewL(reinterpret_cast<TInt>(iUIEngine));
       
   376                 // Enable event waiting
       
   377                 RThread t;
       
   378                 iAsyncEventActive->StartL(&iStatus, t.Id(), iEvent.Name(), NULL);
       
   379                 }
       
   380             else  // state event, set only once for one request
       
   381                 {                
       
   382                 iState = EEventWaitCompleted;
       
   383                 }
       
   384             }
       
   385             break;
       
   386         case EEventWaitCompleted:
       
   387         case EEventRequested:
       
   388         case EEventReleased:
       
   389         default:
       
   390             __TRACE( KError, ( _L( "CUIEngineEvent::RunL: Illegal state %d"), iState ) );
       
   391             User::Leave( KErrGeneral );
       
   392         }
       
   393     }
       
   394 
       
   395 /*
       
   396 -------------------------------------------------------------------------------
       
   397 
       
   398     Class: CUIEngineEvent
       
   399 
       
   400     Method: DoCancel
       
   401 
       
   402     Description: Cancel active request.
       
   403 
       
   404     Parameters: None
       
   405 
       
   406     Return Values: None
       
   407 
       
   408     Errors/Exceptions: None
       
   409 
       
   410     Status: Draft
       
   411 
       
   412 -------------------------------------------------------------------------------
       
   413 */
       
   414 void CUIEngineEvent::DoCancel()
       
   415     {
       
   416     
       
   417     __TRACE( KPrint, ( _L( "CUIEngineEvent::DoCancel") ) );
       
   418     
       
   419     if(iAsyncEventActive)
       
   420         {
       
   421         iAsyncEventActive->Cancel();
       
   422         delete iAsyncEventActive;
       
   423         iAsyncEventActive = NULL;
       
   424         }
       
   425     /* old implementation
       
   426     TRequestStatus status;
       
   427 
       
   428     switch( iState )
       
   429         {
       
   430         case EEventWait:
       
   431             // First cancel waiting
       
   432             iEvent.SetType( TEventIf::ECancelWait );
       
   433             iUIEngine->iTestEngine.Event( iEventPckg, status );
       
   434             User::WaitForRequest( status ); 
       
   435             iState = EEventWaitCompleted;
       
   436             break;
       
   437         default:
       
   438             iUIEngine->iTestEngine.CancelAsyncRequest( ETestEngineEvent ); 
       
   439             iState = EEventIdle;
       
   440             break;
       
   441         }
       
   442     */
       
   443     }
       
   444 
       
   445 
       
   446 /*
       
   447 -------------------------------------------------------------------------------
       
   448 
       
   449     Class: CUIEngineEvent
       
   450 
       
   451     Method: RunError
       
   452 
       
   453     Description: Handle errors from STIF TestFramework
       
   454 
       
   455     Parameters: TInt aError: in: Symbian OS error: Error code
       
   456     
       
   457     Return Values: TInt KErrNone: Always returned KErrNone
       
   458 
       
   459     Errors/Exceptions: None
       
   460 
       
   461     Status: Draft
       
   462 
       
   463 -------------------------------------------------------------------------------
       
   464 */
       
   465 TInt CUIEngineEvent::RunError( TInt aError )
       
   466     {
       
   467     __TRACE( KPrint, ( _L( "CUIEngineEvent::RunError") ) );
       
   468 
       
   469     switch( iState )
       
   470         {
       
   471         case EEventRequested:
       
   472         case EEventWait:
       
   473         case EEventWaitCompleted:
       
   474         case EEventReleased:
       
   475             {
       
   476             // Create response
       
   477             CStifTFwIfProt* resp = NULL; 
       
   478             TRAPD( err, resp = CStifTFwIfProt::NewL(); );
       
   479             if( err != KErrNone )
       
   480                 {
       
   481                 return KErrNone;
       
   482                 }
       
   483 
       
   484             resp->CreateL();
       
   485             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgResponse );
       
   486             resp->AppendId( iSlave );
       
   487             resp->AppendId( iMaster );
       
   488             resp->Append( CStifTFwIfProt::MsgType, CStifTFwIfProt::EMsgRemote );
       
   489             resp->Append( CStifTFwIfProt::CmdType, CStifTFwIfProt::ECmdRequest );
       
   490             resp->Append( CStifTFwIfProt::EventStatus, 
       
   491                          CStifTFwIfProt::EEventError );
       
   492             resp->Append( iEvent.Name() );
       
   493             resp->Append( CStifTFwIfProt::EventStatusParams, 
       
   494                              CStifTFwIfProt::EEventResult,
       
   495                              aError );
       
   496             
       
   497             // Send response
       
   498             iUIEngine->RemoteMsg( NULL, resp->Message() ); 
       
   499             delete resp;
       
   500             }
       
   501             break;
       
   502         default:
       
   503             __TRACE( KError, ( _L( "CUIEngineEvent::RunError: Illegal state %d"), iState ) );
       
   504             return aError;
       
   505         }
       
   506     
       
   507     return KErrNone;
       
   508     }
       
   509 
       
   510 
       
   511 /*
       
   512 -------------------------------------------------------------------------------
       
   513 
       
   514     DESCRIPTION
       
   515 
       
   516     CActiveTimer: This object prints running seconds to console screen.
       
   517 
       
   518 -------------------------------------------------------------------------------
       
   519 */
       
   520 
       
   521 // ================= MEMBER FUNCTIONS =========================================
       
   522 
       
   523 
       
   524 
       
   525 
       
   526 // ================= OTHER EXPORTED FUNCTIONS ================================= 
       
   527 // None
       
   528 
       
   529 //  End of File