PageRenderTime 39ms CodeModel.GetById 14ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llxmlrpctransaction.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 136 lines | 68 code | 28 blank | 40 comment | 0 complexity | 1720d833e5b0d77eff0eaeef6dc2928a MD5 | raw file
  1/** 
  2 * @file llxmlrpctransaction.h
  3 * @brief LLXMLRPCTransaction and related class header file
  4 *
  5 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LLXMLRPCTRANSACTION_H
 28#define LLXMLRPCTRANSACTION_H
 29
 30#include <string>
 31
 32typedef struct _xmlrpc_request* XMLRPC_REQUEST;
 33typedef struct _xmlrpc_value* XMLRPC_VALUE;
 34	// foward decl of types from xmlrpc.h (this usage is type safe)
 35class LLCertificate;
 36
 37class LLXMLRPCValue
 38	// a c++ wrapper around XMLRPC_VALUE
 39{
 40public:
 41	LLXMLRPCValue()						: mV(NULL) { }
 42	LLXMLRPCValue(XMLRPC_VALUE value)	: mV(value) { }
 43	
 44	bool isValid() const;
 45	
 46	std::string	asString()	const;
 47	int			asInt()		const;
 48	bool		asBool()	const;
 49	double		asDouble()	const;
 50
 51	LLXMLRPCValue operator[](const char*) const;
 52	
 53	LLXMLRPCValue rewind();
 54	LLXMLRPCValue next();
 55
 56	static LLXMLRPCValue createArray();
 57	static LLXMLRPCValue createStruct();
 58
 59	void append(LLXMLRPCValue&);
 60	void appendString(const std::string&);
 61	void appendInt(int);
 62	void appendBool(bool);
 63	void appendDouble(double);
 64	void appendValue(LLXMLRPCValue&);
 65
 66	void append(const char*, LLXMLRPCValue&);
 67	void appendString(const char*, const std::string&);
 68	void appendInt(const char*, int);
 69	void appendBool(const char*, bool);
 70	void appendDouble(const char*, double);
 71	void appendValue(const char*, LLXMLRPCValue&);
 72	
 73	void cleanup();
 74		// only call this on the top level created value
 75	
 76	XMLRPC_VALUE getValue() const;
 77	
 78private:
 79	XMLRPC_VALUE mV;
 80};
 81
 82
 83class LLXMLRPCTransaction
 84	// an asynchronous request and respones via XML-RPC
 85{
 86public:
 87	LLXMLRPCTransaction(const std::string& uri,
 88		XMLRPC_REQUEST request, bool useGzip = true);
 89		// does not take ownership of the request object
 90		// request can be freed as soon as the transaction is constructed
 91
 92	LLXMLRPCTransaction(const std::string& uri,
 93		const std::string& method, LLXMLRPCValue params, bool useGzip = true);
 94		// *does* take control of the request value, you must not free it
 95		
 96	~LLXMLRPCTransaction();
 97	
 98	typedef enum e_status {
 99		StatusNotStarted,
100		StatusStarted,
101		StatusDownloading,
102		StatusComplete,
103		StatusCURLError,
104		StatusXMLRPCError,
105		StatusOtherError
106	} EStatus;
107
108	bool process();
109		// run the request a little, returns true when done
110		
111	EStatus status(int* curlCode);
112		// return status, and extended CURL code, if code isn't null
113	
114	LLPointer<LLCertificate> getErrorCert();
115	std::string statusMessage();
116		// return a message string, suitable for showing the user
117	std::string statusURI();
118		// return a URI for the user with more information
119		// can be empty
120
121	XMLRPC_REQUEST response();
122	LLXMLRPCValue responseValue();
123		// only valid if StatusComplete, otherwise NULL
124		// retains ownership of the result object, don't free it
125	
126	F64 transferRate();
127		// only valid if StsatusComplete, otherwise 0.0
128		
129private:
130	class Impl;
131	Impl& impl;
132};
133
134
135
136#endif // LLXMLRPCTRANSACTION_H