From 9a5e7222cef7e81fee0c992c4557ac56e9665808 Mon Sep 17 00:00:00 2001
From: John Hurliman
Date: Tue, 20 Oct 2009 10:33:23 -0700
Subject: * Removing cruft left over from the conversion to the new texture
sending and UDP code * Changing the cache modules to only initialize the
caches if they are actually enabled. Should save a bit of resources from
unused cache systems
---
.../TextureSender/Tests/TextureSenderTests.cs | 180 -----------------
.../Agent/TextureSender/TextureSender.cs | 212 ---------------------
2 files changed, 392 deletions(-)
delete mode 100644 OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs
delete mode 100644 OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs
(limited to 'OpenSim/Region/CoreModules/Agent/TextureSender')
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs
deleted file mode 100644
index efa275c..0000000
--- a/OpenSim/Region/CoreModules/Agent/TextureSender/Tests/TextureSenderTests.cs
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-using System;
-using NUnit.Framework;
-using NUnit.Framework.SyntaxHelpers;
-using OpenMetaverse;
-using OpenSim.Framework;
-using OpenSim.Tests.Common;
-using OpenSim.Tests.Common.Mock;
-
-namespace OpenSim.Region.CoreModules.Agent.TextureSender
-{
- [TestFixture]
- public class UserTextureSenderTests
- {
- public UUID uuid1;
- public UUID uuid2;
- public UUID uuid3;
- public UUID uuid4;
- public int npackets, testsize;
- public TestClient client;
- public TextureSender ts;
- public static Random random = new Random();
-
- [TestFixtureSetUp]
- public void Init()
- {
- AgentCircuitData agent = new AgentCircuitData();
- agent.AgentID = UUID.Random();
- agent.firstname = "testfirstname";
- agent.lastname = "testlastname";
- agent.SessionID = UUID.Zero;
- agent.SecureSessionID = UUID.Zero;
- agent.circuitcode = 123;
- agent.BaseFolder = UUID.Zero;
- agent.InventoryFolder = UUID.Zero;
- agent.startpos = Vector3.Zero;
- agent.CapsPath = "http://wibble.com";
- client = new TestClient(agent, null);
- ts = new TextureSender(client, 0, 0);
- testsize = random.Next(5000,15000);
- npackets = CalculateNumPackets(testsize);
- uuid1 = UUID.Random();
- uuid2 = UUID.Random();
- uuid3 = UUID.Random();
- uuid4 = UUID.Random();
- }
-
- ///
- /// Test sending package
- ///
- [Test]
- public void T010_SendPkg()
- {
- TestHelper.InMethod();
- // Normal sending
- AssetBase abase = new AssetBase(uuid1, "asset one");
- byte[] abdata = new byte[testsize];
- random.NextBytes(abdata);
- abase.Data = abdata;
- bool isdone = false;
- ts.TextureReceived(abase);
- for (int i = 0; i < npackets; i++) {
- isdone = ts.SendTexturePacket();
- }
-
- Assert.That(isdone,Is.False);
- isdone = ts.SendTexturePacket();
- Assert.That(isdone,Is.True);
- }
-
- [Test]
- public void T011_UpdateReq()
- {
- TestHelper.InMethod();
- // Test packet number start
- AssetBase abase = new AssetBase(uuid2, "asset two");
- byte[] abdata = new byte[testsize];
- random.NextBytes(abdata);
- abase.Data = abdata;
-
- bool isdone = false;
- ts.TextureReceived(abase);
- ts.UpdateRequest(0,3);
-
- for (int i = 0; i < npackets-3; i++) {
- isdone = ts.SendTexturePacket();
- }
-
- Assert.That(isdone,Is.False);
- isdone = ts.SendTexturePacket();
- Assert.That(isdone,Is.True);
-
- // Test discard level
- abase = new AssetBase(uuid3, "asset three");
- abdata = new byte[testsize];
- random.NextBytes(abdata);
- abase.Data = abdata;
- isdone = false;
- ts.TextureReceived(abase);
- ts.UpdateRequest(-1,0);
-
- Assert.That(ts.SendTexturePacket(),Is.True);
-
- abase = new AssetBase(uuid4, "asset four");
- abdata = new byte[testsize];
- random.NextBytes(abdata);
- abase.Data = abdata;
- isdone = false;
- ts.TextureReceived(abase);
- ts.UpdateRequest(0,5);
-
- for (int i = 0; i < npackets-5; i++) {
- isdone = ts.SendTexturePacket();
- }
- Assert.That(isdone,Is.False);
- isdone = ts.SendTexturePacket();
- Assert.That(isdone,Is.True);
- }
-
- [Test]
- public void T999_FinishStatus()
- {
- TestHelper.InMethod();
- // Of the 4 assets "sent", only 2 sent the first part.
- Assert.That(client.sentdatapkt.Count,Is.EqualTo(2));
-
- // Sum of all packets sent:
- int totalpkts = (npackets) + (npackets - 2) + (npackets - 4);
- Assert.That(client.sentpktpkt.Count,Is.EqualTo(totalpkts));
- }
-
- ///
- /// Calculate the number of packets that will be required to send the texture loaded into this sender
- /// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
- /// Borrowed from TextureSender.cs
- ///
- ///
- ///
- private int CalculateNumPackets(int length)
- {
- int numPackets = 0;
-
- if (length > 600)
- {
- //over 600 bytes so split up file
- int restData = (length - 600);
- int restPackets = ((restData + 999) / 1000);
- numPackets = restPackets;
- }
-
- return numPackets;
- }
- }
-}
diff --git a/OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs b/OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs
deleted file mode 100644
index 62c5a32..0000000
--- a/OpenSim/Region/CoreModules/Agent/TextureSender/TextureSender.cs
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-using System;
-using System.Reflection;
-using log4net;
-using OpenSim.Framework;
-using OpenSim.Region.Framework.Interfaces;
-
-namespace OpenSim.Region.CoreModules.Agent.TextureSender
-{
- ///
- /// A TextureSender handles the process of receiving a texture requested by the client from the
- /// AssetCache, and then sending that texture back to the client.
- ///
- public class TextureSender : ITextureSender
- {
- private static readonly ILog m_log
- = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
-
- ///
- /// Records the number of times texture send has been called.
- ///
- public int counter = 0;
-
- public bool ImageLoaded = false;
-
- ///
- /// Holds the texture asset to send.
- ///
- private AssetBase m_asset;
-
- //public UUID assetID { get { return m_asset.FullID; } }
-
- // private bool m_cancel = false;
-
- // See ITextureSender
-
- // private bool m_sending = false;
-
- ///
- /// This is actually the number of extra packets required to send the texture data! We always assume
- /// at least one is required.
- ///
- private int NumPackets = 0;
-
- ///
- /// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts
- /// at the 600th byte (0th indexed).
- ///
- private int PacketCounter = 0;
-
- private int RequestedDiscardLevel = -1;
- private IClientAPI RequestUser;
- private uint StartPacketNumber = 0;
-
- public TextureSender(IClientAPI client, int discardLevel, uint packetNumber)
- {
- RequestUser = client;
- RequestedDiscardLevel = discardLevel;
- StartPacketNumber = packetNumber;
- }
-
- #region ITextureSender Members
-
- public bool Cancel
- {
- get { return false; }
- set
- {
- // m_cancel = value;
- }
- }
-
- public bool Sending
- {
- get { return false; }
- set
- {
- // m_sending = value;
- }
- }
-
- // See ITextureSender
- public void UpdateRequest(int discardLevel, uint packetNumber)
- {
- RequestedDiscardLevel = discardLevel;
- StartPacketNumber = packetNumber;
- PacketCounter = (int)StartPacketNumber;
- }
-
- // See ITextureSender
- public bool SendTexturePacket()
- {
- //m_log.DebugFormat("[TEXTURE SENDER]: Sending packet for {0}", m_asset.FullID);
-
- SendPacket();
- counter++;
- if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) ||
- ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets / (RequestedDiscardLevel + 1)))))
- {
- return true;
- }
- return false;
- }
-
- #endregion
-
- ///
- /// Load up the texture data to send.
- ///
- ///
- public void TextureReceived(AssetBase asset)
- {
- m_asset = asset;
- NumPackets = CalculateNumPackets(asset.Data.Length);
- PacketCounter = (int)StartPacketNumber;
- ImageLoaded = true;
- }
-
- ///
- /// Sends a texture packet to the client.
- ///
- private void SendPacket()
- {
- if (PacketCounter <= NumPackets)
- {
- if (PacketCounter == 0)
- {
- if (NumPackets == 0)
- {
- RequestUser.SendImageFirstPart(1, m_asset.FullID, (uint)m_asset.Data.Length, m_asset.Data, 2);
- PacketCounter++;
- }
- else
- {
- byte[] ImageData1 = new byte[600];
- Array.Copy(m_asset.Data, 0, ImageData1, 0, 600);
-
- RequestUser.SendImageFirstPart(
- (ushort)(NumPackets), m_asset.FullID, (uint)m_asset.Data.Length, ImageData1, 2);
- PacketCounter++;
- }
- }
- else
- {
- int size = m_asset.Data.Length - 600 - (1000 * (PacketCounter - 1));
- if (size > 1000) size = 1000;
- byte[] imageData = new byte[size];
- try
- {
- Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), imageData, 0, size);
- }
- catch (ArgumentOutOfRangeException)
- {
- m_log.Error("[TEXTURE SENDER]: Unable to separate texture into multiple packets: Array bounds failure on asset:" +
- m_asset.ID);
- return;
- }
-
- RequestUser.SendImageNextPart((ushort)PacketCounter, m_asset.FullID, imageData);
- PacketCounter++;
- }
- }
- }
-
- ///
- /// Calculate the number of packets that will be required to send the texture loaded into this sender
- /// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
- ///
- ///
- ///
- private int CalculateNumPackets(int length)
- {
- int numPackets = 0;
-
- if (length > 600)
- {
- //over 600 bytes so split up file
- int restData = (length - 600);
- int restPackets = ((restData + 999) / 1000);
- numPackets = restPackets;
- }
-
- return numPackets;
- }
- }
-}
--
cgit v1.1