32 using System.Collections.Generic;
33 using System.Reflection;
34 using OpenSim.Framework;
36 using OpenSim.Server.Base;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.Framework.Scenes;
39 using OpenSim.Services.Interfaces;
40 using OpenSim.Services.Connectors;
41 using OpenSim.Services.Connectors.SimianGrid;
46 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"HGInventoryBroker")]
49 private static readonly ILog m_log =
51 MethodBase.GetCurrentMethod().DeclaringType);
53 private static bool m_Enabled =
false;
56 private Dictionary<string, IInventoryService> m_connectors =
new Dictionary<string, IInventoryService>();
59 protected Dictionary<UUID, string> m_InventoryURLs =
new Dictionary<UUID,string>();
61 private List<Scene> m_Scenes =
new List<Scene>();
68 private object m_Lock =
new object();
75 if (m_UserManagement == null)
77 m_UserManagement = m_Scenes[0].RequestModuleInterface<
IUserManagement>();
79 if (m_UserManagement == null)
81 "[HG INVENTORY CONNECTOR]: Could not retrieve IUserManagement module from {0}",
82 m_Scenes[0].RegionInfo.RegionName);
85 return m_UserManagement;
89 public Type ReplaceableInterface
96 get {
return "HGInventoryBroker"; }
101 IConfig moduleConfig = source.Configs[
"Modules"];
102 if (moduleConfig != null)
104 string name = moduleConfig.GetString(
"InventoryServices",
"");
107 IConfig inventoryConfig = source.Configs[
"InventoryService"];
108 if (inventoryConfig == null)
110 m_log.Error(
"[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
114 string localDll = inventoryConfig.GetString(
"LocalGridInventoryService",
119 if (localDll ==
String.Empty)
121 m_log.Error(
"[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService");
123 throw new Exception(
"Unable to proceed. Please make sure your ini files in config-include are updated according to .example's");
127 m_LocalGridInventoryService =
131 if (m_LocalGridInventoryService == null)
133 m_log.Error(
"[HG INVENTORY CONNECTOR]: Can't load local inventory service");
138 m_log.InfoFormat(
"[HG INVENTORY CONNECTOR]: HG inventory broker enabled with inner connector of type {0}", m_LocalGridInventoryService.GetType());
160 if (m_Scenes.Count == 1)
167 "[HG INVENTORY BROKER]: Manually setting scene in RemoteXInventoryServicesConnector to {0}",
168 scene.RegionInfo.RegionName);
170 ((RemoteXInventoryServicesConnector)m_LocalGridInventoryService)
.Scene = scene;
175 "[HG INVENTORY BROKER]: Manually setting scene in LocalInventoryServicesConnector to {0}",
176 scene.RegionInfo.RegionName);
178 ((LocalInventoryServicesConnector)m_LocalGridInventoryService)
.Scene = scene;
181 scene.EventManager.OnClientClosed += OnClientClosed;
190 m_Scenes.Remove(scene);
198 m_log.InfoFormat(
"[HG INVENTORY CONNECTOR]: Enabled HG inventory for region {0}", scene.RegionInfo.RegionName);
204 void OnClientClosed(UUID clientID,
Scene scene)
206 if (m_InventoryURLs.ContainsKey(clientID))
209 foreach (
Scene s
in m_Scenes)
211 s.TryGetScenePresence(clientID, out sp);
212 if ((sp != null) && !sp.IsChildAgent && (s != scene))
214 m_log.DebugFormat(
"[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping inventoryURL in cache",
215 scene.RegionInfo.RegionName, clientID);
219 DropInventoryServiceURL(clientID);
228 private void CacheInventoryServiceURL(UUID userID)
230 if (UserManagementModule != null && !UserManagementModule.IsLocalGridUser(userID))
233 string inventoryURL = string.Empty;
235 foreach (
Scene scene
in m_Scenes)
237 scene.TryGetScenePresence(userID, out sp);
240 AgentCircuitData aCircuit = scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
241 if (aCircuit == null)
246 if (aCircuit.
ServiceURLs.ContainsKey(
"InventoryServerURI"))
248 inventoryURL = aCircuit.ServiceURLs[
"InventoryServerURI"].ToString();
249 if (inventoryURL != null && inventoryURL !=
string.Empty)
251 inventoryURL = inventoryURL.Trim(
new char[] {
'/' });
252 m_InventoryURLs[userID] = inventoryURL;
253 m_log.DebugFormat(
"[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL);
266 inventoryURL = UserManagementModule.GetUserServerURL(userID,
"InventoryServerURI");
267 if (!
string.IsNullOrEmpty(inventoryURL))
269 inventoryURL = inventoryURL.Trim(
new char[] {
'/' });
270 m_InventoryURLs.Add(userID, inventoryURL);
271 m_log.DebugFormat(
"[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL);
279 private void DropInventoryServiceURL(UUID userID)
281 lock (m_InventoryURLs)
282 if (m_InventoryURLs.ContainsKey(userID))
284 string url = m_InventoryURLs[userID];
285 m_InventoryURLs.Remove(userID);
286 m_log.DebugFormat(
"[HG INVENTORY CONNECTOR]: Removed {0} from the cache of inventory URLs", url);
292 if (m_InventoryURLs.ContainsKey(userID))
293 return m_InventoryURLs[userID];
295 CacheInventoryServiceURL(userID);
297 if (m_InventoryURLs.ContainsKey(userID))
298 return m_InventoryURLs[userID];
305 #region IInventoryService
310 return m_LocalGridInventoryService.CreateUserInventory(userID);
315 string invURL = GetInventoryServiceURL(userID);
319 return m_LocalGridInventoryService.GetInventorySkeleton(userID);
323 return connector.GetInventorySkeleton(userID);
333 string invURL = GetInventoryServiceURL(userID);
337 return m_LocalGridInventoryService.GetRootFolder(userID);
341 root = connector.GetRootFolder(userID);
343 m_Cache.Cache(userID, root);
355 string invURL = GetInventoryServiceURL(userID);
359 return m_LocalGridInventoryService.GetFolderForType(userID, type);
363 f = connector.GetFolderForType(userID, type);
365 m_Cache.Cache(userID, type, f);
374 string invURL = GetInventoryServiceURL(userID);
378 return m_LocalGridInventoryService.GetFolderContent(userID, folderID);
383 m_log.Debug(
"[HG INVENTORY CONNECTOR]: GetFolderContent found content in cache " + folderID);
389 return connector.GetFolderContent(userID, folderID);
394 string invURL = GetInventoryServiceURL(userID);
398 return m_LocalGridInventoryService.GetMultipleFoldersContent(userID, folderIDs);
404 foreach (
UUID fid
in folderIDs)
405 coll[i++] = GetFolderContent(userID, fid);
415 string invURL = GetInventoryServiceURL(userID);
419 return m_LocalGridInventoryService.GetFolderItems(userID, folderID);
421 List<InventoryItemBase> items = m_Cache.GetFolderItems(userID, folderID);
424 m_log.Debug(
"[HG INVENTORY CONNECTOR]: GetFolderItems found items in cache " + folderID);
430 return connector.GetFolderItems(userID, folderID);
440 string invURL = GetInventoryServiceURL(folder.
Owner);
444 return m_LocalGridInventoryService.AddFolder(folder);
448 return connector.AddFolder(folder);
458 string invURL = GetInventoryServiceURL(folder.
Owner);
462 return m_LocalGridInventoryService.UpdateFolder(folder);
466 return connector.UpdateFolder(folder);
471 if (folderIDs == null)
473 if (folderIDs.Count == 0)
478 string invURL = GetInventoryServiceURL(ownerID);
482 return m_LocalGridInventoryService.DeleteFolders(ownerID, folderIDs);
486 return connector.DeleteFolders(ownerID, folderIDs);
496 string invURL = GetInventoryServiceURL(folder.
Owner);
500 return m_LocalGridInventoryService.MoveFolder(folder);
504 return connector.MoveFolder(folder);
514 string invURL = GetInventoryServiceURL(folder.
Owner);
518 return m_LocalGridInventoryService.PurgeFolder(folder);
522 return connector.PurgeFolder(folder);
532 string invURL = GetInventoryServiceURL(item.
Owner);
536 return m_LocalGridInventoryService.AddItem(item);
540 return connector.AddItem(item);
550 string invURL = GetInventoryServiceURL(item.
Owner);
554 return m_LocalGridInventoryService.UpdateItem(item);
558 return connector.UpdateItem(item);
561 public bool MoveItems(UUID ownerID, List<InventoryItemBase> items)
565 if (items.Count == 0)
570 string invURL = GetInventoryServiceURL(ownerID);
574 return m_LocalGridInventoryService.MoveItems(ownerID, items);
578 return connector.MoveItems(ownerID, items);
587 if (itemIDs.Count == 0)
590 string invURL = GetInventoryServiceURL(ownerID);
594 return m_LocalGridInventoryService.DeleteItems(ownerID, itemIDs);
598 return connector.DeleteItems(ownerID, itemIDs);
607 string invURL = GetInventoryServiceURL(item.
Owner);
611 return m_LocalGridInventoryService.GetItem(item);
615 return connector.GetItem(item);
624 string invURL = GetInventoryServiceURL(userID);
628 return m_LocalGridInventoryService.GetMultipleItems(userID, itemIDs);
632 return connector.GetMultipleItems(userID, itemIDs);
642 string invURL = GetInventoryServiceURL(folder.
Owner);
646 return m_LocalGridInventoryService.GetFolder(folder);
650 return connector.GetFolder(folder);
660 return new List<InventoryItemBase>();
667 string invURL = GetInventoryServiceURL(userID);
671 return m_LocalGridInventoryService.GetAssetPermissions(userID, assetID);
675 return connector.GetAssetPermissions(userID, assetID);
685 if (m_connectors.ContainsKey(url))
687 connector = m_connectors[url];
694 m_log.DebugFormat(
"[HG INVENTORY SERVICE]: HELO returned {0}", connectorType);
695 if (connectorType ==
"opensim-simian")
701 RemoteXInventoryServicesConnector rxisc =
new RemoteXInventoryServicesConnector(url);
702 rxisc.Scene = m_Scenes[0];
706 m_connectors.Add(url, connector);
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
bool UpdateFolder(InventoryFolderBase folder)
Update a folder in the user's inventory
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
bool AddFolder(InventoryFolderBase folder)
Add a new folder to the user's inventory
IUserManagement m_UserManagement
bool CreateUserInventory(UUID userID)
Create the entire inventory for a given user
InventoryFolderBase GetRootFolder(UUID userID)
Retrieve the root inventory folder for the given user.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
List< InventoryItemBase > GetFolderItems(UUID userID, UUID folderID)
Gets the items inside a folder
List< InventoryFolderBase > GetInventorySkeleton(UUID userID)
Gets the skeleton of the inventory – folders only
InventoryItemBase GetItem(InventoryItemBase item)
Get an item, given by its UUID
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
bool MoveFolder(InventoryFolderBase folder)
Move an inventory folder to a new location
InventoryCollection[] GetMultipleFoldersContent(UUID userID, UUID[] folderIDs)
Gets everything (folders and items) inside a folder
Cache root and system inventory folders to reduce number of potentially remote inventory calls and as...
bool MoveItems(UUID ownerID, List< InventoryItemBase > items)
Dictionary< string, object > ServiceURLs
int GetAssetPermissions(UUID userID, UUID assetID)
Get the union of permissions of all inventory items that hold the given assetID.
bool AddItem(InventoryItemBase item)
Add a new item to the user's inventory
bool DeleteFolders(UUID ownerID, List< UUID > folderIDs)
Delete an item from the user's inventory
InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
Get multiple items, given by their UUIDs
virtual UUID Owner
The agent who's inventory this is contained by
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.
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
string GetInventoryServiceURL(UUID userID)
bool HasInventoryForUser(UUID userID)
Does the given user have an inventory structure?
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
Inventory Item - contains all the properties associated with an individual inventory piece...
InventoryFolderBase GetFolder(InventoryFolderBase folder)
Get a folder, given by its UUID
List< InventoryItemBase > GetActiveGestures(UUID userId)
Get the active gestures of the agent.
Interactive OpenSim region server
InventoryCollection GetFolderContent(UUID userID, UUID folderID)
Gets everything (folders and items) inside a folder
bool UpdateItem(InventoryItemBase item)
Update an item in the user's inventory
This maintains the relationship between a UUID and a user name.
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
InventoryFolderBase GetFolderForType(UUID userID, FolderType type)
Gets the user folder for the given folder-type
Used to serialize a whole inventory for transfer over the network.