devicediagnostics/devdiagapp/inc/devdiagengine.h
changeset 18 7d11f9a6646f
parent 4 75a71fdb4c92
child 21 c707676bf59f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
     1 /*
       
     2 * Copyright (c) 2007 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:  Handles most of the model related logic..
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef DEVDIAGDENGINE_H
       
    20 #define DEVDIAGDENGINE_H
       
    21 
       
    22 // System Include Files
       
    23 #include <e32base.h>                // CActive
       
    24 #include <etel3rdparty.h>           // CTelephony
       
    25 #include <DiagResultsDatabase.h>    // RDiagResultsDatabase,
       
    26                                     // RDiagResultsDatabaseRecord
       
    27 #include <DiagEngineObserver.h>     // MDiagEngineObserver
       
    28 #include <DiagPluginPoolObserver.h> // MDiagPluginPoolObserver
       
    29 #include <DiagCommonDialog.h>       // TDiagCommonDialog
       
    30 
       
    31 // Forward Declarations
       
    32 class MDevDiagEngineObserver;
       
    33 class MDiagPlugin;
       
    34 class MDiagSuitePlugin;
       
    35 class CDevDiagExecResults;
       
    36 class CDiagResultsDatabaseItem;
       
    37 class CDiagEngine;
       
    38 class RFs;
       
    39 class CDiagPluginPool;
       
    40 class CAknViewAppUi;
       
    41 class CAknDialog;
       
    42 class CIdle;
       
    43 
       
    44 /**
       
    45  *  Device Diagnostics Application Engine
       
    46  *  This class defines the engine used by the Device Diagnostics application.  The
       
    47  *  engine class handles the interfacing between UI components and diagnostics
       
    48  *  components.
       
    49  *
       
    50  *  @lib euser.lib
       
    51  *  @lib diagframework.lib
       
    52  *  @lib etel3rdparty.lib
       
    53  *  @lib diagresultsdatabase.lib
       
    54  *  @lib avkon.lib
       
    55  *  @lib eikcore.lib
       
    56  *  @lib eiksrv.lib
       
    57  *  @lib efsrv.lib
       
    58  *  @lib drmserviceapi.lib
       
    59  */
       
    60 class CDevDiagEngine : public CActive,
       
    61                        public MDiagEngineObserver,
       
    62                        public MDiagPluginPoolObserver
       
    63     {
       
    64 
       
    65 public: // Data Types
       
    66 
       
    67     /**  This enum indicates how the engine should stop tests. */
       
    68     enum TDevDiagAppEngineStopMode
       
    69         {
       
    70         EStopModeSkip,
       
    71         EStopModeCancel,
       
    72         EStopModeSuspend,
       
    73         EStopModeWatchdog
       
    74         };
       
    75 
       
    76     enum TDevDiagAppEngineResumeMode
       
    77         {
       
    78         EResumeModeResume,
       
    79         EResumeModeWatchdog
       
    80         };
       
    81 
       
    82 
       
    83 public: // New Functions
       
    84 
       
    85     /**
       
    86      * Two-phased constructor.
       
    87      */
       
    88     static CDevDiagEngine* NewL();
       
    89 
       
    90     /**
       
    91      * Two-phased constructor.
       
    92      * Leaves the new engine instance on the cleanup stack.
       
    93      */
       
    94     static CDevDiagEngine* NewLC();
       
    95 
       
    96     /**
       
    97     * Destructor.
       
    98     */
       
    99     virtual ~CDevDiagEngine();
       
   100 
       
   101     /**
       
   102      * Sets the engine observer, for receiving engine events.
       
   103      *
       
   104      * @param aObserver A pointer to a class implementing the observer
       
   105      *                  interface.  Ownership is not transferred.
       
   106      */
       
   107     void SetObserver( MDevDiagEngineObserver* aObserver );
       
   108 
       
   109     /**
       
   110      * Run a test or suite of tests.
       
   111      *
       
   112      * @param aUid The UID of the test or suite to execute.
       
   113      * @param aAppUi The application UI which is executing tests.
       
   114      */
       
   115     void ExecuteTestL( TUid aUid, CAknViewAppUi& aAppUi );
       
   116 
       
   117     /**
       
   118      * Gets the results from test execution.  Results may be from a log or
       
   119      * from live test execution.  The caller should check if results are
       
   120      * available before calling this function.
       
   121      *
       
   122      * @return A reference to the execution results.
       
   123      */
       
   124     const CDevDiagExecResults& ExecutionResults() const;
       
   125 
       
   126     /**
       
   127      * Instructs the engine to populate the execution results information with
       
   128      * the last set of logged data.  This may be followed by a call to
       
   129      * ExecutionResults to retrieve the data.
       
   130      */
       
   131     void LoadLastLoggedResultsL();
       
   132 
       
   133     /**
       
   134     * Get results of the suite. Observer will be notified when
       
   135     * results are ready (EDevDiagEngineCommandGetLastResult).
       
   136     * 
       
   137     * @param aParentUid UID of the plug-in whose results are needed.
       
   138     */
       
   139     void GetLastResultsL( TUid aParentUid );
       
   140 
       
   141     /**
       
   142      * Suspends, skips, or halts test execution.
       
   143      *
       
   144      * @param aReason The reason for stopping execution.
       
   145      */
       
   146     void ExecutionStopL( TDevDiagAppEngineStopMode aReason );
       
   147 
       
   148     /**
       
   149      * Resumes the diagnostics engine.  In the case of resuming suspended test
       
   150      * execution, this must have been preceded by a call to ExecutionStopL
       
   151      * with EStopModeSuspend specified.
       
   152      *
       
   153      * @param aReason The reason for resuming execution.
       
   154      */
       
   155     void ExecutionResumeL( TDevDiagAppEngineResumeMode aReason );
       
   156 
       
   157     /**
       
   158      * Gets the plugin pool, which is owned by the engine.
       
   159      *
       
   160      * @return A reference to the plugin pool.
       
   161      */
       
   162     const CDiagPluginPool& PluginPool() const;
       
   163 
       
   164     /**
       
   165      * Checks if the engine is currently running plugins.  This includes
       
   166      * when the engine is suspended for any reason.
       
   167      *
       
   168      * @return ETrue if plugins are running, EFalse otherwise.
       
   169      */
       
   170     TBool IsRunningPlugins() const;
       
   171 
       
   172     /**
       
   173      * Checks if the engine is currently stopping execution.
       
   174      *
       
   175      * @return ETrue if execution is being cancelled, EFalse otherwise.
       
   176      */
       
   177     TBool IsStoppingExecution() const;
       
   178 
       
   179     /**
       
   180      * Checks if the engine is initialzed (it has finished loading plugins).
       
   181      * This must be true before the runtime requirements can be checked or
       
   182      * the reference to the plugin pool can be returned.
       
   183      *
       
   184      * @return ETrue if plugins are loaded, EFalse otherwise.
       
   185      */
       
   186     TBool ArePluginsLoaded() const;
       
   187 
       
   188     /**
       
   189      * Checks if the engine has execution results available.  This must be
       
   190      * true before a reference to the results can be retrieved.
       
   191      *
       
   192      * @return ETrue if results are available, EFalse otherwise.
       
   193      */
       
   194     TBool HasExecutionResults() const;
       
   195     
       
   196     /**
       
   197      * Searches Results Database for a crashed test plug-in.
       
   198      * 
       
   199      * @param aPluginUid Plug-in Uid that crashed.
       
   200      * @return ETrue if crashed plug-in was found, EFalse otherwise.
       
   201      **/
       
   202     TBool CrashedPluginL( TUid& aPluginUid );
       
   203 
       
   204     /**
       
   205      * Marks the crashed test record as complete in the database.  This
       
   206      * means that the test record is not found again when calling CrashedTestRecordL.
       
   207      *
       
   208      * @return KErrNone if the record was successfully completed, otherwise, a
       
   209      *         system error code.
       
   210      */
       
   211     //TInt CompleteCrashedTestRecord();
       
   212     ///@@@KSR: changes for Codescanner error val = High
       
   213     TInt CompleteCrashedTestRecordL();
       
   214     ///@@@KSR: changes for Codescanner error val = High
       
   215     // ADO & Platformization Changes
       
   216     TBool GetPluginDependencyL();
       
   217     // GetState
       
   218     TInt GetState();
       
   219 
       
   220 private: // Data Types
       
   221 
       
   222     /**  This enum indicates the engine's internal state.
       
   223      *   Any changes to this enum must be reflected with changes to the
       
   224      *   SetState function.
       
   225      */
       
   226     enum TDevDiagAppEngineState
       
   227         {
       
   228         EStateInitial = 0,
       
   229         EStateLoadingPlugins,
       
   230         EStateReady,
       
   231         EStateStartingExecution,
       
   232         EStateRunningTests,
       
   233         EStateStoppingExecution,
       
   234         EStateExecutionSuspended,
       
   235         EStateMax
       
   236         };
       
   237 
       
   238 
       
   239 private: // New Functions
       
   240 
       
   241     /**
       
   242      * The default constructor.
       
   243      */
       
   244     CDevDiagEngine();
       
   245 
       
   246     /**
       
   247      * Two-phased constructor.
       
   248      */
       
   249     void ConstructL();
       
   250 
       
   251     /**
       
   252      * Handles state transitions in the application engine by validating the
       
   253      * requested transition.
       
   254      *
       
   255      * @param aNextState The new state to transition to.
       
   256      */
       
   257     void SetState( TDevDiagAppEngineState aNextState );
       
   258 
       
   259     /**
       
   260      * The callback function to continue handling cancelling execution.
       
   261      *
       
   262      * @param aPtr A pointer to "this" object.
       
   263      * @return Always KErrNone.
       
   264      */
       
   265     static TInt HandleExecutionCancelledL( TAny* aPtr );
       
   266 
       
   267 
       
   268 private: // From base class CActive
       
   269 
       
   270     /**
       
   271      * From CActive.
       
   272      * This function is called when an active request completes.  For the
       
   273      * application engine, this only happens when checking runtime
       
   274      * requirements.
       
   275      */
       
   276     virtual void RunL();
       
   277 
       
   278     /**
       
   279      * From CActive.
       
   280      * This function is called to cancel any outstanding asynchronous
       
   281      * requests.
       
   282      */
       
   283     virtual void DoCancel();
       
   284 
       
   285 
       
   286 private: // From base class MDiagEngineObserver
       
   287 
       
   288     /**
       
   289      * From MDiagEngineObserver.
       
   290      * This callback is used when test execution starts.
       
   291      *
       
   292      */
       
   293     virtual void TestExecutionBeginL();
       
   294     
       
   295     /**
       
   296     * Notify client of execution completion of one plug-in.
       
   297     *   This can be either test plug-in or suite plug-in.
       
   298     *
       
   299     * @param aError  - KErrNone - Success.
       
   300     *   KErrNoMemory - Out of memory.
       
   301     *   KErrCancel   - Cancelled due to ExecutionStopL()
       
   302     *
       
   303     * @param aResult - Result of the test. Ownership is transferred here. 
       
   304     *  Client must deallocate aResult to avoid memory leak. aResult is Null 
       
   305     *  if the plug-in being executed is a suite pre/post method.
       
   306     */
       
   307     virtual void TestExecutionPluginExecutedL( TInt aError,
       
   308                                                CDiagResultsDatabaseItem* aResult );
       
   309 
       
   310     /**
       
   311      * From MDiagEngineObserver.
       
   312      * This callback is used to inform the application of the execution
       
   313      * progress for the currently executing test.
       
   314      *
       
   315      * @param aCurrentItemStep The current step for this test.
       
   316      * @param aCurrentItemTotalSteps The total number of steps for this test.
       
   317      */
       
   318     virtual void TestExecutionProgressL( TUint aCurrentItemStep,
       
   319                                          TUint aCurrentItemTotalSteps);
       
   320 
       
   321 
       
   322     /**
       
   323     * From MDiagEngineObserver.
       
   324     * Notify client of engine stopping.
       
   325     *
       
   326     * This indicates that engine execution has stopped. There will not be any
       
   327     * further messages from engine. This could be called because all
       
   328     * tests are completed, or an unrecoverable error occured during execution.
       
   329     *
       
   330     * Note that if cancel is called during plan creation or if plan creation
       
   331     * fails, TestExecutionStoppedL() may be called withing first calling
       
   332     * TestExecutionBeginL(). 
       
   333     *
       
   334     * @param aError - Reason for engine stopping. 
       
   335     *   a) KErrNone - All tests are successfully completed.
       
   336     *   b) KErrCancel - ExecutionStopL is called with ECancelAll. 
       
   337     *       Test session cannot be resumed later.
       
   338     *   c) KErrArgument - Parameters passed to engine are invalid.
       
   339     *   d) Others - Other critical that could not be recovered occured during
       
   340     *       test execution.  Test may be resumed later in this case.
       
   341     */
       
   342     virtual void TestExecutionCompletedL( TInt aError );
       
   343 
       
   344     /**
       
   345      * From MDiagEngineObserver.
       
   346      * Notifes that execution has been suspended.
       
   347      *
       
   348      * @param aSuspendReason Why execution is suspended.
       
   349      */
       
   350     virtual void TestExecutionSuspendedL( TSuspendReason aSuspendReason );
       
   351 
       
   352     /**
       
   353      * From MDiagEngineObserver.
       
   354      * Notifes that execution has been resumed.
       
   355      *
       
   356      * @param aResumeReason Why execution is resumed.
       
   357      */
       
   358     virtual void TestExecutionResumedL( TResumeReason aResumeReason );
       
   359 
       
   360     /**
       
   361      * From MDiagEngineObserver.
       
   362      * Create a common dialog.
       
   363      * @param aDialogType Type of dialog to create.
       
   364      * @param aData Initialization parameter. Ownership is transferred.
       
   365      * @return A pointer to newly created dialog. Ownership is passed to
       
   366      *         caller.
       
   367     */
       
   368     virtual CAknDialog* CreateCommonDialogLC( TDiagCommonDialog aDialogType,
       
   369                                               TAny* aInitData );
       
   370                                               
       
   371     /**
       
   372     * From MDiagEngineObserver.
       
   373     *
       
   374     * Execute a command from plug-in. Parameters are identical to 
       
   375     * MDiagEngineCommon::ExecuteAppCommandL(). 
       
   376     * @see MDiagEngineCommon::ExecuteAppCommandL()
       
   377     * @see TDiagAppCommand
       
   378     */
       
   379     virtual void ExecuteAppCommandL( TDiagAppCommand aCommand, 
       
   380                                      TAny* aParam1,
       
   381                                      TAny* aParam2 );                                              
       
   382 
       
   383 
       
   384 private: // From base class MDiagPluginPoolObserver
       
   385 
       
   386        /**
       
   387      * From MDiagPluginPoolObserver.
       
   388      * This callback is used to inform the application about loading progress
       
   389      * of plugins.
       
   390      *
       
   391      * @param aCurrentPlugin The current plugin index in the loading progress.
       
   392      * @param aPluginCount The total number of plugins to load.
       
   393      @ @param aLoadedPluginUid The UID of the plugin that was just loaded.
       
   394      */
       
   395     virtual void LoadProgressL ( TUint aCurrentPlugin,
       
   396                                  TUint aPluginCount,
       
   397                                  const TUid& aLoadedPluginUid );
       
   398 
       
   399 
       
   400     /**
       
   401     * Notify client of plug-in loading completion
       
   402     *
       
   403     * @param aError     KErrNone - Success
       
   404     *                   KErrCorrupt  - One ore more plugin could not
       
   405     *                   be loaded. 
       
   406     *                   KErrNoMemory - Not enough memory.
       
   407     */
       
   408     virtual void LoadCompletedL( TInt aError );
       
   409 
       
   410 
       
   411 private: // Data
       
   412 
       
   413     /**
       
   414      * The application engine's current state.
       
   415      */
       
   416     TDevDiagAppEngineState iState;
       
   417 
       
   418     /**
       
   419      * The test execution results.
       
   420      * Own.
       
   421      */
       
   422     CDevDiagExecResults* iResults;
       
   423 
       
   424     /**
       
   425      * The current observer of the application engine.
       
   426      * Not own.
       
   427      */
       
   428     MDevDiagEngineObserver* iObserver;
       
   429 
       
   430     /**
       
   431      * The diagnostics engine.
       
   432      * Own.
       
   433      */
       
   434     CDiagEngine* iDiagEngine;
       
   435 
       
   436     /**
       
   437      * The session with the results database server.
       
   438      */
       
   439     RDiagResultsDatabase iResultsDatabase;
       
   440 
       
   441     
       
   442     /**
       
   443      * The plugin pool, which loads and owns plugins.
       
   444      * Own.
       
   445      */
       
   446     CDiagPluginPool* iPluginPool;
       
   447 
       
   448 
       
   449     /**
       
   450      * Holds the number of times suspend has been called.  In nested suspend /
       
   451      * resume scenarios, this is used to ensure we don't resume until we have
       
   452      * matched the number of suspends.
       
   453      */
       
   454     TInt iSuspendCounter;
       
   455     
       
   456      /**
       
   457      * A utility active object that is used to continue handling cancelling
       
   458      * execution, because we cannot use synchronous cancelling due to the
       
   459      * possibility of test plugins displaying the common "Cancel Execution"
       
   460      * dialog.
       
   461      * Own.
       
   462      */
       
   463     CIdle* iIdle;
       
   464     
       
   465     /**
       
   466     * Get Last results UIDs. Own.
       
   467     **/
       
   468     CArrayFixFlat<TUid>* iUids;
       
   469     
       
   470     /**
       
   471     * Buffered last results. Own.
       
   472     **/
       
   473     RPointerArray<CDiagResultsDatabaseItem> iLastResults;
       
   474 
       
   475     };
       
   476 
       
   477 #endif // DEVDIAGDENGINE_H