aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
diff options
context:
space:
mode:
authorteravus2012-11-15 10:05:16 -0500
committerteravus2012-11-15 10:05:16 -0500
commite9153e1d1aae50024d8cd05fe14a9bce34343a0e (patch)
treebc111d34f95a26b99c7e34d9e495dc14d1802cc3 /OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
parentMerge master into teravuswork (diff)
downloadopensim-SC-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.zip
opensim-SC-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.tar.gz
opensim-SC-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.tar.bz2
opensim-SC-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.tar.xz
Revert "Merge master into teravuswork", it should have been avination, not master.
This reverts commit dfac269032300872c4d0dc507f4f9062d102b0f4, reversing changes made to 619c39e5144f15aca129d6d999bcc5c34133ee64.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs (renamed from OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs)81
1 files changed, 11 insertions, 70 deletions
diff --git a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
index dc54c3f..c5c96a9 100644
--- a/OpenSim/Region/CoreModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
@@ -130,25 +130,13 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
130 m_scriptModule.PostScriptEvent(script, "link_message", args); 130 m_scriptModule.PostScriptEvent(script, "link_message", args);
131 } 131 }
132 132
133 private static MethodInfo GetMethodInfoFromType(Type target, string meth, bool searchInstanceMethods)
134 {
135 BindingFlags getMethodFlags =
136 BindingFlags.NonPublic | BindingFlags.Public;
137
138 if (searchInstanceMethods)
139 getMethodFlags |= BindingFlags.Instance;
140 else
141 getMethodFlags |= BindingFlags.Static;
142
143 return target.GetMethod(meth, getMethodFlags);
144 }
145
146 public void RegisterScriptInvocation(object target, string meth) 133 public void RegisterScriptInvocation(object target, string meth)
147 { 134 {
148 MethodInfo mi = GetMethodInfoFromType(target.GetType(), meth, true); 135 MethodInfo mi = target.GetType().GetMethod(meth,
136 BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
149 if (mi == null) 137 if (mi == null)
150 { 138 {
151 m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", meth); 139 m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth);
152 return; 140 return;
153 } 141 }
154 142
@@ -163,71 +151,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
163 151
164 public void RegisterScriptInvocation(object target, MethodInfo mi) 152 public void RegisterScriptInvocation(object target, MethodInfo mi)
165 { 153 {
166 m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, (target is Type) ? ((Type)target).Name : target.GetType().Name); 154 m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name);
167 155
168 Type delegateType; 156 Type delegateType;
169 List<Type> typeArgs = mi.GetParameters() 157 var typeArgs = mi.GetParameters()
170 .Select(p => p.ParameterType) 158 .Select(p => p.ParameterType)
171 .ToList(); 159 .ToList();
172 160
173 if (mi.ReturnType == typeof(void)) 161 if (mi.ReturnType == typeof(void))
174 { 162 {
175 delegateType = Expression.GetActionType(typeArgs.ToArray()); 163 delegateType = Expression.GetActionType(typeArgs.ToArray());
176 } 164 }
177 else 165 else
178 { 166 {
179 typeArgs.Add(mi.ReturnType); 167 typeArgs.Add(mi.ReturnType);
180 delegateType = Expression.GetFuncType(typeArgs.ToArray()); 168 delegateType = Expression.GetFuncType(typeArgs.ToArray());
181 } 169 }
182 170
183 Delegate fcall; 171 Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi);
184 if (!(target is Type))
185 fcall = Delegate.CreateDelegate(delegateType, target, mi);
186 else
187 fcall = Delegate.CreateDelegate(delegateType, (Type)target, mi.Name);
188 172
189 lock (m_scriptInvocation) 173 lock (m_scriptInvocation)
190 { 174 {
191 ParameterInfo[] parameters = fcall.Method.GetParameters(); 175 ParameterInfo[] parameters = fcall.Method.GetParameters ();
192 if (parameters.Length < 2) // Must have two UUID params 176 if (parameters.Length < 2) // Must have two UUID params
193 return; 177 return;
194 178
195 // Hide the first two parameters 179 // Hide the first two parameters
196 Type[] parmTypes = new Type[parameters.Length - 2]; 180 Type[] parmTypes = new Type[parameters.Length - 2];
197 for (int i = 2; i < parameters.Length; i++) 181 for (int i = 2 ; i < parameters.Length ; i++)
198 parmTypes[i - 2] = parameters[i].ParameterType; 182 parmTypes[i - 2] = parameters[i].ParameterType;
199 m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); 183 m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType);
200 } 184 }
201 } 185 }
202
203 public void RegisterScriptInvocation(Type target, string[] methods)
204 {
205 foreach (string method in methods)
206 {
207 MethodInfo mi = GetMethodInfoFromType(target, method, false);
208 if (mi == null)
209 m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}", method);
210 else
211 RegisterScriptInvocation(target, mi);
212 }
213 }
214
215 public void RegisterScriptInvocations(IRegionModuleBase target)
216 {
217 foreach(MethodInfo method in target.GetType().GetMethods(
218 BindingFlags.Public | BindingFlags.Instance |
219 BindingFlags.Static))
220 {
221 if(method.GetCustomAttributes(
222 typeof(ScriptInvocationAttribute), true).Any())
223 {
224 if(method.IsStatic)
225 RegisterScriptInvocation(target.GetType(), method);
226 else
227 RegisterScriptInvocation(target, method);
228 }
229 }
230 }
231 186
232 public Delegate[] GetScriptInvocationList() 187 public Delegate[] GetScriptInvocationList()
233 { 188 {
@@ -330,20 +285,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
330 } 285 }
331 } 286 }
332 287
333 public void RegisterConstants(IRegionModuleBase target)
334 {
335 foreach (FieldInfo field in target.GetType().GetFields(
336 BindingFlags.Public | BindingFlags.Static |
337 BindingFlags.Instance))
338 {
339 if (field.GetCustomAttributes(
340 typeof(ScriptConstantAttribute), true).Any())
341 {
342 RegisterConstant(field.Name, field.GetValue(target));
343 }
344 }
345 }
346
347 /// <summary> 288 /// <summary>
348 /// Operation to check for a registered constant 289 /// Operation to check for a registered constant
349 /// </summary> 290 /// </summary>