devicediagnosticsfw/diagframework/src/diagexecplanentryimpl.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
     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:  Class definition of CDiagExecPlanEntryImpl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // CLASS DECLARATION
       
    20 #include "diagexecplanentryimpl.h"
       
    21 
       
    22 // SYSTEM INCLUDE FILES
       
    23 #include <DiagFrameworkDebug.h>             // LOGSTRING
       
    24 
       
    25 // USER INCLUDE FILES
       
    26 #include "diagengineconfig.h"               // TDiagEngineConfig
       
    27 #include "diagframework.pan"                // Panic Codes
       
    28 
       
    29 // DATA
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL DATA TYPES
       
    34 
       
    35 
       
    36 // ======== LOCAL FUNCTIONS ========
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CDiagExecPlanEntryImpl::CDiagExecPlanEntryImpl
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CDiagExecPlanEntryImpl::CDiagExecPlanEntryImpl( 
       
    45         MDiagEngineCommon& aEngine,
       
    46         const TDiagEngineConfig& aEngineConfig,
       
    47         MDiagExecPlanEntryImplObserver& aObserver,
       
    48         MDiagPlugin& aPlugin,
       
    49         TBool aAsDependency,
       
    50         TType aType )
       
    51     :   CActive( EPriorityStandard ),
       
    52         iEngine( aEngine ),
       
    53         iEngineConfig( aEngineConfig ),
       
    54         iObserver( aObserver ),
       
    55         iPlugin( aPlugin ),
       
    56         iAsDependency( aAsDependency ),
       
    57         iState ( EStateQueued ),
       
    58         iType ( aType )
       
    59     {
       
    60     CActiveScheduler::Add( this );
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CDiagExecPlanEntryImpl::~CDiagExecPlanEntryImpl
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CDiagExecPlanEntryImpl::~CDiagExecPlanEntryImpl()
       
    68     {
       
    69     if ( iWatchdogTimer )
       
    70         {
       
    71         iWatchdogTimer->Cancel();
       
    72         delete iWatchdogTimer;
       
    73         iWatchdogTimer = NULL;
       
    74         }
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CDiagExecPlanEntryImpl::Plugin
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 MDiagPlugin& CDiagExecPlanEntryImpl::Plugin()
       
    82     {
       
    83     return iPlugin;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CDiagExecPlanEntryImpl::Plugin
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 const MDiagPlugin& CDiagExecPlanEntryImpl::Plugin() const
       
    91     {
       
    92     return iPlugin;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CDiagExecPlanEntryImpl::State
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 MDiagExecPlanEntry::TState CDiagExecPlanEntryImpl::State() const
       
   100     {
       
   101     return iState;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CDiagExecPlanEntryImpl::ChangeStateL
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 void CDiagExecPlanEntryImpl::ChangeStateL( TState aState )
       
   109     {
       
   110     iState = aState;
       
   111 
       
   112     TBool watchdogNeeded = EFalse;
       
   113 
       
   114     // determine if we need a watchdog or not.
       
   115     switch( aState )
       
   116         {
       
   117         case EStateRunning:
       
   118         case EStateStopped:
       
   119             watchdogNeeded = ETrue;
       
   120             break;
       
   121 
       
   122         case EStateQueued:
       
   123         case EStateInitDelay:
       
   124         case EStateCompleted:
       
   125         case EStateSuspended:
       
   126         default:
       
   127             watchdogNeeded = EFalse;
       
   128             break;
       
   129         }
       
   130 
       
   131     if ( watchdogNeeded )
       
   132         {
       
   133         if ( iWatchdogTimer == NULL )
       
   134             {
       
   135             LOGSTRING( "CDiagExecPlanEntryImpl::ChangeStateL() Create watchdog timer" )
       
   136             iWatchdogTimer = CPeriodic::NewL( EPriorityStandard );
       
   137             }
       
   138         ResetWatchdog();
       
   139         }
       
   140     else
       
   141         {
       
   142         if ( iWatchdogTimer )
       
   143             {
       
   144             LOGSTRING( "CDiagExecPlanEntryImpl::ChangeStateL() delete watchdog timer" )
       
   145             iWatchdogTimer->Cancel();
       
   146             delete iWatchdogTimer;
       
   147             iWatchdogTimer = NULL;
       
   148             }
       
   149         }
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CDiagExecPlanEntryImpl::Type
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 CDiagExecPlanEntryImpl::TType CDiagExecPlanEntryImpl::Type() const
       
   157     {
       
   158     return iType;
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CDiagExecPlanEntryImpl::SetType
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CDiagExecPlanEntryImpl::SetType( TType aType )
       
   166     {
       
   167     iType = aType;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CDiagExecPlanEntryImpl::AsDependency
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 TBool CDiagExecPlanEntryImpl::AsDependency() const
       
   175     {
       
   176     return iAsDependency;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CDiagExecPlanEntryImpl::SetAsDependency
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CDiagExecPlanEntryImpl::SetAsDependency( TBool aAsDependency )
       
   184     {
       
   185     iAsDependency = aAsDependency;
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CDiagExecPlanEntryImpl::IsStoppedByClient
       
   190 // ---------------------------------------------------------------------------
       
   191 //
       
   192 TBool CDiagExecPlanEntryImpl::IsStoppedByClient() const
       
   193     {
       
   194     return iStoppedByClient;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CDiagExecPlanEntryImpl::Engine
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 MDiagEngineCommon& CDiagExecPlanEntryImpl::Engine()
       
   202     {
       
   203     return iEngine;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CDiagExecPlanEntryImpl::EngineConfig
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 const TDiagEngineConfig& CDiagExecPlanEntryImpl::EngineConfig() const
       
   211     {
       
   212     return iEngineConfig;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CDiagExecPlanEntryImpl::Observer
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 MDiagExecPlanEntryImplObserver& CDiagExecPlanEntryImpl::Observer()
       
   220     {
       
   221     return iObserver;
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CDiagExecPlanEntryImpl::StopExecutionByClientL
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CDiagExecPlanEntryImpl::StopExecutionByClientL( 
       
   230         MDiagEngineCommon::TCancelMode aCancelMode )
       
   231     {
       
   232     iStoppedByClient = ETrue;
       
   233 
       
   234     DoStopExecutionByClientL( aCancelMode );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CDiagExecPlanEntryImpl::ResetWatchdog
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CDiagExecPlanEntryImpl::ResetWatchdog()
       
   242     {
       
   243     if ( iWatchdogTimer )
       
   244         {
       
   245         LOGSTRING2( "CDiagExecPlanEntryImpl::ResetWatchdog() "
       
   246             L"Timout Value = %d microseconds", iWatchdogValue.Int() )
       
   247         iWatchdogTimer->Cancel();
       
   248         iWatchdogTimer->Start( iWatchdogValue,
       
   249                                iWatchdogValue,
       
   250                                TCallBack( WatchdogTimerExpiredL, this ) );
       
   251         }
       
   252     else    
       
   253         {
       
   254         LOGSTRING( "CDiagExecPlanEntryImpl::ResetWatchdog() "
       
   255             L"Watchdog was not running. Reset request ignored." )
       
   256         }
       
   257     }
       
   258 
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // CDiagExecPlanEntryImpl::ResetWatchdog
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CDiagExecPlanEntryImpl::ResetWatchdog( TDiagEngineWatchdogTypes aWatchdogType )
       
   265     {
       
   266     switch ( aWatchdogType )
       
   267         {
       
   268         case EDiagEngineWatchdogTypeAutomatic:
       
   269             iWatchdogValue = iEngineConfig.WatchdogTimeoutValueAutomatic();
       
   270             break;
       
   271 
       
   272         case EDiagEngineWatchdogTypeInteractive:
       
   273             iWatchdogValue = iEngineConfig.WatchdogTimeoutValueInteractive();
       
   274             break;
       
   275 
       
   276         default:
       
   277             __ASSERT_ALWAYS( 0, Panic( EDiagFrameworkBadArgument ) );
       
   278             break;
       
   279         }
       
   280 
       
   281     ResetWatchdog();
       
   282     }
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CDiagExecPlanEntryImpl::ResetWatchdog
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CDiagExecPlanEntryImpl::ResetWatchdog( TTimeIntervalMicroSeconds32 aWatchdogValue )
       
   289     {
       
   290     iWatchdogValue = aWatchdogValue;
       
   291     ResetWatchdog();
       
   292     }
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CDiagExecPlanEntryImpl::StopWatchdogTemporarily
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CDiagExecPlanEntryImpl::StopWatchdogTemporarily()
       
   299     {
       
   300     LOGSTRING( "CDiagExecPlanEntryImpl::StopWatchdogTemporarily() " )
       
   301     if ( iWatchdogTimer )
       
   302         {
       
   303         iWatchdogTimer->Cancel();
       
   304         }
       
   305     }
       
   306 
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 // CDiagEngineImpl::WatchdogTimerExpiredL
       
   310 //
       
   311 // ---------------------------------------------------------------------------
       
   312 //
       
   313 TInt CDiagExecPlanEntryImpl::WatchdogTimerExpiredL( TAny* aPtr )
       
   314     {
       
   315     LOGSTRING( "CDiagExecPlanEntryImpl::WatchdogTimerExpiredL()" )
       
   316     
       
   317     CDiagExecPlanEntryImpl* thisPtr = static_cast< CDiagExecPlanEntryImpl* >( aPtr );
       
   318 
       
   319     // once watchdog expires, it should not be restarted, since it is end of test.
       
   320     thisPtr->iWatchdogTimer->Cancel();
       
   321     delete thisPtr->iWatchdogTimer;
       
   322     thisPtr->iWatchdogTimer = NULL;
       
   323 
       
   324     thisPtr->StopExecutionByWatchdogL();
       
   325     
       
   326     return 0;
       
   327     }
       
   328 
       
   329 
       
   330 
       
   331 // End of File
       
   332