diff options
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetCache.cs')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/AssetCache.cs | 168 |
1 files changed, 91 insertions, 77 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index a950f51..4c18744 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs | |||
@@ -42,6 +42,8 @@ namespace OpenSim.Framework.Communications.Cache | |||
42 | { | 42 | { |
43 | public delegate void DownloadComplete(AssetCache.TextureSender sender); | 43 | public delegate void DownloadComplete(AssetCache.TextureSender sender); |
44 | 44 | ||
45 | public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset); | ||
46 | |||
45 | /// <summary> | 47 | /// <summary> |
46 | /// Manages local cache of assets and their sending to viewers. | 48 | /// Manages local cache of assets and their sending to viewers. |
47 | /// </summary> | 49 | /// </summary> |
@@ -63,6 +65,8 @@ namespace OpenSim.Framework.Communications.Cache | |||
63 | 65 | ||
64 | private Dictionary<LLUUID, Dictionary<LLUUID, int>> TimesTextureSent = new Dictionary<LLUUID, Dictionary<LLUUID, int>>(); | 66 | private Dictionary<LLUUID, Dictionary<LLUUID, int>> TimesTextureSent = new Dictionary<LLUUID, Dictionary<LLUUID, int>>(); |
65 | 67 | ||
68 | public Dictionary<LLUUID, AssetRequestsList> RequestLists = new Dictionary<LLUUID, AssetRequestsList>(); | ||
69 | |||
66 | private IAssetServer _assetServer; | 70 | private IAssetServer _assetServer; |
67 | private Thread _assetCacheThread; | 71 | private Thread _assetCacheThread; |
68 | 72 | ||
@@ -123,6 +127,46 @@ namespace OpenSim.Framework.Communications.Cache | |||
123 | return asset; | 127 | return asset; |
124 | } | 128 | } |
125 | 129 | ||
130 | public void GetAsset(LLUUID assetID, AssetRequestCallback callback) | ||
131 | { | ||
132 | AssetBase asset = null; | ||
133 | if (this.Textures.ContainsKey(assetID)) | ||
134 | { | ||
135 | asset = this.Textures[assetID]; | ||
136 | } | ||
137 | else if (this.Assets.ContainsKey(assetID)) | ||
138 | { | ||
139 | asset = this.Assets[assetID]; | ||
140 | } | ||
141 | |||
142 | if (asset != null) | ||
143 | { | ||
144 | callback(assetID, asset); | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | NewAssetRequest req = new NewAssetRequest(assetID, callback); | ||
149 | if (this.RequestLists.ContainsKey(assetID)) | ||
150 | { | ||
151 | lock (RequestLists) | ||
152 | { | ||
153 | RequestLists[assetID].Requests.Add(req); | ||
154 | } | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | AssetRequestsList reqList = new AssetRequestsList(assetID); | ||
159 | reqList.Requests.Add(req); | ||
160 | lock (RequestLists) | ||
161 | { | ||
162 | RequestLists.Add(assetID, reqList); | ||
163 | } | ||
164 | } | ||
165 | this._assetServer.FetchAsset(assetID, false); | ||
166 | } | ||
167 | } | ||
168 | |||
169 | |||
126 | public AssetBase GetAsset(LLUUID assetID, bool isTexture) | 170 | public AssetBase GetAsset(LLUUID assetID, bool isTexture) |
127 | { | 171 | { |
128 | AssetBase asset = GetAsset(assetID); | 172 | AssetBase asset = GetAsset(assetID); |
@@ -135,7 +179,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
135 | 179 | ||
136 | public void AddAsset(AssetBase asset) | 180 | public void AddAsset(AssetBase asset) |
137 | { | 181 | { |
138 | // System.Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated()); | 182 | //System.Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated()); |
139 | if (asset.Type == 0) | 183 | if (asset.Type == 0) |
140 | { | 184 | { |
141 | //Console.WriteLine("which is a texture"); | 185 | //Console.WriteLine("which is a texture"); |
@@ -207,26 +251,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
207 | while (true) | 251 | while (true) |
208 | { | 252 | { |
209 | TextureSender sender = this.QueueTextures.Dequeue(); | 253 | TextureSender sender = this.QueueTextures.Dequeue(); |
210 | /* if (TimesTextureSent.ContainsKey(sender.request.RequestUser.AgentId)) | 254 | |
211 | { | ||
212 | if (TimesTextureSent[sender.request.RequestUser.AgentId].ContainsKey(sender.request.ImageInfo.FullID)) | ||
213 | { | ||
214 | TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID]++; | ||
215 | } | ||
216 | else | ||
217 | { | ||
218 | TimesTextureSent[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID, 1); | ||
219 | } | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | Dictionary<LLUUID, int> UsersSent = new Dictionary<LLUUID,int>(); | ||
224 | TimesTextureSent.Add(sender.request.RequestUser.AgentId, UsersSent ); | ||
225 | UsersSent.Add(sender.request.ImageInfo.FullID, 1); | ||
226 | |||
227 | } | ||
228 | if (TimesTextureSent[sender.request.RequestUser.AgentId][sender.request.ImageInfo.FullID] < 1000) | ||
229 | {*/ | ||
230 | bool finished = sender.SendTexture(); | 255 | bool finished = sender.SendTexture(); |
231 | if (finished) | 256 | if (finished) |
232 | { | 257 | { |
@@ -237,11 +262,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
237 | // Console.WriteLine("readding texture"); | 262 | // Console.WriteLine("readding texture"); |
238 | this.QueueTextures.Enqueue(sender); | 263 | this.QueueTextures.Enqueue(sender); |
239 | } | 264 | } |
240 | /* } | 265 | |
241 | else | ||
242 | { | ||
243 | this.TextureSent(sender); | ||
244 | }*/ | ||
245 | } | 266 | } |
246 | } | 267 | } |
247 | 268 | ||
@@ -317,6 +338,21 @@ namespace OpenSim.Framework.Communications.Cache | |||
317 | } | 338 | } |
318 | } | 339 | } |
319 | } | 340 | } |
341 | |||
342 | if (RequestLists.ContainsKey(asset.FullID)) | ||
343 | { | ||
344 | AssetRequestsList reqList = RequestLists[asset.FullID]; | ||
345 | foreach (NewAssetRequest req in reqList.Requests) | ||
346 | { | ||
347 | req.Callback(asset.FullID, asset); | ||
348 | } | ||
349 | |||
350 | lock (RequestLists) | ||
351 | { | ||
352 | RequestLists.Remove(asset.FullID); | ||
353 | reqList.Requests.Clear(); | ||
354 | } | ||
355 | } | ||
320 | } | 356 | } |
321 | } | 357 | } |
322 | 358 | ||
@@ -508,17 +544,6 @@ namespace OpenSim.Framework.Communications.Cache | |||
508 | } | 544 | } |
509 | 545 | ||
510 | } | 546 | } |
511 | |||
512 | public AssetInfo CloneAsset(LLUUID newOwner, AssetInfo sourceAsset) | ||
513 | { | ||
514 | AssetInfo newAsset = new AssetInfo(); | ||
515 | newAsset.Data = new byte[sourceAsset.Data.Length]; | ||
516 | Array.Copy(sourceAsset.Data, newAsset.Data, sourceAsset.Data.Length); | ||
517 | newAsset.FullID = LLUUID.Random(); | ||
518 | newAsset.Type = sourceAsset.Type; | ||
519 | newAsset.InvType = sourceAsset.InvType; | ||
520 | return (newAsset); | ||
521 | } | ||
522 | #endregion | 547 | #endregion |
523 | 548 | ||
524 | #region Textures | 549 | #region Textures |
@@ -529,7 +554,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
529 | /// <param name="imageID"></param> | 554 | /// <param name="imageID"></param> |
530 | public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber, int discard) | 555 | public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber, int discard) |
531 | { | 556 | { |
532 | //Console.WriteLine("texture request for " + imageID.ToStringHyphenated() + " packetnumber= " + packetNumber); | 557 | // System.Console.WriteLine("texture request for " + imageID.ToStringHyphenated() + " packetnumber= " + packetNumber); |
533 | //check to see if texture is in local cache, if not request from asset server | 558 | //check to see if texture is in local cache, if not request from asset server |
534 | if (!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId)) | 559 | if (!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId)) |
535 | { | 560 | { |
@@ -540,6 +565,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
540 | //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them"); | 565 | //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them"); |
541 | return; | 566 | return; |
542 | }*/ | 567 | }*/ |
568 | |||
543 | if (!this.Textures.ContainsKey(imageID)) | 569 | if (!this.Textures.ContainsKey(imageID)) |
544 | { | 570 | { |
545 | if (!this.RequestedTextures.ContainsKey(imageID)) | 571 | if (!this.RequestedTextures.ContainsKey(imageID)) |
@@ -556,7 +582,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
556 | return; | 582 | return; |
557 | } | 583 | } |
558 | 584 | ||
559 | //Console.WriteLine("texture already in cache"); | 585 | // System.Console.WriteLine("texture already in cache"); |
560 | TextureImage imag = this.Textures[imageID]; | 586 | TextureImage imag = this.Textures[imageID]; |
561 | AssetRequest req = new AssetRequest(); | 587 | AssetRequest req = new AssetRequest(); |
562 | req.RequestUser = userInfo; | 588 | req.RequestUser = userInfo; |
@@ -583,46 +609,9 @@ namespace OpenSim.Framework.Communications.Cache | |||
583 | this.TextureRequests.Add(req); | 609 | this.TextureRequests.Add(req); |
584 | } | 610 | } |
585 | 611 | ||
586 | public TextureImage CloneImage(LLUUID newOwner, TextureImage source) | 612 | |
587 | { | ||
588 | TextureImage newImage = new TextureImage(); | ||
589 | newImage.Data = new byte[source.Data.Length]; | ||
590 | Array.Copy(source.Data, newImage.Data, source.Data.Length); | ||
591 | //newImage.filename = source.filename; | ||
592 | newImage.FullID = LLUUID.Random(); | ||
593 | newImage.Name = source.Name; | ||
594 | return (newImage); | ||
595 | } | ||
596 | #endregion | 613 | #endregion |
597 | 614 | ||
598 | private IAssetServer LoadAssetDll(string dllName) | ||
599 | { | ||
600 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||
601 | IAssetServer server = null; | ||
602 | |||
603 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
604 | { | ||
605 | if (pluginType.IsPublic) | ||
606 | { | ||
607 | if (!pluginType.IsAbstract) | ||
608 | { | ||
609 | Type typeInterface = pluginType.GetInterface("IAssetPlugin", true); | ||
610 | |||
611 | if (typeInterface != null) | ||
612 | { | ||
613 | IAssetPlugin plug = (IAssetPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
614 | server = plug.GetAssetServer(); | ||
615 | break; | ||
616 | } | ||
617 | |||
618 | typeInterface = null; | ||
619 | } | ||
620 | } | ||
621 | } | ||
622 | pluginAssembly = null; | ||
623 | return server; | ||
624 | } | ||
625 | |||
626 | public class AssetRequest | 615 | public class AssetRequest |
627 | { | 616 | { |
628 | public IClientAPI RequestUser; | 617 | public IClientAPI RequestUser; |
@@ -779,4 +768,29 @@ namespace OpenSim.Framework.Communications.Cache | |||
779 | } | 768 | } |
780 | } | 769 | } |
781 | } | 770 | } |
771 | |||
772 | public class AssetRequestsList | ||
773 | { | ||
774 | public LLUUID AssetID; | ||
775 | public List<NewAssetRequest> Requests = new List<NewAssetRequest>(); | ||
776 | |||
777 | public AssetRequestsList(LLUUID assetID) | ||
778 | { | ||
779 | AssetID = assetID; | ||
780 | } | ||
781 | } | ||
782 | |||
783 | public class NewAssetRequest | ||
784 | { | ||
785 | public LLUUID AssetID; | ||
786 | public AssetRequestCallback Callback; | ||
787 | |||
788 | public NewAssetRequest(LLUUID assetID, AssetRequestCallback callback) | ||
789 | { | ||
790 | AssetID = assetID; | ||
791 | Callback = callback; | ||
792 | } | ||
793 | |||
794 | |||
795 | } | ||
782 | } | 796 | } |