/indra/newview/llaccountingcostmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 181 lines · 124 code · 18 blank · 39 comment · 23 complexity · 81354c36d9c3cc1f9683239d518e786c MD5 · raw file

  1. /**
  2. * @file LLAccountingQuotaManager.cpp
  3. * @ Handles the setting and accessing for costs associated with mesh
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, 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 "llaccountingcostmanager.h"
  28. #include "llagent.h"
  29. #include "llcurl.h"
  30. #include "llhttpclient.h"
  31. //===============================================================================
  32. LLAccountingCostManager::LLAccountingCostManager()
  33. {
  34. }
  35. //===============================================================================
  36. class LLAccountingCostResponder : public LLCurl::Responder
  37. {
  38. public:
  39. LLAccountingCostResponder( const LLSD& objectIDs, const LLHandle<LLAccountingCostObserver>& observer_handle )
  40. : mObjectIDs( objectIDs ),
  41. mObserverHandle( observer_handle )
  42. {
  43. LLAccountingCostObserver* observer = mObserverHandle.get();
  44. if (observer)
  45. {
  46. mTransactionID = observer->getTransactionID();
  47. }
  48. }
  49. void clearPendingRequests ( void )
  50. {
  51. for ( LLSD::array_iterator iter = mObjectIDs.beginArray(); iter != mObjectIDs.endArray(); ++iter )
  52. {
  53. LLAccountingCostManager::getInstance()->removePendingObject( iter->asUUID() );
  54. }
  55. }
  56. void error( U32 statusNum, const std::string& reason )
  57. {
  58. llwarns << "Transport error "<<reason<<llendl;
  59. clearPendingRequests();
  60. LLAccountingCostObserver* observer = mObserverHandle.get();
  61. if (observer && observer->getTransactionID() == mTransactionID)
  62. {
  63. observer->setErrorStatus(statusNum, reason);
  64. }
  65. }
  66. void result( const LLSD& content )
  67. {
  68. //Check for error
  69. if ( !content.isMap() || content.has("error") )
  70. {
  71. llwarns << "Error on fetched data"<< llendl;
  72. }
  73. else if (content.has("selected"))
  74. {
  75. F32 physicsCost = 0.0f;
  76. F32 networkCost = 0.0f;
  77. F32 simulationCost = 0.0f;
  78. physicsCost = content["selected"]["physics"].asReal();
  79. networkCost = content["selected"]["streaming"].asReal();
  80. simulationCost = content["selected"]["simulation"].asReal();
  81. SelectionCost selectionCost( /*transactionID,*/ physicsCost, networkCost, simulationCost );
  82. LLAccountingCostObserver* observer = mObserverHandle.get();
  83. if (observer && observer->getTransactionID() == mTransactionID)
  84. {
  85. observer->onWeightsUpdate(selectionCost);
  86. }
  87. }
  88. clearPendingRequests();
  89. }
  90. private:
  91. //List of posted objects
  92. LLSD mObjectIDs;
  93. // Current request ID
  94. LLUUID mTransactionID;
  95. // Cost update observer handle
  96. LLHandle<LLAccountingCostObserver> mObserverHandle;
  97. };
  98. //===============================================================================
  99. void LLAccountingCostManager::fetchCosts( eSelectionType selectionType,
  100. const std::string& url,
  101. const LLHandle<LLAccountingCostObserver>& observer_handle )
  102. {
  103. // Invoking system must have already determined capability availability
  104. if ( !url.empty() )
  105. {
  106. LLSD objectList;
  107. U32 objectIndex = 0;
  108. IDIt IDIter = mObjectList.begin();
  109. IDIt IDIterEnd = mObjectList.end();
  110. for ( ; IDIter != IDIterEnd; ++IDIter )
  111. {
  112. // Check to see if a request for this object has already been made.
  113. if ( mPendingObjectQuota.find( *IDIter ) == mPendingObjectQuota.end() )
  114. {
  115. mPendingObjectQuota.insert( *IDIter );
  116. objectList[objectIndex++] = *IDIter;
  117. }
  118. }
  119. mObjectList.clear();
  120. //Post results
  121. if ( objectList.size() > 0 )
  122. {
  123. std::string keystr;
  124. if ( selectionType == Roots )
  125. {
  126. keystr="selected_roots";
  127. }
  128. else
  129. if ( selectionType == Prims )
  130. {
  131. keystr="selected_prims";
  132. }
  133. else
  134. {
  135. llinfos<<"Invalid selection type "<<llendl;
  136. mObjectList.clear();
  137. mPendingObjectQuota.clear();
  138. return;
  139. }
  140. LLSD dataToPost = LLSD::emptyMap();
  141. dataToPost[keystr.c_str()] = objectList;
  142. LLHTTPClient::post( url, dataToPost, new LLAccountingCostResponder( objectList, observer_handle ));
  143. }
  144. }
  145. else
  146. {
  147. //url was empty - warn & continue
  148. llwarns<<"Supplied url is empty "<<llendl;
  149. mObjectList.clear();
  150. mPendingObjectQuota.clear();
  151. }
  152. }
  153. //===============================================================================
  154. void LLAccountingCostManager::addObject( const LLUUID& objectID )
  155. {
  156. mObjectList.insert( objectID );
  157. }
  158. //===============================================================================
  159. void LLAccountingCostManager::removePendingObject( const LLUUID& objectID )
  160. {
  161. mPendingObjectQuota.erase( objectID );
  162. }
  163. //===============================================================================