2 // System.Runtime.Remoting.Messaging.MonoMethodMessage.cs
5 // Dietmar Maurer (dietmar@ximian.com)
8 // (C) Ximian, Inc. http://www.ximian.com
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Collections;
36 using System.Reflection;
37 using System.Runtime.CompilerServices;
39 namespace System.Runtime.Remoting.Messaging {
42 internal class MonoMethodMessage : IMethodCallMessage, IMethodReturnMessage, IInternalMessage {
50 byte [] arg_types; /* 1 == IN; 2 == OUT ; 3 = INOUT */
52 public LogicalCallContext ctx;
58 AsyncResult asyncResult;
64 MethodCallDictionary properties;
66 Type[] methodSignature;
71 [MethodImplAttribute(MethodImplOptions.InternalCall)]
72 internal extern void InitMessage (MonoMethod method, object [] out_args);
74 public MonoMethodMessage (MethodBase method, object [] out_args)
77 InitMessage ((MonoMethod)method, out_args);
82 public MonoMethodMessage (Type type, string method_name, object [] in_args)
84 // fixme: consider arg types
85 MethodInfo minfo = type.GetMethod (method_name);
87 InitMessage ((MonoMethod)minfo, null);
89 int len = in_args.Length;
90 for (int i = 0; i < len; i++) {
91 args [i] = in_args [i];
95 public IDictionary Properties {
97 if (properties == null) properties = new MethodCallDictionary (this);
102 public int ArgCount {
104 if (CallType == CallType.EndInvoke)
114 public object [] Args {
120 public bool HasVarArgs {
126 public LogicalCallContext LogicalCallContext {
136 public MethodBase MethodBase {
142 public string MethodName {
151 public object MethodSignature {
153 if (methodSignature == null) {
154 ParameterInfo[] parameters = method.GetParameters();
155 methodSignature = new Type[parameters.Length];
156 for (int n=0; n<parameters.Length; n++)
157 methodSignature[n] = parameters[n].ParameterType;
159 return methodSignature;
163 public string TypeName {
168 return method.DeclaringType.AssemblyQualifiedName;
182 public object GetArg (int arg_num)
187 return args [arg_num];
190 public string GetArgName (int arg_num)
195 return names [arg_num];
198 public int InArgCount {
200 if (CallType == CallType.EndInvoke)
208 foreach (byte t in arg_types) {
209 if ((t & 1) != 0) count++;
216 public object [] InArgs {
218 int i, j, count = InArgCount;
219 object [] inargs = new object [count];
222 foreach (byte t in arg_types) {
224 inargs [j++] = args [i];
232 public object GetInArg (int arg_num)
235 foreach (byte t in arg_types) {
245 public string GetInArgName (int arg_num)
248 foreach (byte t in arg_types) {
258 public Exception Exception {
264 public int OutArgCount {
271 foreach (byte t in arg_types) {
272 if ((t & 2) != 0) count++;
279 public object [] OutArgs {
284 int i, j, count = OutArgCount;
285 object [] outargs = new object [count];
288 foreach (byte t in arg_types) {
290 outargs [j++] = args [i];
298 public object ReturnValue {
304 public object GetOutArg (int arg_num)
307 foreach (byte t in arg_types) {
317 public string GetOutArgName (int arg_num)
320 foreach (byte t in arg_types) {
330 Identity IInternalMessage.TargetIdentity
332 get { return identity; }
333 set { identity = value; }
338 get { return asyncResult != null; }
341 public AsyncResult AsyncResult
343 get { return asyncResult; }
346 internal CallType CallType
350 // FIXME: ideally, the OneWay type would be set by the runtime
352 if (call_type == CallType.Sync && RemotingServices.IsOneWay (method))
353 call_type = CallType.OneWay;
359 internal enum CallType: int