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