From de1fc577666686fb0c3f8b38d8c6c90eb6dff414 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Sat, 23 Mar 2024 17:14:33 +0900 Subject: Update sendReply(): accepting LLSD by value already copies it. --- indra/llcommon/llevents.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/llevents.h') diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index c1dbf4392f..1f35a6de18 100644 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -779,7 +779,7 @@ private: * Before sending the reply event, sendReply() copies the ["reqid"] item from * the request to the reply. */ -LL_COMMON_API bool sendReply(const LLSD& reply, const LLSD& request, +LL_COMMON_API bool sendReply(LLSD reply, const LLSD& request, const std::string& replyKey="reply"); #endif /* ! defined(LL_LLEVENTS_H) */ -- cgit v1.2.3 From 93b30f960ea327fe3c36deed72a8075ce0d13f19 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Sun, 24 Mar 2024 02:16:55 +0900 Subject: Introduce LLStreamListener: bundle LLEventStream+LLTempBoundListener. This is a very common pattern, especially in test code, but elsewhere in the viewer too. Use it in llluamanager_test.cpp. --- indra/llcommon/llevents.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'indra/llcommon/llevents.h') diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index 1f35a6de18..ebc893d1e6 100644 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -151,6 +151,8 @@ typedef boost::signals2::signal LL /// Methods that forward listeners (e.g. constructed with /// boost::bind()) should accept (const LLEventListener&) typedef LLStandardSignal::slot_type LLEventListener; +/// Accept a void listener too +typedef std::function LLVoidListener; /// Result of registering a listener, supports connected(), /// disconnect() and blocked() typedef boost::signals2::connection LLBoundListener; @@ -158,6 +160,23 @@ typedef boost::signals2::connection LLBoundListener; /// referenced listener when the LLTempBoundListener instance is destroyed. typedef boost::signals2::scoped_connection LLTempBoundListener; +/// Accepting (const LLListener&) allows either LLEventListener or LLVoidListener +/// TODO: but compiler considers the constructor call ambiguous?? +class LLListener +{ +public: + LLListener(const LLEventListener& listener): + mListener(listener) + {} + LLListener(const LLVoidListener& listener): + mListener([listener](const LLSD& data){ listener(data); return false; }) + {} + operator LLEventListener() const { return mListener; } + +private: + LLEventListener mListener; +}; + /** * A common idiom for event-based code is to accept either a callable -- * directly called on completion -- or the string name of an LLEventPump on @@ -687,6 +706,30 @@ private: EventList mEventHistory; }; +/***************************************************************************** +* LLNamedListener +*****************************************************************************/ +/** + * LLNamedListener bundles a concrete LLEventPump subclass with a specific + * listener function, with an LLTempBoundListener to ensure that it's + * disconnected before destruction. + */ +template +class LL_COMMON_API LLNamedListener: PUMP +{ + using pump_t = PUMP; +public: + template + LLNamedListener(const std::string& name, LISTENER&& listener): + pump_t(name, false), // don't tweak the name + mConn(pump_t::listen("func", std::forward(listener))) + {} + +private: + LLTempBoundListener mConn; +}; +using LLStreamListener = LLNamedListener<>; + /***************************************************************************** * LLReqID *****************************************************************************/ -- cgit v1.2.3 From fd8c5fced1ee62e08c55adf92fb9c8d0e52d313a Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 25 Mar 2024 10:03:17 -0400 Subject: Remove colliding LLListener. --- indra/llcommon/llevents.h | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'indra/llcommon/llevents.h') diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index ebc893d1e6..77a405871d 100644 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -160,23 +160,6 @@ typedef boost::signals2::connection LLBoundListener; /// referenced listener when the LLTempBoundListener instance is destroyed. typedef boost::signals2::scoped_connection LLTempBoundListener; -/// Accepting (const LLListener&) allows either LLEventListener or LLVoidListener -/// TODO: but compiler considers the constructor call ambiguous?? -class LLListener -{ -public: - LLListener(const LLEventListener& listener): - mListener(listener) - {} - LLListener(const LLVoidListener& listener): - mListener([listener](const LLSD& data){ listener(data); return false; }) - {} - operator LLEventListener() const { return mListener; } - -private: - LLEventListener mListener; -}; - /** * A common idiom for event-based code is to accept either a callable -- * directly called on completion -- or the string name of an LLEventPump on -- cgit v1.2.3