|
1 /* |
|
2 * Copyright (c) 2008 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 the License "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 |
|
18 #ifndef STATEMACHINE_V2_H_ |
|
19 #define STATEMACHINE_V2_H_ |
|
20 |
|
21 namespace stmUiEventEngine |
|
22 { |
|
23 /** |
|
24 * the next templates define the static callbacks required to pass the this object to the member function |
|
25 * There are two definitions, one for the TBool is*() method checking the message, |
|
26 * the other one returning void for entry, event and action methods. |
|
27 */ |
|
28 template<class T, bool (T::*F)()> |
|
29 bool isF(void *p) |
|
30 { |
|
31 return ((reinterpret_cast<T*>(p))->*F)(); |
|
32 } |
|
33 |
|
34 template<class T, void (T::*F)()> |
|
35 void aF(void *p) |
|
36 { |
|
37 ((reinterpret_cast<T*>(p))->*F)(); |
|
38 } |
|
39 |
|
40 ///////////////////////////////////////////////////////////////////////////////////// |
|
41 // We define the state machine in C fashion so that we get the initialized state table |
|
42 // already at compilation phase. The message checking methods, event methods and action methods are |
|
43 // then passed to the C++ object to be processed. |
|
44 // The currently defined states are the following, at the same time they are used as the index to the array of states. |
|
45 enum TStateMachineState { |
|
46 Eignore, |
|
47 EInit, |
|
48 EDispatch, |
|
49 EInTouchTime, |
|
50 EInHoldTime_U, |
|
51 EInHoldTime_D, |
|
52 EInTouchArea, |
|
53 ESuppress_D |
|
54 } ; |
|
55 // Using these kind of functions the state machine is of course single threaded |
|
56 // the necessary parameters need to be passed in the member variables |
|
57 typedef bool (*condition_t)(void* ) ; |
|
58 typedef void (*action_t)(void*) ; |
|
59 |
|
60 /* |
|
61 * The possible events to the state machine. The pointer and timer events are possible. |
|
62 */ |
|
63 enum TStateMachineEvent { |
|
64 EDown, |
|
65 EDrag, |
|
66 ECapacitiveUP, |
|
67 EResistiveUP, |
|
68 ETouchTimer, |
|
69 EHoldTimer, |
|
70 ESuppressTimer |
|
71 } ; |
|
72 /*! |
|
73 * STATE_ELEMENT defines one line in the state/event instance. |
|
74 * It contains three fields: ConditionFunction, ActionFunction and NextState. |
|
75 * The generic state machine will call the ConditionFunction (if it is != NULL) |
|
76 * and if the result is true, it will call ActionFunction (if it is != NULL). |
|
77 * Then it will continue to NextState. |
|
78 * If NextState is Eignore, it will try the next line of state/event. |
|
79 */ |
|
80 typedef struct _STATE_ELEMENT { |
|
81 /*! |
|
82 * Condition function contains the pointer to the method used to check some condition. |
|
83 * If the pointer is non-NULL the state machine will call the function and based on the result |
|
84 * (if true) calls the ActionFunction. |
|
85 */ |
|
86 const condition_t conditionFunction ; |
|
87 /*! |
|
88 * ActionFunction contains a pointer to a method performing some action. The state machine |
|
89 * will call the method if the pointer is non-NULL. |
|
90 */ |
|
91 const action_t actionFunction ; |
|
92 /*! |
|
93 * NextState contains either the next state or Eignore. The state machine will process state elements |
|
94 * until the NextState != Eignroe is found. |
|
95 */ |
|
96 const TStateMachineState nextState ; |
|
97 } STATE_ELEMENT ; |
|
98 |
|
99 /*! |
|
100 * Each state contains an array defining the possible event and the state elements |
|
101 * that are processed if the event happens. |
|
102 */ |
|
103 typedef struct _STATE { |
|
104 /*! |
|
105 * The event defines the pointer event or timer event being processed |
|
106 */ |
|
107 const TStateMachineEvent theEvent ; // |
|
108 /*! |
|
109 * StateElements points to the array of STATE_ELEMENT entries which define the |
|
110 * condition and action functions to be processed and the resulting nesxt state. |
|
111 */ |
|
112 const STATE_ELEMENT* const stateElements ; |
|
113 } STATE ; |
|
114 |
|
115 } // namespace |
|
116 |
|
117 #endif /* STATEMACHINE_V2_H_ */ |