aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/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/XEngine/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 'OpenSim/Region/ScriptEngine/XEngine/Executor.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Executor.cs136
1 files changed, 0 insertions, 136 deletions
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}