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/TextureDownloadModule.cs | |
parent | * Adds the AuthbuyerID field to sqlite and makes use of it. (diff) | |
download | opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.zip opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz opensim-SC_OLD-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2 opensim-SC_OLD-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/TextureDownloadModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/TextureDownloadModule.cs | 218 |
1 files changed, 0 insertions, 218 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs deleted file mode 100644 index bde0dc0..0000000 --- a/OpenSim/Region/Environment/Modules/TextureDownloadModule.cs +++ /dev/null | |||
@@ -1,218 +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 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 | ||
38 | { | ||
39 | //this is a first attempt, to start breaking the mess thats called the assetcache up. | ||
40 | // basically this should be the texture sending (to clients) code moved out of assetcache | ||
41 | //and some small clean up | ||
42 | public class TextureDownloadModule : IRegionModule | ||
43 | { | ||
44 | //private static readonly log4net.ILog m_log | ||
45 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private Scene m_scene; | ||
48 | private List<Scene> m_scenes = new List<Scene>(); | ||
49 | |||
50 | /// <summary> | ||
51 | /// There is one queue for all textures waiting to be sent, regardless of the requesting user. | ||
52 | /// </summary> | ||
53 | private readonly BlockingQueue<ITextureSender> m_queueSenders | ||
54 | = new BlockingQueue<ITextureSender>(); | ||
55 | |||
56 | /// <summary> | ||
57 | /// Each user has their own texture download service. | ||
58 | /// </summary> | ||
59 | private readonly Dictionary<LLUUID, UserTextureDownloadService> m_userTextureServices = | ||
60 | new Dictionary<LLUUID, UserTextureDownloadService>(); | ||
61 | |||
62 | private Thread m_thread; | ||
63 | |||
64 | public TextureDownloadModule() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | public void Initialise(Scene scene, IConfigSource config) | ||
69 | { | ||
70 | if (m_scene == null) | ||
71 | { | ||
72 | //Console.WriteLine("Creating Texture download module"); | ||
73 | m_thread = new Thread(new ThreadStart(ProcessTextureSenders)); | ||
74 | m_thread.Name = "ProcessTextureSenderThread"; | ||
75 | m_thread.IsBackground = true; | ||
76 | m_thread.Start(); | ||
77 | ThreadTracker.Add(m_thread); | ||
78 | } | ||
79 | |||
80 | if (!m_scenes.Contains(scene)) | ||
81 | { | ||
82 | m_scenes.Add(scene); | ||
83 | m_scene = scene; | ||
84 | m_scene.EventManager.OnNewClient += NewClient; | ||
85 | m_scene.EventManager.OnRemovePresence += EventManager_OnRemovePresence; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | /// <summary> | ||
90 | /// Cleanup the texture service related objects for the removed presence. | ||
91 | /// </summary> | ||
92 | /// <param name="agentId"> </param> | ||
93 | private void EventManager_OnRemovePresence(LLUUID agentId) | ||
94 | { | ||
95 | UserTextureDownloadService textureService; | ||
96 | |||
97 | lock (m_userTextureServices) | ||
98 | { | ||
99 | if (m_userTextureServices.TryGetValue(agentId, out textureService)) | ||
100 | { | ||
101 | textureService.Close(); | ||
102 | |||
103 | m_userTextureServices.Remove(agentId); | ||
104 | } | ||
105 | } | ||
106 | } | ||
107 | |||
108 | public void PostInitialise() | ||
109 | { | ||
110 | } | ||
111 | |||
112 | public void Close() | ||
113 | { | ||
114 | } | ||
115 | |||
116 | public string Name | ||
117 | { | ||
118 | get { return "TextureDownloadModule"; } | ||
119 | } | ||
120 | |||
121 | public bool IsSharedModule | ||
122 | { | ||
123 | get { return false; } | ||
124 | } | ||
125 | |||
126 | public void NewClient(IClientAPI client) | ||
127 | { | ||
128 | client.OnRequestTexture += TextureRequest; | ||
129 | } | ||
130 | |||
131 | /// <summary> | ||
132 | /// Does this user have a registered texture download service? | ||
133 | /// </summary> | ||
134 | /// <param name="userID"></param> | ||
135 | /// <param name="textureService"></param> | ||
136 | /// <returns>Always returns true, since a service is created if one does not already exist</returns> | ||
137 | private bool TryGetUserTextureService( | ||
138 | IClientAPI client, out UserTextureDownloadService textureService) | ||
139 | { | ||
140 | lock (m_userTextureServices) | ||
141 | { | ||
142 | if (m_userTextureServices.TryGetValue(client.AgentId, out textureService)) | ||
143 | { | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | textureService = new UserTextureDownloadService(client, m_scene, m_queueSenders); | ||
148 | m_userTextureServices.Add(client.AgentId, textureService); | ||
149 | |||
150 | return true; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | /// <summary> | ||
155 | /// Start the process of requesting a given texture. | ||
156 | /// </summary> | ||
157 | /// <param name="sender"> </param> | ||
158 | /// <param name="e"></param> | ||
159 | public void TextureRequest(Object sender, TextureRequestArgs e) | ||
160 | { | ||
161 | IClientAPI client = (IClientAPI) sender; | ||
162 | UserTextureDownloadService textureService; | ||
163 | |||
164 | if (TryGetUserTextureService(client, out textureService)) | ||
165 | { | ||
166 | textureService.HandleTextureRequest(e); | ||
167 | } | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// Entry point for the thread dedicated to processing the texture queue. | ||
172 | /// </summary> | ||
173 | public void ProcessTextureSenders() | ||
174 | { | ||
175 | ITextureSender sender = null; | ||
176 | |||
177 | while (true) | ||
178 | { | ||
179 | sender = m_queueSenders.Dequeue(); | ||
180 | |||
181 | if (sender.Cancel) | ||
182 | { | ||
183 | TextureSent(sender); | ||
184 | |||
185 | sender.Cancel = false; | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | bool finished = sender.SendTexturePacket(); | ||
190 | if (finished) | ||
191 | { | ||
192 | TextureSent(sender); | ||
193 | } | ||
194 | else | ||
195 | { | ||
196 | m_queueSenders.Enqueue(sender); | ||
197 | } | ||
198 | } | ||
199 | |||
200 | // Make sure that any sender we currently have can get garbage collected | ||
201 | sender = null; | ||
202 | |||
203 | //m_log.InfoFormat("[TEXTURE DOWNLOAD] Texture sender queue size: {0}", m_queueSenders.Count()); | ||
204 | } | ||
205 | } | ||
206 | |||
207 | /// <summary> | ||
208 | /// Called when the texture has finished sending. | ||
209 | /// </summary> | ||
210 | /// <param name="sender"></param> | ||
211 | private void TextureSent(ITextureSender sender) | ||
212 | { | ||
213 | sender.Sending = false; | ||
214 | //m_log.DebugFormat("[TEXTURE DOWNLOAD]: Removing download stat for {0}", sender.assetID); | ||
215 | m_scene.AddPendingDownloads(-1); | ||
216 | } | ||
217 | } | ||
218 | } | ||