Skip to content

Commit

Permalink
Updated generator headers
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Apr 16, 2024
1 parent ea9d5b0 commit 754eba9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 31 deletions.
55 changes: 37 additions & 18 deletions include/etl/generators/fsm_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ namespace etl
}
};

//***************************************************************************
/// Exception for message received but not started.
//***************************************************************************
class fsm_not_started : public etl::fsm_exception
{
public:
fsm_not_started(string_type file_name_, numeric_type line_number_)
: etl::fsm_exception(ETL_ERROR_TEXT("fsm:not started", ETL_FSM_FILE_ID"F"), file_name_, line_number_)
{
}
};

namespace private_fsm
{
template <typename T = void>
Expand Down Expand Up @@ -430,31 +442,38 @@ namespace etl
//*******************************************
void receive(const etl::imessage& message) ETL_OVERRIDE
{
etl::fsm_state_id_t next_state_id = p_state->process_event(message);

if (have_changed_state(next_state_id))
if (is_started())
{
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::fsm_state_id_t next_state_id = p_state->process_event(message);

do
if (have_changed_state(next_state_id))
{
p_state->on_exit_state();
p_state = p_next_state;

next_state_id = p_state->on_enter_state();
ETL_ASSERT_OR_RETURN(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
etl::ifsm_state* p_next_state = state_list[next_state_id];

if (have_changed_state(next_state_id))
do
{
ETL_ASSERT(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
p_next_state = state_list[next_state_id];
}
} while (p_next_state != p_state); // Have we changed state again?
p_state->on_exit_state();
p_state = p_next_state;

next_state_id = p_state->on_enter_state();

if (have_changed_state(next_state_id))
{
ETL_ASSERT_OR_RETURN(next_state_id < number_of_states, ETL_ERROR(etl::fsm_state_id_exception));
p_next_state = state_list[next_state_id];
}
} while (p_next_state != p_state); // Have we changed state again?
}
else if (is_self_transition(next_state_id))
{
p_state->on_exit_state();
p_state->on_enter_state();
}
}
else if (is_self_transition(next_state_id))
else
{
p_state->on_exit_state();
p_state->on_enter_state();
ETL_ASSERT_FAIL(ETL_ERROR(etl::fsm_not_started));
}
}

Expand Down
40 changes: 30 additions & 10 deletions include/etl/generators/message_router_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,40 +354,60 @@ namespace etl
}
};

//***************************************************************************
/// Is T ultimately derived from etl::imessage_router?
//***************************************************************************
template <typename T>
struct is_message_router : public etl::bool_constant<etl::is_base_of<etl::imessage_router, typename etl::remove_cvref<T>::type>::value>
{
};

//***************************************************************************
/// Send a message to a router.
//***************************************************************************
static inline void send_message(etl::imessage_router& destination,
const etl::imessage& message)
template <typename TRouter, typename TMessage>
static
typename etl::enable_if<etl::is_message_router<TRouter>::value && etl::is_message<TMessage>::value, void>::type
send_message(TRouter& destination,
const TMessage& message)
{
destination.receive(message);
}

//***************************************************************************
/// Send a shared message to a router.
//***************************************************************************
static inline void send_message(etl::imessage_router& destination,
etl::shared_message message)
template <typename TRouter>
static
typename etl::enable_if<etl::is_message_router<TRouter>::value, void>::type
send_message(TRouter& destination,
etl::shared_message message)
{
destination.receive(message);
}

//***************************************************************************
/// Send a message to a router with a particular id.
//***************************************************************************
static inline void send_message(etl::imessage_router& destination,
etl::message_router_id_t id,
const etl::imessage& message)
template <typename TRouter, typename TMessage>
static
typename etl::enable_if<etl::is_message_router<TRouter>::value && etl::is_message<TMessage>::value, void>::type
send_message(TRouter& destination,
etl::message_router_id_t id,
const TMessage& message)
{
destination.receive(id, message);
}

//***************************************************************************
/// Send a shared message to a router with a particular id.
//***************************************************************************
static inline void send_message(etl::imessage_router& destination,
etl::message_router_id_t id,
etl::shared_message message)
template <typename TRouter>
static
typename etl::enable_if<etl::is_message_router<TRouter>::value, void>::type
send_message(TRouter& destination,
etl::message_router_id_t id,
etl::shared_message message)
{
destination.receive(id, message);
}
Expand Down
6 changes: 3 additions & 3 deletions include/etl/message_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ namespace etl
/// Send a message to a router.
//***************************************************************************
template <typename TRouter, typename TMessage>
static
static
typename etl::enable_if<etl::is_message_router<TRouter>::value && etl::is_message<TMessage>::value, void>::type
send_message(TRouter& destination,
const TMessage& message)
Expand All @@ -366,7 +366,7 @@ namespace etl
/// Send a shared message to a router.
//***************************************************************************
template <typename TRouter>
static
static
typename etl::enable_if<etl::is_message_router<TRouter>::value, void>::type
send_message(TRouter& destination,
etl::shared_message message)
Expand All @@ -378,7 +378,7 @@ namespace etl
/// Send a message to a router with a particular id.
//***************************************************************************
template <typename TRouter, typename TMessage>
static
static
typename etl::enable_if<etl::is_message_router<TRouter>::value && etl::is_message<TMessage>::value, void>::type
send_message(TRouter& destination,
etl::message_router_id_t id,
Expand Down

0 comments on commit 754eba9

Please sign in to comment.