PageRenderTime 131ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llmessagetemplate.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 192 lines | 144 code | 19 blank | 29 comment | 25 complexity | e774fa9f414ded2c859d77f9d9bfbd67 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmessagetemplate.cpp
  3. * @brief Implementation of message template classes.
  4. *
  5. * $LicenseInfo:firstyear=2007&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. #include "linden_common.h"
  27. #include "llmessagetemplate.h"
  28. #include "message.h"
  29. void LLMsgVarData::addData(const void *data, S32 size, EMsgVariableType type, S32 data_size)
  30. {
  31. mSize = size;
  32. mDataSize = data_size;
  33. if ( (type != MVT_VARIABLE) && (type != MVT_FIXED)
  34. && (mType != MVT_VARIABLE) && (mType != MVT_FIXED))
  35. {
  36. if (mType != type)
  37. {
  38. llwarns << "Type mismatch in LLMsgVarData::addData for " << mName
  39. << llendl;
  40. }
  41. }
  42. if(size)
  43. {
  44. delete[] mData; // Delete it if it already exists
  45. mData = new U8[size];
  46. htonmemcpy(mData, data, mType, size);
  47. }
  48. }
  49. void LLMsgData::addDataFast(char *blockname, char *varname, const void *data, S32 size, EMsgVariableType type, S32 data_size)
  50. {
  51. // remember that if the blocknumber is > 0 then the number is appended to the name
  52. char *namep = (char *)blockname;
  53. LLMsgBlkData* block_data = mMemberBlocks[namep];
  54. if (block_data->mBlockNumber)
  55. {
  56. namep += block_data->mBlockNumber;
  57. block_data->addData(varname, data, size, type, data_size);
  58. }
  59. else
  60. {
  61. block_data->addData(varname, data, size, type, data_size);
  62. }
  63. }
  64. // LLMessageVariable functions and friends
  65. std::ostream& operator<<(std::ostream& s, LLMessageVariable &msg)
  66. {
  67. s << "\t\t" << msg.mName << " (";
  68. switch (msg.mType)
  69. {
  70. case MVT_FIXED:
  71. s << "Fixed, " << msg.mSize << " bytes total)\n";
  72. break;
  73. case MVT_VARIABLE:
  74. s << "Variable, " << msg.mSize << " bytes of size info)\n";
  75. break;
  76. default:
  77. s << "Unknown\n";
  78. break;
  79. }
  80. return s;
  81. }
  82. // LLMessageBlock functions and friends
  83. std::ostream& operator<<(std::ostream& s, LLMessageBlock &msg)
  84. {
  85. s << "\t" << msg.mName << " (";
  86. switch (msg.mType)
  87. {
  88. case MBT_SINGLE:
  89. s << "Fixed";
  90. break;
  91. case MBT_MULTIPLE:
  92. s << "Multiple - " << msg.mNumber << " copies";
  93. break;
  94. case MBT_VARIABLE:
  95. s << "Variable";
  96. break;
  97. default:
  98. s << "Unknown";
  99. break;
  100. }
  101. if (msg.mTotalSize != -1)
  102. {
  103. s << ", " << msg.mTotalSize << " bytes each, " << msg.mNumber*msg.mTotalSize << " bytes total)\n";
  104. }
  105. else
  106. {
  107. s << ")\n";
  108. }
  109. for (LLMessageBlock::message_variable_map_t::iterator iter = msg.mMemberVariables.begin();
  110. iter != msg.mMemberVariables.end(); iter++)
  111. {
  112. LLMessageVariable& ci = *(*iter);
  113. s << ci;
  114. }
  115. return s;
  116. }
  117. // LLMessageTemplate functions and friends
  118. std::ostream& operator<<(std::ostream& s, LLMessageTemplate &msg)
  119. {
  120. switch (msg.mFrequency)
  121. {
  122. case MFT_HIGH:
  123. s << "========================================\n" << "Message #" << msg.mMessageNumber << "\n" << msg.mName << " (";
  124. s << "High";
  125. break;
  126. case MFT_MEDIUM:
  127. s << "========================================\n" << "Message #";
  128. s << (msg.mMessageNumber & 0xFF) << "\n" << msg.mName << " (";
  129. s << "Medium";
  130. break;
  131. case MFT_LOW:
  132. s << "========================================\n" << "Message #";
  133. s << (msg.mMessageNumber & 0xFFFF) << "\n" << msg.mName << " (";
  134. s << "Low";
  135. break;
  136. default:
  137. s << "Unknown";
  138. break;
  139. }
  140. if (msg.mTotalSize != -1)
  141. {
  142. s << ", " << msg.mTotalSize << " bytes total)\n";
  143. }
  144. else
  145. {
  146. s << ")\n";
  147. }
  148. for (LLMessageTemplate::message_block_map_t::iterator iter = msg.mMemberBlocks.begin();
  149. iter != msg.mMemberBlocks.end(); iter++)
  150. {
  151. LLMessageBlock* ci = *iter;
  152. s << *ci;
  153. }
  154. return s;
  155. }
  156. void LLMessageTemplate::banUdp()
  157. {
  158. static const char* deprecation[] = {
  159. "NotDeprecated",
  160. "Deprecated",
  161. "UDPDeprecated",
  162. "UDPBlackListed"
  163. };
  164. if (mDeprecation != MD_DEPRECATED)
  165. {
  166. llinfos << "Setting " << mName << " to UDPBlackListed was " << deprecation[mDeprecation] << llendl;
  167. mDeprecation = MD_UDPBLACKLISTED;
  168. }
  169. else
  170. {
  171. llinfos << mName << " is already more deprecated than UDPBlackListed" << llendl;
  172. }
  173. }