summaryrefslogtreecommitdiff
path: root/indra/newview/llinventorymodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llinventorymodel.cpp')
-rwxr-xr-xindra/newview/llinventorymodel.cpp115
1 files changed, 55 insertions, 60 deletions
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index f92332dea5..6d21dd4ba7 100755
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -524,59 +524,6 @@ const LLUUID LLInventoryModel::findLibraryCategoryUUIDForType(LLFolderType::ETyp
return findCategoryUUIDForTypeInRoot(preferred_type, create_folder, gInventory.getLibraryRootFolderID());
}
-class LLCreateInventoryCategoryResponder : public LLHTTPClient::Responder
-{
- LOG_CLASS(LLCreateInventoryCategoryResponder);
-public:
- LLCreateInventoryCategoryResponder(LLInventoryModel* model,
- boost::optional<inventory_func_type> callback):
- mModel(model),
- mCallback(callback)
- {
- }
-
-protected:
- virtual void httpFailure()
- {
- LL_WARNS(LOG_INV) << dumpResponse() << LL_ENDL;
- }
-
- virtual void httpSuccess()
- {
- //Server has created folder.
- const LLSD& content = getContent();
- if (!content.isMap() || !content.has("folder_id"))
- {
- failureResult(HTTP_INTERNAL_ERROR, "Malformed response contents", content);
- return;
- }
- LLUUID category_id = content["folder_id"].asUUID();
-
- LL_DEBUGS(LOG_INV) << ll_pretty_print_sd(content) << LL_ENDL;
- // Add the category to the internal representation
- LLPointer<LLViewerInventoryCategory> cat =
- new LLViewerInventoryCategory( category_id,
- content["parent_id"].asUUID(),
- (LLFolderType::EType)content["type"].asInteger(),
- content["name"].asString(),
- gAgent.getID() );
- cat->setVersion(LLViewerInventoryCategory::VERSION_INITIAL);
- cat->setDescendentCount(0);
- LLInventoryModel::LLCategoryUpdate update(cat->getParentUUID(), 1);
- mModel->accountForUpdate(update);
- mModel->updateCategory(cat);
-
- if (mCallback)
- {
- mCallback.get()(category_id);
- }
- }
-
-private:
- boost::optional<inventory_func_type> mCallback;
- LLInventoryModel* mModel;
-};
-
// Convenience function to create a new category. You could call
// updateCategory() with a newly generated UUID category, but this
// version will take care of details like what the name should be
@@ -584,7 +531,7 @@ private:
LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id,
LLFolderType::EType preferred_type,
const std::string& pname,
- boost::optional<inventory_func_type> callback)
+ inventory_func_type callback)
{
LLUUID id;
@@ -616,7 +563,7 @@ LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id,
if ( viewer_region )
url = viewer_region->getCapability("CreateInventoryCategory");
- if (!url.empty() && callback.get_ptr())
+ if (!url.empty() && callback)
{
//Let's use the new capability.
@@ -630,11 +577,8 @@ LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id,
request["payload"] = body;
LL_DEBUGS(LOG_INV) << "create category request: " << ll_pretty_print_sd(request) << LL_ENDL;
- // viewer_region->getCapAPI().post(request);
- LLHTTPClient::post(
- url,
- body,
- new LLCreateInventoryCategoryResponder(this, callback) );
+ LLCoros::instance().launch("LLInventoryModel::createNewCategoryCoro",
+ boost::bind(&LLInventoryModel::createNewCategoryCoro, this, _1, url, body, callback));
return LLUUID::null;
}
@@ -663,6 +607,57 @@ LLUUID LLInventoryModel::createNewCategory(const LLUUID& parent_id,
return id;
}
+void LLInventoryModel::createNewCategoryCoro(LLCoros::self& self, std::string url, LLSD postData, inventory_func_type callback)
+{
+ LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+ LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+ httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("createNewCategoryCoro", httpPolicy));
+ LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest);
+ LLCore::HttpOptions::ptr_t httpOpts = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions);
+
+
+ httpOpts->setWantHeaders(true);
+
+ LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Generic POST for " << url << LL_ENDL;
+
+ LLSD result = httpAdapter->postAndYield(self, httpRequest, url, postData, httpOpts);
+
+ LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+ LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+ if (!status)
+ {
+ LL_WARNS() << "HTTP failure attempting to create category." << LL_ENDL;
+ return;
+ }
+
+ if (!result.has("folder_id"))
+ {
+ LL_WARNS() << "Malformed response contents" << ll_pretty_print_sd(result) << LL_ENDL;
+ return;
+ }
+
+ LLUUID categoryId = result["folder_id"].asUUID();
+
+ // Add the category to the internal representation
+ LLPointer<LLViewerInventoryCategory> cat = new LLViewerInventoryCategory(categoryId,
+ result["parent_id"].asUUID(), (LLFolderType::EType)result["type"].asInteger(),
+ result["name"].asString(), gAgent.getID());
+
+ cat->setVersion(LLViewerInventoryCategory::VERSION_INITIAL);
+ cat->setDescendentCount(0);
+ LLInventoryModel::LLCategoryUpdate update(cat->getParentUUID(), 1);
+
+ accountForUpdate(update);
+ updateCategory(cat);
+
+ if (callback)
+ {
+ callback(categoryId);
+ }
+
+}
+
// This is optimized for the case that we just want to know whether a
// category has any immediate children meeting a condition, without
// needing to recurse or build up any lists.