devicediagnostics/devdiagapp/src/devdiagexecutionresults.cpp
changeset 0 3ce708148e4d
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     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:  This class encapsulates test results from live execution runs
       
    15 *                as well as logged results and presents a common interface for
       
    16 *                both.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // System Include Files
       
    22 #include <centralrepository.h>                  // CRepository
       
    23 #include <drmserviceapi.h>                      // CDrmServiceApi
       
    24 #include <DiagEngineCommon.h>                   // MDiagEngineCommon
       
    25 #include <DiagPluginExecPlan.h>                 // CDiagPluginExecPlan
       
    26 #include <DiagExecPlanEntry.h>                  // MDiagExecPlanEntry
       
    27 #include <DiagResultsDatabaseItem.h>            // CDiagResultsDatabaseItem
       
    28 #include <DiagPlugin.h>                         // MDiagPlugin
       
    29 #include <DiagTestPlugin.h>                     // MDiagTestPlugin
       
    30 #include <DiagPluginPool.h>                     // CDiagPluginPool
       
    31 #include <DiagResultsDatabaseTestRecordInfo.h>  // TDiagResultsDatabaseTestRecordInfo
       
    32 #include <DiagResultsDbRecordEngineParam.h>     // CDiagResultsDbRecordEngineParam
       
    33 #include <DiagResultsDatabase.h>                // RDiagResultsDatabase,
       
    34                                                 // RDiagResultsDatabaseRecord
       
    35 #include <DiagFrameworkDebug.h>                 // Debugging Macros
       
    36 
       
    37 // User Include Files
       
    38 #include "devdiagexecutionresults.h"                 // CDevDiagExecResults
       
    39 #include "devdiagapp.hrh"                    // UID definition
       
    40 #include "devdiag.pan"                    // Panic
       
    41 #include "devdiagprivatecrkeys.h"           // CR Key ID Definitions
       
    42 
       
    43 // Local Constants
       
    44 ///@@@KSR: changes for BAD Warnings - #177-D: variable "KRecordsArrayGranularity" was declared but never referenced
       
    45 //const TInt KRecordsArrayGranularity = ( 5 );
       
    46 
       
    47 // Local Data Types
       
    48 typedef CArrayFixFlat< TDiagResultsDatabaseTestRecordInfo > CDatabaseRecordInfoArray;
       
    49 
       
    50 
       
    51 // ============================ MEMBER FUNCTIONS =============================
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // From nested class CDevDiagExecResults::CResult.
       
    55 // Static two-phase constructor.
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CDevDiagExecResults::CResult* CDevDiagExecResults::CResult::NewL(
       
    59     const MDiagPlugin& aPlugin )
       
    60     {
       
    61     CResult* self = CResult::NewLC( aPlugin );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // From nested class CDevDiagExecResults::CResult.
       
    68 // Static two-phase constructor.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CDevDiagExecResults::CResult* CDevDiagExecResults::CResult::NewLC(
       
    72     const MDiagPlugin& aPlugin )
       
    73     {
       
    74     CResult* self = new ( ELeave ) CResult( aPlugin );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     return self;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // From nested class CDevDiagExecResults::CResult.
       
    82 // Destructor.
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CDevDiagExecResults::CResult::~CResult()
       
    86     {
       
    87     delete iResult;
       
    88     iResult = NULL;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // From nested class CDevDiagExecResults::CResult.
       
    93 // Return the test result.  This may be NULL if the test has not been run.
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 const CDiagResultsDatabaseItem* CDevDiagExecResults::CResult::Result() const
       
    97     {
       
    98     return iResult;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // From nested class CDevDiagExecResults::CResult.
       
   103 // Return a reference to the plugin for this result.
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 const MDiagPlugin& CDevDiagExecResults::CResult::Plugin() const
       
   107     {
       
   108     return iPlugin;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // From nested class CDevDiagExecResults::CResult.
       
   113 // Return the execution error code.
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 TInt CDevDiagExecResults::CResult::ExecStatus() const
       
   117     {
       
   118     return iExecStatus;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // From nested class CDevDiagExecResults::CResult.
       
   123 // Return the current execution step for this result.
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TUint CDevDiagExecResults::CResult::CurrentStep() const
       
   127     {
       
   128     return iCurrentStep;
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // From nested class CDevDiagExecResults::CResult.
       
   133 // Return the total execution steps for this result.
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 TUint CDevDiagExecResults::CResult::TotalSteps() const
       
   137     {
       
   138     return iTotalSteps;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // From nested class CDevDiagExecResults::CResult.
       
   143 // This function takes ownership of a result object.
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CDevDiagExecResults::CResult::SetResult(
       
   147     CDiagResultsDatabaseItem* aResult,
       
   148     TInt aError )
       
   149     {
       
   150     // Sanity check.
       
   151     if ( iResult )
       
   152         {
       
   153         delete iResult;
       
   154         }
       
   155 
       
   156     // Set the result and error code Ownership of the result is transferred.
       
   157     iResult = aResult;
       
   158     iExecStatus = aError;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // From nested class CDevDiagExecResults::CResult.
       
   163 // Set the progress information for this result.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CDevDiagExecResults::CResult::SetProgress( TUint aCurrentStep,
       
   167                                                 TUint aTotalSteps )
       
   168     {
       
   169     iCurrentStep = aCurrentStep;
       
   170     iTotalSteps = aTotalSteps;
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // From nested class CDevDiagExecResults::CResult.
       
   175 // The default constructor.
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 CDevDiagExecResults::CResult::CResult( const MDiagPlugin& aPlugin )
       
   179 :   iPlugin( aPlugin )
       
   180     {
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // From nested class CDevDiagExecResults::CResult.
       
   185 // The second phase constructor.
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CDevDiagExecResults::CResult::ConstructL()
       
   189     {
       
   190     }
       
   191 
       
   192 
       
   193 // ============================ MEMBER FUNCTIONS =============================
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // Static two-phase constructor.
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CDevDiagExecResults* CDevDiagExecResults::NewL(
       
   200     TUid aRecordId,
       
   201     CDiagPluginPool& aPluginPool,
       
   202     RDiagResultsDatabase& aDbSession )
       
   203     {
       
   204     LOGSTRING2( "CDevDiagExecResults::NewL( %d )", aRecordId.iUid )
       
   205 
       
   206     CDevDiagExecResults* self = new ( ELeave ) CDevDiagExecResults(
       
   207         aRecordId,
       
   208         aPluginPool,
       
   209         aDbSession );
       
   210     CleanupStack::PushL( self );
       
   211     self->ConstructL();
       
   212     CleanupStack::Pop( self );
       
   213     return self;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // Static two-phase constructor.
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 CDevDiagExecResults* CDevDiagExecResults::NewL(
       
   221     TUid aRecordId,
       
   222     CDiagPluginPool& aPluginPool,
       
   223     RDiagResultsDatabase& aDbSession,
       
   224     TUid aExecutedUid,
       
   225     MDiagEngineCommon* aDiagEngine )
       
   226     {
       
   227     LOGSTRING3( "CDevDiagExecResults::NewL( %d, 0x%x )",
       
   228                 aRecordId.iUid,
       
   229                 aDiagEngine )
       
   230 
       
   231     CDevDiagExecResults* self = new ( ELeave ) CDevDiagExecResults(
       
   232         aRecordId,
       
   233         aPluginPool,
       
   234         aDbSession,
       
   235         aExecutedUid,
       
   236         aDiagEngine );
       
   237     CleanupStack::PushL( self );
       
   238     self->ConstructL();
       
   239     CleanupStack::Pop( self );
       
   240     return self;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // Destructor.
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 CDevDiagExecResults::~CDevDiagExecResults()
       
   248     {
       
   249     LOGSTRING( "CDevDiagExecResults::~CDevDiagExecResults()" )
       
   250     iResults.ResetAndDestroy();
       
   251     }
       
   252 
       
   253 // ---------------------------------------------------------------------------
       
   254 // This function is called during live execution to transfer ownership of a
       
   255 // test result.
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CDevDiagExecResults::AddEntryL( CDiagResultsDatabaseItem* aResult,
       
   259                                      TInt aStatus )
       
   260     {
       
   261     LOGSTRING3( "CDevDiagExecResults::AddEntryL( 0x%x, %d )",
       
   262                 aResult,
       
   263                 aStatus )
       
   264 
       
   265     // This is only valid for live executions.
       
   266     if ( iType != ETypeExecution )
       
   267         {
       
   268         delete aResult;
       
   269         User::Leave( KErrCompletion );
       
   270         }
       
   271 
       
   272     // Assign the result object to the corresponding item in the local array.
       
   273     iResults[ CurrentIndexL() ]->SetResult( aResult, aStatus );
       
   274 
       
   275     // Update the completed step counter.
       
   276     if ( iResults[ CurrentIndexL() ]->Plugin().Type() ==
       
   277         MDiagPlugin::ETypeTestPlugin )
       
   278         {
       
   279         iCompletedSteps += static_cast< const MDiagTestPlugin& >(
       
   280             iResults[ CurrentIndexL() ]->Plugin() ).TotalSteps();
       
   281 
       
   282         if ( aResult && ( aResult->TestResult() ==
       
   283                             CDiagResultsDatabaseItem::EFailed ||
       
   284                           aResult->TestResult() ==
       
   285                             CDiagResultsDatabaseItem::EDependencyFailed ) )
       
   286             {
       
   287             iFailedCount++;
       
   288             }
       
   289         
       
   290         if ( aResult && ( aResult->TestResult() ==
       
   291                             CDiagResultsDatabaseItem::ESuccess) )
       
   292             {
       
   293             iPassedCount++;
       
   294             }
       
   295         }
       
   296     iCurrentPluginStep = 0;
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // This function is called during live execution to transfer ownership of a
       
   301 // test result.
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CDevDiagExecResults::SetProgressL( TUint aCurrentStep, TUint aTotalSteps )
       
   305     {
       
   306     LOGSTRING3( "CDevDiagExecResults::SetProgressL( %d, %d )",
       
   307             aCurrentStep,
       
   308             aTotalSteps )
       
   309 
       
   310     // This is only valid for live executions.
       
   311     if ( iType != ETypeExecution )
       
   312         {
       
   313         return;
       
   314         }
       
   315 
       
   316     // Assign the progress to the corresponding item in the local array.
       
   317     iResults[ CurrentIndexL() ]->SetProgress( aCurrentStep, aTotalSteps );
       
   318 
       
   319     // Update the current step counter.
       
   320     if ( iResults[ CurrentIndexL() ]->Plugin().Type() ==
       
   321         MDiagPlugin::ETypeTestPlugin )
       
   322         {
       
   323         iCurrentPluginStep = aCurrentStep;
       
   324         }
       
   325     else
       
   326         {
       
   327         iCurrentPluginStep = 0;
       
   328         }
       
   329     }
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // This function returns the corresponding results item from the local array.
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 CDevDiagExecResults::CResult& CDevDiagExecResults::operator[] ( TInt aIndex )
       
   336     {
       
   337     return *iResults[ aIndex ];
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // This function returns the corresponding results item from the local array.
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 const CDevDiagExecResults::CResult& CDevDiagExecResults::operator[] (
       
   345     TInt aIndex ) const
       
   346     {
       
   347     return *iResults[ aIndex ];
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // This function returns the current item from the local array.  For results
       
   352 // which are from execution, this is the current execution item.  For results
       
   353 // which are from the database, this is always the last item.
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 CDevDiagExecResults::CResult& CDevDiagExecResults::CurrentItemL()
       
   357     {
       
   358     return *iResults[ CurrentIndexL() ];
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // This function returns the current item from the local array.  For results
       
   363 // which are from execution, this is the current execution item.  For results
       
   364 // which are from the database, this is always the last item.
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 const CDevDiagExecResults::CResult& CDevDiagExecResults::CurrentItemL() const
       
   368     {
       
   369     return *iResults[ CurrentIndexL() ];
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // This function returns the number of items in the local array.
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 TInt CDevDiagExecResults::Count() const
       
   377     {
       
   378     return iResults.Count();
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // This function returns the index of the currently-executing item.
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 TUint CDevDiagExecResults::CurrentIndexL() const
       
   386     {
       
   387     // For live execution, the index from the execution plan is returned.
       
   388     if ( iType == ETypeExecution )
       
   389         {
       
   390         TUint index = 0;
       
   391         index = iDiagEngine->ExecutionPlanL().CurrentIndex();
       
   392         return index;
       
   393         }
       
   394 
       
   395     // For logged test results, the last index is returned.
       
   396     return iResults.Count() - 1;
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // This utility function allows the result view to check if testing is
       
   401 // complete but the diagnostics engine has not yet reported testing as
       
   402 // finished.
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 TBool CDevDiagExecResults::LastTestFinishedL() const
       
   406     {
       
   407     if ( !iDiagEngine ||
       
   408          ( iDiagEngine->ExecutionPlanL().IsLastTest() &&
       
   409            ( iResults[ iLastTestIndex ] )->Result() ) )
       
   410         {
       
   411         return ETrue;
       
   412         }
       
   413 
       
   414     return EFalse;
       
   415     }
       
   416 
       
   417 // ---------------------------------------------------------------------------
       
   418 // This utility function checks to see if a test is being executed / was
       
   419 // executed as a dependency.
       
   420 // ---------------------------------------------------------------------------
       
   421 //
       
   422 TBool CDevDiagExecResults::IsDependencyL( TInt aIndex ) const
       
   423     {
       
   424     //__ASSERT_ALWAYS( ( aIndex < Count() ), Panic( EDevDiagApplicationGeneral ) );
       
   425 
       
   426     // For live execution, get the information from the execution plan.
       
   427     if ( iType == ETypeExecution )
       
   428         {
       
   429         TBool dependent = EFalse;
       
   430         dependent = iDiagEngine->ExecutionPlanL()[ aIndex ].AsDependency();
       
   431         return dependent;
       
   432         }
       
   433 
       
   434     // For logged test results, get the information from the test result.  The
       
   435     // NULL check is needed in case the plugin failed during running and did
       
   436     // not report a result.
       
   437     if ( iResults[ aIndex ]->Result() )
       
   438         {
       
   439         return iResults[ aIndex ]->Result()->WasDependency();
       
   440         }
       
   441     else
       
   442         {
       
   443         return EFalse;
       
   444         }
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // Returns whether or not the results are from a completed test record.  This
       
   449 // information is used to determine the validity of the session's "end time."
       
   450 // ---------------------------------------------------------------------------
       
   451 //
       
   452 TBool CDevDiagExecResults::IsRecordCompleted() const
       
   453     {
       
   454     return iCompleted;
       
   455     }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 // This function locks "execution" style results from further changes, by
       
   459 // changing the results type and clearing the reference to the engine.
       
   460 // ---------------------------------------------------------------------------
       
   461 //
       
   462 void CDevDiagExecResults::Finalize( TBool aTestingComplete )
       
   463     {
       
   464     LOGSTRING( "CDevDiagExecResults::Finalize()" )
       
   465 
       
   466     iDiagEngine = NULL;
       
   467     iType = ETypeLog;
       
   468     iCompletedSteps = iTotalSteps;
       
   469     iCurrentPluginStep = 0;
       
   470     iCompleted = aTestingComplete;
       
   471     }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 // This function returns the total number of steps for all items in the
       
   475 // execution results.
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 TInt CDevDiagExecResults::TotalExecutionSteps() const
       
   479     {
       
   480     return iTotalSteps;
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // This function returns the current execution step based on all items in the
       
   485 // execution results.
       
   486 // ---------------------------------------------------------------------------
       
   487 //
       
   488 TInt CDevDiagExecResults::CurrentExecutionStep() const
       
   489     {
       
   490     return iCompletedSteps + iCurrentPluginStep;
       
   491     }
       
   492 
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // Returns a reference to the plugin that execution was requested for.
       
   496 // ---------------------------------------------------------------------------
       
   497 //
       
   498 const MDiagPlugin& CDevDiagExecResults::ExecutedPluginL() const
       
   499     {
       
   500     LOGSTRING( "CDevDiagExecResults::ExecutedPluginL()" )
       
   501 
       
   502     MDiagPlugin* plugin = NULL;
       
   503     User::LeaveIfError( iPluginPool.FindPlugin( iExecutedPlugin, plugin ) );
       
   504 
       
   505     return *plugin;
       
   506     }
       
   507 
       
   508 // ---------------------------------------------------------------------------
       
   509 // Returns whether or not the execution is for a single plugin.
       
   510 // ---------------------------------------------------------------------------
       
   511 //
       
   512 TBool CDevDiagExecResults::SinglePluginExecutionL() const
       
   513     {
       
   514     if ( !iDiagEngine )
       
   515         {
       
   516         return EFalse;
       
   517         }
       
   518     
       
   519     return ( iDiagEngine->ExecutionPlanL().TestCount( EFalse ) == 1 );
       
   520     }
       
   521 
       
   522 // ---------------------------------------------------------------------------
       
   523 // Returns the number of failed tests in this set of results.
       
   524 // ---------------------------------------------------------------------------
       
   525 //
       
   526 TInt CDevDiagExecResults::FailedResultsCount() const
       
   527     {
       
   528     return iFailedCount;
       
   529     }
       
   530 
       
   531 
       
   532 // ---------------------------------------------------------------------------
       
   533 // Returns the number of passed tests in this set of results.
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 TInt CDevDiagExecResults::PassedResultsCount() const
       
   537     {
       
   538     return iPassedCount;
       
   539     }
       
   540 
       
   541 // ---------------------------------------------------------------------------
       
   542 // Returns whether or not the execution plan's resume index has been reached.
       
   543 // ---------------------------------------------------------------------------
       
   544 //
       
   545 TBool CDevDiagExecResults::ResumeIndexReachedL() const
       
   546     {
       
   547     if ( !iDiagEngine )
       
   548         {
       
   549         return ETrue;
       
   550         }
       
   551 
       
   552     return ( iDiagEngine->ExecutionPlanL().CurrentIndex() >=
       
   553         iDiagEngine->ExecutionPlanL().ResumeIndex() );
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // Returns the UID of the record associated with this set of results.
       
   558 // ---------------------------------------------------------------------------
       
   559 //
       
   560 const TUid& CDevDiagExecResults::RecordId() const
       
   561     {
       
   562     return iRecordId;
       
   563     }
       
   564 
       
   565 // ---------------------------------------------------------------------------
       
   566 // The default constructor.
       
   567 // ---------------------------------------------------------------------------
       
   568 //
       
   569 CDevDiagExecResults::CDevDiagExecResults( TUid aRecordId,
       
   570                                           CDiagPluginPool& aPluginPool,
       
   571                                           RDiagResultsDatabase& aDbSession,
       
   572                                           TUid aExecutedUid,
       
   573                                           MDiagEngineCommon* aDiagEngine )
       
   574 :   iRecordId( aRecordId ),
       
   575     iPluginPool( aPluginPool ),
       
   576     iDbSession( aDbSession ),
       
   577     iDiagEngine( aDiagEngine ),
       
   578     iExecutedPlugin( aExecutedUid )
       
   579     {
       
   580     LOGSTRING3( "CDevDiagExecResults::CDevDiagExecResults( %d, 0x%x )",
       
   581                 aRecordId.iUid,
       
   582                 aDiagEngine )
       
   583 
       
   584     }
       
   585 
       
   586 // ---------------------------------------------------------------------------
       
   587 // The second phase constructor.
       
   588 // ---------------------------------------------------------------------------
       
   589 //
       
   590 void CDevDiagExecResults::ConstructL()
       
   591     {
       
   592     LOGSTRING( "CDevDiagExecResults::ConstructL()" )
       
   593 
       
   594     // There are two types of results: (1) Current Execution, and (2) Logs.
       
   595 
       
   596     // (1) If a pointer to the diagnostics engine was provided, then it is
       
   597     // assumed that the results are from a live execution and this object will
       
   598     // wait for the results to be assigned .
       
   599     if ( iDiagEngine )
       
   600         {
       
   601         // This is the "current execution" type.
       
   602         iType = ETypeExecution;
       
   603         const MDiagPluginExecPlan& execPlan = iDiagEngine->ExecutionPlanL();
       
   604 
       
   605         // Add an entry for every item in the plan.
       
   606         TUint numItems = execPlan.Count();
       
   607         for ( TUint i = 0; i < numItems; i++ )
       
   608             {
       
   609             CResult* result = CResult::NewLC( execPlan[ i ].Plugin() );
       
   610             iResults.AppendL( result );
       
   611             CleanupStack::Pop( result );
       
   612 
       
   613             // Update the total step counter with this plugin's information.
       
   614             if ( execPlan[ i ].Plugin().Type() == MDiagPlugin::ETypeTestPlugin )
       
   615                 {
       
   616                 iTotalSteps += static_cast< const MDiagTestPlugin& >(
       
   617                     execPlan[ i ].Plugin() ).TotalSteps();
       
   618                 iLastTestIndex = i;
       
   619                 }
       
   620             }
       
   621         }
       
   622     // (2) If no pointer to the diagnostics engine was provided, then all the
       
   623     // results which correspond to the record id will be looked up from the
       
   624     // results database.
       
   625     else
       
   626         {
       
   627         // This is the "logged" type.
       
   628         iType = ETypeLog;
       
   629 
       
   630         // Get the record's results from the database.
       
   631         RDiagResultsDatabaseRecord dbRecord;
       
   632         User::LeaveIfError( dbRecord.Connect( iDbSession, iRecordId, ETrue ) );
       
   633         CleanupClosePushL( dbRecord );
       
   634         User::LeaveIfError( dbRecord.IsTestCompleted( iCompleted ) );
       
   635         RPointerArray< CDiagResultsDatabaseItem > logResults;
       
   636         CleanupClosePushL( logResults );
       
   637         User::LeaveIfError( dbRecord.GetTestResults( logResults ) );
       
   638 
       
   639         // Add an entry for each result item.
       
   640         TUint numItems = logResults.Count();
       
   641         for ( TUint i = 0; i < numItems; i++ )
       
   642             {
       
   643             MDiagPlugin* plugin = NULL;
       
   644             TInt err = iPluginPool.FindPlugin( logResults[ i ]->TestUid(),
       
   645                                                plugin );
       
   646 
       
   647             // If a matching plugin was not found for this result, we just
       
   648             // skip over it, because we can't do anything useful with it.
       
   649             // This case should only occur if a plugin logged results
       
   650             // previously, but was later removed from the phone.
       
   651             if ( err != KErrNone )
       
   652                 {
       
   653                 continue; //lint !e960 A continue makes sense here.
       
   654                 }
       
   655 
       
   656             CResult* result = CResult::NewLC( *plugin );
       
   657 
       
   658             // Ownership of the results item is transferred.
       
   659             result->SetResult( logResults[ i ], KErrNone );
       
   660             logResults[ i ] = NULL;
       
   661 
       
   662             // Get the test result.
       
   663             if ( result->Result()->TestResult() ==
       
   664                     CDiagResultsDatabaseItem::EFailed ||
       
   665                  result->Result()->TestResult() ==
       
   666                     CDiagResultsDatabaseItem::EDependencyFailed )
       
   667                 {
       
   668                 iFailedCount++;
       
   669                 }
       
   670 
       
   671             iResults.AppendL( result );
       
   672             CleanupStack::Pop( result );
       
   673             }
       
   674         iLastTestIndex = numItems - 1;
       
   675 
       
   676         CleanupStack::Pop(); // logResults
       
   677         logResults.ResetAndDestroy();
       
   678 
       
   679         // Get the uid of the executed test.
       
   680         CDiagResultsDbRecordEngineParam* execParam;
       
   681         User::LeaveIfError( dbRecord.GetEngineParam( execParam ) );
       
   682         iExecutedPlugin = execParam->ExecutionsUidArray()[ 0 ];
       
   683         delete execParam;
       
   684 
       
   685         CleanupStack::PopAndDestroy(); // dbRecord
       
   686 
       
   687         // Set dummy numbers for the execution steps.
       
   688         iTotalSteps = 1;
       
   689         iCompletedSteps = 1;
       
   690         }
       
   691     }
       
   692     
       
   693     
       
   694 
       
   695  const CDiagResultsDatabaseItem* CDevDiagExecResults::GetSinglepluginExecutionResult() const
       
   696     {
       
   697     
       
   698     	return iResults[ iLastTestIndex ]->Result();
       
   699     	/*
       
   700     	CDiagResultsDatabaseItem* aResult;
       
   701     	const CDevDiagExecResults::CResult& result = CDevDiagExecResults::CurrentItemL();
       
   702     	aResult = result.Result();
       
   703     	return aResult;*/
       
   704     	
       
   705     }
       
   706 // End of File