X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=extras%2Fvom%2Fvom%2Frpc_cmd.hpp;h=1996f4b3fbe884add70d0cf50aac11c4f5fcbb79;hb=208c29aac523231af2420a95ba7e5d361698780b;hp=84b6717c53b8a609e3b571ec15f601e91f8d1726;hpb=4faab21a75a208d83c184bd424938c4dbf6b38e4;p=vpp.git diff --git a/extras/vom/vom/rpc_cmd.hpp b/extras/vom/vom/rpc_cmd.hpp index 84b6717c53b..1996f4b3fbe 100644 --- a/extras/vom/vom/rpc_cmd.hpp +++ b/extras/vom/vom/rpc_cmd.hpp @@ -34,7 +34,7 @@ namespace VOM { * The command is templatised on the type of the HW::item to be set by * the command, and the data returned in the promise, */ -template +template class rpc_cmd : public cmd { public: @@ -71,34 +71,27 @@ public: /** * Fulfill the commands promise. Called from the RX thread */ - void fulfill(const DATA& d) - { - m_promise.set_value(d); - - /* - * we reset the promise after setting the value to reuse it - * when we run the retire command from the same cmd object - */ - // m_promise = std::promise(); - } + void fulfill(const HWITEM& d) { m_promise.set_value(d); } /** * Wait on the commands promise. i.e. block on the completion * of the command. */ - DATA wait() + rc_t wait() { std::future_status status; - std::future result; + std::future result; result = m_promise.get_future(); status = result.wait_for(std::chrono::seconds(5)); if (status != std::future_status::ready) { - return (DATA(rc_t::TIMEOUT)); + m_hw_item.set(rc_t::TIMEOUT); + } else { + m_hw_item = result.get(); } - return (result.get()); + return (m_hw_item.rc()); } /** @@ -116,9 +109,13 @@ public: */ virtual vapi_error_e operator()(MSG& reply) { + HWITEM hi = m_hw_item; int retval = reply.get_response().get_payload().retval; VOM_LOG(log_level_t::DEBUG) << to_string() << " " << retval; - fulfill(rc_t::from_vpp_retval(retval)); + + /* set a temporary value in this callback thread */ + hi.set(rc_t::from_vpp_retval(retval)); + fulfill(hi); return (VAPI_OK); } @@ -137,7 +134,7 @@ protected: /** * The promise that implements the synchronous issue */ - std::promise m_promise; + std::promise m_promise; }; };