aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
diff options
context:
space:
mode:
authorJeff Ames2008-05-01 14:31:30 +0000
committerJeff Ames2008-05-01 14:31:30 +0000
commitd51ce47b2d7635b17f3dd429158e8f59b78b83aa (patch)
treed3595bd5194199184059aa398b91a51dc6c799cf /OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
parent* Looks like I had the bamboo build right in the first place - it was just th... (diff)
downloadopensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.zip
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.gz
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.bz2
opensim-SC-d51ce47b2d7635b17f3dd429158e8f59b78b83aa.tar.xz
Update svn properties. Minor formatting cleanup.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs454
1 files changed, 227 insertions, 227 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
index c0b7380..48db51b 100644
--- a/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/AssetDownload/AssetDownloadModule.cs
@@ -1,228 +1,228 @@
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
28using System.Collections.Generic; 28using System.Collections.Generic;
29using libsecondlife; 29using libsecondlife;
30using libsecondlife.Packets; 30using libsecondlife.Packets;
31using Nini.Config; 31using Nini.Config;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 34using OpenSim.Region.Environment.Scenes;
35 35
36namespace OpenSim.Region.Environment.Modules.Agent.AssetDownload 36namespace OpenSim.Region.Environment.Modules.Agent.AssetDownload
37{ 37{
38 public class AssetDownloadModule : IRegionModule 38 public class AssetDownloadModule : IRegionModule
39 { 39 {
40 /// <summary> 40 /// <summary>
41 /// Asset requests with data which are ready to be sent back to requesters. This includes textures. 41 /// Asset requests with data which are ready to be sent back to requesters. This includes textures.
42 /// </summary> 42 /// </summary>
43 private List<AssetRequest> AssetRequests; 43 private List<AssetRequest> AssetRequests;
44 44
45 private Scene m_scene; 45 private Scene m_scene;
46 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>(); 46 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
47 47
48 /// 48 ///
49 /// Assets requests (for each user) which are waiting for asset server data. This includes texture requests 49 /// Assets requests (for each user) which are waiting for asset server data. This includes texture requests
50 /// </summary> 50 /// </summary>
51 private Dictionary<LLUUID, Dictionary<LLUUID, AssetRequest>> RequestedAssets; 51 private Dictionary<LLUUID, Dictionary<LLUUID, AssetRequest>> RequestedAssets;
52 52
53 public AssetDownloadModule() 53 public AssetDownloadModule()
54 { 54 {
55 RequestedAssets = new Dictionary<LLUUID, Dictionary<LLUUID, AssetRequest>>(); 55 RequestedAssets = new Dictionary<LLUUID, Dictionary<LLUUID, AssetRequest>>();
56 AssetRequests = new List<AssetRequest>(); 56 AssetRequests = new List<AssetRequest>();
57 } 57 }
58 58
59 #region IRegionModule Members 59 #region IRegionModule Members
60 60
61 public void Initialise(Scene scene, IConfigSource config) 61 public void Initialise(Scene scene, IConfigSource config)
62 { 62 {
63 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) 63 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID))
64 { 64 {
65 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene); 65 RegisteredScenes.Add(scene.RegionInfo.RegionID, scene);
66 // scene.EventManager.OnNewClient += NewClient; 66 // scene.EventManager.OnNewClient += NewClient;
67 } 67 }
68 68
69 if (m_scene == null) 69 if (m_scene == null)
70 { 70 {
71 m_scene = scene; 71 m_scene = scene;
72 // m_thread = new Thread(new ThreadStart(RunAssetQueue)); 72 // m_thread = new Thread(new ThreadStart(RunAssetQueue));
73 // m_thread.Name = "AssetDownloadQueueThread"; 73 // m_thread.Name = "AssetDownloadQueueThread";
74 // m_thread.IsBackground = true; 74 // m_thread.IsBackground = true;
75 // m_thread.Start(); 75 // m_thread.Start();
76 // OpenSim.Framework.ThreadTracker.Add(m_thread); 76 // OpenSim.Framework.ThreadTracker.Add(m_thread);
77 } 77 }
78 } 78 }
79 79
80 public void PostInitialise() 80 public void PostInitialise()
81 { 81 {
82 } 82 }
83 83
84 public void Close() 84 public void Close()
85 { 85 {
86 } 86 }
87 87
88 public string Name 88 public string Name
89 { 89 {
90 get { return "AssetDownloadModule"; } 90 get { return "AssetDownloadModule"; }
91 } 91 }
92 92
93 public bool IsSharedModule 93 public bool IsSharedModule
94 { 94 {
95 get { return true; } 95 get { return true; }
96 } 96 }
97 97
98 #endregion 98 #endregion
99 99
100 public void NewClient(IClientAPI client) 100 public void NewClient(IClientAPI client)
101 { 101 {
102 // client.OnRequestAsset += AddAssetRequest; 102 // client.OnRequestAsset += AddAssetRequest;
103 } 103 }
104 104
105 /// <summary> 105 /// <summary>
106 /// Make an asset request the result of which will be packeted up and sent directly back to the client. 106 /// Make an asset request the result of which will be packeted up and sent directly back to the client.
107 /// </summary> 107 /// </summary>
108 /// <param name="userInfo"></param> 108 /// <param name="userInfo"></param>
109 /// <param name="transferRequest"></param> 109 /// <param name="transferRequest"></param>
110 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest) 110 public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
111 { 111 {
112 LLUUID requestID = null; 112 LLUUID requestID = null;
113 byte source = 2; 113 byte source = 2;
114 if (transferRequest.TransferInfo.SourceType == 2) 114 if (transferRequest.TransferInfo.SourceType == 2)
115 { 115 {
116 //direct asset request 116 //direct asset request
117 requestID = new LLUUID(transferRequest.TransferInfo.Params, 0); 117 requestID = new LLUUID(transferRequest.TransferInfo.Params, 0);
118 } 118 }
119 else if (transferRequest.TransferInfo.SourceType == 3) 119 else if (transferRequest.TransferInfo.SourceType == 3)
120 { 120 {
121 //inventory asset request 121 //inventory asset request
122 requestID = new LLUUID(transferRequest.TransferInfo.Params, 80); 122 requestID = new LLUUID(transferRequest.TransferInfo.Params, 80);
123 source = 3; 123 source = 3;
124 //Console.WriteLine("asset request " + requestID); 124 //Console.WriteLine("asset request " + requestID);
125 } 125 }
126 126
127 //not found asset 127 //not found asset
128 // so request from asset server 128 // so request from asset server
129 Dictionary<LLUUID, AssetRequest> userRequests = null; 129 Dictionary<LLUUID, AssetRequest> userRequests = null;
130 if (RequestedAssets.TryGetValue(userInfo.AgentId, out userRequests)) 130 if (RequestedAssets.TryGetValue(userInfo.AgentId, out userRequests))
131 { 131 {
132 if (!userRequests.ContainsKey(requestID)) 132 if (!userRequests.ContainsKey(requestID))
133 { 133 {
134 AssetRequest request = new AssetRequest(); 134 AssetRequest request = new AssetRequest();
135 request.RequestUser = userInfo; 135 request.RequestUser = userInfo;
136 request.RequestAssetID = requestID; 136 request.RequestAssetID = requestID;
137 request.TransferRequestID = transferRequest.TransferInfo.TransferID; 137 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
138 request.AssetRequestSource = source; 138 request.AssetRequestSource = source;
139 request.Params = transferRequest.TransferInfo.Params; 139 request.Params = transferRequest.TransferInfo.Params;
140 userRequests[requestID] = request; 140 userRequests[requestID] = request;
141 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false); 141 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false);
142 } 142 }
143 } 143 }
144 else 144 else
145 { 145 {
146 userRequests = new Dictionary<LLUUID, AssetRequest>(); 146 userRequests = new Dictionary<LLUUID, AssetRequest>();
147 AssetRequest request = new AssetRequest(); 147 AssetRequest request = new AssetRequest();
148 request.RequestUser = userInfo; 148 request.RequestUser = userInfo;
149 request.RequestAssetID = requestID; 149 request.RequestAssetID = requestID;
150 request.TransferRequestID = transferRequest.TransferInfo.TransferID; 150 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
151 request.AssetRequestSource = source; 151 request.AssetRequestSource = source;
152 request.Params = transferRequest.TransferInfo.Params; 152 request.Params = transferRequest.TransferInfo.Params;
153 userRequests.Add(requestID, request); 153 userRequests.Add(requestID, request);
154 RequestedAssets[userInfo.AgentId] = userRequests; 154 RequestedAssets[userInfo.AgentId] = userRequests;
155 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false); 155 m_scene.AssetCache.GetAsset(requestID, AssetCallback, false);
156 } 156 }
157 } 157 }
158 158
159 public void AssetCallback(LLUUID assetID, AssetBase asset) 159 public void AssetCallback(LLUUID assetID, AssetBase asset)
160 { 160 {
161 if (asset != null) 161 if (asset != null)
162 { 162 {
163 foreach (Dictionary<LLUUID, AssetRequest> userRequests in RequestedAssets.Values) 163 foreach (Dictionary<LLUUID, AssetRequest> userRequests in RequestedAssets.Values)
164 { 164 {
165 if (userRequests.ContainsKey(assetID)) 165 if (userRequests.ContainsKey(assetID))
166 { 166 {
167 AssetRequest req = userRequests[assetID]; 167 AssetRequest req = userRequests[assetID];
168 if (req != null) 168 if (req != null)
169 { 169 {
170 req.AssetInf = asset; 170 req.AssetInf = asset;
171 req.NumPackets = CalculateNumPackets(asset.Data); 171 req.NumPackets = CalculateNumPackets(asset.Data);
172 172
173 userRequests.Remove(assetID); 173 userRequests.Remove(assetID);
174 AssetRequests.Add(req); 174 AssetRequests.Add(req);
175 } 175 }
176 } 176 }
177 } 177 }
178 } 178 }
179 } 179 }
180 180
181 /// <summary> 181 /// <summary>
182 /// Calculate the number of packets required to send the asset to the client. 182 /// Calculate the number of packets required to send the asset to the client.
183 /// </summary> 183 /// </summary>
184 /// <param name="data"></param> 184 /// <param name="data"></param>
185 /// <returns></returns> 185 /// <returns></returns>
186 private int CalculateNumPackets(byte[] data) 186 private int CalculateNumPackets(byte[] data)
187 { 187 {
188 const uint m_maxPacketSize = 600; 188 const uint m_maxPacketSize = 600;
189 int numPackets = 1; 189 int numPackets = 1;
190 190
191 if (data.LongLength > m_maxPacketSize) 191 if (data.LongLength > m_maxPacketSize)
192 { 192 {
193 // over max number of bytes so split up file 193 // over max number of bytes so split up file
194 long restData = data.LongLength - m_maxPacketSize; 194 long restData = data.LongLength - m_maxPacketSize;
195 int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize); 195 int restPackets = (int) ((restData + m_maxPacketSize - 1) / m_maxPacketSize);
196 numPackets += restPackets; 196 numPackets += restPackets;
197 } 197 }
198 198
199 return numPackets; 199 return numPackets;
200 } 200 }
201 201
202 #region Nested type: AssetRequest 202 #region Nested type: AssetRequest
203 203
204 public class AssetRequest 204 public class AssetRequest
205 { 205 {
206 public AssetBase AssetInf; 206 public AssetBase AssetInf;
207 public byte AssetRequestSource = 2; 207 public byte AssetRequestSource = 2;
208 public long DataPointer = 0; 208 public long DataPointer = 0;
209 public int DiscardLevel = -1; 209 public int DiscardLevel = -1;
210 public AssetBase ImageInfo; 210 public AssetBase ImageInfo;
211 public bool IsTextureRequest; 211 public bool IsTextureRequest;
212 public int NumPackets = 0; 212 public int NumPackets = 0;
213 public int PacketCounter = 0; 213 public int PacketCounter = 0;
214 public byte[] Params = null; 214 public byte[] Params = null;
215 public LLUUID RequestAssetID; 215 public LLUUID RequestAssetID;
216 public IClientAPI RequestUser; 216 public IClientAPI RequestUser;
217 public LLUUID TransferRequestID; 217 public LLUUID TransferRequestID;
218 //public bool AssetInCache; 218 //public bool AssetInCache;
219 //public int TimeRequested; 219 //public int TimeRequested;
220 220
221 public AssetRequest() 221 public AssetRequest()
222 { 222 {
223 } 223 }
224 } 224 }
225 225
226 #endregion 226 #endregion
227 } 227 }
228} \ No newline at end of file 228} \ No newline at end of file