summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
authorRider Linden <rider@lindenlab.com>2015-05-14 10:33:46 -0700
committerRider Linden <rider@lindenlab.com>2015-05-14 10:33:46 -0700
commit9ec050a0673c28b25eeb28ae7926ff1070cbb4c3 (patch)
tree5c2599b149fe89060013189a5dae14a62f469043 /indra
parent77cd190633abfb10f5bd66a36035e45382242aad (diff)
Make generic callback version of trivial GET/PUT methods. Make message use these methods.
Diffstat (limited to 'indra')
-rw-r--r--indra/llmessage/llcorehttputil.cpp75
-rw-r--r--indra/llmessage/llcorehttputil.h20
-rwxr-xr-xindra/newview/llfloaterregioninfo.cpp4
-rwxr-xr-xindra/newview/llviewerstats.cpp2
4 files changed, 75 insertions, 26 deletions
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index 2ef9f59e2f..521131a986 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -39,6 +39,16 @@ using namespace LLCore;
namespace LLCoreHttpUtil
{
+void logMessageSuccess(std::string logAuth, std::string url, std::string message)
+{
+ LL_INFOS() << logAuth << " Success '" << message << "' for " << url << LL_ENDL;
+}
+
+void logMessageFail(std::string logAuth, std::string url, std::string message)
+{
+ LL_WARNS() << logAuth << " Failure '" << message << "' for " << url << LL_ENDL;
+}
+
//=========================================================================
/// The HttpRequestPumper is a utility class. When constructed it will poll the
/// supplied HttpRequest once per frame until it is destroyed.
@@ -698,14 +708,24 @@ LLCore::HttpStatus HttpCoroutineAdapter::getStatusFromLLSD(const LLSD &httpResul
}
/*static*/
-void HttpCoroutineAdapter::genericHttpGet(const std::string &url, const std::string &success, const std::string &failure)
+void HttpCoroutineAdapter::callbackHttpGet(const std::string &url, completionCallback_t success, completionCallback_t failure)
{
LLCoros::instance().launch("HttpCoroutineAdapter::genericGetCoro",
- boost::bind(&HttpCoroutineAdapter::genericGetCoro, _1, url, success, failure));
+ boost::bind(&HttpCoroutineAdapter::trivialGetCoro, _1, url, success, failure));
}
/*static*/
-void HttpCoroutineAdapter::genericGetCoro(LLCoros::self& self, std::string &url, std::string success, std::string failure)
+void HttpCoroutineAdapter::messageHttpGet(const std::string &url, const std::string &success, const std::string &failure)
+{
+ completionCallback_t cbSuccess = (success.empty()) ? NULL :
+ static_cast<completionCallback_t>(boost::bind(&logMessageSuccess, "HttpCoroutineAdapter", url, success));
+ completionCallback_t cbFailure = (failure.empty()) ? NULL :
+ static_cast<completionCallback_t>(boost::bind(&logMessageFail, "HttpCoroutineAdapter", url, failure));
+ callbackHttpGet(url, cbSuccess, cbFailure);
+}
+
+/*static*/
+void HttpCoroutineAdapter::trivialGetCoro(LLCoros::self& self, std::string &url, completionCallback_t success, completionCallback_t failure)
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
@@ -719,28 +739,43 @@ void HttpCoroutineAdapter::genericGetCoro(LLCoros::self& self, std::string &url,
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
- if (status)
+ if (!status)
{
- LL_INFOS("HttpCoroutineAdapter", "genericGetCoro") << "Success for " << url << std::endl <<
- "Message: '" << success << "'" << LL_ENDL;
+ if (failure)
+ {
+ failure(httpResults);
+ }
}
else
{
- LL_WARNS("HttpCoroutineAdapter", "genericGetCoro") << "Failure for " << url << std::endl <<
- "Message: '" << failure << "'" << std::endl <<
- "Status: " << status.toTerseString() << ": " << status.getMessage() << LL_ENDL;
+ if (success)
+ { // remove the added http_result entry from the results before calling the callback.
+ result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
+ success(result);
+ }
}
}
/*static*/
-void HttpCoroutineAdapter::genericHttpPost(const std::string &url, const LLSD &postData, const std::string &success, const std::string &failure)
+void HttpCoroutineAdapter::callbackHttpPost(const std::string &url, const LLSD &postData, completionCallback_t success, completionCallback_t failure)
{
LLCoros::instance().launch("HttpCoroutineAdapter::genericPostCoro",
- boost::bind(&HttpCoroutineAdapter::genericPostCoro, _1, url, postData, success, failure));
+ boost::bind(&HttpCoroutineAdapter::trivialPostCoro, _1, url, postData, success, failure));
}
/*static*/
-void HttpCoroutineAdapter::genericPostCoro(LLCoros::self& self, std::string &url, LLSD postData, std::string success, std::string failure)
+void HttpCoroutineAdapter::messageHttpPost(const std::string &url, const LLSD &postData, const std::string &success, const std::string &failure)
+{
+ completionCallback_t cbSuccess = (success.empty()) ? NULL :
+ static_cast<completionCallback_t>(boost::bind(&logMessageSuccess, "HttpCoroutineAdapter", url, success));
+ completionCallback_t cbFailure = (failure.empty()) ? NULL :
+ static_cast<completionCallback_t>(boost::bind(&logMessageFail, "HttpCoroutineAdapter", url, failure));
+
+ callbackHttpPost(url, postData, cbSuccess, cbFailure);
+}
+
+/*static*/
+void HttpCoroutineAdapter::trivialPostCoro(LLCoros::self& self, std::string &url, LLSD postData, completionCallback_t success, completionCallback_t failure)
{
LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
@@ -754,16 +789,20 @@ void HttpCoroutineAdapter::genericPostCoro(LLCoros::self& self, std::string &url
LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
- if (status)
+ if (!status)
{
- LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Success for " << url << std::endl <<
- "Message: '" << success << "'" << LL_ENDL;
+ if (failure)
+ {
+ failure(httpResults);
+ }
}
else
{
- LL_WARNS("HttpCoroutineAdapter", "genericPostCoro") << "Failure for " << url << std::endl <<
- "Message: '" << failure << "'" << std::endl <<
- "Status: " << status.toTerseString() << ": " << status.getMessage() << LL_ENDL;
+ if (success)
+ { // remove the added http_result entry from the results before calling the callback.
+ result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
+ success(result);
+ }
}
}
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index 7d60bfbbaf..73a51fe83a 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -387,16 +387,26 @@ public:
///
void cancelYieldingOperation();
-
static LLCore::HttpStatus getStatusFromLLSD(const LLSD &httpResults);
+ /// The convenience routines below can be provided with callback functors
+ /// which will be invoked in the case of success or failure. These callbacks
+ /// should match this form.
+ /// @sa callbackHttpGet
+ /// @sa callbackHttpPost
+ typedef boost::function<void (const LLSD &)> completionCallback_t;
+
+ static void callbackHttpGet(const std::string &url, completionCallback_t success = NULL, completionCallback_t failure = NULL);
+ static void callbackHttpPost(const std::string &url, const LLSD &postData, completionCallback_t success = NULL, completionCallback_t failure = NULL);
+
/// Generic Get and post routines for HTTP via coroutines.
/// These static methods do all required setup for the GET or POST operation.
/// When the operation completes successfully they will put the success message in the log at INFO level,
/// If the operation fails the failure message is written to the log at WARN level.
///
- static void genericHttpGet(const std::string &url, const std::string &success = std::string(), const std::string &failure = std::string());
- static void genericHttpPost(const std::string &url, const LLSD &postData, const std::string &success, const std::string &failure);
+ static void messageHttpGet(const std::string &url, const std::string &success = std::string(), const std::string &failure = std::string());
+ static void messageHttpPost(const std::string &url, const LLSD &postData, const std::string &success, const std::string &failure);
+
private:
static LLSD buildImmediateErrorResult(const LLCore::HttpRequest::ptr_t &request, const std::string &url);
@@ -428,8 +438,8 @@ private:
const std::string & url, LLCore::HttpOptions::ptr_t &options,
LLCore::HttpHeaders::ptr_t &headers, HttpCoroHandler::ptr_t &handler);
- static void genericGetCoro(LLCoros::self& self, std::string &url, std::string success, std::string failure);
- static void genericPostCoro(LLCoros::self& self, std::string &url, LLSD postData, std::string success, std::string failure);
+ static void trivialGetCoro(LLCoros::self& self, std::string &url, completionCallback_t success, completionCallback_t failure);
+ static void trivialPostCoro(LLCoros::self& self, std::string &url, LLSD postData, completionCallback_t success, completionCallback_t failure);
std::string mAdapterName;
LLCore::HttpRequest::priority_t mPriority;
diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp
index 42c03e22eb..3b1de45697 100755
--- a/indra/newview/llfloaterregioninfo.cpp
+++ b/indra/newview/llfloaterregioninfo.cpp
@@ -777,7 +777,7 @@ void LLFloaterRegionInfo::requestMeshRezInfo()
{
std::string request_str = "get mesh_rez_enabled";
- LLCoreHttpUtil::HttpCoroutineAdapter::genericHttpPost(sim_console_url, LLSD(request_str),
+ LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(sim_console_url, LLSD(request_str),
"Requested mesh_rez_enabled", "Error requesting mesh_rez_enabled");
}
}
@@ -814,7 +814,7 @@ BOOL LLPanelRegionGeneralInfo::sendUpdate()
body["allow_parcel_changes"] = getChild<LLUICtrl>("allow_parcel_changes_check")->getValue();
body["block_parcel_search"] = getChild<LLUICtrl>("block_parcel_search_check")->getValue();
- LLCoreHttpUtil::HttpCoroutineAdapter::genericHttpPost(url, body,
+ LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, body,
"Region info update posted.", "Region info update not posted.");
}
else
diff --git a/indra/newview/llviewerstats.cpp b/indra/newview/llviewerstats.cpp
index c6292cec5b..2c3067cd3a 100755
--- a/indra/newview/llviewerstats.cpp
+++ b/indra/newview/llviewerstats.cpp
@@ -601,7 +601,7 @@ void send_stats()
body["MinimalSkin"] = false;
LLViewerStats::getInstance()->addToMessage(body);
- LLCoreHttpUtil::HttpCoroutineAdapter::genericHttpPost(url, body,
+ LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, body,
"Statistics posted to sim", "Failed to post statistics to sim");
LLViewerStats::instance().getRecording().resume();
}