diff options
Diffstat (limited to 'indra/llmessage')
-rw-r--r-- | indra/llmessage/llareslistener.cpp | 46 | ||||
-rw-r--r-- | indra/llmessage/llareslistener.h | 14 | ||||
-rw-r--r-- | indra/llmessage/tests/llareslistener_test.cpp | 2 |
3 files changed, 9 insertions, 53 deletions
diff --git a/indra/llmessage/llareslistener.cpp b/indra/llmessage/llareslistener.cpp index 4bf375069d..a8beb8cbde 100644 --- a/indra/llmessage/llareslistener.cpp +++ b/indra/llmessage/llareslistener.cpp @@ -9,10 +9,6 @@ * $/LicenseInfo$ */ -#if LL_WINDOWS -#pragma warning (disable : 4355) // 'this' used in initializer list: yes, intentionally -#endif - // Precompiled header #include "linden_common.h" // associated header @@ -27,35 +23,13 @@ #include "llsdutil.h" LLAresListener::LLAresListener(const std::string& pumpname, LLAres* llares): - mAres(llares), - mBoundListener(LLEventPumps::instance(). - obtain(pumpname). - listen("LLAresListener", boost::bind(&LLAresListener::process, this, _1))) -{ - // Insert an entry into our mDispatch map for every method we want to be - // able to invoke via this event API. - mDispatch["rewriteURI"] = boost::bind(&LLAresListener::rewriteURI, this, _1); -} - -bool LLAresListener::process(const LLSD& command) + LLDispatchListener(pumpname, "op"), + mAres(llares) { - const std::string op(command["op"]); - // Look up the requested operation. - DispatchMap::const_iterator found = mDispatch.find(op); - if (found == mDispatch.end()) - { - // There's no feedback other than our own reply. If somebody asks - // for an operation that's not supported (perhaps because of a - // typo?), unless we holler loudly, the request will be silently - // ignored. Throwing a tantrum on such errors will hopefully make - // this product more robust. - LL_ERRS("LLAresListener") << "Unsupported request " << op << LL_ENDL; - return false; - } - // Having found the operation, call it. - found->second(command); - // Conventional LLEventPump listener return - return false; + // add() every method we want to be able to invoke via this event API. + // Optional third parameter validates expected LLSD request structure. + add("rewriteURI", &LLAresListener::rewriteURI, + LLSD().insert("uri", LLSD()).insert("reply", LLSD())); } /// This UriRewriteResponder subclass packages returned URIs as an LLSD @@ -97,13 +71,5 @@ private: void LLAresListener::rewriteURI(const LLSD& data) { - static LLSD required(LLSD().insert("uri", LLSD()).insert("reply", LLSD())); - // Validate that the request is well-formed - std::string mismatch(llsd_matches(required, data)); - if (! mismatch.empty()) - { - LL_ERRS("LLAresListener") << "bad rewriteURI request: " << mismatch << LL_ENDL; - } - // Looks as though we have what we need; issue the request mAres->rewriteURI(data["uri"], new UriRewriteResponder(data)); } diff --git a/indra/llmessage/llareslistener.h b/indra/llmessage/llareslistener.h index 8835440c5d..bf093b3d3d 100644 --- a/indra/llmessage/llareslistener.h +++ b/indra/llmessage/llareslistener.h @@ -14,33 +14,23 @@ #if ! defined(LL_LLARESLISTENER_H) #define LL_LLARESLISTENER_H -#include <string> -#include <map> -#include <boost/function.hpp> -#include "llevents.h" +#include "lleventdispatcher.h" class LLAres; class LLSD; /// Listen on an LLEventPump with specified name for LLAres request events. -class LLAresListener +class LLAresListener: public LLDispatchListener { public: /// Specify the pump name on which to listen, and bind the LLAres instance /// to use (e.g. gAres) LLAresListener(const std::string& pumpname, LLAres* llares); - /// Handle request events on the event pump specified at construction time - bool process(const LLSD& command); - private: /// command["op"] == "rewriteURI" void rewriteURI(const LLSD& data); - typedef boost::function<void(const LLSD&)> Callable; - typedef std::map<std::string, Callable> DispatchMap; - DispatchMap mDispatch; - LLTempBoundListener mBoundListener; LLAres* mAres; }; diff --git a/indra/llmessage/tests/llareslistener_test.cpp b/indra/llmessage/tests/llareslistener_test.cpp index 215a3806f8..ac4886ccf4 100644 --- a/indra/llmessage/tests/llareslistener_test.cpp +++ b/indra/llmessage/tests/llareslistener_test.cpp @@ -130,7 +130,7 @@ namespace tut { threw = e.what(); } - ensure_contains("LLAresListener bad op", threw, "Unsupported"); + ensure_contains("LLAresListener bad op", threw, "bad"); } template<> template<> |