wvuing/IMPSConnectionUI/OperationStepSrc/CCnUiCntrlStepDriver.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Control step driver.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include "CCnUiCntrlStepDriver.h"
       
    21 #include "MCnUiCntrlStep.h"
       
    22 
       
    23 #include "CnUiPanics.h"
       
    24 #include "IMPSCommonUiDebugPrint.h"
       
    25 
       
    26 
       
    27 // ================= MEMBER FUNCTIONS =======================
       
    28 // Two-phased constructor.
       
    29 CCnUiCntrlStepDriver* CCnUiCntrlStepDriver::NewL()
       
    30     {
       
    31     CCnUiCntrlStepDriver* self = CCnUiCntrlStepDriver::NewLC();
       
    32     CleanupStack::Pop( self );
       
    33     return self;
       
    34     }
       
    35 
       
    36 
       
    37 // Two-phased constructor.
       
    38 CCnUiCntrlStepDriver* CCnUiCntrlStepDriver::NewLC()
       
    39     {
       
    40     CCnUiCntrlStepDriver* self = new ( ELeave ) CCnUiCntrlStepDriver();
       
    41     CleanupStack::PushL( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 // Destructor
       
    47 CCnUiCntrlStepDriver::~CCnUiCntrlStepDriver()
       
    48     {
       
    49     //step driver owns steps
       
    50     iSteps.ResetAndDestroy();
       
    51     }
       
    52 
       
    53 
       
    54 // C++ default constructor can NOT contain any code, that
       
    55 // might leave.
       
    56 //
       
    57 CCnUiCntrlStepDriver::CCnUiCntrlStepDriver()
       
    58     {
       
    59     }
       
    60 
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CCnUiCntrlStepDriver::AppendStepL()
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CCnUiCntrlStepDriver::AppendStepL( MCnUiCntrlStep* aStep )
       
    68     {
       
    69     __ASSERT_ALWAYS( aStep,
       
    70                      CnUiPanicOrLeaveL( EIMPSConn_NULLPtr,
       
    71                                         KErrArgument ) );
       
    72 
       
    73     User::LeaveIfError( iSteps.Append( aStep ) );
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CCnUiCntrlStepDriver::ExecuteL()
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 TInt CCnUiCntrlStepDriver::ExecuteL()
       
    82     {
       
    83     __ASSERT_ALWAYS( iSteps.Count() > 0,
       
    84                      CnUiPanicOrLeaveL( EIMPSConnStepDriverUninitialized,
       
    85                                         KErrNotSupported ) );
       
    86 
       
    87     //Run each step untill all done or first error occured
       
    88     //At first execution round start form initial step.
       
    89     TInt stepResult = KErrNone;
       
    90     const TInt totalStepCount = iSteps.Count();
       
    91     TInt lastRunnedIndex = 0;
       
    92     TInt runIndex = 0;
       
    93 
       
    94     TBool restartNeeded( ETrue );
       
    95     while ( restartNeeded )
       
    96         {
       
    97         // by default we do not need to restart
       
    98         restartNeeded = EFalse;
       
    99         stepResult = KErrNone;
       
   100 
       
   101         while ( ( runIndex < totalStepCount ) && ( stepResult == KErrNone ) )
       
   102             {
       
   103             MCnUiCntrlStep* cStep = iSteps[ runIndex ];
       
   104             stepResult = cStep->RunStepL();
       
   105             lastRunnedIndex = runIndex;
       
   106             runIndex++;
       
   107             }
       
   108 
       
   109         //Teardown each so far run step untill all are teardowned.
       
   110         //Correct teardown operation is called according the last
       
   111         //runned step return status.
       
   112         //If steps were runned succesfully, some operation may
       
   113         //restart processing if it wishes so. Restart is
       
   114         //done from step wishing so forward.
       
   115         TInt teardownIndex = lastRunnedIndex;
       
   116         while ( ( teardownIndex >= 0 ) && ( !restartNeeded ) )
       
   117             {
       
   118             MCnUiCntrlStep* cStep = iSteps[ teardownIndex ];
       
   119             if ( stepResult == KErrNone )
       
   120                 {
       
   121                 if ( cStep->HandleCompleteL() == ECnUiRestartStep )
       
   122                     {
       
   123                     //Restart runing from this step
       
   124                     runIndex = teardownIndex;
       
   125                     // we need to restart the whole thing from start
       
   126                     restartNeeded = ETrue;
       
   127                     }
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 cStep->UndoStepL();
       
   132                 }
       
   133 
       
   134             teardownIndex--;
       
   135             }
       
   136         }
       
   137 
       
   138     //return the status from last run step
       
   139     return stepResult;
       
   140     }
       
   141 
       
   142 
       
   143 //  End of File
       
   144 
       
   145