From 96d04a050b4eee3fc0e0728043d5aa960d06eb9e Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 30 Jul 2015 16:13:56 -0700 Subject: Added patchAndYield to httputil adapter Converted All AISv3 commands (except copyLibrary) to coro model. --- indra/newview/llaisapi.cpp | 698 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 557 insertions(+), 141 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 9d887a61f1..3565c04609 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -36,6 +36,422 @@ #include "llinventoryobserver.h" #include "llviewercontrol.h" +///---------------------------------------------------------------------------- +#if 1 +/*static*/ +void AISAPI::CreateInventoryCommand(const LLUUID& parentId, const LLSD& newInventory, completion_t callback) +{ +#if 1 + std::string cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + LLUUID tid; + tid.generate(); + + std::string url = cap + std::string("/category/") + parentId.asString() + "?tid=" + tid.asString(); + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + // I may be suffering from golden hammer here, but the first part of this bind + // is actually a static cast for &HttpCoroutineAdapter::postAndYield so that + // the compiler can identify the correct signature to select. + // + // Reads as follows: + // LLSD - method returning LLSD + // (LLCoreHttpUtil::HttpCoroutineAdapter::*) - pointer to member function of HttpCoroutineAdapter + // (LLCore::HttpRequest::ptr_t, const std::string &, const LLSD &, LLCore::HttpOptions::ptr_t, LLCore::HttpHeaders::ptr_t) - signature of method + // + invokationFn_t postFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::postAndYield), _1, _2, _3, _4, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, postFn, url, parentId, newInventory, callback)); +#else + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::CreateInventoryCommandCoro, + _1, parentId, newInventory, callback)); + +#endif + EnqueueAISCommand("CreateInventory", proc); + +} + +/*static*/ +void AISAPI::SlamFolderCommand(const LLUUID& folderId, const LLSD& newInventory, completion_t callback) +{ +#if 1 + std::string cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + LLUUID tid; + tid.generate(); + + std::string url = cap + std::string("/category/") + folderId.asString() + "/links?tid=" + tid.asString(); + + // see comment above in CreateInventoryCommand + invokationFn_t putFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndYield), _1, _2, _3, _4, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, putFn, url, folderId, newInventory, callback)); + +#else + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::SlamFolderCommandCoro, + _1, folderId, newInventory, callback)); +#endif + + EnqueueAISCommand("SlamFolder", proc); +} + +void AISAPI::RemoveCategoryCommand(const LLUUID &categoryId, completion_t callback) +{ + std::string cap; + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + std::string url = cap + std::string("/category/") + categoryId.asString(); + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + invokationFn_t delFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, delFn, url, categoryId, LLSD(), callback)); + + EnqueueAISCommand("RemoveCategory", proc); +} + +/*static*/ +void AISAPI::RemoveItemCommand(const LLUUID &itemId, completion_t callback) +{ +#if 1 + std::string cap; + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + std::string url = cap + std::string("/item/") + itemId.asString(); + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + invokationFn_t delFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, delFn, url, itemId, LLSD(), callback)); + +#else + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::RemoveItemCommandCoro, + _1, itemId, callback)); +#endif + + EnqueueAISCommand("RemoveItem", proc); +} + + +/*static*/ +void AISAPI::PurgeDescendentsCommand(const LLUUID &categoryId, completion_t callback) +{ + std::string cap; + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + std::string url = cap + std::string("/category/") + categoryId.asString() + "/children"; + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + invokationFn_t delFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, delFn, url, categoryId, LLSD(), callback)); + + EnqueueAISCommand("PurgeDescendents", proc); +} + + +/*static*/ +void AISAPI::UpdateCategoryCommand(const LLUUID &categoryId, const LLSD &updates, completion_t callback) +{ + std::string cap; + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + std::string url = cap + std::string("/category/") + categoryId.asString(); + + invokationFn_t patchFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndYield), _1, _2, _3, _4, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, patchFn, url, categoryId, updates, callback)); + + EnqueueAISCommand("UpdateCategory", proc); +} + +/*static*/ +void AISAPI::UpdateItemCommand(const LLUUID &itemId, const LLSD &updates, completion_t callback) +{ + + std::string cap; + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + std::string url = cap + std::string("/item/") + itemId.asString(); + + invokationFn_t patchFn = boost::bind( + // Humans ignore next line. It is just a cast. + static_cast + //---- + (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndYield), _1, _2, _3, _4, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, patchFn, url, itemId, updates, callback)); + + EnqueueAISCommand("UpdateItem", proc); +} + +/*static*/ +void AISAPI::EnqueueAISCommand(const std::string &procName, LLCoprocedureManager::CoProcedure_t proc) +{ + std::string procFullName = "AIS(" + procName + ")"; + LLCoprocedureManager::getInstance()->enqueueCoprocedure("AIS", procFullName, proc); + +} + +/*static*/ +std::string AISAPI::getInvCap() +{ + if (gAgent.getRegion()) + { + return gAgent.getRegion()->getCapability("InventoryAPIv3"); + } + + return std::string(); +} + +/*static*/ +std::string AISAPI::getLibCap() +{ + if (gAgent.getRegion()) + { + return gAgent.getRegion()->getCapability("LibraryAPIv3"); + } + return std::string(); +} + +/*static*/ +void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, + invokationFn_t invoke, std::string url, + LLUUID targetId, LLSD body, completion_t callback) +{ + LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + LLCore::HttpHeaders::ptr_t httpHeaders; + + httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); + + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + LLSD result = invoke(httpAdapter, httpRequest, url, body, httpOptions, httpHeaders); + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status || !result.isMap()) + { + if (!result.isMap()) + { + status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); + } + LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; + LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; + } + + gInventory.onAISUpdateReceived("AISCommand", result); + + if (callback) + { // UUID always null + callback(LLUUID::null); + } + +} + +#if 0 +/*static*/ +void AISAPI::CreateInventoryCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, LLUUID parentId, LLSD newInventory, completion_t callback) +{ + std::string cap; + LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + LLUUID tid; + tid.generate(); + + std::string url = cap + std::string("/category/") + parentId.asString() + "?tid=" + tid.asString(); + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + LLSD result = httpAdapter->postAndYield(httpRequest, url, newInventory, httpOptions); + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status || !result.isMap()) + { + if (!result.isMap()) + { + status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); + } + LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; + LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; + } + + gInventory.onAISUpdateReceived("AISCommand", result); + + if (callback) + { // UUID always null + callback(LLUUID::null); + } + +} + +/*static*/ +void AISAPI::SlamFolderCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, LLUUID folderId, LLSD newInventory, completion_t callback) +{ + std::string cap; + LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + LLUUID tid; + tid.generate(); + + std::string url = cap + std::string("/category/") + folderId.asString() + "/links?tid=" + tid.asString(); + + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + LLSD result = httpAdapter->putAndYield(httpRequest, url, newInventory, httpOptions); + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status || !result.isMap()) + { + if (!result.isMap()) + { + status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); + } + LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; + LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; + } + + gInventory.onAISUpdateReceived("AISCommand", result); + + if (callback) + { // UUID always null + callback(LLUUID::null); + } + +} + +void AISAPI::RemoveItemCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, LLUUID itemId, completion_t callback) +{ + std::string cap; + LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); + + httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); + + cap = getInvCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; + return; + } + + std::string url = cap + std::string("/item/") + itemId.asString(); + LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + + LLSD result = httpAdapter->deleteAndYield(httpRequest, url, httpOptions); + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status || !result.isMap()) + { + if (!result.isMap()) + { + status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); + } + LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; + LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; + } + + gInventory.onAISUpdateReceived("AISCommand", result); + + if (callback) + { // UUID always null + callback(LLUUID::null); + } +} +#endif +#endif ///---------------------------------------------------------------------------- /// Classes for AISv3 support. ///---------------------------------------------------------------------------- @@ -165,153 +581,153 @@ void AISCommand::getCapabilityNames(LLSD& capabilityNames) capabilityNames.append("LibraryAPIv3"); } -RemoveItemCommand::RemoveItemCommand(const LLUUID& item_id, - LLPointer callback): - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - std::string url = cap + std::string("/item/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - LLHTTPClient::ResponderPtr responder = this; - LLSD headers; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); - setCommandFunc(cmd); -} +// RemoveItemCommand::RemoveItemCommand(const LLUUID& item_id, +// LLPointer callback): +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// std::string url = cap + std::string("/item/") + item_id.asString(); +// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; +// LLHTTPClient::ResponderPtr responder = this; +// LLSD headers; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); +// setCommandFunc(cmd); +// } -RemoveCategoryCommand::RemoveCategoryCommand(const LLUUID& item_id, - LLPointer callback): - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - std::string url = cap + std::string("/category/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - LLHTTPClient::ResponderPtr responder = this; - LLSD headers; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); - setCommandFunc(cmd); -} +// RemoveCategoryCommand::RemoveCategoryCommand(const LLUUID& item_id, +// LLPointer callback): +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// std::string url = cap + std::string("/category/") + item_id.asString(); +// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; +// LLHTTPClient::ResponderPtr responder = this; +// LLSD headers; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); +// setCommandFunc(cmd); +// } -PurgeDescendentsCommand::PurgeDescendentsCommand(const LLUUID& item_id, - LLPointer callback): - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - LLCurl::ResponderPtr responder = this; - LLSD headers; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); - setCommandFunc(cmd); -} +// PurgeDescendentsCommand::PurgeDescendentsCommand(const LLUUID& item_id, +// LLPointer callback): +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; +// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; +// LLCurl::ResponderPtr responder = this; +// LLSD headers; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); +// setCommandFunc(cmd); +// } -UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, - const LLSD& updates, - LLPointer callback): - mUpdates(updates), - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - std::string url = cap + std::string("/item/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << LL_ENDL; - LLCurl::ResponderPtr responder = this; - LLSD headers; - headers["Content-Type"] = "application/llsd+xml"; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); - setCommandFunc(cmd); -} +// UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, +// const LLSD& updates, +// LLPointer callback): +// mUpdates(updates), +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// std::string url = cap + std::string("/item/") + item_id.asString(); +// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; +// LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << LL_ENDL; +// LLCurl::ResponderPtr responder = this; +// LLSD headers; +// headers["Content-Type"] = "application/llsd+xml"; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); +// setCommandFunc(cmd); +// } -UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& cat_id, - const LLSD& updates, - LLPointer callback): - mUpdates(updates), - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - std::string url = cap + std::string("/category/") + cat_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - LLCurl::ResponderPtr responder = this; - LLSD headers; - headers["Content-Type"] = "application/llsd+xml"; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); - setCommandFunc(cmd); -} +// UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& cat_id, +// const LLSD& updates, +// LLPointer callback): +// mUpdates(updates), +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// std::string url = cap + std::string("/category/") + cat_id.asString(); +// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; +// LLCurl::ResponderPtr responder = this; +// LLSD headers; +// headers["Content-Type"] = "application/llsd+xml"; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); +// setCommandFunc(cmd); +// } -CreateInventoryCommand::CreateInventoryCommand(const LLUUID& parent_id, - const LLSD& new_inventory, - LLPointer callback): - mNewInventory(new_inventory), - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - LLUUID tid; - tid.generate(); - std::string url = cap + std::string("/category/") + parent_id.asString() + "?tid=" + tid.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - LLCurl::ResponderPtr responder = this; - LLSD headers; - headers["Content-Type"] = "application/llsd+xml"; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::post, url, mNewInventory, responder, headers, timeout); - setCommandFunc(cmd); -} +// CreateInventoryCommand::CreateInventoryCommand(const LLUUID& parent_id, +// const LLSD& new_inventory, +// LLPointer callback): +// mNewInventory(new_inventory), +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// LLUUID tid; +// tid.generate(); +// std::string url = cap + std::string("/category/") + parent_id.asString() + "?tid=" + tid.asString(); +// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; +// LLCurl::ResponderPtr responder = this; +// LLSD headers; +// headers["Content-Type"] = "application/llsd+xml"; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::post, url, mNewInventory, responder, headers, timeout); +// setCommandFunc(cmd); +// } -SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& contents, LLPointer callback): - mContents(contents), - AISCommand(callback) -{ - std::string cap; - if (!getInvCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - LLUUID tid; - tid.generate(); - std::string url = cap + std::string("/category/") + folder_id.asString() + "/links?tid=" + tid.asString(); - LL_INFOS() << url << LL_ENDL; - LLCurl::ResponderPtr responder = this; - LLSD headers; - headers["Content-Type"] = "application/llsd+xml"; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::put, url, mContents, responder, headers, timeout); - setCommandFunc(cmd); -} +// SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& contents, LLPointer callback): +// mContents(contents), +// AISCommand(callback) +// { +// std::string cap; +// if (!getInvCap(cap)) +// { +// LL_WARNS() << "No cap found" << LL_ENDL; +// return; +// } +// LLUUID tid; +// tid.generate(); +// std::string url = cap + std::string("/category/") + folder_id.asString() + "/links?tid=" + tid.asString(); +// LL_INFOS() << url << LL_ENDL; +// LLCurl::ResponderPtr responder = this; +// LLSD headers; +// headers["Content-Type"] = "application/llsd+xml"; +// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; +// command_func_type cmd = boost::bind(&LLHTTPClient::put, url, mContents, responder, headers, timeout); +// setCommandFunc(cmd); +// } CopyLibraryCategoryCommand::CopyLibraryCategoryCommand(const LLUUID& source_id, const LLUUID& dest_id, -- cgit v1.2.3 From 248d61fe0eadd128c7704e37922ba7fdef35d630 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Wed, 12 Aug 2015 16:32:49 -0700 Subject: MAINT-5500: Finish converting the AIS responders to the new coroutine model, Cleaned up dead an unused code. MAINT-4952: Added COPY and MOVE methods to Core:Http adapter --- indra/newview/llaisapi.cpp | 659 +++++++++++---------------------------------- 1 file changed, 154 insertions(+), 505 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 3565c04609..23ea692a16 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -37,11 +37,54 @@ #include "llviewercontrol.h" ///---------------------------------------------------------------------------- -#if 1 +/// Classes for AISv3 support. +///---------------------------------------------------------------------------- + +//========================================================================= +const std::string AISAPI::INVENTORY_CAP_NAME("InventoryAPIv3"); +const std::string AISAPI::LIBRARY_CAP_NAME("LibraryAPIv3"); + +//------------------------------------------------------------------------- +/*static*/ +bool AISAPI::isAvailable() +{ + if (gAgent.getRegion()) + { + return gAgent.getRegion()->isCapabilityAvailable(INVENTORY_CAP_NAME); + } + return false; +} + +/*static*/ +void AISAPI::getCapNames(LLSD& capNames) +{ + capNames.append(INVENTORY_CAP_NAME); + capNames.append(LIBRARY_CAP_NAME); +} + +/*static*/ +std::string AISAPI::getInvCap() +{ + if (gAgent.getRegion()) + { + return gAgent.getRegion()->getCapability(INVENTORY_CAP_NAME); + } + return std::string(); +} + +/*static*/ +std::string AISAPI::getLibCap() +{ + if (gAgent.getRegion()) + { + return gAgent.getRegion()->getCapability(LIBRARY_CAP_NAME); + } + return std::string(); +} + /*static*/ -void AISAPI::CreateInventoryCommand(const LLUUID& parentId, const LLSD& newInventory, completion_t callback) +void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, completion_t callback) { -#if 1 std::string cap = getInvCap(); if (cap.empty()) { @@ -68,23 +111,22 @@ void AISAPI::CreateInventoryCommand(const LLUUID& parentId, const LLSD& newInven // Humans ignore next line. It is just a cast. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::postAndYield), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, postFn, url, parentId, newInventory, callback)); -#else - LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::CreateInventoryCommandCoro, - _1, parentId, newInventory, callback)); - -#endif + _1, postFn, url, parentId, newInventory, callback, COPYINVENTORY)); EnqueueAISCommand("CreateInventory", proc); - } /*static*/ -void AISAPI::SlamFolderCommand(const LLUUID& folderId, const LLSD& newInventory, completion_t callback) +void AISAPI::SlamFolder(const LLUUID& folderId, const LLSD& newInventory, completion_t callback) { -#if 1 std::string cap = getInvCap(); if (cap.empty()) { @@ -99,23 +141,24 @@ void AISAPI::SlamFolderCommand(const LLUUID& folderId, const LLSD& newInventory, // see comment above in CreateInventoryCommand invokationFn_t putFn = boost::bind( - // Humans ignore next line. It is just a cast. + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndYield), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, putFn, url, folderId, newInventory, callback)); - -#else - LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::SlamFolderCommandCoro, - _1, folderId, newInventory, callback)); -#endif + _1, putFn, url, folderId, newInventory, callback, SLAMFOLDER)); EnqueueAISCommand("SlamFolder", proc); } -void AISAPI::RemoveCategoryCommand(const LLUUID &categoryId, completion_t callback) +void AISAPI::RemoveCategory(const LLUUID &categoryId, completion_t callback) { std::string cap; @@ -130,21 +173,26 @@ void AISAPI::RemoveCategoryCommand(const LLUUID &categoryId, completion_t callba LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; invokationFn_t delFn = boost::bind( - // Humans ignore next line. It is just a cast. + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, delFn, url, categoryId, LLSD(), callback)); + _1, delFn, url, categoryId, LLSD(), callback, REMOVECATEGORY)); EnqueueAISCommand("RemoveCategory", proc); } /*static*/ -void AISAPI::RemoveItemCommand(const LLUUID &itemId, completion_t callback) +void AISAPI::RemoveItem(const LLUUID &itemId, completion_t callback) { -#if 1 std::string cap; cap = getInvCap(); @@ -158,25 +206,64 @@ void AISAPI::RemoveItemCommand(const LLUUID &itemId, completion_t callback) LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; invokationFn_t delFn = boost::bind( - // Humans ignore next line. It is just a cast. + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, delFn, url, itemId, LLSD(), callback)); - -#else - LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::RemoveItemCommandCoro, - _1, itemId, callback)); -#endif + _1, delFn, url, itemId, LLSD(), callback, REMOVEITEM)); EnqueueAISCommand("RemoveItem", proc); } +void AISAPI::CopyLibraryCategory(const LLUUID& sourceId, const LLUUID& destId, completion_t callback) +{ + std::string cap; + + cap = getLibCap(); + if (cap.empty()) + { + LL_WARNS("Inventory") << "Library cap not found!" << LL_ENDL; + return; + } + + LL_DEBUGS("Inventory") << "Copying library category: " << sourceId << " => " << destId << LL_ENDL; + + LLUUID tid; + tid.generate(); + + std::string url = cap + std::string("/category/") + sourceId.asString() + "?tid=" + tid.asString(); + LL_INFOS() << url << LL_ENDL; + + std::string destination = destId.asString(); + + invokationFn_t copyFn = boost::bind( + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. + static_cast + //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders + (&LLCoreHttpUtil::HttpCoroutineAdapter::copyAndYield), _1, _2, _3, destination, _5, _6); + + LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, + _1, copyFn, url, destId, LLSD(), callback, COPYLIBRARYCATEGORY)); + + EnqueueAISCommand("CopyLibraryCategory", proc); +} /*static*/ -void AISAPI::PurgeDescendentsCommand(const LLUUID &categoryId, completion_t callback) +void AISAPI::PurgeDescendents(const LLUUID &categoryId, completion_t callback) { std::string cap; @@ -191,20 +278,26 @@ void AISAPI::PurgeDescendentsCommand(const LLUUID &categoryId, completion_t call LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; invokationFn_t delFn = boost::bind( - // Humans ignore next line. It is just a cast. + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, delFn, url, categoryId, LLSD(), callback)); + _1, delFn, url, categoryId, LLSD(), callback, PURGEDESCENDENTS)); EnqueueAISCommand("PurgeDescendents", proc); } /*static*/ -void AISAPI::UpdateCategoryCommand(const LLUUID &categoryId, const LLSD &updates, completion_t callback) +void AISAPI::UpdateCategory(const LLUUID &categoryId, const LLSD &updates, completion_t callback) { std::string cap; @@ -217,19 +310,25 @@ void AISAPI::UpdateCategoryCommand(const LLUUID &categoryId, const LLSD &updates std::string url = cap + std::string("/category/") + categoryId.asString(); invokationFn_t patchFn = boost::bind( - // Humans ignore next line. It is just a cast. + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndYield), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, patchFn, url, categoryId, updates, callback)); + _1, patchFn, url, categoryId, updates, callback, UPDATECATEGORY)); EnqueueAISCommand("UpdateCategory", proc); } /*static*/ -void AISAPI::UpdateItemCommand(const LLUUID &itemId, const LLSD &updates, completion_t callback) +void AISAPI::UpdateItem(const LLUUID &itemId, const LLSD &updates, completion_t callback) { std::string cap; @@ -243,13 +342,19 @@ void AISAPI::UpdateItemCommand(const LLUUID &itemId, const LLSD &updates, comple std::string url = cap + std::string("/item/") + itemId.asString(); invokationFn_t patchFn = boost::bind( - // Humans ignore next line. It is just a cast. + // Humans ignore next line. It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload. static_cast //---- + // _1 -> httpAdapter + // _2 -> httpRequest + // _3 -> url + // _4 -> body + // _5 -> httpOptions + // _6 -> httpHeaders (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndYield), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, - _1, patchFn, url, itemId, updates, callback)); + _1, patchFn, url, itemId, updates, callback, UPDATEITEM)); EnqueueAISCommand("UpdateItem", proc); } @@ -262,31 +367,10 @@ void AISAPI::EnqueueAISCommand(const std::string &procName, LLCoprocedureManager } -/*static*/ -std::string AISAPI::getInvCap() -{ - if (gAgent.getRegion()) - { - return gAgent.getRegion()->getCapability("InventoryAPIv3"); - } - - return std::string(); -} - -/*static*/ -std::string AISAPI::getLibCap() -{ - if (gAgent.getRegion()) - { - return gAgent.getRegion()->getCapability("LibraryAPIv3"); - } - return std::string(); -} - /*static*/ void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, invokationFn_t invoke, std::string url, - LLUUID targetId, LLSD body, completion_t callback) + LLUUID targetId, LLSD body, completion_t callback, COMMAND_TYPE type) { LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); @@ -313,455 +397,20 @@ void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t ht gInventory.onAISUpdateReceived("AISCommand", result); if (callback) - { // UUID always null - callback(LLUUID::null); - } - -} - -#if 0 -/*static*/ -void AISAPI::CreateInventoryCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, LLUUID parentId, LLSD newInventory, completion_t callback) -{ - std::string cap; - LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); - - httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); - - cap = getInvCap(); - if (cap.empty()) - { - LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; - return; - } - - LLUUID tid; - tid.generate(); + { + LLUUID id(LLUUID::null); - std::string url = cap + std::string("/category/") + parentId.asString() + "?tid=" + tid.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; + if (result.has("category_id") && (type == COPYLIBRARYCATEGORY)) + { + id = result["category_id"]; + } - LLSD result = httpAdapter->postAndYield(httpRequest, url, newInventory, httpOptions); - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (!status || !result.isMap()) - { - if (!result.isMap()) - { - status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); - } - LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; - LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; + callback(id); } - gInventory.onAISUpdateReceived("AISCommand", result); - - if (callback) - { // UUID always null - callback(LLUUID::null); - } - -} - -/*static*/ -void AISAPI::SlamFolderCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, LLUUID folderId, LLSD newInventory, completion_t callback) -{ - std::string cap; - LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); - - httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); - - cap = getInvCap(); - if (cap.empty()) - { - LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; - return; - } - - LLUUID tid; - tid.generate(); - - std::string url = cap + std::string("/category/") + folderId.asString() + "/links?tid=" + tid.asString(); - - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - - LLSD result = httpAdapter->putAndYield(httpRequest, url, newInventory, httpOptions); - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (!status || !result.isMap()) - { - if (!result.isMap()) - { - status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); - } - LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; - LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; - } - - gInventory.onAISUpdateReceived("AISCommand", result); - - if (callback) - { // UUID always null - callback(LLUUID::null); - } - -} - -void AISAPI::RemoveItemCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, LLUUID itemId, completion_t callback) -{ - std::string cap; - LLCore::HttpOptions::ptr_t httpOptions(new LLCore::HttpOptions); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); - - httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); - - cap = getInvCap(); - if (cap.empty()) - { - LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL; - return; - } - - std::string url = cap + std::string("/item/") + itemId.asString(); - LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; - - LLSD result = httpAdapter->deleteAndYield(httpRequest, url, httpOptions); - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (!status || !result.isMap()) - { - if (!result.isMap()) - { - status = LLCore::HttpStatus(HTTP_INTERNAL_ERROR, "Malformed response contents"); - } - LL_WARNS("Inventory") << "Inventory error: " << status.toString() << LL_ENDL; - LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL; - } - - gInventory.onAISUpdateReceived("AISCommand", result); - - if (callback) - { // UUID always null - callback(LLUUID::null); - } -} -#endif -#endif -///---------------------------------------------------------------------------- -/// Classes for AISv3 support. -///---------------------------------------------------------------------------- - -// AISCommand - base class for retry-able HTTP requests using the AISv3 cap. -AISCommand::AISCommand(LLPointer callback): - mCommandFunc(NULL), - mCallback(callback) -{ - mRetryPolicy = new LLAdaptiveRetryPolicy(1.0, 32.0, 2.0, 10); -} - -bool AISCommand::run_command() -{ - if (NULL == mCommandFunc) - { - // This may happen if a command failed to initiate itself. - LL_WARNS("Inventory") << "AIS command attempted with null command function" << LL_ENDL; - return false; - } - else - { - mCommandFunc(); - return true; - } -} - -void AISCommand::setCommandFunc(command_func_type command_func) -{ - mCommandFunc = command_func; -} - -// virtual -bool AISCommand::getResponseUUID(const LLSD& content, LLUUID& id) -{ - return false; -} - -/* virtual */ -void AISCommand::httpSuccess() -{ - // Command func holds a reference to self, need to release it - // after a success or final failure. - setCommandFunc(no_op); - - const LLSD& content = getContent(); - if (!content.isMap()) - { - failureResult(HTTP_INTERNAL_ERROR, "Malformed response contents", content); - return; - } - mRetryPolicy->onSuccess(); - - gInventory.onAISUpdateReceived("AISCommand", content); - - if (mCallback) - { - LLUUID id; // will default to null if parse fails. - getResponseUUID(content,id); - mCallback->fire(id); - } -} - -/*virtual*/ -void AISCommand::httpFailure() -{ - LL_WARNS("Inventory") << dumpResponse() << LL_ENDL; - S32 status = getStatus(); - const LLSD& headers = getResponseHeaders(); - mRetryPolicy->onFailure(status, headers); - F32 seconds_to_wait; - if (mRetryPolicy->shouldRetry(seconds_to_wait)) - { - doAfterInterval(boost::bind(&AISCommand::run_command,this),seconds_to_wait); - } - else - { - // Command func holds a reference to self, need to release it - // after a success or final failure. - // *TODO: Notify user? This seems bad. - setCommandFunc(no_op); - } -} - -//static -bool AISCommand::isAPIAvailable() -{ - if (gAgent.getRegion()) - { - return gAgent.getRegion()->isCapabilityAvailable("InventoryAPIv3"); - } - return false; -} - -//static -bool AISCommand::getInvCap(std::string& cap) -{ - if (gAgent.getRegion()) - { - cap = gAgent.getRegion()->getCapability("InventoryAPIv3"); - } - if (!cap.empty()) - { - return true; - } - return false; -} - -//static -bool AISCommand::getLibCap(std::string& cap) -{ - if (gAgent.getRegion()) - { - cap = gAgent.getRegion()->getCapability("LibraryAPIv3"); - } - if (!cap.empty()) - { - return true; - } - return false; -} - -//static -void AISCommand::getCapabilityNames(LLSD& capabilityNames) -{ - capabilityNames.append("InventoryAPIv3"); - capabilityNames.append("LibraryAPIv3"); -} - -// RemoveItemCommand::RemoveItemCommand(const LLUUID& item_id, -// LLPointer callback): -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// std::string url = cap + std::string("/item/") + item_id.asString(); -// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -// LLHTTPClient::ResponderPtr responder = this; -// LLSD headers; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -// RemoveCategoryCommand::RemoveCategoryCommand(const LLUUID& item_id, -// LLPointer callback): -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// std::string url = cap + std::string("/category/") + item_id.asString(); -// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -// LLHTTPClient::ResponderPtr responder = this; -// LLSD headers; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -// PurgeDescendentsCommand::PurgeDescendentsCommand(const LLUUID& item_id, -// LLPointer callback): -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; -// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -// LLCurl::ResponderPtr responder = this; -// LLSD headers; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::del, url, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -// UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, -// const LLSD& updates, -// LLPointer callback): -// mUpdates(updates), -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// std::string url = cap + std::string("/item/") + item_id.asString(); -// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -// LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << LL_ENDL; -// LLCurl::ResponderPtr responder = this; -// LLSD headers; -// headers["Content-Type"] = "application/llsd+xml"; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -// UpdateCategoryCommand::UpdateCategoryCommand(const LLUUID& cat_id, -// const LLSD& updates, -// LLPointer callback): -// mUpdates(updates), -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// std::string url = cap + std::string("/category/") + cat_id.asString(); -// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -// LLCurl::ResponderPtr responder = this; -// LLSD headers; -// headers["Content-Type"] = "application/llsd+xml"; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::patch, url, mUpdates, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -// CreateInventoryCommand::CreateInventoryCommand(const LLUUID& parent_id, -// const LLSD& new_inventory, -// LLPointer callback): -// mNewInventory(new_inventory), -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// LLUUID tid; -// tid.generate(); -// std::string url = cap + std::string("/category/") + parent_id.asString() + "?tid=" + tid.asString(); -// LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -// LLCurl::ResponderPtr responder = this; -// LLSD headers; -// headers["Content-Type"] = "application/llsd+xml"; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::post, url, mNewInventory, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -// SlamFolderCommand::SlamFolderCommand(const LLUUID& folder_id, const LLSD& contents, LLPointer callback): -// mContents(contents), -// AISCommand(callback) -// { -// std::string cap; -// if (!getInvCap(cap)) -// { -// LL_WARNS() << "No cap found" << LL_ENDL; -// return; -// } -// LLUUID tid; -// tid.generate(); -// std::string url = cap + std::string("/category/") + folder_id.asString() + "/links?tid=" + tid.asString(); -// LL_INFOS() << url << LL_ENDL; -// LLCurl::ResponderPtr responder = this; -// LLSD headers; -// headers["Content-Type"] = "application/llsd+xml"; -// F32 timeout = HTTP_REQUEST_EXPIRY_SECS; -// command_func_type cmd = boost::bind(&LLHTTPClient::put, url, mContents, responder, headers, timeout); -// setCommandFunc(cmd); -// } - -CopyLibraryCategoryCommand::CopyLibraryCategoryCommand(const LLUUID& source_id, - const LLUUID& dest_id, - LLPointer callback): - AISCommand(callback) -{ - std::string cap; - if (!getLibCap(cap)) - { - LL_WARNS() << "No cap found" << LL_ENDL; - return; - } - LL_DEBUGS("Inventory") << "Copying library category: " << source_id << " => " << dest_id << LL_ENDL; - LLUUID tid; - tid.generate(); - std::string url = cap + std::string("/category/") + source_id.asString() + "?tid=" + tid.asString(); - LL_INFOS() << url << LL_ENDL; - LLCurl::ResponderPtr responder = this; - LLSD headers; - F32 timeout = HTTP_REQUEST_EXPIRY_SECS; - command_func_type cmd = boost::bind(&LLHTTPClient::copy, url, dest_id.asString(), responder, headers, timeout); - setCommandFunc(cmd); -} - -bool CopyLibraryCategoryCommand::getResponseUUID(const LLSD& content, LLUUID& id) -{ - if (content.has("category_id")) - { - id = content["category_id"]; - return true; - } - return false; } +//------------------------------------------------------------------------- AISUpdate::AISUpdate(const LLSD& update) { parseUpdate(update); -- cgit v1.2.3 From 02c3262ac8e7f27b0effb546ad235e103c9581cf Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 28 Aug 2015 10:05:15 -0700 Subject: MAINT-5574: Added default parameter for callbalk on AISAPI interface. Better check on callback exsit in coroutine Don't create AISAPI::completion_t if there is no call back passed. --- indra/newview/llaisapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 5d2c48a1b4..da2f69126a 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -400,7 +400,7 @@ void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t ht gInventory.onAISUpdateReceived("AISCommand", result); - if (callback) + if (callback && !callback.empty()) { LLUUID id(LLUUID::null); -- cgit v1.2.3 From 97236a42ca08979897d5c7b0826312345754cd67 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Mon, 14 Sep 2015 11:15:23 -0700 Subject: MAINT-5507: Remove HTTPClient and related cruft. --- indra/newview/llaisapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index da2f69126a..2d877f6a47 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -380,7 +380,7 @@ void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t ht LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest()); LLCore::HttpHeaders::ptr_t httpHeaders; - httpOptions->setTimeout(HTTP_REQUEST_EXPIRY_SECS); + httpOptions->setTimeout(LLCoreHttpUtil::HTTP_REQUEST_EXPIRY_SECS); LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; -- cgit v1.2.3 From 75c6549fde060e974c90636685962ee373f94202 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 18 Sep 2015 11:39:22 -0700 Subject: Set consistent terminology for yield/wait -> suspend for coroutines. --- indra/newview/llaisapi.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 2d877f6a47..5b7380a175 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -99,7 +99,7 @@ void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, c LL_DEBUGS("Inventory") << "url: " << url << LL_ENDL; // I may be suffering from golden hammer here, but the first part of this bind - // is actually a static cast for &HttpCoroutineAdapter::postAndYield so that + // is actually a static cast for &HttpCoroutineAdapter::postAndSuspend so that // the compiler can identify the correct signature to select. // // Reads as follows: @@ -117,7 +117,7 @@ void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, c // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::postAndYield), _1, _2, _3, _4, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::postAndSuspend), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, postFn, url, parentId, newInventory, callback, COPYINVENTORY)); @@ -150,7 +150,7 @@ void AISAPI::SlamFolder(const LLUUID& folderId, const LLSD& newInventory, comple // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndYield), _1, _2, _3, _4, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndSuspend), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, putFn, url, folderId, newInventory, callback, SLAMFOLDER)); @@ -182,7 +182,7 @@ void AISAPI::RemoveCategory(const LLUUID &categoryId, completion_t callback) // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, delFn, url, categoryId, LLSD(), callback, REMOVECATEGORY)); @@ -215,7 +215,7 @@ void AISAPI::RemoveItem(const LLUUID &itemId, completion_t callback) // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, delFn, url, itemId, LLSD(), callback, REMOVEITEM)); @@ -258,7 +258,7 @@ void AISAPI::CopyLibraryCategory(const LLUUID& sourceId, const LLUUID& destId, b // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::copyAndYield), _1, _2, _3, destination, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::copyAndSuspend), _1, _2, _3, destination, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, copyFn, url, destId, LLSD(), callback, COPYLIBRARYCATEGORY)); @@ -291,7 +291,7 @@ void AISAPI::PurgeDescendents(const LLUUID &categoryId, completion_t callback) // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndYield), _1, _2, _3, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, delFn, url, categoryId, LLSD(), callback, PURGEDESCENDENTS)); @@ -323,7 +323,7 @@ void AISAPI::UpdateCategory(const LLUUID &categoryId, const LLSD &updates, compl // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndYield), _1, _2, _3, _4, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndSuspend), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, patchFn, url, categoryId, updates, callback, UPDATECATEGORY)); @@ -355,7 +355,7 @@ void AISAPI::UpdateItem(const LLUUID &itemId, const LLSD &updates, completion_t // _4 -> body // _5 -> httpOptions // _6 -> httpHeaders - (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndYield), _1, _2, _3, _4, _5, _6); + (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndSuspend), _1, _2, _3, _4, _5, _6); LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro, _1, patchFn, url, itemId, updates, callback, UPDATEITEM)); -- cgit v1.2.3 From cf835a80cd2bb5d02cc03034009919e0d9eb73b6 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 18 Sep 2015 16:36:49 -0700 Subject: Pref instance() over getInstance() --- indra/newview/llaisapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/llaisapi.cpp') diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 5b7380a175..afc6e208e6 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -367,7 +367,7 @@ void AISAPI::UpdateItem(const LLUUID &itemId, const LLSD &updates, completion_t void AISAPI::EnqueueAISCommand(const std::string &procName, LLCoprocedureManager::CoProcedure_t proc) { std::string procFullName = "AIS(" + procName + ")"; - LLCoprocedureManager::getInstance()->enqueueCoprocedure("AIS", procFullName, proc); + LLCoprocedureManager::instance().enqueueCoprocedure("AIS", procFullName, proc); } -- cgit v1.2.3