Finish the implementation of GetUserInventory, even though it's still not used.

0.7.4.1
Diva Canto 2012-04-06 11:38:47 -07:00
parent 8fd86c9156
commit 6eaff18961
6 changed files with 201 additions and 33 deletions

View File

@ -297,14 +297,35 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return m_LocalGridInventoryService.CreateUserInventory(userID);
}
public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
public List<InventoryFolderBase> GetInventorySkeleton(UUID userID)
{
return m_LocalGridInventoryService.GetInventorySkeleton(userId);
string invURL = GetInventoryServiceURL(userID);
if (invURL == null) // not there, forward to local inventory connector to resolve
return m_LocalGridInventoryService.GetInventorySkeleton(userID);
IInventoryService connector = GetConnector(invURL);
return connector.GetInventorySkeleton(userID);
}
public InventoryCollection GetUserInventory(UUID userID)
{
return null;
string invURL = GetInventoryServiceURL(userID);
m_log.DebugFormat("[HG INVENTORY CONNECTOR]: GetUserInventory for {0} {1}", userID, invURL);
if (invURL == null) // not there, forward to local inventory connector to resolve
return m_LocalGridInventoryService.GetUserInventory(userID);
InventoryCollection c = m_Cache.GetUserInventory(userID);
if (c != null)
return c;
IInventoryService connector = GetConnector(invURL);
c = connector.GetUserInventory(userID);
m_Cache.Cache(userID, c);
return c;
}
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
@ -362,8 +383,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
if (invURL == null) // not there, forward to local inventory connector to resolve
return m_LocalGridInventoryService.GetFolderContent(userID, folderID);
IInventoryService connector = GetConnector(invURL);
InventoryCollection c = m_Cache.GetFolderContent(userID, folderID);
if (c != null)
{
m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolderContent found content in cache " + folderID);
return c;
}
IInventoryService connector = GetConnector(invURL);
return connector.GetFolderContent(userID, folderID);
}
@ -377,8 +404,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
if (invURL == null) // not there, forward to local inventory connector to resolve
return m_LocalGridInventoryService.GetFolderItems(userID, folderID);
IInventoryService connector = GetConnector(invURL);
List<InventoryItemBase> items = m_Cache.GetFolderItems(userID, folderID);
if (items != null)
{
m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolderItems found items in cache " + folderID);
return items;
}
IInventoryService connector = GetConnector(invURL);
return connector.GetFolderItems(userID, folderID);
}

View File

@ -12,6 +12,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
private static ExpiringCache<UUID, InventoryFolderBase> m_RootFolders = new ExpiringCache<UUID, InventoryFolderBase>();
private static ExpiringCache<UUID, Dictionary<AssetType, InventoryFolderBase>> m_FolderTypes = new ExpiringCache<UUID, Dictionary<AssetType, InventoryFolderBase>>();
private static ExpiringCache<UUID, InventoryCollection> m_Inventories = new ExpiringCache<UUID, InventoryCollection>();
public void Cache(UUID userID, InventoryFolderBase root)
{
@ -55,5 +56,55 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return null;
}
public void Cache(UUID userID, InventoryCollection inv)
{
lock (m_Inventories)
m_Inventories.AddOrUpdate(userID, inv, 120);
}
public InventoryCollection GetUserInventory(UUID userID)
{
InventoryCollection inv = null;
if (m_Inventories.TryGetValue(userID, out inv))
return inv;
return null;
}
public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
{
InventoryCollection inv = null;
InventoryCollection c;
if (m_Inventories.TryGetValue(userID, out inv))
{
c = new InventoryCollection();
c.UserID = userID;
c.Folders = inv.Folders.FindAll(delegate(InventoryFolderBase f)
{
return f.ParentID == folderID;
});
c.Items = inv.Items.FindAll(delegate(InventoryItemBase i)
{
return i.Folder == folderID;
});
return c;
}
return null;
}
public List<InventoryItemBase> GetFolderItems(UUID userID, UUID folderID)
{
InventoryCollection inv = null;
if (m_Inventories.TryGetValue(userID, out inv))
{
List<InventoryItemBase> items = inv.Items.FindAll(delegate(InventoryItemBase i)
{
return i.Folder == folderID;
});
return items;
}
return null;
}
}
}

View File

@ -172,7 +172,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
public InventoryCollection GetUserInventory(UUID userID)
{
return null;
return m_RemoteConnector.GetUserInventory(userID);
}
public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
@ -193,16 +193,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
{
InventoryCollection invCol = m_RemoteConnector.GetFolderContent(userID, folderID);
if (UserManager != null)
if (invCol != null && UserManager != null)
{
// Protect ourselves against the caller subsequently modifying the items list
List<InventoryItemBase> items = new List<InventoryItemBase>(invCol.Items);
Util.FireAndForget(delegate
{
foreach (InventoryItemBase item in items)
UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
});
if (items != null && items.Count > 0)
Util.FireAndForget(delegate
{
foreach (InventoryItemBase item in items)
UserManager.AddUser(item.CreatorIdAsUuid, item.CreatorData);
});
}
return invCol;

View File

@ -114,6 +114,8 @@ namespace OpenSim.Server.Handlers.Asset
return HandleCreateUserInventory(request);
case "GETINVENTORYSKELETON":
return HandleGetInventorySkeleton(request);
case "GETUSERINVENTORY":
return HandleGetUserInventory(request);
case "GETROOTFOLDER":
return HandleGetRootFolder(request);
case "GETFOLDERFORTYPE":
@ -153,7 +155,7 @@ namespace OpenSim.Server.Handlers.Asset
}
catch (Exception e)
{
m_log.DebugFormat("[XINVENTORY HANDLER]: Exception {0}", e);
m_log.DebugFormat("[XINVENTORY HANDLER]: Exception {0}", e.StackTrace);
}
return FailureResult();
@ -248,6 +250,45 @@ namespace OpenSim.Server.Handlers.Asset
return encoding.GetBytes(xmlString);
}
byte[] HandleGetUserInventory(Dictionary<string, object> request)
{
Dictionary<string, object> result = new Dictionary<string, object>();
UUID principal = UUID.Zero;
UUID.TryParse(request["PRINCIPAL"].ToString(), out principal);
InventoryCollection icoll = m_InventoryService.GetUserInventory(principal);
if (icoll != null)
{
Dictionary<string, object> folders = new Dictionary<string, object>();
int i = 0;
if (icoll.Folders != null)
{
foreach (InventoryFolderBase f in icoll.Folders)
{
folders["folder_" + i.ToString()] = EncodeFolder(f);
i++;
}
result["FOLDERS"] = folders;
}
if (icoll.Items != null)
{
i = 0;
Dictionary<string, object> items = new Dictionary<string, object>();
foreach (InventoryItemBase it in icoll.Items)
{
items["item_" + i.ToString()] = EncodeItem(it);
i++;
}
result["ITEMS"] = items;
}
}
string xmlString = ServerUtils.BuildXmlResponse(result);
//m_log.DebugFormat("[XXX]: resp string: {0}", xmlString);
UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetBytes(xmlString);
}
byte[] HandleGetRootFolder(Dictionary<string,object> request)
{
Dictionary<string,object> result = new Dictionary<string,object>();
@ -293,22 +334,27 @@ namespace OpenSim.Server.Handlers.Asset
if (icoll != null)
{
Dictionary<string, object> folders = new Dictionary<string, object>();
int i = 0;
foreach (InventoryFolderBase f in icoll.Folders)
int i = 0;
if (icoll.Folders != null)
{
folders["folder_" + i.ToString()] = EncodeFolder(f);
i++;
foreach (InventoryFolderBase f in icoll.Folders)
{
folders["folder_" + i.ToString()] = EncodeFolder(f);
i++;
}
result["FOLDERS"] = folders;
}
result["FOLDERS"] = folders;
i = 0;
Dictionary<string, object> items = new Dictionary<string, object>();
foreach (InventoryItemBase it in icoll.Items)
if (icoll.Items != null)
{
items["item_" + i.ToString()] = EncodeItem(it);
i++;
i = 0;
Dictionary<string, object> items = new Dictionary<string, object>();
foreach (InventoryItemBase it in icoll.Items)
{
items["item_" + i.ToString()] = EncodeItem(it);
i++;
}
result["ITEMS"] = items;
}
result["ITEMS"] = items;
}
string xmlString = ServerUtils.BuildXmlResponse(result);

View File

@ -111,19 +111,21 @@ namespace OpenSim.Services.Connectors
if (ret.Count == 0)
return null;
List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
Dictionary<string, object> folders = (Dictionary<string, object>)ret["FOLDERS"];
List<InventoryFolderBase> fldrs = new List<InventoryFolderBase>();
try
{
foreach (Object o in ret.Values)
folders.Add(BuildFolder((Dictionary<string, object>)o));
foreach (Object o in folders.Values)
fldrs.Add(BuildFolder((Dictionary<string, object>)o));
}
catch (Exception e)
{
m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception unwrapping folder list: {0}", e.Message);
}
return folders;
return fldrs;
}
public InventoryFolderBase GetRootFolder(UUID principalID)
@ -492,12 +494,41 @@ namespace OpenSim.Services.Connectors
return int.Parse(ret["RESULT"].ToString());
}
// These are either obsolete or unused
//
public InventoryCollection GetUserInventory(UUID principalID)
{
return null;
InventoryCollection inventory = new InventoryCollection();
inventory.Folders = new List<InventoryFolderBase>();
inventory.Items = new List<InventoryItemBase>();
inventory.UserID = principalID;
try
{
Dictionary<string, object> ret = MakeRequest("GETUSERINVENTORY",
new Dictionary<string, object> {
{ "PRINCIPAL", principalID.ToString() }
});
if (ret == null)
return null;
if (ret.Count == 0)
return null;
Dictionary<string, object> folders =
(Dictionary<string, object>)ret["FOLDERS"];
Dictionary<string, object> items =
(Dictionary<string, object>)ret["ITEMS"];
foreach (Object o in folders.Values) // getting the values directly, we don't care about the keys folder_i
inventory.Folders.Add(BuildFolder((Dictionary<string, object>)o));
foreach (Object o in items.Values) // getting the values directly, we don't care about the keys item_i
inventory.Items.Add(BuildItem((Dictionary<string, object>)o));
}
catch (Exception e)
{
m_log.DebugFormat("[XINVENTORY CONNECTOR STUB]: Exception in GetUserInventory: {0}", e.Message);
}
return inventory;
}
public void GetUserInventory(UUID principalID, InventoryReceiptCallback callback)

View File

@ -105,6 +105,12 @@ namespace OpenSim.Services.HypergridService
return new List<InventoryFolderBase>();
}
public override InventoryCollection GetUserInventory(UUID userID)
{
// NOGO for this inventory service
return null;
}
public override InventoryFolderBase GetRootFolder(UUID principalID)
{
//m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);