diff options
author | Melanie | 2012-03-26 00:30:52 +0100 |
---|---|---|
committer | Melanie | 2012-03-26 01:47:14 +0100 |
commit | d7cc194e83ade3453649ab897a4f40b0fa856d0d (patch) | |
tree | 89a0fce4043d3a89cafb53d4b25a8f4474b028ac /OpenSim/Region | |
parent | Simplify the module invocation registration. The types and method name (diff) | |
download | opensim-SC-d7cc194e83ade3453649ab897a4f40b0fa856d0d.zip opensim-SC-d7cc194e83ade3453649ab897a4f40b0fa856d0d.tar.gz opensim-SC-d7cc194e83ade3453649ab897a4f40b0fa856d0d.tar.bz2 opensim-SC-d7cc194e83ade3453649ab897a4f40b0fa856d0d.tar.xz |
Correct the design error I introduced into ScriptComms. Untested but about to
be.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs | 7 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 36 |
2 files changed, 25 insertions, 18 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs index 8bfbbf8..8a08fbe 100644 --- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs +++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs | |||
@@ -31,7 +31,6 @@ using OpenMetaverse; | |||
31 | namespace OpenSim.Region.Framework.Interfaces | 31 | namespace OpenSim.Region.Framework.Interfaces |
32 | { | 32 | { |
33 | public delegate void ScriptCommand(UUID script, string id, string module, string command, string k); | 33 | public delegate void ScriptCommand(UUID script, string id, string module, string command, string k); |
34 | public delegate object ScriptInvocation(UUID script, object[] parms); | ||
35 | 34 | ||
36 | /// <summary> | 35 | /// <summary> |
37 | /// Interface for communication between OpenSim modules and in-world scripts | 36 | /// Interface for communication between OpenSim modules and in-world scripts |
@@ -46,10 +45,10 @@ namespace OpenSim.Region.Framework.Interfaces | |||
46 | /// </summary> | 45 | /// </summary> |
47 | event ScriptCommand OnScriptCommand; | 46 | event ScriptCommand OnScriptCommand; |
48 | 47 | ||
49 | void RegisterScriptInvocation(ScriptInvocation fn); | 48 | void RegisterScriptInvocation(Delegate fn); |
50 | ScriptInvocation[] GetScriptInvocationList(); | 49 | Delegate[] GetScriptInvocationList(); |
51 | 50 | ||
52 | ScriptInvocation LookupScriptInvocation(string fname); | 51 | Delegate LookupScriptInvocation(string fname); |
53 | string LookupModInvocation(string fname); | 52 | string LookupModInvocation(string fname); |
54 | Type[] LookupTypeSignature(string fname); | 53 | Type[] LookupTypeSignature(string fname); |
55 | Type LookupReturnType(string fname); | 54 | Type LookupReturnType(string fname); |
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index 8e8a0b6..e37e42e 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -47,15 +47,15 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
47 | #region ScriptInvocation | 47 | #region ScriptInvocation |
48 | protected class ScriptInvocationData | 48 | protected class ScriptInvocationData |
49 | { | 49 | { |
50 | public ScriptInvocation ScriptInvocationFn { get; private set; } | 50 | public Delegate ScriptInvocationDelegate { get; private set; } |
51 | public string FunctionName { get; private set; } | 51 | public string FunctionName { get; private set; } |
52 | public Type[] TypeSignature { get; private set; } | 52 | public Type[] TypeSignature { get; private set; } |
53 | public Type ReturnType { get; private set; } | 53 | public Type ReturnType { get; private set; } |
54 | 54 | ||
55 | public ScriptInvocationData(string fname, ScriptInvocation fn, Type[] callsig, Type returnsig) | 55 | public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig) |
56 | { | 56 | { |
57 | FunctionName = fname; | 57 | FunctionName = fname; |
58 | ScriptInvocationFn = fn; | 58 | ScriptInvocationDelegate = fn; |
59 | TypeSignature = callsig; | 59 | TypeSignature = callsig; |
60 | ReturnType = returnsig; | 60 | ReturnType = returnsig; |
61 | } | 61 | } |
@@ -126,26 +126,30 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
126 | m_scriptModule.PostScriptEvent(script, "link_message", args); | 126 | m_scriptModule.PostScriptEvent(script, "link_message", args); |
127 | } | 127 | } |
128 | 128 | ||
129 | public void RegisterScriptInvocation(ScriptInvocation fcall) | 129 | public void RegisterScriptInvocation(Delegate fcall) |
130 | { | 130 | { |
131 | lock (m_scriptInvocation) | 131 | lock (m_scriptInvocation) |
132 | { | 132 | { |
133 | ParameterInfo[] parameters = fcall.Method.GetParameters (); | 133 | ParameterInfo[] parameters = fcall.Method.GetParameters (); |
134 | Type[] parmTypes = new Type[parameters.Length]; | 134 | if (parameters.Length == 0) // Must have one UUID param |
135 | for (int i = 0 ; i < parameters.Length ; i++) | 135 | return; |
136 | parmTypes[i] = parameters[i].ParameterType; | 136 | |
137 | // Hide the first parameter | ||
138 | Type[] parmTypes = new Type[parameters.Length - 1]; | ||
139 | for (int i = 1 ; i < parameters.Length ; i++) | ||
140 | parmTypes[i - 1] = parameters[i].ParameterType; | ||
137 | m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); | 141 | m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); |
138 | } | 142 | } |
139 | } | 143 | } |
140 | 144 | ||
141 | public ScriptInvocation[] GetScriptInvocationList() | 145 | public Delegate[] GetScriptInvocationList() |
142 | { | 146 | { |
143 | List<ScriptInvocation> ret = new List<ScriptInvocation>(); | 147 | List<Delegate> ret = new List<Delegate>(); |
144 | 148 | ||
145 | lock (m_scriptInvocation) | 149 | lock (m_scriptInvocation) |
146 | { | 150 | { |
147 | foreach (ScriptInvocationData d in m_scriptInvocation.Values) | 151 | foreach (ScriptInvocationData d in m_scriptInvocation.Values) |
148 | ret.Add(d.ScriptInvocationFn); | 152 | ret.Add(d.ScriptInvocationDelegate); |
149 | } | 153 | } |
150 | return ret.ToArray(); | 154 | return ret.ToArray(); |
151 | } | 155 | } |
@@ -177,13 +181,13 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
177 | return null; | 181 | return null; |
178 | } | 182 | } |
179 | 183 | ||
180 | public ScriptInvocation LookupScriptInvocation(string fname) | 184 | public Delegate LookupScriptInvocation(string fname) |
181 | { | 185 | { |
182 | lock (m_scriptInvocation) | 186 | lock (m_scriptInvocation) |
183 | { | 187 | { |
184 | ScriptInvocationData sid; | 188 | ScriptInvocationData sid; |
185 | if (m_scriptInvocation.TryGetValue(fname,out sid)) | 189 | if (m_scriptInvocation.TryGetValue(fname,out sid)) |
186 | return sid.ScriptInvocationFn; | 190 | return sid.ScriptInvocationDelegate; |
187 | } | 191 | } |
188 | 192 | ||
189 | return null; | 193 | return null; |
@@ -215,8 +219,12 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
215 | 219 | ||
216 | public object InvokeOperation(UUID scriptid, string fname, params object[] parms) | 220 | public object InvokeOperation(UUID scriptid, string fname, params object[] parms) |
217 | { | 221 | { |
218 | ScriptInvocation fn = LookupScriptInvocation(fname); | 222 | List<object> olist = new List<object>(); |
219 | return fn(scriptid,parms); | 223 | olist.Add(scriptid); |
224 | foreach (object o in parms) | ||
225 | olist.Add(o); | ||
226 | Delegate fn = LookupScriptInvocation(fname); | ||
227 | return fn.DynamicInvoke(olist.ToArray()); | ||
220 | } | 228 | } |
221 | #endregion | 229 | #endregion |
222 | 230 | ||