diff options
author | Melanie | 2009-08-22 20:18:56 +0100 |
---|---|---|
committer | Melanie | 2009-08-22 20:18:56 +0100 |
commit | 1e4238af92dbfdc12be08c211cd0b9d813bfb268 (patch) | |
tree | 812c0fcb2f7797098d9d3c5855c1ed93e603be76 /OpenSim/Grid/InventoryServer/InventoryServiceBase.cs | |
parent | Change prompt handling in console. No user changes (diff) | |
parent | Moved a debug message. (diff) | |
download | opensim-SC-1e4238af92dbfdc12be08c211cd0b9d813bfb268.zip opensim-SC-1e4238af92dbfdc12be08c211cd0b9d813bfb268.tar.gz opensim-SC-1e4238af92dbfdc12be08c211cd0b9d813bfb268.tar.bz2 opensim-SC-1e4238af92dbfdc12be08c211cd0b9d813bfb268.tar.xz |
Merge branch 'master' of ssh://melanie@opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Grid/InventoryServer/InventoryServiceBase.cs')
-rw-r--r-- | OpenSim/Grid/InventoryServer/InventoryServiceBase.cs | 519 |
1 files changed, 519 insertions, 0 deletions
diff --git a/OpenSim/Grid/InventoryServer/InventoryServiceBase.cs b/OpenSim/Grid/InventoryServer/InventoryServiceBase.cs new file mode 100644 index 0000000..f8b4949 --- /dev/null +++ b/OpenSim/Grid/InventoryServer/InventoryServiceBase.cs | |||
@@ -0,0 +1,519 @@ | |||
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.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Communications; | ||
35 | |||
36 | namespace OpenSim.Grid.InventoryServer | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// Abstract base class used by local and grid implementations of an inventory service. | ||
40 | /// </summary> | ||
41 | public abstract class InventoryServiceBase : IInterServiceInventoryServices | ||
42 | { | ||
43 | |||
44 | private static readonly ILog m_log | ||
45 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | protected List<IInventoryDataPlugin> m_plugins = new List<IInventoryDataPlugin>(); | ||
48 | |||
49 | #region Plugin methods | ||
50 | |||
51 | /// <summary> | ||
52 | /// Add a new inventory data plugin - plugins will be requested in the order they were added. | ||
53 | /// </summary> | ||
54 | /// <param name="plugin">The plugin that will provide data</param> | ||
55 | public void AddPlugin(IInventoryDataPlugin plugin) | ||
56 | { | ||
57 | m_plugins.Add(plugin); | ||
58 | } | ||
59 | |||
60 | /// <summary> | ||
61 | /// Adds a list of inventory data plugins, as described by `provider' | ||
62 | /// and `connect', to `m_plugins'. | ||
63 | /// </summary> | ||
64 | /// <param name="provider"> | ||
65 | /// The filename of the inventory server plugin DLL. | ||
66 | /// </param> | ||
67 | /// <param name="connect"> | ||
68 | /// The connection string for the storage backend. | ||
69 | /// </param> | ||
70 | public void AddPlugin(string provider, string connect) | ||
71 | { | ||
72 | m_plugins.AddRange(DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(provider, connect)); | ||
73 | } | ||
74 | |||
75 | #endregion | ||
76 | |||
77 | #region IInventoryServices methods | ||
78 | |||
79 | public string Host | ||
80 | { | ||
81 | get { return "default"; } | ||
82 | } | ||
83 | |||
84 | public List<InventoryFolderBase> GetInventorySkeleton(UUID userId) | ||
85 | { | ||
86 | // m_log.DebugFormat("[AGENT INVENTORY]: Getting inventory skeleton for {0}", userId); | ||
87 | |||
88 | InventoryFolderBase rootFolder = RequestRootFolder(userId); | ||
89 | |||
90 | // Agent has no inventory structure yet. | ||
91 | if (null == rootFolder) | ||
92 | { | ||
93 | return null; | ||
94 | } | ||
95 | |||
96 | List<InventoryFolderBase> userFolders = new List<InventoryFolderBase>(); | ||
97 | |||
98 | userFolders.Add(rootFolder); | ||
99 | |||
100 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
101 | { | ||
102 | IList<InventoryFolderBase> folders = plugin.getFolderHierarchy(rootFolder.ID); | ||
103 | userFolders.AddRange(folders); | ||
104 | } | ||
105 | |||
106 | // foreach (InventoryFolderBase folder in userFolders) | ||
107 | // { | ||
108 | // m_log.DebugFormat("[AGENT INVENTORY]: Got folder {0} {1}", folder.name, folder.folderID); | ||
109 | // } | ||
110 | |||
111 | return userFolders; | ||
112 | } | ||
113 | |||
114 | // See IInventoryServices | ||
115 | public virtual bool HasInventoryForUser(UUID userID) | ||
116 | { | ||
117 | return false; | ||
118 | } | ||
119 | |||
120 | // See IInventoryServices | ||
121 | public virtual InventoryFolderBase RequestRootFolder(UUID userID) | ||
122 | { | ||
123 | // Retrieve the first root folder we get from the list of plugins. | ||
124 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
125 | { | ||
126 | InventoryFolderBase rootFolder = plugin.getUserRootFolder(userID); | ||
127 | if (rootFolder != null) | ||
128 | return rootFolder; | ||
129 | } | ||
130 | |||
131 | // Return nothing if no plugin was able to supply a root folder | ||
132 | return null; | ||
133 | } | ||
134 | |||
135 | // See IInventoryServices | ||
136 | public bool CreateNewUserInventory(UUID user) | ||
137 | { | ||
138 | InventoryFolderBase existingRootFolder = RequestRootFolder(user); | ||
139 | |||
140 | if (null != existingRootFolder) | ||
141 | { | ||
142 | m_log.WarnFormat( | ||
143 | "[AGENT INVENTORY]: Did not create a new inventory for user {0} since they already have " | ||
144 | + "a root inventory folder with id {1}", | ||
145 | user, existingRootFolder.ID); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | UsersInventory inven = new UsersInventory(); | ||
150 | inven.CreateNewInventorySet(user); | ||
151 | AddNewInventorySet(inven); | ||
152 | |||
153 | return true; | ||
154 | } | ||
155 | |||
156 | return false; | ||
157 | } | ||
158 | |||
159 | public List<InventoryItemBase> GetActiveGestures(UUID userId) | ||
160 | { | ||
161 | List<InventoryItemBase> activeGestures = new List<InventoryItemBase>(); | ||
162 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
163 | { | ||
164 | activeGestures.AddRange(plugin.fetchActiveGestures(userId)); | ||
165 | } | ||
166 | |||
167 | return activeGestures; | ||
168 | } | ||
169 | |||
170 | #endregion | ||
171 | |||
172 | #region Methods used by GridInventoryService | ||
173 | |||
174 | public List<InventoryFolderBase> RequestSubFolders(UUID parentFolderID) | ||
175 | { | ||
176 | List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>(); | ||
177 | |||
178 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
179 | { | ||
180 | inventoryList.AddRange(plugin.getInventoryFolders(parentFolderID)); | ||
181 | } | ||
182 | |||
183 | return inventoryList; | ||
184 | } | ||
185 | |||
186 | public List<InventoryItemBase> RequestFolderItems(UUID folderID) | ||
187 | { | ||
188 | List<InventoryItemBase> itemsList = new List<InventoryItemBase>(); | ||
189 | |||
190 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
191 | { | ||
192 | itemsList.AddRange(plugin.getInventoryInFolder(folderID)); | ||
193 | } | ||
194 | |||
195 | return itemsList; | ||
196 | } | ||
197 | |||
198 | #endregion | ||
199 | |||
200 | // See IInventoryServices | ||
201 | public virtual bool AddFolder(InventoryFolderBase folder) | ||
202 | { | ||
203 | m_log.DebugFormat( | ||
204 | "[AGENT INVENTORY]: Adding folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID); | ||
205 | |||
206 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
207 | { | ||
208 | plugin.addInventoryFolder(folder); | ||
209 | } | ||
210 | |||
211 | // FIXME: Should return false on failure | ||
212 | return true; | ||
213 | } | ||
214 | |||
215 | // See IInventoryServices | ||
216 | public virtual bool UpdateFolder(InventoryFolderBase folder) | ||
217 | { | ||
218 | m_log.DebugFormat( | ||
219 | "[AGENT INVENTORY]: Updating folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID); | ||
220 | |||
221 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
222 | { | ||
223 | plugin.updateInventoryFolder(folder); | ||
224 | } | ||
225 | |||
226 | // FIXME: Should return false on failure | ||
227 | return true; | ||
228 | } | ||
229 | |||
230 | // See IInventoryServices | ||
231 | public virtual bool MoveFolder(InventoryFolderBase folder) | ||
232 | { | ||
233 | m_log.DebugFormat( | ||
234 | "[AGENT INVENTORY]: Moving folder {0} {1} to folder {2}", folder.Name, folder.ID, folder.ParentID); | ||
235 | |||
236 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
237 | { | ||
238 | plugin.moveInventoryFolder(folder); | ||
239 | } | ||
240 | |||
241 | // FIXME: Should return false on failure | ||
242 | return true; | ||
243 | } | ||
244 | |||
245 | // See IInventoryServices | ||
246 | public virtual bool AddItem(InventoryItemBase item) | ||
247 | { | ||
248 | m_log.DebugFormat( | ||
249 | "[AGENT INVENTORY]: Adding item {0} {1} to folder {2}", item.Name, item.ID, item.Folder); | ||
250 | |||
251 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
252 | { | ||
253 | plugin.addInventoryItem(item); | ||
254 | } | ||
255 | |||
256 | // FIXME: Should return false on failure | ||
257 | return true; | ||
258 | } | ||
259 | |||
260 | // See IInventoryServices | ||
261 | public virtual bool UpdateItem(InventoryItemBase item) | ||
262 | { | ||
263 | m_log.InfoFormat( | ||
264 | "[AGENT INVENTORY]: Updating item {0} {1} in folder {2}", item.Name, item.ID, item.Folder); | ||
265 | |||
266 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
267 | { | ||
268 | plugin.updateInventoryItem(item); | ||
269 | } | ||
270 | |||
271 | // FIXME: Should return false on failure | ||
272 | return true; | ||
273 | } | ||
274 | |||
275 | // See IInventoryServices | ||
276 | public virtual bool DeleteItem(InventoryItemBase item) | ||
277 | { | ||
278 | m_log.InfoFormat( | ||
279 | "[AGENT INVENTORY]: Deleting item {0} {1} from folder {2}", item.Name, item.ID, item.Folder); | ||
280 | |||
281 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
282 | { | ||
283 | plugin.deleteInventoryItem(item.ID); | ||
284 | } | ||
285 | |||
286 | // FIXME: Should return false on failure | ||
287 | return true; | ||
288 | } | ||
289 | |||
290 | public virtual InventoryItemBase QueryItem(InventoryItemBase item) | ||
291 | { | ||
292 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
293 | { | ||
294 | InventoryItemBase result = plugin.queryInventoryItem(item.ID); | ||
295 | if (result != null) | ||
296 | return result; | ||
297 | } | ||
298 | |||
299 | return null; | ||
300 | } | ||
301 | |||
302 | public virtual InventoryFolderBase QueryFolder(InventoryFolderBase item) | ||
303 | { | ||
304 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
305 | { | ||
306 | InventoryFolderBase result = plugin.queryInventoryFolder(item.ID); | ||
307 | if (result != null) | ||
308 | return result; | ||
309 | } | ||
310 | |||
311 | return null; | ||
312 | } | ||
313 | |||
314 | /// <summary> | ||
315 | /// Purge a folder of all items items and subfolders. | ||
316 | /// | ||
317 | /// FIXME: Really nasty in a sense, because we have to query the database to get information we may | ||
318 | /// already know... Needs heavy refactoring. | ||
319 | /// </summary> | ||
320 | /// <param name="folder"></param> | ||
321 | public virtual bool PurgeFolder(InventoryFolderBase folder) | ||
322 | { | ||
323 | m_log.DebugFormat( | ||
324 | "[AGENT INVENTORY]: Purging folder {0} {1} of its contents", folder.Name, folder.ID); | ||
325 | |||
326 | List<InventoryFolderBase> subFolders = RequestSubFolders(folder.ID); | ||
327 | |||
328 | foreach (InventoryFolderBase subFolder in subFolders) | ||
329 | { | ||
330 | // m_log.DebugFormat("[AGENT INVENTORY]: Deleting folder {0} {1}", subFolder.Name, subFolder.ID); | ||
331 | |||
332 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
333 | { | ||
334 | plugin.deleteInventoryFolder(subFolder.ID); | ||
335 | } | ||
336 | } | ||
337 | |||
338 | List<InventoryItemBase> items = RequestFolderItems(folder.ID); | ||
339 | |||
340 | foreach (InventoryItemBase item in items) | ||
341 | { | ||
342 | DeleteItem(item); | ||
343 | } | ||
344 | |||
345 | // FIXME: Should return false on failure | ||
346 | return true; | ||
347 | } | ||
348 | |||
349 | private void AddNewInventorySet(UsersInventory inventory) | ||
350 | { | ||
351 | foreach (InventoryFolderBase folder in inventory.Folders.Values) | ||
352 | { | ||
353 | AddFolder(folder); | ||
354 | } | ||
355 | } | ||
356 | |||
357 | public InventoryItemBase GetInventoryItem(UUID itemID) | ||
358 | { | ||
359 | foreach (IInventoryDataPlugin plugin in m_plugins) | ||
360 | { | ||
361 | InventoryItemBase item = plugin.getInventoryItem(itemID); | ||
362 | if (item != null) | ||
363 | return item; | ||
364 | } | ||
365 | |||
366 | return null; | ||
367 | } | ||
368 | |||
369 | /// <summary> | ||
370 | /// Used to create a new user inventory. | ||
371 | /// </summary> | ||
372 | private class UsersInventory | ||
373 | { | ||
374 | public Dictionary<UUID, InventoryFolderBase> Folders = new Dictionary<UUID, InventoryFolderBase>(); | ||
375 | public Dictionary<UUID, InventoryItemBase> Items = new Dictionary<UUID, InventoryItemBase>(); | ||
376 | |||
377 | public virtual void CreateNewInventorySet(UUID user) | ||
378 | { | ||
379 | InventoryFolderBase folder = new InventoryFolderBase(); | ||
380 | |||
381 | folder.ParentID = UUID.Zero; | ||
382 | folder.Owner = user; | ||
383 | folder.ID = UUID.Random(); | ||
384 | folder.Name = "My Inventory"; | ||
385 | folder.Type = (short)AssetType.Folder; | ||
386 | folder.Version = 1; | ||
387 | Folders.Add(folder.ID, folder); | ||
388 | |||
389 | UUID rootFolder = folder.ID; | ||
390 | |||
391 | folder = new InventoryFolderBase(); | ||
392 | folder.ParentID = rootFolder; | ||
393 | folder.Owner = user; | ||
394 | folder.ID = UUID.Random(); | ||
395 | folder.Name = "Animations"; | ||
396 | folder.Type = (short)AssetType.Animation; | ||
397 | folder.Version = 1; | ||
398 | Folders.Add(folder.ID, folder); | ||
399 | |||
400 | folder = new InventoryFolderBase(); | ||
401 | folder.ParentID = rootFolder; | ||
402 | folder.Owner = user; | ||
403 | folder.ID = UUID.Random(); | ||
404 | folder.Name = "Body Parts"; | ||
405 | folder.Type = (short)AssetType.Bodypart; | ||
406 | folder.Version = 1; | ||
407 | Folders.Add(folder.ID, folder); | ||
408 | |||
409 | folder = new InventoryFolderBase(); | ||
410 | folder.ParentID = rootFolder; | ||
411 | folder.Owner = user; | ||
412 | folder.ID = UUID.Random(); | ||
413 | folder.Name = "Calling Cards"; | ||
414 | folder.Type = (short)AssetType.CallingCard; | ||
415 | folder.Version = 1; | ||
416 | Folders.Add(folder.ID, folder); | ||
417 | |||
418 | folder = new InventoryFolderBase(); | ||
419 | folder.ParentID = rootFolder; | ||
420 | folder.Owner = user; | ||
421 | folder.ID = UUID.Random(); | ||
422 | folder.Name = "Clothing"; | ||
423 | folder.Type = (short)AssetType.Clothing; | ||
424 | folder.Version = 1; | ||
425 | Folders.Add(folder.ID, folder); | ||
426 | |||
427 | folder = new InventoryFolderBase(); | ||
428 | folder.ParentID = rootFolder; | ||
429 | folder.Owner = user; | ||
430 | folder.ID = UUID.Random(); | ||
431 | folder.Name = "Gestures"; | ||
432 | folder.Type = (short)AssetType.Gesture; | ||
433 | folder.Version = 1; | ||
434 | Folders.Add(folder.ID, folder); | ||
435 | |||
436 | folder = new InventoryFolderBase(); | ||
437 | folder.ParentID = rootFolder; | ||
438 | folder.Owner = user; | ||
439 | folder.ID = UUID.Random(); | ||
440 | folder.Name = "Landmarks"; | ||
441 | folder.Type = (short)AssetType.Landmark; | ||
442 | folder.Version = 1; | ||
443 | Folders.Add(folder.ID, folder); | ||
444 | |||
445 | folder = new InventoryFolderBase(); | ||
446 | folder.ParentID = rootFolder; | ||
447 | folder.Owner = user; | ||
448 | folder.ID = UUID.Random(); | ||
449 | folder.Name = "Lost And Found"; | ||
450 | folder.Type = (short)AssetType.LostAndFoundFolder; | ||
451 | folder.Version = 1; | ||
452 | Folders.Add(folder.ID, folder); | ||
453 | |||
454 | folder = new InventoryFolderBase(); | ||
455 | folder.ParentID = rootFolder; | ||
456 | folder.Owner = user; | ||
457 | folder.ID = UUID.Random(); | ||
458 | folder.Name = "Notecards"; | ||
459 | folder.Type = (short)AssetType.Notecard; | ||
460 | folder.Version = 1; | ||
461 | Folders.Add(folder.ID, folder); | ||
462 | |||
463 | folder = new InventoryFolderBase(); | ||
464 | folder.ParentID = rootFolder; | ||
465 | folder.Owner = user; | ||
466 | folder.ID = UUID.Random(); | ||
467 | folder.Name = "Objects"; | ||
468 | folder.Type = (short)AssetType.Object; | ||
469 | folder.Version = 1; | ||
470 | Folders.Add(folder.ID, folder); | ||
471 | |||
472 | folder = new InventoryFolderBase(); | ||
473 | folder.ParentID = rootFolder; | ||
474 | folder.Owner = user; | ||
475 | folder.ID = UUID.Random(); | ||
476 | folder.Name = "Photo Album"; | ||
477 | folder.Type = (short)AssetType.SnapshotFolder; | ||
478 | folder.Version = 1; | ||
479 | Folders.Add(folder.ID, folder); | ||
480 | |||
481 | folder = new InventoryFolderBase(); | ||
482 | folder.ParentID = rootFolder; | ||
483 | folder.Owner = user; | ||
484 | folder.ID = UUID.Random(); | ||
485 | folder.Name = "Scripts"; | ||
486 | folder.Type = (short)AssetType.LSLText; | ||
487 | folder.Version = 1; | ||
488 | Folders.Add(folder.ID, folder); | ||
489 | |||
490 | folder = new InventoryFolderBase(); | ||
491 | folder.ParentID = rootFolder; | ||
492 | folder.Owner = user; | ||
493 | folder.ID = UUID.Random(); | ||
494 | folder.Name = "Sounds"; | ||
495 | folder.Type = (short)AssetType.Sound; | ||
496 | folder.Version = 1; | ||
497 | Folders.Add(folder.ID, folder); | ||
498 | |||
499 | folder = new InventoryFolderBase(); | ||
500 | folder.ParentID = rootFolder; | ||
501 | folder.Owner = user; | ||
502 | folder.ID = UUID.Random(); | ||
503 | folder.Name = "Textures"; | ||
504 | folder.Type = (short)AssetType.Texture; | ||
505 | folder.Version = 1; | ||
506 | Folders.Add(folder.ID, folder); | ||
507 | |||
508 | folder = new InventoryFolderBase(); | ||
509 | folder.ParentID = rootFolder; | ||
510 | folder.Owner = user; | ||
511 | folder.ID = UUID.Random(); | ||
512 | folder.Name = "Trash"; | ||
513 | folder.Type = (short)AssetType.TrashFolder; | ||
514 | folder.Version = 1; | ||
515 | Folders.Add(folder.ID, folder); | ||
516 | } | ||
517 | } | ||
518 | } | ||
519 | } | ||