libiqxmlrpc  0.12.4
 All Classes Namespaces Files Functions Typedefs Enumerations
client.h
1 // Libiqxmlrpc - an object-oriented XML-RPC solution.
2 // Copyright (C) 2011 Anton Dedov
3 
4 #ifndef _iqxmlrpc_client_h_
5 #define _iqxmlrpc_client_h_
6 
7 #include "connector.h"
8 #include "request.h"
9 #include "response.h"
10 
11 #include <boost/optional.hpp>
12 #include <boost/scoped_ptr.hpp>
13 
14 namespace iqxmlrpc {
15 
16 class Client_connection;
17 
18 #ifdef _MSC_VER
19 #pragma warning(push)
20 #pragma warning(disable: 4251)
21 #endif
22 
25 class LIBIQXMLRPC_API Client_base: boost::noncopyable {
26 public:
28  const iqnet::Inet_addr& addr,
29  const std::string& uri,
30  const std::string& vhost
31  );
32 
33  virtual ~Client_base();
34 
36  Response execute( const std::string&, const Param_list& );
37 
39  Response execute( const std::string& method, const Value& val )
40  {
41  Param_list pl;
42  pl.push_back( val );
43  return execute( method, pl );
44  }
45 
47  void set_proxy(const iqnet::Inet_addr&);
48 
50 
52  void set_timeout( int seconds );
53 
55  void set_keep_alive( bool keep_alive );
56 
58  void set_authinfo(const std::string& user, const std::string& password);
59 
60 protected:
61  int timeout() const;
62 
63 private:
64  virtual void do_set_proxy( const iqnet::Inet_addr& ) = 0;
65  virtual Client_connection* get_connection() = 0;
66 
67  friend class Auto_conn;
68  class Impl;
69 
70  boost::scoped_ptr<Impl> impl_;
71 };
72 
73 #ifdef _MSC_VER
74 #pragma warning(pop)
75 #endif
76 
80 template <class TRANSPORT>
82 public:
88  const iqnet::Inet_addr& addr,
89  const std::string& uri = "/RPC",
90  const std::string& vhost = ""
91  ):
92  Client_base(addr, uri, vhost),
93  ctr(addr) {}
94 
95 private:
96  virtual void do_set_proxy(const iqnet::Inet_addr& addr)
97  {
98  proxy_ctr = iqnet::Connector<Proxy_connection>(addr);
99  }
100 
101  virtual Client_connection* get_connection()
102  {
103  if (proxy_ctr)
104  return proxy_ctr->connect(timeout());
105 
106  return ctr.connect(timeout());
107  }
108 
110 
111  typedef typename TRANSPORT::Proxy_connection Proxy_connection;
112  boost::optional<iqnet::Connector<Proxy_connection> > proxy_ctr;
113 };
114 
115 } // namespace iqxmlrpc
116 
117 #endif
118 // vim:ts=2:sw=2:et