LocalInventoryService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 OpenSimulator 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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using OpenSim.Framework;
  31. using OpenSim.Framework.Communications.Cache;
  32. using OpenSim.Services.Interfaces;
  33. using OpenMetaverse;
  34. using log4net;
  35. namespace OpenSim.Region.CoreModules.Framework.Library
  36. {
  37. public class LocalInventoryService : IInventoryService
  38. {
  39. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  40. private LibraryRootFolder m_Library;
  41. public LocalInventoryService(LibraryRootFolder lib)
  42. {
  43. m_Library = lib;
  44. }
  45. /// <summary>
  46. /// Retrieve the root inventory folder for the given user.
  47. /// </summary>
  48. /// <param name="userID"></param>
  49. /// <returns>null if no root folder was found</returns>
  50. public InventoryFolderBase GetRootFolder(UUID userID) { return m_Library; }
  51. /// <summary>
  52. /// Gets everything (folders and items) inside a folder
  53. /// </summary>
  54. /// <param name="userId"></param>
  55. /// <param name="folderID"></param>
  56. /// <returns></returns>
  57. public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
  58. {
  59. InventoryFolderImpl folder = null;
  60. InventoryCollection inv = new InventoryCollection();
  61. inv.UserID = m_Library.Owner;
  62. if (folderID != m_Library.ID)
  63. {
  64. folder = m_Library.FindFolder(folderID);
  65. if (folder == null)
  66. {
  67. inv.Folders = new List<InventoryFolderBase>();
  68. inv.Items = new List<InventoryItemBase>();
  69. return inv;
  70. }
  71. }
  72. else
  73. folder = m_Library;
  74. inv.Folders = folder.RequestListOfFolders();
  75. inv.Items = folder.RequestListOfItems();
  76. m_log.DebugFormat("[LIBRARY MODULE]: Got content for folder {0}", folder.Name);
  77. return inv;
  78. }
  79. /// <summary>
  80. /// Add a new folder to the user's inventory
  81. /// </summary>
  82. /// <param name="folder"></param>
  83. /// <returns>true if the folder was successfully added</returns>
  84. public bool AddFolder(InventoryFolderBase folder)
  85. {
  86. //m_log.DebugFormat("[LIBRARY MODULE]: Adding folder {0} ({1}) to {2}", folder.Name, folder.ID, folder.ParentID);
  87. InventoryFolderImpl parent = m_Library;
  88. if (m_Library.ID != folder.ParentID)
  89. parent = m_Library.FindFolder(folder.ParentID);
  90. if (parent == null)
  91. {
  92. m_log.DebugFormat("[LIBRARY MODULE]: could not add folder {0} because parent folder {1} not found", folder.Name, folder.ParentID);
  93. return false;
  94. }
  95. parent.CreateChildFolder(folder.ID, folder.Name, (ushort)folder.Type);
  96. return true;
  97. }
  98. /// <summary>
  99. /// Add a new item to the user's inventory
  100. /// </summary>
  101. /// <param name="item"></param>
  102. /// <returns>true if the item was successfully added</returns>
  103. public bool AddItem(InventoryItemBase item)
  104. {
  105. //m_log.DebugFormat("[LIBRARY MODULE]: Adding item {0} to {1}", item.Name, item.Folder);
  106. InventoryFolderImpl folder = m_Library;
  107. if (m_Library.ID != item.Folder)
  108. folder = m_Library.FindFolder(item.Folder);
  109. if (folder == null)
  110. {
  111. m_log.DebugFormat("[LIBRARY MODULE]: could not add item {0} because folder {1} not found", item.Name, item.Folder);
  112. return false;
  113. }
  114. folder.Items.Add(item.ID, item);
  115. return true;
  116. }
  117. public bool CreateUserInventory(UUID user) { return false; }
  118. /// <summary>
  119. /// Gets the skeleton of the inventory -- folders only
  120. /// </summary>
  121. /// <param name="userId"></param>
  122. /// <returns></returns>
  123. public List<InventoryFolderBase> GetInventorySkeleton(UUID userId) { return null; }
  124. /// <summary>
  125. /// Synchronous inventory fetch.
  126. /// </summary>
  127. /// <param name="userID"></param>
  128. /// <returns></returns>
  129. public InventoryCollection GetUserInventory(UUID userID) { return null; }
  130. /// <summary>
  131. /// Request the inventory for a user. This is an asynchronous operation that will call the callback when the
  132. /// inventory has been received
  133. /// </summary>
  134. /// <param name="userID"></param>
  135. /// <param name="callback"></param>
  136. public void GetUserInventory(UUID userID, InventoryReceiptCallback callback) { }
  137. /// <summary>
  138. /// Gets the user folder for the given folder-type
  139. /// </summary>
  140. /// <param name="userID"></param>
  141. /// <param name="type"></param>
  142. /// <returns></returns>
  143. public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) { return null; }
  144. /// <summary>
  145. /// Gets the items inside a folder
  146. /// </summary>
  147. /// <param name="userID"></param>
  148. /// <param name="folderID"></param>
  149. /// <returns></returns>
  150. public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID) { return null; }
  151. /// <summary>
  152. /// Update a folder in the user's inventory
  153. /// </summary>
  154. /// <param name="folder"></param>
  155. /// <returns>true if the folder was successfully updated</returns>
  156. public bool UpdateFolder(InventoryFolderBase folder) { return false; }
  157. /// <summary>
  158. /// Move an inventory folder to a new location
  159. /// </summary>
  160. /// <param name="folder">A folder containing the details of the new location</param>
  161. /// <returns>true if the folder was successfully moved</returns>
  162. public bool MoveFolder(InventoryFolderBase folder) { return false; }
  163. /// <summary>
  164. /// Delete an item from the user's inventory
  165. /// </summary>
  166. /// <param name="item"></param>
  167. /// <returns>true if the item was successfully deleted</returns>
  168. //bool DeleteItem(InventoryItemBase item);
  169. public bool DeleteFolders(UUID userID, List<UUID> folderIDs) { return false; }
  170. /// <summary>
  171. /// Purge an inventory folder of all its items and subfolders.
  172. /// </summary>
  173. /// <param name="folder"></param>
  174. /// <returns>true if the folder was successfully purged</returns>
  175. public bool PurgeFolder(InventoryFolderBase folder) { return false; }
  176. /// <summary>
  177. /// Update an item in the user's inventory
  178. /// </summary>
  179. /// <param name="item"></param>
  180. /// <returns>true if the item was successfully updated</returns>
  181. public bool UpdateItem(InventoryItemBase item) { return false; }
  182. public bool MoveItems(UUID ownerID, List<InventoryItemBase> items) { return false; }
  183. /// <summary>
  184. /// Delete an item from the user's inventory
  185. /// </summary>
  186. /// <param name="item"></param>
  187. /// <returns>true if the item was successfully deleted</returns>
  188. //bool DeleteItem(InventoryItemBase item);
  189. public bool DeleteItems(UUID userID, List<UUID> itemIDs) { return false; }
  190. /// <summary>
  191. /// Get an item, given by its UUID
  192. /// </summary>
  193. /// <param name="item"></param>
  194. /// <returns></returns>
  195. public InventoryItemBase GetItem(InventoryItemBase item) { return null; }
  196. /// <summary>
  197. /// Get a folder, given by its UUID
  198. /// </summary>
  199. /// <param name="folder"></param>
  200. /// <returns></returns>
  201. public InventoryFolderBase GetFolder(InventoryFolderBase folder) { return null; }
  202. /// <summary>
  203. /// Does the given user have an inventory structure?
  204. /// </summary>
  205. /// <param name="userID"></param>
  206. /// <returns></returns>
  207. public bool HasInventoryForUser(UUID userID) { return false; }
  208. /// <summary>
  209. /// Get the active gestures of the agent.
  210. /// </summary>
  211. /// <param name="userId"></param>
  212. /// <returns></returns>
  213. public List<InventoryItemBase> GetActiveGestures(UUID userId) { return null; }
  214. /// <summary>
  215. /// Get the union of permissions of all inventory items
  216. /// that hold the given assetID.
  217. /// </summary>
  218. /// <param name="userID"></param>
  219. /// <param name="assetID"></param>
  220. /// <returns>The permissions or 0 if no such asset is found in
  221. /// the user's inventory</returns>
  222. public int GetAssetPermissions(UUID userID, UUID assetID) { return 0; }
  223. }
  224. }