|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 #ifndef CXESTATEMACHINE_H |
|
18 #define CXESTATEMACHINE_H |
|
19 |
|
20 #include "cxestatemachinebase.h" |
|
21 |
|
22 class CxeState; |
|
23 |
|
24 /** |
|
25 * CxeStateMachine extends CxeStateMachineBase functionality. All methods call base class |
|
26 * implementation, and will panic if the base class return value indicates failure. |
|
27 * |
|
28 * Engine classes should derive from CxeStateMachine. CxeStateMachineBase is for situations where |
|
29 * asserts can't be used, like unit testing. |
|
30 * |
|
31 * CxeStateMachine is internal to the engine and is not visible in the engine API. |
|
32 */ |
|
33 class CxeStateMachine : public CxeStateMachineBase |
|
34 { |
|
35 public: |
|
36 /** |
|
37 * CxeStateMachine constructor. After construction, the derived class should |
|
38 * add all the defined states and call setInitialState(). |
|
39 * |
|
40 * @sa addState setInitialState |
|
41 * @param stateMachineName Name for this state machine (used for debug prints) |
|
42 */ |
|
43 CxeStateMachine(const char* stateMachineName); |
|
44 virtual ~CxeStateMachine(); |
|
45 |
|
46 protected: |
|
47 /** |
|
48 * Add a new state to the machine. Takes ownership of state. This function will |
|
49 * panic, if new state id is incorrect. |
|
50 * |
|
51 * @param state A CxeState object defining a name, ID, and allowed transitions for |
|
52 * the new state. The CxeState ID must be unique and not to contain overlapping bits |
|
53 * with other state ids, since bitwise AND operator is used for the state ids. |
|
54 * @return True if adding was successful, false if adding failed |
|
55 */ |
|
56 bool addState(CxeState *state); |
|
57 |
|
58 /** |
|
59 * Initiate a state transition from current state to a given state ID. If the state |
|
60 * transition is invalid, this function will panic. |
|
61 * |
|
62 * @param stateId State ID of the new state |
|
63 * @param error Optional error code to be associated with the transition |
|
64 */ |
|
65 bool setState(int stateId, int error = 0); |
|
66 |
|
67 /** |
|
68 * Set the initial state of the state machine. Can be called only once. |
|
69 * This method will panic, if initial state to be set is unknown, or initial |
|
70 * state has already been set. |
|
71 * |
|
72 * @param stateId State ID for the initial state. |
|
73 */ |
|
74 bool setInitialState(int stateId); |
|
75 |
|
76 /** |
|
77 * Pure virtual function to be implemented by derived classes. Called when state changes. |
|
78 * The implementation should emit a signal informing interested parties of a state change. |
|
79 * |
|
80 * @param newStateId State ID for the new state |
|
81 * @param error An error code associated with the state transition |
|
82 */ |
|
83 virtual void handleStateChanged(int newStateId, CxeError::Id error) = 0; |
|
84 |
|
85 private: |
|
86 |
|
87 }; |
|
88 |
|
89 #endif // CXESTATEMACHINE_H |
|
90 |
|
91 |