PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llagentpicksinfo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 125 lines | 76 code | 19 blank | 30 comment | 9 complexity | 5d2338958fb8275db35ed3854695afff MD5 | raw file
  1/** 
  2 * @file llagentpicksinfo.cpp
  3 * @brief LLAgentPicksInfo class implementation
  4 *
  5 * $LicenseInfo:firstyear=2001&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 "llviewerprecompiledheaders.h"
 28#include "llagentpicksinfo.h"
 29
 30#include "llagent.h"
 31#include "llavatarconstants.h"
 32#include "llavatarpropertiesprocessor.h"
 33
 34class LLAgentPicksInfo::LLAgentPicksObserver : public LLAvatarPropertiesObserver
 35{
 36public:
 37	LLAgentPicksObserver()
 38	{
 39		LLAvatarPropertiesProcessor::getInstance()->addObserver(gAgent.getID(), this);
 40	}
 41
 42	~LLAgentPicksObserver()
 43	{
 44		if (LLAvatarPropertiesProcessor::instanceExists())
 45			LLAvatarPropertiesProcessor::getInstance()->removeObserver(gAgent.getID(), this);
 46	}
 47
 48	void sendAgentPicksRequest()
 49	{
 50		LLAvatarPropertiesProcessor::getInstance()->sendAvatarPicksRequest(gAgent.getID());
 51	}
 52
 53	typedef boost::function<void(LLAvatarPicks*)> server_respond_callback_t;
 54
 55	void setServerRespondCallback(const server_respond_callback_t& cb)
 56	{
 57		mServerRespondCallback = cb;
 58	}
 59
 60	virtual void processProperties(void* data, EAvatarProcessorType type)
 61	{
 62		if(APT_PICKS == type)
 63		{
 64			LLAvatarPicks* picks = static_cast<LLAvatarPicks*>(data);
 65			if(picks && gAgent.getID() == picks->target_id)
 66			{
 67				if(mServerRespondCallback)
 68				{
 69					mServerRespondCallback(picks);
 70				}
 71			}
 72		}
 73	}
 74
 75private:
 76
 77	server_respond_callback_t mServerRespondCallback;
 78};
 79
 80//////////////////////////////////////////////////////////////////////////
 81//////////////////////////////////////////////////////////////////////////
 82//////////////////////////////////////////////////////////////////////////
 83
 84LLAgentPicksInfo::LLAgentPicksInfo()
 85 : mAgentPicksObserver(NULL)
 86 , mMaxNumberOfPicks(MAX_AVATAR_PICKS)
 87 // Disable Pick creation until we get number of Picks from server - in case 
 88 // avatar has maximum number of Picks.
 89 , mNumberOfPicks(mMaxNumberOfPicks) 
 90{
 91}
 92
 93LLAgentPicksInfo::~LLAgentPicksInfo()
 94{
 95	delete mAgentPicksObserver;
 96}
 97
 98void LLAgentPicksInfo::requestNumberOfPicks()
 99{
100	if(!mAgentPicksObserver)
101	{
102		mAgentPicksObserver = new LLAgentPicksObserver();
103
104		mAgentPicksObserver->setServerRespondCallback(boost::bind(
105			&LLAgentPicksInfo::onServerRespond, this, _1));
106	}
107
108	mAgentPicksObserver->sendAgentPicksRequest();
109}
110
111bool LLAgentPicksInfo::isPickLimitReached()
112{
113	return getNumberOfPicks() >= getMaxNumberOfPicks();
114}
115
116void LLAgentPicksInfo::onServerRespond(LLAvatarPicks* picks)
117{
118	if(!picks)
119	{
120		llerrs << "Unexpected value" << llendl;
121		return;
122	}
123
124	setNumberOfPicks(picks->picks_list.size());
125}