diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs | 302 |
1 files changed, 0 insertions, 302 deletions
diff --git a/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs deleted file mode 100644 index c7bf6c8..0000000 --- a/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs +++ /dev/null | |||
@@ -1,302 +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 System.Reflection; | ||
31 | using System.Threading; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using BlockingQueue = OpenSim.Framework.BlockingQueue<OpenSim.Region.Framework.Interfaces.ITextureSender>; | ||
40 | using OpenSim.Services.Interfaces; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.Agent.TextureDownload | ||
43 | { | ||
44 | public class TextureDownloadModule : IRegionModule | ||
45 | { | ||
46 | private static readonly ILog m_log | ||
47 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | /// <summary> | ||
50 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. | ||
51 | /// </summary> | ||
52 | private readonly BlockingQueue m_queueSenders | ||
53 | = new BlockingQueue(); | ||
54 | |||
55 | /// <summary> | ||
56 | /// Each user has their own texture download service. | ||
57 | /// </summary> | ||
58 | private readonly Dictionary<UUID, UserTextureDownloadService> m_userTextureServices = | ||
59 | new Dictionary<UUID, UserTextureDownloadService>(); | ||
60 | |||
61 | private Scene m_scene; | ||
62 | private List<Scene> m_scenes = new List<Scene>(); | ||
63 | |||
64 | public TextureDownloadModule() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | #region IRegionModule Members | ||
69 | |||
70 | public void Initialise(Scene scene, IConfigSource config) | ||
71 | { | ||
72 | |||
73 | if (m_scene == null) | ||
74 | { | ||
75 | //m_log.Debug("Creating Texture download module"); | ||
76 | m_scene = scene; | ||
77 | //m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); | ||
78 | //m_thread.Name = "ProcessTextureSenderThread"; | ||
79 | //m_thread.IsBackground = true; | ||
80 | //m_thread.Start(); | ||
81 | //ThreadTracker.Add(m_thread); | ||
82 | } | ||
83 | |||
84 | if (!m_scenes.Contains(scene)) | ||
85 | { | ||
86 | m_scenes.Add(scene); | ||
87 | m_scene = scene; | ||
88 | m_scene.EventManager.OnNewClient += NewClient; | ||
89 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | public void PostInitialise() | ||
94 | { | ||
95 | } | ||
96 | |||
97 | public void Close() | ||
98 | { | ||
99 | } | ||
100 | |||
101 | public string Name | ||
102 | { | ||
103 | get { return "TextureDownloadModule"; } | ||
104 | } | ||
105 | |||
106 | public bool IsSharedModule | ||
107 | { | ||
108 | get { return false; } | ||
109 | } | ||
110 | |||
111 | #endregion | ||
112 | |||
113 | /// <summary> | ||
114 | /// Cleanup the texture service related objects for the removed presence. | ||
115 | /// </summary> | ||
116 | /// <param name="agentId"> </param> | ||
117 | private void EventManager_OnRemovePresence(UUID agentId) | ||
118 | { | ||
119 | UserTextureDownloadService textureService; | ||
120 | |||
121 | lock (m_userTextureServices) | ||
122 | { | ||
123 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) | ||
124 | { | ||
125 | textureService.Close(); | ||
126 | //m_log.DebugFormat("[TEXTURE MODULE]: Removing UserTextureServices from {0}", m_scene.RegionInfo.RegionName); | ||
127 | m_userTextureServices.Remove(agentId); | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | public void NewClient(IClientAPI client) | ||
133 | { | ||
134 | UserTextureDownloadService textureService; | ||
135 | |||
136 | lock (m_userTextureServices) | ||
137 | { | ||
138 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
139 | { | ||
140 | textureService.Close(); | ||
141 | //m_log.DebugFormat("[TEXTURE MODULE]: Removing outdated UserTextureServices from {0}", m_scene.RegionInfo.RegionName); | ||
142 | m_userTextureServices.Remove(client.AgentId); | ||
143 | } | ||
144 | m_userTextureServices.Add(client.AgentId, new UserTextureDownloadService(client, m_scene, m_queueSenders)); | ||
145 | } | ||
146 | |||
147 | client.OnRequestTexture += TextureRequest; | ||
148 | } | ||
149 | |||
150 | /// I'm commenting this out, and replacing it with the implementation below, which | ||
151 | /// may return a null value. This is necessary for avoiding race conditions | ||
152 | /// recreating UserTextureServices for clients that have just been closed. | ||
153 | /// That behavior of always returning a UserTextureServices was causing the | ||
154 | /// A-B-A problem (mantis #2855). | ||
155 | /// | ||
156 | ///// <summary> | ||
157 | ///// Does this user have a registered texture download service? | ||
158 | ///// </summary> | ||
159 | ///// <param name="userID"></param> | ||
160 | ///// <param name="textureService"></param> | ||
161 | ///// <returns>Always returns true, since a service is created if one does not already exist</returns> | ||
162 | //private bool TryGetUserTextureService( | ||
163 | // IClientAPI client, out UserTextureDownloadService textureService) | ||
164 | //{ | ||
165 | // lock (m_userTextureServices) | ||
166 | // { | ||
167 | // if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
168 | // { | ||
169 | // //m_log.DebugFormat("[TEXTURE MODULE]: Found existing UserTextureServices in ", m_scene.RegionInfo.RegionName); | ||
170 | // return true; | ||
171 | // } | ||
172 | |||
173 | // m_log.DebugFormat("[TEXTURE MODULE]: Creating new UserTextureServices in ", m_scene.RegionInfo.RegionName); | ||
174 | // textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); | ||
175 | // m_userTextureServices.Add(client.AgentId, textureService); | ||
176 | |||
177 | // return true; | ||
178 | // } | ||
179 | //} | ||
180 | |||
181 | /// <summary> | ||
182 | /// Does this user have a registered texture download service? | ||
183 | /// </summary> | ||
184 | /// <param name="userID"></param> | ||
185 | /// <param name="textureService"></param> | ||
186 | /// <returns>A UserTextureDownloadService or null in the output parameter, and true or false accordingly.</returns> | ||
187 | private bool TryGetUserTextureService(IClientAPI client, out UserTextureDownloadService textureService) | ||
188 | { | ||
189 | lock (m_userTextureServices) | ||
190 | { | ||
191 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
192 | { | ||
193 | //m_log.DebugFormat("[TEXTURE MODULE]: Found existing UserTextureServices in ", m_scene.RegionInfo.RegionName); | ||
194 | return true; | ||
195 | } | ||
196 | |||
197 | textureService = null; | ||
198 | return false; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | /// <summary> | ||
203 | /// Start the process of requesting a given texture. | ||
204 | /// </summary> | ||
205 | /// <param name="sender"> </param> | ||
206 | /// <param name="e"></param> | ||
207 | public void TextureRequest(Object sender, TextureRequestArgs e) | ||
208 | { | ||
209 | IClientAPI client = (IClientAPI)sender; | ||
210 | |||
211 | if (e.Priority == 1016001f) // Preview | ||
212 | { | ||
213 | if (client.Scene is Scene) | ||
214 | { | ||
215 | Scene scene = (Scene)client.Scene; | ||
216 | |||
217 | ScenePresence sp = scene.GetScenePresence(client.AgentId); | ||
218 | if (sp == null) // Deny unknown user | ||
219 | return; | ||
220 | |||
221 | IInventoryService invService = scene.InventoryService; | ||
222 | if (invService.GetRootFolder(client.AgentId) == null) // Deny no inventory | ||
223 | return; | ||
224 | |||
225 | // Diva 2009-08-13: this test doesn't make any sense to many devs | ||
226 | //if (profile.UserProfile.GodLevel < 200 && profile.RootFolder.FindAsset(e.RequestedAssetID) == null) // Deny if not owned | ||
227 | //{ | ||
228 | // m_log.WarnFormat("[TEXTURE]: user {0} doesn't have permissions to texture {1}"); | ||
229 | // return; | ||
230 | //} | ||
231 | |||
232 | m_log.Debug("Texture preview"); | ||
233 | } | ||
234 | } | ||
235 | |||
236 | UserTextureDownloadService textureService; | ||
237 | |||
238 | if (TryGetUserTextureService(client, out textureService)) | ||
239 | { | ||
240 | textureService.HandleTextureRequest(e); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /// <summary> | ||
245 | /// Entry point for the thread dedicated to processing the texture queue. | ||
246 | /// </summary> | ||
247 | public void ProcessTextureSenders() | ||
248 | { | ||
249 | ITextureSender sender = null; | ||
250 | |||
251 | try | ||
252 | { | ||
253 | while (true) | ||
254 | { | ||
255 | sender = m_queueSenders.Dequeue(); | ||
256 | |||
257 | if (sender.Cancel) | ||
258 | { | ||
259 | TextureSent(sender); | ||
260 | |||
261 | sender.Cancel = false; | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | bool finished = sender.SendTexturePacket(); | ||
266 | if (finished) | ||
267 | { | ||
268 | TextureSent(sender); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | m_queueSenders.Enqueue(sender); | ||
273 | } | ||
274 | } | ||
275 | |||
276 | // Make sure that any sender we currently have can get garbage collected | ||
277 | sender = null; | ||
278 | |||
279 | //m_log.InfoFormat("[TEXTURE] Texture sender queue size: {0}", m_queueSenders.Count()); | ||
280 | } | ||
281 | } | ||
282 | catch (Exception e) | ||
283 | { | ||
284 | // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened | ||
285 | m_log.ErrorFormat( | ||
286 | "[TEXTURE]: Texture send thread terminating with exception. PLEASE REBOOT YOUR SIM - TEXTURES WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}", | ||
287 | e); | ||
288 | } | ||
289 | } | ||
290 | |||
291 | /// <summary> | ||
292 | /// Called when the texture has finished sending. | ||
293 | /// </summary> | ||
294 | /// <param name="sender"></param> | ||
295 | private void TextureSent(ITextureSender sender) | ||
296 | { | ||
297 | sender.Sending = false; | ||
298 | //m_log.DebugFormat("[TEXTURE]: Removing download stat for {0}", sender.assetID); | ||
299 | m_scene.StatsReporter.AddPendingDownloads(-1); | ||
300 | } | ||
301 | } | ||
302 | } | ||