BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
XmlRpcClient.h
Go to the documentation of this file.
1
2#ifndef _XMLRPCCLIENT_H_
3#define _XMLRPCCLIENT_H_
4//
5// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
6//
7#if defined( _MSC_VER )
8# pragma warning( disable : 4786 ) // identifier was truncated in debug info
9#endif
10
11#ifndef MAKEDEPEND
12# include <string>
13#endif
14
15#include "XmlRpcDispatch.h"
16#include "XmlRpcSource.h"
17
18namespace XmlRpc {
19
20 // Arguments and results are represented by XmlRpcValues
21 class XmlRpcValue;
22
23 //! A class to send XML RPC requests to a server and return the results.
24 class XmlRpcClient : public XmlRpcSource {
25 public:
26 // Static data
27 static const char REQUEST_BEGIN[];
28 static const char REQUEST_END_METHODNAME[];
29 static const char PARAMS_TAG[];
30 static const char PARAMS_ETAG[];
31 static const char PARAM_TAG[];
32 static const char PARAM_ETAG[];
33 static const char REQUEST_END[];
34 // Result tags
35 static const char METHODRESPONSE_TAG[];
36 static const char FAULT_TAG[];
37
38 //! Construct a client to connect to the server at the specified host:port address
39 //! @param host The name of the remote machine hosting the server
40 //! @param port The port on the remote machine where the server is listening
41 //! @param uri An optional string to be sent as the URI in the HTTP GET header
42 XmlRpcClient( const char* host, int port, const char* uri = 0 );
43
44 //! Destructor
45 virtual ~XmlRpcClient();
46
47 //! Execute the named procedure on the remote server.
48 //! @param method The name of the remote procedure to execute
49 //! @param params An array of the arguments for the method
50 //! @param result The result value to be returned to the client
51 //! @return true if the request was sent and a result received
52 //! (although the result might be a fault).
53 //!
54 //! Currently this is a synchronous (blocking) implementation (execute
55 //! does not return until it receives a response or an error). Use isFault()
56 //! to determine whether the result is a fault response.
57 bool execute( const char* method, XmlRpcValue const& params, XmlRpcValue& result );
58
59 //! Returns true if the result of the last execute() was a fault response.
60 bool isFault() const { return _isFault; }
61
62 // XmlRpcSource interface implementation
63 //! Close the connection
64 virtual void close();
65
66 //! Handle server responses. Called by the event dispatcher during execute.
67 //! @param eventType The type of event that occurred.
68 //! @see XmlRpcDispatch::EventType
69 virtual unsigned handleEvent( unsigned eventType );
70
71 protected:
72 // Execution processing helpers
73 virtual bool doConnect();
74 virtual bool setupConnection();
75
76 virtual bool generateRequest( const char* method, XmlRpcValue const& params );
77 virtual std::string generateHeader( std::string const& body );
78 virtual bool writeRequest();
79 virtual bool readHeader();
80 virtual bool readResponse();
81 virtual bool parseResponse( XmlRpcValue& result );
82
83 // Possible IO states for the connection
93
94 // Server location
95 std::string _host;
96 std::string _uri;
97 int _port;
98
99 // The xml-encoded request, http header of response, and response xml
100 std::string _request;
101 std::string _header;
102 std::string _response;
103
104 // Number of times the client has attempted to send the request
106
107 // Number of bytes of the request that have been written to the socket so far
109
110 // True if we are currently executing a request. If you want to multithread,
111 // each thread should have its own client.
113
114 // True if the server closed the connection
115 bool _eof;
116
117 // True if a fault response was returned by the server
119
120 // Number of bytes expected in the response body (parsed from response header)
122
123 // Event dispatcher
125
126 }; // class XmlRpcClient
127
128} // namespace XmlRpc
129
130#endif // _XMLRPCCLIENT_H_
static const char PARAM_ETAG[]
static const char PARAMS_ETAG[]
static const char REQUEST_END[]
XmlRpcClient(const char *host, int port, const char *uri=0)
bool execute(const char *method, XmlRpcValue const &params, XmlRpcValue &result)
XmlRpcDispatch _disp
virtual bool doConnect()
virtual std::string generateHeader(std::string const &body)
bool isFault() const
Returns true if the result of the last execute() was a fault response.
virtual void close()
Close the connection.
static const char REQUEST_END_METHODNAME[]
ClientConnectionState _connectionState
virtual bool parseResponse(XmlRpcValue &result)
static const char REQUEST_BEGIN[]
static const char PARAM_TAG[]
virtual bool setupConnection()
virtual bool writeRequest()
virtual bool readResponse()
virtual ~XmlRpcClient()
Destructor.
virtual bool readHeader()
static const char METHODRESPONSE_TAG[]
static const char FAULT_TAG[]
static const char PARAMS_TAG[]
virtual bool generateRequest(const char *method, XmlRpcValue const &params)
virtual unsigned handleEvent(unsigned eventType)
XmlRpcSource(int fd=-1, bool deleteOnClose=false)
RPC method arguments and results are represented by Values.
Definition XmlRpcValue.h:22