OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LocalInventoryServiceConnector.cs
Go to the documentation of this file.
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 
28 using log4net;
29 using Mono.Addins;
30 using Nini.Config;
31 
32 using System;
33 using System.Collections.Generic;
34 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Framework.Monitoring;
37 using OpenSim.Data;
38 using OpenSim.Server.Base;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Services.Interfaces;
42 using OpenMetaverse;
43 
44 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
45 {
46  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalInventoryServicesConnector")]
48  {
49  private static readonly ILog m_log =
50  LogManager.GetLogger(
51  MethodBase.GetCurrentMethod().DeclaringType);
52 
56  public Scene Scene { get; set; }
57 
58  private IInventoryService m_InventoryService;
59 
60  private IUserManagement m_UserManager;
61  private IUserManagement UserManager
62  {
63  get
64  {
65  if (m_UserManager == null)
66  {
67  m_UserManager = Scene.RequestModuleInterface<IUserManagement>();
68  }
69  return m_UserManager;
70  }
71  }
72 
73  private bool m_Enabled = false;
74 
75  public Type ReplaceableInterface
76  {
77  get { return null; }
78  }
79 
80  public string Name
81  {
82  get { return "LocalInventoryServicesConnector"; }
83  }
84 
85  public void Initialise(IConfigSource source)
86  {
87  IConfig moduleConfig = source.Configs["Modules"];
88  if (moduleConfig != null)
89  {
90  string name = moduleConfig.GetString("InventoryServices", "");
91  if (name == Name)
92  {
93  IConfig inventoryConfig = source.Configs["InventoryService"];
94  if (inventoryConfig == null)
95  {
96  m_log.Error("[LOCAL INVENTORY SERVICES CONNECTOR]: InventoryService missing from OpenSim.ini");
97  return;
98  }
99 
100  string serviceDll = inventoryConfig.GetString("LocalServiceModule", String.Empty);
101 
102  if (serviceDll == String.Empty)
103  {
104  m_log.Error("[LOCAL INVENTORY SERVICES CONNECTOR]: No LocalServiceModule named in section InventoryService");
105  return;
106  }
107 
108  Object[] args = new Object[] { source };
109  m_log.DebugFormat("[LOCAL INVENTORY SERVICES CONNECTOR]: Service dll = {0}", serviceDll);
110 
111  m_InventoryService = ServerUtils.LoadPlugin<IInventoryService>(serviceDll, args);
112 
113  if (m_InventoryService == null)
114  {
115  m_log.Error("[LOCAL INVENTORY SERVICES CONNECTOR]: Can't load inventory service");
116  throw new Exception("Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
117  }
118 
119  m_Enabled = true;
120  m_log.Info("[LOCAL INVENTORY SERVICES CONNECTOR]: Local inventory connector enabled");
121  }
122  }
123  }
124 
125  public void PostInitialise()
126  {
127  }
128 
129  public void Close()
130  {
131  }
132 
133  public void AddRegion(Scene scene)
134  {
135  if (!m_Enabled)
136  return;
137 
138  scene.RegisterModuleInterface<IInventoryService>(this);
139 
140  if (Scene == null)
141  Scene = scene;
142  }
143 
144  public void RemoveRegion(Scene scene)
145  {
146  if (!m_Enabled)
147  return;
148  }
149 
150  public void RegionLoaded(Scene scene)
151  {
152  if (!m_Enabled)
153  return;
154  }
155 
156  #region IInventoryService
157 
158  public bool CreateUserInventory(UUID user)
159  {
160  return m_InventoryService.CreateUserInventory(user);
161  }
162 
163  public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
164  {
165  return m_InventoryService.GetInventorySkeleton(userId);
166  }
167 
168  public InventoryFolderBase GetRootFolder(UUID userID)
169  {
170  return m_InventoryService.GetRootFolder(userID);
171  }
172 
173  public InventoryFolderBase GetFolderForType(UUID userID, FolderType type)
174  {
175  return m_InventoryService.GetFolderForType(userID, type);
176  }
177 
178  public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
179  {
180  InventoryCollection invCol = m_InventoryService.GetFolderContent(userID, folderID);
181 
182  if (UserManager != null)
183  {
184  // Protect ourselves against the caller subsequently modifying the items list
185  List<InventoryItemBase> items = new List<InventoryItemBase>(invCol.Items);
186 
187  WorkManager.RunInThread(delegate
188  {
189  foreach (InventoryItemBase item in items)
190  if (!string.IsNullOrEmpty(item.CreatorData))
191  UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
192  }, null, string.Format("GetFolderContent (user {0}, folder {1})", userID, folderID));
193  }
194 
195  return invCol;
196  }
197 
198  public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
199  {
200  InventoryCollection[] invColl = new InventoryCollection[folderIDs.Length];
201  int i = 0;
202  foreach (UUID fid in folderIDs)
203  {
204  invColl[i++] = GetFolderContent(principalID, fid);
205  }
206 
207  return invColl;
208 
209  }
210 
211  public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
212  {
213  return m_InventoryService.GetFolderItems(userID, folderID);
214  }
215 
221  public bool AddFolder(InventoryFolderBase folder)
222  {
223  return m_InventoryService.AddFolder(folder);
224  }
225 
231  public bool UpdateFolder(InventoryFolderBase folder)
232  {
233  return m_InventoryService.UpdateFolder(folder);
234  }
235 
241  public bool MoveFolder(InventoryFolderBase folder)
242  {
243  return m_InventoryService.MoveFolder(folder);
244  }
245 
246  public bool DeleteFolders(UUID ownerID, List<UUID> folderIDs)
247  {
248  return m_InventoryService.DeleteFolders(ownerID, folderIDs);
249  }
250 
256  public bool PurgeFolder(InventoryFolderBase folder)
257  {
258  return m_InventoryService.PurgeFolder(folder);
259  }
260 
261  public bool AddItem(InventoryItemBase item)
262  {
263 // m_log.DebugFormat(
264 // "[LOCAL INVENTORY SERVICES CONNECTOR]: Adding inventory item {0} to user {1} folder {2}",
265 // item.Name, item.Owner, item.Folder);
266 
267  return m_InventoryService.AddItem(item);
268  }
269 
275  public bool UpdateItem(InventoryItemBase item)
276  {
277  return m_InventoryService.UpdateItem(item);
278  }
279 
280  public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
281  {
282  return m_InventoryService.MoveItems(ownerID, items);
283  }
284 
290  public bool DeleteItems(UUID ownerID, List<UUID> itemIDs)
291  {
292  return m_InventoryService.DeleteItems(ownerID, itemIDs);
293  }
294 
296  {
297 // m_log.DebugFormat("[LOCAL INVENTORY SERVICES CONNECTOR]: Requesting inventory item {0}", item.ID);
298 
299 // UUID requestedItemId = item.ID;
300 
301  item = m_InventoryService.GetItem(item);
302 
303 // if (null == item)
304 // m_log.ErrorFormat(
305 // "[LOCAL INVENTORY SERVICES CONNECTOR]: Could not find item with id {0}", requestedItemId);
306 
307  return item;
308  }
309 
310  public InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
311  {
312  return m_InventoryService.GetMultipleItems(userID, itemIDs);
313  }
314 
316  {
317  return m_InventoryService.GetFolder(folder);
318  }
319 
325  public bool HasInventoryForUser(UUID userID)
326  {
327  return m_InventoryService.HasInventoryForUser(userID);
328  }
329 
330  public List<InventoryItemBase> GetActiveGestures(UUID userId)
331  {
332  return m_InventoryService.GetActiveGestures(userId);
333  }
334 
335  public int GetAssetPermissions(UUID userID, UUID assetID)
336  {
337  return m_InventoryService.GetAssetPermissions(userID, assetID);
338  }
339  #endregion IInventoryService
340  }
341 }
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
bool AddFolder(InventoryFolderBase folder)
Add a new folder to the user's inventory
bool HasInventoryForUser(UUID userID)
Does the given user have an inventory structure?
InventoryCollection GetFolderContent(UUID userID, UUID folderID)
Gets everything (folders and items) inside a folder
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
List< InventoryItemBase > GetFolderItems(UUID userID, UUID folderID)
Gets the items inside a folder
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
InventoryFolderBase GetRootFolder(UUID userID)
Retrieve the root inventory folder for the given user.
InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
Get multiple items, given by their UUIDs
bool MoveFolder(InventoryFolderBase folder)
Move an inventory folder to a new location
InventoryFolderBase GetFolderForType(UUID userID, FolderType type)
Gets the user folder for the given folder-type
InventoryFolderBase GetFolder(InventoryFolderBase folder)
Get a folder, given by its UUID
bool UpdateFolder(InventoryFolderBase folder)
Update a folder in the user's inventory
int GetAssetPermissions(UUID userID, UUID assetID)
Get the union of permissions of all inventory items that hold the given assetID.
InventoryItemBase GetItem(InventoryItemBase item)
Get an item, given by its UUID
List< InventoryFolderBase > GetInventorySkeleton(UUID userId)
Gets the skeleton of the inventory – folders only
Inventory Item - contains all the properties associated with an individual inventory piece...
string CreatorData
Extended creator information of the form <profile url>="">;<name>
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
bool DeleteFolders(UUID ownerID, List< UUID > folderIDs)
Delete an item from the user's inventory
bool DeleteItems(UUID ownerID, List< UUID > itemIDs)
Delete an item from the user's inventory
List< InventoryItemBase > GetActiveGestures(UUID userId)
Get the active gestures of the agent.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
bool PurgeFolder(InventoryFolderBase folder)
Purge an inventory folder of all its items and subfolders.
This maintains the relationship between a UUID and a user name.
Used to serialize a whole inventory for transfer over the network.
virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
Gets everything (folders and items) inside a folder