Update contrib.
1 // Copyright (c) 2004-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Implementation of finite state machine
23 #include "t_ms_main.h"
24 #include "cstatemachine.h"
30 return new (ELeave) CStateMachine;
33 CStateMachine::CStateMachine()
35 // Intentionally left blank
38 CStateMachine::~CStateMachine()
40 allStates.ResetAndDestroy();
44 CStateMachine::MoveTo(int aStateId)
48 test.Printf(_L("The current state is undefined\n"));
52 iCurrentState->MoveTo(aStateId);
53 iCurrentState = FindState(aStateId);
57 CStateMachine::AddState(int aStateId)
59 const TState* state = FindState(aStateId);
65 case EUsbMsDriveState_Disconnected:
66 state = new TDisconnected();
68 case EUsbMsDriveState_Connecting:
69 state = new TConnecting();
71 case EUsbMsDriveState_Connected:
72 state = new TConnected();
74 case EUsbMsDriveState_Disconnecting:
75 state = new TDisconnecting();
77 case EUsbMsDriveState_Active:
78 state = new TActive();
80 case EUsbMsDriveState_Locked:
81 state = new TLocked();
83 case EUsbMsState_Read:
86 case EUsbMsState_Written:
87 state = new TWritten();
95 allStates.Append(state);
103 CStateMachine::SetInitState(int aStateId)
105 iCurrentState = FindState(aStateId);
106 iFromStateId = aStateId;
110 CStateMachine::FindState(int aStateId) const
112 TInt count = allStates.Count();
113 for (TInt i = 0; i < count; i++)
115 if (allStates[i]->GetStateId() == aStateId)
124 TInt CStateMachine::CurrentStateId() const
126 return iCurrentState->GetStateId();
129 TInt CStateMachine::FromStateId() const
134 void CStateMachine::SetFromStateId(TInt aStateId)
136 iFromStateId = aStateId;