PageRenderTime 326ms CodeModel.GetById 120ms app.highlight 91ms RepoModel.GetById 111ms app.codeStats 0ms

/indra/newview/llwlhandlers.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 197 lines | 127 code | 26 blank | 44 comment | 15 complexity | bd0a7fd7edb4d36747b16aa6bc6aaa33 MD5 | raw file
  1/** 
  2 * @file llwlhandlers.cpp
  3 * @brief Various classes which handle Windlight-related messaging
  4 *
  5 * $LicenseInfo:firstyear=2009&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
 29#include "llwlhandlers.h"
 30
 31#include "llagent.h"
 32#include "llviewerregion.h"
 33#include "llenvmanager.h"
 34#include "llnotificationsutil.h"
 35
 36/****
 37 * LLEnvironmentRequest
 38 ****/
 39// static
 40bool LLEnvironmentRequest::initiate()
 41{
 42	LLViewerRegion* cur_region = gAgent.getRegion();
 43
 44	if (!cur_region)
 45	{
 46		LL_WARNS("WindlightCaps") << "Viewer region not set yet, skipping env. settings request" << LL_ENDL;
 47		return false;
 48	}
 49
 50	if (!cur_region->capabilitiesReceived())
 51	{
 52		LL_INFOS("WindlightCaps") << "Deferring windlight settings request until we've got region caps" << LL_ENDL;
 53		cur_region->setCapabilitiesReceivedCallback(boost::bind(&LLEnvironmentRequest::onRegionCapsReceived, _1));
 54		return false;
 55	}
 56
 57	return doRequest();
 58}
 59
 60// static
 61void LLEnvironmentRequest::onRegionCapsReceived(const LLUUID& region_id)
 62{
 63	if (region_id != gAgent.getRegion()->getRegionID())
 64	{
 65		LL_INFOS("WindlightCaps") << "Got caps for a non-current region" << LL_ENDL;
 66		return;
 67	}
 68
 69	LL_DEBUGS("WindlightCaps") << "Received region capabilities" << LL_ENDL;
 70	doRequest();
 71}
 72
 73// static
 74bool LLEnvironmentRequest::doRequest()
 75{
 76	std::string url = gAgent.getRegion()->getCapability("EnvironmentSettings");
 77	if (url.empty())
 78	{
 79		LL_INFOS("WindlightCaps") << "Skipping windlight setting request - we don't have this capability" << LL_ENDL;
 80		// region is apparently not capable of this; don't respond at all
 81		return false;
 82	}
 83
 84	LL_INFOS("WindlightCaps") << "Requesting region windlight settings via " << url << LL_ENDL;
 85	LLHTTPClient::get(url, new LLEnvironmentRequestResponder());
 86	return true;
 87}
 88
 89/****
 90 * LLEnvironmentRequestResponder
 91 ****/
 92int LLEnvironmentRequestResponder::sCount = 0; // init to 0
 93
 94LLEnvironmentRequestResponder::LLEnvironmentRequestResponder()
 95{
 96	mID = ++sCount;
 97}
 98/*virtual*/ void LLEnvironmentRequestResponder::result(const LLSD& unvalidated_content)
 99{
100	LL_INFOS("WindlightCaps") << "Received region windlight settings" << LL_ENDL;
101
102	if (mID != sCount)
103	{
104		LL_INFOS("WindlightCaps") << "Got superseded by another responder; ignoring..." << LL_ENDL;
105		return;
106	}
107
108	if (unvalidated_content[0]["regionID"].asUUID() != gAgent.getRegion()->getRegionID())
109	{
110		LL_WARNS("WindlightCaps") << "Not in the region from where this data was received (wanting "
111			<< gAgent.getRegion()->getRegionID() << " but got " << unvalidated_content[0]["regionID"].asUUID()
112			<< ") - ignoring..." << LL_ENDL;
113		return;
114	}
115
116	LLEnvManagerNew::getInstance()->onRegionSettingsResponse(unvalidated_content);
117}
118/*virtual*/ void LLEnvironmentRequestResponder::error(U32 status, const std::string& reason)
119{
120	LL_INFOS("WindlightCaps") << "Got an error, not using region windlight..." << LL_ENDL;
121	LLEnvManagerNew::getInstance()->onRegionSettingsResponse(LLSD());
122}
123
124/****
125 * LLEnvironmentApply
126 ****/
127
128clock_t LLEnvironmentApply::UPDATE_WAIT_SECONDS = clock_t(3.f);
129clock_t LLEnvironmentApply::sLastUpdate = clock_t(0.f);
130
131// static
132bool LLEnvironmentApply::initiateRequest(const LLSD& content)
133{
134	clock_t current = clock();
135
136	// Make sure we don't update too frequently.
137	if (current < sLastUpdate + (UPDATE_WAIT_SECONDS * CLOCKS_PER_SEC))
138	{
139		LLSD args(LLSD::emptyMap());
140		args["WAIT"] = (F64)UPDATE_WAIT_SECONDS;
141		LLNotificationsUtil::add("EnvUpdateRate", args);
142		return false;
143	}
144
145	sLastUpdate = current;
146
147	// Send update request.
148	std::string url = gAgent.getRegion()->getCapability("EnvironmentSettings");
149	if (url.empty())
150	{
151		LL_WARNS("WindlightCaps") << "Applying windlight settings not supported" << LL_ENDL;
152		return false;
153	}
154
155	LL_INFOS("WindlightCaps") << "Sending windlight settings to " << url << LL_ENDL;
156	LL_DEBUGS("WindlightCaps") << "content: " << content << LL_ENDL;
157	LLHTTPClient::post(url, content, new LLEnvironmentApplyResponder());
158	return true;
159}
160
161/****
162 * LLEnvironmentApplyResponder
163 ****/
164/*virtual*/ void LLEnvironmentApplyResponder::result(const LLSD& content)
165{
166	if (content["regionID"].asUUID() != gAgent.getRegion()->getRegionID())
167	{
168		LL_WARNS("WindlightCaps") << "No longer in the region where data was sent (currently "
169			<< gAgent.getRegion()->getRegionID() << ", reply is from " << content["regionID"].asUUID()
170			<< "); ignoring..." << LL_ENDL;
171		return;
172	}
173	else if (content["success"].asBoolean())
174	{
175		LL_DEBUGS("WindlightCaps") << "Success in applying windlight settings to region " << content["regionID"].asUUID() << LL_ENDL;
176		LLEnvManagerNew::instance().onRegionSettingsApplyResponse(true);
177	}
178	else
179	{
180		LL_WARNS("WindlightCaps") << "Region couldn't apply windlight settings!  Reason from sim: " << content["fail_reason"].asString() << LL_ENDL;
181		LLSD args(LLSD::emptyMap());
182		args["FAIL_REASON"] = content["fail_reason"].asString();
183		LLNotificationsUtil::add("WLRegionApplyFail", args);
184		LLEnvManagerNew::instance().onRegionSettingsApplyResponse(false);
185	}
186}
187/*virtual*/ void LLEnvironmentApplyResponder::error(U32 status, const std::string& reason)
188{
189	std::stringstream msg;
190	msg << reason << " (Code " << status << ")";
191
192	LL_WARNS("WindlightCaps") << "Couldn't apply windlight settings to region!  Reason: " << msg << LL_ENDL;
193
194	LLSD args(LLSD::emptyMap());
195	args["FAIL_REASON"] = msg.str();
196	LLNotificationsUtil::add("WLRegionApplyFail", args);
197}