diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs new file mode 100644 index 0000000..57c2091 --- /dev/null +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs | |||
@@ -0,0 +1,108 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | |||
5 | using OpenSim.Framework; | ||
6 | using OpenSim.Framework.Client; | ||
7 | using OpenSim.Region.Framework.Scenes; | ||
8 | |||
9 | using OpenMetaverse; | ||
10 | using Nini.Config; | ||
11 | using log4net; | ||
12 | |||
13 | namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory | ||
14 | { | ||
15 | public abstract class InventoryCache | ||
16 | { | ||
17 | private static readonly ILog m_log = | ||
18 | LogManager.GetLogger( | ||
19 | MethodBase.GetCurrentMethod().DeclaringType); | ||
20 | |||
21 | protected List<Scene> m_Scenes; | ||
22 | |||
23 | // The cache proper | ||
24 | protected Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>> m_InventoryCache; | ||
25 | |||
26 | protected virtual void Init(IConfigSource source) | ||
27 | { | ||
28 | m_Scenes = new List<Scene>(); | ||
29 | m_InventoryCache = new Dictionary<UUID, Dictionary<AssetType, InventoryFolderBase>>(); | ||
30 | } | ||
31 | |||
32 | public virtual void AddRegion(Scene scene) | ||
33 | { | ||
34 | m_Scenes.Add(scene); | ||
35 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; | ||
36 | scene.EventManager.OnClientClosed += OnClientClosed; | ||
37 | } | ||
38 | |||
39 | public virtual void RemoveRegion(Scene scene) | ||
40 | { | ||
41 | if ((m_Scenes != null) && m_Scenes.Contains(scene)) | ||
42 | { | ||
43 | m_Scenes.Remove(scene); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | void OnMakeRootAgent(ScenePresence presence) | ||
48 | { | ||
49 | // Get system folders | ||
50 | |||
51 | // First check if they're here already | ||
52 | lock (m_InventoryCache) | ||
53 | { | ||
54 | if (m_InventoryCache.ContainsKey(presence.UUID)) | ||
55 | { | ||
56 | m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent, system folders for {0} {1} already in cache", presence.Firstname, presence.Lastname); | ||
57 | return; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | // If not, go get them and place them in the cache | ||
62 | Dictionary<AssetType, InventoryFolderBase> folders = GetSystemFolders(presence.UUID); | ||
63 | m_log.DebugFormat("[INVENTORY CACHE]: OnMakeRootAgent, fetched system folders for {0} {1}: count {2}", | ||
64 | presence.Firstname, presence.Lastname, folders.Count); | ||
65 | if (folders.Count > 0) | ||
66 | lock (m_InventoryCache) | ||
67 | m_InventoryCache.Add(presence.UUID, folders); | ||
68 | } | ||
69 | |||
70 | void OnClientClosed(UUID clientID, Scene scene) | ||
71 | { | ||
72 | ScenePresence sp = null; | ||
73 | foreach (Scene s in m_Scenes) | ||
74 | { | ||
75 | s.TryGetAvatar(clientID, out sp); | ||
76 | if (sp != null) | ||
77 | { | ||
78 | m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed, but user {0} still in sim. Keeping system folders in cache", clientID); | ||
79 | return; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed, user {0} out of sim. Dropping system folders", clientID); | ||
84 | // Drop system folders | ||
85 | lock (m_InventoryCache) | ||
86 | if (m_InventoryCache.ContainsKey(clientID)) | ||
87 | m_InventoryCache.Remove(clientID); | ||
88 | |||
89 | } | ||
90 | |||
91 | public abstract Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID); | ||
92 | |||
93 | public InventoryFolderBase GetFolderForType(UUID userID, AssetType type) | ||
94 | { | ||
95 | Dictionary<AssetType, InventoryFolderBase> folders = null; | ||
96 | lock (m_InventoryCache) | ||
97 | { | ||
98 | m_InventoryCache.TryGetValue(userID, out folders); | ||
99 | } | ||
100 | if ((folders != null) && folders.ContainsKey(type)) | ||
101 | { | ||
102 | return folders[type]; | ||
103 | } | ||
104 | |||
105 | return null; | ||
106 | } | ||
107 | } | ||
108 | } | ||