PageRenderTime 867ms CodeModel.GetById 644ms app.highlight 7ms RepoModel.GetById 214ms 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
  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
 27#include "llscriptresourceconsumer.h"
 28
 29#include "llscriptresourcepool.h"
 30
 31LLScriptResourceConsumer::LLScriptResourceConsumer()
 32	: mScriptResourcePool(&LLScriptResourcePool::null)
 33{ }
 34
 35// Get the resource pool this consumer is currently using.
 36// virtual 
 37LLScriptResourcePool& LLScriptResourceConsumer::getScriptResourcePool()
 38{
 39	return *mScriptResourcePool;
 40}
 41
 42// Get the resource pool this consumer is currently using.
 43// virtual 
 44const LLScriptResourcePool& LLScriptResourceConsumer::getScriptResourcePool() const
 45{
 46	return *mScriptResourcePool;
 47}
 48
 49// virtual
 50void LLScriptResourceConsumer::setScriptResourcePool(LLScriptResourcePool& new_pool)
 51{
 52	mScriptResourcePool = &new_pool;
 53}
 54
 55bool LLScriptResourceConsumer::switchScriptResourcePools(LLScriptResourcePool& new_pool)
 56{
 57	if (&new_pool == &LLScriptResourcePool::null)
 58	{
 59		llwarns << "New pool is null" << llendl;
 60	}
 61
 62	if (isInPool(new_pool))
 63	{
 64		return true;
 65	}
 66
 67	if (!canUseScriptResourcePool(new_pool))
 68	{
 69		return false;
 70	}
 71
 72	S32 used_urls = getUsedPublicURLs();
 73	
 74	getScriptResourcePool().getPublicURLResource().release( used_urls );
 75	setScriptResourcePool(new_pool);
 76	getScriptResourcePool().getPublicURLResource().request( used_urls );
 77	
 78	return true;
 79}
 80
 81bool LLScriptResourceConsumer::canUseScriptResourcePool(const LLScriptResourcePool& resource_pool)
 82{
 83	if (isInPool(resource_pool))
 84	{
 85		return true;
 86	}
 87
 88	if (resource_pool.getPublicURLResource().getAvailable() < getUsedPublicURLs())
 89	{
 90		return false;
 91	}
 92	
 93	return true;
 94}
 95
 96bool LLScriptResourceConsumer::isInPool(const LLScriptResourcePool& resource_pool)
 97{
 98	const LLScriptResourcePool& current_pool = getScriptResourcePool();
 99	if ( &resource_pool == &current_pool )
100	{
101		// This consumer is already in this pool
102		return true;
103	}
104	return false;
105}
106