Annotation of /linden_release/linden/indra/llmessage/llsdmessagebuilder.cpp
Parent Directory
|
Revision Log
Revision 100 - (view) (download)
| 1 : | mjm | 57 | /** |
| 2 : | * @file llsdmessagebuilder.cpp | ||
| 3 : | * @brief LLSDMessageBuilder class implementation. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 100 | * Copyright (c) 2007-2009, Linden Research, Inc. |
| 8 : | mjm | 57 | * |
| 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 http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 21 : | * | ||
| 22 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 23 : | * that you have read and understood your obligations described above, | ||
| 24 : | * and agree to abide by those obligations. | ||
| 25 : | * | ||
| 26 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 27 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 28 : | * COMPLETENESS OR PERFORMANCE. | ||
| 29 : | * $/LicenseInfo$ | ||
| 30 : | */ | ||
| 31 : | |||
| 32 : | #include "linden_common.h" | ||
| 33 : | |||
| 34 : | #include "llsdmessagebuilder.h" | ||
| 35 : | |||
| 36 : | #include "llmessagetemplate.h" | ||
| 37 : | #include "llquaternion.h" | ||
| 38 : | #include "llsdutil.h" | ||
| 39 : | #include "llsdserialize.h" | ||
| 40 : | #include "u64.h" | ||
| 41 : | #include "v3dmath.h" | ||
| 42 : | #include "v3math.h" | ||
| 43 : | #include "v4math.h" | ||
| 44 : | |||
| 45 : | LLSDMessageBuilder::LLSDMessageBuilder() : | ||
| 46 : | mCurrentMessage(LLSD::emptyMap()), | ||
| 47 : | mCurrentBlock(NULL), | ||
| 48 : | mCurrentMessageName(""), | ||
| 49 : | mCurrentBlockName(""), | ||
| 50 : | mbSBuilt(FALSE), | ||
| 51 : | mbSClear(TRUE) | ||
| 52 : | { | ||
| 53 : | } | ||
| 54 : | |||
| 55 : | //virtual | ||
| 56 : | LLSDMessageBuilder::~LLSDMessageBuilder() | ||
| 57 : | { | ||
| 58 : | } | ||
| 59 : | |||
| 60 : | |||
| 61 : | // virtual | ||
| 62 : | void LLSDMessageBuilder::newMessage(const char* name) | ||
| 63 : | { | ||
| 64 : | mbSBuilt = FALSE; | ||
| 65 : | mbSClear = FALSE; | ||
| 66 : | |||
| 67 : | mCurrentMessage = LLSD::emptyMap(); | ||
| 68 : | mCurrentMessageName = (char*)name; | ||
| 69 : | } | ||
| 70 : | |||
| 71 : | // virtual | ||
| 72 : | void LLSDMessageBuilder::clearMessage() | ||
| 73 : | { | ||
| 74 : | mbSBuilt = FALSE; | ||
| 75 : | mbSClear = TRUE; | ||
| 76 : | |||
| 77 : | mCurrentMessage = LLSD::emptyMap(); | ||
| 78 : | mCurrentMessageName = ""; | ||
| 79 : | } | ||
| 80 : | |||
| 81 : | // virtual | ||
| 82 : | void LLSDMessageBuilder::nextBlock(const char* blockname) | ||
| 83 : | { | ||
| 84 : | LLSD& block = mCurrentMessage[blockname]; | ||
| 85 : | if(block.isUndefined()) | ||
| 86 : | { | ||
| 87 : | block[0] = LLSD::emptyMap(); | ||
| 88 : | mCurrentBlock = &(block[0]); | ||
| 89 : | } | ||
| 90 : | else if(block.isArray()) | ||
| 91 : | { | ||
| 92 : | block[block.size()] = LLSD::emptyMap(); | ||
| 93 : | mCurrentBlock = &(block[block.size() - 1]); | ||
| 94 : | } | ||
| 95 : | else | ||
| 96 : | { | ||
| 97 : | llerrs << "existing block not array" << llendl; | ||
| 98 : | } | ||
| 99 : | } | ||
| 100 : | |||
| 101 : | // TODO: Remove this horror... | ||
| 102 : | BOOL LLSDMessageBuilder::removeLastBlock() | ||
| 103 : | { | ||
| 104 : | /* TODO: finish implementing this */ | ||
| 105 : | return FALSE; | ||
| 106 : | } | ||
| 107 : | |||
| 108 : | void LLSDMessageBuilder::addBinaryData( | ||
| 109 : | const char* varname, | ||
| 110 : | const void* data, | ||
| 111 : | S32 size) | ||
| 112 : | { | ||
| 113 : | std::vector<U8> v; | ||
| 114 : | v.resize(size); | ||
| 115 : | memcpy(&(v[0]), reinterpret_cast<const U8*>(data), size); | ||
| 116 : | (*mCurrentBlock)[varname] = v; | ||
| 117 : | } | ||
| 118 : | |||
| 119 : | void LLSDMessageBuilder::addS8(const char* varname, S8 v) | ||
| 120 : | { | ||
| 121 : | (*mCurrentBlock)[varname] = v; | ||
| 122 : | } | ||
| 123 : | |||
| 124 : | void LLSDMessageBuilder::addU8(const char* varname, U8 v) | ||
| 125 : | { | ||
| 126 : | (*mCurrentBlock)[varname] = v; | ||
| 127 : | } | ||
| 128 : | |||
| 129 : | void LLSDMessageBuilder::addS16(const char* varname, S16 v) | ||
| 130 : | { | ||
| 131 : | (*mCurrentBlock)[varname] = v; | ||
| 132 : | } | ||
| 133 : | |||
| 134 : | void LLSDMessageBuilder::addU16(const char* varname, U16 v) | ||
| 135 : | { | ||
| 136 : | (*mCurrentBlock)[varname] = v; | ||
| 137 : | } | ||
| 138 : | |||
| 139 : | void LLSDMessageBuilder::addF32(const char* varname, F32 v) | ||
| 140 : | { | ||
| 141 : | (*mCurrentBlock)[varname] = v; | ||
| 142 : | } | ||
| 143 : | |||
| 144 : | void LLSDMessageBuilder::addS32(const char* varname, S32 v) | ||
| 145 : | { | ||
| 146 : | (*mCurrentBlock)[varname] = v; | ||
| 147 : | } | ||
| 148 : | |||
| 149 : | void LLSDMessageBuilder::addU32(const char* varname, U32 v) | ||
| 150 : | { | ||
| 151 : | (*mCurrentBlock)[varname] = ll_sd_from_U32(v); | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | void LLSDMessageBuilder::addU64(const char* varname, U64 v) | ||
| 155 : | { | ||
| 156 : | (*mCurrentBlock)[varname] = ll_sd_from_U64(v); | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | void LLSDMessageBuilder::addF64(const char* varname, F64 v) | ||
| 160 : | { | ||
| 161 : | (*mCurrentBlock)[varname] = v; | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | void LLSDMessageBuilder::addIPAddr(const char* varname, U32 v) | ||
| 165 : | { | ||
| 166 : | (*mCurrentBlock)[varname] = ll_sd_from_ipaddr(v); | ||
| 167 : | } | ||
| 168 : | |||
| 169 : | void LLSDMessageBuilder::addIPPort(const char* varname, U16 v) | ||
| 170 : | { | ||
| 171 : | (*mCurrentBlock)[varname] = v; | ||
| 172 : | } | ||
| 173 : | |||
| 174 : | void LLSDMessageBuilder::addBOOL(const char* varname, BOOL v) | ||
| 175 : | { | ||
| 176 : | (*mCurrentBlock)[varname] = (v == TRUE); | ||
| 177 : | } | ||
| 178 : | |||
| 179 : | void LLSDMessageBuilder::addString(const char* varname, const char* v) | ||
| 180 : | { | ||
| 181 : | if (v) | ||
| 182 : | (*mCurrentBlock)[varname] = v; /* Flawfinder: ignore */ | ||
| 183 : | else | ||
| 184 : | (*mCurrentBlock)[varname] = ""; | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | void LLSDMessageBuilder::addString(const char* varname, const std::string& v) | ||
| 188 : | { | ||
| 189 : | if (v.size()) | ||
| 190 : | (*mCurrentBlock)[varname] = v; | ||
| 191 : | else | ||
| 192 : | (*mCurrentBlock)[varname] = ""; | ||
| 193 : | } | ||
| 194 : | |||
| 195 : | void LLSDMessageBuilder::addVector3(const char* varname, const LLVector3& v) | ||
| 196 : | { | ||
| 197 : | (*mCurrentBlock)[varname] = ll_sd_from_vector3(v); | ||
| 198 : | } | ||
| 199 : | |||
| 200 : | void LLSDMessageBuilder::addVector4(const char* varname, const LLVector4& v) | ||
| 201 : | { | ||
| 202 : | (*mCurrentBlock)[varname] = ll_sd_from_vector4(v); | ||
| 203 : | } | ||
| 204 : | |||
| 205 : | void LLSDMessageBuilder::addVector3d(const char* varname, const LLVector3d& v) | ||
| 206 : | { | ||
| 207 : | (*mCurrentBlock)[varname] = ll_sd_from_vector3d(v); | ||
| 208 : | } | ||
| 209 : | |||
| 210 : | void LLSDMessageBuilder::addQuat(const char* varname, const LLQuaternion& v) | ||
| 211 : | { | ||
| 212 : | (*mCurrentBlock)[varname] = ll_sd_from_quaternion(v); | ||
| 213 : | } | ||
| 214 : | |||
| 215 : | void LLSDMessageBuilder::addUUID(const char* varname, const LLUUID& v) | ||
| 216 : | { | ||
| 217 : | (*mCurrentBlock)[varname] = v; | ||
| 218 : | } | ||
| 219 : | |||
| 220 : | void LLSDMessageBuilder::compressMessage(U8*& buf_ptr, U32& buffer_length) | ||
| 221 : | { | ||
| 222 : | } | ||
| 223 : | |||
| 224 : | BOOL LLSDMessageBuilder::isMessageFull(const char* blockname) const | ||
| 225 : | { | ||
| 226 : | return FALSE; | ||
| 227 : | } | ||
| 228 : | |||
| 229 : | U32 LLSDMessageBuilder::buildMessage(U8*, U32, U8) | ||
| 230 : | { | ||
| 231 : | return 0; | ||
| 232 : | } | ||
| 233 : | |||
| 234 : | void LLSDMessageBuilder::copyFromMessageData(const LLMsgData& data) | ||
| 235 : | { | ||
| 236 : | // copy the blocks | ||
| 237 : | // counting variables used to encode multiple block info | ||
| 238 : | S32 block_count = 0; | ||
| 239 : | char* block_name = NULL; | ||
| 240 : | |||
| 241 : | // loop through msg blocks to loop through variables, totalling up size | ||
| 242 : | // data and filling the new (send) message | ||
| 243 : | LLMsgData::msg_blk_data_map_t::const_iterator iter = | ||
| 244 : | data.mMemberBlocks.begin(); | ||
| 245 : | LLMsgData::msg_blk_data_map_t::const_iterator end = | ||
| 246 : | data.mMemberBlocks.end(); | ||
| 247 : | for(; iter != end; ++iter) | ||
| 248 : | { | ||
| 249 : | const LLMsgBlkData* mbci = iter->second; | ||
| 250 : | if(!mbci) continue; | ||
| 251 : | |||
| 252 : | // do we need to encode a block code? | ||
| 253 : | if (block_count == 0) | ||
| 254 : | { | ||
| 255 : | block_count = mbci->mBlockNumber; | ||
| 256 : | block_name = (char*)mbci->mName; | ||
| 257 : | } | ||
| 258 : | |||
| 259 : | // counting down mutliple blocks | ||
| 260 : | block_count--; | ||
| 261 : | |||
| 262 : | nextBlock(block_name); | ||
| 263 : | |||
| 264 : | // now loop through the variables | ||
| 265 : | LLMsgBlkData::msg_var_data_map_t::const_iterator dit = mbci->mMemberVarData.begin(); | ||
| 266 : | LLMsgBlkData::msg_var_data_map_t::const_iterator dend = mbci->mMemberVarData.end(); | ||
| 267 : | |||
| 268 : | for(; dit != dend; ++dit) | ||
| 269 : | { | ||
| 270 : | //const LLMsgVarData& mvci = *dit; | ||
| 271 : | |||
| 272 : | // TODO: Copy mvci data in to block: | ||
| 273 : | // (*mCurrentBlock)[varname] = v; | ||
| 274 : | } | ||
| 275 : | } | ||
| 276 : | } | ||
| 277 : | |||
| 278 : | //virtual | ||
| 279 : | void LLSDMessageBuilder::copyFromLLSD(const LLSD& msg) | ||
| 280 : | { | ||
| 281 : | mCurrentMessage = msg; | ||
| 282 : | lldebugs << LLSDNotationStreamer(mCurrentMessage) << llendl; | ||
| 283 : | } | ||
| 284 : | |||
| 285 : | const LLSD& LLSDMessageBuilder::getMessage() const | ||
| 286 : | { | ||
| 287 : | return mCurrentMessage; | ||
| 288 : | } | ||
| 289 : | |||
| 290 : | //virtual | ||
| 291 : | void LLSDMessageBuilder::setBuilt(BOOL b) { mbSBuilt = b; } | ||
| 292 : | |||
| 293 : | //virtual | ||
| 294 : | BOOL LLSDMessageBuilder::isBuilt() const {return mbSBuilt;} | ||
| 295 : | |||
| 296 : | //virtual | ||
| 297 : | BOOL LLSDMessageBuilder::isClear() const {return mbSClear;} | ||
| 298 : | |||
| 299 : | //virtual | ||
| 300 : | S32 LLSDMessageBuilder::getMessageSize() | ||
| 301 : | { | ||
| 302 : | // babbage: size is unknown as message stored as LLSD. | ||
| 303 : | // return non-zero if pending data, as send can be skipped for 0 size. | ||
| 304 : | // return 1 to encourage senders checking size against splitting message. | ||
| 305 : | return mCurrentMessage.size()? 1 : 0; | ||
| 306 : | } | ||
| 307 : | |||
| 308 : | //virtual | ||
| 309 : | const char* LLSDMessageBuilder::getMessageName() const | ||
| 310 : | { | ||
| 311 : | return mCurrentMessageName.c_str(); | ||
| 312 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

