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;
38 using System.Runtime.InteropServices;
40 namespace System.Runtime.Remoting.Messaging {
43 [StructLayout (LayoutKind.Sequential)]
44 internal class MonoMethodMessage : IMethodCallMessage, IMethodReturnMessage, IInternalMessage {
46 #pragma warning disable 649
47 #region keep in sync with MonoMessage in object-internals.h
51 byte [] arg_types; /* 1 == IN; 2 == OUT; 3 == INOUT; 4 == COPY OUT */
52 public LogicalCallContext ctx;
55 AsyncResult asyncResult;
58 #pragma warning restore 649
62 MethodCallDictionary properties;
64 Type[] methodSignature;
69 [MethodImplAttribute(MethodImplOptions.InternalCall)]
70 internal extern void InitMessage (MonoMethod method, object [] out_args);
72 public MonoMethodMessage (MethodBase method, object [] out_args)
75 InitMessage ((MonoMethod)method, out_args);
80 public MonoMethodMessage (Type type, string method_name, object [] in_args)
82 // fixme: consider arg types
83 MethodInfo minfo = type.GetMethod (method_name);
85 InitMessage ((MonoMethod)minfo, null);
87 int len = in_args.Length;
88 for (int i = 0; i < len; i++) {
89 args [i] = in_args [i];
93 public IDictionary Properties {
95 if (properties == null) properties = new MethodCallDictionary (this);
100 public int ArgCount {
102 if (CallType == CallType.EndInvoke)
112 public object [] Args {
118 public bool HasVarArgs {
124 public LogicalCallContext LogicalCallContext {
134 public MethodBase MethodBase {
140 public string MethodName {
149 public object MethodSignature {
151 if (methodSignature == null) {
152 ParameterInfo[] parameters = method.GetParameters();
153 methodSignature = new Type[parameters.Length];
154 for (int n=0; n<parameters.Length; n++)
155 methodSignature[n] = parameters[n].ParameterType;
157 return methodSignature;
161 public string TypeName {
166 return method.DeclaringType.AssemblyQualifiedName;
180 public object GetArg (int arg_num)
185 return args [arg_num];
188 public string GetArgName (int arg_num)
193 return names [arg_num];
196 public int InArgCount {
198 if (CallType == CallType.EndInvoke)
206 foreach (byte t in arg_types) {
207 if ((t & 1) != 0) count++;
214 public object [] InArgs {
216 int i, j, count = InArgCount;
217 object [] inargs = new object [count];
220 foreach (byte t in arg_types) {
222 inargs [j++] = args [i];
230 public object GetInArg (int arg_num)
233 foreach (byte t in arg_types) {
243 public string GetInArgName (int arg_num)
246 foreach (byte t in arg_types) {
256 public Exception Exception {
262 public int OutArgCount {
269 foreach (byte t in arg_types) {
270 if ((t & 2) != 0) count++;
277 public object [] OutArgs {
282 int i, j, count = OutArgCount;
283 object [] outargs = new object [count];
286 foreach (byte t in arg_types) {
288 outargs [j++] = args [i];
296 public object ReturnValue {
302 public object GetOutArg (int arg_num)
305 foreach (byte t in arg_types) {
315 public string GetOutArgName (int arg_num)
318 foreach (byte t in arg_types) {
328 Identity IInternalMessage.TargetIdentity
330 get { return identity; }
331 set { identity = value; }
336 get { return asyncResult != null; }
339 public AsyncResult AsyncResult
341 get { return asyncResult; }
344 internal CallType CallType
348 // FIXME: ideally, the OneWay type would be set by the runtime
350 if (call_type == CallType.Sync && RemotingServices.IsOneWay (method))
351 call_type = CallType.OneWay;
356 public bool NeedsOutProcessing (out int outCount) {
359 foreach (byte t in arg_types) {
362 else if ((t & 4) != 0)
365 return outCount > 0 || res;
370 internal enum CallType: int