2 // Mono.Remoting.Channels.Unix.UnixChannel.cs
4 // Author: Rodrigo Moya (rodrigo@ximian.com)
5 // Lluis Sanchez Gual (lluis@ideary.com)
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Collections
;
33 using System
.Runtime
.Remoting
.Messaging
;
34 using System
.Runtime
.Remoting
.Channels
;
35 using System
.Text
.RegularExpressions
;
37 namespace Mono
.Remoting
.Channels
.Unix
39 public class UnixChannel
: IChannelReceiver
, IChannel
, IChannelSender
41 private UnixClientChannel _clientChannel
;
42 private UnixServerChannel _serverChannel
= null;
43 private string _name
= "unix";
44 private int _priority
= 1;
46 public UnixChannel (): this (null)
50 public UnixChannel (string path
)
52 Hashtable ht
= new Hashtable();
57 void Init (IDictionary properties
, IClientChannelSinkProvider clientSink
, IServerChannelSinkProvider serverSink
)
59 _clientChannel
= new UnixClientChannel (properties
,clientSink
);
61 if(properties
["path"] != null)
62 _serverChannel
= new UnixServerChannel(properties
, serverSink
);
64 object val
= properties
["name"];
65 if (val
!= null) _name
= val
as string;
67 val
= properties
["priority"];
68 if (val
!= null) _priority
= Convert
.ToInt32 (val
);
72 public UnixChannel (IDictionary properties
,
73 IClientChannelSinkProvider clientSinkProvider
,
74 IServerChannelSinkProvider serverSinkProvider
)
76 Init (properties
, clientSinkProvider
, serverSinkProvider
);
79 public IMessageSink
CreateMessageSink(string url
, object remoteChannelData
, out string objectURI
)
81 return _clientChannel
.CreateMessageSink(url
, remoteChannelData
, out objectURI
);
84 public string ChannelName
89 public int ChannelPriority
91 get { return _priority; }
94 public void StartListening (object data
)
96 if (_serverChannel
!= null) _serverChannel
.StartListening (data
);
99 public void StopListening (object data
)
101 if (_serverChannel
!= null) _serverChannel
.StopListening(data
);
104 public string[] GetUrlsForUri (string uri
)
106 if (_serverChannel
!= null) return _serverChannel
.GetUrlsForUri(uri
);
110 public object ChannelData
114 if (_serverChannel
!= null) return _serverChannel
.ChannelData
;
119 public string Parse (string url
, out string objectURI
)
121 return UnixChannel
.ParseUnixURL (url
, out objectURI
);
124 internal static string ParseUnixURL (string url
, out string objectURI
)
126 // format: "unix:///path/to/unix/socket?/path/to/object"
130 if (!url
.StartsWith ("unix://")) return null;
132 int i
= url
.IndexOf ('?');
133 if (i
== -1) return url
.Substring (7);
135 objectURI
= url
.Substring (i
+1);
137 if (objectURI
.Length
== 0)
140 return url
.Substring (7, i
- 7);