PageRenderTime 57ms CodeModel.GetById 33ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llremoteparcelrequest.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 197 lines | 126 code | 28 blank | 43 comment | 16 complexity | cb5d101b1b8d744dab25da232ab68a64 MD5 | raw file
  1/** 
  2 * @file llremoteparcelrequest.cpp
  3 * @author Sam Kolb
  4 * @brief Get information about a parcel you aren't standing in to display
  5 * landmark/teleport information.
  6 *
  7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "llviewerprecompiledheaders.h"
 30
 31#include "message.h"
 32
 33#include "llpanel.h"
 34#include "llhttpclient.h"
 35#include "llsdserialize.h"
 36#include "llurlentry.h"
 37#include "llviewerregion.h"
 38#include "llview.h"
 39
 40#include "llagent.h"
 41#include "llremoteparcelrequest.h"
 42
 43
 44LLRemoteParcelRequestResponder::LLRemoteParcelRequestResponder(LLHandle<LLRemoteParcelInfoObserver> observer_handle)
 45	 : mObserverHandle(observer_handle)
 46{}
 47
 48//If we get back a normal response, handle it here
 49//virtual
 50void LLRemoteParcelRequestResponder::result(const LLSD& content)
 51{
 52	LLUUID parcel_id = content["parcel_id"];
 53
 54	// Panel inspecting the information may be closed and destroyed
 55	// before this response is received.
 56	LLRemoteParcelInfoObserver* observer = mObserverHandle.get();
 57	if (observer)
 58	{
 59		observer->setParcelID(parcel_id);
 60	}
 61}
 62
 63//If we get back an error (not found, etc...), handle it here
 64//virtual
 65void LLRemoteParcelRequestResponder::error(U32 status, const std::string& reason)
 66{
 67	llinfos << "LLRemoteParcelRequest::error("
 68		<< status << ": " << reason << ")" << llendl;
 69
 70	// Panel inspecting the information may be closed and destroyed
 71	// before this response is received.
 72	LLRemoteParcelInfoObserver* observer = mObserverHandle.get();
 73	if (observer)
 74	{
 75		observer->setErrorStatus(status, reason);
 76	}
 77}
 78
 79void LLRemoteParcelInfoProcessor::addObserver(const LLUUID& parcel_id, LLRemoteParcelInfoObserver* observer)
 80{
 81	observer_multimap_t::iterator it;
 82	observer_multimap_t::iterator start = mObservers.lower_bound(parcel_id);
 83	observer_multimap_t::iterator end = mObservers.upper_bound(parcel_id);
 84
 85	// Check if the observer is already in observers list for this UUID
 86	for(it = start; it != end; ++it)
 87	{
 88		if (it->second.get() == observer)
 89		{
 90			return;
 91		}
 92	}
 93
 94	mObservers.insert(std::make_pair(parcel_id, observer->getObserverHandle()));
 95}
 96
 97void LLRemoteParcelInfoProcessor::removeObserver(const LLUUID& parcel_id, LLRemoteParcelInfoObserver* observer)
 98{
 99	if (!observer)
100	{
101		return;
102	}
103
104	observer_multimap_t::iterator it;
105	observer_multimap_t::iterator start = mObservers.lower_bound(parcel_id);
106	observer_multimap_t::iterator end = mObservers.upper_bound(parcel_id);
107
108	for(it = start; it != end; ++it)
109	{
110		if (it->second.get() == observer)
111		{
112			mObservers.erase(it);
113			break;
114		}
115	}
116}
117
118//static
119void LLRemoteParcelInfoProcessor::processParcelInfoReply(LLMessageSystem* msg, void**)
120{
121	LLParcelData parcel_data;
122
123	msg->getUUID	("Data", "ParcelID", parcel_data.parcel_id);
124	msg->getUUID	("Data", "OwnerID", parcel_data.owner_id);
125	msg->getString	("Data", "Name", parcel_data.name);
126	msg->getString	("Data", "Desc", parcel_data.desc);
127	msg->getS32		("Data", "ActualArea", parcel_data.actual_area);
128	msg->getS32		("Data", "BillableArea", parcel_data.billable_area);
129	msg->getU8		("Data", "Flags", parcel_data.flags);
130	msg->getF32		("Data", "GlobalX", parcel_data.global_x);
131	msg->getF32		("Data", "GlobalY", parcel_data.global_y);
132	msg->getF32		("Data", "GlobalZ", parcel_data.global_z);
133	msg->getString	("Data", "SimName", parcel_data.sim_name);
134	msg->getUUID	("Data", "SnapshotID", parcel_data.snapshot_id);
135	msg->getF32		("Data", "Dwell", parcel_data.dwell);
136	msg->getS32		("Data", "SalePrice", parcel_data.sale_price);
137	msg->getS32		("Data", "AuctionID", parcel_data.auction_id);
138
139	LLRemoteParcelInfoProcessor::observer_multimap_t & observers = LLRemoteParcelInfoProcessor::getInstance()->mObservers;
140
141	typedef std::vector<observer_multimap_t::iterator> deadlist_t;
142	deadlist_t dead_iters;
143
144	observer_multimap_t::iterator oi = observers.lower_bound(parcel_data.parcel_id);
145	observer_multimap_t::iterator end = observers.upper_bound(parcel_data.parcel_id);
146
147	while (oi != end)
148	{
149		// increment the loop iterator now since it may become invalid below
150		observer_multimap_t::iterator cur_oi = oi++;
151
152		LLRemoteParcelInfoObserver * observer = cur_oi->second.get();
153		if(observer)
154		{
155			// may invalidate cur_oi if the observer removes itself 
156			observer->processParcelInfo(parcel_data);
157		}
158		else
159		{
160			// the handle points to an expired observer, so don't keep it
161			// around anymore
162			dead_iters.push_back(cur_oi);
163		}
164	}
165
166	deadlist_t::iterator i;
167	deadlist_t::iterator end_dead = dead_iters.end();
168	for(i = dead_iters.begin(); i != end_dead; ++i)
169	{
170		observers.erase(*i);
171	}
172
173	LLUrlEntryParcel::LLParcelData url_data;
174	url_data.parcel_id = parcel_data.parcel_id;
175	url_data.name = parcel_data.name;
176	url_data.sim_name = parcel_data.sim_name;
177	url_data.global_x = parcel_data.global_x;
178	url_data.global_y = parcel_data.global_y;
179	url_data.global_z = parcel_data.global_z;
180
181	// Pass the parcel data to LLUrlEntryParcel to render
182	// human readable parcel name.
183	LLUrlEntryParcel::processParcelInfo(url_data);
184}
185
186void LLRemoteParcelInfoProcessor::sendParcelInfoRequest(const LLUUID& parcel_id)
187{
188	LLMessageSystem *msg = gMessageSystem;
189
190	msg->newMessage("ParcelInfoRequest");
191	msg->nextBlockFast(_PREHASH_AgentData);
192	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
193	msg->addUUID("SessionID", gAgent.getSessionID());
194	msg->nextBlock("Data");
195	msg->addUUID("ParcelID", parcel_id);
196	gAgent.sendReliableMessage();
197}