OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
RemoteXInventoryServiceConnector.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 System;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using Mono.Addins;
33 using Nini.Config;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Monitoring;
36 using OpenSim.Services.Connectors;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
40 using OpenMetaverse;
41 
42 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
43 {
44  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteXInventoryServicesConnector")]
46  {
47  private static readonly ILog m_log =
48  LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 
53  public Scene Scene { get; set; }
54 
55  private bool m_Enabled;
56  private XInventoryServicesConnector m_RemoteConnector;
57 
58  private IUserManagement m_UserManager;
59  public IUserManagement UserManager
60  {
61  get
62  {
63  if (m_UserManager == null)
64  {
65  m_UserManager = Scene.RequestModuleInterface<IUserManagement>();
66 
67  if (m_UserManager == null)
68  m_log.ErrorFormat(
69  "[XINVENTORY CONNECTOR]: Could not retrieve IUserManagement module from {0}",
70  Scene.RegionInfo.RegionName);
71  }
72 
73  return m_UserManager;
74  }
75  }
76 
77  public Type ReplaceableInterface
78  {
79  get { return null; }
80  }
81 
82  public string Name
83  {
84  get { return "RemoteXInventoryServicesConnector"; }
85  }
86 
88  {
89  }
90 
92  {
93  m_RemoteConnector = new XInventoryServicesConnector(url);
94  }
95 
96  public RemoteXInventoryServicesConnector(IConfigSource source)
97  {
98  Init(source);
99  }
100 
101  protected void Init(IConfigSource source)
102  {
103  m_RemoteConnector = new XInventoryServicesConnector(source);
104  }
105 
106  #region ISharedRegionModule
107 
108  public void Initialise(IConfigSource source)
109  {
110  IConfig moduleConfig = source.Configs["Modules"];
111  if (moduleConfig != null)
112  {
113  string name = moduleConfig.GetString("InventoryServices", "");
114  if (name == Name)
115  {
116  Init(source);
117  m_Enabled = true;
118 
119  m_log.Info("[XINVENTORY CONNECTOR]: Remote XInventory enabled");
120  }
121  }
122  }
123 
124  public void PostInitialise()
125  {
126  }
127 
128  public void Close()
129  {
130  }
131 
132  public void AddRegion(Scene scene)
133  {
134 // m_Scene = scene;
135  //m_log.Debug("[XXXX] Adding scene " + m_Scene.RegionInfo.RegionName);
136 
137  if (!m_Enabled)
138  return;
139 
140  scene.RegisterModuleInterface<IInventoryService>(this);
141 
142  if (Scene == null)
143  Scene = scene;
144  }
145 
146  public void RemoveRegion(Scene scene)
147  {
148  if (!m_Enabled)
149  return;
150  }
151 
152  public void RegionLoaded(Scene scene)
153  {
154  if (!m_Enabled)
155  return;
156 
157  m_log.InfoFormat("[XINVENTORY CONNECTOR]: Enabled remote XInventory for region {0}", scene.RegionInfo.RegionName);
158 
159  }
160 
161  #endregion ISharedRegionModule
162 
163  #region IInventoryService
164 
165  public bool CreateUserInventory(UUID user)
166  {
167  return false;
168  }
169 
170  public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
171  {
172  return m_RemoteConnector.GetInventorySkeleton(userId);
173  }
174 
175  public InventoryFolderBase GetRootFolder(UUID userID)
176  {
177  return m_RemoteConnector.GetRootFolder(userID);
178  }
179 
180  public InventoryFolderBase GetFolderForType(UUID userID, FolderType type)
181  {
182  return m_RemoteConnector.GetFolderForType(userID, type);
183  }
184 
185  public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
186  {
187  InventoryCollection invCol = m_RemoteConnector.GetFolderContent(userID, folderID);
188 
189  // Commenting this for now, because it's causing more grief than good
190  //if (invCol != null && UserManager != null)
191  //{
192  // // Protect ourselves against the caller subsequently modifying the items list
193  // List<InventoryItemBase> items = new List<InventoryItemBase>(invCol.Items);
194 
195  // if (items != null && items.Count > 0)
196  // //Util.FireAndForget(delegate
197  // //{
198  // foreach (InventoryItemBase item in items)
199  // if (!string.IsNullOrEmpty(item.CreatorData))
200  // UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
201  // //});
202  //}
203 
204  return invCol;
205  }
206 
207  public virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
208  {
209  return m_RemoteConnector.GetMultipleFoldersContent(principalID, folderIDs);
210  }
211 
212  public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
213  {
214  return m_RemoteConnector.GetFolderItems(userID, folderID);
215  }
216 
217  public bool AddFolder(InventoryFolderBase folder)
218  {
219  if (folder == null)
220  return false;
221 
222  return m_RemoteConnector.AddFolder(folder);
223  }
224 
225  public bool UpdateFolder(InventoryFolderBase folder)
226  {
227  if (folder == null)
228  return false;
229 
230  return m_RemoteConnector.UpdateFolder(folder);
231  }
232 
233  public bool MoveFolder(InventoryFolderBase folder)
234  {
235  if (folder == null)
236  return false;
237 
238  return m_RemoteConnector.MoveFolder(folder);
239  }
240 
241  public bool DeleteFolders(UUID ownerID, List<UUID> folderIDs)
242  {
243  if (folderIDs == null)
244  return false;
245  if (folderIDs.Count == 0)
246  return false;
247 
248  return m_RemoteConnector.DeleteFolders(ownerID, folderIDs);
249  }
250 
251 
252  public bool PurgeFolder(InventoryFolderBase folder)
253  {
254  if (folder == null)
255  return false;
256 
257  return m_RemoteConnector.PurgeFolder(folder);
258  }
259 
260  public bool AddItem(InventoryItemBase item)
261  {
262  if (item == null)
263  return false;
264 
265  return m_RemoteConnector.AddItem(item);
266  }
267 
268  public bool UpdateItem(InventoryItemBase item)
269  {
270  if (item == null)
271  return false;
272 
273  return m_RemoteConnector.UpdateItem(item);
274  }
275 
276  public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
277  {
278  if (items == null)
279  return false;
280 
281  return m_RemoteConnector.MoveItems(ownerID, items);
282  }
283 
284 
285  public bool DeleteItems(UUID ownerID, List<UUID> itemIDs)
286  {
287  if (itemIDs == null)
288  return false;
289  if (itemIDs.Count == 0)
290  return true;
291 
292  return m_RemoteConnector.DeleteItems(ownerID, itemIDs);
293  }
294 
296  {
297  //m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetItem {0}", item.ID);
298  if (item == null)
299  return null;
300 
301  if (m_RemoteConnector == null)
302  m_log.DebugFormat("[XINVENTORY CONNECTOR]: connector stub is null!!!");
303  return m_RemoteConnector.GetItem(item);
304  }
305 
306  public InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
307  {
308  if (itemIDs == null)
309  return new InventoryItemBase[0];
310 
311  return m_RemoteConnector.GetMultipleItems(userID, itemIDs);
312  }
313 
315  {
316  //m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetFolder {0}", folder.ID);
317  if (folder == null)
318  return null;
319 
320  return m_RemoteConnector.GetFolder(folder);
321  }
322 
323  public bool HasInventoryForUser(UUID userID)
324  {
325  return false;
326  }
327 
328  public List<InventoryItemBase> GetActiveGestures(UUID userId)
329  {
330  return new List<InventoryItemBase>();
331  }
332 
333  public int GetAssetPermissions(UUID userID, UUID assetID)
334  {
335  return m_RemoteConnector.GetAssetPermissions(userID, assetID);
336  }
337 
338  #endregion
339  }
340 }
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
int GetAssetPermissions(UUID userID, UUID assetID)
Get the union of permissions of all inventory items that hold the given assetID.
InventoryFolderBase GetFolder(InventoryFolderBase folder)
Get a folder, given by its UUID
bool DeleteItems(UUID ownerID, List< UUID > itemIDs)
Delete an item from the user's inventory
bool PurgeFolder(InventoryFolderBase folder)
Purge an inventory folder of all its items and subfolders.
bool AddFolder(InventoryFolderBase folder)
Add a new folder to the user's inventory
bool DeleteFolders(UUID ownerID, List< UUID > folderIDs)
Delete an item from the user's inventory
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
InventoryCollection GetFolderContent(UUID userID, UUID folderID)
Gets everything (folders and items) inside a folder
bool UpdateFolder(InventoryFolderBase folder)
Update a folder in the user's inventory
List< InventoryItemBase > GetFolderItems(UUID userID, UUID folderID)
Gets the items inside a folder
InventoryFolderBase GetFolderForType(UUID userID, FolderType type)
Gets the user folder for the given folder-type
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
InventoryItemBase GetItem(InventoryItemBase item)
Get an item, given by its UUID
Inventory Item - contains all the properties associated with an individual inventory piece...
InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
Get multiple items, given by their UUIDs
List< InventoryItemBase > GetActiveGestures(UUID userId)
Get the active gestures of the agent.
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 MoveFolder(InventoryFolderBase folder)
Move an inventory folder to a new location
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
InventoryFolderBase GetRootFolder(UUID userID)
Retrieve the root inventory folder for the given user.
virtual InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderIDs)
Gets everything (folders and items) inside a folder
This maintains the relationship between a UUID and a user name.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
Used to serialize a whole inventory for transfer over the network.
List< InventoryFolderBase > GetInventorySkeleton(UUID userId)
Gets the skeleton of the inventory – folders only