Make internal abstract methods virtual to fix MethodBase subclassing.
[mono.git] / mcs / class / Mono.Posix / Mono.Remoting.Channels.Unix / UnixClientChannel.cs
1 //
2 // Mono.Remoting.Channels.Unix.UnixClientChannel.cs
3 //
4 // Author: Dietmar Maurer (dietmar@ximian.com)
5 //     Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System;
32 using System.Collections;
33 using System.IO;
34 using System.Net.Sockets;
35 using System.Runtime.Remoting.Messaging;
36 using System.Runtime.Remoting.Channels;
37 using System.Threading;
38
39 namespace Mono.Remoting.Channels.Unix
40 {
41     public class UnixClientChannel : IChannelSender, IChannel
42     {
43         int priority = 1;                    
44         string name = "unix";
45         IClientChannelSinkProvider _sinkProvider;
46         
47         public UnixClientChannel ()
48         {
49             _sinkProvider = new UnixBinaryClientFormatterSinkProvider ();
50             _sinkProvider.Next = new UnixClientTransportSinkProvider ();
51         }
52
53         public UnixClientChannel (IDictionary properties, IClientChannelSinkProvider sinkProvider)
54         {
55             object val = properties ["name"];
56             if (val != null) name = val as string;
57             
58             val = properties ["priority"];
59             if (val != null) priority = Convert.ToInt32 (val);
60             
61             if (sinkProvider != null)
62             {
63                 _sinkProvider = sinkProvider;
64
65                 // add the unix provider at the end of the chain
66                 IClientChannelSinkProvider prov = sinkProvider;
67                 while (prov.Next != null) prov = prov.Next;
68                 prov.Next = new UnixClientTransportSinkProvider ();
69
70                 // Note: a default formatter is added only when
71                 // no sink providers are specified in the config file.
72             }
73             else
74             {
75                 _sinkProvider = new UnixBinaryClientFormatterSinkProvider ();
76                 _sinkProvider.Next = new UnixClientTransportSinkProvider ();
77             }
78
79         }
80
81         public UnixClientChannel (string name, IClientChannelSinkProvider sinkProvider)
82         {
83             this.name = name;
84             _sinkProvider = sinkProvider;
85
86             // add the unix provider at the end of the chain
87             IClientChannelSinkProvider prov = sinkProvider;
88             while (prov.Next != null) prov = prov.Next;
89             prov.Next = new UnixClientTransportSinkProvider ();
90         }
91         
92         public string ChannelName
93         {
94             get {
95                 return name;
96             }
97         }
98
99         public int ChannelPriority
100         {
101             get {
102                 return priority;
103             }
104         }
105
106         public IMessageSink CreateMessageSink (string url,
107                                                object remoteChannelData,
108                                                out string objectURI)
109         {
110             if (url != null && Parse (url, out objectURI) != null)
111                 return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
112                                                                                 
113             if (remoteChannelData != null) {
114                 IChannelDataStore ds = remoteChannelData as IChannelDataStore;
115                 if (ds != null && ds.ChannelUris.Length > 0)
116                     url = ds.ChannelUris [0];
117                 else {
118                     objectURI = null;
119                     return null;
120                 }
121             }
122             
123             if (Parse (url, out objectURI) == null)
124                 return null;
125
126             return (IMessageSink) _sinkProvider.CreateSink (this, url, remoteChannelData);
127         }
128
129         public string Parse (string url, out string objectURI)
130         {
131             return UnixChannel.ParseUnixURL (url, out objectURI);
132         }
133     }
134 }