OGS1InventoryService.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. */
  28. using System;
  29. using System.Collections.Generic;
  30. using libsecondlife;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Framework.Console;
  35. using OpenSim.Framework.Servers;
  36. namespace OpenSim.Region.Communications.OGS1
  37. {
  38. public class OGS1InventoryService : IInventoryServices
  39. {
  40. private string _inventoryServerUrl;
  41. private Dictionary<LLUUID, InventoryRequest> m_RequestingInventory = new Dictionary<LLUUID, InventoryRequest>();
  42. public OGS1InventoryService(string inventoryServerUrl)
  43. {
  44. _inventoryServerUrl = inventoryServerUrl;
  45. }
  46. #region IInventoryServices Members
  47. // See IInventoryServices
  48. public void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack,
  49. InventoryItemInfo itemCallBack)
  50. {
  51. if (!m_RequestingInventory.ContainsKey(userID))
  52. {
  53. InventoryRequest request = new InventoryRequest(userID, folderCallBack, itemCallBack);
  54. m_RequestingInventory.Add(userID, request);
  55. RequestInventory(userID);
  56. }
  57. }
  58. /// <summary>
  59. /// Request the entire user's inventory (folders and items) from the inventory server.
  60. ///
  61. /// XXX May want to change this so that we don't end up shuffling over data which might prove
  62. /// entirely unnecessary.
  63. /// </summary>
  64. /// <param name="userID"></param>
  65. private void RequestInventory(LLUUID userID)
  66. {
  67. try
  68. {
  69. MainLog.Instance.Verbose(
  70. "INVENTORY", "Requesting inventory from {0}/GetInventory/ for user {1}",
  71. _inventoryServerUrl, userID);
  72. RestObjectPosterResponse<InventoryCollection> requester
  73. = new RestObjectPosterResponse<InventoryCollection>();
  74. requester.ResponseCallback = InventoryResponse;
  75. requester.BeginPostObject<Guid>(_inventoryServerUrl + "/GetInventory/", userID.UUID);
  76. }
  77. catch (Exception e)
  78. {
  79. MainLog.Instance.Error("INVENTORY", e.ToString());
  80. }
  81. }
  82. /// <summary>
  83. /// Callback used by the inventory server GetInventory request
  84. /// </summary>
  85. /// <param name="userID"></param>
  86. private void InventoryResponse(InventoryCollection response)
  87. {
  88. LLUUID userID = response.UserID;
  89. if (m_RequestingInventory.ContainsKey(userID))
  90. {
  91. MainLog.Instance.Verbose("INVENTORY",
  92. "Received inventory response for user {0} containing {1} folders and {2} items",
  93. userID, response.Folders.Count, response.AllItems.Count);
  94. InventoryFolderImpl rootFolder = null;
  95. InventoryRequest request = m_RequestingInventory[userID];
  96. foreach (InventoryFolderBase folder in response.Folders)
  97. {
  98. if (folder.parentID == LLUUID.Zero)
  99. {
  100. InventoryFolderImpl newfolder = new InventoryFolderImpl(folder);
  101. rootFolder = newfolder;
  102. request.FolderCallBack(userID, newfolder);
  103. }
  104. }
  105. if (rootFolder != null)
  106. {
  107. foreach (InventoryFolderBase folder in response.Folders)
  108. {
  109. if (folder.folderID != rootFolder.folderID)
  110. {
  111. InventoryFolderImpl newfolder = new InventoryFolderImpl(folder);
  112. request.FolderCallBack(userID, newfolder);
  113. }
  114. }
  115. foreach (InventoryItemBase item in response.AllItems)
  116. {
  117. request.ItemCallBack(userID, item);
  118. }
  119. }
  120. m_RequestingInventory.Remove(userID);
  121. }
  122. else
  123. {
  124. MainLog.Instance.Warn(
  125. "INVENTORY",
  126. "Received inventory response for {0} for which we do not have a record of requesting!",
  127. userID);
  128. }
  129. }
  130. public void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder)
  131. {
  132. SynchronousRestObjectPoster.BeginPostObject<InventoryFolderBase, bool>(
  133. "POST", _inventoryServerUrl + "/NewFolder/", folder);
  134. }
  135. public void MoveInventoryFolder(LLUUID userID, InventoryFolderBase folder)
  136. {
  137. SynchronousRestObjectPoster.BeginPostObject<InventoryFolderBase, bool>(
  138. "POST", _inventoryServerUrl + "/MoveFolder/", folder);
  139. }
  140. public void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
  141. {
  142. SynchronousRestObjectPoster.BeginPostObject<InventoryItemBase, bool>(
  143. "POST", _inventoryServerUrl + "/NewItem/", item);
  144. }
  145. public void DeleteInventoryItem(LLUUID userID, InventoryItemBase item)
  146. {
  147. SynchronousRestObjectPoster.BeginPostObject<InventoryItemBase, bool>(
  148. "POST", _inventoryServerUrl + "/DeleteItem/", item);
  149. }
  150. public void CreateNewUserInventory(LLUUID user)
  151. {
  152. }
  153. public List<InventoryFolderBase> RequestFirstLevelFolders(LLUUID userID)
  154. {
  155. return new List<InventoryFolderBase>();
  156. }
  157. #endregion
  158. public class InventoryRequest
  159. {
  160. public LLUUID UserID;
  161. public InventoryFolderInfo FolderCallBack;
  162. public InventoryItemInfo ItemCallBack;
  163. public InventoryRequest(LLUUID userId, InventoryFolderInfo folderCall, InventoryItemInfo itemCall)
  164. {
  165. UserID = userId;
  166. FolderCallBack = folderCall;
  167. ItemCallBack = itemCall;
  168. }
  169. }
  170. }
  171. }