diff options
author | diva | 2009-06-07 19:00:55 +0000 |
---|---|---|
committer | diva | 2009-06-07 19:00:55 +0000 |
commit | 1ad237a8a757a0e6074278aff76805d01abf0c0b (patch) | |
tree | e6a697dd113aeb90c7dd92ee4d07f278d7ebf8de /OpenSim/Framework/Communications | |
parent | Skip lone ident statments or for-loop assignments (diff) | |
download | opensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.zip opensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.gz opensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.bz2 opensim-SC_OLD-1ad237a8a757a0e6074278aff76805d01abf0c0b.tar.xz |
First draft of inventory service connectors, and service implementation. No handlers yet, this is just the OUT part for now. It's not active and nothing in the simulator uses this yet. Just checking it in to start sharing with others. There are a couple of interesting software design points that could use other devs opinions.
Hopefully I added all needed files.
Diffstat (limited to 'OpenSim/Framework/Communications')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs | 470 |
1 files changed, 0 insertions, 470 deletions
diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs deleted file mode 100644 index 71f6f1b..0000000 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ /dev/null | |||
@@ -1,470 +0,0 @@ | |||
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 System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | //using System.Reflection; | ||
33 | |||
34 | //using log4net; | ||
35 | |||
36 | namespace OpenSim.Framework.Communications.Cache | ||
37 | { | ||
38 | public class InventoryFolderImpl : InventoryFolderBase | ||
39 | { | ||
40 | //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
41 | |||
42 | public static readonly string PATH_DELIMITER = "/"; | ||
43 | |||
44 | /// <summary> | ||
45 | /// Items that are contained in this folder | ||
46 | /// </summary> | ||
47 | public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>(); | ||
48 | |||
49 | /// <summary> | ||
50 | /// Child folders that are contained in this folder | ||
51 | /// </summary> | ||
52 | protected Dictionary<UUID, InventoryFolderImpl> m_childFolders = new Dictionary<UUID, InventoryFolderImpl>(); | ||
53 | |||
54 | // Constructors | ||
55 | public InventoryFolderImpl(InventoryFolderBase folderbase) | ||
56 | { | ||
57 | Owner = folderbase.Owner; | ||
58 | ID = folderbase.ID; | ||
59 | Name = folderbase.Name; | ||
60 | ParentID = folderbase.ParentID; | ||
61 | Type = folderbase.Type; | ||
62 | Version = folderbase.Version; | ||
63 | } | ||
64 | |||
65 | public InventoryFolderImpl() | ||
66 | { | ||
67 | } | ||
68 | |||
69 | /// <summary> | ||
70 | /// Create a new subfolder. | ||
71 | /// </summary> | ||
72 | /// <param name="folderID"></param> | ||
73 | /// <param name="folderName"></param> | ||
74 | /// <param name="type"></param> | ||
75 | /// <returns>The newly created subfolder. Returns null if the folder already exists</returns> | ||
76 | public InventoryFolderImpl CreateChildFolder(UUID folderID, string folderName, ushort type) | ||
77 | { | ||
78 | lock (m_childFolders) | ||
79 | { | ||
80 | if (!m_childFolders.ContainsKey(folderID)) | ||
81 | { | ||
82 | InventoryFolderImpl subFold = new InventoryFolderImpl(); | ||
83 | subFold.Name = folderName; | ||
84 | subFold.ID = folderID; | ||
85 | subFold.Type = (short) type; | ||
86 | subFold.ParentID = this.ID; | ||
87 | subFold.Owner = Owner; | ||
88 | m_childFolders.Add(subFold.ID, subFold); | ||
89 | |||
90 | return subFold; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | return null; | ||
95 | } | ||
96 | |||
97 | /// <summary> | ||
98 | /// Add a folder that already exists. | ||
99 | /// </summary> | ||
100 | /// <param name="folder"></param> | ||
101 | public void AddChildFolder(InventoryFolderImpl folder) | ||
102 | { | ||
103 | lock (m_childFolders) | ||
104 | { | ||
105 | folder.ParentID = ID; | ||
106 | m_childFolders[folder.ID] = folder; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | /// <summary> | ||
111 | /// Does this folder contain the given child folder? | ||
112 | /// </summary> | ||
113 | /// <param name="folderID"></param> | ||
114 | /// <returns></returns> | ||
115 | public bool ContainsChildFolder(UUID folderID) | ||
116 | { | ||
117 | return m_childFolders.ContainsKey(folderID); | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// Get a child folder | ||
122 | /// </summary> | ||
123 | /// <param name="folderID"></param> | ||
124 | /// <returns>The folder if it exists, null if it doesn't</returns> | ||
125 | public InventoryFolderImpl GetChildFolder(UUID folderID) | ||
126 | { | ||
127 | InventoryFolderImpl folder = null; | ||
128 | |||
129 | lock (m_childFolders) | ||
130 | { | ||
131 | m_childFolders.TryGetValue(folderID, out folder); | ||
132 | } | ||
133 | |||
134 | return folder; | ||
135 | } | ||
136 | |||
137 | /// <summary> | ||
138 | /// Removes the given child subfolder. | ||
139 | /// </summary> | ||
140 | /// <param name="folderID"></param> | ||
141 | /// <returns> | ||
142 | /// The folder removed, or null if the folder was not present. | ||
143 | /// </returns> | ||
144 | public InventoryFolderImpl RemoveChildFolder(UUID folderID) | ||
145 | { | ||
146 | InventoryFolderImpl removedFolder = null; | ||
147 | |||
148 | lock (m_childFolders) | ||
149 | { | ||
150 | if (m_childFolders.ContainsKey(folderID)) | ||
151 | { | ||
152 | removedFolder = m_childFolders[folderID]; | ||
153 | m_childFolders.Remove(folderID); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | return removedFolder; | ||
158 | } | ||
159 | |||
160 | /// <summary> | ||
161 | /// Delete all the folders and items in this folder. | ||
162 | /// </summary> | ||
163 | public void Purge() | ||
164 | { | ||
165 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
166 | { | ||
167 | folder.Purge(); | ||
168 | } | ||
169 | |||
170 | m_childFolders.Clear(); | ||
171 | Items.Clear(); | ||
172 | } | ||
173 | |||
174 | /// <summary> | ||
175 | /// Returns the item if it exists in this folder or in any of this folder's descendant folders | ||
176 | /// </summary> | ||
177 | /// <param name="itemID"></param> | ||
178 | /// <returns>null if the item is not found</returns> | ||
179 | public InventoryItemBase FindItem(UUID itemID) | ||
180 | { | ||
181 | lock (Items) | ||
182 | { | ||
183 | if (Items.ContainsKey(itemID)) | ||
184 | { | ||
185 | return Items[itemID]; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | lock (m_childFolders) | ||
190 | { | ||
191 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
192 | { | ||
193 | InventoryItemBase item = folder.FindItem(itemID); | ||
194 | |||
195 | if (item != null) | ||
196 | { | ||
197 | return item; | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | |||
202 | return null; | ||
203 | } | ||
204 | |||
205 | public InventoryItemBase FindAsset(UUID assetID) | ||
206 | { | ||
207 | lock (Items) | ||
208 | { | ||
209 | foreach (InventoryItemBase item in Items.Values) | ||
210 | { | ||
211 | if (item.AssetID == assetID) | ||
212 | return item; | ||
213 | } | ||
214 | } | ||
215 | |||
216 | lock (m_childFolders) | ||
217 | { | ||
218 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
219 | { | ||
220 | InventoryItemBase item = folder.FindAsset(assetID); | ||
221 | |||
222 | if (item != null) | ||
223 | { | ||
224 | return item; | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | |||
229 | return null; | ||
230 | } | ||
231 | |||
232 | /// <summary> | ||
233 | /// Deletes an item if it exists in this folder or any children | ||
234 | /// </summary> | ||
235 | /// <param name="folderID"></param> | ||
236 | /// <returns></returns> | ||
237 | public bool DeleteItem(UUID itemID) | ||
238 | { | ||
239 | bool found = false; | ||
240 | |||
241 | lock (Items) | ||
242 | { | ||
243 | if (Items.ContainsKey(itemID)) | ||
244 | { | ||
245 | Items.Remove(itemID); | ||
246 | return true; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | lock (m_childFolders) | ||
251 | { | ||
252 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
253 | { | ||
254 | found = folder.DeleteItem(itemID); | ||
255 | |||
256 | if (found == true) | ||
257 | { | ||
258 | break; | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | |||
263 | return found; | ||
264 | } | ||
265 | |||
266 | /// <summary> | ||
267 | /// Returns the folder requested if it is this folder or is a descendent of this folder. The search is depth | ||
268 | /// first. | ||
269 | /// </summary> | ||
270 | /// <returns>The requested folder if it exists, null if it does not.</returns> | ||
271 | public InventoryFolderImpl FindFolder(UUID folderID) | ||
272 | { | ||
273 | if (folderID == ID) | ||
274 | return this; | ||
275 | |||
276 | lock (m_childFolders) | ||
277 | { | ||
278 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
279 | { | ||
280 | InventoryFolderImpl returnFolder = folder.FindFolder(folderID); | ||
281 | |||
282 | if (returnFolder != null) | ||
283 | return returnFolder; | ||
284 | } | ||
285 | } | ||
286 | |||
287 | return null; | ||
288 | } | ||
289 | |||
290 | /// <summary> | ||
291 | /// Look through all child subfolders for a folder marked as one for a particular asset type, and return it. | ||
292 | /// </summary> | ||
293 | /// <param name="type"></param> | ||
294 | /// <returns>Returns null if no such folder is found</returns> | ||
295 | public InventoryFolderImpl FindFolderForType(int type) | ||
296 | { | ||
297 | lock (m_childFolders) | ||
298 | { | ||
299 | foreach (InventoryFolderImpl f in m_childFolders.Values) | ||
300 | { | ||
301 | if (f.Type == type) | ||
302 | return f; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | return null; | ||
307 | } | ||
308 | |||
309 | /// <summary> | ||
310 | /// Find a folder given a PATH_DELIMITER delimited path starting from this folder | ||
311 | /// </summary> | ||
312 | /// | ||
313 | /// This method does not handle paths that contain multiple delimitors | ||
314 | /// | ||
315 | /// FIXME: We do not yet handle situations where folders have the same name. We could handle this by some | ||
316 | /// XPath like expression | ||
317 | /// | ||
318 | /// FIXME: Delimitors which occur in names themselves are not currently escapable. | ||
319 | /// | ||
320 | /// <param name="path"> | ||
321 | /// The path to the required folder. | ||
322 | /// It this is empty or consists only of the PATH_DELIMTER then this folder itself is returned. | ||
323 | /// </param> | ||
324 | /// <returns>null if the folder is not found</returns> | ||
325 | public InventoryFolderImpl FindFolderByPath(string path) | ||
326 | { | ||
327 | if (path == string.Empty) | ||
328 | return this; | ||
329 | |||
330 | path = path.Trim(); | ||
331 | |||
332 | if (path == PATH_DELIMITER) | ||
333 | return this; | ||
334 | |||
335 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | ||
336 | |||
337 | lock (m_childFolders) | ||
338 | { | ||
339 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
340 | { | ||
341 | if (folder.Name == components[0]) | ||
342 | if (components.Length > 1) | ||
343 | return folder.FindFolderByPath(components[1]); | ||
344 | else | ||
345 | return folder; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | // We didn't find a folder with the given name | ||
350 | return null; | ||
351 | } | ||
352 | |||
353 | /// <summary> | ||
354 | /// Find an item given a PATH_DELIMITOR delimited path starting from this folder. | ||
355 | /// | ||
356 | /// This method does not handle paths that contain multiple delimitors | ||
357 | /// | ||
358 | /// FIXME: We do not yet handle situations where folders or items have the same name. We could handle this by some | ||
359 | /// XPath like expression | ||
360 | /// | ||
361 | /// FIXME: Delimitors which occur in names themselves are not currently escapable. | ||
362 | /// </summary> | ||
363 | /// <param name="path"> | ||
364 | /// The path to the required item. | ||
365 | /// </param> | ||
366 | /// <returns>null if the item is not found</returns> | ||
367 | public InventoryItemBase FindItemByPath(string path) | ||
368 | { | ||
369 | string[] components = path.Split(new string[] { PATH_DELIMITER }, 2, StringSplitOptions.None); | ||
370 | |||
371 | if (components.Length == 1) | ||
372 | { | ||
373 | lock (Items) | ||
374 | { | ||
375 | foreach (InventoryItemBase item in Items.Values) | ||
376 | { | ||
377 | if (item.Name == components[0]) | ||
378 | return item; | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | else | ||
383 | { | ||
384 | lock (m_childFolders) | ||
385 | { | ||
386 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
387 | { | ||
388 | if (folder.Name == components[0]) | ||
389 | return folder.FindItemByPath(components[1]); | ||
390 | } | ||
391 | } | ||
392 | } | ||
393 | |||
394 | // We didn't find an item or intermediate folder with the given name | ||
395 | return null; | ||
396 | } | ||
397 | |||
398 | /// <summary> | ||
399 | /// Return a copy of the list of child items in this folder. The items themselves are the originals. | ||
400 | /// </summary> | ||
401 | public List<InventoryItemBase> RequestListOfItems() | ||
402 | { | ||
403 | List<InventoryItemBase> itemList = new List<InventoryItemBase>(); | ||
404 | |||
405 | lock (Items) | ||
406 | { | ||
407 | foreach (InventoryItemBase item in Items.Values) | ||
408 | { | ||
409 | itemList.Add(item); | ||
410 | } | ||
411 | } | ||
412 | |||
413 | //m_log.DebugFormat("[INVENTORY FOLDER IMPL]: Found {0} items", itemList.Count); | ||
414 | |||
415 | return itemList; | ||
416 | } | ||
417 | |||
418 | /// <summary> | ||
419 | /// Return a copy of the list of child folders in this folder. The folders themselves are the originals. | ||
420 | /// </summary> | ||
421 | public List<InventoryFolderBase> RequestListOfFolders() | ||
422 | { | ||
423 | List<InventoryFolderBase> folderList = new List<InventoryFolderBase>(); | ||
424 | |||
425 | lock (m_childFolders) | ||
426 | { | ||
427 | foreach (InventoryFolderBase folder in m_childFolders.Values) | ||
428 | { | ||
429 | folderList.Add(folder); | ||
430 | } | ||
431 | } | ||
432 | |||
433 | return folderList; | ||
434 | } | ||
435 | |||
436 | public List<InventoryFolderImpl> RequestListOfFolderImpls() | ||
437 | { | ||
438 | List<InventoryFolderImpl> folderList = new List<InventoryFolderImpl>(); | ||
439 | |||
440 | lock (m_childFolders) | ||
441 | { | ||
442 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
443 | { | ||
444 | folderList.Add(folder); | ||
445 | } | ||
446 | } | ||
447 | |||
448 | return folderList; | ||
449 | } | ||
450 | |||
451 | /// <value> | ||
452 | /// The total number of items in this folder and in the immediate child folders (though not from other | ||
453 | /// descendants). | ||
454 | /// </value> | ||
455 | public int TotalCount | ||
456 | { | ||
457 | get | ||
458 | { | ||
459 | int total = Items.Count; | ||
460 | |||
461 | foreach (InventoryFolderImpl folder in m_childFolders.Values) | ||
462 | { | ||
463 | total = total + folder.TotalCount; | ||
464 | } | ||
465 | |||
466 | return total; | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | } | ||