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