mirror of
https://github.com/ETLCPP/etl.git
synced 2026-11-09 14:49:53 +08:00
Added flag to call on_enter_state on start. Default true.
This commit is contained in:
parent
bf16ee4f5c
commit
fb2d2e96f6
@ -242,17 +242,26 @@ namespace etl
|
||||
//*******************************************
|
||||
void start(bool call_on_enter_state = true)
|
||||
{
|
||||
// Can only be started once.
|
||||
if (p_state == nullptr)
|
||||
{
|
||||
p_state = state_list[0];
|
||||
ETL_ASSERT(p_state != nullptr, ETL_ERROR(etl::fsm_null_state_exception));
|
||||
// Can only be started once.
|
||||
if (p_state == nullptr)
|
||||
{
|
||||
p_state = state_list[0];
|
||||
ETL_ASSERT(p_state != nullptr, ETL_ERROR(etl::fsm_null_state_exception));
|
||||
|
||||
if (call_on_enter_state)
|
||||
{
|
||||
p_state->on_enter_state();
|
||||
}
|
||||
}
|
||||
if (call_on_enter_state)
|
||||
{
|
||||
etl::fsm_state_id_t next_state_id;
|
||||
etl::ifsm_state* p_last_state;
|
||||
|
||||
do
|
||||
{
|
||||
p_last_state = p_state;
|
||||
next_state_id = p_state->on_enter_state();
|
||||
p_state = state_list[next_state_id];
|
||||
|
||||
} while (p_last_state != p_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
@ -260,7 +269,7 @@ namespace etl
|
||||
//*******************************************
|
||||
void receive(const etl::imessage& message)
|
||||
{
|
||||
etl::null_message_router nmr;
|
||||
static etl::null_message_router nmr;
|
||||
receive(nmr, message);
|
||||
}
|
||||
|
||||
@ -269,26 +278,26 @@ namespace etl
|
||||
//*******************************************
|
||||
void receive(etl::imessage_router& source, const etl::imessage& message)
|
||||
{
|
||||
etl::fsm_state_id_t next_state_id = p_state->process_event(source, message);
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
etl::fsm_state_id_t next_state_id = p_state->process_event(source, message);
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
|
||||
etl::ifsm_state* p_next_state = state_list[next_state_id];
|
||||
etl::ifsm_state* p_next_state = state_list[next_state_id];
|
||||
|
||||
// Have we changed state?
|
||||
if (p_next_state != p_state)
|
||||
{
|
||||
do
|
||||
// Have we changed state?
|
||||
if (p_next_state != p_state)
|
||||
{
|
||||
p_state->on_exit_state();
|
||||
p_state = p_next_state;
|
||||
do
|
||||
{
|
||||
p_state->on_exit_state();
|
||||
p_state = p_next_state;
|
||||
|
||||
next_state_id = p_state->on_enter_state();
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
next_state_id = p_state->on_enter_state();
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
|
||||
p_next_state = state_list[next_state_id];
|
||||
p_next_state = state_list[next_state_id];
|
||||
|
||||
} while (p_next_state != p_state); // Have we changed state again?
|
||||
}
|
||||
} while (p_next_state != p_state); // Have we changed state again?
|
||||
}
|
||||
}
|
||||
|
||||
using imessage_router::accepts;
|
||||
|
||||
@ -254,17 +254,26 @@ namespace etl
|
||||
//*******************************************
|
||||
void start(bool call_on_enter_state = true)
|
||||
{
|
||||
// Can only be started once.
|
||||
if (p_state == nullptr)
|
||||
{
|
||||
p_state = state_list[0];
|
||||
ETL_ASSERT(p_state != nullptr, ETL_ERROR(etl::fsm_null_state_exception));
|
||||
// Can only be started once.
|
||||
if (p_state == nullptr)
|
||||
{
|
||||
p_state = state_list[0];
|
||||
ETL_ASSERT(p_state != nullptr, ETL_ERROR(etl::fsm_null_state_exception));
|
||||
|
||||
if (call_on_enter_state)
|
||||
{
|
||||
p_state->on_enter_state();
|
||||
}
|
||||
}
|
||||
if (call_on_enter_state)
|
||||
{
|
||||
etl::fsm_state_id_t next_state_id;
|
||||
etl::ifsm_state* p_last_state;
|
||||
|
||||
do
|
||||
{
|
||||
p_last_state = p_state;
|
||||
next_state_id = p_state->on_enter_state();
|
||||
p_state = state_list[next_state_id];
|
||||
|
||||
} while (p_last_state != p_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
@ -272,7 +281,7 @@ namespace etl
|
||||
//*******************************************
|
||||
void receive(const etl::imessage& message)
|
||||
{
|
||||
etl::null_message_router nmr;
|
||||
static etl::null_message_router nmr;
|
||||
receive(nmr, message);
|
||||
}
|
||||
|
||||
@ -281,26 +290,26 @@ namespace etl
|
||||
//*******************************************
|
||||
void receive(etl::imessage_router& source, const etl::imessage& message)
|
||||
{
|
||||
etl::fsm_state_id_t next_state_id = p_state->process_event(source, message);
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
etl::fsm_state_id_t next_state_id = p_state->process_event(source, message);
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
|
||||
etl::ifsm_state* p_next_state = state_list[next_state_id];
|
||||
etl::ifsm_state* p_next_state = state_list[next_state_id];
|
||||
|
||||
// Have we changed state?
|
||||
if (p_next_state != p_state)
|
||||
{
|
||||
do
|
||||
// Have we changed state?
|
||||
if (p_next_state != p_state)
|
||||
{
|
||||
p_state->on_exit_state();
|
||||
p_state = p_next_state;
|
||||
do
|
||||
{
|
||||
p_state->on_exit_state();
|
||||
p_state = p_next_state;
|
||||
|
||||
next_state_id = p_state->on_enter_state();
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
next_state_id = p_state->on_enter_state();
|
||||
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
|
||||
|
||||
p_next_state = state_list[next_state_id];
|
||||
p_next_state = state_list[next_state_id];
|
||||
|
||||
} while (p_next_state != p_state); // Have we changed state again?
|
||||
}
|
||||
} while (p_next_state != p_state); // Have we changed state again?
|
||||
}
|
||||
}
|
||||
|
||||
using imessage_router::accepts;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user