PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lscript/lscript_execute/llscriptresourceconsumer.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 106 lines | 58 code | 17 blank | 31 comment | 8 complexity | c5d4278852ea77bb342e6e45419e059f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llscriptresourceconsumer.cpp
  3. * @brief An interface for a script resource consumer.
  4. *
  5. * $LicenseInfo:firstyear=2008&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 "llscriptresourceconsumer.h"
  27. #include "llscriptresourcepool.h"
  28. LLScriptResourceConsumer::LLScriptResourceConsumer()
  29. : mScriptResourcePool(&LLScriptResourcePool::null)
  30. { }
  31. // Get the resource pool this consumer is currently using.
  32. // virtual
  33. LLScriptResourcePool& LLScriptResourceConsumer::getScriptResourcePool()
  34. {
  35. return *mScriptResourcePool;
  36. }
  37. // Get the resource pool this consumer is currently using.
  38. // virtual
  39. const LLScriptResourcePool& LLScriptResourceConsumer::getScriptResourcePool() const
  40. {
  41. return *mScriptResourcePool;
  42. }
  43. // virtual
  44. void LLScriptResourceConsumer::setScriptResourcePool(LLScriptResourcePool& new_pool)
  45. {
  46. mScriptResourcePool = &new_pool;
  47. }
  48. bool LLScriptResourceConsumer::switchScriptResourcePools(LLScriptResourcePool& new_pool)
  49. {
  50. if (&new_pool == &LLScriptResourcePool::null)
  51. {
  52. llwarns << "New pool is null" << llendl;
  53. }
  54. if (isInPool(new_pool))
  55. {
  56. return true;
  57. }
  58. if (!canUseScriptResourcePool(new_pool))
  59. {
  60. return false;
  61. }
  62. S32 used_urls = getUsedPublicURLs();
  63. getScriptResourcePool().getPublicURLResource().release( used_urls );
  64. setScriptResourcePool(new_pool);
  65. getScriptResourcePool().getPublicURLResource().request( used_urls );
  66. return true;
  67. }
  68. bool LLScriptResourceConsumer::canUseScriptResourcePool(const LLScriptResourcePool& resource_pool)
  69. {
  70. if (isInPool(resource_pool))
  71. {
  72. return true;
  73. }
  74. if (resource_pool.getPublicURLResource().getAvailable() < getUsedPublicURLs())
  75. {
  76. return false;
  77. }
  78. return true;
  79. }
  80. bool LLScriptResourceConsumer::isInPool(const LLScriptResourcePool& resource_pool)
  81. {
  82. const LLScriptResourcePool& current_pool = getScriptResourcePool();
  83. if ( &resource_pool == &current_pool )
  84. {
  85. // This consumer is already in this pool
  86. return true;
  87. }
  88. return false;
  89. }