From dd377becaa98c4c1ac1a717c80aff769a53c845f Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Thu, 2 Apr 2020 14:10:37 +0100 Subject: [PATCH] small fixes in state transitions --- lib/include/srslte/common/choice_type.h | 2 +- lib/include/srslte/common/fsm.h | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/include/srslte/common/choice_type.h b/lib/include/srslte/common/choice_type.h index 514b00002..8be6b0b95 100644 --- a/lib/include/srslte/common/choice_type.h +++ b/lib/include/srslte/common/choice_type.h @@ -217,8 +217,8 @@ struct tagged_union_t using U2 = typename std::decay::type; static_assert(type_indexer::index != invalid_idx, "The provided type to ctor is not part of the list of possible types"); - new (get_buffer()) U2(std::forward(args)...); type_id = type_indexer::index; + new (get_buffer()) U2(std::forward(args)...); } template diff --git a/lib/include/srslte/common/fsm.h b/lib/include/srslte/common/fsm.h index 50ef90f2c..fbaf7a2a5 100644 --- a/lib/include/srslte/common/fsm.h +++ b/lib/include/srslte/common/fsm.h @@ -107,9 +107,8 @@ struct fsm_helper { static_assert(FSM::is_nested, "State is not present in the FSM list of valid states"); if (p != nullptr) { srslte::get(f->states).exit(); - p = nullptr; } - handle_state_change(f->parent_fsm()->derived(), s, p); + handle_state_change(f->parent_fsm()->derived(), s, static_cast(f)); } //! Trigger Event, that will result in a state transition @@ -132,20 +131,25 @@ struct fsm_helper { template auto call_trigger(State* current_state) -> NextState { - using next_state = NextState; - static_assert(not std::is_same::value, "State cannot transition to itself.\n"); + static_assert(not std::is_same, State>::value, "State cannot transition to itself.\n"); auto target_state = f->react(*current_state, std::move(ev)); fsm_helper::handle_state_change(f, &target_state, current_state); return target_state; } + //! No react method found. Try forward trigger to HSM + template + void call_trigger(State* current_state, Args&&... args) + { + call_trigger2(current_state); + } //! In case a react(CurrentState&, Event) method is not found, but we are in a NestedFSM with a trigger method template - auto call_trigger(State* s) -> decltype(std::declval().trigger(std::declval())) + auto call_trigger2(State* s) -> decltype(std::declval().trigger(std::declval())) { s->trigger(std::move(ev)); } //! No trigger or react method found. Do nothing - void call_trigger(...) {} + void call_trigger2(...) {} FSM* f; Event ev; @@ -173,6 +177,7 @@ protected: class derived_view : public Derived { public: + using derived_t = Derived; using Derived::react; using Derived::states; }; @@ -225,10 +230,9 @@ protected: template class nested_fsm_t : public fsm_t { - using base_t = fsm_t; - using parent_t = ParentFSM; - public: + using base_t = nested_fsm_t; + using parent_t = ParentFSM; static const bool is_nested = true; explicit nested_fsm_t(ParentFSM* parent_fsm_) : fsm_ptr(parent_fsm_) {}