From d519f1885f587409592cf92bc0f4ba8533a1866f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Wed, 19 Aug 2009 10:56:08 -0700 Subject: Added MoveItems, which is most useful upon viewer-delete inventory operation. Moving a batch of items is a 1-time operation. Made it async anyway, so that the viewer doesn't wait in case the DB layer is dumb (which is the case currently). --- .../Communications/Tests/LoginServiceTests.cs | 5 +++ OpenSim/Framework/IClientAPI.cs | 2 +- .../Region/ClientStack/LindenUDP/LLClientView.cs | 19 ++++++---- .../Inventory/BaseInventoryConnector.cs | 2 ++ .../Inventory/HGInventoryBroker.cs | 17 +++++++++ .../Inventory/LocalInventoryServiceConnector.cs | 6 ++++ .../Inventory/RemoteInventoryServiceConnector.cs | 10 ++++++ OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 31 +++------------- .../Inventory/InventoryServerInConnector.cs | 21 ++++++++--- .../Inventory/HGInventoryServiceConnector.cs | 13 +++++++ .../Inventory/ISessionAuthInventoryService.cs | 2 ++ .../Inventory/InventoryServiceConnector.cs | 42 ++++++++++++++++++++++ .../QuickAndDirtyInventoryServiceConnector.cs | 5 +++ OpenSim/Services/Interfaces/IInventoryService.cs | 2 ++ .../Services/InventoryService/InventoryService.cs | 18 ++++++++++ OpenSim/Tests/Common/Mock/TestInventoryService.cs | 5 +++ 16 files changed, 162 insertions(+), 38 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs index d5d4d1e..6f86704 100644 --- a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs @@ -547,6 +547,11 @@ namespace OpenSim.Framework.Communications.Tests return false; } + public bool MoveItems(UUID owner, List items) + { + return false; + } + public bool DeleteItems(UUID owner, List items) { return false; diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index ca37a5b..c6cdcaa 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -254,7 +254,7 @@ namespace OpenSim.Framework string newName); public delegate void MoveInventoryItem( - IClientAPI remoteClient, UUID folderID, UUID itemID, int length, string newName); + IClientAPI remoteClient, List items); public delegate void RemoveInventoryItem( IClientAPI remoteClient, List itemIDs); diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index e2fb659..6969a3d 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -7027,14 +7027,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (OnMoveInventoryItem != null) { handlerMoveInventoryItem = null; + InventoryItemBase itm = null; + List items = new List(); foreach (MoveInventoryItemPacket.InventoryDataBlock datablock in moveitem.InventoryData) { - handlerMoveInventoryItem = OnMoveInventoryItem; - if (handlerMoveInventoryItem != null) - { - handlerMoveInventoryItem(this, datablock.FolderID, datablock.ItemID, datablock.Length, - Util.FieldToString(datablock.NewName)); - } + itm = new InventoryItemBase(datablock.ItemID, AgentId); + itm.Folder = datablock.FolderID; + itm.Name = Util.FieldToString(datablock.NewName); + // weird, comes out as empty string + //m_log.DebugFormat("[XXX] new name: {0}", itm.Name); + items.Add(itm); + } + handlerMoveInventoryItem = OnMoveInventoryItem; + if (handlerMoveInventoryItem != null) + { + handlerMoveInventoryItem(this, items); } } break; diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs index d1ae3e4..d4cb616 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs @@ -181,6 +181,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory /// true if the item was successfully updated public abstract bool UpdateItem(InventoryItemBase item); + public abstract bool MoveItems(UUID ownerID, List items); + /// /// Delete an item from the user's inventory /// diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs index 6a1f2d5..787c6c8 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs @@ -393,6 +393,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory } } + public override bool MoveItems(UUID ownerID, List items) + { + if (items == null) + return false; + if (items.Count == 0) + return true; + + if (IsLocalGridUser(ownerID)) + return m_GridService.MoveItems(ownerID, items); + else + { + UUID sessionID = GetSessionID(ownerID); + string uri = GetUserInventoryURI(ownerID) + "/" + ownerID.ToString(); + return m_HGService.MoveItems(uri, items, sessionID); + } + } + public override bool DeleteItems(UUID ownerID, List itemIDs) { m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Delete {0} items for user {1}", itemIDs.Count, ownerID); diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs index b2640af..562c5dd 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs @@ -289,6 +289,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory return m_InventoryService.UpdateItem(item); } + + public override bool MoveItems(UUID ownerID, List items) + { + return m_InventoryService.MoveItems(ownerID, items); + } + /// /// Delete an item from the user's inventory /// diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs index 081d0f7..201442c 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs @@ -273,6 +273,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory return m_RemoteConnector.UpdateItem(item.Owner.ToString(), item, sessionID); } + public override bool MoveItems(UUID ownerID, List items) + { + if (items == null) + return false; + + UUID sessionID = GetSessionID(ownerID); + return m_RemoteConnector.MoveItems(ownerID.ToString(), items, sessionID); + } + + public override bool DeleteItems(UUID ownerID, List itemIDs) { if (itemIDs == null) diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 5e2eb73..a119efc 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -638,36 +638,13 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - public void MoveInventoryItem(IClientAPI remoteClient, UUID folderID, UUID itemID, int length, - string newName) + public void MoveInventoryItem(IClientAPI remoteClient, List items) { m_log.DebugFormat( - "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId); + "[AGENT INVENTORY]: Moving {0} items for user {1}", items.Count, remoteClient.AgentId); - InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId); - item = InventoryService.GetItem(item); - - if (item != null) - { - if (newName != String.Empty) - { - item.Name = newName; - } - item.Folder = folderID; - - // Diva comment: can't we just update? - List uuids = new List(); - uuids.Add(item.ID); - InventoryService.DeleteItems(item.Owner, uuids); - - AddInventoryItem(remoteClient, item); - } - else - { - m_log.Warn("[AGENT INVENTORY]: Failed to find item " + itemID.ToString()); - - return; - } + if (!InventoryService.MoveItems(remoteClient.AgentId, items)) + m_log.Warn("[AGENT INVENTORY]: Failed to move items for user " + remoteClient.AgentId); } /// diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs index 6cfc7df..6ef1d9d 100644 --- a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs @@ -125,8 +125,8 @@ namespace OpenSim.Server.Handlers.Inventory "POST", "/NewFolder/", m_InventoryService.AddFolder, CheckAuthSession)); m_httpServer.AddStreamHandler( - new RestDeserialiseTrustedHandler( - "POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckTrustSource)); + new RestDeserialiseSecureHandler( + "POST", "/CreateFolder/", m_InventoryService.AddFolder, CheckAuthSession)); m_httpServer.AddStreamHandler( new RestDeserialiseSecureHandler( @@ -137,9 +137,13 @@ namespace OpenSim.Server.Handlers.Inventory "POST", "/AddNewItem/", m_InventoryService.AddItem, CheckTrustSource)); m_httpServer.AddStreamHandler( - new RestDeserialiseTrustedHandler>( - "POST", "/GetItems/", GetFolderItems, CheckTrustSource)); + new RestDeserialiseSecureHandler>( + "POST", "/GetItems/", GetFolderItems, CheckAuthSession)); + m_httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler, bool>( + "POST", "/MoveItems/", MoveItems, CheckAuthSession)); + // for persistent active gestures m_httpServer.AddStreamHandler( new RestDeserialiseTrustedHandler> @@ -256,6 +260,15 @@ namespace OpenSim.Server.Handlers.Inventory return m_InventoryService.DeleteItems(UUID.Zero, uuids); } + public bool MoveItems(List items) + { + // oops we lost the user info here. Bad bad handlers + // let's peek at one item + UUID ownerID = UUID.Zero; + if (items.Count > 0) + ownerID = items[0].Owner; + return m_InventoryService.MoveItems(ownerID, items); + } #endregion /// diff --git a/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs index 00b74b5..45e921a 100644 --- a/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs @@ -253,6 +253,19 @@ namespace OpenSim.Services.Connectors.Inventory return false; } + public bool MoveItems(string id, List items, UUID sessionID) + { + string url = string.Empty; + string userID = string.Empty; + + if (StringToUrlAndUserID(id, out url, out userID)) + { + ISessionAuthInventoryService connector = GetConnector(url); + return connector.MoveItems(userID, items, sessionID); + } + return false; + } + public bool DeleteItems(string id, List itemIDs, UUID sessionID) { string url = string.Empty; diff --git a/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs b/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs index e4e713c..c89c9b7 100644 --- a/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs +++ b/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs @@ -116,6 +116,8 @@ namespace OpenSim.Services.Connectors /// true if the item was successfully updated bool UpdateItem(string userID, InventoryItemBase item, UUID session_id); + bool MoveItems(string userID, List items, UUID session_id); + /// /// Delete an item from the user's inventory /// diff --git a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs index 9b2e331..bcf9d87 100644 --- a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs @@ -383,6 +383,48 @@ namespace OpenSim.Services.Connectors return false; } + /** + * MoveItems Async group + */ + + delegate void MoveItemsDelegate(string userID, List items, UUID sessionID); + + private void MoveItemsAsync(string userID, List items, UUID sessionID) + { + try + { + SynchronousRestSessionObjectPoster, bool>.BeginPostObject( + "POST", m_ServerURI + "/MoveItems/", items, sessionID.ToString(), userID.ToString()); + + // Success + return; + } + catch (Exception e) + { + m_log.ErrorFormat("[INVENTORY CONNECTOR]: Move inventory items operation failed, {0} {1} (old server?). Trying slow way.", + e.Source, e.Message); + } + + foreach (InventoryItemBase item in items) + { + InventoryItemBase itm = this.QueryItem(userID, item, sessionID); + itm.Name = item.Name; + itm.Folder = item.Folder; + this.UpdateItem(userID, itm, sessionID); + } + } + + private void MoveItemsCompleted(IAsyncResult iar) + { + } + + public bool MoveItems(string userID, List items, UUID sessionID) + { + MoveItemsDelegate d = MoveItemsAsync; + d.BeginInvoke(userID, items, sessionID, MoveItemsCompleted, d); + return true; + } + public bool DeleteItems(string userID, List items, UUID sessionID) { try diff --git a/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs index 3bbf129..cd283ff 100644 --- a/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs @@ -151,6 +151,11 @@ namespace OpenSim.Services.Connectors return false; } + public bool MoveItems(UUID ownerID, List items) + { + return false; + } + public bool DeleteItems(UUID owner, List itemIDs) { return false; diff --git a/OpenSim/Services/Interfaces/IInventoryService.cs b/OpenSim/Services/Interfaces/IInventoryService.cs index 6409b57..ebdb09a 100644 --- a/OpenSim/Services/Interfaces/IInventoryService.cs +++ b/OpenSim/Services/Interfaces/IInventoryService.cs @@ -142,6 +142,8 @@ namespace OpenSim.Services.Interfaces /// true if the item was successfully updated bool UpdateItem(InventoryItemBase item); + bool MoveItems(UUID ownerID, List items); + /// /// Delete an item from the user's inventory /// diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs index 69b1b28..e0217f6 100644 --- a/OpenSim/Services/InventoryService/InventoryService.cs +++ b/OpenSim/Services/InventoryService/InventoryService.cs @@ -386,6 +386,24 @@ namespace OpenSim.Services.InventoryService return true; } + public virtual bool MoveItems(UUID ownerID, List items) + { + m_log.InfoFormat( + "[INVENTORY SERVICE]: Moving {0} items from user {1}", items.Count, ownerID); + + InventoryItemBase itm = null; + foreach (InventoryItemBase item in items) + { + itm = GetInventoryItem(item.ID); + itm.Folder = item.Folder; + if ((item.Name != null) && !item.Name.Equals(string.Empty)) + itm.Name = item.Name; + m_Database.updateInventoryItem(itm); + } + + return true; + } + // See IInventoryServices public virtual bool DeleteItems(UUID owner, List itemIDs) { diff --git a/OpenSim/Tests/Common/Mock/TestInventoryService.cs b/OpenSim/Tests/Common/Mock/TestInventoryService.cs index f770f75..ee22e5e 100644 --- a/OpenSim/Tests/Common/Mock/TestInventoryService.cs +++ b/OpenSim/Tests/Common/Mock/TestInventoryService.cs @@ -143,6 +143,11 @@ namespace OpenSim.Tests.Common.Mock return false; } + public bool MoveItems(UUID ownerID, List items) + { + return false; + } + public bool DeleteItems(UUID ownerID, List itemIDs) { return false; -- cgit v1.1