diff --git a/lib/include/srslte/common/stack_procedure.h b/lib/include/srslte/common/stack_procedure.h index 2bba82d2e..d062a365f 100644 --- a/lib/include/srslte/common/stack_procedure.h +++ b/lib/include/srslte/common/stack_procedure.h @@ -35,7 +35,7 @@ enum class proc_outcome_t { repeat, yield, success, error }; /************************************************************************************** * helper functions for method optional overloading ************************************************************************************/ -namespace detail { +namespace proc_detail { // used by proc_t to call T::then() method only if it exists template auto optional_then(T* obj, const ProcResult& result) -> decltype(obj->then(result)) @@ -59,7 +59,7 @@ inline auto optional_clear(...) -> void template auto get_result_type(const T& obj) -> decltype(obj.get_result()); inline auto get_result_type(...) -> void; -} // namespace detail +} // namespace proc_detail /************************************************************************************** * class: callback_group_t @@ -132,7 +132,7 @@ private: * successful run. **************************************************************************************/ -namespace detail { +namespace proc_detail { struct proc_result_base_t { bool is_success() const { return state == result_state_t::value; } bool is_error() const { return state == result_state_t::error; } @@ -144,9 +144,9 @@ struct proc_result_base_t { protected: enum class result_state_t { none, value, error } state = result_state_t::none; }; -} // namespace detail +} // namespace proc_detail template -struct proc_result_t : public detail::proc_result_base_t { +struct proc_result_t : public proc_detail::proc_result_base_t { const T* value() const { return state == result_state_t::value ? &t : nullptr; } void set_val(const T& t_) { @@ -163,13 +163,15 @@ protected: T t; }; template <> -struct proc_result_t : public detail::proc_result_base_t { +struct proc_result_t : public proc_detail::proc_result_base_t { template void extract_val(Proc& p) { set_val(); } }; +// specialization for ResultType=void +using proc_state_t = proc_result_t; /************************************************************************************** * class: proc_future_t @@ -280,7 +282,7 @@ public: template explicit proc_t(Args&&... args) : proc_ptr(new T(std::forward(args)...)) { - static_assert(std::is_same()))>::value, + static_assert(std::is_same()))>::value, "The types \"proc_t::result_type\" and the return of T::get_result() have to match"); } @@ -347,7 +349,7 @@ protected: proc_result.set_error(); } // call T::then() if it exists - detail::optional_then(proc_ptr.get(), proc_result); + proc_detail::optional_then(proc_ptr.get(), proc_result); // signal continuations complete_callbacks(proc_result); // propagate proc_result to future if it exists, and release future @@ -358,7 +360,7 @@ protected: // reset the current result, to prepare it for a new run. proc_result.clear(); // back to inactive - detail::optional_clear(proc_ptr.get()); + proc_detail::optional_clear(proc_ptr.get()); proc_state = proc_status_t::idle; } diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 6172e57a3..bedebffa5 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -214,8 +214,8 @@ public: class nas_interface_ue { public: - virtual void start_attach_request(srslte::proc_result_t* proc_result, srslte::establishment_cause_t cause_) = 0; - virtual bool detach_request(const bool switch_off) = 0; + virtual void start_attach_request(srslte::proc_state_t* proc_result, srslte::establishment_cause_t cause_) = 0; + virtual bool detach_request(const bool switch_off) = 0; }; // PDCP interface for RRC diff --git a/srsue/hdr/stack/rrc/rrc_procedures.h b/srsue/hdr/stack/rrc/rrc_procedures.h index c80eaeeb6..59d268f74 100644 --- a/srsue/hdr/stack/rrc/rrc_procedures.h +++ b/srsue/hdr/stack/rrc/rrc_procedures.h @@ -138,7 +138,7 @@ public: explicit plmn_search_proc(rrc* parent_); srslte::proc_outcome_t init(); srslte::proc_outcome_t step(); - void then(const srslte::proc_result_t& result) const; + void then(const srslte::proc_state_t& result) const; static const char* name() { return "PLMN Search"; } private: @@ -158,7 +158,7 @@ public: explicit connection_request_proc(rrc* parent_); srslte::proc_outcome_t init(srslte::establishment_cause_t cause_, srslte::unique_byte_buffer_t dedicated_info_nas_); srslte::proc_outcome_t step(); - void then(const srslte::proc_result_t& result); + void then(const srslte::proc_state_t& result); srslte::proc_outcome_t react(const cell_selection_proc::cell_selection_complete_ev& e); static const char* name() { return "Connection Request"; } diff --git a/srsue/hdr/stack/upper/nas.h b/srsue/hdr/stack/upper/nas.h index be11b32be..f69297ca4 100644 --- a/srsue/hdr/stack/upper/nas.h +++ b/srsue/hdr/stack/upper/nas.h @@ -60,7 +60,7 @@ public: bool get_ipv6_addr(uint8_t* ipv6_addr); // UE interface - void start_attach_request(srslte::proc_result_t* result, srslte::establishment_cause_t cause_) final; + void start_attach_request(srslte::proc_state_t* result, srslte::establishment_cause_t cause_) final; bool detach_request(const bool switch_off) final; void plmn_search_completed(const rrc_interface_nas::found_plmn_t found_plmns[rrc_interface_nas::MAX_FOUND_PLMNS], @@ -259,15 +259,15 @@ private: class rrc_connect_proc { public: - using rrc_connect_complete_ev = srslte::proc_result_t; + using rrc_connect_complete_ev = srslte::proc_state_t; struct connection_request_completed_t { bool outcome; }; - rrc_connect_proc(nas* nas_ptr_) : nas_ptr(nas_ptr_) {} + explicit rrc_connect_proc(nas* nas_ptr_) : nas_ptr(nas_ptr_) {} srslte::proc_outcome_t init(srslte::establishment_cause_t cause_, srslte::unique_byte_buffer_t pdu); srslte::proc_outcome_t step(); - void then(const srslte::proc_result_t& result); + void then(const srslte::proc_state_t& result); srslte::proc_outcome_t react(connection_request_completed_t event); static const char* name() { return "RRC Connect"; } @@ -290,10 +290,10 @@ private: } }; - plmn_search_proc(nas* nas_ptr_) : nas_ptr(nas_ptr_) {} + explicit plmn_search_proc(nas* nas_ptr_) : nas_ptr(nas_ptr_) {} srslte::proc_outcome_t init(); srslte::proc_outcome_t step(); - void then(const srslte::proc_result_t& result); + void then(const srslte::proc_state_t& result); srslte::proc_outcome_t react(const plmn_search_complete_t& t); srslte::proc_outcome_t react(const rrc_connect_proc::rrc_connect_complete_ev& t); static const char* name() { return "PLMN Search"; } diff --git a/srsue/src/stack/rrc/rrc_procedures.cc b/srsue/src/stack/rrc/rrc_procedures.cc index da9b9d532..debcf9640 100644 --- a/srsue/src/stack/rrc/rrc_procedures.cc +++ b/srsue/src/stack/rrc/rrc_procedures.cc @@ -527,7 +527,7 @@ proc_outcome_t rrc::plmn_search_proc::step() return proc_outcome_t::repeat; } -void rrc::plmn_search_proc::then(const srslte::proc_result_t& result) const +void rrc::plmn_search_proc::then(const srslte::proc_state_t& result) const { // on cleanup, call plmn_search_completed if (result.is_success()) { @@ -641,7 +641,7 @@ proc_outcome_t rrc::connection_request_proc::step() return proc_outcome_t::error; } -void rrc::connection_request_proc::then(const srslte::proc_result_t& result) +void rrc::connection_request_proc::then(const srslte::proc_state_t& result) { if (result.is_error()) { log_h->warning("Could not establish connection. Deallocating dedicatedInfoNAS PDU\n"); diff --git a/srsue/src/stack/upper/nas.cc b/srsue/src/stack/upper/nas.cc index 50965cfec..4269815ef 100644 --- a/srsue/src/stack/upper/nas.cc +++ b/srsue/src/stack/upper/nas.cc @@ -62,10 +62,10 @@ proc_outcome_t nas::plmn_search_proc::step() return proc_outcome_t::yield; } -void nas::plmn_search_proc::then(const srslte::proc_result_t& result) +void nas::plmn_search_proc::then(const srslte::proc_state_t& result) { ProcInfo("Completed with %s\n", result.is_success() ? "success" : "failure"); - + // start T3411 nas_ptr->nas_log->debug("Starting T3411\n"); nas_ptr->timers->get(nas_ptr->t3411)->reset(); @@ -201,7 +201,7 @@ proc_outcome_t nas::rrc_connect_proc::step() return proc_outcome_t::error; } -void nas::rrc_connect_proc::then(const srslte::proc_result_t& result) +void nas::rrc_connect_proc::then(const srslte::proc_state_t& result) { nas_ptr->plmn_searcher.trigger(result); } @@ -338,7 +338,7 @@ void nas::timer_expired(uint32_t timeout_id) * The function returns true if the UE could attach correctly or false in case of error or timeout during attachment. * */ -void nas::start_attach_request(srslte::proc_result_t* result, srslte::establishment_cause_t cause_) +void nas::start_attach_request(srslte::proc_state_t* result, srslte::establishment_cause_t cause_) { nas_log->info("Attach Request\n"); switch (state) { @@ -365,7 +365,7 @@ void nas::start_attach_request(srslte::proc_result_t* result, srslte::esta } return; } - plmn_searcher.then([this, result](const proc_result_t& res) { + plmn_searcher.then([this, result](const proc_state_t& res) { nas_log->info("Attach Request from PLMN Search %s\n", res.is_success() ? "finished successfully" : "failed"); if (result != nullptr) { *result = res; @@ -393,7 +393,7 @@ void nas::start_attach_request(srslte::proc_result_t* result, srslte::esta } return; } - rrc_connector.then([this, result](const proc_result_t& res) { + rrc_connector.then([this, result](const proc_state_t& res) { if (res.is_success()) { nas_log->info("NAS attached successfully\n"); } else { @@ -466,7 +466,7 @@ bool nas::paging(s_tmsi_t* ue_identity) return false; } // once completed, call paging complete - rrc_connector.then([this](proc_result_t outcome) { + rrc_connector.then([this](proc_state_t outcome) { rrc->paging_completed(outcome.is_success()); return proc_outcome_t::success; }); diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index e410f3337..3bfb3447f 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -145,7 +145,7 @@ public: void init() { start(-1); } bool switch_on() final { - proc_result_t proc_result; + proc_state_t proc_result; nas->start_attach_request(&proc_result, srslte::establishment_cause_t::mo_data); while (not proc_result.is_complete()) { usleep(1000);