lltemplatemessagebuilder.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /**
  2. * @file lltemplatemessagebuilder.h
  3. * @brief Declaration of LLTemplateMessageBuilder 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_LLTEMPLATEMESSAGEBUILDER_H
  33. #define LL_LLTEMPLATEMESSAGEBUILDER_H
  34. #include <map>
  35. #include "llmessagebuilder.h"
  36. #include "llpreprocessor.h"
  37. class LLMsgData;
  38. class LLMessageTemplate;
  39. class LLMsgBlkData;
  40. class LLMessageTemplate;
  41. class LLTemplateMessageBuilder : public LLMessageBuilder
  42. {
  43. protected:
  44. LOG_CLASS(LLTemplateMessageBuilder);
  45. public:
  46. typedef std::map<const char*, LLMessageTemplate*> template_name_map_t;
  47. LLTemplateMessageBuilder(const template_name_map_t&);
  48. virtual ~LLTemplateMessageBuilder();
  49. virtual void newMessage(const char* name);
  50. virtual void nextBlock(const char* blockname);
  51. // *TODO: Babbage: remove this horror...
  52. virtual bool removeLastBlock();
  53. /** All add* methods expect pointers to canonical varname strings. */
  54. virtual void addBinaryData(const char *varname, const void* data,
  55. S32 size);
  56. virtual void addBool(const char* varname, bool b);
  57. virtual void addS8(const char* varname, S8 s);
  58. virtual void addU8(const char* varname, U8 u);
  59. virtual void addS16(const char* varname, S16 i);
  60. virtual void addU16(const char* varname, U16 i);
  61. virtual void addF32(const char* varname, F32 f);
  62. virtual void addS32(const char* varname, S32 s);
  63. virtual void addU32(const char* varname, U32 u);
  64. virtual void addU64(const char* varname, U64 lu);
  65. virtual void addF64(const char* varname, F64 d);
  66. virtual void addVector3(const char* varname, const LLVector3& vec);
  67. virtual void addVector4(const char* varname, const LLVector4& vec);
  68. virtual void addVector3d(const char* varname, const LLVector3d& vec);
  69. virtual void addQuat(const char* varname, const LLQuaternion& quat);
  70. virtual void addUUID(const char* varname, const LLUUID& uuid);
  71. virtual void addIPAddr(const char* varname, U32 ip);
  72. virtual void addIPPort(const char* varname, U16 port);
  73. virtual void addString(const char* varname, const char* s);
  74. virtual void addString(const char* varname, const std::string& s);
  75. virtual bool isMessageFull(const char* blockname) const;
  76. virtual void compressMessage(U8*& buf_ptr, U32& buffer_length);
  77. LL_INLINE virtual bool isBuilt() const { return mSBuilt; }
  78. LL_INLINE virtual bool isClear() const { return mSClear; }
  79. // Returns the built message size
  80. virtual U32 buildMessage(U8* buffer, U32 buffer_size, U8 offset_to_data);
  81. virtual void clearMessage();
  82. // *TODO: babbage: remove this horror.
  83. LL_INLINE virtual void setBuilt(bool b) { mSBuilt = b; }
  84. LL_INLINE virtual S32 getMessageSize() { return mCurrentSendTotal; }
  85. LL_INLINE virtual const char* getMessageName() const { return mCurrentSMessageName; }
  86. virtual void copyFromMessageData(const LLMsgData& data);
  87. virtual void copyFromLLSD(const LLSD&) {}
  88. LL_INLINE LLMsgData* getCurrentMessage() const { return mCurrentSMessageData; }
  89. private:
  90. void addData(const char* varname, const void* data, EMsgVariableType type,
  91. S32 size);
  92. void addData(const char* varname, const void* data, EMsgVariableType type);
  93. private:
  94. LLMsgData* mCurrentSMessageData;
  95. const LLMessageTemplate* mCurrentSMessageTemplate;
  96. LLMsgBlkData* mCurrentSDataBlock;
  97. char* mCurrentSMessageName;
  98. char* mCurrentSBlockName;
  99. const template_name_map_t& mMessageTemplates;
  100. S32 mCurrentSendTotal;
  101. bool mSBuilt;
  102. bool mSClear;
  103. };
  104. #endif // LL_LLTEMPLATEMESSAGEBUILDER_H