From 0377ddb5de48406f6d72d676ca853fcb0b8ff497 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Fri, 10 Apr 2009 19:07:41 +0000 Subject: [PATCH] Add events to IScriptEngine to notify scripting modules of the removal of objects from the scene, and of scripts from objects. This facilitates the development of modules that can register prims with externall servers for inbound email and XMLRPC. Currently implemented in XEngine only. Also applying cmickeyb's compiler locking patch, since it seems risk-free. --- .../ScriptEngine/DotNetEngine/ScriptEngine.cs | 3 +++ .../ScriptEngine/Interfaces/IScriptEngine.cs | 7 +++++++ .../ScriptEngine/Shared/CodeTools/Compiler.cs | 7 +++++-- OpenSim/Region/ScriptEngine/XEngine/XEngine.cs | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs index c2b07fc594..b850227d0c 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs @@ -96,6 +96,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine get { return "ScriptEngine.DotNetEngine"; } } + public event ScriptRemoved OnScriptRemoved; + public event ObjectRemoved OnObjectRemoved; + public ScriptEngine() { // For logging, just need any instance, doesn't matter diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs index 95a8530725..8da46f4cd9 100644 --- a/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs +++ b/OpenSim/Region/ScriptEngine/Interfaces/IScriptEngine.cs @@ -41,6 +41,10 @@ namespace OpenSim.Region.ScriptEngine.Interfaces /// An interface for a script API module to communicate with /// the engine it's running under /// + + public delegate void ScriptRemoved(UUID script); + public delegate void ObjectRemoved(UUID prim); + public interface IScriptEngine { /// @@ -50,6 +54,9 @@ namespace OpenSim.Region.ScriptEngine.Interfaces Scene World { get; } + event ScriptRemoved OnScriptRemoved; + event ObjectRemoved OnObjectRemoved; + /// /// Post an event to a single script /// diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs index 162f323f96..10291849f0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs @@ -527,8 +527,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools break; case enumCompileType.cs: case enumCompileType.lsl: - results = CScodeProvider.CompileAssemblyFromSource( - parameters, Script); + lock (CScodeProvider) + { + results = CScodeProvider.CompileAssemblyFromSource( + parameters, Script); + } break; case enumCompileType.js: results = JScodeProvider.CompileAssemblyFromSource( diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs index 09480f6c35..357ee32881 100644 --- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs +++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs @@ -142,6 +142,9 @@ namespace OpenSim.Region.ScriptEngine.XEngine get { return m_ScriptConfig; } } + public event ScriptRemoved OnScriptRemoved; + public event ObjectRemoved OnObjectRemoved; + // // IRegionModule functions // @@ -702,6 +705,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (part != null) part.RemoveScriptEvents(itemID); + bool objectRemoved = false; + lock (m_PrimObjects) { // Remove the script from it's prim @@ -715,6 +720,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine if (m_PrimObjects[localID].Count == 0) { m_PrimObjects.Remove(localID); + objectRemoved = true; } } } @@ -731,8 +737,16 @@ namespace OpenSim.Region.ScriptEngine.XEngine instance = null; + ObjectRemoved handlerObjectRemoved = OnObjectRemoved; + if (handlerObjectRemoved != null) + handlerObjectRemoved(part.UUID); + CleanAssemblies(); } + + ScriptRemoved handlerScriptRemoved = OnScriptRemoved; + if (handlerScriptRemoved != null) + handlerScriptRemoved(itemID); } public void OnScriptReset(uint localID, UUID itemID)