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