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

/indra/llmessage/lluseroperation.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 190 lines | 125 code | 25 blank | 40 comment | 16 complexity | a26c9e1287a0d3ca46cde3a5e912e9e9 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lluseroperation.cpp
  3. * @brief LLUserOperation class definition.
  4. *
  5. * $LicenseInfo:firstyear=2002&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 "linden_common.h"
  27. #include "lluseroperation.h"
  28. ///----------------------------------------------------------------------------
  29. /// Local function declarations, constants, enums, and typedefs
  30. ///----------------------------------------------------------------------------
  31. LLUserOperationMgr* gUserOperationMgr = NULL;
  32. ///----------------------------------------------------------------------------
  33. /// Class LLUserOperation
  34. ///----------------------------------------------------------------------------
  35. LLUserOperation::LLUserOperation(const LLUUID& agent_id)
  36. : mAgentID(agent_id),
  37. mTimer(),
  38. mNoExpire(FALSE)
  39. {
  40. mTransactionID.generate();
  41. }
  42. LLUserOperation::LLUserOperation(const LLUUID& agent_id,
  43. const LLUUID& transaction_id) :
  44. mAgentID(agent_id),
  45. mTransactionID(transaction_id),
  46. mTimer(),
  47. mNoExpire(FALSE)
  48. {
  49. }
  50. // protected constructor which is used by base classes that determine
  51. // transaction, agent, et. after construction.
  52. LLUserOperation::LLUserOperation() :
  53. mTimer(),
  54. mNoExpire(FALSE)
  55. {
  56. }
  57. LLUserOperation::~LLUserOperation()
  58. {
  59. }
  60. void LLUserOperation::SetNoExpireFlag(const BOOL flag)
  61. {
  62. mNoExpire = flag;
  63. }
  64. BOOL LLUserOperation::isExpired()
  65. {
  66. if (!mNoExpire)
  67. {
  68. const F32 EXPIRE_TIME_SECS = 10.f;
  69. return mTimer.getElapsedTimeF32() > EXPIRE_TIME_SECS;
  70. }
  71. return FALSE;
  72. }
  73. void LLUserOperation::expire()
  74. {
  75. // by default, do do anything.
  76. }
  77. ///----------------------------------------------------------------------------
  78. /// Class LLUserOperationMgr
  79. ///----------------------------------------------------------------------------
  80. LLUserOperationMgr::LLUserOperationMgr()
  81. {
  82. }
  83. LLUserOperationMgr::~LLUserOperationMgr()
  84. {
  85. if (mUserOperationList.size() > 0)
  86. {
  87. llwarns << "Exiting with user operations pending." << llendl;
  88. }
  89. }
  90. void LLUserOperationMgr::addOperation(LLUserOperation* op)
  91. {
  92. if(!op)
  93. {
  94. llwarns << "Tried to add null op" << llendl;
  95. return;
  96. }
  97. LLUUID id = op->getTransactionID();
  98. llassert(mUserOperationList.count(id) == 0);
  99. mUserOperationList[id] = op;
  100. }
  101. LLUserOperation* LLUserOperationMgr::findOperation(const LLUUID& tid)
  102. {
  103. user_operation_list_t::iterator iter = mUserOperationList.find(tid);
  104. if (iter != mUserOperationList.end())
  105. return iter->second;
  106. else
  107. return NULL;
  108. }
  109. BOOL LLUserOperationMgr::deleteOperation(LLUserOperation* op)
  110. {
  111. size_t rv = 0;
  112. if(op)
  113. {
  114. LLUUID id = op->getTransactionID();
  115. rv = mUserOperationList.erase(id);
  116. delete op;
  117. op = NULL;
  118. }
  119. return rv ? TRUE : FALSE;
  120. }
  121. void LLUserOperationMgr::deleteExpiredOperations()
  122. {
  123. const S32 MAX_OPS_CONSIDERED = 2000;
  124. S32 ops_left = MAX_OPS_CONSIDERED;
  125. LLUserOperation* op = NULL;
  126. user_operation_list_t::iterator it;
  127. if(mLastOperationConsidered.isNull())
  128. {
  129. it = mUserOperationList.begin();
  130. }
  131. else
  132. {
  133. it = mUserOperationList.lower_bound(mLastOperationConsidered);
  134. }
  135. while((ops_left--) && (it != mUserOperationList.end()))
  136. {
  137. op = (*it).second;
  138. if(op && op->isExpired())
  139. {
  140. lldebugs << "expiring: " << (*it).first << llendl;
  141. op->expire();
  142. mUserOperationList.erase(it++);
  143. delete op;
  144. }
  145. else if(op)
  146. {
  147. ++it;
  148. }
  149. else
  150. {
  151. mUserOperationList.erase(it++);
  152. }
  153. }
  154. if(it != mUserOperationList.end())
  155. {
  156. mLastOperationConsidered = (*it).first;
  157. }
  158. else
  159. {
  160. mLastOperationConsidered.setNull();
  161. }
  162. }
  163. ///----------------------------------------------------------------------------
  164. /// Local function definitions
  165. ///----------------------------------------------------------------------------