diff options
author | Melanie Thielker | 2008-09-26 15:34:23 +0000 |
---|---|---|
committer | Melanie Thielker | 2008-09-26 15:34:23 +0000 |
commit | 12a6b7c835cae71e87352a48087c253e8c147c38 (patch) | |
tree | 52b9d26b7cb62e0b1ae1a6a6f5db42dabe511899 /OpenSim/Region/ScriptEngine/Common/Executor.cs | |
parent | * minor: fix lolbug in RestInventoryService spotted by jhurliman (diff) | |
download | opensim-SC_OLD-12a6b7c835cae71e87352a48087c253e8c147c38.zip opensim-SC_OLD-12a6b7c835cae71e87352a48087c253e8c147c38.tar.gz opensim-SC_OLD-12a6b7c835cae71e87352a48087c253e8c147c38.tar.bz2 opensim-SC_OLD-12a6b7c835cae71e87352a48087c253e8c147c38.tar.xz |
Yay! Common/ is gone! One API is achieved!
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Common/Executor.cs | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/Executor.cs b/OpenSim/Region/ScriptEngine/Common/Executor.cs deleted file mode 100644 index 792004a..0000000 --- a/OpenSim/Region/ScriptEngine/Common/Executor.cs +++ /dev/null | |||
@@ -1,128 +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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | |||
32 | namespace OpenSim.Region.ScriptEngine.Common | ||
33 | { | ||
34 | public class Executor : ExecutorBase | ||
35 | { | ||
36 | // Cache functions by keeping a reference to them in a dictionary | ||
37 | private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>(); | ||
38 | private Dictionary<string, scriptEvents> m_stateEvents = new Dictionary<string, scriptEvents>(); | ||
39 | |||
40 | public Executor(IScript script) : base(script) | ||
41 | { | ||
42 | initEventFlags(); | ||
43 | } | ||
44 | |||
45 | |||
46 | protected override scriptEvents DoGetStateEventFlags(string state) | ||
47 | { | ||
48 | // Console.WriteLine("Get event flags for " + state); | ||
49 | |||
50 | // Check to see if we've already computed the flags for this state | ||
51 | scriptEvents eventFlags = scriptEvents.None; | ||
52 | if (m_stateEvents.ContainsKey(state)) | ||
53 | { | ||
54 | m_stateEvents.TryGetValue(state, out eventFlags); | ||
55 | return eventFlags; | ||
56 | } | ||
57 | |||
58 | // Fill in the events for this state, cache the results in the map | ||
59 | foreach (KeyValuePair<string, scriptEvents> kvp in m_eventFlagsMap) | ||
60 | { | ||
61 | string evname = state + "_event_" + kvp.Key; | ||
62 | Type type = m_Script.GetType(); | ||
63 | try | ||
64 | { | ||
65 | MethodInfo mi = type.GetMethod(evname); | ||
66 | if (mi != null) | ||
67 | { | ||
68 | // Console.WriteLine("Found handler for " + kvp.Key); | ||
69 | eventFlags |= kvp.Value; | ||
70 | } | ||
71 | } | ||
72 | catch | ||
73 | { | ||
74 | } | ||
75 | } | ||
76 | |||
77 | // Save the flags we just computed and return the result | ||
78 | m_stateEvents.Add(state, eventFlags); | ||
79 | return (eventFlags); | ||
80 | } | ||
81 | |||
82 | protected override void DoExecuteEvent(string state, string FunctionName, object[] args) | ||
83 | { | ||
84 | // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory. | ||
85 | // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead! | ||
86 | |||
87 | string EventName = state + "_event_" + FunctionName; | ||
88 | |||
89 | //#if DEBUG | ||
90 | // Console.WriteLine("ScriptEngine: Script event function name: " + EventName); | ||
91 | //#endif | ||
92 | |||
93 | if (Events.ContainsKey(EventName) == false) | ||
94 | { | ||
95 | // Not found, create | ||
96 | Type type = m_Script.GetType(); | ||
97 | try | ||
98 | { | ||
99 | MethodInfo mi = type.GetMethod(EventName); | ||
100 | Events.Add(EventName, mi); | ||
101 | } | ||
102 | catch | ||
103 | { | ||
104 | // Event name not found, cache it as not found | ||
105 | Events.Add(EventName, null); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // Get event | ||
110 | MethodInfo ev = null; | ||
111 | Events.TryGetValue(EventName, out ev); | ||
112 | |||
113 | if (ev == null) // No event by that name! | ||
114 | { | ||
115 | //Console.WriteLine("ScriptEngine Can not find any event named: \String.Empty + EventName + "\String.Empty); | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | //cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined | ||
120 | #if DEBUG | ||
121 | //Console.WriteLine("ScriptEngine: Executing function name: " + EventName); | ||
122 | #endif | ||
123 | // Found | ||
124 | ev.Invoke(m_Script, args); | ||
125 | |||
126 | } | ||
127 | } | ||
128 | } | ||