aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/IScript.cs3
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs (renamed from OpenSim/Region/ScriptEngine/XEngine/ExecutorBase.cs)123
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp1
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs14
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Executor.cs136
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs9
6 files changed, 111 insertions, 175 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/IScript.cs b/OpenSim/Region/ScriptEngine/Interfaces/IScript.cs
index 42042e8..3f49422 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/IScript.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/IScript.cs
@@ -29,6 +29,7 @@ using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using OpenSim.Region.ScriptEngine.Interfaces; 31using OpenSim.Region.ScriptEngine.Interfaces;
32using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
32 33
33namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase 34namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
34{ 35{
@@ -37,6 +38,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
37 string[] GetApis(); 38 string[] GetApis();
38 void InitApi(string name, IScriptApi data); 39 void InitApi(string name, IScriptApi data);
39 40
41 int GetStateEventFlags(string state);
42 void ExecuteEvent(string state, string FunctionName, object[] args);
40 Dictionary<string,Object> GetVars(); 43 Dictionary<string,Object> GetVars();
41 void SetVars(Dictionary<string,Object> vars); 44 void SetVars(Dictionary<string,Object> vars);
42 void ResetVars(); 45 void ResetVars();
diff --git a/OpenSim/Region/ScriptEngine/XEngine/ExecutorBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
index 79c3cc9..0241da5 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/ExecutorBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
@@ -27,14 +27,14 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection;
30using System.Runtime.Remoting.Lifetime; 31using System.Runtime.Remoting.Lifetime;
31using OpenSim.Region.ScriptEngine.Shared; 32using OpenSim.Region.ScriptEngine.Shared;
32using OpenSim.Region.ScriptEngine.Shared.ScriptBase; 33using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
33using OpenSim.Region.ScriptEngine.Interfaces;
34 34
35namespace OpenSim.Region.ScriptEngine.XEngine 35namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
36{ 36{
37 public abstract class ExecutorBase : MarshalByRefObject 37 public class Executor : MarshalByRefObject
38 { 38 {
39 /// <summary> 39 /// <summary>
40 /// Contains the script to execute functions in. 40 /// Contains the script to execute functions in.
@@ -76,13 +76,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
76 object_rez = 4194304 76 object_rez = 4194304
77 } 77 }
78 78
79 /// <summary> 79 // Cache functions by keeping a reference to them in a dictionary
80 /// Create a new instance of ExecutorBase 80 private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>();
81 /// </summary> 81 private Dictionary<string, scriptEvents> m_stateEvents = new Dictionary<string, scriptEvents>();
82 /// <param name="Script"></param> 82
83 public ExecutorBase(IScript Script) 83 public Executor(IScript script)
84 { 84 {
85 m_Script = Script; 85 m_Script = script;
86 initEventFlags(); 86 initEventFlags();
87 } 87 }
88 88
@@ -90,7 +90,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
90 /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class) 90 /// Make sure our object does not timeout when in AppDomain. (Called by ILease base class)
91 /// </summary> 91 /// </summary>
92 /// <returns></returns> 92 /// <returns></returns>
93 public override Object InitializeLifetimeService() 93 public Object InitializeLifetimeService()
94 { 94 {
95 //Console.WriteLine("Executor: InitializeLifetimeService()"); 95 //Console.WriteLine("Executor: InitializeLifetimeService()");
96 // return null; 96 // return null;
@@ -105,37 +105,94 @@ namespace OpenSim.Region.ScriptEngine.XEngine
105 return lease; 105 return lease;
106 } 106 }
107 107
108 /// <summary> 108
109 /// Get current AppDomain 109 public scriptEvents GetStateEventFlags(string state)
110 /// </summary>
111 /// <returns>Current AppDomain</returns>
112 public AppDomain GetAppDomain()
113 { 110 {
114 return AppDomain.CurrentDomain; 111 //Console.WriteLine("Get event flags for " + state);
112
113 // Check to see if we've already computed the flags for this state
114 scriptEvents eventFlags = scriptEvents.None;
115 if (m_stateEvents.ContainsKey(state))
116 {
117 m_stateEvents.TryGetValue(state, out eventFlags);
118 return eventFlags;
119 }
120
121 Type type=m_Script.GetType();
122
123 // Fill in the events for this state, cache the results in the map
124 foreach (KeyValuePair<string, scriptEvents> kvp in m_eventFlagsMap)
125 {
126 string evname = state + "_event_" + kvp.Key;
127 //Console.WriteLine("Trying event "+evname);
128 try
129 {
130 MethodInfo mi = type.GetMethod(evname);
131 if (mi != null)
132 {
133 //Console.WriteLine("Found handler for " + kvp.Key);
134 eventFlags |= kvp.Value;
135 }
136 }
137 catch(Exception)
138 {
139 //Console.WriteLine("Exeption in GetMethod:\n"+e.ToString());
140 }
141 }
142
143 // Save the flags we just computed and return the result
144 if (eventFlags != 0)
145 m_stateEvents.Add(state, eventFlags);
146
147 //Console.WriteLine("Returning {0:x}", eventFlags);
148 return (eventFlags);
115 } 149 }
116 150
117 /// <summary>
118 /// Execute a specific function/event in script.
119 /// </summary>
120 /// <param name="FunctionName">Name of function to execute</param>
121 /// <param name="args">Arguments to pass to function</param>
122 public void ExecuteEvent(string state, string FunctionName, object[] args) 151 public void ExecuteEvent(string state, string FunctionName, object[] args)
123 { 152 {
124 DoExecuteEvent(state, FunctionName, args); 153 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
125 } 154 // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
126 155
127 protected abstract void DoExecuteEvent(string state, string FunctionName, object[] args); 156 string EventName = state + "_event_" + FunctionName;
128 157
129 /// <summary> 158//#if DEBUG
130 /// Compute the events handled by the current state of the script 159// Console.WriteLine("ScriptEngine: Script event function name: " + EventName);
131 /// </summary> 160//#endif
132 /// <returns>state mask</returns> 161
133 public scriptEvents GetStateEventFlags(string state) 162 if (Events.ContainsKey(EventName) == false)
134 { 163 {
135 return DoGetStateEventFlags(state); 164 // Not found, create
136 } 165 Type type = m_Script.GetType();
166 try
167 {
168 MethodInfo mi = type.GetMethod(EventName);
169 Events.Add(EventName, mi);
170 }
171 catch
172 {
173 Console.WriteLine("Event {0}not found", EventName);
174 // Event name not found, cache it as not found
175 Events.Add(EventName, null);
176 }
177 }
178
179 // Get event
180 MethodInfo ev = null;
181 Events.TryGetValue(EventName, out ev);
182
183 if (ev == null) // No event by that name!
184 {
185 //Console.WriteLine("ScriptEngine Can not find any event named: \String.Empty + EventName + "\String.Empty);
186 return;
187 }
137 188
138 protected abstract scriptEvents DoGetStateEventFlags(string state); 189//cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined
190#if DEBUG
191 //Console.WriteLine("ScriptEngine: Executing function name: " + EventName);
192#endif
193 // Found
194 ev.Invoke(m_Script, args);
195 }
139 196
140 protected void initEventFlags() 197 protected void initEventFlags()
141 { 198 {
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
index 37bedfc..87904bb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
@@ -17,6 +17,7 @@
17 <excludeFiles /> 17 <excludeFiles />
18 </DeploymentInformation> 18 </DeploymentInformation>
19 <Contents> 19 <Contents>
20 <File name="./Executor.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
20 <File name="./LSL_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 21 <File name="./LSL_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
21 <File name="./LSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 22 <File name="./LSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
22 <File name="./OSSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 23 <File name="./OSSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index c28aa9a..9f0dd27 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
@@ -56,6 +56,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
56 56
57 public ScriptBaseClass() 57 public ScriptBaseClass()
58 { 58 {
59 m_Executor = new Executor(this);
60
59 MethodInfo[] myArrayMethodInfo = GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance); 61 MethodInfo[] myArrayMethodInfo = GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance);
60 62
61 foreach (MethodInfo mi in myArrayMethodInfo) 63 foreach (MethodInfo mi in myArrayMethodInfo)
@@ -68,6 +70,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
68 } 70 }
69 } 71 }
70 72
73 private Executor m_Executor = null;
74
75 public int GetStateEventFlags(string state)
76 {
77 return (int)m_Executor.GetStateEventFlags(state);
78 }
79
80 public void ExecuteEvent(string state, string FunctionName, object[] args)
81 {
82 m_Executor.ExecuteEvent(state, FunctionName, args);
83 }
84
71 public string[] GetApis() 85 public string[] GetApis()
72 { 86 {
73 string[] apis = new string[inits.Count]; 87 string[] apis = new string[inits.Count];
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Executor.cs b/OpenSim/Region/ScriptEngine/XEngine/Executor.cs
deleted file mode 100644
index b848a02..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/Executor.cs
+++ /dev/null
@@ -1,136 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using OpenSim.Region.ScriptEngine.Shared;
32using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
33
34namespace OpenSim.Region.ScriptEngine.XEngine
35{
36 public class Executor : ExecutorBase
37 {
38 // Cache functions by keeping a reference to them in a dictionary
39 private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>();
40 private Dictionary<string, scriptEvents> m_stateEvents = new Dictionary<string, scriptEvents>();
41
42 public Executor(IScript script) : base(script)
43 {
44 initEventFlags();
45 }
46
47
48 protected override scriptEvents DoGetStateEventFlags(string state)
49 {
50 //Console.WriteLine("Get event flags for " + state);
51
52 // Check to see if we've already computed the flags for this state
53 scriptEvents eventFlags = scriptEvents.None;
54 if (m_stateEvents.ContainsKey(state))
55 {
56 m_stateEvents.TryGetValue(state, out eventFlags);
57 return eventFlags;
58 }
59
60 Type type=m_Script.GetType();
61
62 // Fill in the events for this state, cache the results in the map
63 foreach (KeyValuePair<string, scriptEvents> kvp in m_eventFlagsMap)
64 {
65 string evname = state + "_event_" + kvp.Key;
66 //Console.WriteLine("Trying event "+evname);
67 try
68 {
69 MethodInfo mi = type.GetMethod(evname);
70 if (mi != null)
71 {
72 //Console.WriteLine("Found handler for " + kvp.Key);
73 eventFlags |= kvp.Value;
74 }
75 }
76 catch(Exception)
77 {
78 //Console.WriteLine("Exeption in GetMethod:\n"+e.ToString());
79 }
80 }
81
82 // Save the flags we just computed and return the result
83 if (eventFlags != 0)
84 m_stateEvents.Add(state, eventFlags);
85
86 //Console.WriteLine("Returning {0:x}", eventFlags);
87 return (eventFlags);
88 }
89
90 protected override void DoExecuteEvent(string state, string FunctionName, object[] args)
91 {
92 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
93 // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
94
95 string EventName = state + "_event_" + FunctionName;
96
97//#if DEBUG
98// Console.WriteLine("ScriptEngine: Script event function name: " + EventName);
99//#endif
100
101 if (Events.ContainsKey(EventName) == false)
102 {
103 // Not found, create
104 Type type = m_Script.GetType();
105 try
106 {
107 MethodInfo mi = type.GetMethod(EventName);
108 Events.Add(EventName, mi);
109 }
110 catch
111 {
112 Console.WriteLine("Event {0}not found", EventName);
113 // Event name not found, cache it as not found
114 Events.Add(EventName, null);
115 }
116 }
117
118 // Get event
119 MethodInfo ev = null;
120 Events.TryGetValue(EventName, out ev);
121
122 if (ev == null) // No event by that name!
123 {
124 //Console.WriteLine("ScriptEngine Can not find any event named: \String.Empty + EventName + "\String.Empty);
125 return;
126 }
127
128//cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined
129#if DEBUG
130 //Console.WriteLine("ScriptEngine: Executing function name: " + EventName);
131#endif
132 // Found
133 ev.Invoke(m_Script, args);
134 }
135 }
136}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index c528c02..cfe0599 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -863,7 +863,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
863 private LLUUID m_ObjectID; 863 private LLUUID m_ObjectID;
864 private LLUUID m_AssetID; 864 private LLUUID m_AssetID;
865 private IScript m_Script; 865 private IScript m_Script;
866 private Executor m_Executor;
867 private LLUUID m_AppDomain; 866 private LLUUID m_AppDomain;
868 private DetectParams[] m_DetectParams; 867 private DetectParams[] m_DetectParams;
869 private bool m_TimerQueued; 868 private bool m_TimerQueued;
@@ -1009,12 +1008,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1009 m_Script.InitApi(kv.Key, kv.Value); 1008 m_Script.InitApi(kv.Key, kv.Value);
1010 } 1009 }
1011 1010
1012 m_Executor = new Executor(m_Script);
1013
1014// m_Engine.Log.Debug("[XEngine] Script instance created"); 1011// m_Engine.Log.Debug("[XEngine] Script instance created");
1015 1012
1016 part.SetScriptEvents(m_ItemID, 1013 part.SetScriptEvents(m_ItemID,
1017 (int)m_Executor.GetStateEventFlags(State)); 1014 (int)m_Script.GetStateEventFlags(State));
1018 } 1015 }
1019 catch (Exception e) 1016 catch (Exception e)
1020 { 1017 {
@@ -1274,7 +1271,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1274 if (part != null) 1271 if (part != null)
1275 { 1272 {
1276 part.SetScriptEvents(m_ItemID, 1273 part.SetScriptEvents(m_ItemID,
1277 (int)m_Executor.GetStateEventFlags(State)); 1274 (int)m_Script.GetStateEventFlags(State));
1278 } 1275 }
1279 } 1276 }
1280 else 1277 else
@@ -1290,7 +1287,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1290 m_EventStart = DateTime.Now; 1287 m_EventStart = DateTime.Now;
1291 m_InEvent = true; 1288 m_InEvent = true;
1292 1289
1293 m_Executor.ExecuteEvent(State, data.EventName, data.Params); 1290 m_Script.ExecuteEvent(State, data.EventName, data.Params);
1294 1291
1295 m_InEvent = false; 1292 m_InEvent = false;
1296 m_CurrentEvent = String.Empty; 1293 m_CurrentEvent = String.Empty;