diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs | 436 |
1 files changed, 218 insertions, 218 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs index ae2df69..474ac75 100644 --- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs +++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs | |||
@@ -1,219 +1,219 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Threading; | 30 | using System.Threading; |
31 | using libsecondlife; | 31 | using libsecondlife; |
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Region.Environment.Interfaces; | 34 | using OpenSim.Region.Environment.Interfaces; |
35 | using OpenSim.Region.Environment.Scenes; | 35 | using OpenSim.Region.Environment.Scenes; |
36 | 36 | ||
37 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | 37 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload |
38 | { | 38 | { |
39 | public class TextureDownloadModule : IRegionModule | 39 | public class TextureDownloadModule : IRegionModule |
40 | { | 40 | { |
41 | //private static readonly log4net.ILog m_log | 41 | //private static readonly log4net.ILog m_log |
42 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 42 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
43 | 43 | ||
44 | /// <summary> | 44 | /// <summary> |
45 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. | 45 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. |
46 | /// </summary> | 46 | /// </summary> |
47 | private readonly BlockingQueue<ITextureSender> m_queueSenders | 47 | private readonly BlockingQueue<ITextureSender> m_queueSenders |
48 | = new BlockingQueue<ITextureSender>(); | 48 | = new BlockingQueue<ITextureSender>(); |
49 | 49 | ||
50 | /// <summary> | 50 | /// <summary> |
51 | /// Each user has their own texture download service. | 51 | /// Each user has their own texture download service. |
52 | /// </summary> | 52 | /// </summary> |
53 | private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = | 53 | private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = |
54 | new Dictionary<LLUUID, UserTextureDownloadService>(); | 54 | new Dictionary<LLUUID, UserTextureDownloadService>(); |
55 | 55 | ||
56 | private Scene m_scene; | 56 | private Scene m_scene; |
57 | private List<Scene> m_scenes = new List<Scene>(); | 57 | private List<Scene> m_scenes = new List<Scene>(); |
58 | 58 | ||
59 | private Thread m_thread; | 59 | private Thread m_thread; |
60 | 60 | ||
61 | public TextureDownloadModule() | 61 | public TextureDownloadModule() |
62 | { | 62 | { |
63 | } | 63 | } |
64 | 64 | ||
65 | #region IRegionModule Members | 65 | #region IRegionModule Members |
66 | 66 | ||
67 | public void Initialise(Scene scene, IConfigSource config) | 67 | public void Initialise(Scene scene, IConfigSource config) |
68 | { | 68 | { |
69 | if (m_scene == null) | 69 | if (m_scene == null) |
70 | { | 70 | { |
71 | //Console.WriteLine("Creating Texture download module"); | 71 | //Console.WriteLine("Creating Texture download module"); |
72 | m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); | 72 | m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); |
73 | m_thread.Name = "ProcessTextureSenderThread"; | 73 | m_thread.Name = "ProcessTextureSenderThread"; |
74 | m_thread.IsBackground = true; | 74 | m_thread.IsBackground = true; |
75 | m_thread.Start(); | 75 | m_thread.Start(); |
76 | ThreadTracker.Add(m_thread); | 76 | ThreadTracker.Add(m_thread); |
77 | } | 77 | } |
78 | 78 | ||
79 | if (!m_scenes.Contains(scene)) | 79 | if (!m_scenes.Contains(scene)) |
80 | { | 80 | { |
81 | m_scenes.Add(scene); | 81 | m_scenes.Add(scene); |
82 | m_scene = scene; | 82 | m_scene = scene; |
83 | m_scene.EventManager.OnNewClient += NewClient; | 83 | m_scene.EventManager.OnNewClient += NewClient; |
84 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; | 84 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | public void PostInitialise() | 88 | public void PostInitialise() |
89 | { | 89 | { |
90 | } | 90 | } |
91 | 91 | ||
92 | public void Close() | 92 | public void Close() |
93 | { | 93 | { |
94 | } | 94 | } |
95 | 95 | ||
96 | public string Name | 96 | public string Name |
97 | { | 97 | { |
98 | get { return "TextureDownloadModule"; } | 98 | get { return "TextureDownloadModule"; } |
99 | } | 99 | } |
100 | 100 | ||
101 | public bool IsSharedModule | 101 | public bool IsSharedModule |
102 | { | 102 | { |
103 | get { return false; } | 103 | get { return false; } |
104 | } | 104 | } |
105 | 105 | ||
106 | #endregion | 106 | #endregion |
107 | 107 | ||
108 | /// <summary> | 108 | /// <summary> |
109 | /// Cleanup the texture service related objects for the removed presence. | 109 | /// Cleanup the texture service related objects for the removed presence. |
110 | /// </summary> | 110 | /// </summary> |
111 | /// <param name="agentId"> </param> | 111 | /// <param name="agentId"> </param> |
112 | private void EventManager_OnRemovePresence(LLUUID agentId) | 112 | private void EventManager_OnRemovePresence(LLUUID agentId) |
113 | { | 113 | { |
114 | UserTextureDownloadService textureService; | 114 | UserTextureDownloadService textureService; |
115 | 115 | ||
116 | lock (m_userTextureServices) | 116 | lock (m_userTextureServices) |
117 | { | 117 | { |
118 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) | 118 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) |
119 | { | 119 | { |
120 | textureService.Close(); | 120 | textureService.Close(); |
121 | 121 | ||
122 | m_userTextureServices.Remove(agentId); | 122 | m_userTextureServices.Remove(agentId); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | public void NewClient(IClientAPI client) | 127 | public void NewClient(IClientAPI client) |
128 | { | 128 | { |
129 | client.OnRequestTexture += TextureRequest; | 129 | client.OnRequestTexture += TextureRequest; |
130 | } | 130 | } |
131 | 131 | ||
132 | /// <summary> | 132 | /// <summary> |
133 | /// Does this user have a registered texture download service? | 133 | /// Does this user have a registered texture download service? |
134 | /// </summary> | 134 | /// </summary> |
135 | /// <param name="userID"></param> | 135 | /// <param name="userID"></param> |
136 | /// <param name="textureService"></param> | 136 | /// <param name="textureService"></param> |
137 | /// <returns>Always returns true, since a service is created if one does not already exist</returns> | 137 | /// <returns>Always returns true, since a service is created if one does not already exist</returns> |
138 | private bool TryGetUserTextureService( | 138 | private bool TryGetUserTextureService( |
139 | IClientAPI client, out UserTextureDownloadService textureService) | 139 | IClientAPI client, out UserTextureDownloadService textureService) |
140 | { | 140 | { |
141 | lock (m_userTextureServices) | 141 | lock (m_userTextureServices) |
142 | { | 142 | { |
143 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | 143 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) |
144 | { | 144 | { |
145 | return true; | 145 | return true; |
146 | } | 146 | } |
147 | 147 | ||
148 | textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); | 148 | textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); |
149 | m_userTextureServices.Add(client.AgentId, textureService); | 149 | m_userTextureServices.Add(client.AgentId, textureService); |
150 | 150 | ||
151 | return true; | 151 | return true; |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | /// <summary> | 155 | /// <summary> |
156 | /// Start the process of requesting a given texture. | 156 | /// Start the process of requesting a given texture. |
157 | /// </summary> | 157 | /// </summary> |
158 | /// <param name="sender"> </param> | 158 | /// <param name="sender"> </param> |
159 | /// <param name="e"></param> | 159 | /// <param name="e"></param> |
160 | public void TextureRequest(Object sender, TextureRequestArgs e) | 160 | public void TextureRequest(Object sender, TextureRequestArgs e) |
161 | { | 161 | { |
162 | IClientAPI client = (IClientAPI) sender; | 162 | IClientAPI client = (IClientAPI) sender; |
163 | UserTextureDownloadService textureService; | 163 | UserTextureDownloadService textureService; |
164 | 164 | ||
165 | if (TryGetUserTextureService(client, out textureService)) | 165 | if (TryGetUserTextureService(client, out textureService)) |
166 | { | 166 | { |
167 | textureService.HandleTextureRequest(e); | 167 | textureService.HandleTextureRequest(e); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | /// <summary> | 171 | /// <summary> |
172 | /// Entry point for the thread dedicated to processing the texture queue. | 172 | /// Entry point for the thread dedicated to processing the texture queue. |
173 | /// </summary> | 173 | /// </summary> |
174 | public void ProcessTextureSenders() | 174 | public void ProcessTextureSenders() |
175 | { | 175 | { |
176 | ITextureSender sender = null; | 176 | ITextureSender sender = null; |
177 | 177 | ||
178 | while (true) | 178 | while (true) |
179 | { | 179 | { |
180 | sender = m_queueSenders.Dequeue(); | 180 | sender = m_queueSenders.Dequeue(); |
181 | 181 | ||
182 | if (sender.Cancel) | 182 | if (sender.Cancel) |
183 | { | 183 | { |
184 | TextureSent(sender); | 184 | TextureSent(sender); |
185 | 185 | ||
186 | sender.Cancel = false; | 186 | sender.Cancel = false; |
187 | } | 187 | } |
188 | else | 188 | else |
189 | { | 189 | { |
190 | bool finished = sender.SendTexturePacket(); | 190 | bool finished = sender.SendTexturePacket(); |
191 | if (finished) | 191 | if (finished) |
192 | { | 192 | { |
193 | TextureSent(sender); | 193 | TextureSent(sender); |
194 | } | 194 | } |
195 | else | 195 | else |
196 | { | 196 | { |
197 | m_queueSenders.Enqueue(sender); | 197 | m_queueSenders.Enqueue(sender); |
198 | } | 198 | } |
199 | } | 199 | } |
200 | 200 | ||
201 | // Make sure that any sender we currently have can get garbage collected | 201 | // Make sure that any sender we currently have can get garbage collected |
202 | sender = null; | 202 | sender = null; |
203 | 203 | ||
204 | //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count()); | 204 | //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count()); |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | /// <summary> | 208 | /// <summary> |
209 | /// Called when the texture has finished sending. | 209 | /// Called when the texture has finished sending. |
210 | /// </summary> | 210 | /// </summary> |
211 | /// <param name="sender"></param> | 211 | /// <param name="sender"></param> |
212 | private void TextureSent(ITextureSender sender) | 212 | private void TextureSent(ITextureSender sender) |
213 | { | 213 | { |
214 | sender.Sending = false; | 214 | sender.Sending = false; |
215 | //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID); | 215 | //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID); |
216 | m_scene.AddPendingDownloads(-1); | 216 | m_scene.AddPendingDownloads(-1); |
217 | } | 217 | } |
218 | } | 218 | } |
219 | } \ No newline at end of file | 219 | } \ No newline at end of file |