diff options
Diffstat (limited to 'host/lib/utils')
-rw-r--r-- | host/lib/utils/rpc.hpp | 26 |
1 files changed, 25 insertions, 1 deletions
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; }; |