Merge "add missing packages requires" into tizen
[profile/ivi/ico-uxf-homescreen.git] / lib / misc / state-machine / CicoStateMachine.h
1 /*
2  * Copyright (c) 2013 TOYOTA MOTOR CORPORATION.
3  *
4  * Contact: 
5  *
6  * Licensed under the Apache License, Version 2.0 (the License){}
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License. 
17  */
18 #ifndef CICOSTATEMACHINE_H
19 #define CICOSTATEMACHINE_H
20
21 #include <iostream>
22 #include <string>
23 #include <vector>
24
25 #include "CicoStateCore.h"
26
27 #ifndef CICOSTATE_H
28 class CicoState;
29 #endif
30
31 #ifndef CICOFINALSTATE_H
32 class CicoFinalState;
33 #endif
34
35 #ifndef CICOHISTORYSTATE_H
36 class CicoHistoryState;
37 #endif
38
39
40 /**
41  * state-machine object class definition
42  * @author m.kamoshida
43  * @version 0.1
44  */
45
46 /**
47  * @brief The CicoStateMachine class
48  *   state-machine object class definition
49  */
50 class CicoStateMachine : public CicoStateCore
51 {
52 public:
53     // Constructior
54                 CicoStateMachine(int value = 0);
55                 CicoStateMachine(const std::string& name, int value = 0);
56
57     // registration state/historyState/fainalState objects
58     void        addState(CicoState* state);
59     void        addState(CicoFinalState* state);
60     void        addState(CicoHistoryState* state);
61
62     // registration start position
63     void        addInitState(CicoState* state);
64     void        addInitState(CicoHistoryState* state);
65
66     // start state-machine
67     bool        start();
68
69     // Delivery of the event
70     bool        eventEntry(const CicoEvent& ev);
71     // Test event delivery
72     bool        eventTest(const CicoEvent& ev);
73
74     // stop state-machine
75     bool        stop();
76
77     // Acquisition of state-objects is registered
78     const CicoStateCore* getState(const int value) const;
79     const CicoStateCore* getState(const std::string& name) const;
80
81     // get current active state-objects
82     bool        getCurrentState(std::vector<const CicoState*>& states,
83                                 CicoStateCore::E_GetPolicy policy=CicoStateCore::ELvlBttm);
84     const CicoState* getCurrentState();
85
86 protected:
87 private:
88     bool        m_eventExec;            // During event processing flag
89 };
90
91 /**
92  * @brief CicoStateMachine::addState
93  * @param state register child state-object pointer
94  */
95 inline void CicoStateMachine::addState(CicoState* state)
96 {
97     CicoStateCore::addState((CicoStateCore*)state);
98 }
99
100 /**
101  * @brief CicoStateMachine::addState
102  * @param state register child state-object pointer
103  */
104 inline void CicoStateMachine::addState(CicoFinalState* state)
105 {
106     CicoStateCore::addState((CicoStateCore*)state);
107 }
108
109 /**
110  * @brief CicoStateMachine::addState
111  * @param state register child state-object pointer
112  */
113 inline void CicoStateMachine::addState(CicoHistoryState* state)
114 {
115     CicoStateCore::addState((CicoStateCore*)state);
116 }
117
118 /**
119  * @brief CicoStateMachine::addInitState
120  * @param state
121  * @param state state-object pointer is tart position
122  */
123 inline void CicoStateMachine::addInitState(CicoState* state)
124 {
125     CicoStateCore::addInitState((CicoStateCore*)state);
126 }
127
128 /**
129  * @brief CicoStateMachine::addInitState
130  * @param state state-object pointer is tart positions
131  */
132 inline void CicoStateMachine::addInitState(CicoHistoryState* state)
133 {
134     CicoStateCore::addInitState((CicoStateCore*)state);
135 }
136
137 /**
138  * @brief CicoStateMachine::getCurrentState
139  * @param states active state-object pointers store area
140  * @param policy get policy
141  * @return true:get success / false get fail
142  */
143 inline bool CicoStateMachine::getCurrentState(std::vector<const CicoState*>& states,
144                                               CicoStateCore::E_GetPolicy policy)
145 {
146     return CicoStateCore::getCurrentState(states, policy);
147 }
148
149 /**
150  * @brief CicoStateMachine::getCurrentState
151  * @      get active state-object
152  * @return active state-object pointer
153  */
154 inline const CicoState* CicoStateMachine::getCurrentState()
155 {
156     return CicoStateCore::getCurrentState();
157 }
158
159 /**
160  * @brief CicoStateMachine::getState
161  * @param value state-object identification number
162  * @return not 0:state-object pointer/0 get fail
163  */
164 inline const CicoStateCore* CicoStateMachine::getState(const int value) const
165 {
166     return CicoStateCore::getState(value);
167 }
168
169 /**
170  * @brief CicoStateMachine::getState
171  * @param name state-object identification name
172  * @return not 0:state-object pointer/0 get fail
173  */
174 inline const CicoStateCore* CicoStateMachine::getState(const std::string& name) const
175 {
176     return CicoStateCore::getState(name);
177 }
178
179 #endif // CICOSTATEMACHINE_H