This library is designed to create and run state graphs. It supports hierarchical states and parallel states execution.

Committer:
martin13
Date:
Tue Feb 02 20:47:45 2021 +0000
Revision:
4:22b4462fcb26
Parent:
0:f4fdca2c4c67
Added unittests

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martin13 0:f4fdca2c4c67 1 ////////////////////////////////////////////////////////////////////////////////
martin13 0:f4fdca2c4c67 2 // Copyright Rottor SAS 2017
martin13 0:f4fdca2c4c67 3 // All rigths reserved.
martin13 0:f4fdca2c4c67 4 //
martin13 0:f4fdca2c4c67 5 // File Name : State.cpp
martin13 0:f4fdca2c4c67 6 // Authors : Martin Matignon
martin13 0:f4fdca2c4c67 7 //
martin13 0:f4fdca2c4c67 8 // If you find any bug or if you have any question please contact
martin13 0:f4fdca2c4c67 9 // Martin Matignon <martin.matignon@rottor.fr>
martin13 0:f4fdca2c4c67 10 // Nicolas Forestier <nicolas.forestier@rottor.fr>
martin13 0:f4fdca2c4c67 11 //
martin13 0:f4fdca2c4c67 12 ////////////////////////////////////////////////////////////////////////////////
martin13 0:f4fdca2c4c67 13
martin13 0:f4fdca2c4c67 14 #include "State.h"
martin13 0:f4fdca2c4c67 15
martin13 0:f4fdca2c4c67 16 bool preempt_flag = false;
martin13 0:f4fdca2c4c67 17
martin13 0:f4fdca2c4c67 18 const char* State::SUCCEDED = "SUCCEDED";
martin13 0:f4fdca2c4c67 19 const char* State::ABORTED = "ABORTED";
martin13 0:f4fdca2c4c67 20 const char* State::PREEMPTED = "PREEMPTED";
martin13 0:f4fdca2c4c67 21
martin13 0:f4fdca2c4c67 22 State::State(const char* uuid,
martin13 0:f4fdca2c4c67 23 StateType_t type):
martin13 0:f4fdca2c4c67 24 m_uuid(uuid),
martin13 0:f4fdca2c4c67 25 m_type(type),
martin13 0:f4fdca2c4c67 26 m_preempt(false),
martin13 0:f4fdca2c4c67 27 m_outcome(NULL)
martin13 0:f4fdca2c4c67 28 {
martin13 0:f4fdca2c4c67 29 /* Empty */
martin13 0:f4fdca2c4c67 30 }
martin13 0:f4fdca2c4c67 31
martin13 0:f4fdca2c4c67 32 void State::setUUID(const char* uuid){
martin13 0:f4fdca2c4c67 33 m_uuid = uuid;
martin13 0:f4fdca2c4c67 34 }
martin13 0:f4fdca2c4c67 35
martin13 0:f4fdca2c4c67 36 const char* State::getUUID(){
martin13 0:f4fdca2c4c67 37 return m_uuid;
martin13 0:f4fdca2c4c67 38 }
martin13 0:f4fdca2c4c67 39
martin13 0:f4fdca2c4c67 40 void State::setType(State::StateType_t type){
martin13 0:f4fdca2c4c67 41 m_type = type;
martin13 0:f4fdca2c4c67 42 }
martin13 0:f4fdca2c4c67 43
martin13 0:f4fdca2c4c67 44 State::StateType_t State::getType(){
martin13 0:f4fdca2c4c67 45 return m_type;
martin13 0:f4fdca2c4c67 46 }
martin13 0:f4fdca2c4c67 47
martin13 0:f4fdca2c4c67 48 void State::_onParallelExecute(){
martin13 0:f4fdca2c4c67 49 m_outcome = onExecute();
martin13 0:f4fdca2c4c67 50 }
martin13 0:f4fdca2c4c67 51
martin13 0:f4fdca2c4c67 52 const char* State::getOutcome(){
martin13 0:f4fdca2c4c67 53 return m_outcome;
martin13 0:f4fdca2c4c67 54 }
martin13 0:f4fdca2c4c67 55
martin13 0:f4fdca2c4c67 56 void State::preempt(){
martin13 0:f4fdca2c4c67 57 preempt_flag = true;
martin13 0:f4fdca2c4c67 58 }
martin13 0:f4fdca2c4c67 59
martin13 0:f4fdca2c4c67 60 bool State::isPreempted(){
martin13 0:f4fdca2c4c67 61 return preempt_flag;
martin13 0:f4fdca2c4c67 62 }