| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Collections.Generic; |
| | 4 | |
|
| | 5 | | namespace Ice.Internal; |
| | 6 | |
|
| | 7 | | public interface EndpointFactory |
| | 8 | | { |
| | 9 | | void initialize(); |
| | 10 | |
|
| | 11 | | short type(); |
| | 12 | |
|
| | 13 | | string protocol(); |
| | 14 | |
|
| | 15 | | EndpointI create(List<string> args, bool oaEndpoint); |
| | 16 | |
|
| | 17 | | EndpointI read(Ice.InputStream s); |
| | 18 | |
|
| | 19 | | EndpointFactory clone(ProtocolInstance instance); |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public abstract class EndpointFactoryWithUnderlying : EndpointFactory |
| | 23 | | { |
| 1 | 24 | | protected EndpointFactoryWithUnderlying(ProtocolInstance instance, short type) |
| | 25 | | { |
| 1 | 26 | | instance_ = instance; |
| 1 | 27 | | _type = type; |
| 1 | 28 | | } |
| | 29 | |
|
| | 30 | | public void initialize() |
| | 31 | | { |
| | 32 | | // |
| | 33 | | // Get the endpoint factory for the underlying type and clone it with |
| | 34 | | // our protocol instance. |
| | 35 | | // |
| 1 | 36 | | EndpointFactory factory = instance_.getEndpointFactory(_type); |
| 1 | 37 | | if (factory != null) |
| | 38 | | { |
| 1 | 39 | | _underlying = factory.clone(instance_); |
| 1 | 40 | | _underlying.initialize(); |
| | 41 | | } |
| 1 | 42 | | } |
| | 43 | |
|
| 1 | 44 | | public short type() => instance_.type(); |
| | 45 | |
|
| 1 | 46 | | public string protocol() => instance_.protocol(); |
| | 47 | |
|
| | 48 | | public EndpointI create(List<string> args, bool oaEndpoint) |
| | 49 | | { |
| 1 | 50 | | if (_underlying == null) |
| | 51 | | { |
| 0 | 52 | | return null; // Can't create an endpoint without underlying factory. |
| | 53 | | } |
| 1 | 54 | | return createWithUnderlying(_underlying.create(args, oaEndpoint), args, oaEndpoint); |
| | 55 | | } |
| | 56 | |
|
| | 57 | | public EndpointI read(Ice.InputStream s) |
| | 58 | | { |
| 1 | 59 | | if (_underlying == null) |
| | 60 | | { |
| 0 | 61 | | return null; // Can't create an endpoint without underlying factory. |
| | 62 | | } |
| 1 | 63 | | return readWithUnderlying(_underlying.read(s), s); |
| | 64 | | } |
| | 65 | |
|
| 1 | 66 | | public EndpointFactory clone(ProtocolInstance instance) => cloneWithUnderlying(instance, _type); |
| | 67 | |
|
| | 68 | | public abstract EndpointFactory cloneWithUnderlying(ProtocolInstance instance, short underlying); |
| | 69 | |
|
| | 70 | | protected abstract EndpointI createWithUnderlying(EndpointI underlying, List<string> args, bool oaEndpoint); |
| | 71 | |
|
| | 72 | | protected abstract EndpointI readWithUnderlying(EndpointI underlying, Ice.InputStream s); |
| | 73 | |
|
| | 74 | | protected readonly ProtocolInstance instance_; |
| | 75 | |
|
| | 76 | | private readonly short _type; |
| | 77 | | private EndpointFactory _underlying; |
| | 78 | | } |