Merge pull request #1156 from felfert/master
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.Ipc / IpcChannel.cs
1 //\r
2 // System.Runtime.Remoting.Channels.Ipc.IpcChannel.cs\r
3 //\r
4 // Author: Robert Jordan (robertj@gmx.net)\r
5 //\r
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)\r
7 //\r
8 //\r
9 // Permission is hereby granted, free of charge, to any person obtaining\r
10 // a copy of this software and associated documentation files (the\r
11 // "Software"), to deal in the Software without restriction, including\r
12 // without limitation the rights to use, copy, modify, merge, publish,\r
13 // distribute, sublicense, and/or sell copies of the Software, and to\r
14 // permit persons to whom the Software is furnished to do so, subject to\r
15 // the following conditions:\r
16 // \r
17 // The above copyright notice and this permission notice shall be\r
18 // included in all copies or substantial portions of the Software.\r
19 // \r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
27 //\r
28 \r
29 \r
30 using System;\r
31 using System.Collections;\r
32 using System.Runtime.Remoting;\r
33 using System.Runtime.Remoting.Messaging;\r
34 \r
35 using Unix  = System.Runtime.Remoting.Channels.Ipc.Unix;\r
36 using Win32 = System.Runtime.Remoting.Channels.Ipc.Win32;\r
37 \r
38 namespace System.Runtime.Remoting.Channels.Ipc\r
39 {\r
40         public class IpcChannel : IChannelReceiver, IChannelSender, IChannel\r
41         {\r
42                 IChannel _innerChannel;\r
43 \r
44                 internal static bool IsUnix\r
45                 {\r
46                         get { \r
47                                 int p = (int) Environment.OSVersion.Platform;\r
48                                 return ((p == 4) || (p == 128) || (p == 6));\r
49                         }\r
50                 }\r
51 \r
52                 public IpcChannel ()\r
53                 {\r
54                         if (IsUnix)\r
55                                 _innerChannel = new Unix.IpcChannel ();\r
56                         else\r
57                                 _innerChannel = new Win32.IpcChannel ();\r
58                 }\r
59 \r
60                 public IpcChannel (string portName)\r
61                 {\r
62                         if (IsUnix)\r
63                                 _innerChannel = new Unix.IpcChannel (portName);\r
64                         else\r
65                                 _innerChannel = new Win32.IpcChannel (portName);\r
66                 }\r
67 \r
68                 public IpcChannel (IDictionary properties,\r
69                                    IClientChannelSinkProvider clientSinkProvider,\r
70                                    IServerChannelSinkProvider serverSinkProvider)\r
71                 {\r
72                         if (IsUnix)\r
73                                 _innerChannel = new Unix.IpcChannel (properties, clientSinkProvider, serverSinkProvider);\r
74                         else\r
75                                 _innerChannel = new Win32.IpcChannel (properties, clientSinkProvider, serverSinkProvider);\r
76                 }\r
77 \r
78                 public string ChannelName\r
79                 {\r
80                         get { return _innerChannel.ChannelName; }\r
81                 }\r
82 \r
83                 public int ChannelPriority\r
84                 {\r
85                         get { return _innerChannel.ChannelPriority; }\r
86                 }\r
87 \r
88                 public string Parse (string url, out string objectURI)\r
89                 {\r
90                         return _innerChannel.Parse (url, out objectURI);\r
91                 }\r
92 \r
93                 public IMessageSink CreateMessageSink (string url,\r
94                                                        object remoteChannelData,\r
95                                                        out string objectURI)\r
96                 {\r
97                         return ((IChannelSender)_innerChannel).CreateMessageSink (url, remoteChannelData, out  objectURI);\r
98                 }\r
99 \r
100                 public object ChannelData\r
101                 {\r
102                         get { return ((IChannelReceiver)_innerChannel).ChannelData; }\r
103                 }\r
104 \r
105                 public string[] GetUrlsForUri (string objectURI)\r
106                 {\r
107                         return ((IChannelReceiver)_innerChannel).GetUrlsForUri (objectURI);\r
108                 }\r
109 \r
110                 public void StartListening (object data)\r
111                 {\r
112                         ((IChannelReceiver)_innerChannel).StartListening (data);\r
113                 }\r
114 \r
115                 public void StopListening (object data)\r
116                 {\r
117                         ((IChannelReceiver)_innerChannel).StopListening (data);\r
118                 }\r
119 \r
120         }\r
121 }\r
122 \r