PageRenderTime 32ms CodeModel.GetById 15ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llattachmentsmgr.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 131 lines | 86 code | 16 blank | 29 comment | 13 complexity | 5b1061c9517e12cd04ae67129ab144ed MD5 | raw file
  1/** 
  2 * @file llattachmentsmgr.cpp
  3 * @brief Manager for initiating attachments changes on the viewer
  4 *
  5 * $LicenseInfo:firstyear=2004&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 "llviewerprecompiledheaders.h"
 28#include "llattachmentsmgr.h"
 29
 30#include "llagent.h"
 31#include "llinventorymodel.h"
 32#include "lltooldraganddrop.h" // pack_permissions_slam
 33#include "llviewerinventory.h"
 34#include "llviewerregion.h"
 35#include "message.h"
 36
 37
 38LLAttachmentsMgr::LLAttachmentsMgr()
 39{
 40}
 41
 42LLAttachmentsMgr::~LLAttachmentsMgr()
 43{
 44}
 45
 46void LLAttachmentsMgr::addAttachment(const LLUUID& item_id,
 47									 const U8 attachment_pt,
 48									 const BOOL add)
 49{
 50	AttachmentsInfo attachment;
 51	attachment.mItemID = item_id;
 52	attachment.mAttachmentPt = attachment_pt;
 53	attachment.mAdd = add;
 54	mPendingAttachments.push_back(attachment);
 55}
 56
 57// static
 58void LLAttachmentsMgr::onIdle(void *)
 59{
 60	LLAttachmentsMgr::instance().onIdle();
 61}
 62
 63void LLAttachmentsMgr::onIdle()
 64{
 65	S32 obj_count = mPendingAttachments.size();
 66	if (obj_count == 0)
 67	{
 68		return;
 69	}
 70	
 71	// Limit number of packets to send
 72	const S32 MAX_PACKETS_TO_SEND = 10;
 73	const S32 OBJECTS_PER_PACKET = 4;
 74	const S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND * OBJECTS_PER_PACKET;
 75	if( obj_count > MAX_OBJECTS_TO_SEND )
 76	{
 77		obj_count = MAX_OBJECTS_TO_SEND;
 78	}
 79
 80	LLUUID compound_msg_id;
 81	compound_msg_id.generate();
 82	LLMessageSystem* msg = gMessageSystem;
 83
 84	
 85	S32 i = 0;
 86	for (attachments_vec_t::const_iterator iter = mPendingAttachments.begin();
 87		 iter != mPendingAttachments.end();
 88		 ++iter)
 89	{
 90		if( 0 == (i % OBJECTS_PER_PACKET) )
 91		{
 92			// Start a new message chunk
 93			msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
 94			msg->nextBlockFast(_PREHASH_AgentData);
 95			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
 96			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
 97			msg->nextBlockFast(_PREHASH_HeaderData);
 98			msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id );
 99			msg->addU8Fast(_PREHASH_TotalObjects, obj_count );
100			msg->addBOOLFast(_PREHASH_FirstDetachAll, false );
101		}
102
103		const AttachmentsInfo &attachment = (*iter);
104		LLViewerInventoryItem* item = gInventory.getItem(attachment.mItemID);
105		if (!item)
106		{
107			llinfos << "Attempted to add non-existant item ID:" << attachment.mItemID << llendl;
108			continue;
109		}
110		S32 attachment_pt = attachment.mAttachmentPt;
111		if (attachment.mAdd) 
112			attachment_pt |= ATTACHMENT_ADD;
113
114		msg->nextBlockFast(_PREHASH_ObjectData );
115		msg->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
116		msg->addUUIDFast(_PREHASH_OwnerID, item->getPermissions().getOwner());
117		msg->addU8Fast(_PREHASH_AttachmentPt, attachment_pt);
118		pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
119		msg->addStringFast(_PREHASH_Name, item->getName());
120		msg->addStringFast(_PREHASH_Description, item->getDescription());
121
122		if( (i+1 == obj_count) || ((OBJECTS_PER_PACKET-1) == (i % OBJECTS_PER_PACKET)) )
123		{
124			// End of message chunk
125			msg->sendReliable( gAgent.getRegion()->getHost() );
126		}
127		i++;
128	}
129
130	mPendingAttachments.clear();
131}