* Add DeleteAllContents() method to InventoryFolderImpl - not yet used but will be soon

* Add locking to InventoryFolderImpl class - need more though.
0.6.0-stable
Justin Clarke Casey 2008-04-22 20:47:54 +00:00
parent cdcd092d9a
commit 8d8b4a314f
1 changed files with 126 additions and 56 deletions

View File

@ -57,8 +57,9 @@ namespace OpenSim.Framework.Communications.Cache
{ {
} }
// Methods
public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type)
{
lock (SubFolders)
{ {
if (!SubFolders.ContainsKey(folderID)) if (!SubFolders.ContainsKey(folderID))
{ {
@ -71,16 +72,46 @@ namespace OpenSim.Framework.Communications.Cache
SubFolders.Add(subFold.ID, subFold); SubFolders.Add(subFold.ID, subFold);
return subFold; return subFold;
} }
}
return null; return null;
} }
/// <summary>
/// Delete all the folders and items in this folder.
///
/// TODO: This method is not used yet, but will be shortly
/// </summary>
public void DeleteAllContents()
{
foreach (InventoryFolderImpl folder in SubFolders.Values)
{
folder.DeleteAllContents();
}
SubFolders.Clear();
Items.Clear();
}
/// <summary>
/// Does this folder contain the given item?
/// </summary>
/// <param name="itemID"></param>
/// <returns></returns>
public InventoryItemBase HasItem(LLUUID itemID) public InventoryItemBase HasItem(LLUUID itemID)
{ {
InventoryItemBase base2 = null; InventoryItemBase base2 = null;
lock (Items)
{
if (Items.ContainsKey(itemID)) if (Items.ContainsKey(itemID))
{ {
return Items[itemID]; return Items[itemID];
} }
}
lock (SubFolders)
{
foreach (InventoryFolderImpl folder in SubFolders.Values) foreach (InventoryFolderImpl folder in SubFolders.Values)
{ {
base2 = folder.HasItem(itemID); base2 = folder.HasItem(itemID);
@ -89,17 +120,31 @@ namespace OpenSim.Framework.Communications.Cache
break; break;
} }
} }
}
return base2; return base2;
} }
/// <summary>
/// Delete an item from the folder.
/// </summary>
/// <param name="folderID"></param>
/// <returns></returns>
public bool DeleteItem(LLUUID itemID) public bool DeleteItem(LLUUID itemID)
{ {
bool found = false; bool found = false;
lock (Items)
{
if (Items.ContainsKey(itemID)) if (Items.ContainsKey(itemID))
{ {
Items.Remove(itemID); Items.Remove(itemID);
return true; return true;
} }
}
lock (SubFolders)
{
foreach (InventoryFolderImpl folder in SubFolders.Values) foreach (InventoryFolderImpl folder in SubFolders.Values)
{ {
found = folder.DeleteItem(itemID); found = folder.DeleteItem(itemID);
@ -108,13 +153,20 @@ namespace OpenSim.Framework.Communications.Cache
break; break;
} }
} }
}
return found; return found;
} }
/// <summary>
/// Does this folder contain the given subfolder?
/// </summary>
/// <returns></returns>
public InventoryFolderImpl HasSubFolder(LLUUID folderID) public InventoryFolderImpl HasSubFolder(LLUUID folderID)
{ {
InventoryFolderImpl returnFolder = null; InventoryFolderImpl returnFolder = null;
lock (SubFolders)
{
if (SubFolders.ContainsKey(folderID)) if (SubFolders.ContainsKey(folderID))
{ {
returnFolder = SubFolders[folderID]; returnFolder = SubFolders[folderID];
@ -130,26 +182,44 @@ namespace OpenSim.Framework.Communications.Cache
} }
} }
} }
}
return returnFolder; return returnFolder;
} }
/// <summary>
/// Return the list of items in this folder
/// </summary>
public List<InventoryItemBase> RequestListOfItems() public List<InventoryItemBase> RequestListOfItems()
{ {
List<InventoryItemBase> itemList = new List<InventoryItemBase>(); List<InventoryItemBase> itemList = new List<InventoryItemBase>();
lock (Items)
{
foreach (InventoryItemBase item in Items.Values) foreach (InventoryItemBase item in Items.Values)
{ {
itemList.Add(item); itemList.Add(item);
} }
}
return itemList; return itemList;
} }
/// <summary>
/// Return the list of folders in this folder
/// </summary>
public List<InventoryFolderBase> RequestListOfFolders() public List<InventoryFolderBase> RequestListOfFolders()
{ {
List<InventoryFolderBase> folderList = new List<InventoryFolderBase>(); List<InventoryFolderBase> folderList = new List<InventoryFolderBase>();
lock (SubFolders)
{
foreach (InventoryFolderBase folder in SubFolders.Values) foreach (InventoryFolderBase folder in SubFolders.Values)
{ {
folderList.Add(folder); folderList.Add(folder);
} }
}
return folderList; return folderList;
} }
} }