diff options
Diffstat (limited to 'linden/indra/llmessage/llsdmessagebuilder.cpp')
-rwxr-xr-x | linden/indra/llmessage/llsdmessagebuilder.cpp | 281 |
1 files changed, 281 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llsdmessagebuilder.cpp b/linden/indra/llmessage/llsdmessagebuilder.cpp new file mode 100755 index 0000000..b7deb48 --- /dev/null +++ b/linden/indra/llmessage/llsdmessagebuilder.cpp | |||
@@ -0,0 +1,281 @@ | |||
1 | #include "linden_common.h" | ||
2 | |||
3 | #include "llsdmessagebuilder.h" | ||
4 | |||
5 | #include "llmessagetemplate.h" | ||
6 | #include "llquaternion.h" | ||
7 | #include "llsdutil.h" | ||
8 | #include "llsdserialize.h" | ||
9 | #include "u64.h" | ||
10 | #include "v3dmath.h" | ||
11 | #include "v3math.h" | ||
12 | #include "v4math.h" | ||
13 | |||
14 | LLSDMessageBuilder::LLSDMessageBuilder() : | ||
15 | mCurrentMessage(LLSD::emptyMap()), | ||
16 | mCurrentBlock(NULL), | ||
17 | mCurrentMessageName(""), | ||
18 | mCurrentBlockName(""), | ||
19 | mbSBuilt(FALSE), | ||
20 | mbSClear(TRUE) | ||
21 | { | ||
22 | } | ||
23 | |||
24 | //virtual | ||
25 | LLSDMessageBuilder::~LLSDMessageBuilder() | ||
26 | { | ||
27 | } | ||
28 | |||
29 | |||
30 | // virtual | ||
31 | void LLSDMessageBuilder::newMessage(const char *name) | ||
32 | { | ||
33 | mbSBuilt = FALSE; | ||
34 | mbSClear = FALSE; | ||
35 | |||
36 | mCurrentMessage = LLSD::emptyMap(); | ||
37 | mCurrentMessageName = (char *)name; | ||
38 | } | ||
39 | |||
40 | // virtual | ||
41 | void LLSDMessageBuilder::clearMessage() | ||
42 | { | ||
43 | mbSBuilt = FALSE; | ||
44 | mbSClear = TRUE; | ||
45 | |||
46 | mCurrentMessage = LLSD::emptyMap(); | ||
47 | mCurrentMessageName = ""; | ||
48 | } | ||
49 | |||
50 | // virtual | ||
51 | void LLSDMessageBuilder::nextBlock(const char* blockname) | ||
52 | { | ||
53 | LLSD& block = mCurrentMessage[blockname]; | ||
54 | if(block.isUndefined()) | ||
55 | { | ||
56 | block[0] = LLSD::emptyMap(); | ||
57 | mCurrentBlock = &(block[0]); | ||
58 | } | ||
59 | else if(block.isArray()) | ||
60 | { | ||
61 | block[block.size()] = LLSD::emptyMap(); | ||
62 | mCurrentBlock = &(block[block.size() - 1]); | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | llerrs << "existing block not array" << llendl; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | // TODO: Remove this horror... | ||
71 | BOOL LLSDMessageBuilder::removeLastBlock() | ||
72 | { | ||
73 | /* TODO: finish implementing this */ | ||
74 | return FALSE; | ||
75 | } | ||
76 | |||
77 | void LLSDMessageBuilder::addBinaryData(const char *varname, | ||
78 | const void *data, S32 size) | ||
79 | { | ||
80 | std::vector<U8> v; | ||
81 | v.resize(size); | ||
82 | memcpy(&(v[0]), reinterpret_cast<const U8*>(data), size); | ||
83 | (*mCurrentBlock)[varname] = v; | ||
84 | } | ||
85 | |||
86 | void LLSDMessageBuilder::addS8(const char *varname, S8 v) | ||
87 | { | ||
88 | (*mCurrentBlock)[varname] = v; | ||
89 | } | ||
90 | |||
91 | void LLSDMessageBuilder::addU8(const char *varname, U8 v) | ||
92 | { | ||
93 | (*mCurrentBlock)[varname] = v; | ||
94 | } | ||
95 | |||
96 | void LLSDMessageBuilder::addS16(const char *varname, S16 v) | ||
97 | { | ||
98 | (*mCurrentBlock)[varname] = v; | ||
99 | } | ||
100 | |||
101 | void LLSDMessageBuilder::addU16(const char *varname, U16 v) | ||
102 | { | ||
103 | (*mCurrentBlock)[varname] = v; | ||
104 | } | ||
105 | |||
106 | void LLSDMessageBuilder::addF32(const char *varname, F32 v) | ||
107 | { | ||
108 | (*mCurrentBlock)[varname] = v; | ||
109 | } | ||
110 | |||
111 | void LLSDMessageBuilder::addS32(const char *varname, S32 v) | ||
112 | { | ||
113 | (*mCurrentBlock)[varname] = v; | ||
114 | } | ||
115 | |||
116 | void LLSDMessageBuilder::addU32(const char *varname, U32 v) | ||
117 | { | ||
118 | (*mCurrentBlock)[varname] = ll_sd_from_U32(v); | ||
119 | } | ||
120 | |||
121 | void LLSDMessageBuilder::addU64(const char *varname, U64 v) | ||
122 | { | ||
123 | (*mCurrentBlock)[varname] = ll_sd_from_U64(v); | ||
124 | } | ||
125 | |||
126 | void LLSDMessageBuilder::addF64(const char *varname, F64 v) | ||
127 | { | ||
128 | (*mCurrentBlock)[varname] = v; | ||
129 | } | ||
130 | |||
131 | void LLSDMessageBuilder::addIPAddr(const char *varname, U32 v) | ||
132 | { | ||
133 | (*mCurrentBlock)[varname] = ll_sd_from_ipaddr(v); | ||
134 | } | ||
135 | |||
136 | void LLSDMessageBuilder::addIPPort(const char *varname, U16 v) | ||
137 | { | ||
138 | (*mCurrentBlock)[varname] = v; | ||
139 | } | ||
140 | |||
141 | void LLSDMessageBuilder::addBOOL(const char* varname, BOOL v) | ||
142 | { | ||
143 | (*mCurrentBlock)[varname] = (v == TRUE); | ||
144 | } | ||
145 | |||
146 | void LLSDMessageBuilder::addString(const char* varname, const char* v) | ||
147 | { | ||
148 | if (v) | ||
149 | (*mCurrentBlock)[varname] = v; /* Flawfinder: ignore */ | ||
150 | else | ||
151 | (*mCurrentBlock)[varname] = ""; | ||
152 | } | ||
153 | |||
154 | void LLSDMessageBuilder::addString(const char* varname, const std::string& v) | ||
155 | { | ||
156 | if (v.size()) | ||
157 | (*mCurrentBlock)[varname] = v; | ||
158 | else | ||
159 | (*mCurrentBlock)[varname] = ""; | ||
160 | } | ||
161 | |||
162 | void LLSDMessageBuilder::addVector3(const char *varname, const LLVector3& v) | ||
163 | { | ||
164 | (*mCurrentBlock)[varname] = ll_sd_from_vector3(v); | ||
165 | } | ||
166 | |||
167 | void LLSDMessageBuilder::addVector4(const char *varname, const LLVector4& v) | ||
168 | { | ||
169 | (*mCurrentBlock)[varname] = ll_sd_from_vector4(v); | ||
170 | } | ||
171 | |||
172 | void LLSDMessageBuilder::addVector3d(const char *varname, const LLVector3d& v) | ||
173 | { | ||
174 | (*mCurrentBlock)[varname] = ll_sd_from_vector3d(v); | ||
175 | } | ||
176 | |||
177 | void LLSDMessageBuilder::addQuat(const char *varname, const LLQuaternion& v) | ||
178 | { | ||
179 | (*mCurrentBlock)[varname] = ll_sd_from_quaternion(v); | ||
180 | } | ||
181 | |||
182 | void LLSDMessageBuilder::addUUID(const char *varname, const LLUUID& v) | ||
183 | { | ||
184 | (*mCurrentBlock)[varname] = v; | ||
185 | } | ||
186 | |||
187 | void LLSDMessageBuilder::compressMessage(U8*& buf_ptr, U32& buffer_length) | ||
188 | { | ||
189 | } | ||
190 | |||
191 | BOOL LLSDMessageBuilder::isMessageFull(const char* blockname) const | ||
192 | { | ||
193 | return FALSE; | ||
194 | } | ||
195 | |||
196 | // make sure that all the desired data is in place and then copy the data | ||
197 | // into MAX_BUFFER_SIZEd buffer | ||
198 | U32 LLSDMessageBuilder::buildMessage(U8* buffer, U32 buffer_size) | ||
199 | { | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | void LLSDMessageBuilder::copyFromMessageData(const LLMsgData& data) | ||
204 | { | ||
205 | // copy the blocks | ||
206 | // counting variables used to encode multiple block info | ||
207 | S32 block_count = 0; | ||
208 | char *block_name = NULL; | ||
209 | |||
210 | // loop through msg blocks to loop through variables, totalling up size | ||
211 | // data and filling the new (send) message | ||
212 | LLMsgData::msg_blk_data_map_t::const_iterator iter = | ||
213 | data.mMemberBlocks.begin(); | ||
214 | LLMsgData::msg_blk_data_map_t::const_iterator end = | ||
215 | data.mMemberBlocks.end(); | ||
216 | for(; iter != end; ++iter) | ||
217 | { | ||
218 | const LLMsgBlkData* mbci = iter->second; | ||
219 | if(!mbci) continue; | ||
220 | |||
221 | // do we need to encode a block code? | ||
222 | if (block_count == 0) | ||
223 | { | ||
224 | block_count = mbci->mBlockNumber; | ||
225 | block_name = (char *)mbci->mName; | ||
226 | } | ||
227 | |||
228 | // counting down mutliple blocks | ||
229 | block_count--; | ||
230 | |||
231 | nextBlock(block_name); | ||
232 | |||
233 | // now loop through the variables | ||
234 | LLMsgBlkData::msg_var_data_map_t::const_iterator dit = mbci->mMemberVarData.begin(); | ||
235 | LLMsgBlkData::msg_var_data_map_t::const_iterator dend = mbci->mMemberVarData.end(); | ||
236 | |||
237 | for(; dit != dend; ++dit) | ||
238 | { | ||
239 | //const LLMsgVarData& mvci = *dit; | ||
240 | |||
241 | // TODO: Copy mvci data in to block: | ||
242 | // (*mCurrentBlock)[varname] = v; | ||
243 | } | ||
244 | } | ||
245 | } | ||
246 | |||
247 | //virtual | ||
248 | void LLSDMessageBuilder::copyFromLLSD(const LLSD& msg) | ||
249 | { | ||
250 | mCurrentMessage = msg; | ||
251 | llinfos << LLSDXMLStreamer(mCurrentMessage) << llendl; | ||
252 | } | ||
253 | |||
254 | const LLSD& LLSDMessageBuilder::getMessage() const | ||
255 | { | ||
256 | return mCurrentMessage; | ||
257 | } | ||
258 | |||
259 | //virtual | ||
260 | void LLSDMessageBuilder::setBuilt(BOOL b) { mbSBuilt = b; } | ||
261 | |||
262 | //virtual | ||
263 | BOOL LLSDMessageBuilder::isBuilt() const {return mbSBuilt;} | ||
264 | |||
265 | //virtual | ||
266 | BOOL LLSDMessageBuilder::isClear() const {return mbSClear;} | ||
267 | |||
268 | //virtual | ||
269 | S32 LLSDMessageBuilder::getMessageSize() | ||
270 | { | ||
271 | // babbage: size is unknown as message stored as LLSD. | ||
272 | // return non-zero if pending data, as send can be skipped for 0 size. | ||
273 | // return 1 to encourage senders checking size against splitting message. | ||
274 | return mCurrentMessage.size()? 1 : 0; | ||
275 | } | ||
276 | |||
277 | //virtual | ||
278 | const char* LLSDMessageBuilder::getMessageName() const | ||
279 | { | ||
280 | return mCurrentMessageName.c_str(); | ||
281 | } | ||