(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / System.Runtime.Remoting.Messaging / MethodResponse.cs
blob36390441e47b99c5f179c17488bb73728e5b5e7b
1 //
2 // System.Runtime.Remoting.Messaging.MethodResponse.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 // Patrik Torstensson
6 //
7 // 2002 (C) Copyright, Ximian, Inc.
8 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System;
34 using System.Collections;
35 using System.Reflection;
36 using System.Runtime.Remoting;
37 using System.Runtime.Serialization;
39 namespace System.Runtime.Remoting.Messaging {
41 [Serializable] [CLSCompliant (false)]
42 public class MethodResponse : IMethodReturnMessage, ISerializable, IInternalMessage, ISerializationRootObject
44 string _methodName;
45 string _uri;
46 string _typeName;
47 MethodBase _methodBase;
49 object _returnValue;
50 Exception _exception;
51 Type [] _methodSignature;
52 ArgInfo _inArgInfo;
54 object [] _args;
55 object [] _outArgs;
56 IMethodCallMessage _callMsg;
57 LogicalCallContext _callContext;
58 Identity _targetIdentity;
60 protected IDictionary ExternalProperties;
61 protected IDictionary InternalProperties;
63 public MethodResponse (Header[] headers, IMethodCallMessage mcm)
65 if (mcm != null)
67 _methodName = mcm.MethodName;
68 _uri = mcm.Uri;
69 _typeName = mcm.TypeName;
70 _methodBase = mcm.MethodBase;
71 _methodSignature = (Type[]) mcm.MethodSignature;
72 _args = mcm.Args;
75 if (headers != null)
77 foreach (Header header in headers)
78 InitMethodProperty (header.Name, header.Value);
82 internal MethodResponse (Exception e, IMethodCallMessage msg) {
83 _callMsg = msg;
85 if (null != msg)
86 _uri = msg.Uri;
87 else
88 _uri = String.Empty;
90 _exception = e;
91 _returnValue = null;
92 _outArgs = new object[0]; // .NET does this
95 internal MethodResponse (object returnValue, object [] outArgs, LogicalCallContext callCtx, IMethodCallMessage msg) {
96 _callMsg = msg;
98 _uri = msg.Uri;
100 _exception = null;
101 _returnValue = returnValue;
102 _args = outArgs;
105 internal MethodResponse (IMethodCallMessage msg, CADMethodReturnMessage retmsg) {
106 _callMsg = msg;
108 _methodBase = msg.MethodBase;
109 //_typeName = msg.TypeName;
110 _uri = msg.Uri;
111 _methodName = msg.MethodName;
113 // Get unmarshalled arguments
114 ArrayList args = retmsg.GetArguments ();
116 _exception = retmsg.GetException (args);
117 _returnValue = retmsg.GetReturnValue (args);
118 _args = retmsg.GetArgs (args);
120 _callContext = retmsg.GetLogicalCallContext (args);
121 if (_callContext == null) _callContext = new LogicalCallContext ();
123 if (retmsg.PropertiesCount > 0)
124 CADMessageBase.UnmarshalProperties (Properties, retmsg.PropertiesCount, args);
127 internal MethodResponse (SerializationInfo info, StreamingContext context)
129 foreach (SerializationEntry entry in info)
130 InitMethodProperty (entry.Name, entry.Value);
133 internal void InitMethodProperty (string key, object value)
135 switch (key)
137 case "__TypeName": _typeName = (string) value; break;
138 case "__MethodName": _methodName = (string) value; break;
139 case "__MethodSignature": _methodSignature = (Type[]) value; break;
140 case "__Uri": _uri = (string) value; break;
141 case "__Return": _returnValue = value; break;
142 case "__OutArgs": _args = (object[]) value; break;
143 case "__fault": _exception = (Exception) value; break;
144 case "__CallContext": _callContext = (LogicalCallContext) value; break;
145 default: Properties [key] = value; break;
149 public int ArgCount {
150 get {
151 if (null == _args)
152 return 0;
154 return _args.Length;
158 public object[] Args {
159 get {
160 return _args;
164 public Exception Exception {
165 get {
166 return _exception;
170 public bool HasVarArgs {
171 get {
172 return (MethodBase.CallingConvention | CallingConventions.VarArgs) != 0;
176 public LogicalCallContext LogicalCallContext {
177 get {
178 return _callContext;
182 public MethodBase MethodBase {
183 get {
184 if (null == _methodBase) {
185 if (_callMsg != null)
186 _methodBase = _callMsg.MethodBase;
187 else if (MethodName != null && TypeName != null)
188 _methodBase = RemotingServices.GetMethodBaseFromMethodMessage (this);
190 return _methodBase;
194 public string MethodName {
195 get {
196 if (null == _methodName && null != _callMsg)
197 _methodName = _callMsg.MethodName;
199 return _methodName;
203 public object MethodSignature {
204 get {
205 if (null == _methodSignature && null != _callMsg)
206 _methodSignature = (Type []) _callMsg.MethodSignature;
208 return _methodSignature;
212 public int OutArgCount {
213 get {
214 if (_args == null || _args.Length == 0) return 0;
215 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
216 return _inArgInfo.GetInOutArgCount ();
220 public object[] OutArgs {
221 get {
222 if (_outArgs == null && _args != null) {
223 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
224 _outArgs = _inArgInfo.GetInOutArgs (_args);
226 return _outArgs;
230 public virtual IDictionary Properties {
231 get {
232 if (null == ExternalProperties) {
233 MethodReturnDictionary properties = new MethodReturnDictionary (this);
234 ExternalProperties = properties;
235 InternalProperties = properties.GetInternalProperties();
238 return ExternalProperties;
242 public object ReturnValue {
243 get {
244 return _returnValue;
248 public string TypeName {
249 get {
250 if (null == _typeName && null != _callMsg)
251 _typeName = _callMsg.TypeName;
253 return _typeName;
257 public string Uri {
258 get {
259 if (null == _uri && null != _callMsg)
260 _uri = _callMsg.Uri;
262 return _uri;
265 set {
266 _uri = value;
270 public object GetArg (int argNum)
272 if (null == _args)
273 return null;
275 return _args [argNum];
278 public string GetArgName (int index)
280 return MethodBase.GetParameters()[index].Name;
283 public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
285 if (_exception == null)
287 info.AddValue ("__TypeName", _typeName);
288 info.AddValue ("__MethodName", _methodName);
289 info.AddValue ("__MethodSignature", _methodSignature);
290 info.AddValue ("__Uri", _uri);
291 info.AddValue ("__Return", _returnValue);
292 info.AddValue ("__OutArgs", _args);
294 else
295 info.AddValue ("__fault", _exception);
297 info.AddValue ("__CallContext", _callContext);
299 if (InternalProperties != null) {
300 foreach (DictionaryEntry entry in InternalProperties)
301 info.AddValue ((string) entry.Key, entry.Value);
305 public object GetOutArg (int argNum)
307 if (_args == null) return null;
308 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
309 return _args[_inArgInfo.GetInOutArgIndex (argNum)];
312 public string GetOutArgName (int index)
314 if (null == _methodBase)
315 return "__method_" + index;
317 if (_inArgInfo == null) _inArgInfo = new ArgInfo (MethodBase, ArgInfoType.Out);
318 return _inArgInfo.GetInOutArgName(index);
321 [MonoTODO]
322 public virtual object HeaderHandler (Header[] h)
324 throw new NotImplementedException ();
327 [MonoTODO]
328 public void RootSetObjectData (SerializationInfo info, StreamingContext context)
330 throw new NotImplementedException ();
333 Identity IInternalMessage.TargetIdentity
335 get { return _targetIdentity; }
336 set { _targetIdentity = value; }
339 public override string ToString ()
341 string s = _typeName.Split(',')[0] + "." + _methodName + " (";
342 if (_exception != null)
344 s += "Exception\n)" + _exception;
346 else
348 if (_args != null)
350 for (int n=0; n<_args.Length; n++)
352 if (n>0) s+= ", ";
353 if (_args[n] != null) s += _args[n].GetType().Name + " ";
354 s += GetOutArgName (n);
355 if (_args[n] != null) s += " = {" + _args[n] + "}";
356 else s+=" = {null}";
359 s += ")";
361 return s;