summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/lleventapi.cpp30
-rw-r--r--indra/llcommon/lleventapi.h83
-rw-r--r--indra/llcommon/llevents.cpp11
-rw-r--r--indra/llcommon/llqueuedthread.cpp7
-rw-r--r--indra/llcommon/llqueuedthread.h2
-rw-r--r--indra/llcommon/llworkerthread.cpp4
-rw-r--r--indra/llcommon/llworkerthread.h2
7 files changed, 134 insertions, 5 deletions
diff --git a/indra/llcommon/lleventapi.cpp b/indra/llcommon/lleventapi.cpp
index 4270c8b511..ff5459c1eb 100644
--- a/indra/llcommon/lleventapi.cpp
+++ b/indra/llcommon/lleventapi.cpp
@@ -34,6 +34,7 @@
// std headers
// external library headers
// other Linden headers
+#include "llerror.h"
LLEventAPI::LLEventAPI(const std::string& name, const std::string& desc, const std::string& field):
lbase(name, field),
@@ -45,3 +46,32 @@ LLEventAPI::LLEventAPI(const std::string& name, const std::string& desc, const s
LLEventAPI::~LLEventAPI()
{
}
+
+LLEventAPI::Response::Response(const LLSD& seed, const LLSD& request, const LLSD::String& replyKey):
+ mResp(seed),
+ mReq(request),
+ mKey(replyKey)
+{}
+
+LLEventAPI::Response::~Response()
+{
+ // When you instantiate a stack Response object, if the original
+ // request requested a reply, send it when we leave this block, no
+ // matter how.
+ sendReply(mResp, mReq, mKey);
+}
+
+void LLEventAPI::Response::warn(const std::string& warning)
+{
+ LL_WARNS("LLEventAPI::Response") << warning << LL_ENDL;
+ mResp["warnings"].append(warning);
+}
+
+void LLEventAPI::Response::error(const std::string& error)
+{
+ // Use LL_WARNS rather than LL_ERROR: we don't want the viewer to shut
+ // down altogether.
+ LL_WARNS("LLEventAPI::Response") << error << LL_ENDL;
+
+ mResp["error"] = error;
+}
diff --git a/indra/llcommon/lleventapi.h b/indra/llcommon/lleventapi.h
index d75d521e8e..1a37d780b6 100644
--- a/indra/llcommon/lleventapi.h
+++ b/indra/llcommon/lleventapi.h
@@ -76,6 +76,89 @@ public:
LLEventDispatcher::add(name, desc, callable, required);
}
+ /**
+ * Instantiate a Response object in any LLEventAPI subclass method that
+ * wants to guarantee a reply (if requested) will be sent on exit from the
+ * method. The reply will be sent if request.has(@a replyKey), default
+ * "reply". If specified, the value of request[replyKey] is the name of
+ * the LLEventPump on which to send the reply. Conventionally you might
+ * code something like:
+ *
+ * @code
+ * void MyEventAPI::someMethod(const LLSD& request)
+ * {
+ * // Send a reply event as long as request.has("reply")
+ * Response response(LLSD(), request);
+ * // ...
+ * // will be sent in reply event
+ * response["somekey"] = some_data;
+ * }
+ * @endcode
+ */
+ class LL_COMMON_API Response
+ {
+ public:
+ /**
+ * Instantiating a Response object in an LLEventAPI subclass method
+ * ensures that, if desired, a reply event will be sent.
+ *
+ * @a seed is the initial reply LLSD that will be further decorated before
+ * being sent as the reply
+ *
+ * @a request is the incoming request LLSD; we particularly care about
+ * [replyKey] and ["reqid"]
+ *
+ * @a replyKey [default "reply"] is the string name of the LLEventPump
+ * on which the caller wants a reply. If <tt>(!
+ * request.has(replyKey))</tt>, no reply will be sent.
+ */
+ Response(const LLSD& seed, const LLSD& request, const LLSD::String& replyKey="reply");
+ ~Response();
+
+ /**
+ * @code
+ * if (some condition)
+ * {
+ * response.warn("warnings are logged and collected in [\"warnings\"]");
+ * }
+ * @endcode
+ */
+ void warn(const std::string& warning);
+ /**
+ * @code
+ * if (some condition isn't met)
+ * {
+ * // In a function returning void, you can validly 'return
+ * // expression' if the expression is itself of type void. But
+ * // returning is up to you; response.error() has no effect on
+ * // flow of control.
+ * return response.error("error message, logged and also sent as [\"error\"]");
+ * }
+ * @endcode
+ */
+ void error(const std::string& error);
+
+ /**
+ * set other keys...
+ *
+ * @code
+ * // set any attributes you want to be sent in the reply
+ * response["info"] = some_value;
+ * // ...
+ * response["ok"] = went_well;
+ * @endcode
+ */
+ LLSD& operator[](const LLSD::String& key) { return mResp[key]; }
+
+ /**
+ * set the response to the given data
+ */
+ void setResponse(LLSD const & response){ mResp = response; }
+
+ LLSD mResp, mReq;
+ LLSD::String mKey;
+ };
+
private:
std::string mDesc;
};
diff --git a/indra/llcommon/llevents.cpp b/indra/llcommon/llevents.cpp
index ff03506e84..db1ea4792b 100644
--- a/indra/llcommon/llevents.cpp
+++ b/indra/llcommon/llevents.cpp
@@ -591,6 +591,17 @@ void LLReqID::stamp(LLSD& response) const
bool sendReply(const LLSD& reply, const LLSD& request, const std::string& replyKey)
{
+ // If the original request has no value for replyKey, it's pointless to
+ // construct or send a reply event: on which LLEventPump should we send
+ // it? Allow that to be optional: if the caller wants to require replyKey,
+ // it can so specify when registering the operation method.
+ if (! request.has(replyKey))
+ {
+ return false;
+ }
+
+ // Here the request definitely contains replyKey; reasonable to proceed.
+
// Copy 'reply' to modify it.
LLSD newreply(reply);
// Get the ["reqid"] element from request
diff --git a/indra/llcommon/llqueuedthread.cpp b/indra/llcommon/llqueuedthread.cpp
index efd9c4b68f..5dee7a3541 100644
--- a/indra/llcommon/llqueuedthread.cpp
+++ b/indra/llcommon/llqueuedthread.cpp
@@ -32,7 +32,7 @@
//============================================================================
// MAIN THREAD
-LLQueuedThread::LLQueuedThread(const std::string& name, bool threaded) :
+LLQueuedThread::LLQueuedThread(const std::string& name, bool threaded, bool should_pause) :
LLThread(name),
mThreaded(threaded),
mIdleThread(TRUE),
@@ -41,6 +41,11 @@ LLQueuedThread::LLQueuedThread(const std::string& name, bool threaded) :
{
if (mThreaded)
{
+ if(should_pause)
+ {
+ pause() ; //call this before start the thread.
+ }
+
start();
}
}
diff --git a/indra/llcommon/llqueuedthread.h b/indra/llcommon/llqueuedthread.h
index a53b22f6fc..499d13a792 100644
--- a/indra/llcommon/llqueuedthread.h
+++ b/indra/llcommon/llqueuedthread.h
@@ -149,7 +149,7 @@ public:
static handle_t nullHandle() { return handle_t(0); }
public:
- LLQueuedThread(const std::string& name, bool threaded = true);
+ LLQueuedThread(const std::string& name, bool threaded = true, bool should_pause = false);
virtual ~LLQueuedThread();
virtual void shutdown();
diff --git a/indra/llcommon/llworkerthread.cpp b/indra/llcommon/llworkerthread.cpp
index 6b308bb917..e186621503 100644
--- a/indra/llcommon/llworkerthread.cpp
+++ b/indra/llcommon/llworkerthread.cpp
@@ -34,8 +34,8 @@
//============================================================================
// Run on MAIN thread
-LLWorkerThread::LLWorkerThread(const std::string& name, bool threaded) :
- LLQueuedThread(name, threaded)
+LLWorkerThread::LLWorkerThread(const std::string& name, bool threaded, bool should_pause) :
+ LLQueuedThread(name, threaded, should_pause)
{
mDeleteMutex = new LLMutex;
}
diff --git a/indra/llcommon/llworkerthread.h b/indra/llcommon/llworkerthread.h
index bef5ef53fe..973b78ca01 100644
--- a/indra/llcommon/llworkerthread.h
+++ b/indra/llcommon/llworkerthread.h
@@ -83,7 +83,7 @@ private:
LLMutex* mDeleteMutex;
public:
- LLWorkerThread(const std::string& name, bool threaded = true);
+ LLWorkerThread(const std::string& name, bool threaded = true, bool should_pause = false);
~LLWorkerThread();
/*virtual*/ S32 update(U32 max_time_ms);