LocalInventoryService.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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.OwnerID = 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. public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
  79. {
  80. InventoryCollection[] invColl = new InventoryCollection[folderIDs.Length];
  81. int i = 0;
  82. foreach (UUID fid in folderIDs)
  83. {
  84. invColl[i++] = GetFolderContent(principalID, fid);
  85. }
  86. return invColl;
  87. }
  88. public virtual InventoryItemBase[] GetMultipleItems(UUID principalID, UUID[] itemIDs)
  89. {
  90. InventoryItemBase[] itemColl = new InventoryItemBase[itemIDs.Length];
  91. int i = 0;
  92. foreach (UUID fid in itemIDs)
  93. itemColl[i++] = GetItem(principalID, fid);
  94. return itemColl;
  95. }
  96. /// <summary>
  97. /// Add a new folder to the user's inventory
  98. /// </summary>
  99. /// <param name="folder"></param>
  100. /// <returns>true if the folder was successfully added</returns>
  101. public bool AddFolder(InventoryFolderBase folder)
  102. {
  103. //m_log.DebugFormat("[LIBRARY MODULE]: Adding folder {0} ({1}) to {2}", folder.Name, folder.ID, folder.ParentID);
  104. InventoryFolderImpl parent = m_Library;
  105. if (m_Library.ID != folder.ParentID)
  106. parent = m_Library.FindFolder(folder.ParentID);
  107. if (parent == null)
  108. {
  109. m_log.DebugFormat("[LIBRARY MODULE]: could not add folder {0} because parent folder {1} not found", folder.Name, folder.ParentID);
  110. return false;
  111. }
  112. parent.CreateChildFolder(folder.ID, folder.Name, (ushort)folder.Type);
  113. return true;
  114. }
  115. /// <summary>
  116. /// Add a new item to the user's inventory
  117. /// </summary>
  118. /// <param name="item"></param>
  119. /// <returns>true if the item was successfully added</returns>
  120. public bool AddItem(InventoryItemBase item)
  121. {
  122. //m_log.DebugFormat("[LIBRARY MODULE]: Adding item {0} to {1}", item.Name, item.Folder);
  123. InventoryFolderImpl folder = m_Library;
  124. if (m_Library.ID != item.Folder)
  125. folder = m_Library.FindFolder(item.Folder);
  126. if (folder == null)
  127. {
  128. m_log.DebugFormat("[LIBRARY MODULE]: could not add item {0} because folder {1} not found", item.Name, item.Folder);
  129. return false;
  130. }
  131. folder.Items.Add(item.ID, item);
  132. return true;
  133. }
  134. public bool CreateUserInventory(UUID user) { return false; }
  135. /// <summary>
  136. /// Gets the skeleton of the inventory -- folders only
  137. /// </summary>
  138. /// <param name="userId"></param>
  139. /// <returns></returns>
  140. public List<InventoryFolderBase> GetInventorySkeleton(UUID userId) { return null; }
  141. /// <summary>
  142. /// Gets the user folder for the given folder-type
  143. /// </summary>
  144. /// <param name="userID"></param>
  145. /// <param name="type"></param>
  146. /// <returns></returns>
  147. public InventoryFolderBase GetFolderForType(UUID userID, FolderType type) { return null; }
  148. /// <summary>
  149. /// Gets the items inside a folder
  150. /// </summary>
  151. /// <param name="userID"></param>
  152. /// <param name="folderID"></param>
  153. /// <returns></returns>
  154. public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID) { return null; }
  155. /// <summary>
  156. /// Update a folder in the user's inventory
  157. /// </summary>
  158. /// <param name="folder"></param>
  159. /// <returns>true if the folder was successfully updated</returns>
  160. public bool UpdateFolder(InventoryFolderBase folder) { return false; }
  161. /// <summary>
  162. /// Move an inventory folder to a new location
  163. /// </summary>
  164. /// <param name="folder">A folder containing the details of the new location</param>
  165. /// <returns>true if the folder was successfully moved</returns>
  166. public bool MoveFolder(InventoryFolderBase folder) { return false; }
  167. /// <summary>
  168. /// Delete an item from the user's inventory
  169. /// </summary>
  170. /// <param name="item"></param>
  171. /// <returns>true if the item was successfully deleted</returns>
  172. //bool DeleteItem(InventoryItemBase item);
  173. public bool DeleteFolders(UUID userID, List<UUID> folderIDs) { return false; }
  174. /// <summary>
  175. /// Purge an inventory folder of all its items and subfolders.
  176. /// </summary>
  177. /// <param name="folder"></param>
  178. /// <returns>true if the folder was successfully purged</returns>
  179. public bool PurgeFolder(InventoryFolderBase folder) { return false; }
  180. /// <summary>
  181. /// Update an item in the user's inventory
  182. /// </summary>
  183. /// <param name="item"></param>
  184. /// <returns>true if the item was successfully updated</returns>
  185. public bool UpdateItem(InventoryItemBase item) { return false; }
  186. public bool MoveItems(UUID ownerID, List<InventoryItemBase> items) { return false; }
  187. /// <summary>
  188. /// Delete an item from the user's inventory
  189. /// </summary>
  190. /// <param name="item"></param>
  191. /// <returns>true if the item was successfully deleted</returns>
  192. //bool DeleteItem(InventoryItemBase item);
  193. public bool DeleteItems(UUID userID, List<UUID> itemIDs) { return false; }
  194. /// <summary>
  195. /// Get an item, given by its UUID
  196. /// </summary>
  197. /// <param name="item"></param>
  198. /// <returns></returns>
  199. public InventoryItemBase GetItem(UUID principalID, UUID itemID) { return null; }
  200. /// <summary>
  201. /// Get a folder, given by its UUID
  202. /// </summary>
  203. /// <param name="folder"></param>
  204. /// <returns></returns>
  205. public InventoryFolderBase GetFolder(UUID principalID, UUID folderID) { return null; }
  206. /// <summary>
  207. /// Does the given user have an inventory structure?
  208. /// </summary>
  209. /// <param name="userID"></param>
  210. /// <returns></returns>
  211. public bool HasInventoryForUser(UUID userID) { return false; }
  212. /// <summary>
  213. /// Get the active gestures of the agent.
  214. /// </summary>
  215. /// <param name="userId"></param>
  216. /// <returns></returns>
  217. public List<InventoryItemBase> GetActiveGestures(UUID userId) { return null; }
  218. /// <summary>
  219. /// Get the union of permissions of all inventory items
  220. /// that hold the given assetID.
  221. /// </summary>
  222. /// <param name="userID"></param>
  223. /// <param name="assetID"></param>
  224. /// <returns>The permissions or 0 if no such asset is found in
  225. /// the user's inventory</returns>
  226. public int GetAssetPermissions(UUID userID, UUID assetID) { return 0; }
  227. }
  228. }