aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
diff options
context:
space:
mode:
authorMelanie Thielker2008-08-27 21:36:03 +0000
committerMelanie Thielker2008-08-27 21:36:03 +0000
commita2985b5655d336b6da3ae48dcf80b9cbb16b90fb (patch)
tree1b02f9b907f75d4085ca6050ed481d82b9c2cfc0 /OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs
parent* Updates OGP module to define a default starting point (diff)
downloadopensim-SC_OLD-a2985b5655d336b6da3ae48dcf80b9cbb16b90fb.zip
opensim-SC_OLD-a2985b5655d336b6da3ae48dcf80b9cbb16b90fb.tar.gz
opensim-SC_OLD-a2985b5655d336b6da3ae48dcf80b9cbb16b90fb.tar.bz2
opensim-SC_OLD-a2985b5655d336b6da3ae48dcf80b9cbb16b90fb.tar.xz
Refactor Executor into the script app domain and IScript. This changes
an implicit reference into a proxied one and further reduces memory consumption of XEngine
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/Executor.cs (renamed from OpenSim/Region/ScriptEngine/XEngine/ExecutorBase.cs)123
1 files changed, 90 insertions, 33 deletions
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 {