XmlRpcClient.h
Go to the documentation of this file.
00001 
00002 #ifndef _XMLRPCCLIENT_H_
00003 #define _XMLRPCCLIENT_H_
00004 //
00005 // XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
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   // Arguments and results are represented by XmlRpcValues
00023   class XmlRpcValue;
00024 
00026   class XMLRPCPP_DECL XmlRpcClient : public XmlRpcSource {
00027   public:
00028     // Static data
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     // Result tags
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     // XmlRpcSource interface implementation
00070     virtual void close();
00071 
00075     virtual unsigned handleEvent(unsigned eventType);
00076 
00077   protected:
00078     // Execution processing helpers
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     // Possible IO states for the connection
00090     enum ClientConnectionState { NO_CONNECTION, CONNECTING, WRITE_REQUEST, READ_HEADER, READ_RESPONSE, IDLE };
00091     ClientConnectionState _connectionState;
00092 
00093     // Server location
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     // The xml-encoded request, http header of response, and response xml
00103     std::string _request;
00104     std::string _header;
00105     std::string _response;
00106 
00107     // Number of times the client has attempted to send the request
00108     int _sendAttempts;
00109 
00110     // Number of bytes of the request that have been written to the socket so far
00111     int _bytesWritten;
00112 
00113     // True if we are currently executing a request. If you want to multithread,
00114     // each thread should have its own client.
00115     bool _executing;
00116 
00117     // True if the server closed the connection
00118     bool _eof;
00119 
00120     // True if a fault response was returned by the server
00121     bool _isFault;
00122 
00123     // Number of bytes expected in the response body (parsed from response header)
00124     int _contentLength;
00125 
00126     // Event dispatcher
00127     XmlRpcDispatch _disp;
00128 
00129   };    // class XmlRpcClient
00130 
00131 }       // namespace XmlRpc
00132 
00133 #endif  // _XMLRPCCLIENT_H_


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley
autogenerated on Tue Mar 7 2017 03:44:43