llsdmessagebuilder.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * @file llsdmessagebuilder.h
  3. * @brief Declaration of LLSDMessageBuilder class.
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLSDMESSAGEBUILDER_H
  33. #define LL_LLSDMESSAGEBUILDER_H
  34. #include <map>
  35. #include "llmessagebuilder.h"
  36. #include "llsd.h"
  37. class LLMessageTemplate;
  38. class LLMsgData;
  39. class LLSDMessageBuilder final : public LLMessageBuilder
  40. {
  41. protected:
  42. LOG_CLASS(LLSDMessageBuilder);
  43. public:
  44. LLSDMessageBuilder();
  45. void newMessage(const char* name) override;
  46. void nextBlock(const char* blockname) override;
  47. // *TODO: Babbage: remove this horror...
  48. LL_INLINE bool removeLastBlock() override { return false; }
  49. /** All add* methods expect pointers to canonical varname strings. */
  50. void addBinaryData(const char* varname, const void* data,
  51. S32 size) override;
  52. void addBool(const char* varname, bool b) override;
  53. void addS8(const char* varname, S8 s) override;
  54. void addU8(const char* varname, U8 u) override;
  55. void addS16(const char* varname, S16 i) override;
  56. void addU16(const char* varname, U16 i) override;
  57. void addF32(const char* varname, F32 f) override;
  58. void addS32(const char* varname, S32 s) override;
  59. void addU32(const char* varname, U32 u) override;
  60. void addU64(const char* varname, U64 lu) override;
  61. void addF64(const char* varname, F64 d) override;
  62. void addVector3(const char* varname, const LLVector3& vec) override;
  63. void addVector4(const char* varname, const LLVector4& vec) override;
  64. void addVector3d(const char* varname, const LLVector3d& vec) override;
  65. void addQuat(const char* varname, const LLQuaternion& quat) override;
  66. void addUUID(const char* varname, const LLUUID& uuid) override;
  67. void addIPAddr(const char* varname, U32 ip) override;
  68. void addIPPort(const char* varname, U16 port) override;
  69. void addString(const char* varname, const char* s) override;
  70. void addString(const char* varname, const std::string& s) override;
  71. LL_INLINE bool isMessageFull(const char*) const override
  72. {
  73. return false;
  74. }
  75. LL_INLINE void compressMessage(U8*&, U32&) override {}
  76. LL_INLINE bool isBuilt() const override { return mSBuilt; }
  77. LL_INLINE bool isClear() const override { return mSClear; }
  78. // Null implementation which returns 0
  79. LL_INLINE U32 buildMessage(U8*, U32, U8) override { return 0; }
  80. void clearMessage() override;
  81. // *TODO: babbage: remove this horror.
  82. LL_INLINE void setBuilt(bool b) override { mSBuilt = b; }
  83. // Babbage: size is unknown as message stored as LLSD. Return non-zero if
  84. // pending data, as send can be skipped for 0 size. Return 1 to encourage
  85. // senders checking size against splitting message.
  86. LL_INLINE S32 getMessageSize() override { return mCurrentMessage.size() ? 1 : 0; }
  87. LL_INLINE const char* getMessageName() const override { return mCurrentMessageName.c_str(); }
  88. void copyFromMessageData(const LLMsgData& data) override;
  89. void copyFromLLSD(const LLSD& msg) override;
  90. LL_INLINE const LLSD& getMessage() const { return mCurrentMessage; }
  91. private:
  92. /* mCurrentMessage is of the following format:
  93. mCurrentMessage = { 'block_name1' : [ { 'block1_field1' : 'b1f1_data',
  94. 'block1_field2' : 'b1f2_data',
  95. ...
  96. 'block1_fieldn' : 'b1fn_data'},
  97. { 'block2_field1' : 'b2f1_data',
  98. 'block2_field2' : 'b2f2_data',
  99. ...
  100. 'block2_fieldn' : 'b2fn_data'},
  101. ...
  102. { 'blockm_field1' : 'bmf1_data',
  103. 'blockm_field2' : 'bmf2_data',
  104. ...
  105. 'blockm_fieldn' : 'bmfn_data'} ],
  106. 'block_name2' : ...,
  107. ...
  108. 'block_namem' }
  109. */
  110. LLSD mCurrentMessage;
  111. LLSD* mCurrentBlock;
  112. std::string mCurrentMessageName;
  113. std::string mCurrentBlockName;
  114. bool mSBuilt;
  115. bool mSClear;
  116. };
  117. #endif // LL_LLSDMESSAGEBUILDER_H