equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
|
17 |
17 #include "cxestatemachinebase.h" |
18 #include "cxestatemachinebase.h" |
18 #include "cxutils.h" |
19 #include "cxutils.h" |
19 #include "cxeerrormappingsymbian.h" |
|
20 #include "cxestate.h" |
20 #include "cxestate.h" |
21 |
21 |
22 CxeStateMachineBase::CxeStateMachineBase( const char* stateMachineName ) : |
22 CxeStateMachineBase::CxeStateMachineBase(const char *stateMachineName) : |
23 mStateBitsUsed(0), mStateId(0), mName(stateMachineName) |
23 mStateBitsUsed(0), mStateId(0), mName(stateMachineName) |
24 { |
24 { |
25 } |
25 } |
26 |
26 |
27 CxeStateMachineBase::~CxeStateMachineBase() |
27 CxeStateMachineBase::~CxeStateMachineBase() |
28 { |
28 { |
29 qDeleteAll(mStates); |
29 qDeleteAll(mStates); |
30 mStates.clear(); |
30 mStates.clear(); |
31 } |
31 } |
32 |
32 |
33 bool CxeStateMachineBase::addState( CxeState* state ) |
33 bool CxeStateMachineBase::addState(CxeState *state) |
34 { |
34 { |
35 bool success( state // non-null state object |
35 bool success( state // non-null state object |
36 && state->stateId() // state id is not zero |
36 && state->stateId() // state id is not zero |
37 && !(mStateBitsUsed & state->stateId()) // no overlapping bits |
37 && !(mStateBitsUsed & state->stateId()) // no overlapping bits |
38 ); |
38 ); |
44 } |
44 } |
45 |
45 |
46 return success; |
46 return success; |
47 } |
47 } |
48 |
48 |
49 bool CxeStateMachineBase::setState( int stateId, int error ) |
49 bool CxeStateMachineBase::setState(int stateId, CxeError::Id error) |
50 { |
50 { |
51 bool success = true; |
51 bool success = true; |
52 |
52 |
53 if (stateId == mStateId) { |
53 if (stateId == mStateId) { |
54 // No transition, nothing needs to be done |
54 // No transition, nothing needs to be done |
74 |
74 |
75 success = verifyStateChange(stateId); |
75 success = verifyStateChange(stateId); |
76 |
76 |
77 if (success) { |
77 if (success) { |
78 mStateId = stateId; |
78 mStateId = stateId; |
79 handleStateChanged(mStateId, CxeErrorHandlingSymbian::map(error)); |
79 handleStateChanged(mStateId, error); |
80 } |
80 } |
81 |
81 |
82 return success; |
82 return success; |
83 } |
83 } |
84 |
84 |
85 bool CxeStateMachineBase::setInitialState( int stateId ) |
85 bool CxeStateMachineBase::setInitialState(int stateId) |
86 { |
86 { |
87 bool success = mStates.contains(stateId); |
87 bool success = mStates.contains(stateId); |
88 |
88 |
89 if (success) { |
89 if (success) { |
90 // New state name known, print it |
90 // New state name known, print it |
111 int CxeStateMachineBase::stateId() const |
111 int CxeStateMachineBase::stateId() const |
112 { |
112 { |
113 return mStateId; |
113 return mStateId; |
114 } |
114 } |
115 |
115 |
116 bool CxeStateMachineBase::verifyStateChange( int newStateId ) |
116 bool CxeStateMachineBase::verifyStateChange(int newStateId) |
117 { |
117 { |
118 bool allowStateChange = false; |
118 bool allowStateChange = false; |
119 |
119 |
120 // Check that current state can be found in the state chart |
120 // Check that current state can be found in the state chart |
121 if ( mStates.contains(stateId()) ) { |
121 if ( mStates.contains(stateId()) ) { |
124 allowStateChange = (currentState->allowedNextStates() & newStateId); |
124 allowStateChange = (currentState->allowedNextStates() & newStateId); |
125 } |
125 } |
126 |
126 |
127 return allowStateChange; |
127 return allowStateChange; |
128 } |
128 } |
129 |
|
130 |
|
131 |
|
132 |
|