commsfwsupport/commselements/testing/ElementServer/src/StateMachineImpl.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This contains the implementation of a StateMachine for testing
       
    15 // purpose.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include "StateMachineImpl.h"
       
    20 
       
    21 /*
       
    22  * @file StateMachineImpl.cpp
       
    23  */
       
    24 
       
    25 /*
       
    26  * Creates a new state machine object.
       
    27  * 
       
    28  * @return Pointer to a state machine implementation.
       
    29  */
       
    30 CStateMachineImpl* CStateMachineImpl::NewL()
       
    31     {
       
    32     CStateMachineImpl* stateMachine = new (ELeave) CStateMachineImpl();
       
    33     CleanupStack::PushL(stateMachine);
       
    34     return stateMachine;
       
    35     }
       
    36 
       
    37 /*
       
    38  * Sets the state machines fragment member to the given HBuf.
       
    39  * 
       
    40  * @param HBufC8* The fragment that the member should be set to.
       
    41  */
       
    42 void CStateMachineImpl::SetFragment(HBufC8* aFragment)
       
    43     {
       
    44     iFragment = aFragment;
       
    45     }
       
    46 
       
    47 /*
       
    48  * Returns the member variable to test the setting function.
       
    49  * 
       
    50  * @return The member variable value.
       
    51  */
       
    52 MStateMachineNotify* CStateMachineImpl::StateMachineNotifier()
       
    53     {
       
    54     return iStateMachineNotify;
       
    55     }
       
    56 
       
    57 /*
       
    58  * Overriden function so we can stop the active scheduler.
       
    59  */
       
    60 void CStateMachineImpl::OnCompletion()
       
    61     {
       
    62     CActiveScheduler::Stop();
       
    63     CStateMachine::OnCompletion();
       
    64     }
       
    65 
       
    66 /*
       
    67  * Creates an active scheduler that a newly created state machine will be added too.
       
    68  * 
       
    69  * @return An active scheduler used for testing.
       
    70  */
       
    71 CActiveScheduler* CStateMachineImpl::StartActiveSchedulerL()
       
    72     {
       
    73     CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler;
       
    74     CActiveScheduler::Install(activeScheduler);
       
    75     return activeScheduler;
       
    76     }
       
    77 
       
    78 /*
       
    79  * The processing method called from within a state machine's RunL. Processes
       
    80  * state changes.
       
    81  * 
       
    82  * @param TRequestStatus The state machines internal status.
       
    83  * @return CAsyncEvent* A pointer to the next state, or NULL to complete.
       
    84  */
       
    85 CAsynchEvent* CAsyncEventImpl::ProcessL(TRequestStatus& aStatus)
       
    86     {
       
    87     iRuns++;
       
    88     iTestStep->LogStateChange(iAsyncEvent);
       
    89     if (iAsyncEvent == EPanicAsyncEvent)
       
    90         User::Leave(KElementStateMachineError);
       
    91     if (iAsyncEvent == EForcedErrorAsyncEvent)
       
    92         {
       
    93             iStateMachine->SetLastError(iError);
       
    94         if (iRuns == 2)
       
    95             iStateMachine->SetErrorEvent(NULL);
       
    96         }
       
    97     if (iAsyncEvent == ESuspendAsyncEvent)
       
    98         {
       
    99         iStateMachine->SetSuspendRequest(ETrue);
       
   100         }
       
   101     TRequestStatus* p = &aStatus;
       
   102     User::RequestComplete(p, iError); //move to the next state
       
   103     if (iAsyncEvent == ECancelAsyncEvent)
       
   104         {
       
   105         iStateMachine->Cancel(iError);
       
   106         }
       
   107     return Next();
       
   108     }