typedefed the proc_result_t<void> to become proc_state_t

master
Francisco Paisana 5 years ago committed by Andre Puschmann
parent f2d88e5a5b
commit b254bdbb93

@ -35,7 +35,7 @@ enum class proc_outcome_t { repeat, yield, success, error };
/************************************************************************************** /**************************************************************************************
* helper functions for method optional overloading * helper functions for method optional overloading
************************************************************************************/ ************************************************************************************/
namespace detail { namespace proc_detail {
// used by proc_t<T> to call T::then() method only if it exists // used by proc_t<T> to call T::then() method only if it exists
template <typename T, typename ProcResult> template <typename T, typename ProcResult>
auto optional_then(T* obj, const ProcResult& result) -> decltype(obj->then(result)) auto optional_then(T* obj, const ProcResult& result) -> decltype(obj->then(result))
@ -59,7 +59,7 @@ inline auto optional_clear(...) -> void
template <class T> template <class T>
auto get_result_type(const T& obj) -> decltype(obj.get_result()); auto get_result_type(const T& obj) -> decltype(obj.get_result());
inline auto get_result_type(...) -> void; inline auto get_result_type(...) -> void;
} // namespace detail } // namespace proc_detail
/************************************************************************************** /**************************************************************************************
* class: callback_group_t<Args...> * class: callback_group_t<Args...>
@ -132,7 +132,7 @@ private:
* successful run. * successful run.
**************************************************************************************/ **************************************************************************************/
namespace detail { namespace proc_detail {
struct proc_result_base_t { struct proc_result_base_t {
bool is_success() const { return state == result_state_t::value; } bool is_success() const { return state == result_state_t::value; }
bool is_error() const { return state == result_state_t::error; } bool is_error() const { return state == result_state_t::error; }
@ -144,9 +144,9 @@ struct proc_result_base_t {
protected: protected:
enum class result_state_t { none, value, error } state = result_state_t::none; enum class result_state_t { none, value, error } state = result_state_t::none;
}; };
} // namespace detail } // namespace proc_detail
template <typename T> template <typename T>
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; } const T* value() const { return state == result_state_t::value ? &t : nullptr; }
void set_val(const T& t_) void set_val(const T& t_)
{ {
@ -163,13 +163,15 @@ protected:
T t; T t;
}; };
template <> template <>
struct proc_result_t<void> : public detail::proc_result_base_t { struct proc_result_t<void> : public proc_detail::proc_result_base_t {
template <typename Proc> template <typename Proc>
void extract_val(Proc& p) void extract_val(Proc& p)
{ {
set_val(); set_val();
} }
}; };
// specialization for ResultType=void
using proc_state_t = proc_result_t<void>;
/************************************************************************************** /**************************************************************************************
* class: proc_future_t * class: proc_future_t
@ -280,7 +282,7 @@ public:
template <typename... Args> template <typename... Args>
explicit proc_t(Args&&... args) : proc_ptr(new T(std::forward<Args>(args)...)) explicit proc_t(Args&&... args) : proc_ptr(new T(std::forward<Args>(args)...))
{ {
static_assert(std::is_same<result_type, decltype(detail::get_result_type(std::declval<T>()))>::value, static_assert(std::is_same<result_type, decltype(proc_detail::get_result_type(std::declval<T>()))>::value,
"The types \"proc_t::result_type\" and the return of T::get_result() have to match"); "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(); proc_result.set_error();
} }
// call T::then() if it exists // 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 // signal continuations
complete_callbacks(proc_result); complete_callbacks(proc_result);
// propagate proc_result to future if it exists, and release future // 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. // reset the current result, to prepare it for a new run.
proc_result.clear(); proc_result.clear();
// back to inactive // back to inactive
detail::optional_clear(proc_ptr.get()); proc_detail::optional_clear(proc_ptr.get());
proc_state = proc_status_t::idle; proc_state = proc_status_t::idle;
} }

@ -214,8 +214,8 @@ public:
class nas_interface_ue class nas_interface_ue
{ {
public: public:
virtual void start_attach_request(srslte::proc_result_t<void>* proc_result, srslte::establishment_cause_t cause_) = 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; virtual bool detach_request(const bool switch_off) = 0;
}; };
// PDCP interface for RRC // PDCP interface for RRC

@ -138,7 +138,7 @@ public:
explicit plmn_search_proc(rrc* parent_); explicit plmn_search_proc(rrc* parent_);
srslte::proc_outcome_t init(); srslte::proc_outcome_t init();
srslte::proc_outcome_t step(); srslte::proc_outcome_t step();
void then(const srslte::proc_result_t<void>& result) const; void then(const srslte::proc_state_t& result) const;
static const char* name() { return "PLMN Search"; } static const char* name() { return "PLMN Search"; }
private: private:
@ -158,7 +158,7 @@ public:
explicit connection_request_proc(rrc* parent_); 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 init(srslte::establishment_cause_t cause_, srslte::unique_byte_buffer_t dedicated_info_nas_);
srslte::proc_outcome_t step(); srslte::proc_outcome_t step();
void then(const srslte::proc_result_t<void>& result); void then(const srslte::proc_state_t& result);
srslte::proc_outcome_t react(const cell_selection_proc::cell_selection_complete_ev& e); srslte::proc_outcome_t react(const cell_selection_proc::cell_selection_complete_ev& e);
static const char* name() { return "Connection Request"; } static const char* name() { return "Connection Request"; }

@ -60,7 +60,7 @@ public:
bool get_ipv6_addr(uint8_t* ipv6_addr); bool get_ipv6_addr(uint8_t* ipv6_addr);
// UE interface // UE interface
void start_attach_request(srslte::proc_result_t<void>* 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; 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], 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 class rrc_connect_proc
{ {
public: public:
using rrc_connect_complete_ev = srslte::proc_result_t<void>; using rrc_connect_complete_ev = srslte::proc_state_t;
struct connection_request_completed_t { struct connection_request_completed_t {
bool outcome; 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 init(srslte::establishment_cause_t cause_, srslte::unique_byte_buffer_t pdu);
srslte::proc_outcome_t step(); srslte::proc_outcome_t step();
void then(const srslte::proc_result_t<void>& result); void then(const srslte::proc_state_t& result);
srslte::proc_outcome_t react(connection_request_completed_t event); srslte::proc_outcome_t react(connection_request_completed_t event);
static const char* name() { return "RRC Connect"; } 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 init();
srslte::proc_outcome_t step(); srslte::proc_outcome_t step();
void then(const srslte::proc_result_t<void>& 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 plmn_search_complete_t& t);
srslte::proc_outcome_t react(const rrc_connect_proc::rrc_connect_complete_ev& t); srslte::proc_outcome_t react(const rrc_connect_proc::rrc_connect_complete_ev& t);
static const char* name() { return "PLMN Search"; } static const char* name() { return "PLMN Search"; }

@ -527,7 +527,7 @@ proc_outcome_t rrc::plmn_search_proc::step()
return proc_outcome_t::repeat; return proc_outcome_t::repeat;
} }
void rrc::plmn_search_proc::then(const srslte::proc_result_t<void>& result) const void rrc::plmn_search_proc::then(const srslte::proc_state_t& result) const
{ {
// on cleanup, call plmn_search_completed // on cleanup, call plmn_search_completed
if (result.is_success()) { if (result.is_success()) {
@ -641,7 +641,7 @@ proc_outcome_t rrc::connection_request_proc::step()
return proc_outcome_t::error; return proc_outcome_t::error;
} }
void rrc::connection_request_proc::then(const srslte::proc_result_t<void>& result) void rrc::connection_request_proc::then(const srslte::proc_state_t& result)
{ {
if (result.is_error()) { if (result.is_error()) {
log_h->warning("Could not establish connection. Deallocating dedicatedInfoNAS PDU\n"); log_h->warning("Could not establish connection. Deallocating dedicatedInfoNAS PDU\n");

@ -62,7 +62,7 @@ proc_outcome_t nas::plmn_search_proc::step()
return proc_outcome_t::yield; return proc_outcome_t::yield;
} }
void nas::plmn_search_proc::then(const srslte::proc_result_t<void>& result) void nas::plmn_search_proc::then(const srslte::proc_state_t& result)
{ {
ProcInfo("Completed with %s\n", result.is_success() ? "success" : "failure"); ProcInfo("Completed with %s\n", result.is_success() ? "success" : "failure");
@ -201,7 +201,7 @@ proc_outcome_t nas::rrc_connect_proc::step()
return proc_outcome_t::error; return proc_outcome_t::error;
} }
void nas::rrc_connect_proc::then(const srslte::proc_result_t<void>& result) void nas::rrc_connect_proc::then(const srslte::proc_state_t& result)
{ {
nas_ptr->plmn_searcher.trigger(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. * 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<void>* 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"); nas_log->info("Attach Request\n");
switch (state) { switch (state) {
@ -365,7 +365,7 @@ void nas::start_attach_request(srslte::proc_result_t<void>* result, srslte::esta
} }
return; return;
} }
plmn_searcher.then([this, result](const proc_result_t<void>& 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"); nas_log->info("Attach Request from PLMN Search %s\n", res.is_success() ? "finished successfully" : "failed");
if (result != nullptr) { if (result != nullptr) {
*result = res; *result = res;
@ -393,7 +393,7 @@ void nas::start_attach_request(srslte::proc_result_t<void>* result, srslte::esta
} }
return; return;
} }
rrc_connector.then([this, result](const proc_result_t<void>& res) { rrc_connector.then([this, result](const proc_state_t& res) {
if (res.is_success()) { if (res.is_success()) {
nas_log->info("NAS attached successfully\n"); nas_log->info("NAS attached successfully\n");
} else { } else {
@ -466,7 +466,7 @@ bool nas::paging(s_tmsi_t* ue_identity)
return false; return false;
} }
// once completed, call paging complete // once completed, call paging complete
rrc_connector.then([this](proc_result_t<void> outcome) { rrc_connector.then([this](proc_state_t outcome) {
rrc->paging_completed(outcome.is_success()); rrc->paging_completed(outcome.is_success());
return proc_outcome_t::success; return proc_outcome_t::success;
}); });

@ -145,7 +145,7 @@ public:
void init() { start(-1); } void init() { start(-1); }
bool switch_on() final bool switch_on() final
{ {
proc_result_t<void> proc_result; proc_state_t proc_result;
nas->start_attach_request(&proc_result, srslte::establishment_cause_t::mo_data); nas->start_attach_request(&proc_result, srslte::establishment_cause_t::mo_data);
while (not proc_result.is_complete()) { while (not proc_result.is_complete()) {
usleep(1000); usleep(1000);

Loading…
Cancel
Save