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