Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Endpoint.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_ENDPOINT_H
4#define ICE_ENDPOINT_H
5
6#include "EndpointF.h"
7#include "Ice/EndpointTypes.h"
8#include "Ice/Version.h"
9
10#include <string>
11#include <vector>
12
13#if defined(__clang__)
14# pragma clang diagnostic push
15# pragma clang diagnostic ignored "-Wshadow-field-in-constructor"
16#elif defined(__GNUC__)
17# pragma GCC diagnostic push
18# pragma GCC diagnostic ignored "-Wshadow"
19#endif
20
21namespace Ice
22{
23 /// An endpoint specifies the address of the server-end of an Ice connection: an object adapter listens on one or
24 /// more endpoints and a client establishes a connection to an endpoint.
25 /// @headerfile Ice/Ice.h
26 class ICE_API Endpoint
27 {
28 public:
29 /// Default constructor.
30 Endpoint() = default;
31
32 virtual ~Endpoint();
33
34 Endpoint(const Endpoint&) = delete;
35 Endpoint& operator=(const Endpoint&) = delete;
36
37 /// Operator equal to. Checks if this endpoint is equal to the @p rhs endpoint.
38 /// @param rhs The endpoint to compare against.
39 /// @return `true` if the endpoints are equal, `false` otherwise.
40 virtual bool operator==(const Endpoint& rhs) const = 0;
41
42 /// Operator less than. Checks if this endpoint is less than the @p rhs endpoint.
43 /// @param rhs The endpoint to compare against.
44 /// @return `true` if this endpoint is less than the @p rhs endpoint, `false` otherwise.
45 virtual bool operator<(const Endpoint& rhs) const = 0;
46
47 /// Returns a string representation of this endpoint.
48 /// @return The string representation of this endpoint.
49 [[nodiscard]] virtual std::string toString() const noexcept = 0;
50
51 /// Returns the endpoint information.
52 /// @return The endpoint information class.
53 [[nodiscard]] virtual EndpointInfoPtr getInfo() const noexcept = 0;
54 };
55
56 /// Base class for the endpoint info classes.
57 /// @headerfile Ice/Ice.h
58 class ICE_API EndpointInfo
59 {
60 public:
61 virtual ~EndpointInfo();
62 EndpointInfo(const EndpointInfo&) = delete;
63 EndpointInfo& operator=(const EndpointInfo&) = delete;
64
65 /// Returns the type of the endpoint.
66 /// @return The endpoint type.
67 [[nodiscard]] virtual std::int16_t type() const noexcept;
68
69 /// Returns `true` if this endpoint's transport is a datagram transport (namely, UDP), `false` otherwise.
70 /// @return `true` for a UDP endpoint, `false` otherwise.
71 [[nodiscard]] virtual bool datagram() const noexcept;
72
73 /// Returns `true` if this endpoint's transport uses SSL, `false` otherwise.
74 /// @return `true` for SSL and SSL-based transports, `false` otherwise.
75 [[nodiscard]] virtual bool secure() const noexcept;
76
77 /// The information of the underlying endpoint or nullptr if there's no underlying endpoint.
79
80 /// Specifies whether or not compression should be used if available when using this endpoint.
81 const bool compress;
82
83 protected:
84 /// @private
85 explicit EndpointInfo(EndpointInfoPtr underlyingInfo)
86 : underlying(std::move(underlyingInfo)),
88 {
89 }
90
91 /// @private
92 explicit EndpointInfo(bool compress) : compress(compress) {}
93 };
94
95 /// Provides access to the address details of an IP endpoint.
96 /// @see Endpoint
97 /// @headerfile Ice/Ice.h
98 class ICE_API IPEndpointInfo : public EndpointInfo
99 {
100 public:
101 IPEndpointInfo(const IPEndpointInfo&) = delete;
102 IPEndpointInfo& operator=(const IPEndpointInfo&) = delete;
103
104 ~IPEndpointInfo() override;
105
106 /// The host or address configured with the endpoint.
107 const std::string host;
108
109 /// The port number.
110 const int port;
111
112 /// The source IP address.
113 const std::string sourceAddress;
114
115 protected:
116 /// @private
117 IPEndpointInfo(bool compress, std::string host, int port, std::string sourceAddress)
118 : EndpointInfo{compress},
119 host{std::move(host)},
120 port{port},
121 sourceAddress{std::move(sourceAddress)}
122 {
123 }
124 };
125
126 /// Provides access to a TCP endpoint information.
127 /// @see Endpoint
128 /// @headerfile Ice/Ice.h
129 class ICE_API TCPEndpointInfo final : public IPEndpointInfo
130 {
131 public:
132 ~TCPEndpointInfo() final;
133 TCPEndpointInfo(const TCPEndpointInfo&) = delete;
134 TCPEndpointInfo& operator=(const TCPEndpointInfo&) = delete;
135
136 [[nodiscard]] std::int16_t type() const noexcept final { return _type; }
137 [[nodiscard]] bool secure() const noexcept final { return _secure; }
138
139 /// @private
141 bool compress,
142 std::string host,
143 int port,
144 std::string sourceAddress,
145 std::int16_t type,
146 bool secure)
147 : IPEndpointInfo{compress, std::move(host), port, std::move(sourceAddress)},
148 _type{type},
149 _secure{secure}
150 {
151 }
152
153 private:
154 const std::int16_t _type;
155 const bool _secure;
156 };
157
158 /// Provides access to an UDP endpoint information.
159 /// @see Endpoint
160 /// @headerfile Ice/Ice.h
161 class ICE_API UDPEndpointInfo final : public IPEndpointInfo
162 {
163 public:
164 ~UDPEndpointInfo() final;
165 UDPEndpointInfo(const UDPEndpointInfo&) = delete;
166 UDPEndpointInfo& operator=(const UDPEndpointInfo&) = delete;
167
168 /// The multicast interface.
169 const std::string mcastInterface;
170
171 /// The multicast time-to-live (or hops).
172 const int mcastTtl;
173
174 [[nodiscard]] std::int16_t type() const noexcept final { return UDPEndpointType; }
175 [[nodiscard]] bool datagram() const noexcept final { return true; }
176
177 /// @private
179 bool compress,
180 std::string host,
181 int port,
182 std::string sourceAddress,
183 std::string mcastInterface,
184 int mcastTtl)
185 : IPEndpointInfo{compress, std::move(host), port, std::move(sourceAddress)},
186 mcastInterface{std::move(mcastInterface)},
187 mcastTtl{mcastTtl}
188 {
189 }
190 };
191
192 /// Provides access to a WebSocket endpoint information.
193 /// @headerfile Ice/Ice.h
194 class ICE_API WSEndpointInfo final : public EndpointInfo
195 {
196 public:
197 ~WSEndpointInfo() final;
198 WSEndpointInfo(const WSEndpointInfo&) = delete;
199 WSEndpointInfo& operator=(const WSEndpointInfo&) = delete;
200
201 /// The URI configured with the endpoint.
202 const std::string resource;
203
204 /// @private
205 WSEndpointInfo(EndpointInfoPtr underlying, std::string resource)
206 : EndpointInfo{std::move(underlying)},
207 resource{std::move(resource)}
208 {
209 }
210 };
211
212 /// Provides access to an IAP endpoint information.
213 /// @headerfile Ice/Ice.h
214 class IAPEndpointInfo final : public EndpointInfo
215 {
216 public:
217 ~IAPEndpointInfo() final;
218 IAPEndpointInfo(const IAPEndpointInfo&) = delete;
219 IAPEndpointInfo& operator=(const IAPEndpointInfo&) = delete;
220
221 [[nodiscard]] std::int16_t type() const noexcept final { return _type; }
222 [[nodiscard]] bool secure() const noexcept final { return _secure; }
223
224 /// The accessory manufacturer. Can be empty.
225 const std::string manufacturer;
226
227 /// The accessory model number. Can be empty.
228 const std::string modelNumber;
229
230 /// The accessory name. Can be empty.
231 const std::string name;
232
233 /// The protocol supported by the accessory.
234 const std::string protocol;
235
236 /// @private
237 IAPEndpointInfo(
238 bool compress,
239 std::string manufacturer,
240 std::string modelNumber,
241 std::string name,
242 std::string protocol,
243 std::int16_t type,
244 bool secure)
245 : EndpointInfo{compress},
246 manufacturer{std::move(manufacturer)},
247 modelNumber{std::move(modelNumber)},
248 name{std::move(name)},
249 protocol{std::move(protocol)},
250 _type{type},
251 _secure{secure}
252 {
253 }
254
255 private:
256 const std::int16_t _type;
257 const bool _secure;
258 };
259
260 /// Provides access to the details of an opaque endpoint.
261 /// @see Endpoint
262 /// @headerfile Ice/Ice.h
263 class ICE_API OpaqueEndpointInfo final : public EndpointInfo
264 {
265 public:
266 ~OpaqueEndpointInfo() final;
267 OpaqueEndpointInfo(const OpaqueEndpointInfo&) = delete;
268 OpaqueEndpointInfo& operator=(const OpaqueEndpointInfo&) = delete;
269
270 [[nodiscard]] std::int16_t type() const noexcept final { return _type; }
271
272 /// The encoding version of the opaque endpoint (to decode or encode the rawBytes).
274
275 /// The raw encoding of the opaque endpoint.
276 const std::vector<std::byte> rawBytes;
277
278 /// @private
279 OpaqueEndpointInfo(std::int16_t type, Ice::EncodingVersion rawEncoding, std::vector<std::byte> rawBytes)
280 : EndpointInfo{false},
282 rawBytes{std::move(rawBytes)},
283 _type{type}
284 {
285 }
286
287 private:
288 std::int16_t _type;
289 };
290}
291
292#if defined(__clang__)
293# pragma clang diagnostic pop
294#elif defined(__GNUC__)
295# pragma GCC diagnostic pop
296#endif
297
298#endif
virtual bool secure() const noexcept
Returns true if this endpoint's transport uses SSL, false otherwise.
virtual std::int16_t type() const noexcept
Returns the type of the endpoint.
const EndpointInfoPtr underlying
The information of the underlying endpoint or nullptr if there's no underlying endpoint.
Definition Endpoint.h:78
const bool compress
Specifies whether or not compression should be used if available when using this endpoint.
Definition Endpoint.h:81
virtual bool datagram() const noexcept
Returns true if this endpoint's transport is a datagram transport (namely, UDP), false otherwise.
Base class for the endpoint info classes.
Definition Endpoint.h:59
virtual bool operator==(const Endpoint &rhs) const =0
Operator equal to.
virtual std::string toString() const noexcept=0
Returns a string representation of this endpoint.
virtual EndpointInfoPtr getInfo() const noexcept=0
Returns the endpoint information.
Endpoint()=default
Default constructor.
virtual bool operator<(const Endpoint &rhs) const =0
Operator less than.
const std::string name
The accessory name. Can be empty.
Definition Endpoint.h:231
const std::string modelNumber
The accessory model number. Can be empty.
Definition Endpoint.h:228
const std::string protocol
The protocol supported by the accessory.
Definition Endpoint.h:234
const std::string manufacturer
The accessory manufacturer. Can be empty.
Definition Endpoint.h:225
std::int16_t type() const noexcept final
Returns the type of the endpoint.
Definition Endpoint.h:221
bool secure() const noexcept final
Returns true if this endpoint's transport uses SSL, false otherwise.
Definition Endpoint.h:222
const std::string host
The host or address configured with the endpoint.
Definition Endpoint.h:107
const int port
The port number.
Definition Endpoint.h:110
const std::string sourceAddress
The source IP address.
Definition Endpoint.h:113
Provides access to the address details of an IP endpoint.
Definition Endpoint.h:99
const Ice::EncodingVersion rawEncoding
The encoding version of the opaque endpoint (to decode or encode the rawBytes).
Definition Endpoint.h:273
const std::vector< std::byte > rawBytes
The raw encoding of the opaque endpoint.
Definition Endpoint.h:276
std::int16_t type() const noexcept final
Returns the type of the endpoint.
Definition Endpoint.h:270
bool secure() const noexcept final
Returns true if this endpoint's transport uses SSL, false otherwise.
Definition Endpoint.h:137
std::int16_t type() const noexcept final
Returns the type of the endpoint.
Definition Endpoint.h:136
Provides access to a TCP endpoint information.
Definition Endpoint.h:130
const int mcastTtl
The multicast time-to-live (or hops).
Definition Endpoint.h:172
bool datagram() const noexcept final
Returns true if this endpoint's transport is a datagram transport (namely, UDP), false otherwise.
Definition Endpoint.h:175
std::int16_t type() const noexcept final
Returns the type of the endpoint.
Definition Endpoint.h:174
const std::string mcastInterface
The multicast interface.
Definition Endpoint.h:169
Provides access to an UDP endpoint information.
Definition Endpoint.h:162
const std::string resource
The URI configured with the endpoint.
Definition Endpoint.h:202
std::shared_ptr< EndpointInfo > EndpointInfoPtr
A shared pointer to an EndpointInfo.
Definition EndpointF.h:23
constexpr std::int16_t UDPEndpointType
Identifies UDP endpoints.
The Ice RPC framework.
Definition SampleEvent.h:59
Represents a version of the Slice encoding.
Definition Version.h:65