aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/ScriptEngine/Common/Executor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/ScriptEngine/Common/Executor.cs')
-rw-r--r--OpenSim/Grid/ScriptEngine/Common/Executor.cs115
1 files changed, 115 insertions, 0 deletions
diff --git a/OpenSim/Grid/ScriptEngine/Common/Executor.cs b/OpenSim/Grid/ScriptEngine/Common/Executor.cs
new file mode 100644
index 0000000..49bc713
--- /dev/null
+++ b/OpenSim/Grid/ScriptEngine/Common/Executor.cs
@@ -0,0 +1,115 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Reflection;
5using System.Runtime.Remoting.Lifetime;
6
7namespace OpenSim.Grid.ScriptEngine.Common
8{
9 public class Executor : MarshalByRefObject
10 {
11 // Private instance for each script
12
13 private IScript m_Script;
14 private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>();
15 private bool m_Running = true;
16 //private List<IScript> Scripts = new List<IScript>();
17
18 public Executor(IScript Script)
19 {
20 m_Script = Script;
21 }
22
23 // Object never expires
24 public override Object InitializeLifetimeService()
25 {
26 //Console.WriteLine("Executor: InitializeLifetimeService()");
27 // return null;
28 ILease lease = (ILease)base.InitializeLifetimeService();
29
30 if (lease.CurrentState == LeaseState.Initial)
31 {
32 lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
33// lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
34// lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
35 }
36 return lease;
37 }
38
39 public AppDomain GetAppDomain()
40 {
41 return AppDomain.CurrentDomain;
42 }
43
44 public void ExecuteEvent(string FunctionName, object[] args)
45 {
46 // IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
47 // Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
48 //try
49 //{
50 if (m_Running == false)
51 {
52 // Script is inactive, do not execute!
53 return;
54 }
55
56 string EventName = m_Script.State() + "_event_" + FunctionName;
57
58 //type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args);
59
60 //Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\"");
61
62 if (Events.ContainsKey(EventName) == false)
63 {
64 // Not found, create
65 Type type = m_Script.GetType();
66 try
67 {
68 MethodInfo mi = type.GetMethod(EventName);
69 Events.Add(EventName, mi);
70 }
71 catch
72 {
73 // Event name not found, cache it as not found
74 Events.Add(EventName, null);
75 }
76 }
77
78 // Get event
79 MethodInfo ev = null;
80 Events.TryGetValue(EventName, out ev);
81
82 if (ev == null) // No event by that name!
83 {
84 //Console.WriteLine("ScriptEngine Can not find any event named: \"" + EventName + "\"");
85 return;
86 }
87
88 // Found
89 //try
90 //{
91 // Invoke it
92 ev.Invoke(m_Script, args);
93
94 //}
95 //catch (Exception e)
96 //{
97 // // TODO: Send to correct place
98 // Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
99 //}
100
101
102 //}
103 //catch { }
104 }
105
106
107 public void StopScript()
108 {
109 m_Running = false;
110 }
111
112
113 }
114
115}