diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-05-30 15:54:10 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:58 -0800 |
commit | 54acfcd1213a27cfa33b86751d2d3e9e186e1086 (patch) | |
tree | 658678e584903b6b28e6d0d8bf4c94b8a10d8ad9 /host | |
parent | 639539dc41241f1981e74e7eb7fe81d75e558007 (diff) | |
download | uhd-54acfcd1213a27cfa33b86751d2d3e9e186e1086.tar.gz uhd-54acfcd1213a27cfa33b86751d2d3e9e186e1086.tar.bz2 uhd-54acfcd1213a27cfa33b86751d2d3e9e186e1086.zip |
mpmd/rpc: Added a convenience wrapper for calling with a token
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_impl.cpp | 13 | ||||
-rw-r--r-- | host/lib/utils/rpc.hpp | 26 |
2 files changed, 34 insertions, 5 deletions
diff --git a/host/lib/usrp/mpmd/mpmd_impl.cpp b/host/lib/usrp/mpmd/mpmd_impl.cpp index 2d93c16ff..1d8b2b03b 100644 --- a/host/lib/usrp/mpmd/mpmd_impl.cpp +++ b/host/lib/usrp/mpmd/mpmd_impl.cpp @@ -49,6 +49,7 @@ mpmd_mboard_impl::mpmd_mboard_impl(const std::string& addr) if (_rpc_token.empty()){ throw uhd::value_error("mpmd device claiming failed!"); } + rpc->set_token(_rpc_token); _claimer_task = task::make([this] { if (not this->claim()) { throw uhd::value_error("mpmd device reclaiming loop failed!"); @@ -77,11 +78,15 @@ mpmd_mboard_impl::mpmd_mboard_impl(const std::string& addr) uhd::sid_t mpmd_mboard_impl::allocate_sid(const uint16_t port, const uhd::sid_t address, const uint32_t xbar_src_addr, - const uint32_t xbar_src_port){ - const uint32_t sid = rpc->call<uint32_t>("allocate_sid", _rpc_token, port, - address.get(), xbar_src_addr, xbar_src_port); + const uint32_t xbar_src_port) +{ + const uint32_t sid = rpc->call_with_token<uint32_t>( + "allocate_sid", + port, address.get(), xbar_src_addr, xbar_src_port + ); return sid; } + mpmd_mboard_impl::~mpmd_mboard_impl() {} mpmd_mboard_impl::uptr mpmd_mboard_impl::make(const std::string& addr) @@ -94,7 +99,7 @@ mpmd_mboard_impl::uptr mpmd_mboard_impl::make(const std::string& addr) bool mpmd_mboard_impl::claim() { - return rpc->call<bool>("reclaim", _rpc_token); + return rpc->call_with_token<bool>("reclaim"); } mpmd_impl::mpmd_impl(const device_addr_t& device_addr) diff --git a/host/lib/utils/rpc.hpp b/host/lib/utils/rpc.hpp index bae8f7fe1..17e5fe099 100644 --- a/host/lib/utils/rpc.hpp +++ b/host/lib/utils/rpc.hpp @@ -43,7 +43,12 @@ class rpc_client */ rpc_client(std::string const& addr, uint16_t port) : _client(addr, port) {} - /*! Perform an RPC call + /*! Perform an RPC call. + * + * Thread safe (locked). + * + * \param func_name The function name that is called via RPC + * \param args All these arguments are passed to the RPC call */ template <typename return_type, typename... Args> return_type call(std::string const& func_name, Args&&... args) @@ -53,7 +58,26 @@ class rpc_client .template as<return_type>(); }; + /*! Perform an RPC call; also includes a token. + * + * The first argument to the actual RPC function call is the current token + * value. To set a token value, call set_token() + */ + template <typename return_type, typename... Args> + return_type call_with_token(std::string const& func_name, Args&&... args) + { + return call<return_type>(func_name, _token, std::forward<Args>(args)...); + }; + + /*! Sets the token value. This is used by call_with_token(). + */ + void set_token(const std::string &token) + { + _token = token; + } + private: + std::string _token; std::mutex _mutex; ::rpc::client _client; }; |