testexecfw/stf/stfext/testmodules/scriptermod/inc/TestScripterUtils.h
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: This file contains the header file of the TestScripter 
       
    15  * module of STIF Test Framework.
       
    16  *
       
    17  */
       
    18 
       
    19 #ifndef TESTSCRIPTERUTILS_H_
       
    20 #define TESTSCRIPTERUTILS_H_
       
    21 
       
    22 //  INCLUDES
       
    23 #include <StifTestInterface.h>
       
    24 #include <StifTFwIfProt.h>
       
    25 
       
    26 // CONSTANTS
       
    27 // None
       
    28 
       
    29 // MACROS
       
    30 // None
       
    31 
       
    32 // DATA TYPES
       
    33 typedef TBuf<0x200> TRemoteProtMsg;
       
    34 
       
    35 // FUNCTION PROTOTYPES
       
    36 // None
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class CTestRunner;
       
    40 class CSubTestCaseRunner;
       
    41 class CRemoteCallTimeoutMonitor;
       
    42 class CStifTFwIfProt;
       
    43 class CStifLogger;
       
    44 class CSlave;
       
    45 class CRemoteSubTestCaseRunner;
       
    46 
       
    47 // DESCRIPTION
       
    48 // Testcase starting information
       
    49 NONSHARABLE_CLASS(CStartInfo): public CBase
       
    50     {
       
    51     public: // Constructors and destructor
       
    52         /**
       
    53         * Two-phased constructor.
       
    54         */
       
    55         static CStartInfo* NewL();
       
    56         
       
    57         /**
       
    58         * Destructor.
       
    59         */
       
    60         virtual ~CStartInfo();
       
    61             
       
    62     public: // New functions
       
    63         /**
       
    64         * Sets module name.
       
    65         */
       
    66         void SetModuleNameL( const TDesC& aModule, TInt aExtLength = 0 );
       
    67             
       
    68         /**
       
    69         * Sets initialization file name.
       
    70         */
       
    71         void SetIniFileL( const TDesC& aIni );
       
    72             
       
    73         /**
       
    74         * Sets configuration file name.
       
    75         */
       
    76         void SetConfigL( const TDesC& aConfig );
       
    77             
       
    78         /**
       
    79         * Sets test identifier.
       
    80         */
       
    81         void SetTestIdL( const TDesC& aTestId );
       
    82 
       
    83         /**
       
    84         * Sets test case title.
       
    85         */
       
    86         void SetTitleL( const TDesC& aTitle);
       
    87 
       
    88         /**
       
    89          * Sets test case index.
       
    90          */
       
    91         void SetTestCaseNumber( TInt aTestCaseNumber );
       
    92         
       
    93         /**
       
    94          * Sets test case expected result.
       
    95          */
       
    96         void SetExpectedResult( TInt aExpectedResult );
       
    97         
       
    98         /**
       
    99          * Sets expected result category.
       
   100          */
       
   101         void SetExpectedResultCategory( TFullTestResult::TCaseExecutionResult aCategory );
       
   102 
       
   103         /**
       
   104          * Sets timeout value.
       
   105          */
       
   106         void SetTimeout( TInt aTimeout );
       
   107         
       
   108         /**
       
   109          * Gets test module name.
       
   110          */
       
   111         const TDesC& GetModuleName() const;
       
   112 
       
   113         /**
       
   114          * Gets ini file path.
       
   115          */
       
   116         const TDesC& GetIniFile() const;
       
   117 
       
   118         /**
       
   119          * Gets config file path
       
   120          */
       
   121         const TDesC& GetConfig() const;
       
   122 
       
   123         /**
       
   124          * Gets test case id.
       
   125          */
       
   126         const TDesC& GetTestId() const;
       
   127 
       
   128         /**
       
   129          * Gets test case title.
       
   130          */
       
   131         const TDesC& GetTitle() const;
       
   132 
       
   133         /**
       
   134          * Gets test case title.
       
   135          */
       
   136         TInt GetTestCaseNumber() const;
       
   137         
       
   138         /**
       
   139          * Gets expected result.
       
   140          */
       
   141         TInt GetExpectedResult() const;
       
   142 
       
   143         /**
       
   144          * Gets expected result category.
       
   145          */
       
   146         TFullTestResult::TCaseExecutionResult GetExpectedResultCategory() const;
       
   147 
       
   148         /**
       
   149          * Gets timeout value.
       
   150          */
       
   151         TInt GetTimeout() const;
       
   152 
       
   153         /**
       
   154          * Copy values from other CStartInfo instance.
       
   155          */
       
   156         void CopyL( const CStartInfo& aStartInfo );
       
   157         
       
   158     private:
       
   159         /**
       
   160         * C++ default constructor.
       
   161         */
       
   162         CStartInfo();
       
   163                     
       
   164         /**
       
   165         * By default Symbian OS constructor is private.
       
   166         */
       
   167         void ConstructL();
       
   168                 
       
   169     private:
       
   170         // Module name
       
   171         HBufC*  iModule;
       
   172         
       
   173         // Ini file path
       
   174         HBufC*  iIniFile;
       
   175         
       
   176         // Config file path
       
   177         HBufC*  iConfig;
       
   178         
       
   179         // Test id ( used for complete, pausetest, reasume
       
   180         HBufC*  iTestId;
       
   181         
       
   182         // Title of the test case
       
   183         HBufC*  iTitle;
       
   184 
       
   185         // Test case index
       
   186         TInt    iCaseNum;
       
   187         
       
   188         // Test case expected result
       
   189         TInt    iExpectedResult;
       
   190         
       
   191         // Test case expected result category
       
   192         TFullTestResult::TCaseExecutionResult iCategory;
       
   193         
       
   194         // Test case timeout value
       
   195         TInt    iTimeout;
       
   196     };
       
   197 
       
   198 // TestScripter loop helper
       
   199 NONSHARABLE_CLASS(CLoopHelper): public CActive
       
   200     {
       
   201     public:
       
   202         /**
       
   203         * Two-phased constructor.
       
   204         */
       
   205         static CLoopHelper* NewL( CTestRunner* aTestRunner );
       
   206     public:
       
   207         /**
       
   208         * Destrucktor.
       
   209         */
       
   210         ~CLoopHelper();
       
   211         
       
   212         /**
       
   213          * Should be to indicate loop start.
       
   214          */
       
   215         void LoopStartL();
       
   216         
       
   217         /**
       
   218          * Should be called to indicate end of iteration and begining of next iteration
       
   219          */
       
   220         void IterationEndStartNextIterationL();
       
   221         
       
   222         /**
       
   223          * Should be called to indicate loop end
       
   224          */
       
   225         void LoopEndL();
       
   226 
       
   227         /**
       
   228          * Should be called to register sub test case executed inside loop
       
   229          */
       
   230         void RegisterInLoopSubTestCaseL( CSubTestCaseRunner* aSubTestCaseRunner );
       
   231         
       
   232         /**
       
   233          * Should be called to unregister sub test case executed inside loop
       
   234          */
       
   235         void UnregisterInLoopSubTestCaseL( CSubTestCaseRunner* aSubTestCaseRunner );
       
   236 
       
   237         /**
       
   238          * Should be called to register remote event allocated inside loop
       
   239          */
       
   240         void RegisterInLoopSlaveL( CSlave* aSlave );
       
   241 
       
   242         /**
       
   243          * Should be called to unregister remote event allocated inside loop
       
   244          */
       
   245         void UnregisterInLoopSlaveL( CSlave* aSlave );
       
   246         
       
   247         /**
       
   248          * Returns array of registered in loop slaves.
       
   249          */
       
   250         RPointerArray<CSlave>& GetRegisteredInLoopSlaves();
       
   251         
       
   252         /**
       
   253          * Should be called to indicate end of sub test case executed inside loop
       
   254          */
       
   255         void NotifySubTestCaseEndL( CSubTestCaseRunner* aSubTestCaseRunner, TBool aPassed );
       
   256         
       
   257         /**
       
   258          * Indicates whether loop is in progress or not
       
   259          */
       
   260         TBool LoopInProgress() const;
       
   261     private:
       
   262         /**
       
   263          * Constructor
       
   264          */
       
   265         CLoopHelper( CTestRunner* aTestRunner );
       
   266         
       
   267         /**
       
   268         * By default Symbian OS constructor is private.
       
   269         */
       
   270         void ConstructL();
       
   271         
       
   272         /**
       
   273          * See CActive::DoCancel
       
   274          */
       
   275         void DoCancel();
       
   276         
       
   277         /**
       
   278          * See CActive::Runl
       
   279          */
       
   280         void RunL();
       
   281 
       
   282         /**
       
   283          * Indicate begining of the loop iteration
       
   284          */
       
   285         void IterationBeginL( TBool aFirstIteration );
       
   286 
       
   287         /**
       
   288          * Indicate end of the loop iteration
       
   289          */
       
   290         void IterationEndL( TBool aLastIteration );        
       
   291     private:
       
   292         // Pointer to CTestRunner
       
   293         CTestRunner* iTestRunner;
       
   294         
       
   295         // Indicates whether loop is in progress
       
   296         TBool iInProgress;
       
   297         
       
   298         // Indicates whether loop iteration is ongoing
       
   299         TBool iIterationOngoing;
       
   300         
       
   301         // Indicates whether current iteration is last iteration 
       
   302         TBool iLoopEnd;
       
   303         
       
   304         // Counter of passed iterations
       
   305         TInt iPassedIterationsCounter;
       
   306         
       
   307         // Indicates if current iteration should be count as passed or failed
       
   308         TBool iPassCurrentIteration;
       
   309         
       
   310         // Array of sub test cases executed in loop
       
   311         RPointerArray<CSubTestCaseRunner> iInLoopSubTestCases;    
       
   312         
       
   313         // Array of remote events allocated inside loop
       
   314         RPointerArray<CSlave> iInLoopSlaves;
       
   315     };   
       
   316 
       
   317 // TestScripter remote event wrapper
       
   318 class TEventTS: public TEventIf
       
   319     {
       
   320     public:  // Constructors and destructor
       
   321         /**
       
   322         * C++ default constructor.
       
   323         */
       
   324         TEventTS();
       
   325         
       
   326         /**
       
   327         * C++ parametric constructor.
       
   328         */
       
   329         TEventTS( TName& aEventName );
       
   330   
       
   331         /**
       
   332         * C++ destructor.
       
   333         */
       
   334         ~TEventTS();
       
   335 
       
   336     public: // New functions
       
   337         
       
   338         /**
       
   339         * Set request status member.
       
   340         */
       
   341         void SetRequestStatus( TRequestStatus* aStatus );
       
   342         
       
   343         /**
       
   344         * Set event pending.
       
   345         */
       
   346         void SetEvent( TEventType aEventType );
       
   347         
       
   348         /**
       
   349         * Wait event.
       
   350         */
       
   351         void WaitEvent( TRequestStatus& aStatus );
       
   352         
       
   353     private: // New functions
       
   354         /**
       
   355         * Complete request status member.
       
   356         */
       
   357         void Complete( TInt aError );
       
   358 
       
   359     private:    // Data
       
   360         /**
       
   361         * Request status.
       
   362         */
       
   363         TRequestStatus* iClientReqStatus; 
       
   364     };
       
   365 
       
   366 // Interface for classes which can handle errors which may occure during remote
       
   367 // message receive
       
   368 NONSHARABLE_CLASS( MReceiveErrorHandler )
       
   369     {
       
   370     public:
       
   371 		/**
       
   372 		 * Handle error which occured during remote message receive
       
   373 		 */
       
   374         virtual void HandleRemoteReceiveError( 
       
   375                 TInt aError, const TDesC& aErrorDescription ) = 0;        
       
   376     };
       
   377 
       
   378 // Interface for classes which should be notified about remote allocate 
       
   379 // and free requests results
       
   380 NONSHARABLE_CLASS( MSlaveAllocateFreeMonitor )
       
   381     {
       
   382     public:
       
   383 		/**
       
   384 		 * Notify slave is allocated
       
   385 		 */
       
   386         virtual void NotifySlaveAllocatedL( TUint16 aSlaveId ) = 0;
       
   387         
       
   388         /**
       
   389          * Notify slave is freed
       
   390          */
       
   391         virtual void NotifySlaveFreedL( TUint16 aSlaveId ) = 0;
       
   392     };
       
   393 
       
   394 // Interface for classes which should be notified about results of remote test 
       
   395 // control requests 
       
   396 NONSHARABLE_CLASS( MRemoteTestCasesMonitor )
       
   397     {
       
   398     public:
       
   399 		/**
       
   400 		 * Notify test case has been started.
       
   401 		 */
       
   402         virtual void NotifyTestCaseStartedL( TUint16 aSlaveId, TUint16 aSlaveTestId ) = 0;
       
   403         
       
   404         /**
       
   405          * Notify test case can't be started.
       
   406          */
       
   407         virtual void NotifyTestCaseRunErrorL( TUint16 aSlaveId, const TFullTestResult& aTestCaseResult ) = 0;
       
   408         
       
   409         /**
       
   410          * Notify execution test case has finished
       
   411          */
       
   412         virtual void NotifyTestCaseFinishedL( TUint16 aSlaveId, TUint16 aSlaveTestId, const TFullTestResult& aTestCaseResult ) = 0;
       
   413         
       
   414         /**
       
   415          * Notify test case has been paused.
       
   416          */
       
   417         virtual void NotifyTestCasePausedL( TUint16 aSlaveId, TUint16 aSlaveTestId ) = 0;
       
   418         
       
   419         /**
       
   420          * Notify test case has been resumed.
       
   421          */
       
   422         virtual void NotifyTestCaseResumedL( TUint16 aSlaveId, TUint16 aSlaveTestId ) = 0;
       
   423         
       
   424         /**
       
   425          * Notify test case has been cancelled.
       
   426          */
       
   427         virtual void NotifyTestCaseCancelledL( TUint16 aSlaveId, TUint16 aSlaveTestId ) = 0;
       
   428     };
       
   429 
       
   430 // Interface for classes which should be notified about results of remote events
       
   431 // control requests.
       
   432 NONSHARABLE_CLASS( MRemoteEventsMonitor )
       
   433     {
       
   434     public:
       
   435 		/**
       
   436 		 * Notify remote event has been requested
       
   437 		 */
       
   438         virtual void NotifyEventRequestedL( TUint16 aSlaveId, 
       
   439                 const TDesC& aEventName, 
       
   440                 CStifTFwIfProt::TEventStatus aEventStatus,
       
   441                 TEventIf::TEventType aEventType,
       
   442                 TInt aResult ) = 0;
       
   443 
       
   444         /**
       
   445          * Notify remote event state has changed
       
   446          */
       
   447         virtual void NotifyEventStateChangedL( TUint16 aSlaveId, 
       
   448                 const TDesC& aEventName, 
       
   449                 CStifTFwIfProt::TEventStatus aEventStatus,
       
   450                 TEventIf::TEventType aEventType,
       
   451                 TInt aResult ) = 0;
       
   452         
       
   453         /**
       
   454          * Notify remote event has been released
       
   455          */
       
   456         virtual void NotifyEventReleasedL( TUint16 aSlaveId, 
       
   457                 const TDesC& aEventName, TInt aResult ) = 0;
       
   458         
       
   459         /**
       
   460          * Notify remote event has been sucessfully set
       
   461          */
       
   462         virtual void NotifyEventSetCompletedL( TUint16 aSlaveId, 
       
   463                 const TDesC& aEventName, TInt aResult ) = 0;
       
   464         
       
   465         /**
       
   466          * Notify remote event has been sucessfully unset
       
   467          */
       
   468         virtual void NotifyEventUnsetCompletedL( TUint16 aSlaveId, 
       
   469                 const TDesC& aEventName, TInt aResult ) = 0;        
       
   470     };
       
   471 
       
   472 // Interface for classes which should be notified about results of sendreceive 
       
   473 // and send unknown requests 
       
   474 NONSHARABLE_CLASS( MRemoteSendReceiveMonitor )
       
   475     {
       
   476     public:
       
   477 		/**
       
   478 		 * Notify sendreceive request has been started
       
   479 		 */
       
   480         virtual void NotifySendReceiveStartedL( TUint16 aSlaveId ) = 0;
       
   481 
       
   482         /**
       
   483          * Notify sendreceive request has finished
       
   484          */
       
   485         virtual void NotifySendReceiveResultL( 
       
   486                 TUint16 aSlaveId, 
       
   487                 CStifTFwIfProt::TRunStatus aRunStatus,
       
   488                 TInt aRunResult ) = 0;
       
   489         
       
   490         /**
       
   491          * Notify send unknown request has finished
       
   492          */
       
   493         virtual void NotifySendUnknownL( TUint16 aSlaveId, TInt aResult ) = 0;        
       
   494     };
       
   495 
       
   496 // This class creates, execute and recive respons for master-slave requests
       
   497 NONSHARABLE_CLASS( CRemoteCallsProxy ): public CActive
       
   498     {
       
   499     public:
       
   500 		/**
       
   501 		 * Two phase constructor.
       
   502 		 */
       
   503         static CRemoteCallsProxy* NewL( CTestModuleIf& aTestModuleIf, CStifLogger* aLogger );
       
   504     public:
       
   505         /**
       
   506          * Destructor.
       
   507          */
       
   508         ~CRemoteCallsProxy();
       
   509 
       
   510         /**
       
   511          * Sends slave allocate request.
       
   512          */
       
   513         void AllocateL( TUint32 aMasterId, const TDesC& aType );
       
   514         
       
   515         /**
       
   516          * Sends slave free request.
       
   517          */
       
   518         void FreeL( TUint32 aMasterId, TUint16 aSlaveId );
       
   519         
       
   520         /**
       
   521          * Sends sendreceive request.
       
   522          */
       
   523         void SendReceiveL(  TUint32 aMasterId, TUint16 aSlaveId, const TDesC& aMessage );
       
   524         
       
   525         /**
       
   526          * Sends unknown request
       
   527          */        
       
   528         void SendUnknownL(  TUint32 aMasterId, TUint16 aSlaveId,
       
   529                 const TDesC& aCommand, const TDesC& aMessage );
       
   530         
       
   531         /**
       
   532          * Sends start test case request.
       
   533          */
       
   534         void RunTestCaseL( TUint32 aMasterId, TUint16 aSlaveId, CStartInfo* aStartInfo );
       
   535         
       
   536         /**
       
   537          * Sends pause test case request.
       
   538          */
       
   539         void PauseTestCaseL( TUint32 aMasterId, TUint16 aSlaveId, TUint16 aTestId );
       
   540         
       
   541         /**
       
   542          * Sends resume test case request.
       
   543          */
       
   544         void ResumeTestCaseL( TUint32 aMasterId, TUint16 aSlaveId, TUint16 aTestId );
       
   545         
       
   546         /**
       
   547          * Sends cancel test case request.
       
   548          */
       
   549         void CancelTestCaseL( TUint32 aMasterId, TUint16 aSlaveId, TUint16 aTestId );
       
   550         
       
   551         /**
       
   552          * Sends request event request.
       
   553          */
       
   554         void RequestEventL( TUint32 aMasterId, TUint16 aSlaveId, const TDesC& aEventName );
       
   555         
       
   556         /**
       
   557          * Sends set event request.
       
   558          */
       
   559         void SetEventL( TUint32 aMasterId, TUint16 aSlaveId, const TDesC& aEventName, 
       
   560                 TEventIf::TEventType aEventType = TEventIf::EIndication );
       
   561         
       
   562         /**
       
   563          * Sends unset event request.
       
   564          */
       
   565         void UnsetEventL( TUint32 aMasterId, TUint16 aSlaveId, const TDesC& aEventName );
       
   566         
       
   567         /**
       
   568          * Sends release event request.
       
   569          */
       
   570         void ReleaseEventL( TUint32 aMasterId, TUint16 aSlaveId, const TDesC& aEventName );
       
   571         
       
   572         /**
       
   573          * Sets slave allocate/free requests notyfications handler.
       
   574          */
       
   575         void SetSlaveAllocateFreeMonitor( MSlaveAllocateFreeMonitor* aSlaveAllocateFreeMonitor );
       
   576 
       
   577         /**
       
   578          * Sets remote test case control requests notyfications handler.
       
   579          */
       
   580         void SetRemoteTestCasesMonitor( MRemoteTestCasesMonitor* aRemoteTestCasesMonitor );
       
   581 
       
   582         /**
       
   583          * Sets remote events control requests notyfications handler.
       
   584          */
       
   585         void SetRemoteEventsMonitor( MRemoteEventsMonitor* aRemoteEventssMonitor );
       
   586 
       
   587         /**
       
   588          * Sets remote sendreceive request notyfications handler.
       
   589          */
       
   590         void SetRemoteSendReceiveMonitor( MRemoteSendReceiveMonitor* aRemoteSendReceiveMonitor );
       
   591 
       
   592         /**
       
   593          * Sets remote respones receive error handler.
       
   594          */
       
   595         void SetReceiveErrorHandler( MReceiveErrorHandler* aReceiveErrorHandler );
       
   596         
       
   597     private:
       
   598         /**
       
   599          * Constructor.
       
   600          */
       
   601         CRemoteCallsProxy( CTestModuleIf& aTestModuleIf, CStifLogger* aLogger  );
       
   602         
       
   603         /**
       
   604          * Second phase of two phase construction.
       
   605          */
       
   606         void ConstructL();
       
   607         
       
   608         /**
       
   609          * Cancels remote responses receiving.
       
   610          */
       
   611         void DoCancel();
       
   612         
       
   613         /**
       
   614          * Handlers remote request respons
       
   615          */
       
   616         void RunL();
       
   617         
       
   618         /**
       
   619          * Handles errors during remote request response dispatching
       
   620          */
       
   621         TInt RunError( TInt aError );
       
   622         
       
   623         /**
       
   624          * Starts remote requests respons receiving.
       
   625          */
       
   626         void StartReceivingL();
       
   627         
       
   628         /**
       
   629          * Dispatches received remote request response.
       
   630          */
       
   631         void DispatchReceivedRemoteMsgL();
       
   632         
       
   633         /**
       
   634          * Handles slave reserve request response.
       
   635          */
       
   636         void ReceiveResponseReserveL( CStifTFwIfProt* aMsg );
       
   637         
       
   638         /**
       
   639          * Handles slave release request response.
       
   640          */
       
   641         void ReceiveResponseReleaseL( CStifTFwIfProt* aMsg );
       
   642         
       
   643         /**
       
   644          * Handles remote test case run request response.
       
   645          */
       
   646         void ReceiveResponseRunL( CStifTFwIfProt* aMsg );
       
   647         
       
   648         /**
       
   649          * Handles remote test case control request response.
       
   650          */
       
   651         void ReceiveResponseTestCtlL( CStifTFwIfProt* aMsg );
       
   652 
       
   653         /**
       
   654          * Handles remote event control request response.
       
   655          */
       
   656         void ReceiveResponseEventCtlL( CStifTFwIfProt* aMsg );
       
   657 
       
   658         /**
       
   659          * Handles remote sendreceive request response.
       
   660          */
       
   661         void ReceiveResponseSendReceiveL( CStifTFwIfProt* aMsg );
       
   662         
       
   663         /**
       
   664          * Handles remote send unknown request response.
       
   665          */
       
   666         void ReceiveResponseSendUnknownL( CStifTFwIfProt* aMsg );
       
   667     private:
       
   668         // Pointer to STF looger
       
   669         CStifLogger* iLogger;
       
   670         
       
   671         // TestModuleIf used to send master-slave requests
       
   672         CTestModuleIf& iTestModuleIf;
       
   673         
       
   674         // Buffer for remote request response
       
   675         TRemoteProtMsg iReceivedRemoteMsg;
       
   676 
       
   677         // Buffer for error  description
       
   678         TBuf<256> iReceiveErrorDescription;
       
   679         
       
   680         // Pointer to slave allocate/free monitor
       
   681         MSlaveAllocateFreeMonitor* iSlaveAllocateFreeMonitor;
       
   682         
       
   683         // Pointer to test case control requests monitor
       
   684         MRemoteTestCasesMonitor* iRemoteTestCasesMonitor;
       
   685         
       
   686         // Pointer to events control requests monitor
       
   687         MRemoteEventsMonitor* iRemoteEventsMonitor;
       
   688         
       
   689         // Pointer to send/receive requests monitor
       
   690         MRemoteSendReceiveMonitor* iRemoteSendReceiveMonitor;
       
   691         
       
   692         // Pointer to receive error handler
       
   693         MReceiveErrorHandler* iReceiveErrorHandler;
       
   694     };
       
   695 
       
   696 // This class contains most important informations about allocated slave device
       
   697 NONSHARABLE_CLASS( CSlave ): public CBase
       
   698     {
       
   699     public:
       
   700 		/**
       
   701 		 * Two phase constructor.
       
   702 		 */
       
   703         static CSlave* NewL();
       
   704         
       
   705         /**
       
   706          * Destructor.
       
   707          */
       
   708         ~CSlave();
       
   709         
       
   710         /**
       
   711          * Returns slave name.
       
   712          */
       
   713         const TDesC& GetName() const;
       
   714         
       
   715         /**
       
   716          * Sets slave name.
       
   717          */
       
   718         void SetNameL( const TDesC& aName );
       
   719         
       
   720         /**
       
   721          * Returns slave master's id.
       
   722          */
       
   723         TUint32 GetMasterId() const;
       
   724         
       
   725         /**
       
   726          * Sets slave master's id
       
   727          */
       
   728         void SetMasterId( TUint32 aMasterId );
       
   729         
       
   730         /**
       
   731          * Returns slave's id.
       
   732          */
       
   733         TUint16 GetSlaveId() const;
       
   734         
       
   735         /**
       
   736          * Sets slave's id.
       
   737          */
       
   738         void SetSlaveId( TUint16 aSlaveId );
       
   739 
       
   740         /**
       
   741          * Returns true if slave has running remote sub test cases.
       
   742          */
       
   743         TBool HasRunningTestCases() const;
       
   744         
       
   745         /**
       
   746          * Register slave remote sub test case.
       
   747          */
       
   748         void RegisterSubTestCaseL( CRemoteSubTestCaseRunner* aSubTestCase );
       
   749         
       
   750         /**
       
   751          * Unregister slave remote sub test case.
       
   752          */
       
   753         void UnregisterSubTestCaseL( CRemoteSubTestCaseRunner* aSubTestCase );
       
   754         
       
   755         /**
       
   756          * Returns list of slave remote sub test cases. 
       
   757          */
       
   758         RPointerArray<CRemoteSubTestCaseRunner>& GetSubTestCases();
       
   759         
       
   760         /**
       
   761          * Waits until all running slave remote sub test cases finis.
       
   762          */
       
   763         void WaitForSubTestCasesL();
       
   764         
       
   765         /**
       
   766          * Cancel WaitForSubTestCasesL call.
       
   767          */
       
   768         void CancelWaitForSubTestCases();
       
   769         
       
   770         /**
       
   771          * Register slave remote event.
       
   772          */
       
   773         void AddEventL( TEventTS* aEvent );
       
   774 
       
   775         /**
       
   776          * Unregister slave remote event.
       
   777          */
       
   778         void RemoveEventL( TEventTS* aEvent );
       
   779         
       
   780         /**
       
   781          * Returns selected slave remote event.
       
   782          */
       
   783         TEventTS* GetEvent( const TDesC& aName );
       
   784         
       
   785         RPointerArray<TEventTS>& GetEvents();
       
   786     private:
       
   787         /**
       
   788          * Constructor.
       
   789          */
       
   790         CSlave();
       
   791         
       
   792         /**
       
   793          * Second phase of two phase construction.
       
   794          */
       
   795         void ConstructL();
       
   796     private:
       
   797         /**
       
   798          * Slave's name.
       
   799          */
       
   800         HBufC* iName;
       
   801         
       
   802         /**
       
   803          * Slave's master id.
       
   804          */
       
   805         TUint32 iMasterId;
       
   806         
       
   807         /**
       
   808          * Slave's id.
       
   809          */
       
   810         TUint16 iSlaveId;
       
   811         
       
   812         /**
       
   813          * List of slave's remote sub test cases.
       
   814          */
       
   815         RPointerArray<CRemoteSubTestCaseRunner> iSubTestCases;
       
   816         
       
   817         /**
       
   818          * List of slave's remote events.
       
   819          */
       
   820         RPointerArray<TEventTS> iEvents;
       
   821         
       
   822         /**
       
   823          * nested active scheduler loop used to wait for running remote sub
       
   824          * test cases finis.
       
   825          */
       
   826         CActiveSchedulerWait* iNestedASLoop;
       
   827     };
       
   828 
       
   829 // Manages slaves and wraps most of the master-slave communication
       
   830 NONSHARABLE_CLASS( CSlavesManager ): 
       
   831     protected CActive, 
       
   832     private MSlaveAllocateFreeMonitor, 
       
   833     private MRemoteTestCasesMonitor,
       
   834     private MRemoteEventsMonitor,
       
   835     private MRemoteSendReceiveMonitor,
       
   836     private MReceiveErrorHandler
       
   837     {
       
   838     private:
       
   839 		/**
       
   840 		 * Types of internal CSlavesManager states.
       
   841 		 */
       
   842         enum TSlavesManagerOperation { 
       
   843 			ESMOIdle, 
       
   844 			ESMOSlaveAllocate, 
       
   845 			ESMOSlaveFree,
       
   846 			ESMOEventRequest, 
       
   847 			ESMOEventRelease,
       
   848 			ESMOEventSet, 
       
   849 			ESMOEventUnset,
       
   850 			ESMOSendReceiveWaitForStarted,
       
   851 			ESMOSendReceiveWaitForReady,
       
   852 			ESMOSendUnknown,
       
   853 			};
       
   854     public:
       
   855         /**
       
   856          * Two phase constructor.
       
   857          */
       
   858         static CSlavesManager* NewL( CTestRunner* aTestRunner, CTestModuleIf& aTestModuleIf );
       
   859         
       
   860         /**
       
   861          * Destructor.
       
   862          */
       
   863         ~CSlavesManager();
       
   864         
       
   865         /**
       
   866          * Allocates slave device.
       
   867          */
       
   868         void SlaveAllocateL( const TDesC& aName, const TDesC& aType );
       
   869         
       
   870         /**
       
   871          * Frees slave device.
       
   872          */
       
   873         void SlaveFreeL( const TDesC& aName );
       
   874 
       
   875         /**
       
   876          * Send remote command.
       
   877          */
       
   878         void SendReceiveL( CSlave* aSlave, const TDesC& aMessage );
       
   879         
       
   880         /**
       
   881          * Send command not specified in STF master-slave protocol
       
   882          */
       
   883         void SendUnknownL( CSlave* aSlave, const TDesC& aCommand, const TDesC& aMessage );
       
   884         
       
   885         /**
       
   886          * Returns selected slave device wrapper object.
       
   887          */
       
   888         CSlave* GetSlave( const TDesC& aName );
       
   889         
       
   890         /**
       
   891          * Returns selected slave device wrapper object.
       
   892          */
       
   893         CSlave* GetSlave( TUint16 aSlaveId );
       
   894 
       
   895         RPointerArray<CSlave>& GetSlaves();
       
   896 
       
   897         /**
       
   898          * Requests specified event from slave device
       
   899          */
       
   900         void EventRequestL( CSlave* aSlave, TEventTS* aEvent );
       
   901         
       
   902         /**
       
   903          * Releases selected remote event.
       
   904          */
       
   905         void EventReleaseL( CSlave* aSlave, const TDesC& aEventName );        
       
   906 
       
   907         /**
       
   908          * Sets remote event.
       
   909          */
       
   910         void EventSetL( CSlave* aSlave, const TDesC& aEventName, TEventIf::TEventType aEventType );
       
   911         
       
   912         /**
       
   913          * Unsets remote event
       
   914          */
       
   915         void EventUnsetL( CSlave* aSlave, const TDesC& aEventName );        
       
   916         
       
   917         /**
       
   918          * Returns CRemoteCallsProxy used in master-slave communication.
       
   919          */
       
   920         CRemoteCallsProxy* GetRemoteCallsProxy();
       
   921         
       
   922     private:
       
   923         /**
       
   924          * Constructor.
       
   925          */
       
   926         CSlavesManager( CTestRunner* aTestRunner, CTestModuleIf& aTestModuleIf );
       
   927         
       
   928         /**
       
   929          * Second phase of two phase construction.
       
   930          */
       
   931         void ConstructL();
       
   932 
       
   933         /**
       
   934          * Handles operation timeout event.
       
   935          */
       
   936         void RunL();
       
   937         
       
   938         /**
       
   939          * Cancels operation timeout monitor.
       
   940          */
       
   941         void DoCancel();
       
   942         
       
   943 		/**
       
   944 		 * Notify slave is allocated
       
   945 		 */
       
   946         void NotifySlaveAllocatedL( TUint16 aSlaveId );
       
   947         
       
   948         /**
       
   949          * Notify slave is freed
       
   950          */
       
   951         void NotifySlaveFreedL( TUint16 aSlaveId );
       
   952 
       
   953 		/**
       
   954 		 * Notify test case has been started.
       
   955 		 */
       
   956         void NotifyTestCaseStartedL( TUint16 aSlaveId, TUint16 aSlaveTestId );
       
   957         
       
   958         /**
       
   959          * Notify test case can't be started.
       
   960          */        
       
   961         void NotifyTestCaseRunErrorL( TUint16 aSlaveId, 
       
   962         		const TFullTestResult& aTestCaseResult );
       
   963         
       
   964         /**
       
   965          * Notify execution test case has finished
       
   966          */
       
   967         void NotifyTestCaseFinishedL( TUint16 aSlaveId, TUint16 aSlaveTestId, 
       
   968         		const TFullTestResult& aTestCaseResult );
       
   969         
       
   970         /**
       
   971          * Notify test case has been paused.
       
   972          */
       
   973         void NotifyTestCasePausedL( TUint16 aSlaveId, TUint16 aSlaveTestId );
       
   974         
       
   975         /**
       
   976          * Notify test case has been resumed.
       
   977          */
       
   978         void NotifyTestCaseResumedL( TUint16 aSlaveId, TUint16 aSlaveTestId );
       
   979         
       
   980         /**
       
   981          * Notify test case has been cancelled.
       
   982          */
       
   983         void NotifyTestCaseCancelledL( TUint16 aSlaveId, TUint16 aSlaveTestId );
       
   984         
       
   985 		/**
       
   986 		 * Notify remote event has been requested
       
   987 		 */
       
   988         void NotifyEventRequestedL( TUint16 aSlaveId, 
       
   989                 const TDesC& aEventName, 
       
   990                 CStifTFwIfProt::TEventStatus aEventStatus,
       
   991                 TEventIf::TEventType aEventType,
       
   992                 TInt aResult );
       
   993         
       
   994         /**
       
   995          * Notify remote event state has changed
       
   996          */
       
   997         void NotifyEventStateChangedL( TUint16 aSlaveId, 
       
   998                 const TDesC& aEventName, 
       
   999                 CStifTFwIfProt::TEventStatus aEventStatus,
       
  1000                 TEventIf::TEventType aEventType,
       
  1001                 TInt aResult );
       
  1002         
       
  1003         /**
       
  1004          * Notify remote event has been released
       
  1005          */
       
  1006         void NotifyEventReleasedL( TUint16 aSlaveId, 
       
  1007                 const TDesC& aEventName, TInt aResult  );
       
  1008 
       
  1009         /**
       
  1010          * Notify remote event has been sucessfully set
       
  1011          */
       
  1012         void NotifyEventSetCompletedL( TUint16 aSlaveId, 
       
  1013                 const TDesC& aEventName, TInt aResult );
       
  1014         
       
  1015         /**
       
  1016          * Notify remote event has been sucessfully unset
       
  1017          */
       
  1018         void NotifyEventUnsetCompletedL( TUint16 aSlaveId, 
       
  1019                 const TDesC& aEventName, TInt aResult );        
       
  1020         
       
  1021 		/**
       
  1022 		 * Notify sendreceive request has been started
       
  1023 		 */
       
  1024         void NotifySendReceiveStartedL( TUint16 aSlaveId );
       
  1025         
       
  1026         /**
       
  1027          * Notify sendreceive request has finished
       
  1028          */
       
  1029         void NotifySendReceiveResultL( 
       
  1030                 TUint16 aSlaveId, 
       
  1031                 CStifTFwIfProt::TRunStatus aRunStatus,
       
  1032                 TInt aRunResult );
       
  1033         
       
  1034         /**
       
  1035          * Notify send unknown request has finished
       
  1036          */
       
  1037         void NotifySendUnknownL( TUint16 aSlaveId, TInt aResult );
       
  1038         
       
  1039 		/**
       
  1040 		 * Handle error which occured during remote message receive
       
  1041 		 */
       
  1042         void HandleRemoteReceiveError( TInt aError, const TDesC& aErrorDescription );
       
  1043         
       
  1044     private:
       
  1045         // Indicates currently performed operation
       
  1046         TSlavesManagerOperation iOperation;
       
  1047         
       
  1048         // Contains last operation result
       
  1049         TInt iLastOperationResult;
       
  1050         
       
  1051         // Pointer to CTestRunner object
       
  1052         CTestRunner* iTestRunner;
       
  1053         
       
  1054         // TestModuleIf used by CRemoteCallsProxy in master-slave communication
       
  1055         CTestModuleIf& iTestModuleIf;
       
  1056         
       
  1057         // CRemoteCallsProxy used in master-slave communication
       
  1058         CRemoteCallsProxy* iRemoteCallsProxy;
       
  1059         
       
  1060         // Array of allocated slave devices
       
  1061         RPointerArray<CSlave> iSlaves;
       
  1062         
       
  1063         // Temporary field used during slave device allocation
       
  1064         CSlave* iSlaveForAllocate;
       
  1065         
       
  1066         // Temporary field used during event request
       
  1067         TEventTS* iEventForRequest;
       
  1068         
       
  1069         // Operation timeout
       
  1070         TTimeIntervalMicroSeconds32 iOperationTimeout;
       
  1071 
       
  1072         // Operation timeout timer
       
  1073         RTimer iOperationTimeoutTimer;
       
  1074         
       
  1075         // Nested active scheduler loop used to block CSlavesManager methods 
       
  1076         // execution until respons for selected request is received
       
  1077         CActiveSchedulerWait* iNestedASLoop;
       
  1078     };
       
  1079 
       
  1080 #endif /* TESTSCRIPTERUTILS_H_ */