llxmlrpctransaction.h

Go to the documentation of this file.
00001 
00032 #ifndef LLXMLRPCTRANSACTION_H
00033 #define LLXMLRPCTRANSACTION_H
00034 
00035 #include <string>
00036 
00037 typedef struct _xmlrpc_request* XMLRPC_REQUEST;
00038 typedef struct _xmlrpc_value* XMLRPC_VALUE;
00039         // foward decl of types from xmlrpc.h (this usage is type safe)
00040 
00041 class LLXMLRPCValue
00042         // a c++ wrapper around XMLRPC_VALUE
00043 {
00044 public:
00045         LLXMLRPCValue()                                         : mV(NULL) { }
00046         LLXMLRPCValue(XMLRPC_VALUE value)       : mV(value) { }
00047         
00048         bool isValid() const;
00049         
00050         std::string     asString()      const;
00051         int                     asInt()         const;
00052         bool            asBool()        const;
00053         double          asDouble()      const;
00054 
00055         LLXMLRPCValue operator[](const char*) const;
00056         
00057         LLXMLRPCValue rewind();
00058         LLXMLRPCValue next();
00059 
00060         static LLXMLRPCValue createArray();
00061         static LLXMLRPCValue createStruct();
00062 
00063         void append(LLXMLRPCValue&);
00064         void appendString(const std::string&);
00065         void appendInt(int);
00066         void appendBool(bool);
00067         void appendDouble(double);
00068         void appendValue(LLXMLRPCValue&);
00069 
00070         void append(const char*, LLXMLRPCValue&);
00071         void appendString(const char*, const std::string&);
00072         void appendInt(const char*, int);
00073         void appendBool(const char*, bool);
00074         void appendDouble(const char*, double);
00075         void appendValue(const char*, LLXMLRPCValue&);
00076         
00077         void free();
00078                 // only call this on the top level created value
00079         
00080         XMLRPC_VALUE getValue() const;
00081         
00082 private:
00083         XMLRPC_VALUE mV;
00084 };
00085 
00086 
00087 class LLXMLRPCTransaction
00088         // an asynchronous request and respones via XML-RPC
00089 {
00090 public:
00091         LLXMLRPCTransaction(const std::string& uri,
00092                 XMLRPC_REQUEST request, bool useGzip = true);
00093                 // does not take ownership of the request object
00094                 // request can be freed as soon as the transaction is constructed
00095 
00096         LLXMLRPCTransaction(const std::string& uri,
00097                 const std::string& method, LLXMLRPCValue params, bool useGzip = true);
00098                 // *does* take control of the request value, you must not free it
00099                 
00100         ~LLXMLRPCTransaction();
00101         
00102         typedef enum {
00103                 StatusNotStarted,
00104                 StatusStarted,
00105                 StatusDownloading,
00106                 StatusComplete,
00107                 StatusCURLError,
00108                 StatusXMLRPCError,
00109                 StatusOtherError
00110         } Status;
00111 
00112         bool process();
00113                 // run the request a little, returns true when done
00114                 
00115         Status status(int* curlCode);
00116                 // return status, and extended CURL code, if code isn't null
00117         std::string statusMessage();
00118                 // return a message string, suitable for showing the user
00119         std::string statusURI();
00120                 // return a URI for the user with more information
00121                 // can be empty
00122 
00123         XMLRPC_REQUEST response();
00124         LLXMLRPCValue responseValue();
00125                 // only valid if StatusComplete, otherwise NULL
00126                 // retains ownership of the result object, don't free it
00127         
00128         F64 transferRate();
00129                 // only valid if StsatusComplete, otherwise 0.0
00130                 
00131 private:
00132         class Impl;
00133         Impl& impl;
00134 };
00135 
00136 
00137 
00138 #endif // LLXMLRPCTRANSACTION_H

Generated on Thu Jul 1 06:09:48 2010 for Second Life Viewer by  doxygen 1.4.7