diff options
author | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-06-10 16:29:10 -0400 |
---|---|---|
committer | Brad Payne (Vir Linden) <vir@lindenlab.com> | 2013-06-10 16:29:10 -0400 |
commit | 6d46132ef5218cd17d8d201f16e5a7df4b1e39a6 (patch) | |
tree | 1a9ea4578e12a4eac75ee43b5aa5833dd990137c | |
parent | 89e3959cf393ce9eeb058304264d4f55f4fe9ca2 (diff) |
SH-4216 WIP - finished item/cat update and reorg of aisv3 code
-rwxr-xr-x | indra/llinventory/llinventory.cpp | 11 | ||||
-rwxr-xr-x | indra/llinventory/llinventory.h | 2 | ||||
-rwxr-xr-x | indra/newview/llaisapi.cpp | 1 | ||||
-rwxr-xr-x | indra/newview/llviewerinventory.cpp | 351 | ||||
-rwxr-xr-x | indra/newview/llviewerinventory.h | 9 |
5 files changed, 38 insertions, 336 deletions
diff --git a/indra/llinventory/llinventory.cpp b/indra/llinventory/llinventory.cpp index 77b837f8ac..6336d02f22 100755 --- a/indra/llinventory/llinventory.cpp +++ b/indra/llinventory/llinventory.cpp @@ -1049,11 +1049,16 @@ void LLInventoryItem::asLLSD( LLSD& sd ) const LLFastTimer::DeclareTimer FTM_INVENTORY_SD_DESERIALIZE("Inventory SD Deserialize"); -bool LLInventoryItem::fromLLSD(const LLSD& sd) +bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) { LLFastTimer _(FTM_INVENTORY_SD_DESERIALIZE); - mInventoryType = LLInventoryType::IT_NONE; - mAssetUUID.setNull(); + if (is_new) + { + // If we're adding LLSD to an existing object, need avoid + // clobbering these fields. + mInventoryType = LLInventoryType::IT_NONE; + mAssetUUID.setNull(); + } std::string w; w = INV_ITEM_ID_LABEL; diff --git a/indra/llinventory/llinventory.h b/indra/llinventory/llinventory.h index cc474f3d4c..b718f0f9b7 100755 --- a/indra/llinventory/llinventory.h +++ b/indra/llinventory/llinventory.h @@ -210,7 +210,7 @@ public: void unpackBinaryBucket(U8* bin_bucket, S32 bin_bucket_size); LLSD asLLSD() const; void asLLSD( LLSD& sd ) const; - bool fromLLSD(const LLSD& sd); + bool fromLLSD(const LLSD& sd, bool is_new = true); //-------------------------------------------------------------------- // Member Variables diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp index 6adf35efb8..393e5c0a68 100755 --- a/indra/newview/llaisapi.cpp +++ b/indra/newview/llaisapi.cpp @@ -202,6 +202,7 @@ UpdateItemCommand::UpdateItemCommand(const LLUUID& item_id, } std::string url = cap + std::string("/item/") + item_id.asString(); LL_DEBUGS("Inventory") << "url: " << url << llendl; + LL_DEBUGS("Inventory") << "request: " << ll_pretty_print_sd(mUpdates) << llendl; LLCurl::ResponderPtr responder = this; LLSD headers; headers["Content-Type"] = "application/llsd+xml"; diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp index 57d7d4fef6..55575764b9 100755 --- a/indra/newview/llviewerinventory.cpp +++ b/indra/newview/llviewerinventory.cpp @@ -259,271 +259,6 @@ public: }; LLInventoryHandler gInventoryHandler; -#if 0 // DELETE these when working in their new home - -///---------------------------------------------------------------------------- -/// Classes for AISv3 support. -///---------------------------------------------------------------------------- -class AISCommand: public LLHTTPClient::Responder -{ -public: - typedef boost::function<void()> command_func_type; - - AISCommand(LLPointer<LLInventoryCallback> callback): - mCallback(callback) - { - mRetryPolicy = new LLAdaptiveRetryPolicy(1.0, 32.0, 2.0, 10); - } - - virtual ~AISCommand() - { - } - - void run_command() - { - mCommandFunc(); - } - - void setCommandFunc(command_func_type command_func) - { - mCommandFunc = command_func; - } - - // Need to do command-specific parsing to get an id here. May or - // may not need to bother, since most LLInventoryCallbacks do - // their work in the destructor. - virtual bool getResponseUUID(const LLSD& content, LLUUID& id) - { - return false; - } - - /* virtual */ void 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 item_id; // will default to null if parse fails. - getResponseUUID(content,item_id); - mCallback->fire(item_id); - } - } - - /*virtual*/ void httpFailure() - { - const LLSD& content = getContent(); - S32 status = getStatus(); - const std::string& reason = getReason(); - const LLSD& headers = getResponseHeaders(); - if (!content.isMap()) - { - LL_DEBUGS("Inventory") << "Malformed response contents " << content - << " status " << status << " reason " << reason << llendl; - } - else - { - LL_DEBUGS("Inventory") << "failed with content: " << ll_pretty_print_sd(content) - << " status " << status << " reason " << reason << llendl; - } - 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. - setCommandFunc(no_op); - } - } - - static bool getCap(std::string& cap) - { - if (gAgent.getRegion()) - { - cap = gAgent.getRegion()->getCapability("InventoryAPIv3"); - } - if (!cap.empty()) - { - return true; - } - return false; - } - -private: - command_func_type mCommandFunc; - LLPointer<LLHTTPRetryPolicy> mRetryPolicy; - LLPointer<LLInventoryCallback> mCallback; -}; - -class RemoveItemCommand: public AISCommand -{ -public: - RemoveItemCommand(const LLUUID& item_id, - LLPointer<LLInventoryCallback> callback): - AISCommand(callback) - { - std::string cap; - if (!getCap(cap)) - { - llwarns << "No cap found" << llendl; - return; - } - std::string url = cap + std::string("/item/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; - 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); - } -}; - -class RemoveCategoryCommand: public AISCommand -{ -public: - RemoveCategoryCommand(const LLUUID& item_id, - LLPointer<LLInventoryCallback> callback): - AISCommand(callback) - { - std::string cap; - if (!getCap(cap)) - { - llwarns << "No cap found" << llendl; - return; - } - std::string url = cap + std::string("/category/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; - 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); - } -}; - -class PurgeDescendentsCommand: public AISCommand -{ -public: - PurgeDescendentsCommand(const LLUUID& item_id, - LLPointer<LLInventoryCallback> callback): - AISCommand(callback) - { - std::string cap; - if (!getCap(cap)) - { - llwarns << "No cap found" << llendl; - return; - } - std::string url = cap + std::string("/category/") + item_id.asString() + "/children"; - LL_DEBUGS("Inventory") << "url: " << url << llendl; - 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); - } -}; - -class UpdateItemCommand: public AISCommand -{ -public: - UpdateItemCommand(const LLUUID& item_id, - const LLSD& updates, - LLPointer<LLInventoryCallback> callback): - mUpdates(updates), - AISCommand(callback) - { - std::string cap; - if (!getCap(cap)) - { - llwarns << "No cap found" << llendl; - return; - } - std::string url = cap + std::string("/item/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; - 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); - } -private: - LLSD mUpdates; -}; - -class UpdateCategoryCommand: public AISCommand -{ -public: - UpdateCategoryCommand(const LLUUID& item_id, - const LLSD& updates, - LLPointer<LLInventoryCallback> callback): - mUpdates(updates), - AISCommand(callback) - { - std::string cap; - if (!getCap(cap)) - { - llwarns << "No cap found" << llendl; - return; - } - std::string url = cap + std::string("/category/") + item_id.asString(); - LL_DEBUGS("Inventory") << "url: " << url << llendl; - 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); - } -private: - LLSD mUpdates; -}; - -class SlamFolderCommand: public AISCommand -{ -public: - SlamFolderCommand(const LLUUID& folder_id, const LLSD& contents, LLPointer<LLInventoryCallback> callback): - mContents(contents), - AISCommand(callback) - { - std::string cap; - if (!getCap(cap)) - { - llwarns << "No cap found" << llendl; - return; - } - LLUUID tid; - tid.generate(); - std::string url = cap + std::string("/category/") + folder_id.asString() + "/links?tid=" + tid.asString(); - llinfos << url << llendl; - 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); - } -private: - LLSD mContents; -}; -#endif - ///---------------------------------------------------------------------------- /// Class LLViewerInventoryItem ///---------------------------------------------------------------------------- @@ -718,23 +453,9 @@ void LLViewerInventoryItem::setTransactionID(const LLTransactionID& transaction_ { mTransactionID = transaction_id; } -// virtual -void LLViewerInventoryItem::packMessage(LLMessageSystem* msg) const -{ - static const LLSD updates; - packUpdateMessage(msg,updates); -} -void LLViewerInventoryItem::packUpdateMessage(LLMessageSystem* msg, const LLSD& updates) const +void LLViewerInventoryItem::packMessage(LLMessageSystem* msg) const { - for (LLSD::map_const_iterator it = updates.beginMap(); it != updates.endMap(); ++it) - { - if ((it->first != "desc") && (it->first != "name")) - { - llerrs << "unhandled field: " << it->first << llendl; - } - } - msg->addUUIDFast(_PREHASH_ItemID, mUUID); msg->addUUIDFast(_PREHASH_FolderID, mParentUUID); mPermissions.packMessage(msg); @@ -745,26 +466,8 @@ void LLViewerInventoryItem::packUpdateMessage(LLMessageSystem* msg, const LLSD& msg->addS8Fast(_PREHASH_InvType, type); msg->addU32Fast(_PREHASH_Flags, mFlags); mSaleInfo.packMessage(msg); - if (updates.has("name")) - { - std::string new_name = updates["name"].asString(); - LLInventoryObject::correctInventoryName(new_name); - msg->addStringFast(_PREHASH_Name, new_name); - } - else - { - msg->addStringFast(_PREHASH_Name, mName); - } - if (updates.has("desc")) - { - std::string new_desc = updates["desc"].asString(); - LLInventoryItem::correctInventoryDescription(new_desc); - msg->addStringFast(_PREHASH_Description, new_desc); - } - else - { - msg->addStringFast(_PREHASH_Description, mDescription); - } + msg->addStringFast(_PREHASH_Name, mName); + msg->addStringFast(_PREHASH_Description, mDescription); msg->addS32Fast(_PREHASH_CreationDate, mCreationDate); U32 crc = getCRC32(); msg->addU32Fast(_PREHASH_CRC, crc); @@ -881,30 +584,13 @@ void LLViewerInventoryCategory::copyViewerCategory(const LLViewerInventoryCatego } -void LLViewerInventoryCategory::packUpdateMessage(LLMessageSystem* msg, const LLSD& updates) const +void LLViewerInventoryCategory::packMessage(LLMessageSystem* msg) const { - for (LLSD::map_const_iterator it = updates.beginMap(); it != updates.endMap(); ++it) - { - if (it->first != "name") - { - llerrs << "unhandled field: " << it->first << llendl; - } - } - msg->addUUIDFast(_PREHASH_FolderID, mUUID); msg->addUUIDFast(_PREHASH_ParentID, mParentUUID); S8 type = static_cast<S8>(mPreferredType); msg->addS8Fast(_PREHASH_Type, type); - if (updates.has("name")) - { - std::string new_name = updates["name"].asString(); - LLInventoryObject::correctInventoryName(new_name); - msg->addStringFast(_PREHASH_Name, new_name); - } - else - { - msg->addStringFast(_PREHASH_Name, mName); - } + msg->addStringFast(_PREHASH_Name, mName); } void LLViewerInventoryCategory::updateParentOnServer(BOOL restamp) const @@ -1475,10 +1161,16 @@ void update_inventory_item( LL_DEBUGS("Inventory") << "item_id: [" << item_id << "] name " << (obj ? obj->getName() : "(NOT FOUND)") << llendl; if(obj) { + LLPointer<LLViewerInventoryItem> new_item(new LLViewerInventoryItem); + new_item->copyViewerItem(obj); + new_item->fromLLSD(updates,false); + std::string cap; if (AISCommand::getCap(cap)) { - LLPointer<AISCommand> cmd_ptr = new UpdateItemCommand(item_id, updates, cb); + LLSD new_llsd; + new_item->asLLSD(new_llsd); + LLPointer<AISCommand> cmd_ptr = new UpdateItemCommand(item_id, new_llsd, cb); cmd_ptr->run_command(); } else // no cap @@ -1488,13 +1180,15 @@ void update_inventory_item( msg->nextBlockFast(_PREHASH_AgentData); msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); - msg->addUUIDFast(_PREHASH_TransactionID, obj->getTransactionID()); + msg->addUUIDFast(_PREHASH_TransactionID, new_item->getTransactionID()); msg->nextBlockFast(_PREHASH_InventoryData); msg->addU32Fast(_PREHASH_CallbackID, 0); - obj->packUpdateMessage(msg, updates); + new_item->packMessage(msg); gAgent.sendReliableMessage(); - gInventory.onItemUpdated(item_id, updates,true); + LLInventoryModel::LLCategoryUpdate up(new_item->getParentUUID(), 0); + gInventory.accountForUpdate(up); + gInventory.updateItem(new_item); if (cb) { cb->fire(item_id); @@ -1518,11 +1212,14 @@ void update_inventory_category( return; } + LLPointer<LLViewerInventoryCategory> new_cat = new LLViewerInventoryCategory(obj); + new_cat->fromLLSD(updates); //std::string cap; // FIXME - restore this once the back-end work has been done. if (0) // if (AISCommand::getCap(cap)) { - LLPointer<AISCommand> cmd_ptr = new UpdateCategoryCommand(cat_id, updates, cb); + LLSD new_llsd = new_cat->asLLSD(); + LLPointer<AISCommand> cmd_ptr = new UpdateCategoryCommand(cat_id, new_llsd, cb); cmd_ptr->run_command(); } else // no cap @@ -1533,10 +1230,12 @@ void update_inventory_category( msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); msg->nextBlockFast(_PREHASH_FolderData); - obj->packUpdateMessage(msg, updates); + new_cat->packMessage(msg); gAgent.sendReliableMessage(); - gInventory.onCategoryUpdated(cat_id, updates); + LLInventoryModel::LLCategoryUpdate up(new_cat->getParentUUID(), 0); + gInventory.accountForUpdate(up); + gInventory.updateCategory(new_cat); if (cb) { cb->fire(cat_id); diff --git a/indra/newview/llviewerinventory.h b/indra/newview/llviewerinventory.h index 9af71dfc9c..032efd9542 100755 --- a/indra/newview/llviewerinventory.h +++ b/indra/newview/llviewerinventory.h @@ -122,7 +122,7 @@ public: virtual void updateServer(BOOL is_new) const; void fetchFromServer(void) const; - //virtual void packMessage(LLMessageSystem* msg) const; + virtual void packMessage(LLMessageSystem* msg) const; virtual BOOL unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0); virtual BOOL unpackMessage(LLSD item); virtual BOOL importFile(LLFILE* fp); @@ -138,9 +138,6 @@ public: void setComplete(BOOL complete) { mIsComplete = complete; } //void updateAssetOnServer() const; - virtual void packMessage(LLMessageSystem* msg) const; - // Contents of updates will take precedence over fields of item where they differ. - void packUpdateMessage(LLMessageSystem* msg, const LLSD& updates) const; virtual void setTransactionID(const LLTransactionID& transaction_id); struct comparePointers { @@ -202,6 +199,8 @@ public: virtual void updateParentOnServer(BOOL restamp_children) const; virtual void updateServer(BOOL is_new) const; + virtual void packMessage(LLMessageSystem* msg) const; + const LLUUID& getOwnerID() const { return mOwnerID; } // Version handling @@ -226,8 +225,6 @@ public: void determineFolderType(); void changeType(LLFolderType::EType new_folder_type); - void packUpdateMessage(LLMessageSystem* msg, const LLSD& updates) const; - private: friend class LLInventoryModel; void localizeName(); // intended to be called from the LLInventoryModel |