PageRenderTime 164ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LLXMLRPCTRANSACTION_H
  27. #define LLXMLRPCTRANSACTION_H
  28. #include <string>
  29. typedef struct _xmlrpc_request* XMLRPC_REQUEST;
  30. typedef struct _xmlrpc_value* XMLRPC_VALUE;
  31. // foward decl of types from xmlrpc.h (this usage is type safe)
  32. class LLCertificate;
  33. class LLXMLRPCValue
  34. // a c++ wrapper around XMLRPC_VALUE
  35. {
  36. public:
  37. LLXMLRPCValue() : mV(NULL) { }
  38. LLXMLRPCValue(XMLRPC_VALUE value) : mV(value) { }
  39. bool isValid() const;
  40. std::string asString() const;
  41. int asInt() const;
  42. bool asBool() const;
  43. double asDouble() const;
  44. LLXMLRPCValue operator[](const char*) const;
  45. LLXMLRPCValue rewind();
  46. LLXMLRPCValue next();
  47. static LLXMLRPCValue createArray();
  48. static LLXMLRPCValue createStruct();
  49. void append(LLXMLRPCValue&);
  50. void appendString(const std::string&);
  51. void appendInt(int);
  52. void appendBool(bool);
  53. void appendDouble(double);
  54. void appendValue(LLXMLRPCValue&);
  55. void append(const char*, LLXMLRPCValue&);
  56. void appendString(const char*, const std::string&);
  57. void appendInt(const char*, int);
  58. void appendBool(const char*, bool);
  59. void appendDouble(const char*, double);
  60. void appendValue(const char*, LLXMLRPCValue&);
  61. void cleanup();
  62. // only call this on the top level created value
  63. XMLRPC_VALUE getValue() const;
  64. private:
  65. XMLRPC_VALUE mV;
  66. };
  67. class LLXMLRPCTransaction
  68. // an asynchronous request and respones via XML-RPC
  69. {
  70. public:
  71. LLXMLRPCTransaction(const std::string& uri,
  72. XMLRPC_REQUEST request, bool useGzip = true);
  73. // does not take ownership of the request object
  74. // request can be freed as soon as the transaction is constructed
  75. LLXMLRPCTransaction(const std::string& uri,
  76. const std::string& method, LLXMLRPCValue params, bool useGzip = true);
  77. // *does* take control of the request value, you must not free it
  78. ~LLXMLRPCTransaction();
  79. typedef enum e_status {
  80. StatusNotStarted,
  81. StatusStarted,
  82. StatusDownloading,
  83. StatusComplete,
  84. StatusCURLError,
  85. StatusXMLRPCError,
  86. StatusOtherError
  87. } EStatus;
  88. bool process();
  89. // run the request a little, returns true when done
  90. EStatus status(int* curlCode);
  91. // return status, and extended CURL code, if code isn't null
  92. LLPointer<LLCertificate> getErrorCert();
  93. std::string statusMessage();
  94. // return a message string, suitable for showing the user
  95. std::string statusURI();
  96. // return a URI for the user with more information
  97. // can be empty
  98. XMLRPC_REQUEST response();
  99. LLXMLRPCValue responseValue();
  100. // only valid if StatusComplete, otherwise NULL
  101. // retains ownership of the result object, don't free it
  102. F64 transferRate();
  103. // only valid if StsatusComplete, otherwise 0.0
  104. private:
  105. class Impl;
  106. Impl& impl;
  107. };
  108. #endif // LLXMLRPCTRANSACTION_H