PageRenderTime 68ms CodeModel.GetById 9ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llattachmentsmgr.h"
  28. #include "llagent.h"
  29. #include "llinventorymodel.h"
  30. #include "lltooldraganddrop.h" // pack_permissions_slam
  31. #include "llviewerinventory.h"
  32. #include "llviewerregion.h"
  33. #include "message.h"
  34. LLAttachmentsMgr::LLAttachmentsMgr()
  35. {
  36. }
  37. LLAttachmentsMgr::~LLAttachmentsMgr()
  38. {
  39. }
  40. void LLAttachmentsMgr::addAttachment(const LLUUID& item_id,
  41. const U8 attachment_pt,
  42. const BOOL add)
  43. {
  44. AttachmentsInfo attachment;
  45. attachment.mItemID = item_id;
  46. attachment.mAttachmentPt = attachment_pt;
  47. attachment.mAdd = add;
  48. mPendingAttachments.push_back(attachment);
  49. }
  50. // static
  51. void LLAttachmentsMgr::onIdle(void *)
  52. {
  53. LLAttachmentsMgr::instance().onIdle();
  54. }
  55. void LLAttachmentsMgr::onIdle()
  56. {
  57. S32 obj_count = mPendingAttachments.size();
  58. if (obj_count == 0)
  59. {
  60. return;
  61. }
  62. // Limit number of packets to send
  63. const S32 MAX_PACKETS_TO_SEND = 10;
  64. const S32 OBJECTS_PER_PACKET = 4;
  65. const S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND * OBJECTS_PER_PACKET;
  66. if( obj_count > MAX_OBJECTS_TO_SEND )
  67. {
  68. obj_count = MAX_OBJECTS_TO_SEND;
  69. }
  70. LLUUID compound_msg_id;
  71. compound_msg_id.generate();
  72. LLMessageSystem* msg = gMessageSystem;
  73. S32 i = 0;
  74. for (attachments_vec_t::const_iterator iter = mPendingAttachments.begin();
  75. iter != mPendingAttachments.end();
  76. ++iter)
  77. {
  78. if( 0 == (i % OBJECTS_PER_PACKET) )
  79. {
  80. // Start a new message chunk
  81. msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
  82. msg->nextBlockFast(_PREHASH_AgentData);
  83. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  84. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  85. msg->nextBlockFast(_PREHASH_HeaderData);
  86. msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id );
  87. msg->addU8Fast(_PREHASH_TotalObjects, obj_count );
  88. msg->addBOOLFast(_PREHASH_FirstDetachAll, false );
  89. }
  90. const AttachmentsInfo &attachment = (*iter);
  91. LLViewerInventoryItem* item = gInventory.getItem(attachment.mItemID);
  92. if (!item)
  93. {
  94. llinfos << "Attempted to add non-existant item ID:" << attachment.mItemID << llendl;
  95. continue;
  96. }
  97. S32 attachment_pt = attachment.mAttachmentPt;
  98. if (attachment.mAdd)
  99. attachment_pt |= ATTACHMENT_ADD;
  100. msg->nextBlockFast(_PREHASH_ObjectData );
  101. msg->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
  102. msg->addUUIDFast(_PREHASH_OwnerID, item->getPermissions().getOwner());
  103. msg->addU8Fast(_PREHASH_AttachmentPt, attachment_pt);
  104. pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
  105. msg->addStringFast(_PREHASH_Name, item->getName());
  106. msg->addStringFast(_PREHASH_Description, item->getDescription());
  107. if( (i+1 == obj_count) || ((OBJECTS_PER_PACKET-1) == (i % OBJECTS_PER_PACKET)) )
  108. {
  109. // End of message chunk
  110. msg->sendReliable( gAgent.getRegion()->getHost() );
  111. }
  112. i++;
  113. }
  114. mPendingAttachments.clear();
  115. }