From 169032b4a42736b3feef682fcbfd1cc1f8b159ba Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sat, 16 Feb 2008 07:53:02 +0000 Subject: Fixed ScriptEngine config in OpenSim.ini.example that was out of place. Added some info to failure on GridServices listening port so people can see what actually went wrong. Moved most of the function/event execution module to a baseclass so other execution methods (instead of reflection) can be used with custom script modules run by ScriptEngine.Common. + some accumulated patches --- OpenSim/Region/ScriptEngine/Common/Executor.cs | 64 +----------- OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs | 107 +++++++++++++++++++++ OpenSim/Region/ScriptEngine/Common/IScript.cs | 2 +- .../Region/ScriptEngine/Common/LSL_BaseClass.cs | 2 +- OpenSim/Region/ScriptEngine/Common/TRPC/MyBase.cs | 10 ++ OpenSim/Region/ScriptEngine/LSOEngine/LSOScript.cs | 22 +++++ 6 files changed, 145 insertions(+), 62 deletions(-) create mode 100644 OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs create mode 100644 OpenSim/Region/ScriptEngine/Common/TRPC/MyBase.cs create mode 100644 OpenSim/Region/ScriptEngine/LSOEngine/LSOScript.cs (limited to 'OpenSim/Region/ScriptEngine') diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs index 6262c64..e35882b 100644 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ b/OpenSim/Region/ScriptEngine/Common/Executor.cs @@ -33,64 +33,26 @@ using System.Runtime.Remoting.Lifetime; namespace OpenSim.Region.ScriptEngine.Common { - public class Executor : MarshalByRefObject + public class Executor : ExecutorBase { - // Private instance for each script - - private IScript m_Script; + // Cache functions by keeping a reference to them in a dictionary private Dictionary Events = new Dictionary(); - private bool m_Running = true; - //private List Scripts = new List(); - public Executor(IScript Script) + public Executor(IScript script) : base(script) { - m_Script = Script; } - // Object never expires - public override Object InitializeLifetimeService() - { - //Console.WriteLine("Executor: InitializeLifetimeService()"); - // return null; - ILease lease = (ILease) base.InitializeLifetimeService(); - - if (lease.CurrentState == LeaseState.Initial) - { - lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1); -// lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); -// lease.RenewOnCallTime = TimeSpan.FromSeconds(2); - } - return lease; - } - - public AppDomain GetAppDomain() - { - return AppDomain.CurrentDomain; - } - - public void ExecuteEvent(string FunctionName, object[] args) + protected override void DoExecuteEvent(string FunctionName, object[] args) { // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! - //try - //{ - if (m_Running == false) - { - // Script is inactive, do not execute! - return; - } string EventName = m_Script.State + "_event_" + FunctionName; -//cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined ///#if DEBUG /// Console.WriteLine("ScriptEngine: Script event function name: " + EventName); ///#endif - //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args); - - //Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \String.Empty + EventName + "\String.Empty); - if (Events.ContainsKey(EventName) == false) { // Not found, create @@ -122,27 +84,9 @@ namespace OpenSim.Region.ScriptEngine.Common /// Console.WriteLine("ScriptEngine: Executing function name: " + EventName); ///#endif // Found - //try - //{ - // Invoke it ev.Invoke(m_Script, args); - //} - //catch (Exception e) - //{ - // // TODO: Send to correct place - // Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString()); - //} - - - //} - //catch { } } - - public void StopScript() - { - m_Running = false; - } } } \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs b/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs new file mode 100644 index 0000000..83aa230 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Common/ExecutorBase.cs @@ -0,0 +1,107 @@ +/* +* 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 OpenSim 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.Collections.Generic; +using System.Runtime.Remoting.Lifetime; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.Common +{ + public abstract class ExecutorBase : MarshalByRefObject + { + /// + /// Contains the script to execute functions in. + /// + protected IScript m_Script; + /// + /// If set to False events will not be executed. + /// + protected bool m_Running = true; + + /// + /// Create a new instance of ExecutorBase + /// + /// + public ExecutorBase(IScript Script) + { + m_Script = Script; + } + + /// + /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class) + /// + /// + public override Object InitializeLifetimeService() + { + //Console.WriteLine("Executor: InitializeLifetimeService()"); + // return null; + ILease lease = (ILease)base.InitializeLifetimeService(); + + if (lease.CurrentState == LeaseState.Initial) + { + lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1); + // lease.SponsorshipTimeout = TimeSpan.FromMinutes(2); + // lease.RenewOnCallTime = TimeSpan.FromSeconds(2); + } + return lease; + } + + /// + /// Get current AppDomain + /// + /// Current AppDomain + public AppDomain GetAppDomain() + { + return AppDomain.CurrentDomain; + } + + /// + /// Execute a specific function/event in script. + /// + /// Name of function to execute + /// Arguments to pass to function + public void ExecuteEvent(string FunctionName, object[] args) + { + if (m_Running == false) + { + // Script is inactive, do not execute! + return; + } + } + protected abstract void DoExecuteEvent(string FunctionName, object[] args); + + /// + /// Stop script from running. Event execution will be ignored. + /// + public void StopScript() + { + m_Running = false; + } + + } +} diff --git a/OpenSim/Region/ScriptEngine/Common/IScript.cs b/OpenSim/Region/ScriptEngine/Common/IScript.cs index c392278..96c4e3c 100644 --- a/OpenSim/Region/ScriptEngine/Common/IScript.cs +++ b/OpenSim/Region/ScriptEngine/Common/IScript.cs @@ -33,7 +33,7 @@ namespace OpenSim.Region.ScriptEngine.Common public interface IScript { string State { get; set; } - Executor Exec { get; } + ExecutorBase Exec { get; } string Source { get; set; } void Start(LSL_BuiltIn_Commands_Interface BuiltIn_Commands); EventQueueManager.Queue_llDetectParams_Struct llDetectParams { get; set; } diff --git a/OpenSim/Region/ScriptEngine/Common/LSL_BaseClass.cs b/OpenSim/Region/ScriptEngine/Common/LSL_BaseClass.cs index b6710f0..e3d0451 100644 --- a/OpenSim/Region/ScriptEngine/Common/LSL_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/Common/LSL_BaseClass.cs @@ -75,7 +75,7 @@ namespace OpenSim.Region.ScriptEngine.Common private Executor m_Exec; - Executor IScript.Exec + ExecutorBase IScript.Exec { get { diff --git a/OpenSim/Region/ScriptEngine/Common/TRPC/MyBase.cs b/OpenSim/Region/ScriptEngine/Common/TRPC/MyBase.cs new file mode 100644 index 0000000..1f66b14 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Common/TRPC/MyBase.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.ScriptEngine.Common.TRPC +{ + class MyBase + { + } +} diff --git a/OpenSim/Region/ScriptEngine/LSOEngine/LSOScript.cs b/OpenSim/Region/ScriptEngine/LSOEngine/LSOScript.cs new file mode 100644 index 0000000..e87bec8 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/LSOEngine/LSOScript.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using OpenSim.Region.ScriptEngine.LSOEngine.LSO; + +namespace OpenSim.Region.ScriptEngine.LSOEngine +{ + /// + /// This class encapsulated an LSO file and contains execution-specific data + /// + public class LSOScript + { + private byte[] LSOCode = new byte[1024 * 16]; // Contains the LSO-file + //private System.IO.MemoryStream LSOCode = new MemoryStream(1024 * 16); + + public void Execute(LSO_Enums.Event_Mask_Values Event, params object[] param) + { + + } + } +} -- cgit v1.1