summaryrefslogtreecommitdiff
path: root/indra/llcommon/lleventfilter.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2019-10-16 09:15:47 -0400
committerNat Goodspeed <nat@lindenlab.com>2020-03-25 18:58:16 -0400
commit53aeea4d82801f5d624a4f6a62090195d3a24f2f (patch)
treecb44db71ccdf56ef1f430e981c4fc58f73085db9 /indra/llcommon/lleventfilter.cpp
parent6945755e5299e071e46d53f09821ac73993f7afe (diff)
DRTVWR-476: Add LLEventLogProxy, LLEventLogProxyFor<T>.
LLEventLogProxy can be introduced to serve as a logging proxy for an existing LLEventPump subclass instance. Access through the LLEventLogProxy will be logged; access directly to the underlying LLEventPump will not. LLEventLogProxyFor<LLEventPumpSubclass> functions as a drop-in replacement for the original LLEventPumpSubclass instance. It internally instantiates LLEventPumpSubclass and serves as a proxy for that instance. Add unit tests for LLEventMailDrop and LLEventLogProxyFor<LLEventMailDrop>, both "plain" (events only) and via lleventcoro.h synchronization.
Diffstat (limited to 'indra/llcommon/lleventfilter.cpp')
-rw-r--r--indra/llcommon/lleventfilter.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/indra/llcommon/lleventfilter.cpp b/indra/llcommon/lleventfilter.cpp
index 9fb18dc67d..06b3cb769e 100644
--- a/indra/llcommon/lleventfilter.cpp
+++ b/indra/llcommon/lleventfilter.cpp
@@ -37,6 +37,7 @@
// other Linden headers
#include "llerror.h" // LL_ERRS
#include "llsdutil.h" // llsd_matches()
+#include "stringize.h"
/*****************************************************************************
* LLEventFilter
@@ -409,3 +410,61 @@ void LLEventBatchThrottle::setSize(std::size_t size)
flush();
}
}
+
+/*****************************************************************************
+* LLEventLogProxy
+*****************************************************************************/
+LLEventLogProxy::LLEventLogProxy(LLEventPump& source, const std::string& name, bool tweak):
+ // note: we are NOT using the constructor that implicitly connects!
+ LLEventFilter(name, tweak),
+ // instead we simply capture a reference to the subject LLEventPump
+ mPump(source)
+{
+}
+
+bool LLEventLogProxy::post(const LLSD& event) /* override */
+{
+ auto counter = mCounter++;
+ auto eventplus = event;
+ if (eventplus.type() == LLSD::TypeMap)
+ {
+ eventplus["_cnt"] = counter;
+ }
+ std::string hdr{STRINGIZE(getName() << ": post " << counter)};
+ LL_INFOS("LogProxy") << hdr << ": " << event << LL_ENDL;
+ bool result = mPump.post(eventplus);
+ LL_INFOS("LogProxy") << hdr << " => " << result << LL_ENDL;
+ return result;
+}
+
+LLBoundListener LLEventLogProxy::listen_impl(const std::string& name,
+ const LLEventListener& target,
+ const NameList& after,
+ const NameList& before)
+{
+ LL_DEBUGS("LogProxy") << "LLEventLogProxy('" << getName() << "').listen('"
+ << name << "')" << LL_ENDL;
+ return mPump.listen(name,
+ [this, name, target](const LLSD& event)->bool
+ { return listener(name, target, event); },
+ after,
+ before);
+}
+
+bool LLEventLogProxy::listener(const std::string& name,
+ const LLEventListener& target,
+ const LLSD& event) const
+{
+ auto eventminus = event;
+ std::string counter{"**"};
+ if (eventminus.has("_cnt"))
+ {
+ counter = stringize(eventminus["_cnt"].asInteger());
+ eventminus.erase("_cnt");
+ }
+ std::string hdr{STRINGIZE(getName() << " to " << name << " " << counter)};
+ LL_INFOS("LogProxy") << hdr << ": " << eventminus << LL_ENDL;
+ bool result = target(eventminus);
+ LL_INFOS("LogProxy") << hdr << " => " << result << LL_ENDL;
+ return result;
+}