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