summaryrefslogtreecommitdiff
path: root/csharp/src/IceSSL/EndpointI.cs
blob: d9c10f58e4733388045c1f0fc4e3da3834b4f9d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

namespace IceSSL
{
    using System.Collections.Generic;

    sealed class EndpointI : IceInternal.EndpointI
    {
        internal EndpointI(Instance instance, IceInternal.EndpointI del)
        {
            _instance = instance;
            _delegate = del;
        }

        public override void streamWriteImpl(Ice.OutputStream os)
        {
            _delegate.streamWriteImpl(os);
        }

        private sealed class InfoI : EndpointInfo
        {
            public InfoI(EndpointI e)
            {
                _endpoint = e;
            }

            override public short type()
            {
                return _endpoint.type();
            }

            override public bool datagram()
            {
                return _endpoint.datagram();
            }

            override public bool secure()
            {
                return _endpoint.secure();
            }

            private EndpointI _endpoint;
        }

        public override Ice.EndpointInfo getInfo()
        {
            InfoI info = new InfoI(this);
            info.underlying = _delegate.getInfo();
            info.compress = info.underlying.compress;
            info.timeout = info.underlying.timeout;
            return info;
        }

        public override short type()
        {
            return _delegate.type();
        }

        public override string protocol()
        {
            return _delegate.protocol();
        }

        public override int timeout()
        {
            return _delegate.timeout();
        }

        public override IceInternal.EndpointI timeout(int timeout)
        {
            if(timeout == _delegate.timeout())
            {
                return this;
            }
            else
            {
                return new EndpointI(_instance, _delegate.timeout(timeout));
            }
        }

        public override string connectionId()
        {
            return _delegate.connectionId();
        }

        public override IceInternal.EndpointI connectionId(string connectionId)
        {
            if(connectionId.Equals(_delegate.connectionId()))
            {
                return this;
            }
            else
            {
                return new EndpointI(_instance, _delegate.connectionId(connectionId));
            }
        }

        public override bool compress()
        {
            return _delegate.compress();
        }

        public override IceInternal.EndpointI compress(bool compress)
        {
            if(compress == _delegate.compress())
            {
                return this;
            }
            else
            {
                return new EndpointI(_instance, _delegate.compress(compress));
            }
        }

        public override bool datagram()
        {
            return _delegate.datagram();
        }

        public override bool secure()
        {
            return _delegate.secure();
        }

        public override IceInternal.Transceiver transceiver()
        {
            return null;
        }

        private sealed class EndpointI_connectorsI : IceInternal.EndpointI_connectors
        {
            public EndpointI_connectorsI(Instance instance, string host, IceInternal.EndpointI_connectors cb)
            {
                _instance = instance;
                _host = host;
                _callback = cb;
            }

            public void connectors(List<IceInternal.Connector> connectors)
            {
                List<IceInternal.Connector> l = new List<IceInternal.Connector>();
                foreach(IceInternal.Connector c in connectors)
                {
                    l.Add(new ConnectorI(_instance, c, _host));
                }
                _callback.connectors(l);
            }

            public void exception(Ice.LocalException ex)
            {
                _callback.exception(ex);
            }

            private Instance _instance;
            private string _host;
            private IceInternal.EndpointI_connectors _callback;
        }

        public override void connectors_async(Ice.EndpointSelectionType selType,
                                              IceInternal.EndpointI_connectors callback)
        {
            string host = "";
            for(Ice.EndpointInfo p = _delegate.getInfo(); p != null; p = p.underlying)
            {
                if(p is Ice.IPEndpointInfo)
                {
                    host = ((Ice.IPEndpointInfo)p).host;
                    break;
                }
            }
            _delegate.connectors_async(selType, new EndpointI_connectorsI(_instance, host, callback));
        }

        public override IceInternal.Acceptor acceptor(string adapterName)
        {
            return new AcceptorI(this, _instance, _delegate.acceptor(adapterName), adapterName);
        }

        public EndpointI endpoint(IceInternal.EndpointI del)
        {
            if(del == _delegate)
            {
                return this;
            }
            else
            {
                return new EndpointI(_instance, del);
            }
        }

        public override List<IceInternal.EndpointI> expandIfWildcard()
        {
            List<IceInternal.EndpointI> l = new List<IceInternal.EndpointI>();
            foreach(IceInternal.EndpointI e in _delegate.expandIfWildcard())
            {
                l.Add(e == _delegate ? this : new EndpointI(_instance, e));
            }
            return l;
        }

        public override List<IceInternal.EndpointI> expandHost(out IceInternal.EndpointI publish)
        {
            List<IceInternal.EndpointI> l = new List<IceInternal.EndpointI>();
            foreach(IceInternal.EndpointI e in _delegate.expandHost(out publish))
            {
                l.Add(e == _delegate ? this : new EndpointI(_instance, e));
            }
            if(publish != null)
            {
                publish = publish == _delegate ? this : new EndpointI(_instance, publish);
            }
            return l;
        }

        public override bool equivalent(IceInternal.EndpointI endpoint)
        {
            if(!(endpoint is EndpointI))
            {
                return false;
            }
            EndpointI endpointI = (EndpointI)endpoint;
            return _delegate.equivalent(endpointI._delegate);
        }

        public override string options()
        {
            return _delegate.options();
        }

        //
        // Compare endpoints for sorting purposes
        //
        public override int CompareTo(IceInternal.EndpointI obj)
        {
            if(!(obj is EndpointI))
            {
                return type() < obj.type() ? -1 : 1;
            }

            EndpointI p = (EndpointI)obj;
            if(this == p)
            {
                return 0;
            }

            return _delegate.CompareTo(p._delegate);
        }

        public override int GetHashCode()
        {
            return _delegate.GetHashCode();
        }

        protected override bool checkOption(string option, string argument, string endpoint)
        {
            return false;
        }

        private Instance _instance;
        private IceInternal.EndpointI _delegate;
    }

    internal sealed class EndpointFactoryI : IceInternal.EndpointFactoryWithUnderlying
    {
        public EndpointFactoryI(Instance instance, short type) : base(instance, type)
        {
            _instance = instance;
        }

        override public IceInternal.EndpointFactory
        cloneWithUnderlying(IceInternal.ProtocolInstance inst, short underlying)
        {
            return new EndpointFactoryI(new Instance(_instance.engine(), inst.type(), inst.protocol()), underlying);
        }

        override protected IceInternal.EndpointI
        createWithUnderlying(IceInternal.EndpointI underlying, List<string> args, bool oaEndpoint)
        {
            return new EndpointI(_instance, underlying);
        }

        override protected IceInternal.EndpointI
        readWithUnderlying(IceInternal.EndpointI underlying, Ice.InputStream s)
        {
            return new EndpointI(_instance, underlying);
        }

        private Instance _instance;
    }
}