In Test:
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Ipc.Win32 / IpcChannel.cs
1 //
2 // System.Runtime.Remoting.Channels.Ipc.Win32.IpcChannel.cs
3 //
4 // Author: Robert Jordan (robertj@gmx.net)
5 //
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
7 //
8 //
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:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
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.
27 //
28
29 #if NET_2_0
30
31 using System;
32 using System.Collections;
33 using System.Runtime.Remoting;
34 using System.Runtime.Remoting.Channels;
35 using System.Runtime.Remoting.Messaging;
36
37 namespace System.Runtime.Remoting.Channels.Ipc.Win32
38 {
39     internal class IpcChannel : IChannelSender, IChannelReceiver, IChannel
40     {
41         readonly IpcClientChannel clientChannel;
42         readonly IpcServerChannel serverChannel;
43
44         /// <summary>
45         /// Creates a client channel.
46         /// </summary>
47         public IpcChannel()
48         {
49             clientChannel = new IpcClientChannel();
50         }
51
52         /// <summary>
53         /// Creates a server channel.
54         /// </summary>
55         /// <param name="portName">The port name.</param>
56         public IpcChannel(string portName)
57             : this()
58         {
59             serverChannel = new IpcServerChannel(portName);
60         }
61
62         /// <summary>
63         /// Creates both server and client channels.
64         /// </summary>
65         /// <param name="properties">The channel properties.</param>
66         /// <param name="clientProvider">The client sink provider. It may be <c>null</c>.</param>
67         /// <param name="serverProvider">The server sink provider. It may be <c>null</c>.</param>
68         public IpcChannel(IDictionary properties,
69             IClientChannelSinkProvider clientProvider,
70             IServerChannelSinkProvider serverProvider
71             )
72         {
73             clientChannel = new IpcClientChannel(properties, clientProvider);
74             serverChannel = new IpcServerChannel(properties, serverProvider);
75         }
76
77         #region IChannelSender Members
78
79         public IMessageSink CreateMessageSink(string url, object remoteChannelData, out string objectURI)
80         {
81             return clientChannel.CreateMessageSink(url, remoteChannelData, out objectURI);
82         }
83
84         #endregion
85
86         #region IChannel Members
87
88         public string ChannelName
89         {
90             get
91             {
92                 return serverChannel != null 
93                     ? serverChannel.ChannelName 
94                     : clientChannel.ChannelName;
95             }
96         }
97
98         public int ChannelPriority
99         {
100             get
101             {
102                 return serverChannel != null
103                     ? serverChannel.ChannelPriority 
104                     : clientChannel.ChannelPriority;
105             }
106         }
107
108         public string Parse(string url, out string objectURI)
109         {
110             return IpcChannelHelper.Parse(url, out objectURI);
111         }
112
113         #endregion
114
115         #region IChannelReceiver Members
116
117         public void StartListening(object data)
118         {
119             serverChannel.StartListening(data);
120         }
121
122         public object ChannelData
123         {
124             get
125             {
126                 return serverChannel != null ? serverChannel.ChannelData : null;
127             }
128         }
129
130         public void StopListening(object data)
131         {
132             serverChannel.StopListening(data);
133         }
134
135         public string[] GetUrlsForUri(string objectURI)
136         {
137             return serverChannel.GetUrlsForUri(objectURI);
138         }
139
140         #endregion
141     }
142 }
143
144 #endif