From 00b2b60a0c495656e1b8e0a20272c449eea49b3c Mon Sep 17 00:00:00 2001
From: Rider Linden <rider@lindenlab.com>
Date: Fri, 22 May 2015 16:14:00 -0700
Subject: [PATCH] Region debug console to coroutines.

---
 indra/newview/llfloaterregiondebugconsole.cpp | 50 +++++++++++++++++++
 indra/newview/llfloaterregiondebugconsole.h   |  6 ++-
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/indra/newview/llfloaterregiondebugconsole.cpp b/indra/newview/llfloaterregiondebugconsole.cpp
index 40757a4d049..00955ff941a 100755
--- a/indra/newview/llfloaterregiondebugconsole.cpp
+++ b/indra/newview/llfloaterregiondebugconsole.cpp
@@ -35,6 +35,7 @@
 #include "lllineeditor.h"
 #include "lltexteditor.h"
 #include "llviewerregion.h"
+#include "llcorehttputil.h"
 
 // Two versions of the sim console API are supported.
 //
@@ -68,6 +69,7 @@ namespace
 	const std::string CONSOLE_NOT_SUPPORTED(
 		"This region does not support the simulator console.");
 
+#if 0
 	// This responder handles the initial response. Unless error() is called
 	// we assume that the simulator has received our request. Error will be
 	// called if this request times out.
@@ -119,6 +121,7 @@ namespace
 	public:
 		LLTextEditor * mOutput;
 	};
+#endif
 
 	// This handles responses for console commands sent via the asynchronous
 	// API.
@@ -202,26 +205,73 @@ void LLFloaterRegionDebugConsole::onInput(LLUICtrl* ctrl, const LLSD& param)
 		}
 		else
 		{
+#if 1
+            LLSD postData = LLSD(input->getText());
+            LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpPost(url, postData,
+                boost::bind(&LLFloaterRegionDebugConsole::onConsoleSuccess, this, _1),
+                boost::bind(&LLFloaterRegionDebugConsole::onConsoleError, this, _1));
+#else
 			// Using SimConsole (deprecated)
 			LLHTTPClient::post(
 				url,
 				LLSD(input->getText()),
 				new ConsoleResponder(mOutput));
+#endif
 		}
 	}
 	else
 	{
+#if 1
+        LLSD postData = LLSD(input->getText());
+        LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpPost(url, postData,
+            NULL,
+            boost::bind(&LLFloaterRegionDebugConsole::onAsyncConsoleError, this, _1));
+
+#else
 		// Using SimConsoleAsync
 		LLHTTPClient::post(
 			url,
 			LLSD(input->getText()),
 			new AsyncConsoleResponder);
+#endif
 	}
 
 	mOutput->appendText(text, false);
 	input->clear();
 }
 
+void LLFloaterRegionDebugConsole::onAsyncConsoleError(LLSD result)
+{
+    LL_WARNS("Console") << UNABLE_TO_SEND_COMMAND << LL_ENDL;
+    sConsoleReplySignal(UNABLE_TO_SEND_COMMAND);
+}
+
+void LLFloaterRegionDebugConsole::onConsoleError(LLSD result)
+{
+    LL_WARNS("Console") << UNABLE_TO_SEND_COMMAND << LL_ENDL;
+    if (mOutput)
+    {
+        mOutput->appendText(
+            UNABLE_TO_SEND_COMMAND + PROMPT,
+            false);
+    }
+
+}
+
+void LLFloaterRegionDebugConsole::onConsoleSuccess(LLSD result)
+{
+    if (mOutput)
+    {
+        LLSD response = result;
+        if (response.isMap() && response.has(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT))
+        {
+            response = response[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT];
+        }
+        mOutput->appendText(
+            response.asString() + PROMPT, false);
+    }
+}
+
 void LLFloaterRegionDebugConsole::onReplyReceived(const std::string& output)
 {
 	mOutput->appendText(output + PROMPT, false);
diff --git a/indra/newview/llfloaterregiondebugconsole.h b/indra/newview/llfloaterregiondebugconsole.h
index fd3af4152e9..ee4bd79b178 100755
--- a/indra/newview/llfloaterregiondebugconsole.h
+++ b/indra/newview/llfloaterregiondebugconsole.h
@@ -38,7 +38,7 @@ class LLTextEditor;
 typedef boost::signals2::signal<
 	void (const std::string& output)> console_reply_signal_t;
 
-class LLFloaterRegionDebugConsole : public LLFloater, public LLHTTPClient::Responder
+class LLFloaterRegionDebugConsole : public LLFloater
 {
 public:
 	LLFloaterRegionDebugConsole(LLSD const & key);
@@ -56,6 +56,10 @@ class LLFloaterRegionDebugConsole : public LLFloater, public LLHTTPClient::Respo
  private:
 	void onReplyReceived(const std::string& output);
 
+    void onAsyncConsoleError(LLSD result);
+    void onConsoleError(LLSD result);
+    void onConsoleSuccess(LLSD result);
+
 	boost::signals2::connection mReplySignalConnection;
 };
 
-- 
GitLab