Go to the documentation of this file.00001
00002 #ifndef _XMLRPCCLIENT_H_
00003 #define _XMLRPCCLIENT_H_
00004
00005
00006
00007 #if defined(_MSC_VER)
00008 # pragma warning(disable:4786) // identifier was truncated in debug info
00009 #endif
00010
00011
00012 #ifndef MAKEDEPEND
00013 # include <string>
00014 #endif
00015
00016 #include "XmlRpcDispatch.h"
00017 #include "XmlRpcSource.h"
00018 #include "XmlRpcDecl.h"
00019
00020 namespace XmlRpc {
00021
00022
00023 class XmlRpcValue;
00024
00026 class XMLRPCPP_DECL XmlRpcClient : public XmlRpcSource {
00027 public:
00028
00029 static const char REQUEST_BEGIN[];
00030 static const char REQUEST_END_METHODNAME[];
00031 static const char PARAMS_TAG[];
00032 static const char PARAMS_ETAG[];
00033 static const char PARAM_TAG[];
00034 static const char PARAM_ETAG[];
00035 static const char REQUEST_END[];
00036
00037 static const char METHODRESPONSE_TAG[];
00038 static const char FAULT_TAG[];
00039
00044 XmlRpcClient(const char* host, int port, const char* uri=0);
00045
00047 virtual ~XmlRpcClient();
00048
00059 bool execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result);
00060
00061 bool executeNonBlock(const char* method, XmlRpcValue const& params);
00062 bool executeCheckDone(XmlRpcValue& result);
00063
00065 bool isFault() const { return _isFault; }
00066
00067
00068
00070 virtual void close();
00071
00075 virtual unsigned handleEvent(unsigned eventType);
00076
00077 protected:
00078
00079 virtual bool doConnect();
00080 virtual bool setupConnection();
00081
00082 virtual bool generateRequest(const char* method, XmlRpcValue const& params);
00083 virtual std::string generateHeader(std::string const& body);
00084 virtual bool writeRequest();
00085 virtual bool readHeader();
00086 virtual bool readResponse();
00087 virtual bool parseResponse(XmlRpcValue& result);
00088
00089
00090 enum ClientConnectionState { NO_CONNECTION, CONNECTING, WRITE_REQUEST, READ_HEADER, READ_RESPONSE, IDLE };
00091 ClientConnectionState _connectionState;
00092
00093
00094 std::string _host;
00095 std::string _uri;
00096 int _port;
00097 public:
00098 const std::string &getHost() { return _host; }
00099 const std::string &getUri() { return _uri; }
00100 int getPort() const { return _port; }
00101
00102
00103 std::string _request;
00104 std::string _header;
00105 std::string _response;
00106
00107
00108 int _sendAttempts;
00109
00110
00111 int _bytesWritten;
00112
00113
00114
00115 bool _executing;
00116
00117
00118 bool _eof;
00119
00120
00121 bool _isFault;
00122
00123
00124 int _contentLength;
00125
00126
00127 XmlRpcDispatch _disp;
00128
00129 };
00130
00131 }
00132
00133 #endif // _XMLRPCCLIENT_H_