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 {
44 #pragma warning disable 649
45 #region keep in sync with MonoMessage in object-internals.h
49 byte [] arg_types; /* 1 == IN; 2 == OUT; 3 == INOUT; 4 == COPY OUT */
50 public LogicalCallContext ctx;
53 AsyncResult asyncResult;
56 #pragma warning restore 649
60 MethodCallDictionary properties;
62 Type[] methodSignature;
67 [MethodImplAttribute(MethodImplOptions.InternalCall)]
68 internal extern void InitMessage (MonoMethod method, object [] out_args);
70 public MonoMethodMessage (MethodBase method, object [] out_args)
73 InitMessage ((MonoMethod)method, out_args);
78 public MonoMethodMessage (Type type, string method_name, object [] in_args)
80 // fixme: consider arg types
81 MethodInfo minfo = type.GetMethod (method_name);
83 InitMessage ((MonoMethod)minfo, null);
85 int len = in_args.Length;
86 for (int i = 0; i < len; i++) {
87 args [i] = in_args [i];
91 public IDictionary Properties {
93 if (properties == null) properties = new MethodCallDictionary (this);
100 if (CallType == CallType.EndInvoke)
110 public object [] Args {
116 public bool HasVarArgs {
122 public LogicalCallContext LogicalCallContext {
132 public MethodBase MethodBase {
138 public string MethodName {
147 public object MethodSignature {
149 if (methodSignature == null) {
150 ParameterInfo[] parameters = method.GetParameters();
151 methodSignature = new Type[parameters.Length];
152 for (int n=0; n<parameters.Length; n++)
153 methodSignature[n] = parameters[n].ParameterType;
155 return methodSignature;
159 public string TypeName {
164 return method.DeclaringType.AssemblyQualifiedName;
178 public object GetArg (int arg_num)
183 return args [arg_num];
186 public string GetArgName (int arg_num)
191 return names [arg_num];
194 public int InArgCount {
196 if (CallType == CallType.EndInvoke)
204 foreach (byte t in arg_types) {
205 if ((t & 1) != 0) count++;
212 public object [] InArgs {
214 int i, j, count = InArgCount;
215 object [] inargs = new object [count];
218 foreach (byte t in arg_types) {
220 inargs [j++] = args [i];
228 public object GetInArg (int arg_num)
231 foreach (byte t in arg_types) {
241 public string GetInArgName (int arg_num)
244 foreach (byte t in arg_types) {
254 public Exception Exception {
260 public int OutArgCount {
267 foreach (byte t in arg_types) {
268 if ((t & 2) != 0) count++;
275 public object [] OutArgs {
280 int i, j, count = OutArgCount;
281 object [] outargs = new object [count];
284 foreach (byte t in arg_types) {
286 outargs [j++] = args [i];
294 public object ReturnValue {
300 public object GetOutArg (int arg_num)
303 foreach (byte t in arg_types) {
313 public string GetOutArgName (int arg_num)
316 foreach (byte t in arg_types) {
326 Identity IInternalMessage.TargetIdentity
328 get { return identity; }
329 set { identity = value; }
334 get { return asyncResult != null; }
337 public AsyncResult AsyncResult
339 get { return asyncResult; }
342 internal CallType CallType
346 // FIXME: ideally, the OneWay type would be set by the runtime
348 if (call_type == CallType.Sync && RemotingServices.IsOneWay (method))
349 call_type = CallType.OneWay;
354 public bool NeedsOutProcessing (out int outCount) {
357 foreach (byte t in arg_types) {
360 else if ((t & 4) != 0)
363 return outCount > 0 || res;
368 internal enum CallType: int