llvoinventorylistener.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * @file llvoinventorylistener.cpp
  3. * @brief Interface for classes that wish to receive updates about viewer object inventory
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llvoinventorylistener.h"
  34. #include "llviewerobject.h"
  35. //static
  36. LLVOInventoryListener::listeners_list_t LLVOInventoryListener::sListeners;
  37. LLVOInventoryListener::LLVOInventoryListener()
  38. {
  39. sListeners.insert(this);
  40. }
  41. LLVOInventoryListener::~LLVOInventoryListener()
  42. {
  43. removeVOInventoryListeners();
  44. sListeners.erase(this);
  45. }
  46. void LLVOInventoryListener::removeVOInventoryListener(LLViewerObject* object)
  47. {
  48. if (!object)
  49. {
  50. object = mListenerVObject;
  51. }
  52. if (object && mListenerVObjects.count(object))
  53. {
  54. object->removeInventoryListener(this);
  55. mListenerVObjects.erase(object);
  56. if (mListenerVObject == object)
  57. {
  58. mListenerVObject = NULL;
  59. }
  60. }
  61. }
  62. void LLVOInventoryListener::removeVOInventoryListeners()
  63. {
  64. while (!mListenerVObjects.empty())
  65. {
  66. objects_list_t::iterator it = mListenerVObjects.begin();
  67. removeVOInventoryListener(*it);
  68. }
  69. }
  70. void LLVOInventoryListener::registerVOInventoryListener(LLViewerObject* object,
  71. void* user_data)
  72. {
  73. if (object && !object->isDead())
  74. {
  75. removeVOInventoryListener(object);
  76. mListenerVObject = object;
  77. mListenerVObjects.insert(object);
  78. object->registerInventoryListener(this, user_data);
  79. }
  80. }
  81. void LLVOInventoryListener::requestVOInventory(LLViewerObject* object)
  82. {
  83. if (!object)
  84. {
  85. object = mListenerVObject;
  86. }
  87. if (object && !object->isDead())
  88. {
  89. object->requestInventory();
  90. }
  91. }
  92. void LLVOInventoryListener::clearVOInventoryListener(LLViewerObject* object)
  93. {
  94. mListenerVObjects.erase(object);
  95. if (mListenerVObject == object)
  96. {
  97. mListenerVObject = NULL;
  98. }
  99. }
  100. bool LLVOInventoryListener::hasRegisteredListener(LLViewerObject* object)
  101. {
  102. return object && mListenerVObjects.count(object) != 0;
  103. }
  104. //static
  105. void LLVOInventoryListener::removeObjectFromListeners(LLViewerObject* object)
  106. {
  107. if (!object) return;
  108. for (listeners_list_t::iterator it = sListeners.begin(),
  109. end = sListeners.end();
  110. it != end; ++it)
  111. {
  112. LLVOInventoryListener* listener = *it;
  113. if (listener) // Paranoia
  114. {
  115. listener->removeVOInventoryListener(object);
  116. }
  117. }
  118. }