PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llagentpicksinfo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 125 lines | 76 code | 19 blank | 30 comment | 9 complexity | 5d2338958fb8275db35ed3854695afff MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llagentpicksinfo.cpp
  3. * @brief LLAgentPicksInfo class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&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 "llagentpicksinfo.h"
  28. #include "llagent.h"
  29. #include "llavatarconstants.h"
  30. #include "llavatarpropertiesprocessor.h"
  31. class LLAgentPicksInfo::LLAgentPicksObserver : public LLAvatarPropertiesObserver
  32. {
  33. public:
  34. LLAgentPicksObserver()
  35. {
  36. LLAvatarPropertiesProcessor::getInstance()->addObserver(gAgent.getID(), this);
  37. }
  38. ~LLAgentPicksObserver()
  39. {
  40. if (LLAvatarPropertiesProcessor::instanceExists())
  41. LLAvatarPropertiesProcessor::getInstance()->removeObserver(gAgent.getID(), this);
  42. }
  43. void sendAgentPicksRequest()
  44. {
  45. LLAvatarPropertiesProcessor::getInstance()->sendAvatarPicksRequest(gAgent.getID());
  46. }
  47. typedef boost::function<void(LLAvatarPicks*)> server_respond_callback_t;
  48. void setServerRespondCallback(const server_respond_callback_t& cb)
  49. {
  50. mServerRespondCallback = cb;
  51. }
  52. virtual void processProperties(void* data, EAvatarProcessorType type)
  53. {
  54. if(APT_PICKS == type)
  55. {
  56. LLAvatarPicks* picks = static_cast<LLAvatarPicks*>(data);
  57. if(picks && gAgent.getID() == picks->target_id)
  58. {
  59. if(mServerRespondCallback)
  60. {
  61. mServerRespondCallback(picks);
  62. }
  63. }
  64. }
  65. }
  66. private:
  67. server_respond_callback_t mServerRespondCallback;
  68. };
  69. //////////////////////////////////////////////////////////////////////////
  70. //////////////////////////////////////////////////////////////////////////
  71. //////////////////////////////////////////////////////////////////////////
  72. LLAgentPicksInfo::LLAgentPicksInfo()
  73. : mAgentPicksObserver(NULL)
  74. , mMaxNumberOfPicks(MAX_AVATAR_PICKS)
  75. // Disable Pick creation until we get number of Picks from server - in case
  76. // avatar has maximum number of Picks.
  77. , mNumberOfPicks(mMaxNumberOfPicks)
  78. {
  79. }
  80. LLAgentPicksInfo::~LLAgentPicksInfo()
  81. {
  82. delete mAgentPicksObserver;
  83. }
  84. void LLAgentPicksInfo::requestNumberOfPicks()
  85. {
  86. if(!mAgentPicksObserver)
  87. {
  88. mAgentPicksObserver = new LLAgentPicksObserver();
  89. mAgentPicksObserver->setServerRespondCallback(boost::bind(
  90. &LLAgentPicksInfo::onServerRespond, this, _1));
  91. }
  92. mAgentPicksObserver->sendAgentPicksRequest();
  93. }
  94. bool LLAgentPicksInfo::isPickLimitReached()
  95. {
  96. return getNumberOfPicks() >= getMaxNumberOfPicks();
  97. }
  98. void LLAgentPicksInfo::onServerRespond(LLAvatarPicks* picks)
  99. {
  100. if(!picks)
  101. {
  102. llerrs << "Unexpected value" << llendl;
  103. return;
  104. }
  105. setNumberOfPicks(picks->picks_list.size());
  106. }