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