aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectors
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
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')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Inventory/HGInventoryBroker.cs366
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Inventory/LocalInventoryServiceConnector.cs246
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectors/Inventory/RemoteInventoryServiceConnector.cs246
3 files changed, 858 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}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/LocalInventoryServiceConnector.cs
new file mode 100644
index 0000000..3db08eb
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/LocalInventoryServiceConnector.cs
@@ -0,0 +1,246 @@
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.Data;
35using OpenSim.Server.Base;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
39using OpenMetaverse;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectors.Inventory
42{
43 public class LocalInventoryServicesConnector :
44 ISharedRegionModule, IInventoryService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private IInventoryService m_InventoryService;
51
52 private bool m_Enabled = false;
53
54 public string Name
55 {
56 get { return "LocalInventoryServicesConnector"; }
57 }
58
59 public void Initialise(IConfigSource source)
60 {
61 IConfig moduleConfig = source.Configs["Modules"];
62 if (moduleConfig != null)
63 {
64 string name = moduleConfig.GetString("InventoryServices", "");
65 if (name == Name)
66 {
67 IConfig assetConfig = source.Configs["InventoryService"];
68 if (assetConfig == null)
69 {
70 m_log.Error("[INVENTORY CONNECTOR]: InventoryService missing from OpenSim.ini");
71 return;
72 }
73
74 string serviceDll = assetConfig.GetString("LocalServiceModule",
75 String.Empty);
76
77 if (serviceDll == String.Empty)
78 {
79 m_log.Error("[INVENTORY CONNECTOR]: No LocalServiceModule named in section InventoryService");
80 return;
81 }
82
83 Object[] args = new Object[] { source };
84 m_InventoryService =
85 ServerUtils.LoadPlugin<IInventoryService>(serviceDll,
86 args);
87
88 if (m_InventoryService == null)
89 {
90 m_log.Error("[INVENTORY CONNECTOR]: Can't load asset service");
91 return;
92 }
93
94 //List<IInventoryDataPlugin> plugins
95 // = DataPluginFactory.LoadDataPlugins<IInventoryDataPlugin>(
96 // configSettings.StandaloneInventoryPlugin,
97 // configSettings.StandaloneInventorySource);
98
99 //foreach (IInventoryDataPlugin plugin in plugins)
100 //{
101 // // Using the OSP wrapper plugin for database plugins should be made configurable at some point
102 // m_InventoryService.AddPlugin(new OspInventoryWrapperPlugin(plugin, this));
103 //}
104
105 m_Enabled = true;
106 m_log.Info("[INVENTORY CONNECTOR]: Local asset connector enabled");
107 }
108 }
109 }
110
111 public void PostInitialise()
112 {
113 }
114
115 public void Close()
116 {
117 }
118
119 public void AddRegion(Scene scene)
120 {
121 if (!m_Enabled)
122 return;
123
124 scene.RegisterModuleInterface<IInventoryService>(this);
125 }
126
127 public void RemoveRegion(Scene scene)
128 {
129 }
130
131 public void RegionLoaded(Scene scene)
132 {
133 if (!m_Enabled)
134 return;
135
136 m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled local assets for region {0}", scene.RegionInfo.RegionName);
137
138 }
139
140 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
141 {
142 m_InventoryService.GetUserInventory(userID, callback);
143 }
144
145 /// <summary>
146 /// Add a new folder to the user's inventory
147 /// </summary>
148 /// <param name="folder"></param>
149 /// <returns>true if the folder was successfully added</returns>
150 public bool AddFolder(InventoryFolderBase folder)
151 {
152 return m_InventoryService.AddFolder(folder);
153 }
154
155 /// <summary>
156 /// Update a folder in the user's inventory
157 /// </summary>
158 /// <param name="folder"></param>
159 /// <returns>true if the folder was successfully updated</returns>
160 public bool UpdateFolder(InventoryFolderBase folder)
161 {
162 return m_InventoryService.UpdateFolder(folder);
163 }
164
165 /// <summary>
166 /// Move an inventory folder to a new location
167 /// </summary>
168 /// <param name="folder">A folder containing the details of the new location</param>
169 /// <returns>true if the folder was successfully moved</returns>
170 public bool MoveFolder(InventoryFolderBase folder)
171 {
172 return m_InventoryService.MoveFolder(folder);
173 }
174
175 /// <summary>
176 /// Purge an inventory folder of all its items and subfolders.
177 /// </summary>
178 /// <param name="folder"></param>
179 /// <returns>true if the folder was successfully purged</returns>
180 public bool PurgeFolder(InventoryFolderBase folder)
181 {
182 return m_InventoryService.PurgeFolder(folder);
183 }
184
185 /// <summary>
186 /// Add a new item to the user's inventory
187 /// </summary>
188 /// <param name="item"></param>
189 /// <returns>true if the item was successfully added</returns>
190 public bool AddItem(InventoryItemBase item)
191 {
192 return m_InventoryService.AddItem(item);
193 }
194
195 /// <summary>
196 /// Update an item in the user's inventory
197 /// </summary>
198 /// <param name="item"></param>
199 /// <returns>true if the item was successfully updated</returns>
200 public bool UpdateItem(InventoryItemBase item)
201 {
202 return m_InventoryService.UpdateItem(item);
203 }
204
205 /// <summary>
206 /// Delete an item from the user's inventory
207 /// </summary>
208 /// <param name="item"></param>
209 /// <returns>true if the item was successfully deleted</returns>
210 public bool DeleteItem(InventoryItemBase item)
211 {
212 return m_InventoryService.DeleteItem(item);
213 }
214
215 public InventoryItemBase QueryItem(InventoryItemBase item)
216 {
217 return m_InventoryService.QueryItem(item);
218 }
219
220 public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
221 {
222 return m_InventoryService.QueryFolder(folder);
223 }
224
225 /// <summary>
226 /// Does the given user have an inventory structure?
227 /// </summary>
228 /// <param name="userID"></param>
229 /// <returns></returns>
230 public bool HasInventoryForUser(UUID userID)
231 {
232 return m_InventoryService.HasInventoryForUser(userID);
233 }
234
235 /// <summary>
236 /// Retrieve the root inventory folder for the given user.
237 /// </summary>
238 /// <param name="userID"></param>
239 /// <returns>null if no root folder was found</returns>
240 public InventoryFolderBase RequestRootFolder(UUID userID)
241 {
242 return m_InventoryService.RequestRootFolder(userID);
243 }
244
245 }
246}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/RemoteInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/RemoteInventoryServiceConnector.cs
new file mode 100644
index 0000000..ddb6cff
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectors/Inventory/RemoteInventoryServiceConnector.cs
@@ -0,0 +1,246 @@
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 System;
30using System.Collections.Generic;
31using System.Reflection;
32using Nini.Config;
33using OpenSim.Framework;
34using OpenSim.Framework.Statistics;
35using OpenSim.Services.Connectors;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
39using OpenMetaverse;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectors.Inventory
42{
43 public class RemoteInventoryServicesConnector :
44 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 InventoryServicesConnector m_RemoteConnector;
54
55 public string Name
56 {
57 get { return "RemoteInventoryServicesConnector"; }
58 }
59
60 public RemoteInventoryServicesConnector(IConfigSource source)
61 {
62 Init(source);
63 }
64
65 private void Init(IConfigSource source)
66 {
67 m_RemoteConnector = new InventoryServicesConnector(source);
68 }
69
70
71 #region ISharedRegionModule
72
73 public void Initialise(IConfigSource source)
74 {
75 IConfig moduleConfig = source.Configs["Modules"];
76 if (moduleConfig != null)
77 {
78 string name = moduleConfig.GetString("InventoryServices", "");
79 if (name == Name)
80 {
81 Init(source);
82 m_Enabled = true;
83
84 m_log.Info("[INVENTORY CONNECTOR]: Remote inventory enabled");
85 }
86 }
87 }
88
89 public void PostInitialise()
90 {
91 }
92
93 public void Close()
94 {
95 }
96
97 public void AddRegion(Scene scene)
98 {
99 if (!m_Enabled)
100 return;
101
102 if (!m_Initialized)
103 m_Scene = scene;
104
105 scene.RegisterModuleInterface<IInventoryService>(this);
106 }
107
108 public void RemoveRegion(Scene scene)
109 {
110 }
111
112 public void RegionLoaded(Scene scene)
113 {
114 if (!m_Enabled)
115 return;
116
117 m_log.InfoFormat("[INVENTORY CONNECTOR]: Enabled remote inventory for region {0}", scene.RegionInfo.RegionName);
118
119 }
120
121 #endregion ISharedRegionModule
122
123 #region IInventoryService
124
125 public void GetUserInventory(UUID userID, InventoryReceiptCallback callback)
126 {
127 UUID sessionID = GetSessionID(userID);
128 try
129 {
130 m_RemoteConnector.GetUserInventory(userID.ToString(), sessionID, callback);
131 }
132 catch (Exception e)
133 {
134 if (StatsManager.SimExtraStats != null)
135 StatsManager.SimExtraStats.AddInventoryServiceRetrievalFailure();
136
137 m_log.ErrorFormat("[INVENTORY CONNECTOR]: Request inventory operation failed, {0} {1}",
138 e.Source, e.Message);
139 }
140
141 }
142
143 public bool AddFolder(InventoryFolderBase folder)
144 {
145 if (folder == null)
146 return false;
147
148 UUID sessionID = GetSessionID(folder.Owner);
149 return m_RemoteConnector.AddFolder(folder.Owner.ToString(), folder, sessionID);
150 }
151
152 public bool UpdateFolder(InventoryFolderBase folder)
153 {
154 if (folder == null)
155 return false;
156
157 UUID sessionID = GetSessionID(folder.Owner);
158 return m_RemoteConnector.UpdateFolder(folder.Owner.ToString(), folder, sessionID);
159 }
160
161 public bool MoveFolder(InventoryFolderBase folder)
162 {
163 if (folder == null)
164 return false;
165
166 UUID sessionID = GetSessionID(folder.Owner);
167 return m_RemoteConnector.MoveFolder(folder.Owner.ToString(), folder, sessionID);
168 }
169
170 public bool PurgeFolder(InventoryFolderBase folder)
171 {
172 if (folder == null)
173 return false;
174
175 UUID sessionID = GetSessionID(folder.Owner);
176 return m_RemoteConnector.PurgeFolder(folder.Owner.ToString(), folder, sessionID);
177 }
178
179 public bool AddItem(InventoryItemBase item)
180 {
181 if (item == null)
182 return false;
183
184 UUID sessionID = GetSessionID(item.Owner);
185 return m_RemoteConnector.AddItem(item.Owner.ToString(), item, sessionID);
186 }
187
188 public bool UpdateItem(InventoryItemBase item)
189 {
190 if (item == null)
191 return false;
192
193 UUID sessionID = GetSessionID(item.Owner);
194 return m_RemoteConnector.UpdateItem(item.Owner.ToString(), item, sessionID);
195 }
196
197 public bool DeleteItem(InventoryItemBase item)
198 {
199 if (item == null)
200 return false;
201
202 UUID sessionID = GetSessionID(item.Owner);
203 return m_RemoteConnector.DeleteItem(item.Owner.ToString(), item, sessionID);
204 }
205
206 public InventoryItemBase QueryItem(InventoryItemBase item)
207 {
208 if (item == null)
209 return null;
210
211 UUID sessionID = GetSessionID(item.Owner);
212 return m_RemoteConnector.QueryItem(item.Owner.ToString(), item, sessionID);
213 }
214
215 public InventoryFolderBase QueryFolder(InventoryFolderBase folder)
216 {
217 if (folder == null)
218 return null;
219
220 UUID sessionID = GetSessionID(folder.Owner);
221 return m_RemoteConnector.QueryFolder(folder.Owner.ToString(), folder, sessionID);
222 }
223
224 public bool HasInventoryForUser(UUID userID)
225 {
226 return false;
227 }
228
229 public InventoryFolderBase RequestRootFolder(UUID userID)
230 {
231 return null;
232 }
233
234 #endregion
235
236 private UUID GetSessionID(UUID userID)
237 {
238 ScenePresence sp = m_Scene.GetScenePresence(userID);
239 if (sp != null)
240 return sp.ControllingClient.SessionId;
241
242 return UUID.Zero;
243 }
244
245 }
246}