(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / System.Runtime.Remoting.Contexts / CrossContextChannel.cs
blob3457f1bd381557a9a76a31c2c6f0dc9b2fb3c200
1 //
2 // System.Runtime.Remoting.Contexts.CrossContextChannel.cs
3 //
4 // Author: Lluis Sanchez Gual (lluis@ideary.com)
5 //
6 // (C) 2002, Lluis Sanchez Gual
7 //
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.Threading;
34 using System.Runtime.Remoting.Messaging;
35 using System.Runtime.Remoting.Activation;
36 using System.Runtime.Remoting.Channels;
38 namespace System.Runtime.Remoting.Contexts
40 internal class CrossContextChannel: IMessageSink
42 public IMessage SyncProcessMessage (IMessage msg)
44 ServerIdentity identity = (ServerIdentity) RemotingServices.GetMessageTargetIdentity (msg);
46 Context oldContext = null;
47 IMessage response;
49 if (Threading.Thread.CurrentContext != identity.Context)
50 oldContext = Context.SwitchToContext (identity.Context);
52 try
54 Context.NotifyGlobalDynamicSinks (true, msg, false, false);
55 Thread.CurrentContext.NotifyDynamicSinks (true, msg, false, false);
57 response = identity.Context.GetServerContextSinkChain().SyncProcessMessage (msg);
59 Context.NotifyGlobalDynamicSinks (false, msg, false, false);
60 Thread.CurrentContext.NotifyDynamicSinks (false, msg, false, false);
62 catch (Exception ex)
64 response = new ReturnMessage (ex, (IMethodCallMessage)msg);
66 finally
68 if (oldContext != null)
69 Context.SwitchToContext (oldContext);
72 return response;
75 public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink)
77 ServerIdentity identity = (ServerIdentity) RemotingServices.GetMessageTargetIdentity (msg);
79 Context oldContext = null;
80 if (Threading.Thread.CurrentContext != identity.Context)
81 oldContext = Context.SwitchToContext (identity.Context);
83 try
85 Context.NotifyGlobalDynamicSinks (true, msg, false, true);
86 Thread.CurrentContext.NotifyDynamicSinks (true, msg, false, false);
87 if (replySink != null) replySink = new ContextRestoreSink (replySink, oldContext, msg);
89 IMessageCtrl res = identity.AsyncObjectProcessMessage (msg, replySink);
91 if (replySink == null)
93 Context.NotifyGlobalDynamicSinks (false, msg, false, false);
94 Thread.CurrentContext.NotifyDynamicSinks (false, msg, false, false);
97 return res;
99 catch (Exception ex)
101 if (replySink != null)
102 replySink.SyncProcessMessage (new ReturnMessage (ex, (IMethodCallMessage)msg));
103 return null;
105 finally
107 if (oldContext != null)
108 Context.SwitchToContext (oldContext);
112 public IMessageSink NextSink
114 get { return null; }
117 class ContextRestoreSink: IMessageSink
119 IMessageSink _next;
120 Context _context;
121 IMessage _call;
123 public ContextRestoreSink (IMessageSink next, Context context, IMessage call)
125 _next = next;
126 _context = context;
127 _call = call;
130 public IMessage SyncProcessMessage (IMessage msg)
134 Context.NotifyGlobalDynamicSinks (false, msg, false, false);
135 Thread.CurrentContext.NotifyDynamicSinks (false, msg, false, false);
136 return _next.SyncProcessMessage (msg);
138 catch (Exception ex)
140 return new ReturnMessage (ex, (IMethodCallMessage)_call);
142 finally
144 if (_context != null)
145 Context.SwitchToContext (_context);
149 public IMessageCtrl AsyncProcessMessage (IMessage msg, IMessageSink replySink)
151 throw new NotSupportedException(); // Not needed
154 public IMessageSink NextSink
156 get { return _next; }