2009-05-26 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / OneWayBindingElement.cs
1 //
2 // OneWayBindingElement.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
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 using System;
29 using System.Collections.Generic;
30 using System.ServiceModel.Description;
31 using System.ServiceModel.Security;
32 using System.ServiceModel.Channels;
33
34 namespace System.ServiceModel.Channels
35 {
36         public sealed class OneWayBindingElement : BindingElement
37         {
38                 public OneWayBindingElement ()
39                 {
40                         pool = new ChannelPoolSettings ();
41                 }
42
43                 OneWayBindingElement (OneWayBindingElement other)
44                 {
45                         pool = new ChannelPoolSettings (other.pool);
46                 }
47
48                 ChannelPoolSettings pool;
49
50                 public ChannelPoolSettings ChannelPoolSettings {
51                         get { return pool; }
52                 }
53
54                 [MonoTODO ("It generates just pass-thru factory")]
55                 public override IChannelFactory<TChannel>
56                         BuildChannelFactory<TChannel> (BindingContext context)
57                 {
58                         if (typeof (TChannel) == typeof (IOutputSessionChannel) ||
59                             typeof (TChannel) == typeof (IOutputChannel))
60                                 return new OneWayChannelFactory<TChannel> (context.BuildInnerChannelFactory<TChannel> ());
61                         throw new ArgumentException (String.Format ("The requested channel type '{0}' is not supported by this binding element", typeof (TChannel)));
62                 }
63
64                 [MonoTODO ("It generates just pass-thru listener")]
65                 public override IChannelListener<TChannel>
66                         BuildChannelListener<TChannel> (
67                         BindingContext context)
68                 {
69                         if (typeof (TChannel) == typeof (IInputSessionChannel) ||
70                             typeof (TChannel) == typeof (IInputChannel))
71                                 return new OneWayChannelListener<TChannel> (context.BuildInnerChannelListener<TChannel> ());
72                         throw new ArgumentException (String.Format ("The requested channel type '{0}' is not supported by this binding element", typeof (TChannel)));
73                 }
74
75                 public override bool CanBuildChannelFactory<TChannel> (
76                         BindingContext context)
77                 {
78                         return typeof (TChannel) == typeof (IOutputSessionChannel) ||
79                                 typeof (TChannel) == typeof (IOutputChannel);
80                 }
81
82                 public override bool CanBuildChannelListener<TChannel> (
83                         BindingContext context)
84                 {
85                         return typeof (TChannel) == typeof (IInputSessionChannel) ||
86                                 typeof (TChannel) == typeof (IInputChannel);
87                 }
88
89                 public override BindingElement Clone ()
90                 {
91                         return new OneWayBindingElement (this);
92                 }
93
94                 [MonoTODO]
95                 public override T GetProperty<T> (BindingContext context)
96                 {
97                         throw new NotImplementedException ();
98                 }
99         }
100
101         class OneWayChannelFactory<TChannel> : ChannelFactoryBase<TChannel>
102         {
103                 IChannelFactory<TChannel> inner;
104
105                 public OneWayChannelFactory (IChannelFactory<TChannel> inner)
106                 {
107                         this.inner = inner;
108                 }
109
110                 protected override TChannel OnCreateChannel (EndpointAddress address, Uri via)
111                 {
112                         return inner.CreateChannel (address, via);
113                 }
114
115                 protected override void OnOpen (TimeSpan timeout)
116                 {
117                         inner.Open (timeout);
118                 }
119
120                 protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
121                 {
122                         return inner.BeginOpen (timeout, callback, state);
123                 }
124
125                 protected override void OnEndOpen (IAsyncResult result)
126                 {
127                         inner.EndOpen (result);
128                 }
129
130                 protected override void OnClose (TimeSpan timeout)
131                 {
132                         inner.Close (timeout);
133                 }
134
135                 protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
136                 {
137                         return inner.BeginClose (timeout, callback, state);
138                 }
139
140                 protected override void OnEndClose (IAsyncResult result)
141                 {
142                         inner.EndClose (result);
143                 }
144         }
145
146         class OneWayChannelListener<TChannel> : ChannelListenerBase<TChannel>
147                 where TChannel : class, IChannel
148         {
149                 IChannelListener<TChannel> inner;
150
151                 public OneWayChannelListener (IChannelListener<TChannel> inner)
152                 {
153                         this.inner = inner;
154                 }
155
156                 public override Uri Uri {
157                         get { return inner.Uri; }
158                 }
159
160                 protected override void OnAbort ()
161                 {
162                         inner.Abort ();
163                 }
164
165                 protected override void OnOpen (TimeSpan timeout)
166                 {
167                         inner.Open (timeout);
168                 }
169
170                 protected override IAsyncResult OnBeginOpen (TimeSpan timeout, AsyncCallback callback, object state)
171                 {
172                         return inner.BeginOpen (timeout, callback, state);
173                 }
174
175                 protected override void OnEndOpen (IAsyncResult result)
176                 {
177                         inner.EndOpen (result);
178                 }
179
180                 protected override void OnClose (TimeSpan timeout)
181                 {
182                         inner.Close (timeout);
183                 }
184
185                 protected override IAsyncResult OnBeginClose (TimeSpan timeout, AsyncCallback callback, object state)
186                 {
187                         return inner.BeginClose (timeout, callback, state);
188                 }
189
190                 protected override void OnEndClose (IAsyncResult result)
191                 {
192                         inner.EndClose (result);
193                 }
194
195                 protected override bool OnWaitForChannel (TimeSpan timeout)
196                 {
197                         return inner.WaitForChannel (timeout);
198                 }
199
200                 protected override IAsyncResult OnBeginWaitForChannel (TimeSpan timeout, AsyncCallback callback, object state)
201                 {
202                         return inner.BeginWaitForChannel (timeout, callback, state);
203                 }
204
205                 protected override bool OnEndWaitForChannel (IAsyncResult result)
206                 {
207                         return inner.EndWaitForChannel (result);
208                 }
209
210                 protected override TChannel OnAcceptChannel (TimeSpan timeout)
211                 {
212                         return inner.AcceptChannel (timeout);
213                 }
214
215                 protected override IAsyncResult OnBeginAcceptChannel (TimeSpan timeout, AsyncCallback callback, object state)
216                 {
217                         return inner.BeginAcceptChannel (timeout, callback, state);
218                 }
219
220                 protected override TChannel OnEndAcceptChannel (IAsyncResult result)
221                 {
222                         return inner.EndAcceptChannel (result);
223                 }
224         }
225 }