diff options
author | lbsa71 | 2008-01-03 13:40:38 +0000 |
---|---|---|
committer | lbsa71 | 2008-01-03 13:40:38 +0000 |
commit | 1d098aa84c8c82a4e62ebbaa20809a0efd3e8774 (patch) | |
tree | 515865fcaf2f2d80fdfe9ac9046865ebb2979dd7 /OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs | |
parent | * Added lock to Contains to avoid enumeration exceptions (diff) | |
download | opensim-SC-1d098aa84c8c82a4e62ebbaa20809a0efd3e8774.zip opensim-SC-1d098aa84c8c82a4e62ebbaa20809a0efd3e8774.tar.gz opensim-SC-1d098aa84c8c82a4e62ebbaa20809a0efd3e8774.tar.bz2 opensim-SC-1d098aa84c8c82a4e62ebbaa20809a0efd3e8774.tar.xz |
* Some work on TextureDownloadModule
* fixed Cancel bug
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs new file mode 100644 index 0000000..6ee43e2 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/UserTextureDownloadService.cs | |||
@@ -0,0 +1,98 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using libsecondlife; | ||
4 | using OpenSim.Framework; | ||
5 | using OpenSim.Framework.Console; | ||
6 | using OpenSim.Region.Environment.Scenes; | ||
7 | |||
8 | namespace OpenSim.Region.Environment.Modules | ||
9 | { | ||
10 | public class UserTextureDownloadService | ||
11 | { | ||
12 | private readonly Dictionary<LLUUID, TextureSender> m_textureSenders = new Dictionary<LLUUID, TextureSender>(); | ||
13 | private readonly BlockingQueue<TextureSender> m_sharedSendersQueue; | ||
14 | private readonly Scene m_scene; | ||
15 | |||
16 | public UserTextureDownloadService(Scene scene, BlockingQueue<TextureSender> sharedQueue) | ||
17 | { | ||
18 | m_scene = scene; | ||
19 | m_sharedSendersQueue = sharedQueue; | ||
20 | } | ||
21 | |||
22 | public void HandleTextureRequest(IClientAPI client, TextureRequestArgs e) | ||
23 | { | ||
24 | TextureSender textureSender; | ||
25 | |||
26 | //TODO: should be working out the data size/ number of packets to be sent for each discard level | ||
27 | if ((e.DiscardLevel >= 0) || (e.Priority != 0)) | ||
28 | { | ||
29 | lock (m_textureSenders) | ||
30 | { | ||
31 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
32 | { | ||
33 | textureSender.UpdateRequest(e.DiscardLevel, e.PacketNumber); | ||
34 | |||
35 | if ((textureSender.ImageLoaded) && | ||
36 | (textureSender.Sending == false)) | ||
37 | { | ||
38 | EnqueueTextureSender(textureSender); | ||
39 | } | ||
40 | } | ||
41 | else | ||
42 | { | ||
43 | TextureSender requestHandler = | ||
44 | new TextureSender(client, e.RequestedAssetID, e.DiscardLevel, e.PacketNumber); | ||
45 | m_textureSenders.Add(e.RequestedAssetID, requestHandler); | ||
46 | m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | lock (m_textureSenders) | ||
53 | { | ||
54 | if (m_textureSenders.TryGetValue(e.RequestedAssetID, out textureSender)) | ||
55 | { | ||
56 | textureSender.Cancel = true; | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | public void TextureCallback(LLUUID textureID, AssetBase asset) | ||
63 | { | ||
64 | lock (m_textureSenders) | ||
65 | { | ||
66 | TextureSender textureSender; | ||
67 | |||
68 | if (m_textureSenders.TryGetValue(textureID, out textureSender)) | ||
69 | { | ||
70 | if (!textureSender.ImageLoaded) | ||
71 | { | ||
72 | textureSender.TextureReceived(asset); | ||
73 | |||
74 | EnqueueTextureSender(textureSender); | ||
75 | } | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | throw new Exception("Got a texture with no sender object to handle it, this shouldn't happen"); | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | private void EnqueueTextureSender(TextureSender textureSender) | ||
85 | { | ||
86 | MainLog.Instance.Debug( "TEXTUREDOWNLOAD", "Start: ["+textureSender.RequestedAssetID+"] to ["+textureSender.RequestUser.Name+"]"); | ||
87 | |||
88 | textureSender.Cancel = false; | ||
89 | textureSender.Sending = true; | ||
90 | textureSender.counter = 0; | ||
91 | |||
92 | if (!m_sharedSendersQueue.Contains(textureSender)) | ||
93 | { | ||
94 | m_sharedSendersQueue.Enqueue(textureSender); | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | } \ No newline at end of file | ||