Merge pull request #1323 from StephenMcConnel/bug-23591
[mono.git] / mcs / class / System.Runtime.Remoting / System.Runtime.Remoting.Channels.CORBA / CORBAChannel.cs
1 //
2 // System.Runtime.Remoting.Channels.CORBA.CORBAChannel.cs
3 //
4 // Author: Dietmar Maurer (dietmar@ximian.com)
5 //
6 // 2002 (C) Copyright, Ximian, Inc.
7 //
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System.Collections;
31 using System.Runtime.Remoting.Messaging;
32 using System.Text.RegularExpressions;
33
34 namespace System.Runtime.Remoting.Channels.CORBA
35 {
36         public class CORBAChannel : IChannelReceiver, IChannel,
37                 IChannelSender
38         {
39                 CORBAServerChannel svr_chnl;
40                 CORBAClientChannel cnt_chnl;
41                 
42                 string name = "corba";
43
44                 public CORBAChannel ()
45                 {
46                         svr_chnl = new CORBAServerChannel (0);
47                         cnt_chnl = new CORBAClientChannel ();
48                 }
49
50                 public CORBAChannel (int port)
51                 {
52                         svr_chnl = new CORBAServerChannel (port);
53                         cnt_chnl = new CORBAClientChannel ();
54                 }
55
56                 [MonoTODO]
57                 public CORBAChannel (IDictionary properties,
58                                       IClientChannelSinkProvider clientSinkProvider,
59                                       IServerChannelSinkProvider serverSinkProvider)
60                 {
61                         throw new NotImplementedException ();
62                 }
63
64                 public object ChannelData
65                 {
66                         get {
67                                 return svr_chnl.ChannelData;
68                         }
69                 }
70
71                 public string ChannelName
72                 {
73                         get {
74                                 return name;
75                         }
76                 }
77
78                 public int ChannelPriority
79                 {
80                         get {
81                                 return svr_chnl.ChannelPriority;
82                         }
83                 }
84
85                 public IMessageSink CreateMessageSink (string url,
86                                                        object remoteChannelData,
87                                                        out string objectURI)
88                 {
89                         return cnt_chnl.CreateMessageSink (url, remoteChannelData, out objectURI);
90                 }
91
92                 public string[] GetUrlsForUri (string objectURI)
93                 {
94                         return svr_chnl.GetUrlsForUri (objectURI);
95                 }
96
97                 public string Parse (string url, out string objectURI)
98                 {
99                         return svr_chnl.Parse (url, out objectURI);
100                 }
101
102                 public void StartListening (object data)
103                 {
104                         svr_chnl.StartListening (data);
105                 }
106
107                 public void StopListening (object data)
108                 {
109                         svr_chnl.StopListening (data);
110                 }
111
112                 internal static string ParseCORBAURL (string url, out string objectURI, out int port)
113                 {
114                         // format: "corba://host:port/path/to/object"
115                         
116                         objectURI = null;
117                         port = 0;
118                         
119                         Match m = Regex.Match (url, "corba://([^:]+):([0-9]+)(/.*)");
120
121                         if (!m.Success)
122                                 return null;
123                         
124                         string host = m.Groups[1].Value;
125                         string port_str = m.Groups[2].Value;
126                         objectURI = m.Groups[3].Value;
127                         port = Convert.ToInt32 (port_str);
128                                 
129                         return host;
130                 }
131         }
132 }