USRP Hardware Driver and USRP Manual  Version: 003.008.002-0-ge9d11b35
UHD and USRP Manual
rpc_client.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2013 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_RPC_CLIENT_HPP
19 #define INCLUDED_RPC_CLIENT_HPP
20 
21 #include <boost/asio.hpp>
22 #include <boost/smart_ptr.hpp>
23 #include <boost/thread/thread.hpp>
24 #include <boost/thread/condition_variable.hpp>
25 #include "rpc_common.hpp"
26 #include <uhd/utils/log.hpp>
27 
28 namespace uhd { namespace usrprio_rpc {
29 
30 class rpc_client : private boost::noncopyable
31 {
32 public:
33  static const boost::uint32_t CURRENT_VERSION = 1;
34  static const boost::uint32_t OLDEST_COMPATIBLE_VERSION = 1;
35 
36  rpc_client(
37  const std::string& server,
38  const std::string& port,
39  boost::uint32_t process_id,
40  boost::uint32_t host_id);
41  ~rpc_client();
42 
43  const boost::system::error_code& call(
44  func_id_t func_id,
45  const func_args_writer_t& in_args,
46  func_args_reader_t &out_args,
47  boost::posix_time::milliseconds timeout);
48 
49  inline const boost::system::error_code& status() const {
50  return _exec_err;
51  }
52 
53  /* [Possible boost::system::error_code values]
54  * boost::asio::error::connection_aborted: Network connection failure
55  * boost::asio::error::eof: Network connection closed cleanly
56  * boost::asio::error::connection_refused: Software handshake failure (version mismatch, etc)
57  * boost::asio::error::timed_out: RPC call timed out
58  * boost::asio::error::operation_aborted: RPC call aborted but connection alive
59  */
60 
61 private:
62  void _handle_response_hdr(const boost::system::error_code& err, size_t transferred, size_t expected);
63  void _handle_response_data(const boost::system::error_code& err, size_t transferred, size_t expected);
64  void _wait_for_next_response_header();
65 
66  inline void _stop_io_service() {
67  if (_io_service_thread.get()) {
68  UHD_LOG << "rpc_client stopping..." << std::endl;
69  _io_service.stop();
70  _io_service_thread->join();
71  _io_service_thread.reset();
72  UHD_LOG << "rpc_client stopped." << std::endl;
73  }
74  }
75 
76  //Services
77  boost::asio::io_service _io_service;
78  boost::scoped_ptr<boost::thread> _io_service_thread;
79  boost::asio::ip::tcp::socket _socket;
80  //Handshake info
81  hshake_args_t _hshake_args_client;
82  hshake_args_t _hshake_args_server;
83  //In-out function args
84  func_xport_buf_t _request;
85  func_xport_buf_t _response;
86  //Synchronization
87  boost::mutex _mutex;
88  boost::condition_variable _exec_gate;
89  boost::system::error_code _exec_err;
90 };
91 
92 }}
93 
94 #endif /* INCLUDED_RPC_CLIENT_HPP */
Definition: rpc_common.hpp:76
Definition: rpc_client.hpp:30
Definition: rpc_common.hpp:107
const boost::system::error_code & status() const
Definition: rpc_client.hpp:49
Definition: rpc_common.hpp:49
rpc_client(const std::string &server, const std::string &port, boost::uint32_t process_id, boost::uint32_t host_id)
static const boost::uint32_t OLDEST_COMPATIBLE_VERSION
Definition: rpc_client.hpp:34
Definition: convert.hpp:28
static const boost::uint32_t CURRENT_VERSION
Definition: rpc_client.hpp:33
boost::int32_t func_id_t
Definition: rpc_common.hpp:38
#define UHD_LOG
Definition: log.hpp:66
const boost::system::error_code & call(func_id_t func_id, const func_args_writer_t &in_args, func_args_reader_t &out_args, boost::posix_time::milliseconds timeout)
Definition: rpc_common.hpp:69