summaryrefslogtreecommitdiff
path: root/indra/llcommon/lazyeventapi.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2022-06-22 10:51:11 -0400
committerNat Goodspeed <nat@lindenlab.com>2022-06-22 10:51:11 -0400
commit6b53036f7499a4e42813378009050eaf02c0b69d (patch)
treecfa65d470b614a6ef246dce074186e54b4ffbc23 /indra/llcommon/lazyeventapi.cpp
parentf9d810ac2a02ef96c843e214c7479146dd4f4157 (diff)
DRTVWR-564: Allow LLLeapListener to report LazyEventAPIs too.
One important factor in the design of LazyEventAPI was the desire to allow LLLeapListener to query metadata for an LLEventAPI even if it hasn't yet been instantiated by LazyEventAPI. That's why LazyEventAPI requires the same metadata required by a classic LLEventAPI. Instead of just publicly exposing its data members, give LazyEventAPI a query API mimicking LLEventAPI / LLEventDispatcher. Protect data members and private methods. Adapt lazyeventapi_test.cpp accordingly. Extend LLLeapListener::getAPIs() and getAPI() to look through LazyEventAPIBase instances after first checking existing LLEventAPI instances. Because the query API for LazyEventAPIBase mimics LLEventAPI's, extract getAPI()'s actual metadata reporting to a new internal template function reportAPI(). While we're touching LLLeapListener, we no longer need BOOST_FOREACH().
Diffstat (limited to 'indra/llcommon/lazyeventapi.cpp')
-rw-r--r--indra/llcommon/lazyeventapi.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/indra/llcommon/lazyeventapi.cpp b/indra/llcommon/lazyeventapi.cpp
index aefc2db6da..028af9f33f 100644
--- a/indra/llcommon/lazyeventapi.cpp
+++ b/indra/llcommon/lazyeventapi.cpp
@@ -15,9 +15,11 @@
#include "lazyeventapi.h"
// STL headers
// std headers
+#include <algorithm> // std::find_if
// external library headers
// other Linden headers
#include "llevents.h"
+#include "llsdutil.h"
LL::LazyEventAPIBase::LazyEventAPIBase(
const std::string& name, const std::string& desc, const std::string& field)
@@ -51,3 +53,20 @@ LL::LazyEventAPIBase::~LazyEventAPIBase()
LLEventPumps::instance().unregisterPumpFactory(mParams.name);
}
}
+
+LLSD LL::LazyEventAPIBase::getMetadata(const std::string& name) const
+{
+ // Since mOperations is a vector rather than a map, just search.
+ auto found = std::find_if(mOperations.begin(), mOperations.end(),
+ [&name](const auto& namedesc)
+ { return (namedesc.first == name); });
+ if (found == mOperations.end())
+ return {};
+
+ // LLEventDispatcher() supplements the returned metadata in different
+ // ways, depending on metadata provided to the specific add() method.
+ // Don't try to emulate all that. At some point we might consider more
+ // closely unifying LLEventDispatcher machinery with LazyEventAPI, but for
+ // now this will have to do.
+ return llsd::map("name", found->first, "desc", found->second);
+}