diff options
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/RemoteInventoryServiceConnector.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/ServiceConnectors/Inventory/RemoteInventoryServiceConnector.cs | 246 |
1 files changed, 246 insertions, 0 deletions
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 | |||
28 | using log4net; | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Statistics; | ||
35 | using OpenSim.Services.Connectors; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | using OpenMetaverse; | ||
40 | |||
41 | namespace 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 | } | ||