34 #error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
63 #ifndef ETL_FSM_INCLUDED
64 #define ETL_FSM_INCLUDED
74 #include "message_router.h"
88 #if !defined(ETL_FSM_STATE_ID_TYPE)
104 fsm_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
117 fsm_null_state_exception(string_type file_name_, numeric_type line_number_)
118 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:null state", ETL_FILE
"A"), file_name_, line_number_)
130 fsm_state_id_exception(string_type file_name_, numeric_type line_number_)
131 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:state id", ETL_FILE
"B"), file_name_, line_number_)
143 fsm_state_list_exception(string_type file_name_, numeric_type line_number_)
144 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:state list", ETL_FILE
"C"), file_name_, line_number_)
156 fsm_state_list_order_exception(string_type file_name_, numeric_type line_number_)
157 :
etl::fsm_exception(ETL_ERROR_TEXT(
"fsm:state list order", ETL_FILE
"D"), file_name_, line_number_)
186 : state_id(state_id_),
187 p_context(ETL_NULLPTR)
199 inline etl::fsm& get_fsm_context()
const
209 virtual void on_exit_state() {}
212 void set_fsm_context(
etl::fsm& context)
214 p_context = &context;
238 fsm(etl::message_router_id_t
id)
247 template <
typename TSize>
250 state_list = p_states;
259 state_list[i]->set_fsm_context(*
this);
269 void start(
bool call_on_enter_state =
true)
272 if (p_state == ETL_NULLPTR)
274 p_state = state_list[0];
277 if (call_on_enter_state)
284 p_last_state = p_state;
285 next_state_id = p_state->on_enter_state();
286 p_state = state_list[next_state_id];
288 }
while (p_last_state != p_state);
307 if ((destination_router_id == get_message_router_id()) || (destination_router_id == imessage_router::ALL_MESSAGE_ROUTERS))
324 if (p_next_state != p_state)
328 p_state->on_exit_state();
329 p_state = p_next_state;
331 next_state_id = p_state->on_enter_state();
334 p_next_state = state_list[next_state_id];
336 }
while (p_next_state != p_state);
340 using imessage_router::accepts;
383 return p_state != ETL_NULLPTR;
390 void reset(
bool call_on_exit_state =
false)
392 if ((p_state != ETL_NULLPTR) && call_on_exit_state)
394 p_state->on_exit_state();
397 p_state = ETL_NULLPTR;
401 ETL_DEPRECATED
bool is_null_router() const ETL_OVERRIDE
407 bool is_producer() const ETL_OVERRIDE
413 bool is_consumer() const ETL_OVERRIDE
Base exception class for FSM.
Definition: fsm.h:89
Exception for null state pointer.
Definition: fsm.h:102
Exception for invalid state id.
Definition: fsm.h:115
Exception for incompatible state list.
Definition: fsm.h:128
Exception for incompatible order state list.
Definition: fsm.h:141
The FSM class.
Definition: fsm.h:220
etl::fsm_state_id_t get_state_id() const
Gets the current state id.
Definition: fsm.h:342
void receive(const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition: fsm_generator.h:296
fsm(etl::message_router_id_t id)
Constructor.
Definition: fsm_generator.h:238
bool accepts(etl::message_id_t) const ETL_OVERRIDE
Does this FSM accept the message id? Yes, it accepts everything!
Definition: fsm_generator.h:346
void reset(bool call_on_exit_state=false)
Reset the FSM to pre-started state.
Definition: fsm_generator.h:390
ifsm_state & get_state()
Gets a reference to the current state interface.
Definition: fsm_generator.h:363
void set_states(etl::ifsm_state **p_states, TSize size)
Set the states for the FSM.
Definition: fsm_generator.h:248
const ifsm_state & get_state() const
Gets a const reference to the current state interface.
Definition: fsm_generator.h:372
void receive(etl::imessage_router &source, const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition: fsm_generator.h:316
void start(bool call_on_enter_state=true)
Starts the FSM. Can only be called once. Subsequent calls will do nothing.
Definition: fsm_generator.h:269
void receive(imessage_router &source, etl::message_router_id_t destination_router_id, const etl::imessage &message) ETL_OVERRIDE
Top level message handler for the FSM.
Definition: fsm_generator.h:305
bool is_started() const
Checks if the FSM has been started.
Definition: fsm_generator.h:381
Interface class for FSM states.
Definition: fsm.h:154
~ifsm_state()
Destructor.
Definition: fsm_generator.h:194
etl::fsm_state_id_t get_state_id() const
Gets the id for this state.
Definition: fsm_generator.h:175
ifsm_state(etl::fsm_state_id_t state_id_)
Constructor.
Definition: fsm_generator.h:185
This is the base of all message routers.
Definition: message_router_generator.h:114
This router can be used as a sink for messages or a 'null source' router.
Definition: message_router_generator.h:194
#define ETL_ASSERT(b, e)
Definition: error_handler.h:290
exception(string_type reason_, string_type file_, numeric_type line_)
Constructor.
Definition: exception.h:67
Definition: exception.h:47
Defines a type that is as larger or larger than the specified type. Will return the specified type is...
Definition: largest_generator.h:352
Definition: absolute.h:37
uint_least8_t message_id_t
Allow alternative type for message id.
Definition: message_types.h:40
uint_least8_t fsm_state_id_t
Allow alternative type for state id.
Definition: fsm.h:73