From 516ad5b3c234321daf01294d6e03bdc4be019d36 Mon Sep 17 00:00:00 2001 From: Todd Stinson Date: Fri, 17 Feb 2012 19:03:16 -0800 Subject: PATH-292: Implementing the new freeze/unfreeze functionality on the basic panel. --- indra/newview/llpathfindingmanager.cpp | 181 +++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 indra/newview/llpathfindingmanager.cpp (limited to 'indra/newview/llpathfindingmanager.cpp') diff --git a/indra/newview/llpathfindingmanager.cpp b/indra/newview/llpathfindingmanager.cpp new file mode 100644 index 0000000000..e46ec0e171 --- /dev/null +++ b/indra/newview/llpathfindingmanager.cpp @@ -0,0 +1,181 @@ +/** + * @file llpathfindingmanager.cpp + * @author William Todd Stinson + * @brief A state manager for the various pathfinding states. + * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include + +#include + +#include "llviewerprecompiledheaders.h" +#include "llpathfindingmanager.h" +#include "llsingleton.h" +#include "llhttpclient.h" +#include "llagent.h" +#include "llviewerregion.h" + +#define CAP_SERVICE_RETRIEVE_NAVMESH "RetrieveNavMeshSrc" + +#define CAP_SERVICE_AGENT_STATE "AgentPreferences" +#define ALTER_PERMANENT_OBJECTS_FIELD "alter_permanent_objects" + +//--------------------------------------------------------------------------- +// AgentStateResponder +//--------------------------------------------------------------------------- + +class AgentStateResponder : public LLHTTPClient::Responder +{ +public: + AgentStateResponder(LLPathfindingManager::agent_state_callback_t pAgentStateCB, const std::string &pCapabilityURL); + virtual ~AgentStateResponder(); + + virtual void result(const LLSD &pContent); + virtual void error(U32 pStatus, const std::string& pReason); + +protected: + +private: + LLPathfindingManager::agent_state_callback_t mAgentStateCB; + std::string mCapabilityURL; +}; + +//--------------------------------------------------------------------------- +// LLPathfindingManager +//--------------------------------------------------------------------------- + +LLPathfindingManager::LLPathfindingManager() +{ +} + +LLPathfindingManager::~LLPathfindingManager() +{ +} + +bool LLPathfindingManager::isPathfindingEnabledForCurrentRegion() const +{ + std::string retrieveNavMeshURL = getRetrieveNavMeshURLForCurrentRegion(); + return !retrieveNavMeshURL.empty(); +} + +void LLPathfindingManager::requestGetAgentState(agent_state_callback_t pAgentStateCB) const +{ + std::string agentStateURL = getAgentStateURLForCurrentRegion(); + + if (agentStateURL.empty()) + { + pAgentStateCB(kAgentStateError); + } + else + { + LLHTTPClient::ResponderPtr responder = new AgentStateResponder(pAgentStateCB, agentStateURL); + LLHTTPClient::get(agentStateURL, responder); + } +} + +void LLPathfindingManager::requestSetAgentState(EAgentState pAgentState, agent_state_callback_t pAgentStateCB) const +{ + std::string agentStateURL = getAgentStateURLForCurrentRegion(); + + if (agentStateURL.empty()) + { + pAgentStateCB(kAgentStateError); + } + else + { + LLSD request; + request[ALTER_PERMANENT_OBJECTS_FIELD] = static_cast(pAgentState == kAgentStateUnfrozen); + + LLHTTPClient::ResponderPtr responder = new AgentStateResponder(pAgentStateCB, agentStateURL); + LLHTTPClient::post(agentStateURL, request, responder); + } +} + +void LLPathfindingManager::handleAgentStateResult(const LLSD &pContent, agent_state_callback_t pAgentStateCB) const +{ + llassert(pContent.has(ALTER_PERMANENT_OBJECTS_FIELD)); + llassert(pContent.get(ALTER_PERMANENT_OBJECTS_FIELD).isBoolean()); + EAgentState agentState = (pContent.get(ALTER_PERMANENT_OBJECTS_FIELD).asBoolean() ? kAgentStateUnfrozen : kAgentStateFrozen); + + pAgentStateCB(agentState); +} + +void LLPathfindingManager::handleAgentStateError(U32 pStatus, const std::string &pReason, const std::string &pURL, agent_state_callback_t pAgentStateCB) const +{ + llwarns << "error with request to URL '" << pURL << "' because " << pReason << " (statusCode:" << pStatus << ")" << llendl; + pAgentStateCB(kAgentStateError); +} + +std::string LLPathfindingManager::getRetrieveNavMeshURLForCurrentRegion() const +{ + return getCapabilityURLForCurrentRegion(CAP_SERVICE_RETRIEVE_NAVMESH); +} + +std::string LLPathfindingManager::getAgentStateURLForCurrentRegion() const +{ + return getCapabilityURLForCurrentRegion(CAP_SERVICE_AGENT_STATE); +} + +std::string LLPathfindingManager::getCapabilityURLForCurrentRegion(const std::string &pCapabilityName) const +{ + std::string capabilityURL(""); + + LLViewerRegion* region = gAgent.getRegion(); + if (region != NULL) + { + capabilityURL = region->getCapability(pCapabilityName); + } + + if (capabilityURL.empty()) + { + llwarns << "cannot find capability '" << pCapabilityName << "' for current region '" + << ((region != NULL) ? region->getName() : "") << "'" << llendl; + } + + return capabilityURL; +} + +//--------------------------------------------------------------------------- +// AgentStateResponder +//--------------------------------------------------------------------------- + +AgentStateResponder::AgentStateResponder(LLPathfindingManager::agent_state_callback_t pAgentStateCB, const std::string &pCapabilityURL) + : mAgentStateCB(pAgentStateCB), + mCapabilityURL(pCapabilityURL) +{ +} + +AgentStateResponder::~AgentStateResponder() +{ +} + +void AgentStateResponder::result(const LLSD &pContent) +{ + LLPathfindingManager::getInstance()->handleAgentStateResult(pContent, mAgentStateCB); +} + +void AgentStateResponder::error(U32 pStatus, const std::string &pReason) +{ + LLPathfindingManager::getInstance()->handleAgentStateError(pStatus, pReason, mCapabilityURL, mAgentStateCB); +} -- cgit v1.2.3