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 #region keep in sync with MonoMessage in object-internals.h
48 byte [] arg_types; /* 1 == IN; 2 == OUT; 3 == INOUT; 4 == COPY OUT */
49 public LogicalCallContext ctx;
52 AsyncResult asyncResult;
58 MethodCallDictionary properties;
60 Type[] methodSignature;
65 [MethodImplAttribute(MethodImplOptions.InternalCall)]
66 internal extern void InitMessage (MonoMethod method, object [] out_args);
68 public MonoMethodMessage (MethodBase method, object [] out_args)
71 InitMessage ((MonoMethod)method, out_args);
76 public MonoMethodMessage (Type type, string method_name, object [] in_args)
78 // fixme: consider arg types
79 MethodInfo minfo = type.GetMethod (method_name);
81 InitMessage ((MonoMethod)minfo, null);
83 int len = in_args.Length;
84 for (int i = 0; i < len; i++) {
85 args [i] = in_args [i];
89 public IDictionary Properties {
91 if (properties == null) properties = new MethodCallDictionary (this);
98 if (CallType == CallType.EndInvoke)
108 public object [] Args {
114 public bool HasVarArgs {
120 public LogicalCallContext LogicalCallContext {
130 public MethodBase MethodBase {
136 public string MethodName {
145 public object MethodSignature {
147 if (methodSignature == null) {
148 ParameterInfo[] parameters = method.GetParameters();
149 methodSignature = new Type[parameters.Length];
150 for (int n=0; n<parameters.Length; n++)
151 methodSignature[n] = parameters[n].ParameterType;
153 return methodSignature;
157 public string TypeName {
162 return method.DeclaringType.AssemblyQualifiedName;
176 public object GetArg (int arg_num)
181 return args [arg_num];
184 public string GetArgName (int arg_num)
189 return names [arg_num];
192 public int InArgCount {
194 if (CallType == CallType.EndInvoke)
202 foreach (byte t in arg_types) {
203 if ((t & 1) != 0) count++;
210 public object [] InArgs {
212 int i, j, count = InArgCount;
213 object [] inargs = new object [count];
216 foreach (byte t in arg_types) {
218 inargs [j++] = args [i];
226 public object GetInArg (int arg_num)
229 foreach (byte t in arg_types) {
239 public string GetInArgName (int arg_num)
242 foreach (byte t in arg_types) {
252 public Exception Exception {
258 public int OutArgCount {
265 foreach (byte t in arg_types) {
266 if ((t & 2) != 0) count++;
273 public object [] OutArgs {
278 int i, j, count = OutArgCount;
279 object [] outargs = new object [count];
282 foreach (byte t in arg_types) {
284 outargs [j++] = args [i];
292 public object ReturnValue {
298 public object GetOutArg (int arg_num)
301 foreach (byte t in arg_types) {
311 public string GetOutArgName (int arg_num)
314 foreach (byte t in arg_types) {
324 Identity IInternalMessage.TargetIdentity
326 get { return identity; }
327 set { identity = value; }
332 get { return asyncResult != null; }
335 public AsyncResult AsyncResult
337 get { return asyncResult; }
340 internal CallType CallType
344 // FIXME: ideally, the OneWay type would be set by the runtime
346 if (call_type == CallType.Sync && RemotingServices.IsOneWay (method))
347 call_type = CallType.OneWay;
352 public bool NeedsOutProcessing (out int outCount) {
355 foreach (byte t in arg_types) {
358 else if ((t & 4) != 0)
361 return outCount > 0 || res;
366 internal enum CallType: int