summaryrefslogtreecommitdiff
path: root/indra/llcommon/lualistener.h
diff options
context:
space:
mode:
authornat-goodspeed <nat@lindenlab.com>2024-02-23 11:39:24 -0500
committerGitHub <noreply@github.com>2024-02-23 11:39:24 -0500
commitad32c066691152e6a23f025d6aa5ead0e91b7be9 (patch)
tree95256b06398914fc8a91b35e60d7de9a78d90a02 /indra/llcommon/lualistener.h
parentb631f9aa218e56b12b4648a37f92ddf405eaa0f4 (diff)
parent904d82402c8b927f5e09830d10247079fb4a94f4 (diff)
Merge pull request #879 from secondlife/lua-events
Lua listen_events(), await_event() => get_event_pumps(), get_event_next().
Diffstat (limited to 'indra/llcommon/lualistener.h')
-rw-r--r--indra/llcommon/lualistener.h35
1 files changed, 18 insertions, 17 deletions
diff --git a/indra/llcommon/lualistener.h b/indra/llcommon/lualistener.h
index df88d55dd5..c13b7bbd5f 100644
--- a/indra/llcommon/lualistener.h
+++ b/indra/llcommon/lualistener.h
@@ -12,14 +12,13 @@
#if ! defined(LL_LUALISTENER_H)
#define LL_LUALISTENER_H
-#include "llevents.h"
#include "llinstancetracker.h"
-#include "lluuid.h"
+#include "llsd.h"
+#include "llthreadsafequeue.h"
+#include <iosfwd> // std::ostream
#include <memory> // std::unique_ptr
-
-#ifdef LL_TEST
-#include "lleventfilter.h"
-#endif
+#include <string>
+#include <utility> // std::pair
struct lua_State;
class LLLeapListener;
@@ -31,7 +30,6 @@ class LLLeapListener;
* inconvenience malicious Lua scripts wanting to mess with others. The idea
* is that a given lua_State stores in its Registry:
* - "event.listener": the int key of the corresponding LuaListener, if any
- * - "event.function": the Lua function to be called with incoming events
* The original thought was that LuaListener would itself store the Lua
* function -- but surprisingly, there is no C/C++ type in the API that stores
* a Lua function.
@@ -55,22 +53,25 @@ public:
~LuaListener();
- std::string getReplyName() const { return mReplyPump.getName(); }
+ std::string getReplyName() const;
std::string getCommandName() const;
+ /**
+ * LuaListener enqueues reply events from its LLLeapListener on mQueue.
+ * Call getNext() to retrieve the next such event. Blocks the calling
+ * coroutine if the queue is empty.
+ */
+ using PumpData = std::pair<std::string, LLSD>;
+ PumpData getNext();
+
+ friend std::ostream& operator<<(std::ostream& out, const LuaListener& self);
+
private:
static int getUniqueKey();
+ bool queueEvent(const std::string& pump, const LLSD& data);
- static LLBoundListener connect(lua_State* L, LLEventPump& pump, const std::string& listener);
-
- static bool call_lua(lua_State* L, const std::string& pump, const LLSD& data);
+ LLThreadSafeQueue<PumpData> mQueue;
-#ifndef LL_TEST
- LLEventStream mReplyPump{ LLUUID::generateNewID().asString() };
-#else
- LLEventLogProxyFor<LLEventStream> mReplyPump{ "luapump", false };
-#endif
- LLTempBoundListener mReplyConnection;
std::unique_ptr<LLLeapListener> mListener;
};