2 // System.Runtime.Remoting.Channels.Ipc.Unix.IpcClientChannel.cs
4 // Author: Robert Jordan (robertj@gmx.net)
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Collections
;
34 using System
.Runtime
.Remoting
;
35 using System
.Runtime
.Remoting
.Messaging
;
36 using Win32
= System
.Runtime
.Remoting
.Channels
.Ipc
.Win32
;
38 namespace System
.Runtime
.Remoting
.Channels
.Ipc
.Unix
40 internal class IpcClientChannel
: IChannelSender
, IChannel
44 public IpcClientChannel ()
46 _innerChannel
= Activator
.CreateInstance(UnixChannelLoader
.LoadClientChannel ());
49 public IpcClientChannel (IDictionary properties
,
50 IClientChannelSinkProvider sinkProvider
)
52 _innerChannel
= Activator
.CreateInstance(UnixChannelLoader
.LoadClientChannel (), new object [] {properties, sinkProvider}
);
55 public IpcClientChannel (string name
,
56 IClientChannelSinkProvider sinkProvider
)
58 _innerChannel
= Activator
.CreateInstance(UnixChannelLoader
.LoadClientChannel (), new object [] {name, sinkProvider}
);
61 public string ChannelName
63 get { return ((IChannel)_innerChannel).ChannelName; }
66 public int ChannelPriority
68 get { return ((IChannel)_innerChannel).ChannelPriority; }
71 public string Parse (string url
, out string objectUri
)
73 return Win32
.IpcChannelHelper
.Parse (url
, out objectUri
);
78 // Converts an ipc URL to a unix URL.
79 // Returns the URL unchanged if it was not ipc.
81 internal static string IpcToUnix (string url
)
88 Win32
.IpcChannelHelper
.Parse (url
, out portName
, out objectUri
);
89 if (objectUri
!= null)
90 url
= "unix://" + Path
.Combine (Path
.GetTempPath (), portName
) + "?" + objectUri
;
94 public IMessageSink
CreateMessageSink(string url
,
95 object remoteChannelData
,
98 url
= IpcToUnix (url
);
99 IMessageSink sink
= ((IChannelSender
)_innerChannel
).CreateMessageSink (url
, remoteChannelData
, out objectUri
);
102 return new UrlMapperSink (sink
);
110 // Simple message sink that changes ipc URLs to unix URLs.
112 sealed class UrlMapperSink
: IMessageSink
114 readonly IMessageSink _sink
;
116 public UrlMapperSink (IMessageSink sink
)
121 public IMessageSink NextSink
123 get { return _sink.NextSink; }
126 static void ChangeUri (IMessage msg
)
128 string uri
= msg
.Properties
["__Uri"] as string;
130 msg
.Properties
["__Uri"] = IpcClientChannel
.IpcToUnix (uri
);
134 public IMessage
SyncProcessMessage(IMessage msg
)
137 return _sink
.SyncProcessMessage (msg
);
140 public IMessageCtrl
AsyncProcessMessage(IMessage msg
,
141 IMessageSink replySink
)
144 return _sink
.AsyncProcessMessage (msg
, replySink
);