diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-06-02 14:59:47 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:58 -0800 |
commit | 11401e2564bd50bdd76c84d9baedbb797ecf3f61 (patch) | |
tree | 00cd5ef509a5b0a111736630f440a46690550584 | |
parent | 18098228932f3e25e3ac1750599c5e531657f161 (diff) | |
download | uhd-11401e2564bd50bdd76c84d9baedbb797ecf3f61.tar.gz uhd-11401e2564bd50bdd76c84d9baedbb797ecf3f61.tar.bz2 uhd-11401e2564bd50bdd76c84d9baedbb797ecf3f61.zip |
rpc: Changed API to request/notify for better distinction between the two
-rw-r--r-- | host/lib/usrp/dboard/eiscat/eiscat_radio_ctrl_impl.cpp | 10 | ||||
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_impl.cpp | 6 | ||||
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_mboard_impl.cpp | 13 | ||||
-rw-r--r-- | host/lib/utils/rpc.hpp | 46 |
4 files changed, 50 insertions, 25 deletions
diff --git a/host/lib/usrp/dboard/eiscat/eiscat_radio_ctrl_impl.cpp b/host/lib/usrp/dboard/eiscat/eiscat_radio_ctrl_impl.cpp index d948a89c0..1be41dd84 100644 --- a/host/lib/usrp/dboard/eiscat/eiscat_radio_ctrl_impl.cpp +++ b/host/lib/usrp/dboard/eiscat/eiscat_radio_ctrl_impl.cpp @@ -398,7 +398,7 @@ void eiscat_radio_ctrl_impl::set_rpc_client( _rpcc = rpcc; std::function<void()> send_sysref; if (block_args.has_key("use_mpm_sysref")) { - send_sysref = [rpcc](){ rpcc->call<void>("db_0_send_sysref"); }; + send_sysref = [rpcc](){ rpcc->notify("db_0_send_sysref"); }; } else { send_sysref = [this](){ this->sr_write("SR_SYSREF", 1); }; } @@ -408,12 +408,12 @@ void eiscat_radio_ctrl_impl::set_rpc_client( "Finalizing dboard initialization using internal PPS" ); send_sysref(); - rpcc->call_with_token<void>("db_0_init_adcs_and_deframers"); - rpcc->call_with_token<void>("db_1_init_adcs_and_deframers"); + rpcc->notify_with_token("db_0_init_adcs_and_deframers"); + rpcc->notify_with_token("db_1_init_adcs_and_deframers"); send_sysref(); std::this_thread::sleep_for(std::chrono::milliseconds(500)); - rpcc->call_with_token<void>("db_0_check_deframer_status"); - rpcc->call_with_token<void>("db_1_check_deframer_status"); + rpcc->notify_with_token("db_0_check_deframer_status"); + rpcc->notify_with_token("db_1_check_deframer_status"); } /**************************************************************************** diff --git a/host/lib/usrp/mpmd/mpmd_impl.cpp b/host/lib/usrp/mpmd/mpmd_impl.cpp index efc89f86e..f1c5efc14 100644 --- a/host/lib/usrp/mpmd/mpmd_impl.cpp +++ b/host/lib/usrp/mpmd/mpmd_impl.cpp @@ -140,16 +140,16 @@ void mpmd_impl::setup_rfnoc_blocks( const uhd::device_addr_t& ctrl_xport_args ) { auto &mb = _mb[mb_index]; - mb->num_xbars = mb->rpc->call<size_t>("get_num_xbars"); + mb->num_xbars = mb->rpc->request<size_t>("get_num_xbars"); UHD_LOG_TRACE("MPM", "Mboard " << mb_index << " reports " << mb->num_xbars << " crossbar(s)." ); for (size_t xbar_index = 0; xbar_index < mb->num_xbars; xbar_index++) { const size_t num_blocks = - mb->rpc->call<size_t>("get_num_blocks", xbar_index); + mb->rpc->request<size_t>("get_num_blocks", xbar_index); const size_t base_port = - mb->rpc->call<size_t>("get_base_port", xbar_index); + mb->rpc->request<size_t>("get_base_port", xbar_index); const size_t local_addr = mb->get_xbar_local_addr(xbar_index); UHD_LOGGER_TRACE("MPMD") << "Enumerating RFNoC blocks for xbar " << xbar_index diff --git a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp index 934663e29..6ebb2caf6 100644 --- a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp +++ b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp @@ -39,7 +39,7 @@ mpmd_mboard_impl::mpmd_mboard_impl( << "Initializing mboard, connecting to IP address: " << ip_addr << " mboard args: " << mb_args.to_string() ; - auto device_info_dict = rpc->call<dev_info>("get_device_info"); + auto device_info_dict = rpc->request<dev_info>("get_device_info"); for (const auto &info_pair: device_info_dict) { device_info[info_pair.first] = info_pair.second; } @@ -47,12 +47,13 @@ mpmd_mboard_impl::mpmd_mboard_impl( << "MPM reports device info: " << device_info.to_string(); // Claim logic - auto rpc_token = rpc->call<std::string>("claim", + auto rpc_token = rpc->request<std::string>("claim", mb_args.get("session_id", MPMD_DEFAULT_SESSION_ID) ); if (rpc_token.empty()) { throw uhd::value_error("mpmd device claiming failed!"); } + UHD_LOG_TRACE("MPMD", "Received claim token " << rpc_token); rpc->set_token(rpc_token); _claimer_task = task::make([this] { if (not this->claim()) { @@ -64,7 +65,7 @@ mpmd_mboard_impl::mpmd_mboard_impl( }); // Initialize properties - this->num_xbars = rpc->call<size_t>("get_num_xbars"); + this->num_xbars = rpc->request<size_t>("get_num_xbars"); // Local addresses are not yet valid after this! this->xbar_local_addrs.resize(this->num_xbars, 0xFF); @@ -100,7 +101,7 @@ uhd::sid_t mpmd_mboard_impl::allocate_sid(const uint16_t port, const uint32_t xbar_src_addr, const uint32_t xbar_src_port) { - const auto sid = rpc->call_with_token<uint32_t>( + const auto sid = rpc->request_with_token<uint32_t>( "allocate_sid", port, address.get(), xbar_src_addr, xbar_src_port ); @@ -111,7 +112,7 @@ void mpmd_mboard_impl::set_xbar_local_addr( const size_t xbar_index, const size_t local_addr ) { - rpc->call_with_token<void>("set_xbar_local_addr", xbar_index, local_addr); + UHD_ASSERT_THROW(rpc->request_with_token<bool>("set_xbar_local_addr", xbar_index, local_addr)); UHD_ASSERT_THROW(xbar_index < xbar_local_addrs.size()); xbar_local_addrs.at(xbar_index) = local_addr; } @@ -121,7 +122,7 @@ void mpmd_mboard_impl::set_xbar_local_addr( ****************************************************************************/ bool mpmd_mboard_impl::claim() { - return rpc->call_with_token<bool>("reclaim"); + return rpc->request_with_token<bool>("reclaim"); } /***************************************************************************** diff --git a/host/lib/utils/rpc.hpp b/host/lib/utils/rpc.hpp index f8cec8f26..1ae4f3c74 100644 --- a/host/lib/utils/rpc.hpp +++ b/host/lib/utils/rpc.hpp @@ -46,15 +46,18 @@ class rpc_client */ rpc_client(std::string const& addr, uint16_t port) : _client(addr, port) {} - /*! Perform an RPC call. + /*! Perform an RPC request. * - * Thread safe (locked). + * Thread safe (locked). This function blocks until it receives a valid + * response from the server. * * \param func_name The function name that is called via RPC * \param args All these arguments are passed to the RPC call + * + * \throws uhd::runtime_error in case of failure */ template <typename return_type, typename... Args> - return_type call(std::string const& func_name, Args&&... args) + return_type request(std::string const& func_name, Args&&... args) { std::lock_guard<std::mutex> lock(_mutex); try { @@ -73,8 +76,18 @@ class rpc_client } }; + /*! Perform an RPC notification. + * + * Thread safe (locked). This function does not require a response from the + * server, although the underlying implementation may provide one. + * + * \param func_name The function name that is called via RPC + * \param args All these arguments are passed to the RPC call + * + * \throws uhd::runtime_error in case of failure + */ template <typename... Args> - void call(std::string const& func_name, Args&&... args) + void notify(std::string const& func_name, Args&&... args) { std::lock_guard<std::mutex> lock(_mutex); try { @@ -92,18 +105,29 @@ class rpc_client } }; - /*! Perform an RPC call; also includes a token. + /*! Like request(), also provides a token. * - * The first argument to the actual RPC function call is the current token - * value. To set a token value, call set_token() + * This is a convenience wrapper to directly call a function that requires + * a token without having to have a copy of the token. */ template <typename return_type, typename... Args> - return_type call_with_token(std::string const& func_name, Args&&... args) + return_type request_with_token(std::string const& func_name, Args&&... args) + { + return request<return_type>(func_name, _token, std::forward<Args>(args)...); + }; + + /*! Like notify(), also provides a token. + * + * This is a convenience wrapper to directly call a function that requires + * a token without having to have a copy of the token. + */ + template <typename... Args> + void notify_with_token(std::string const& func_name, Args&&... args) { - return call<return_type>(func_name, _token, std::forward<Args>(args)...); + notify(func_name, _token, std::forward<Args>(args)...); }; - /*! Sets the token value. This is used by call_with_token(). + /*! Sets the token value. This is used by the `_with_token` methods. */ void set_token(const std::string &token) { @@ -116,6 +140,6 @@ class rpc_client ::rpc::client _client; }; -} +} /* namespace uhd */ #endif /* INCLUDED_UTILS_RPC_HPP */ |