2 * Copyright (c) 2013 TOYOTA MOTOR CORPORATION.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef CICOSTATECORE_H
19 #define CICOSTATECORE_H
24 #include "CicoEvent.h"
26 #ifndef CICOEVENTINFO_H
34 #ifndef CICOSTATEACTION_H
35 class CicoStateAction;
38 #ifndef CICOSTATEMACHINE_H
39 class CicoStateMachine;
42 #ifndef CICOSTAEACTION_H
43 class CicoStateAction;
46 #ifndef CICOHISTORYSTATE_H
47 class CicoHistoryState;
52 * It is the core definition of the state transition
57 * @brief The CicoStateCore class
61 // Type of state object
63 EStateMachine = 0, // kind of stateMachine object
64 EState, // kind of state object
65 EHistoryState, // kind of history state object
66 EFinalState // kind of final state 0bject
69 enum E_GetPolicy { // get current state policy
70 ELvlTop = 0, // First-degree active state
71 ELvlAll, // ALL active state
72 ELvlBttm // Buttom active state
75 CicoStateCore(E_TOSO ts, CicoStateCore* parent =0);
76 CicoStateCore(E_TOSO ts, const std::string& name,
77 CicoStateCore* parent =0);
78 CicoStateCore(E_TOSO ts, const std::string& name, int value,
79 CicoStateCore* parent =0);
80 CicoStateCore(E_TOSO ts, int value, CicoStateCore* parent =0);
83 virtual ~CicoStateCore();
85 // Identification name get/set
86 const std::string& getName() const;
87 void setName(const std::string& name);
89 // Identification number get/set
91 void setValue(int value);
94 const CicoStateCore* getParent() const;
96 // active/inactive get
97 bool isActive() const; // active state
100 E_TOSO getType() const;
101 bool isStateMachine() const;
102 bool isState() const;
103 bool isFinalState() const;
104 bool isHistoryState() const;
106 bool isRegisteredInit() const;
109 void getObjects(std::vector<CicoStateCore*>& obj);
110 const CicoEventInfo* getEventInfo(const std::string& name,
111 unsigned short ev) const;
116 enum E_SttUnionKind {
117 EPUnused = 0, // unused
118 EPDir, // pointer direct
119 EPVec // pointer vector
123 * event infomation define
128 CicoEventInfo* d; // direct pointer
129 std::vector<CicoEventInfo*>* v; // vecter pointers
134 * start position define
137 E_SttUnionKind suk; // union kind
139 CicoStateCore* d; // direct pointer
140 std::vector<CicoStateCore*>* v; // vector pointers
148 CicoStateAction* dcsa; // direct pointer
149 int dav; // additional value
153 std::vector<CicoStateAction*>* vcsa; // vector pointers
154 std::vector<int>* vav; // vector additional values
158 E_SttUnionKind suk; // union kind
160 stDirSttAction d; // direct data
161 stVecSttAction v; // vector datas
165 // my area operations
166 void initTransition();
167 void initStartPosition();
168 void initSttAction();
170 void clearTransition();
171 void clearStartPosition();
172 void clearSttAction();
176 void setParent(CicoStateCore* parent);
177 friend void setParentF(CicoStateCore* stt, CicoStateCore* parent);
180 void addState(CicoStateCore* state);
181 friend void addStateF(CicoStateCore* parent, CicoStateCore* state);
184 void setFinishTransition(CicoStateCore* state);
187 void addTransition(const CicoEventInfo& evInf,
188 CicoStateCore* state);
191 void addInitState(CicoStateCore* state);
194 void addEntryAction(CicoStateAction* action, int addval);
197 void addExitAction(CicoStateAction* action, int addval);
200 void addDoAction(CicoStateAction* action, int addval);
203 void addAction(stSttAction& ssa, CicoStateAction* action,
207 void toActivate(const CicoEvent& ev);
208 friend void toActivateF(CicoStateCore* stt, const CicoEvent& ev);
211 void toDeactivate(const CicoEvent& ev);
212 friend void toDeactivateF(CicoStateCore* stt, const CicoEvent& ev);
215 void onEntry(const CicoEvent& ev);
216 void onExit(const CicoEvent& ev);
217 void onDo(const CicoEvent& ev);
218 void onEntryRun(CicoStateAction* run, const CicoEvent& ev, int val);
219 void onExitRun(CicoStateAction* run, const CicoEvent& ev, int val);
220 void onDoRun(CicoStateAction* run, const CicoEvent& ev, int val);
222 enum E_ActiveImpact {
223 Single = 0, // is Active
224 Follower // is Follower active
226 // get active state-objects
227 bool getActiveSonar(std::vector<CicoState*>& stt,
228 std::vector<E_ActiveImpact>& impact);
230 bool getActiveSonarChild(std::vector<CicoState*>& stt,
231 std::vector<E_ActiveImpact>& impact);
234 const CicoEventInfo* eventTest(const CicoEvent& ev,
235 const CicoStateCore* sm) const;
237 friend const CicoEventInfo* eventTestF(const CicoStateCore* stt,
239 const CicoStateCore* sm);
241 // start state-object Activation
242 virtual bool start(const CicoEvent& ev, bool parent = true);
243 friend bool startF(CicoStateCore* s, const CicoEvent& ev, bool parent);
245 // stop state-object Deactivation
246 virtual bool stop(const CicoEvent& ev);
249 virtual void holdHistory(); // Hold History
250 friend void holdHistoryF(CicoStateCore* s);
253 bool getCurrentState(std::vector<const CicoState*>& states,
255 const CicoState* getCurrentState(); //
256 friend bool getCurrentStateF(CicoStateCore* stt,
257 std::vector<const CicoState*>& states,
260 void getRegisteredInit(std::vector<CicoStateCore*>& stt, int& cnt);
263 void stateEnd(const CicoEvent& ev);
264 friend void stateEndF(CicoStateCore* stt, const CicoEvent& ev);
266 // The transition from s to d
267 void onTransition(const CicoEvent& ev, CicoStateCore* s, CicoStateCore* d);
270 void getRoots(const CicoStateCore* stt, std::vector<CicoStateCore*>& roots);
273 bool onDoExec(const CicoEvent& ev);
274 friend bool onDoExecF(CicoStateCore* s, const CicoEvent& ev);
277 const CicoStateCore* getState(const int value) const;
278 const CicoStateCore* getState(const std::string& name) const;
279 friend const CicoStateCore* getStateF(const CicoStateCore* s,
281 friend const CicoStateCore* getStateF(const CicoStateCore* s,
282 const std::string& name);
285 friend void getLogPartF(const CicoStateCore* s, std::string& l);
289 std::string m_name; // identification name
290 int m_value; // identification number
291 E_TOSO m_eType; // type my class
292 CicoStateCore* m_parent; // parent state object
293 std::vector<CicoStateCore*> m_childs; // Child state-objects
294 bool m_existHistoy; // flag History holder
295 CicoStateCore* m_stateTermination; //
297 stEventInfo m_eventInfo;
299 stStartPosition m_startPosition;
312 * @brief CicoStateCore::getName
313 * @ get state-object identification nemae
314 * @return state-object identification name
316 inline const std::string& CicoStateCore::getName() const
322 * @brief CicoStateCore::getValue
323 * @ get state-object identification number
324 * @return state-object identification number
326 inline int CicoStateCore::getValue() const
332 * @brief CicoStateCore::setValue
333 * @ set state-object identification number
334 * @paran value identification number
336 inline void CicoStateCore::setValue(int value)
342 * @brief CicoStateCore::getParent
343 * @return not 0:parent state-object pointer / 0:none parent
345 inline const CicoStateCore* CicoStateCore::getParent() const
347 return m_parent; // parent state object
351 * @brief CicoStateCore::getType
352 * @return type of state-object class
354 inline CicoStateCore::E_TOSO CicoStateCore::getType() const
360 * @brief CicoStateCore::isActive
361 * get active/notactive status
362 * @return active state true:active / false:not active
364 inline bool CicoStateCore::isActive() const
366 return m_activeState;
370 * @brief CicoStateCore::isStateMachine
371 * @return true:stateMachine-object
372 * @ false:none stateMachine-object
374 inline bool CicoStateCore::isStateMachine() const
376 if (EStateMachine == m_eType) {
383 * @brief CicoStateCore::isState
384 * @return true:state-object
385 * @ false:none state-object
387 inline bool CicoStateCore::isState() const
389 if (EState == m_eType) {
396 * @brief CicoStateCore::isFinalState
397 * @return true:finalState-object
398 * @ false:none finaltate-object
400 inline bool CicoStateCore::isFinalState() const
402 if (EFinalState == m_eType) {
409 * @brief CicoStateCore::isHistoryState
410 * @return true:historyState-object
411 * @ false:none historystate-object
413 inline bool CicoStateCore::isHistoryState() const
415 if (EHistoryState == m_eType) {
425 void getLogPartF(const CicoEvent& e, std::string& l);
432 void getLogPartF(const CicoEventInfo& e, std::string& l);
434 #endif // CICOSTATECORE_H