Main Page   Class Hierarchy   Compound List   File List   Compound Members  

XmlRpcClient.h

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 
00019 namespace XmlRpc {
00020 
00021   // Arguments and results are represented by XmlRpcValues
00022   class XmlRpcValue;
00023 
00025   class XmlRpcClient : public XmlRpcSource {
00026   public:
00027     // Static data
00028     static const char REQUEST_BEGIN[];
00029     static const char REQUEST_END_METHODNAME[];
00030     static const char PARAMS_TAG[];
00031     static const char PARAMS_ETAG[];
00032     static const char PARAM_TAG[];
00033     static const char PARAM_ETAG[];
00034     static const char REQUEST_END[];
00035     // Result tags
00036     static const char METHODRESPONSE_TAG[];
00037     static const char FAULT_TAG[];
00038 
00043     XmlRpcClient(const char* host, int port, const char* uri=0);
00044 
00046     virtual ~XmlRpcClient();
00047 
00058     bool execute(const char* method, XmlRpcValue const& params, XmlRpcValue& result);
00059 
00061     bool isFault() const { return _isFault; }
00062 
00063 
00064     // XmlRpcSource interface implementation
00066     virtual void close();
00067 
00071     virtual unsigned handleEvent(unsigned eventType);
00072 
00073   protected:
00074     // Execution processing helpers
00075     virtual bool doConnect();
00076     virtual bool setupConnection();
00077 
00078     virtual bool generateRequest(const char* method, XmlRpcValue const& params);
00079     virtual std::string generateHeader(std::string const& body);
00080     virtual bool writeRequest();
00081     virtual bool readHeader();
00082     virtual bool readResponse();
00083     virtual bool parseResponse(XmlRpcValue& result);
00084 
00085     // Possible IO states for the connection
00086     enum ClientConnectionState { NO_CONNECTION, CONNECTING, WRITE_REQUEST, READ_HEADER, READ_RESPONSE, IDLE };
00087     ClientConnectionState _connectionState;
00088 
00089     // Server location
00090     std::string _host;
00091     std::string _uri;
00092     int _port;
00093 
00094     // The xml-encoded request, http header of response, and response xml
00095     std::string _request;
00096     std::string _header;
00097     std::string _response;
00098 
00099     // Number of times the client has attempted to send the request
00100     int _sendAttempts;
00101 
00102     // Number of bytes of the request that have been written to the socket so far
00103     int _bytesWritten;
00104 
00105     // True if we are currently executing a request. If you want to multithread,
00106     // each thread should have its own client.
00107     bool _executing;
00108 
00109     // True if the server closed the connection
00110     bool _eof;
00111 
00112 
00113     // True if a fault response was returned by the server
00114 
00115     bool _isFault;
00116 
00117 
00118     // Number of bytes expected in the response body (parsed from response header)
00119     int _contentLength;
00120 
00121     // Event dispatcher
00122     XmlRpcDispatch _disp;
00123 
00124   };    // class XmlRpcClient
00125 
00126 }       // namespace XmlRpc
00127 
00128 #endif  // _XMLRPCCLIENT_H_

Generated on Thu Mar 6 11:32:57 2003 for XmlRpc++ by doxygen1.3-rc3