From e3927d28688ea0c9718cafec286c1c8e15d54f6f Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 31 Oct 2012 00:31:18 +0000 Subject: [PATCH] Make "show object part" command correctly display script status. Uses new IEntityInventory.TryGetScriptInstanceRunning() Makes it clearer that TaskInventoryItem.ScriptRunning cannot be used as it is temporary and not updated. --- OpenSim/Framework/TaskInventoryDictionary.cs | 4 +- OpenSim/Framework/TaskInventoryItem.cs | 19 +++---- .../Avatar/Attachments/AttachmentsModule.cs | 6 +-- .../Objects/Commands/ObjectCommandsModule.cs | 8 ++- .../Framework/Interfaces/IEntityInventory.cs | 13 +++++ .../Scenes/SceneObjectPartInventory.cs | 52 +++++++++++++------ .../ScriptEngine/XEngine/Tests/XEngineTest.cs | 10 +++- 7 files changed, 77 insertions(+), 35 deletions(-) diff --git a/OpenSim/Framework/TaskInventoryDictionary.cs b/OpenSim/Framework/TaskInventoryDictionary.cs index 421bd5ddcf..8af2c41866 100644 --- a/OpenSim/Framework/TaskInventoryDictionary.cs +++ b/OpenSim/Framework/TaskInventoryDictionary.cs @@ -35,10 +35,12 @@ using OpenMetaverse; namespace OpenSim.Framework { /// - /// A dictionary for task inventory. + /// A dictionary containing task inventory items. Indexed by item UUID. /// + /// /// This class is not thread safe. Callers must synchronize on Dictionary methods or Clone() this object before /// iterating over it. + /// public class TaskInventoryDictionary : Dictionary, ICloneable, IXmlSerializable { diff --git a/OpenSim/Framework/TaskInventoryItem.cs b/OpenSim/Framework/TaskInventoryItem.cs index 3b40381c61..a06f8e73ef 100644 --- a/OpenSim/Framework/TaskInventoryItem.cs +++ b/OpenSim/Framework/TaskInventoryItem.cs @@ -73,9 +73,6 @@ namespace OpenSim.Framework private bool _ownerChanged = false; - // This used ONLY during copy. It can't be relied on at other times! - private bool _scriptRunning = true; - public UUID AssetID { get { return _assetID; @@ -353,14 +350,13 @@ namespace OpenSim.Framework } } - public bool ScriptRunning { - get { - return _scriptRunning; - } - set { - _scriptRunning = value; - } - } + /// + /// This used ONLY during copy. It can't be relied on at other times! + /// + /// + /// For true script running status, use IEntityInventory.TryGetScriptInstanceRunning() for now. + /// + public bool ScriptRunning { get; set; } // See ICloneable @@ -388,6 +384,7 @@ namespace OpenSim.Framework public TaskInventoryItem() { + ScriptRunning = true; CreationDate = (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; } } diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 464dfd34e0..d857463938 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -531,9 +531,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments if (grp.HasGroupChanged) { -// m_log.DebugFormat( -// "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", -// grp.UUID, grp.AttachmentPoint); + m_log.DebugFormat( + "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}", + grp.UUID, grp.AttachmentPoint); string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp, scriptedState); diff --git a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs index f9d13d8867..c336ab38c6 100644 --- a/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs +++ b/OpenSim/Region/CoreModules/World/Objects/Commands/ObjectCommandsModule.cs @@ -609,12 +609,18 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands cdt.AddColumn("Asset UUID", 36); foreach (TaskInventoryItem item in inv.GetInventoryItems()) + { + bool foundScriptInstance, scriptRunning; + foundScriptInstance + = SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, item, out scriptRunning); + cdt.AddRow( item.Name, ((InventoryType)item.InvType).ToString(), - (InventoryType)item.InvType == InventoryType.LSL ? item.ScriptRunning.ToString() : "n/a", + foundScriptInstance ? scriptRunning.ToString() : "n/a", item.ItemID.ToString(), item.AssetID.ToString()); + } return sb.Append(cdt.ToString()); } diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs index c457b2f2f5..150193da5b 100644 --- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs +++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs @@ -149,6 +149,19 @@ namespace OpenSim.Region.Framework.Interfaces /// void StopScriptInstance(UUID itemId); + /// + /// Try to get the script running status. + /// + /// + /// Returns true if a script for the item was found in one of the simulator's script engines. In this case, + /// the running parameter will reflect the running status. + /// Returns false if the item could not be found, if the item is not a script or if a script instance for the + /// item was not found in any of the script engines. In this case, running status is irrelevant. + /// + /// + /// + bool TryGetScriptInstanceRunning(UUID itemId, out bool running); + /// /// Add an item to this entity's inventory. If an item with the same name already exists, then an alternative /// name is chosen. diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index bdb044692b..db723fa481 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -232,31 +232,49 @@ namespace OpenSim.Region.Framework.Scenes if (m_part == null || m_part.ParentGroup == null || m_part.ParentGroup.Scene == null) return; - IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces(); - if (engines == null) // No engine at all - return; - lock (Items) { foreach (TaskInventoryItem item in Items.Values) { - if (item.InvType == (int)InventoryType.LSL) - { - foreach (IScriptModule e in engines) - { - bool running; - - if (e.HasScript(item.ItemID, out running)) - { - item.ScriptRunning = running; - break; - } - } - } + bool running; + if (TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running)) + item.ScriptRunning = running; } } } + public bool TryGetScriptInstanceRunning(UUID itemId, out bool running) + { + running = false; + + TaskInventoryItem item = GetInventoryItem(itemId); + + if (item == null) + return false; + + return TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running); + } + + public static bool TryGetScriptInstanceRunning(Scene scene, TaskInventoryItem item, out bool running) + { + running = false; + + if (item.InvType != (int)InventoryType.LSL) + return false; + + IScriptModule[] engines = scene.RequestModuleInterfaces(); + if (engines == null) // No engine at all + return false; + + foreach (IScriptModule e in engines) + { + if (e.HasScript(item.ItemID, out running)) + return true; + } + + return false; + } + public int CreateScriptInstances(int startParam, bool postOnRez, string engine, int stateSource) { int scriptsValidForStarting = 0; diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs index f247a0be42..f331658662 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs @@ -90,7 +90,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests // log4net.Config.XmlConfigurator.Configure(); UUID userId = TestHelpers.ParseTail(0x1); -// UUID objectId = TestHelpers.ParseTail(0x2); +// UUID objectId = TestHelpers.ParseTail(0x100); // UUID itemId = TestHelpers.ParseTail(0x3); string itemName = "TestStartScript() Item"; @@ -105,12 +105,18 @@ namespace OpenSim.Region.ScriptEngine.XEngine.Tests m_scene.EventManager.OnChatFromWorld += OnChatFromWorld; - m_scene.RezNewScript(userId, itemTemplate); + SceneObjectPart partWhereRezzed = m_scene.RezNewScript(userId, itemTemplate); m_chatEvent.WaitOne(60000); Assert.That(m_osChatMessageReceived, Is.Not.Null, "No chat message received in TestStartScript()"); Assert.That(m_osChatMessageReceived.Message, Is.EqualTo("Script running")); + + bool running; + TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName); + Assert.That( + SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True); + Assert.That(running, Is.True); } private void OnChatFromWorld(object sender, OSChatMessage oscm)