30#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
51#ifndef ETL_FSM_INCLUDED
52#define ETL_FSM_INCLUDED
60#include "message_router.h"
77#if !defined(ETL_FSM_STATE_ID_TYPE)
86#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION)
91 typename,
typename,
typename,
typename,
92 typename,
typename,
typename,
typename,
93 typename,
typename,
typename,
typename,
94 typename,
typename,
typename,
typename>
105 fsm_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
118 fsm_null_state_exception(string_type file_name_, numeric_type line_number_)
119 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:null state", ETL_FSM_FILE_ID
"A"), file_name_, line_number_)
131 fsm_state_id_exception(string_type file_name_, numeric_type line_number_)
132 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:state id", ETL_FSM_FILE_ID
"B"), file_name_, line_number_)
144 fsm_state_list_exception(string_type file_name_, numeric_type line_number_)
145 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:state list", ETL_FSM_FILE_ID
"C"), file_name_, line_number_)
157 fsm_state_list_order_exception(string_type file_name_, numeric_type line_number_)
158 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:state list order", ETL_FSM_FILE_ID
"D"), file_name_, line_number_)
169 fsm_not_started(string_type file_name_, numeric_type line_number_)
170 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:not started", ETL_FSM_FILE_ID
"F"), file_name_, line_number_)
182 fsm_reentrant_transition_forbidden(string_type file_name_, numeric_type line_number_)
183 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:reentrant calls to start/receive/etc. forbidden", ETL_FSM_FILE_ID
"G"), file_name_, line_number_)
188 namespace private_fsm
190 template <
typename T =
void>
200 static ETL_CONSTANT
fsm_state_id_t Pass_To_Parent = No_State_Change - 1U;
203 static ETL_CONSTANT
fsm_state_id_t Self_Transition = No_State_Change - 2U;
206 template <
typename T>
207 ETL_CONSTANT
fsm_state_id_t ifsm_state_helper<T>::No_State_Change;
209 template <
typename T>
212 template <
typename T>
213 ETL_CONSTANT
fsm_state_id_t ifsm_state_helper<T>::Self_Transition;
216 template <
size_t Id,
typename...>
struct check_ids : etl::true_type
220 template <
size_t Id,
typename TState0,
typename... TRest>
222 :
etl::integral_constant<bool, (TState0::STATE_ID == Id) && private_fsm::check_ids<Id + 1, TRest...>::value>
239 : is_locked(transition_guard_flag)
274 template <
typename... TStates>
281 ETL_STATIC_ASSERT((private_fsm::check_ids<0, TStates...>::value),
"State IDs must be 0..N-1 and in order");
282 ETL_STATIC_ASSERT(
sizeof...(TStates) > 0,
"At least one state is required");
283 ETL_STATIC_ASSERT(
sizeof...(TStates) < private_fsm::ifsm_state_helper<>::No_State_Change,
"State IDs mst be less than ifsm_state::No_State_Change");
288 static ETL_CONSTEXPR
size_t size()
290 return sizeof...(TStates);
296 template <
typename TState>
305 template <
typename TState>
306 const TState&
get()
const
316 etl::ifsm_state** get_state_list()
322 etl::tuple<TStates...> storage{};
344#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION)
346 friend class fsm_state;
349 typename,
typename,
typename,
typename,
350 typename,
typename,
typename,
typename,
351 typename,
typename,
typename,
typename,
352 typename,
typename,
typename,
typename>
371 state.p_parent =
this;
373 if (p_default_child == ETL_NULLPTR)
375 p_default_child = &state;
383 template <
typename TSize>
386 p_active_child = ETL_NULLPTR;
387 p_default_child = ETL_NULLPTR;
389 for (TSize i = 0; i <
size; ++i)
402 : state_id(state_id_),
403 p_context(ETL_NULLPTR),
404 p_parent(ETL_NULLPTR),
405 p_active_child(ETL_NULLPTR),
406 p_default_child(ETL_NULLPTR)
427 virtual fsm_state_id_t on_enter_state() {
return No_State_Change; }
428 virtual void on_exit_state() {}
431 void set_fsm_context(etl::fsm& context)
433 p_context = &context;
464 using imessage_router::receive;
469 fsm(etl::message_router_id_t
id)
470 : imessage_router(id)
471 , p_state(ETL_NULLPTR)
472 , state_list(ETL_NULLPTR)
473 , number_of_states(0U)
474 , is_processing_state_change(false)
482 template <
typename TSize>
485 state_list = p_states;
495 state_list[i]->set_fsm_context(*
this);
504 template <
typename... TStates>
505 void set_states(etl::fsm_state_pack<TStates...>& state_pack)
507 state_list = state_pack.get_state_list();
512 state_list[i]->set_fsm_context(*
this);
523 virtual void start(
bool call_on_enter_state =
true)
530 p_state = state_list[0];
533 if (call_on_enter_state)
540 p_last_state = p_state;
541 next_state_id = p_state->on_enter_state();
542 if (next_state_id != ifsm_state::No_State_Change)
545 p_state = state_list[next_state_id];
547 }
while (p_last_state != p_state);
563 process_state_change(next_state_id);
580 return process_state_change(new_state_id);
584 return ifsm_state::No_State_Change;
588 using imessage_router::accepts;
605 return p_state->get_state_id();
631 return p_state != ETL_NULLPTR;
638 virtual void reset(
bool call_on_exit_state =
false)
644 p_state->on_exit_state();
647 p_state = ETL_NULLPTR;
651 ETL_DEPRECATED
bool is_null_router() const ETL_OVERRIDE
657 bool is_producer() const ETL_OVERRIDE
663 bool is_consumer() const ETL_OVERRIDE
673 return (next_state_id != p_state->get_state_id()) &&
674 (next_state_id != ifsm_state::No_State_Change) &&
675 (next_state_id != ifsm_state::Self_Transition);
681 return (next_state_id == ifsm_state::Self_Transition);
689 if (is_self_transition(next_state_id))
691 p_state->on_exit_state();
692 next_state_id = p_state->on_enter_state();
695 if (have_changed_state(next_state_id))
697 ETL_ASSERT_OR_RETURN_VALUE(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception), p_state->get_state_id());
698 etl::ifsm_state* p_next_state = state_list[next_state_id];
702 p_state->on_exit_state();
703 p_state = p_next_state;
705 next_state_id = p_state->on_enter_state();
707 if (have_changed_state(next_state_id))
709 ETL_ASSERT_OR_RETURN_VALUE(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception), p_state->get_state_id());
710 p_next_state = state_list[next_state_id];
712 }
while (p_next_state != p_state);
715 return p_state->get_state_id();
718 etl::ifsm_state* p_state;
719 etl::ifsm_state** state_list;
721 bool is_processing_state_change;
727#if ETL_USING_CPP17 && !defined(ETL_FSM_FORCE_CPP03_IMPLEMENTATION)
731 template <
typename TContext,
typename TDerived,
etl::fsm_state_id_t STATE_ID_,
typename... TMessageTypes>
749 TContext& get_fsm_context()
const
751 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
768 const bool was_handled = (process_event_type<TMessageTypes>(message, new_state_id) || ...);
770 if (!was_handled || (new_state_id == Pass_To_Parent))
772 new_state_id = (p_parent !=
nullptr) ? p_parent->process_event(message) :
static_cast<TDerived*
>(
this)->on_event_unknown(message);
779 template <
typename TMessage>
782 if (TMessage::ID == msg.get_message_id())
784 new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const TMessage&
>(msg));
795 template <
typename TContext,
typename TDerived,
etl::fsm_state_id_t STATE_ID_,
typename... TMessageTypes>
806 typename T1 = void,
typename T2 = void,
typename T3 = void,
typename T4 = void,
807 typename T5 = void,
typename T6 = void,
typename T7 = void,
typename T8 = void,
808 typename T9 = void,
typename T10 = void,
typename T11 = void,
typename T12 = void,
809 typename T13 = void,
typename T14 = void,
typename T15 = void,
typename T16 =
void>
827 TContext& get_fsm_context()
const
829 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
841 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
842 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
843 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
844 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
845 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
846 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
847 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
848 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
849 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
850 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
851 case T11::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T11&
>(
message));
break;
852 case T12::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T12&
>(
message));
break;
853 case T13::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T13&
>(
message));
break;
854 case T14::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T14&
>(
message));
break;
855 case T15::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T15&
>(
message));
break;
856 case T16::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T16&
>(
message));
break;
857 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
860 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
868 typename T1,
typename T2,
typename T3,
typename T4,
869 typename T5,
typename T6,
typename T7,
typename T8,
870 typename T9,
typename T10,
typename T11,
typename T12,
871 typename T13,
typename T14,
typename T15>
872 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, void> :
public ifsm_state
889 TContext& get_fsm_context()
const
891 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
903 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
904 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
905 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
906 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
907 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
908 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
909 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
910 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
911 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
912 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
913 case T11::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T11&
>(
message));
break;
914 case T12::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T12&
>(
message));
break;
915 case T13::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T13&
>(
message));
break;
916 case T14::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T14&
>(
message));
break;
917 case T15::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T15&
>(
message));
break;
918 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
921 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
929 typename T1,
typename T2,
typename T3,
typename T4,
930 typename T5,
typename T6,
typename T7,
typename T8,
931 typename T9,
typename T10,
typename T11,
typename T12,
932 typename T13,
typename T14>
933 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, void, void> :
public ifsm_state
950 TContext& get_fsm_context()
const
952 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
964 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
965 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
966 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
967 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
968 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
969 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
970 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
971 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
972 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
973 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
974 case T11::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T11&
>(
message));
break;
975 case T12::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T12&
>(
message));
break;
976 case T13::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T13&
>(
message));
break;
977 case T14::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T14&
>(
message));
break;
978 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
981 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
989 typename T1,
typename T2,
typename T3,
typename T4,
990 typename T5,
typename T6,
typename T7,
typename T8,
991 typename T9,
typename T10,
typename T11,
typename T12,
993 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, void, void, void> :
public ifsm_state
1010 TContext& get_fsm_context()
const
1012 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1024 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1025 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1026 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1027 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1028 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1029 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1030 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1031 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
1032 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
1033 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
1034 case T11::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T11&
>(
message));
break;
1035 case T12::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T12&
>(
message));
break;
1036 case T13::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T13&
>(
message));
break;
1037 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1040 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1048 typename T1,
typename T2,
typename T3,
typename T4,
1049 typename T5,
typename T6,
typename T7,
typename T8,
1050 typename T9,
typename T10,
typename T11,
typename T12>
1051 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, void, void, void, void> :
public ifsm_state
1068 TContext& get_fsm_context()
const
1070 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1082 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1083 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1084 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1085 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1086 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1087 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1088 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1089 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
1090 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
1091 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
1092 case T11::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T11&
>(
message));
break;
1093 case T12::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T12&
>(
message));
break;
1094 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1097 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1105 typename T1,
typename T2,
typename T3,
typename T4,
1106 typename T5,
typename T6,
typename T7,
typename T8,
1107 typename T9,
typename T10,
typename T11>
1108 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, void, void, void, void, void> :
public ifsm_state
1125 TContext& get_fsm_context()
const
1127 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1139 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1140 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1141 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1142 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1143 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1144 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1145 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1146 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
1147 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
1148 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
1149 case T11::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T11&
>(
message));
break;
1150 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1153 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1161 typename T1,
typename T2,
typename T3,
typename T4,
1162 typename T5,
typename T6,
typename T7,
typename T8,
1163 typename T9,
typename T10>
1164 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, void, void, void, void, void, void> :
public ifsm_state
1181 TContext& get_fsm_context()
const
1183 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1195 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1196 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1197 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1198 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1199 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1200 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1201 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1202 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
1203 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
1204 case T10::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T10&
>(
message));
break;
1205 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1208 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1216 typename T1,
typename T2,
typename T3,
typename T4,
1217 typename T5,
typename T6,
typename T7,
typename T8,
1219 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, void, void, void, void, void, void, void> :
public ifsm_state
1236 TContext& get_fsm_context()
const
1238 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1250 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1251 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1252 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1253 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1254 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1255 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1256 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1257 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
1258 case T9::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T9&
>(
message));
break;
1259 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1262 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1270 typename T1,
typename T2,
typename T3,
typename T4,
1271 typename T5,
typename T6,
typename T7,
typename T8>
1272 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, void, void, void, void, void, void, void, void> :
public ifsm_state
1289 TContext& get_fsm_context()
const
1291 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1303 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1304 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1305 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1306 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1307 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1308 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1309 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1310 case T8::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T8&
>(
message));
break;
1311 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1314 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1322 typename T1,
typename T2,
typename T3,
typename T4,
1323 typename T5,
typename T6,
typename T7>
1324 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1341 TContext& get_fsm_context()
const
1343 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1355 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1356 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1357 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1358 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1359 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1360 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1361 case T7::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T7&
>(
message));
break;
1362 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1365 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1373 typename T1,
typename T2,
typename T3,
typename T4,
1374 typename T5,
typename T6>
1375 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1392 TContext& get_fsm_context()
const
1394 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1406 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1407 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1408 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1409 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1410 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1411 case T6::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T6&
>(
message));
break;
1412 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1415 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1423 typename T1,
typename T2,
typename T3,
typename T4,
1425 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, void, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1442 TContext& get_fsm_context()
const
1444 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1456 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1457 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1458 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1459 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1460 case T5::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T5&
>(
message));
break;
1461 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1464 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1472 typename T1,
typename T2,
typename T3,
typename T4>
1473 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, void, void, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1490 TContext& get_fsm_context()
const
1492 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1504 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1505 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1506 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1507 case T4::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T4&
>(
message));
break;
1508 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1511 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1519 typename T1,
typename T2,
typename T3>
1520 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, void, void, void, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1537 TContext& get_fsm_context()
const
1539 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1551 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1552 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1553 case T3::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T3&
>(
message));
break;
1554 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1557 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1565 typename T1,
typename T2>
1566 class fsm_state<TContext, TDerived, STATE_ID_, T1, T2, void, void, void, void, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1583 TContext& get_fsm_context()
const
1585 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1597 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1598 case T2::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T2&
>(
message));
break;
1599 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1602 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1611 class fsm_state<TContext, TDerived, STATE_ID_, T1, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1628 TContext& get_fsm_context()
const
1630 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1642 case T1::ID: new_state_id =
static_cast<TDerived*
>(
this)->on_event(
static_cast<const T1&
>(
message));
break;
1643 default: new_state_id = p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
break;
1646 return (new_state_id != Pass_To_Parent) ? new_state_id : (p_parent ? p_parent->process_event(
message) : No_State_Change);
1653 template <
typename TContext,
typename TDerived, etl::fsm_state_
id_t STATE_ID_>
1654 class fsm_state<TContext, TDerived, STATE_ID_, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void, void> :
public ifsm_state
1671 TContext& get_fsm_context()
const
1673 return static_cast<TContext&
>(ifsm_state::get_fsm_context());
1679 return p_parent ? p_parent->process_event(
message) :
static_cast<TDerived*
>(
this)->on_event_unknown(
message);
1684 typename T1,
typename T2,
typename T3,
typename T4,
1685 typename T5,
typename T6,
typename T7,
typename T8,
1686 typename T9,
typename T10,
typename T11,
typename T12,
1687 typename T13,
typename T14,
typename T15,
typename T16>
1688 ETL_CONSTANT
etl::fsm_state_id_t fsm_state<TContext, TDerived, STATE_ID_, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::STATE_ID;
Base exception class for FSM.
Definition fsm.h:102
Exception for message received but not started.
Definition fsm.h:167
Exception for null state pointer.
Definition fsm.h:115
Exception for call to receive/start/etc. while receive/start/etc. is already happening....
Definition fsm.h:180
Exception for invalid state id.
Definition fsm.h:128
Exception for incompatible state list.
Definition fsm.h:141
Exception for incompatible order state list.
Definition fsm.h:154
The FSM class.
Definition fsm.h:460
etl::fsm_state_id_t get_state_id() const
Gets the current state id.
Definition fsm.h:602
void receive(const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition fsm.h:555
virtual void start(bool call_on_enter_state=true)
Definition fsm.h:523
fsm(etl::message_router_id_t id)
Constructor.
Definition fsm.h:469
virtual void reset(bool call_on_exit_state=false)
Definition fsm.h:638
bool accepts(etl::message_id_t) const ETL_OVERRIDE
Definition fsm.h:594
etl::fsm_state_id_t transition_to(etl::fsm_state_id_t new_state_id)
Invoke a state transition.
Definition fsm.h:574
void set_states(etl::ifsm_state **p_states, TSize size)
Definition fsm.h:483
const ifsm_state & get_state() const
Gets a const reference to the current state interface.
Definition fsm.h:620
ifsm_state & get_state()
Gets a reference to the current state interface.
Definition fsm.h:611
bool is_started() const
Checks if the FSM has been started.
Definition fsm.h:629
Interface class for FSM states.
Definition fsm.h:333
void add_child_state(etl::ifsm_state &state)
Definition fsm.h:368
void set_child_states(etl::ifsm_state **state_list, TSize size)
Definition fsm.h:384
etl::fsm_state_id_t get_state_id() const
Gets the id for this state.
Definition fsm.h:359
ifsm_state(etl::fsm_state_id_t state_id_)
Constructor.
Definition fsm.h:401
virtual ~ifsm_state()
Destructor.
Definition fsm.h:413
friend class etl::fsm
Allows ifsm_state functions to be private.
Definition fsm.h:337
This is the base of all message routers.
Definition message_router_generator.h:121
RAII detection mechanism to catch reentrant calls to methods that might transition the state machine ...
Definition fsm.h:232
~fsm_reentrancy_guard() ETL_NOEXCEPT
Definition fsm.h:249
fsm_reentrancy_guard(bool &transition_guard_flag)
Definition fsm.h:238
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
Definition integral_limits.h:516
Defines a type that is as larger or larger than the specified type. Will return the specified type is...
Definition largest_generator.h:352
integral_constant
Definition type_traits_generator.h:895
bitset_ext
Definition absolute.h:39
uint_least8_t message_id_t
Allow alternative type for message id.
Definition message_types.h:40
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
T & get(array< T, Size > &a)
Definition array.h:1216
uint_least8_t fsm_state_id_t
Allow alternative type for state id.
Definition fsm.h:78