PageRenderTime 63ms CodeModel.GetById 30ms app.highlight 16ms RepoModel.GetById 14ms app.codeStats 1ms

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