Skip to content

Commit

Permalink
Fix non trivial exit processing
Browse files Browse the repository at this point in the history
exit events where sometimes called 2 times due to the fact that they
always returned false.
This was always triggering process_internal_generic_event in
include/boost/sml/back/state_machine.hpp line 190.

Change implementation to have a behavior similar to the on_entry events
but with reversed logic, bottom to top instead of top to bottom
  • Loading branch information
Guilhem Codron authored and kris-jusiak committed Jul 31, 2020
1 parent 3f9554d commit 3737aca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
17 changes: 7 additions & 10 deletions include/boost/sml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,18 +856,8 @@ template <class T>
struct transitions<T> {
template <class TEvent, class SM, class TDeps, class TSubs>
static bool execute(const TEvent &event, SM &sm, TDeps &deps, TSubs &subs, typename SM::state_t &current_state) {
return execute_impl(event, sm, deps, subs, current_state);
}
template <class TEvent, class SM, class TDeps, class TSubs>
static bool execute_impl(const TEvent &event, SM &sm, TDeps &deps, TSubs &subs, typename SM::state_t &current_state) {
return aux::get<T>(sm.transitions_).execute(event, sm, deps, subs, current_state, typename SM::has_entry_exits{});
}
template <class _, class TEvent, class SM, class TDeps, class TSubs>
static bool execute_impl(const on_exit<_, TEvent> &event, SM &sm, TDeps &deps, TSubs &subs,
typename SM::state_t &current_state) {
aux::get<T>(sm.transitions_).execute(event, sm, deps, subs, current_state, typename SM::has_entry_exits{});
return false;
}
};
template <>
struct transitions<aux::true_type> {
Expand Down Expand Up @@ -910,6 +900,13 @@ struct transitions_sub<sm<TSM>, T, Ts...> {
sub_sm<sm_impl<TSM>>::get(&subs).process_event(event, deps, subs);
return true;
}
template <class _, class TEvent, class SM, class TDeps, class TSubs>
static bool execute_impl(const back::on_exit<_, TEvent> &event, SM &sm, TDeps &deps, TSubs &subs,
typename SM::state_t &current_state) {
sub_sm<sm_impl<TSM>>::get(&subs).process_event(event, deps, subs);
transitions<T, Ts...>::execute(event, sm, deps, subs, current_state);
return true;
}
};
template <class TSM>
struct transitions_sub<sm<TSM>> {
Expand Down
20 changes: 8 additions & 12 deletions include/boost/sml/back/transitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,8 @@ template <class T>
struct transitions<T> {
template <class TEvent, class SM, class TDeps, class TSubs>
static bool execute(const TEvent& event, SM& sm, TDeps& deps, TSubs& subs, typename SM::state_t& current_state) {
return execute_impl(event, sm, deps, subs, current_state);
}

template <class TEvent, class SM, class TDeps, class TSubs>
static bool execute_impl(const TEvent& event, SM& sm, TDeps& deps, TSubs& subs, typename SM::state_t& current_state) {
return aux::get<T>(sm.transitions_).execute(event, sm, deps, subs, current_state, typename SM::has_entry_exits{});
}

template <class _, class TEvent, class SM, class TDeps, class TSubs>
static bool execute_impl(const on_exit<_, TEvent>& event, SM& sm, TDeps& deps, TSubs& subs,
typename SM::state_t& current_state) {
aux::get<T>(sm.transitions_).execute(event, sm, deps, subs, current_state, typename SM::has_entry_exits{});
return false; // from bottom to top
}
};

template <>
Expand Down Expand Up @@ -102,6 +90,14 @@ struct transitions_sub<sm<TSM>, T, Ts...> {
sub_sm<sm_impl<TSM>>::get(&subs).process_event(event, deps, subs);
return true; // from top to bottom
}

template <class _, class TEvent, class SM, class TDeps, class TSubs>
static bool execute_impl(const back::on_exit<_, TEvent>& event, SM& sm, TDeps& deps, TSubs& subs,
typename SM::state_t& current_state) {
sub_sm<sm_impl<TSM>>::get(&subs).process_event(event, deps, subs);
transitions<T, Ts...>::execute(event, sm, deps, subs, current_state);
return true; // from bottom to top
}
};

/// @brief Event executor on a sub state machine without transition in parent state machine.
Expand Down

0 comments on commit 3737aca

Please sign in to comment.