llsdmessagebuilder.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llsdmessagebuilder.h"
00035 
00036 #include "llmessagetemplate.h"
00037 #include "llquaternion.h"
00038 #include "llsdutil.h"
00039 #include "llsdserialize.h"
00040 #include "u64.h"
00041 #include "v3dmath.h"
00042 #include "v3math.h"
00043 #include "v4math.h"
00044 
00045 LLSDMessageBuilder::LLSDMessageBuilder() :
00046         mCurrentMessage(LLSD::emptyMap()),
00047         mCurrentBlock(NULL),
00048         mCurrentMessageName(""),
00049         mCurrentBlockName(""),
00050         mbSBuilt(FALSE),
00051         mbSClear(TRUE)
00052 {
00053 }
00054 
00055 //virtual
00056 LLSDMessageBuilder::~LLSDMessageBuilder()
00057 {
00058 }
00059 
00060 
00061 // virtual
00062 void LLSDMessageBuilder::newMessage(const char* name)
00063 {
00064         mbSBuilt = FALSE;
00065         mbSClear = FALSE;
00066 
00067         mCurrentMessage = LLSD::emptyMap();
00068         mCurrentMessageName = (char*)name;
00069 }
00070 
00071 // virtual
00072 void LLSDMessageBuilder::clearMessage()
00073 {
00074         mbSBuilt = FALSE;
00075         mbSClear = TRUE;
00076 
00077         mCurrentMessage = LLSD::emptyMap();
00078         mCurrentMessageName = "";
00079 }
00080 
00081 // virtual
00082 void LLSDMessageBuilder::nextBlock(const char* blockname)
00083 {
00084         LLSD& block = mCurrentMessage[blockname];
00085         if(block.isUndefined())
00086         {
00087                 block[0] = LLSD::emptyMap();
00088                 mCurrentBlock = &(block[0]);
00089         }
00090         else if(block.isArray())
00091         {
00092                 block[block.size()] = LLSD::emptyMap();
00093                 mCurrentBlock = &(block[block.size() - 1]);
00094         }
00095         else
00096         {
00097                 llerrs << "existing block not array" << llendl;
00098         }
00099 }
00100 
00101 // TODO: Remove this horror...
00102 BOOL LLSDMessageBuilder::removeLastBlock()
00103 {
00104         /* TODO: finish implementing this */
00105         return FALSE;
00106 }
00107 
00108 void LLSDMessageBuilder::addBinaryData(
00109         const char* varname, 
00110         const void* data,
00111         S32 size)
00112 {
00113         std::vector<U8> v;
00114         v.resize(size);
00115         memcpy(&(v[0]), reinterpret_cast<const U8*>(data), size);
00116         (*mCurrentBlock)[varname] = v;
00117 }
00118 
00119 void LLSDMessageBuilder::addS8(const char* varname, S8 v)
00120 {
00121         (*mCurrentBlock)[varname] = v;
00122 }
00123 
00124 void LLSDMessageBuilder::addU8(const char* varname, U8 v)
00125 {
00126         (*mCurrentBlock)[varname] = v;
00127 }
00128 
00129 void LLSDMessageBuilder::addS16(const char* varname, S16 v)
00130 {
00131         (*mCurrentBlock)[varname] = v;
00132 }
00133 
00134 void LLSDMessageBuilder::addU16(const char* varname, U16 v)
00135 {
00136         (*mCurrentBlock)[varname] = v;
00137 }
00138 
00139 void LLSDMessageBuilder::addF32(const char* varname, F32 v)
00140 {
00141         (*mCurrentBlock)[varname] = v;
00142 }
00143 
00144 void LLSDMessageBuilder::addS32(const char* varname, S32 v)
00145 {
00146         (*mCurrentBlock)[varname] = v;
00147 }
00148 
00149 void LLSDMessageBuilder::addU32(const char* varname, U32 v)
00150 {
00151         (*mCurrentBlock)[varname] = ll_sd_from_U32(v);
00152 }
00153 
00154 void LLSDMessageBuilder::addU64(const char* varname, U64 v)
00155 {
00156         (*mCurrentBlock)[varname] = ll_sd_from_U64(v);
00157 }
00158 
00159 void LLSDMessageBuilder::addF64(const char* varname, F64 v)
00160 {
00161         (*mCurrentBlock)[varname] = v;
00162 }
00163 
00164 void LLSDMessageBuilder::addIPAddr(const char* varname, U32 v)
00165 {
00166         (*mCurrentBlock)[varname] = ll_sd_from_ipaddr(v);
00167 }
00168 
00169 void LLSDMessageBuilder::addIPPort(const char* varname, U16 v)
00170 {
00171         (*mCurrentBlock)[varname] = v;
00172 }
00173 
00174 void LLSDMessageBuilder::addBOOL(const char* varname, BOOL v)
00175 {
00176         (*mCurrentBlock)[varname] = (v == TRUE);
00177 }
00178 
00179 void LLSDMessageBuilder::addString(const char* varname, const char* v)
00180 {
00181         if (v)
00182                 (*mCurrentBlock)[varname] = v;  /* Flawfinder: ignore */  
00183         else
00184                 (*mCurrentBlock)[varname] = ""; 
00185 }
00186 
00187 void LLSDMessageBuilder::addString(const char* varname, const std::string& v)
00188 {
00189         if (v.size())
00190                 (*mCurrentBlock)[varname] = v; 
00191         else
00192                 (*mCurrentBlock)[varname] = ""; 
00193 }
00194 
00195 void LLSDMessageBuilder::addVector3(const char* varname, const LLVector3& v)
00196 {
00197         (*mCurrentBlock)[varname] = ll_sd_from_vector3(v);
00198 }
00199 
00200 void LLSDMessageBuilder::addVector4(const char* varname, const LLVector4& v)
00201 {
00202         (*mCurrentBlock)[varname] = ll_sd_from_vector4(v);
00203 }
00204 
00205 void LLSDMessageBuilder::addVector3d(const char* varname, const LLVector3d& v)
00206 {
00207         (*mCurrentBlock)[varname] = ll_sd_from_vector3d(v);
00208 }
00209 
00210 void LLSDMessageBuilder::addQuat(const char* varname, const LLQuaternion& v)
00211 {
00212         (*mCurrentBlock)[varname] = ll_sd_from_quaternion(v);
00213 }
00214 
00215 void LLSDMessageBuilder::addUUID(const char* varname, const LLUUID& v)
00216 {
00217         (*mCurrentBlock)[varname] = v;
00218 }
00219 
00220 void LLSDMessageBuilder::compressMessage(U8*& buf_ptr, U32& buffer_length)
00221 {
00222 }
00223 
00224 BOOL LLSDMessageBuilder::isMessageFull(const char* blockname) const
00225 {
00226         return FALSE;
00227 }
00228 
00229 U32 LLSDMessageBuilder::buildMessage(U8*, U32, U8)
00230 {
00231         return 0;
00232 }
00233 
00234 void LLSDMessageBuilder::copyFromMessageData(const LLMsgData& data)
00235 {
00236         // copy the blocks
00237         // counting variables used to encode multiple block info
00238         S32 block_count = 0;
00239     char* block_name = NULL;
00240 
00241         // loop through msg blocks to loop through variables, totalling up size
00242         // data and filling the new (send) message
00243         LLMsgData::msg_blk_data_map_t::const_iterator iter = 
00244                 data.mMemberBlocks.begin();
00245         LLMsgData::msg_blk_data_map_t::const_iterator end = 
00246                 data.mMemberBlocks.end();
00247         for(; iter != end; ++iter)
00248         {
00249                 const LLMsgBlkData* mbci = iter->second;
00250                 if(!mbci) continue;
00251 
00252                 // do we need to encode a block code?
00253                 if (block_count == 0)
00254                 {
00255                         block_count = mbci->mBlockNumber;
00256                         block_name = (char*)mbci->mName;
00257                 }
00258 
00259                 // counting down mutliple blocks
00260                 block_count--;
00261 
00262                 nextBlock(block_name);
00263 
00264                 // now loop through the variables
00265                 LLMsgBlkData::msg_var_data_map_t::const_iterator dit = mbci->mMemberVarData.begin();
00266                 LLMsgBlkData::msg_var_data_map_t::const_iterator dend = mbci->mMemberVarData.end();
00267                 
00268                 for(; dit != dend; ++dit)
00269                 {
00270                         //const LLMsgVarData& mvci = *dit;
00271 
00272                         // TODO: Copy mvci data in to block:
00273                         // (*mCurrentBlock)[varname] = v;
00274                 }
00275         }
00276 }
00277 
00278 //virtual
00279 void LLSDMessageBuilder::copyFromLLSD(const LLSD& msg)
00280 {
00281         mCurrentMessage = msg;
00282         lldebugs << LLSDNotationStreamer(mCurrentMessage) << llendl;
00283 }
00284 
00285 const LLSD& LLSDMessageBuilder::getMessage() const
00286 {
00287          return mCurrentMessage;
00288 }
00289 
00290 //virtual
00291 void LLSDMessageBuilder::setBuilt(BOOL b) { mbSBuilt = b; }
00292 
00293 //virtual 
00294 BOOL LLSDMessageBuilder::isBuilt() const {return mbSBuilt;}
00295 
00296 //virtual 
00297 BOOL LLSDMessageBuilder::isClear() const {return mbSClear;}
00298 
00299 //virtual 
00300 S32 LLSDMessageBuilder::getMessageSize()
00301 {
00302         // babbage: size is unknown as message stored as LLSD.
00303         // return non-zero if pending data, as send can be skipped for 0 size.
00304         // return 1 to encourage senders checking size against splitting message.
00305         return mCurrentMessage.size()? 1 : 0;
00306 }
00307 
00308 //virtual 
00309 const char* LLSDMessageBuilder::getMessageName() const 
00310 {
00311         return mCurrentMessageName.c_str();
00312 }

Generated on Thu Jul 1 06:09:08 2010 for Second Life Viewer by  doxygen 1.4.7