diff options
author | Adam Frisby | 2008-04-30 21:16:36 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-30 21:16:36 +0000 |
commit | f5c312bc3c2567449c7268a54a08a54119f58d53 (patch) | |
tree | 424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs | |
parent | * Adds the AuthbuyerID field to sqlite and makes use of it. (diff) | |
download | opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.zip opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2 opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz |
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.)
* This should be moved into a seperate project file.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs new file mode 100644 index 0000000..b8899d2 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs | |||
@@ -0,0 +1,215 @@ | |||
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 OpenSim 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.Threading; | ||
31 | using libsecondlife; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Environment.Interfaces; | ||
35 | using OpenSim.Region.Environment.Scenes; | ||
36 | |||
37 | namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload | ||
38 | { | ||
39 | public class TextureDownloadModule : IRegionModule | ||
40 | { | ||
41 | //private static readonly log4net.ILog m_log | ||
42 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | private Scene m_scene; | ||
45 | private List<Scene> m_scenes = new List<Scene>(); | ||
46 | |||
47 | /// <summary> | ||
48 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. | ||
49 | /// </summary> | ||
50 | private readonly BlockingQueue<ITextureSender> m_queueSenders | ||
51 | = new BlockingQueue<ITextureSender>(); | ||
52 | |||
53 | /// <summary> | ||
54 | /// Each user has their own texture download service. | ||
55 | /// </summary> | ||
56 | private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = | ||
57 | new Dictionary<LLUUID, UserTextureDownloadService>(); | ||
58 | |||
59 | private Thread m_thread; | ||
60 | |||
61 | public TextureDownloadModule() | ||
62 | { | ||
63 | } | ||
64 | |||
65 | public void Initialise(Scene scene, IConfigSource config) | ||
66 | { | ||
67 | if (m_scene == null) | ||
68 | { | ||
69 | //Console.WriteLine("Creating Texture download module"); | ||
70 | m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); | ||
71 | m_thread.Name = "ProcessTextureSenderThread"; | ||
72 | m_thread.IsBackground = true; | ||
73 | m_thread.Start(); | ||
74 | ThreadTracker.Add(m_thread); | ||
75 | } | ||
76 | |||
77 | if (!m_scenes.Contains(scene)) | ||
78 | { | ||
79 | m_scenes.Add(scene); | ||
80 | m_scene = scene; | ||
81 | m_scene.EventManager.OnNewClient += NewClient; | ||
82 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Cleanup the texture service related objects for the removed presence. | ||
88 | /// </summary> | ||
89 | /// <param name="agentId"> </param> | ||
90 | private void EventManager_OnRemovePresence(LLUUID agentId) | ||
91 | { | ||
92 | UserTextureDownloadService textureService; | ||
93 | |||
94 | lock (m_userTextureServices) | ||
95 | { | ||
96 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) | ||
97 | { | ||
98 | textureService.Close(); | ||
99 | |||
100 | m_userTextureServices.Remove(agentId); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public void PostInitialise() | ||
106 | { | ||
107 | } | ||
108 | |||
109 | public void Close() | ||
110 | { | ||
111 | } | ||
112 | |||
113 | public string Name | ||
114 | { | ||
115 | get { return "TextureDownloadModule"; } | ||
116 | } | ||
117 | |||
118 | public bool IsSharedModule | ||
119 | { | ||
120 | get { return false; } | ||
121 | } | ||
122 | |||
123 | public void NewClient(IClientAPI client) | ||
124 | { | ||
125 | client.OnRequestTexture += TextureRequest; | ||
126 | } | ||
127 | |||
128 | /// <summary> | ||
129 | /// Does this user have a registered texture download service? | ||
130 | /// </summary> | ||
131 | /// <param name="userID"></param> | ||
132 | /// <param name="textureService"></param> | ||
133 | /// <returns>Always returns true, since a service is created if one does not already exist</returns> | ||
134 | private bool TryGetUserTextureService( | ||
135 | IClientAPI client, out UserTextureDownloadService textureService) | ||
136 | { | ||
137 | lock (m_userTextureServices) | ||
138 | { | ||
139 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
140 | { | ||
141 | return true; | ||
142 | } | ||
143 | |||
144 | textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); | ||
145 | m_userTextureServices.Add(client.AgentId, textureService); | ||
146 | |||
147 | return true; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | /// <summary> | ||
152 | /// Start the process of requesting a given texture. | ||
153 | /// </summary> | ||
154 | /// <param name="sender"> </param> | ||
155 | /// <param name="e"></param> | ||
156 | public void TextureRequest(Object sender, TextureRequestArgs e) | ||
157 | { | ||
158 | IClientAPI client = (IClientAPI) sender; | ||
159 | UserTextureDownloadService textureService; | ||
160 | |||
161 | if (TryGetUserTextureService(client, out textureService)) | ||
162 | { | ||
163 | textureService.HandleTextureRequest(e); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | /// <summary> | ||
168 | /// Entry point for the thread dedicated to processing the texture queue. | ||
169 | /// </summary> | ||
170 | public void ProcessTextureSenders() | ||
171 | { | ||
172 | ITextureSender sender = null; | ||
173 | |||
174 | while (true) | ||
175 | { | ||
176 | sender = m_queueSenders.Dequeue(); | ||
177 | |||
178 | if (sender.Cancel) | ||
179 | { | ||
180 | TextureSent(sender); | ||
181 | |||
182 | sender.Cancel = false; | ||
183 | } | ||
184 | else | ||
185 | { | ||
186 | bool finished = sender.SendTexturePacket(); | ||
187 | if (finished) | ||
188 | { | ||
189 | TextureSent(sender); | ||
190 | } | ||
191 | else | ||
192 | { | ||
193 | m_queueSenders.Enqueue(sender); | ||
194 | } | ||
195 | } | ||
196 | |||
197 | // Make sure that any sender we currently have can get garbage collected | ||
198 | sender = null; | ||
199 | |||
200 | //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count()); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// Called when the texture has finished sending. | ||
206 | /// </summary> | ||
207 | /// <param name="sender"></param> | ||
208 | private void TextureSent(ITextureSender sender) | ||
209 | { | ||
210 | sender.Sending = false; | ||
211 | //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID); | ||
212 | m_scene.AddPendingDownloads(-1); | ||
213 | } | ||
214 | } | ||
215 | } \ No newline at end of file | ||