Merge pull request #556 from jack-pappas/ipproto-patch
[mono.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / MethodResponse.cs
index d2af42fff34b689406bd8e6000635d0a81953922..34d3bfb6b7eb9e314ebf2cd613f5e8bc2920c0ee 100644 (file)
@@ -7,6 +7,29 @@
 // 2002 (C) Copyright, Ximian, Inc.
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System;
 using System.Collections;
 using System.Reflection;
@@ -16,7 +39,8 @@ using System.Runtime.Serialization;
 namespace System.Runtime.Remoting.Messaging {
 
        [Serializable] [CLSCompliant (false)]
-       public class MethodResponse : IMethodReturnMessage, ISerializable, IInternalMessage
+       [System.Runtime.InteropServices.ComVisible (true)]
+       public class MethodResponse : IMethodReturnMessage, ISerializable, IInternalMessage, ISerializationRootObject
        {
                string _methodName;
                string _uri;
@@ -37,7 +61,7 @@ namespace System.Runtime.Remoting.Messaging {
                protected IDictionary ExternalProperties;
                protected IDictionary InternalProperties;
 
-               public MethodResponse (Header[] headers, IMethodCallMessage mcm)
+               public MethodResponse (Header[] h1, IMethodCallMessage mcm)
                {
                        if (mcm != null)
                        {
@@ -49,9 +73,9 @@ namespace System.Runtime.Remoting.Messaging {
                                _args = mcm.Args;
                        }
 
-                       if (headers != null)
+                       if (h1 != null)
                        {
-                               foreach (Header header in headers)
+                               foreach (Header header in h1)
                                        InitMethodProperty (header.Name, header.Value);
                        }
                }
@@ -76,7 +100,7 @@ namespace System.Runtime.Remoting.Messaging {
                        
                        _exception = null;
                        _returnValue = returnValue;
-                       _outArgs = outArgs;
+                       _args = outArgs;
                }
 
                internal MethodResponse (IMethodCallMessage msg, CADMethodReturnMessage retmsg) {
@@ -92,8 +116,11 @@ namespace System.Runtime.Remoting.Messaging {
 
                        _exception = retmsg.GetException (args);
                        _returnValue = retmsg.GetReturnValue (args);
-                       _outArgs = retmsg.GetArgs (args);
+                       _args = retmsg.GetArgs (args);
 
+                       _callContext = retmsg.GetLogicalCallContext (args);
+                       if (_callContext == null) _callContext = new LogicalCallContext ();
+                       
                        if (retmsg.PropertiesCount > 0)
                                CADMessageBase.UnmarshalProperties (Properties, retmsg.PropertiesCount, args);
                }
@@ -113,7 +140,7 @@ namespace System.Runtime.Remoting.Messaging {
                                case "__MethodSignature": _methodSignature = (Type[]) value; break;
                                case "__Uri": _uri = (string) value; break;
                                case "__Return": _returnValue = value; break;
-                               case "__OutArgs": _outArgs = (object[]) value; break;
+                               case "__OutArgs": _args = (object[]) value; break;
                                case "__fault": _exception = (Exception) value; break;
                                case "__CallContext": _callContext = (LogicalCallContext) value; break;
                                default: Properties [key] = value; break;
@@ -143,21 +170,26 @@ namespace System.Runtime.Remoting.Messaging {
                
                public bool HasVarArgs {
                        get { 
-                               return false;   // TODO: implement var args
+                               return (MethodBase.CallingConvention | CallingConventions.VarArgs) != 0;
                        }
                }
                
                public LogicalCallContext LogicalCallContext {
-                       get { 
+                       get {
+                               if (_callContext == null)
+                                       _callContext = new LogicalCallContext ();
                                return _callContext;
                        }
                }
                
                public MethodBase MethodBase {
                        get { 
-                               if (null == _methodBase && null != _callMsg)
-                                       _methodBase = _callMsg.MethodBase;
-
+                               if (null == _methodBase) {
+                                       if (_callMsg != null)
+                                               _methodBase = _callMsg.MethodBase;
+                                       else if (MethodName != null && TypeName != null)
+                                               _methodBase = RemotingServices.GetMethodBaseFromMethodMessage (this);
+                               }
                                return _methodBase;
                        }
                }
@@ -182,18 +214,18 @@ namespace System.Runtime.Remoting.Messaging {
 
                public int OutArgCount {
                        get { 
-                               if (null == _outArgs)
-                                       return 0;
-
-                               return _outArgs.Length;
+                               if (_args == null || _args.Length == 0) return 0;
+                               if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
+                               return _inArgInfo.GetInOutArgCount ();
                        }
                }
 
                public object[] OutArgs {
                        get { 
-                               if (null == _outArgs)
-                                       return new object[0];
-
+                               if (_outArgs == null && _args != null) {
+                                       if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
+                                       _outArgs = _inArgInfo.GetInOutArgs (_args);
+                               }                                       
                                return _outArgs;
                        }
                }
@@ -238,17 +270,22 @@ namespace System.Runtime.Remoting.Messaging {
                        }
                }
 
+               string IInternalMessage.Uri {
+                       get { return Uri; }
+                       set { Uri = value; }
+               }
+
                public object GetArg (int argNum)
                {
-                       if (null == _outArgs)
+                       if (null == _args)
                                return null;
 
-                       return _outArgs [argNum];
+                       return _args [argNum];
                }
 
                public string GetArgName (int index)
                {
-                       throw new NotSupportedException ();
+                       return MethodBase.GetParameters()[index].Name;
                }
 
                public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
@@ -260,7 +297,7 @@ namespace System.Runtime.Remoting.Messaging {
                                info.AddValue ("__MethodSignature", _methodSignature);
                                info.AddValue ("__Uri", _uri);
                                info.AddValue ("__Return", _returnValue);
-                               info.AddValue ("__OutArgs", _outArgs);
+                               info.AddValue ("__OutArgs", _args);
                        }
                        else
                                info.AddValue ("__fault", _exception);
@@ -275,10 +312,9 @@ namespace System.Runtime.Remoting.Messaging {
 
                public object GetOutArg (int argNum)
                {
-                       if (null == _methodBase)
-                               return null;
-
-                       return _outArgs [argNum];
+                       if (_args == null) return null;
+                       if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
+                       return _args[_inArgInfo.GetInOutArgIndex (argNum)];
                }
 
                public string GetOutArgName (int index)
@@ -297,7 +333,7 @@ namespace System.Runtime.Remoting.Messaging {
                }
 
                [MonoTODO]
-               public void RootSetObjectData (SerializationInfo info, StreamingContext context)
+               public void RootSetObjectData (SerializationInfo info, StreamingContext ctx)
                {
                        throw new NotImplementedException ();
                } 
@@ -307,5 +343,6 @@ namespace System.Runtime.Remoting.Messaging {
                        get { return _targetIdentity; }
                        set { _targetIdentity = value; }
                }
+
        }
 }