aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs
diff options
context:
space:
mode:
authordiva2009-06-07 19:00:55 +0000
committerdiva2009-06-07 19:00:55 +0000
commit1ad237a8a757a0e6074278aff76805d01abf0c0b (patch)
treee6a697dd113aeb90c7dd92ee4d07f278d7ebf8de /OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs
parentSkip lone ident statments or for-loop assignments (diff)
downloadopensim-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/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs366
1 files changed, 366 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs
new file mode 100644
index 0000000..f4cd269
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs
@@ -0,0 +1,366 @@
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
28using log4net;
29using Nini.Config;
30using System;
31using System.Collections.Generic;
32using System.Reflection;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Server.Base;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
39using OpenSim.Services.Connectors;
40using OpenMetaverse;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectors.Inventory
43{
44 public class HGInventoryBroker : ISharedRegionModule, IInventoryService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private bool m_Enabled = false;
51 private bool m_Initialized = false;
52 private Scene m_Scene;
53 private UserProfileCacheService m_UserProfileService; // This should change to IUserProfileService
54
55 private IInventoryService m_GridService;
56 private ISessionAuthInventoryService m_HGService;
57
58 private string m_LocalGridInventoryURI = string.Empty;
59 public string Name
60 {
61 get { return "HGInventoryBroker"; }
62 }
63
64 public void Initialise(IConfigSource source)
65 {
66 IConfig moduleConfig = source.Configs["Modules"];
67 if (moduleConfig != null)
68 {
69 string name = moduleConfig.GetString("InventoryServices", "");
70 if (name == Name)
71 {
72 IConfig inventoryConfig = source.Configs["InventoryService"];
73 if (inventoryConfig == null)
74 {
75 m_log.Error("[HG INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
76 return;
77 }
78
79 string localDll = inventoryConfig.GetString("LocalGridInventoryService",
80 String.Empty);
81 string HGDll = inventoryConfig.GetString("HypergridInventoryService",
82 String.Empty);
83
84 if (localDll == String.Empty)
85 {
86 m_log.Error("[HG INVENTORY CONNECTOR]: No LocalGridInventoryService named in section InventoryService");
87 return;
88 }
89
90 if (HGDll == String.Empty)
91 {
92 m_log.Error("[HG INVENTORY CONNECTOR]: No HypergridInventoryService named in section InventoryService");
93 return;
94 }
95
96 Object[] args = new Object[] { source };
97 m_GridService =
98 ServerUtils.LoadPlugin<IInventoryService>(localDll,
99 args);
100
101 m_HGService =
102 ServerUtils.LoadPlugin<ISessionAuthInventoryService>(HGDll,
103 args);
104
105 if (m_GridService == null)
106 {
107 m_log.Error("[HG INVENTORY CONNECTOR]: Can't load local inventory service");
108 return;
109 }
110 if (m_HGService == null)
111 {
112 m_log.Error("[HG INVENTORY CONNECTOR]: Can't load hypergrid inventory service");
113 return;
114 }
115
116 m_LocalGridInventoryURI = inventoryConfig.GetString("InventoryServerURI", string.Empty);
117
118 m_Enabled = true;
119 m_log.Info("[HG INVENTORY CONNECTOR]: HG asset broker enabled");
120 }
121 }
122 }
123
124 public void PostInitialise()
125 {
126 }
127
128 public void Close()
129 {
130 }
131
132 public void AddRegion(Scene scene)
133 {
134 if (!m_Enabled)
135 return;
136
137 if (!m_Initialized)
138 {
139 m_Scene = scene;
140 // HACK for now. Ugh!
141 m_UserProfileService = m_Scene.CommsManager.UserProfileCacheService;
142 }
143
144 scene.RegisterModuleInterface<IInventoryService>(this);
145 }
146
147 public void RemoveRegion(Scene scene)
148 {
149 }
150
151 public void RegionLoaded(Scene scene)
152 {
153 if (!m_Enabled)
154 return;
155
156 m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled remote inventory for region {0}", scene.RegionInfo.RegionName);
157
158 }
159
160 #region IInventoryService
161
162 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
163 {
164 if (IsLocalGridUser(userID))
165 m_GridService.GetUserInventory(userID, callback);
166 else
167 {
168 UUID sessionID = GetSessionID(userID);
169 string uri = "http://" + GetUserInventoryURI(userID) + "/" + userID.ToString();
170 m_HGService.GetUserInventory(uri, sessionID, callback);
171 }
172 }
173
174 public bool AddFolder(InventoryFolderBase folder)
175 {
176 if (folder == null)
177 return false;
178
179 if (IsLocalGridUser(folder.Owner))
180 return m_GridService.AddFolder(folder);
181 else
182 {
183 UUID sessionID = GetSessionID(folder.Owner);
184 string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
185 return m_HGService.AddFolder(uri, folder, sessionID);
186 }
187 }
188
189 public bool UpdateFolder(InventoryFolderBase folder)
190 {
191 if (folder == null)
192 return false;
193
194 if (IsLocalGridUser(folder.Owner))
195 return m_GridService.UpdateFolder(folder);
196 else
197 {
198 UUID sessionID = GetSessionID(folder.Owner);
199 string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
200 return m_HGService.UpdateFolder(uri, folder, sessionID);
201 }
202 }
203
204 public bool MoveFolder(InventoryFolderBase folder)
205 {
206 if (folder == null)
207 return false;
208
209 if (IsLocalGridUser(folder.Owner))
210 return m_GridService.MoveFolder(folder);
211 else
212 {
213 UUID sessionID = GetSessionID(folder.Owner);
214 string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
215 return m_HGService.MoveFolder(uri, folder, sessionID);
216 }
217 }
218
219 public bool PurgeFolder(InventoryFolderBase folder)
220 {
221 if (folder == null)
222 return false;
223
224 if (IsLocalGridUser(folder.Owner))
225 return m_GridService.PurgeFolder(folder);
226 else
227 {
228 UUID sessionID = GetSessionID(folder.Owner);
229 string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
230 return m_HGService.PurgeFolder(uri, folder, sessionID);
231 }
232 }
233
234 public bool AddItem(InventoryItemBase item)
235 {
236 if (item == null)
237 return false;
238
239 if (IsLocalGridUser(item.Owner))
240 return m_GridService.AddItem(item);
241 else
242 {
243 UUID sessionID = GetSessionID(item.Owner);
244 string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
245 return m_HGService.AddItem(uri, item, sessionID);
246 }
247 }
248
249 public bool UpdateItem(InventoryItemBase item)
250 {
251 if (item == null)
252 return false;
253
254 if (IsLocalGridUser(item.Owner))
255 return m_GridService.UpdateItem(item);
256 else
257 {
258 UUID sessionID = GetSessionID(item.Owner);
259 string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
260 return m_HGService.UpdateItem(uri, item, sessionID);
261 }
262 }
263
264 public bool DeleteItem(InventoryItemBase item)
265 {
266 if (item == null)
267 return false;
268
269 if (IsLocalGridUser(item.Owner))
270 return m_GridService.DeleteItem(item);
271 else
272 {
273 UUID sessionID = GetSessionID(item.Owner);
274 string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
275 return m_HGService.DeleteItem(uri, item, sessionID);
276 }
277 }
278
279 public InventoryItemBase QueryItem(InventoryItemBase item)
280 {
281 if (item == null)
282 return null;
283
284 if (IsLocalGridUser(item.Owner))
285 return m_GridService.QueryItem(item);
286 else
287 {
288 UUID sessionID = GetSessionID(item.Owner);
289 string uri = "http://" + GetUserInventoryURI(item.Owner) + "/" + item.Owner.ToString();
290 return m_HGService.QueryItem(uri, item, sessionID);
291 }
292 }
293
294 public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
295 {
296 if (folder == null)
297 return null;
298
299 if (IsLocalGridUser(folder.Owner))
300 return m_GridService.QueryFolder(folder);
301 else
302 {
303 UUID sessionID = GetSessionID(folder.Owner);
304 string uri = "http://" + GetUserInventoryURI(folder.Owner) + "/" + folder.Owner.ToString();
305 return m_HGService.QueryFolder(uri, folder, sessionID);
306 }
307 }
308
309 public bool HasInventoryForUser(UUID userID)
310 {
311 return false;
312 }
313
314 public InventoryFolderBase RequestRootFolder(UUID userID)
315 {
316 return null;
317 }
318
319 #endregion
320
321 private UUID GetSessionID(UUID userID)
322 {
323 ScenePresence sp = m_Scene.GetScenePresence(userID);
324 if (sp != null)
325 return sp.ControllingClient.SessionId;
326
327 return UUID.Zero;
328 }
329
330 private bool IsLocalGridUser(UUID userID)
331 {
332 if (m_UserProfileService == null)
333 return false;
334
335 CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID);
336 if (uinfo == null)
337 return true;
338
339 string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
340
341 if ((userInventoryServerURI == m_LocalGridInventoryURI) || (userInventoryServerURI == ""))
342 {
343 return true;
344 }
345 return false;
346 }
347
348 private string GetUserInventoryURI(UUID userID)
349 {
350 string invURI = m_LocalGridInventoryURI;
351
352 CachedUserInfo uinfo = m_UserProfileService.GetUserDetails(userID);
353 if ((uinfo == null) || (uinfo.UserProfile == null))
354 return invURI;
355
356 string userInventoryServerURI = HGNetworkServersInfo.ServerURI(uinfo.UserProfile.UserInventoryURI);
357
358 if ((userInventoryServerURI != null) &&
359 (userInventoryServerURI != ""))
360 invURI = userInventoryServerURI;
361 return invURI;
362 }
363
364
365 }
366}