Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Proxy.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_PROXY_H
4#define ICE_PROXY_H
5
6#include "BatchRequestQueueF.h"
7#include "CommunicatorF.h"
8#include "Current.h"
9#include "EndpointF.h"
10#include "EndpointSelectionType.h"
11#include "Ice/BuiltinSequences.h"
12#include "LocalExceptions.h"
13#include "ReferenceF.h"
14#include "RequestHandlerF.h"
15
16#include <chrono>
17#include <functional>
18#include <future>
19#include <iosfwd>
20#include <optional>
21#include <string_view>
22#include <type_traits>
23
24namespace IceInternal
25{
26 class ProxyGetConnection;
27 class ProxyFlushBatchAsync;
28
29 template<typename T> class OutgoingAsyncT;
30}
31
32namespace Ice
33{
34 /// Marker value used to indicate that no explicit request context was passed to a proxy invocation.
35 ICE_API extern const Context noExplicitContext;
36
37 class LocatorPrx;
38 class ObjectPrx;
39 class OutputStream;
40 class RouterPrx;
41
42 /// Provides typed proxy functions.
43 /// @headerfile Ice/Ice.h
44 template<typename Prx, typename... Bases> class Proxy : public virtual Bases...
45 {
46 public:
47 /// The arrow operator.
48 /// @return A pointer to this object.
49 /// @remark This operator is provided for aesthetics and for compatibility reasons. A proxy is not pointer-like:
50 /// it does not hold a value and can't be null. Calling `greeter->greet("bob")` is 100% equivalent to calling
51 /// `greeter.greet("bob")` when greeter is a GreeterPrx proxy. An advantage of the arrow syntax is it's the same
52 /// whether greeter is a GreeterPrx, an optional<GreeterPrx>, or a smart pointer like in earlier versions of
53 /// Ice. It's also aesthetically pleasing when making invocations: the proxy appears like a pointer to the
54 /// remote object.
55 const Prx* operator->() const noexcept { return &asPrx(); }
56
57 // We don't provide the non-const operator-> because only the assignment operator can modify the proxy.
58
59 /// Creates a proxy that is identical to this proxy, except for the adapter ID.
60 /// @param id The adapter ID for the new proxy.
61 /// @return A proxy with the new adapter ID.
62 [[nodiscard]] Prx ice_adapterId(std::string id) const
63 {
64 return fromReference(asPrx()._adapterId(std::move(id)));
65 }
66
67 /// Creates a proxy that is identical to this proxy, but uses batch datagram invocations.
68 /// @return A proxy that uses batch datagram invocations.
69 [[nodiscard]] Prx ice_batchDatagram() const { return fromReference(asPrx()._batchDatagram()); }
70
71 /// Creates a proxy that is identical to this proxy, but uses batch oneway invocations.
72 /// @return A proxy that uses batch oneway invocations.
73 [[nodiscard]] Prx ice_batchOneway() const { return fromReference(asPrx()._batchOneway()); }
74
75 /// Creates a proxy that is identical to this proxy, except for collocation optimization.
76 /// @param b `true` if the new proxy enables collocation optimization, `false` otherwise.
77 /// @return A proxy with the specified collocation optimization.
78 [[nodiscard]] Prx ice_collocationOptimized(bool b) const
79 {
80 return fromReference(asPrx()._collocationOptimized(b));
81 }
82
83 /// Creates a proxy that is identical to this proxy, except for its compression setting which overrides the
84 /// compression setting from the proxy endpoints.
85 /// @param b `true` enables compression for the new proxy, `false` disables compression.
86 /// @return A proxy with the specified compression override setting.
87 [[nodiscard]] Prx ice_compress(bool b) const { return fromReference(asPrx()._compress(b)); }
88
89 /// Creates a proxy that is identical to this proxy, except for connection caching.
90 /// @param b `true` if the new proxy should cache connections, `false` otherwise.
91 /// @return A proxy with the specified caching policy.
92 [[nodiscard]] Prx ice_connectionCached(bool b) const { return fromReference(asPrx()._connectionCached(b)); }
93
94 /// Creates a proxy that is identical to this proxy, except for its connection ID.
95 /// @param id The connection ID for the new proxy. An empty string removes the connection ID.
96 /// @return A proxy with the specified connection ID.
97 [[nodiscard]] Prx ice_connectionId(std::string id) const
98 {
99 return fromReference(asPrx()._connectionId(std::move(id)));
100 }
101
102 /// Creates a proxy that is identical to this proxy, except for the per-proxy context.
103 /// @param context The context for the new proxy.
104 /// @return A proxy with the new per-proxy context.
105 [[nodiscard]] Prx ice_context(Context context) const
106 {
107 return fromReference(asPrx()._context(std::move(context)));
108 }
109
110 /// Creates a proxy that is identical to this proxy, but uses datagram invocations.
111 /// @return A proxy that uses datagram invocations.
112 [[nodiscard]] Prx ice_datagram() const { return fromReference(asPrx()._datagram()); }
113
114 /// Creates a proxy that is identical to this proxy, except for the encoding used to marshal parameters.
115 /// @param version The encoding version to use to marshal request parameters.
116 /// @return A proxy with the specified encoding version.
117 [[nodiscard]] Prx ice_encodingVersion(EncodingVersion version) const
118 {
119 return fromReference(asPrx()._encodingVersion(version));
120 }
121
122 /// Creates a proxy that is identical to this proxy, except for the endpoint selection policy.
123 /// @param type The new endpoint selection policy.
124 /// @return A proxy with the specified endpoint selection policy.
125 [[nodiscard]] Prx ice_endpointSelection(EndpointSelectionType type) const
126 {
127 return fromReference(asPrx()._endpointSelection(type));
128 }
129
130 /// Creates a proxy that is identical to this proxy, except for the endpoints.
131 /// @param endpoints The endpoints for the new proxy.
132 /// @return A proxy with the new endpoints.
133 [[nodiscard]] Prx ice_endpoints(EndpointSeq endpoints) const
134 {
135 return fromReference(asPrx()._endpoints(std::move(endpoints)));
136 }
137
138 /// Creates a proxy that is identical to this proxy, except it's a fixed proxy bound to the given connection.
139 /// @param connection The fixed proxy connection.
140 /// @return A fixed proxy bound to the given connection.
141 [[nodiscard]] Prx ice_fixed(ConnectionPtr connection) const
142 {
143 return fromReference(asPrx()._fixed(std::move(connection)));
144 }
145
146 /// Creates a proxy that is identical to this proxy, except for the invocation timeout.
147 /// @param timeout The new invocation timeout (in milliseconds).
148 /// @return A proxy with the new timeout.
149 [[nodiscard]] Prx ice_invocationTimeout(int timeout) const
150 {
151 return ice_invocationTimeout(std::chrono::milliseconds(timeout));
152 }
153
154 /// Creates a proxy that is identical to this proxy, except for the invocation timeout.
155 /// @param timeout The new invocation timeout.
156 /// @return A proxy with the new timeout.
157 template<class Rep, class Period>
158 [[nodiscard]] Prx ice_invocationTimeout(const std::chrono::duration<Rep, Period>& timeout) const
159 {
160 return fromReference(
161 asPrx()._invocationTimeout(std::chrono::duration_cast<std::chrono::milliseconds>(timeout)));
162 }
163
164 /// Creates a proxy that is identical to this proxy, except for the locator.
165 /// @param locator The locator for the new proxy.
166 /// @return A proxy with the specified locator.
167 [[nodiscard]] Prx ice_locator(const std::optional<LocatorPrx>& locator) const
168 {
169 return fromReference(asPrx()._locator(locator));
170 }
171
172 /// Creates a proxy that is identical to this proxy, except for the locator cache timeout.
173 /// @param timeout The new locator cache timeout (in seconds).
174 /// @return A proxy with the new timeout.
175 [[nodiscard]] Prx ice_locatorCacheTimeout(int timeout) const
176 {
177 return ice_locatorCacheTimeout(std::chrono::seconds(timeout));
178 }
179
180 /// Creates a proxy that is identical to this proxy, except for the locator cache timeout.
181 /// @param timeout The new locator cache timeout.
182 /// @return A proxy with the new timeout.
183 template<class Rep, class Period>
184 [[nodiscard]] Prx ice_locatorCacheTimeout(const std::chrono::duration<Rep, Period>& timeout) const
185 {
186 return fromReference(
187 asPrx()._locatorCacheTimeout(std::chrono::duration_cast<std::chrono::seconds>(timeout)));
188 }
189
190 /// Creates a proxy that is identical to this proxy, but uses oneway invocations.
191 /// @return A proxy that uses oneway invocations.
192 [[nodiscard]] Prx ice_oneway() const { return fromReference(asPrx()._oneway()); }
193
194 /// Creates a proxy that is identical to this proxy, except for the router.
195 /// @param router The router for the new proxy.
196 /// @return A proxy with the specified router.
197 [[nodiscard]] Prx ice_router(const std::optional<RouterPrx>& router) const
198 {
199 return fromReference(asPrx()._router(router));
200 }
201
202 /// Creates a proxy that is identical to this proxy, but uses twoway invocations.
203 /// @return A proxy that uses twoway invocations.
204 [[nodiscard]] Prx ice_twoway() const { return fromReference(asPrx()._twoway()); }
205
206 protected:
207 /// @cond INTERNAL
208
209 // This constructor never initializes the base classes since they are all virtual and Proxy is never the most
210 // derived class.
211 Proxy() = default;
212
213 // The copy constructor and assignment operators are to keep GCC happy.
214 Proxy(const Proxy&) noexcept = default;
215 Proxy& operator=(const Proxy&) noexcept { return *this; } // NOLINT
216 Proxy& operator=(Proxy&&) noexcept { return *this; } // NOLINT
217 /// @endcond
218
219 private:
220 Prx fromReference(IceInternal::ReferencePtr&& ref) const
221 {
222 const Prx& self = asPrx();
223 return ref == self._reference ? self : Prx::_fromReference(std::move(ref));
224 }
225
226 [[nodiscard]] const Prx& asPrx() const noexcept { return *static_cast<const Prx*>(this); }
227 };
228
229 /// The base class for all Ice proxies.
230 /// @headerfile Ice/Ice.h
231 class ICE_API ObjectPrx : public Proxy<ObjectPrx>
232 {
233 public:
234 /// Copy constructor. Constructs with a copy of the contents of @p other.
235 /// @param other The proxy to copy from.
236 ObjectPrx(const ObjectPrx& other) noexcept = default;
237
238 /// Move constructor. Constructs a proxy with the contents of @p other using move semantics.
239 /// @param other The proxy to move from.
240 ObjectPrx(ObjectPrx&& other) noexcept = default;
241
242 /// Constructs a proxy from a Communicator and a proxy string.
243 /// @param communicator The communicator of the new proxy.
244 /// @param proxyString The proxy string to parse.
245 ObjectPrx(const Ice::CommunicatorPtr& communicator, std::string_view proxyString);
246
247 virtual ~ObjectPrx();
248
249 /// Copy assignment operator. Replaces the contents of this proxy with a copy of the contents of @p rhs.
250 /// @param rhs The proxy to copy from.
251 /// @return A reference to this proxy.
252 ObjectPrx& operator=(const ObjectPrx& rhs) noexcept = default;
253
254 /// Move assignment operator. Replaces the contents of this proxy with the contents of @p rhs using move
255 /// semantics.
256 /// @param rhs The proxy to move from.
257 /// @return A reference to this proxy.
258 ObjectPrx& operator=(ObjectPrx&& rhs) noexcept = default;
259
260 /// Tests whether this object supports a specific Slice interface.
261 /// @param typeId The type ID of the Slice interface to test against.
262 /// @param context The request context.
263 /// @return `true` if the target object implements the Slice interface specified by @p typeId or implements a
264 /// derived interface, `false` otherwise.
265 [[nodiscard]] bool ice_isA(std::string_view typeId, const Ice::Context& context = Ice::noExplicitContext) const;
266
267 /// Tests whether this object supports a specific Slice interface.
268 /// @param typeId The type ID of the Slice interface to test against.
269 /// @param response The response callback. It accepts:
270 /// - `true` if the target object implements the Slice interface specified by @p typeId or implements a
271 /// derived interface, `false` otherwise.
272 /// @param ex The exception callback.
273 /// @param sent The sent callback.
274 /// @param context The request context.
275 /// @return A function that can be called to cancel the invocation locally.
276 // NOLINTNEXTLINE(modernize-use-nodiscard)
277 std::function<void()> ice_isAAsync(
278 std::string_view typeId,
279 std::function<void(bool)> response,
280 std::function<void(std::exception_ptr)> ex = nullptr,
281 std::function<void(bool)> sent = nullptr,
282 const Ice::Context& context = Ice::noExplicitContext) const;
283
284 /// Tests whether this object supports a specific Slice interface.
285 /// @param typeId The type ID of the Slice interface to test against.
286 /// @param context The request context.
287 /// @return A future that becomes available when the invocation completes. This future holds:
288 /// - `true` if the target object implements the Slice interface specified by @p typeId or implements a
289 /// derived interface, `false` otherwise.
290 [[nodiscard]] std::future<bool>
291 ice_isAAsync(std::string_view typeId, const Ice::Context& context = Ice::noExplicitContext) const;
292
293 /// @private
294 void _iceI_isA(const std::shared_ptr<IceInternal::OutgoingAsyncT<bool>>&, std::string_view, const Ice::Context&)
295 const;
296
297 /// Tests whether the target object of this proxy can be reached.
298 /// @param context The request context.
299 void ice_ping(const Ice::Context& context = Ice::noExplicitContext) const;
300
301 /// Tests whether the target object of this proxy can be reached.
302 /// @param response The response callback.
303 /// @param ex The exception callback.
304 /// @param sent The sent callback.
305 /// @param context The request context.
306 /// @return A function that can be called to cancel the invocation locally.
307 // NOLINTNEXTLINE(modernize-use-nodiscard)
308 std::function<void()> ice_pingAsync(
309 std::function<void()> response,
310 std::function<void(std::exception_ptr)> ex = nullptr,
311 std::function<void(bool)> sent = nullptr,
312 const Ice::Context& context = Ice::noExplicitContext) const;
313
314 /// Tests whether the target object of this proxy can be reached.
315 /// @param context The request context.
316 /// @return A future that becomes available when the response is received.
317 [[nodiscard]] std::future<void> ice_pingAsync(const Ice::Context& context = Ice::noExplicitContext) const;
318
319 /// @private
320 void _iceI_ping(const std::shared_ptr<IceInternal::OutgoingAsyncT<void>>&, const Ice::Context&) const;
321
322 /// Gets the Slice interfaces supported by this object as a list of type IDs.
323 /// @param context The request context.
324 /// @return The Slice type IDs of the interfaces supported by this object, in alphabetical order.
325 [[nodiscard]] std::vector<std::string> ice_ids(const Ice::Context& context = Ice::noExplicitContext) const;
326
327 /// Gets the Slice interfaces supported by this object as a list of type IDs.
328 /// @param response The response callback. It accepts:
329 /// - The Slice type IDs of the interfaces supported by this object, in alphabetical order.
330 /// @param ex The exception callback.
331 /// @param sent The sent callback.
332 /// @param context The request context.
333 /// @return A function that can be called to cancel the invocation locally.
334 // NOLINTNEXTLINE(modernize-use-nodiscard)
335 std::function<void()> ice_idsAsync(
336 std::function<void(std::vector<std::string>)> response,
337 std::function<void(std::exception_ptr)> ex = nullptr,
338 std::function<void(bool)> sent = nullptr,
339 const Ice::Context& context = Ice::noExplicitContext) const;
340
341 /// Gets the Slice interfaces supported by this object as a list of type IDs.
342 /// @param context The request context.
343 /// @return A future that becomes available when the invocation completes. This future holds:
344 /// - The Slice type IDs of the interfaces supported by this object, in alphabetical order.
345 [[nodiscard]] std::future<std::vector<std::string>>
347
348 /// @private
349 void _iceI_ids(
350 const std::shared_ptr<IceInternal::OutgoingAsyncT<std::vector<std::string>>>&,
351 const Ice::Context&) const;
352
353 /// Gets the type ID of the most-derived Slice interface supported by this object.
354 /// @param context The request context.
355 /// @return The Slice type ID of the most-derived interface.
356 [[nodiscard]] std::string ice_id(const Ice::Context& context = Ice::noExplicitContext) const;
357
358 /// Gets the type ID of the most-derived Slice interface supported by this object.
359 /// @param response The response callback. It accepts:
360 /// - The type ID of the most-derived interface.
361 /// @param ex The exception callback.
362 /// @param sent The sent callback.
363 /// @param context The request context.
364 /// @return A function that can be called to cancel the invocation locally.
365 // NOLINTNEXTLINE(modernize-use-nodiscard)
366 std::function<void()> ice_idAsync(
367 std::function<void(std::string)> response,
368 std::function<void(std::exception_ptr)> ex = nullptr,
369 std::function<void(bool)> sent = nullptr,
370 const Ice::Context& context = Ice::noExplicitContext) const;
371
372 /// Gets the type ID of the most-derived Slice interface supported by this object.
373 /// @param context The request context.
374 /// @return A future that becomes available when the invocation completes. This future holds:
375 /// - The type ID of the most-derived interface.
376 [[nodiscard]] std::future<std::string> ice_idAsync(const Ice::Context& context = Ice::noExplicitContext) const;
377
378 /// @private
379 void _iceI_id(const std::shared_ptr<IceInternal::OutgoingAsyncT<std::string>>&, const Ice::Context&) const;
380
381 /// Invokes an operation.
382 /// @param operation The name of the operation to invoke.
383 /// @param mode The operation mode (normal or idempotent).
384 /// @param inParams An encapsulation containing the encoded in-parameters for the operation.
385 /// @param outParams An encapsulation containing the encoded result.
386 /// @param context The request context.
387 /// @return `true` if the operation completed successfully, `false` if it completed with a user exception.
389 std::string_view operation,
391 const std::vector<std::byte>& inParams,
392 std::vector<std::byte>& outParams,
393 const Ice::Context& context = Ice::noExplicitContext) const;
394
395 /// Invokes an operation asynchronously.
396 /// @param operation The name of the operation to invoke.
397 /// @param mode The operation mode (normal or idempotent).
398 /// @param inParams An encapsulation containing the encoded in-parameters for the operation.
399 /// @param context The request context.
400 /// @return A future that becomes available when the invocation completes. This future holds:
401 /// - `returnValue` `true` if the operation completed successfully, `false` if it completed with a user
402 /// exception.
403 /// - `outParams` An encapsulation containing the encoded result.
404 [[nodiscard]] std::future<std::tuple<bool, std::vector<std::byte>>> ice_invokeAsync(
405 std::string_view operation,
407 const std::vector<std::byte>& inParams,
408 const Ice::Context& context = Ice::noExplicitContext) const;
409
410 /// Invokes an operation asynchronously.
411 /// @param operation The name of the operation to invoke.
412 /// @param mode The operation mode (normal or idempotent).
413 /// @param inParams An encapsulation containing the encoded in-parameters for the operation.
414 /// @param response The response callback. It accepts:
415 /// - `returnValue` `true` if the operation completed successfully, `false` if it completed with a user
416 /// exception.
417 /// - `outParams` An encapsulation containing the encoded result.
418 /// @param ex The exception callback.
419 /// @param sent The sent callback.
420 /// @param context The request context.
421 /// @return A function that can be called to cancel the invocation locally.
422 // NOLINTNEXTLINE(modernize-use-nodiscard)
423 std::function<void()> ice_invokeAsync(
424 std::string_view operation,
426 const std::vector<std::byte>& inParams,
427 std::function<void(bool, std::vector<std::byte>)> response,
428 std::function<void(std::exception_ptr)> ex = nullptr,
429 std::function<void(bool)> sent = nullptr,
430 const Ice::Context& context = Ice::noExplicitContext) const;
431
432 /// Invokes an operation.
433 /// @param operation The name of the operation to invoke.
434 /// @param mode The operation mode (normal or idempotent).
435 /// @param inParams An encapsulation containing the encoded in-parameters for the operation.
436 /// @param outParams An encapsulation containing the encoded result.
437 /// @param context The request context.
438 /// @return `true` if the operation completed successfully, `false` if it completed with a user exception.
440 std::string_view operation,
442 std::pair<const std::byte*, const std::byte*> inParams,
443 std::vector<std::byte>& outParams,
444 const Ice::Context& context = Ice::noExplicitContext) const;
445
446 /// Invokes an operation asynchronously.
447 /// @param operation The name of the operation to invoke.
448 /// @param mode The operation mode (normal or idempotent).
449 /// @param inParams An encapsulation containing the encoded in-parameters for the operation.
450 /// @param context The request context.
451 /// @return A future that becomes available when the invocation completes. This future holds:
452 /// - `returnValue` `true` if the operation completed successfully, `false` if it completed with a user
453 /// exception.
454 /// - `outParams` An encapsulation containing the encoded result.
455 [[nodiscard]] std::future<std::tuple<bool, std::vector<std::byte>>> ice_invokeAsync(
456 std::string_view operation,
458 std::pair<const std::byte*, const std::byte*> inParams,
459 const Ice::Context& context = Ice::noExplicitContext) const;
460
461 /// Invokes an operation asynchronously.
462 /// @param operation The name of the operation to invoke.
463 /// @param mode The operation mode (normal or idempotent).
464 /// @param inParams An encapsulation containing the encoded in-parameters for the operation.
465 /// @param response The response callback. It accepts:
466 /// - `returnValue` `true` if the operation completed successfully, `false` if it completed with a user
467 /// exception.
468 /// - `outParams` An encapsulation containing the encoded result.
469 /// @param ex The exception callback.
470 /// @param sent The sent callback.
471 /// @param context The request context.
472 /// @return A function that can be called to cancel the invocation locally.
473 // NOLINTNEXTLINE(modernize-use-nodiscard)
474 std::function<void()> ice_invokeAsync(
475 std::string_view operation,
477 std::pair<const std::byte*, const std::byte*> inParams,
478 std::function<void(bool, std::pair<const std::byte*, const std::byte*>)> response,
479 std::function<void(std::exception_ptr)> ex = nullptr,
480 std::function<void(bool)> sent = nullptr,
481 const Ice::Context& context = Ice::noExplicitContext) const;
482
483 /// Gets the connection for this proxy. If the proxy does not yet have an established connection,
484 /// it first attempts to create a connection.
485 /// @return The connection for this proxy.
486 /// @remark You can call this function to establish a connection or associate the proxy with an existing
487 /// connection and ignore the return value.
488 Ice::ConnectionPtr ice_getConnection() const; // NOLINT(modernize-use-nodiscard)
489
490 /// Gets the connection for this proxy. If the proxy does not yet have an established connection,
491 /// it first attempts to create a connection.
492 /// @param response The response callback. It accepts:
493 /// - The connection for this proxy.
494 /// @param ex The exception callback.
495 /// @param sent The sent callback.
496 /// @return A function that can be called to cancel the invocation locally.
497 // NOLINTNEXTLINE(modernize-use-nodiscard)
498 std::function<void()> ice_getConnectionAsync(
499 std::function<void(Ice::ConnectionPtr)> response,
500 std::function<void(std::exception_ptr)> ex = nullptr,
501 std::function<void(bool)> sent = nullptr) const;
502
503 /// Gets the connection for this proxy. If the proxy does not yet have an established connection,
504 /// it first attempts to create a connection.
505 /// @return A future that becomes available when the invocation completes. This future holds:
506 /// - The connection for this proxy.
507 [[nodiscard]] std::future<Ice::ConnectionPtr> ice_getConnectionAsync() const;
508
509 /// @private
510 void _iceI_getConnection(const std::shared_ptr<IceInternal::ProxyGetConnection>&) const;
511
512 /// Gets the cached Connection for this proxy. If the proxy does not yet have an established connection, it does
513 /// not attempt to create a connection.
514 /// @return The cached connection for this proxy, or nullptr if the proxy does not have an established
515 /// connection.
516 [[nodiscard]] Ice::ConnectionPtr ice_getCachedConnection() const noexcept;
517
518 /// Flushes any pending batched requests for this communicator. The call blocks until the flush is complete.
520
521 /// Flushes asynchronously any pending batched requests for this communicator.
522 /// @param ex The exception callback.
523 /// @param sent The sent callback.
524 /// @return A function that can be called to cancel the invocation locally.
525 // NOLINTNEXTLINE(modernize-use-nodiscard)
526 std::function<void()> ice_flushBatchRequestsAsync(
527 std::function<void(std::exception_ptr)> ex,
528 std::function<void(bool)> sent = nullptr) const;
529
530 /// Flushes asynchronously any pending batched requests for this communicator.
531 /// @return A future that becomes available when the flush completes.
532 [[nodiscard]] std::future<void> ice_flushBatchRequestsAsync() const;
533
534 /// Gets the identity embedded in this proxy.
535 /// @return The identity of the target object.
536 [[nodiscard]] const Ice::Identity& ice_getIdentity() const noexcept;
537
538 /// Creates a proxy that is identical to this proxy, except for the identity.
539 /// @param id The identity for the new proxy.
540 /// @return A proxy with the new identity.
541 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
542 [[nodiscard]] Prx ice_identity(Ice::Identity id) const
543 {
544 return Prx::_fromReference(_identity(std::move(id)));
545 }
546
547 /// Gets the per-proxy context for this proxy.
548 /// @return The per-proxy context.
549 [[nodiscard]] Ice::Context ice_getContext() const;
550
551 /// Gets the facet for this proxy.
552 /// @return The facet for this proxy. If the proxy uses the default facet, the return value is the empty string.
553 [[nodiscard]] const std::string& ice_getFacet() const noexcept;
554
555 /// Creates a proxy that is identical to this proxy, except for the facet.
556 /// @param facet The facet for the new proxy.
557 /// @return A proxy with the new facet.
558 template<typename Prx = ObjectPrx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
559 [[nodiscard]] Prx ice_facet(std::string facet) const
560 {
561 return Prx::_fromReference(_facet(std::move(facet)));
562 }
563
564 /// Gets the adapter ID for this proxy.
565 /// @return The adapter ID. If the proxy does not have an adapter ID, the return value is the empty string.
566 [[nodiscard]] std::string ice_getAdapterId() const;
567
568 /// Gets the endpoints used by this proxy.
569 /// @return The endpoints used by this proxy.
570 [[nodiscard]] Ice::EndpointSeq ice_getEndpoints() const;
571
572 /// Gets the locator cache timeout of this proxy.
573 /// @return The locator cache timeout value.
574 [[nodiscard]] std::chrono::milliseconds ice_getLocatorCacheTimeout() const noexcept;
575
576 /// Determines whether this proxy caches connections.
577 /// @return `true` if this proxy caches connections, `false` otherwise.
578 [[nodiscard]] bool ice_isConnectionCached() const noexcept;
579
580 /// Gets the endpoint selection policy for this proxy (randomly or ordered).
581 /// @return The endpoint selection policy.
582 [[nodiscard]] Ice::EndpointSelectionType ice_getEndpointSelection() const noexcept;
583
584 /// Gets the encoding version used to marshal request parameters.
585 /// @return The encoding version.
586 [[nodiscard]] Ice::EncodingVersion ice_getEncodingVersion() const noexcept;
587
588 /// Gets the router for this proxy.
589 /// @return The router for the proxy. If no router is configured for the proxy, the return value
590 /// is nullopt.
591 [[nodiscard]] std::optional<RouterPrx> ice_getRouter() const noexcept;
592
593 /// Gets the locator for this proxy.
594 /// @return The locator for this proxy. If no locator is configured, the return value is nullopt.
595 [[nodiscard]] std::optional<LocatorPrx> ice_getLocator() const noexcept;
596
597 /// Determines whether this proxy uses collocation optimization.
598 /// @return `true` if the proxy uses collocation optimization, `false` otherwise.
599 [[nodiscard]] bool ice_isCollocationOptimized() const noexcept;
600
601 /// Gets the invocation timeout of this proxy.
602 /// @return The invocation timeout value.
603 [[nodiscard]] std::chrono::milliseconds ice_getInvocationTimeout() const noexcept;
604
605 /// Determines whether this proxy uses twoway invocations.
606 /// @return `true` if this proxy uses twoway invocations, `false` otherwise.
607 [[nodiscard]] bool ice_isTwoway() const noexcept;
608
609 /// Determines whether this proxy uses oneway invocations.
610 /// @return `true` if this proxy uses oneway invocations, `false` otherwise.
611 [[nodiscard]] bool ice_isOneway() const noexcept;
612
613 /// Determines whether this proxy uses batch oneway invocations.
614 /// @return `true` if this proxy uses batch oneway invocations, `false` otherwise.
615 [[nodiscard]] bool ice_isBatchOneway() const noexcept;
616
617 /// Determines whether this proxy uses datagram invocations.
618 /// @return `true` if this proxy uses datagram invocations, `false` otherwise.
619 [[nodiscard]] bool ice_isDatagram() const noexcept;
620
621 /// Determines whether this proxy uses batch datagram invocations.
622 /// @return `true` if this proxy uses batch datagram invocations, `false` otherwise.
623 [[nodiscard]] bool ice_isBatchDatagram() const noexcept;
624
625 /// Gets the compression override setting of this proxy.
626 /// @return The compression override setting. If nullopt is returned, no override is set. Otherwise, true
627 /// if compression is enabled, `false` otherwise.
628 [[nodiscard]] std::optional<bool> ice_getCompress() const noexcept;
629
630 /// Gets the connection ID of this proxy.
631 /// @return The connection ID.
632 [[nodiscard]] std::string ice_getConnectionId() const;
633
634 /// Determines whether this proxy is a fixed proxy.
635 /// @return `true` if this proxy is a fixed proxy, `false` otherwise.
636 [[nodiscard]] bool ice_isFixed() const noexcept;
637
638 /// Returns the Slice type ID associated with this type.
639 /// @return The Slice type ID.
640 static const char* ice_staticId() noexcept;
641
642 /// Gets the communicator that created this proxy.
643 /// @return The communicator that created this proxy.
644 [[nodiscard]] Ice::CommunicatorPtr ice_getCommunicator() const noexcept;
645
646 /// Creates a stringified version of this proxy.
647 /// @return A stringified proxy.
648 [[nodiscard]] std::string ice_toString() const;
649
650 /// @private
651 void _iceI_flushBatchRequests(const std::shared_ptr<IceInternal::ProxyFlushBatchAsync>&) const;
652
653 /// @cond INTERNAL
654 static ObjectPrx _fromReference(IceInternal::ReferencePtr ref) { return ObjectPrx(std::move(ref)); }
655
656 [[nodiscard]] const IceInternal::ReferencePtr& _getReference() const noexcept { return _reference; }
657 [[nodiscard]] const IceInternal::RequestHandlerCachePtr& _getRequestHandlerCache() const noexcept
658 {
659 return _requestHandlerCache;
660 }
661
662 void _checkTwowayOnly(std::string_view) const;
663
664 [[nodiscard]] size_t _hash() const noexcept;
665
666 void _write(OutputStream&) const;
667
668 protected:
669 // This constructor is never called; it allows Proxy's default constructor to compile.
670 ObjectPrx() = default;
671
672 // The constructor used by _fromReference.
673 explicit ObjectPrx(IceInternal::ReferencePtr&&);
674 /// @endcond
675
676 private:
677 template<typename Prx, typename... Bases> friend class Proxy;
678
679 // Gets a reference with the specified setting; returns _reference if the setting is already set.
680 [[nodiscard]] IceInternal::ReferencePtr _adapterId(std::string) const;
681 [[nodiscard]] IceInternal::ReferencePtr _batchDatagram() const;
682 [[nodiscard]] IceInternal::ReferencePtr _batchOneway() const;
683 [[nodiscard]] IceInternal::ReferencePtr _collocationOptimized(bool) const;
684 [[nodiscard]] IceInternal::ReferencePtr _compress(bool) const;
685 [[nodiscard]] IceInternal::ReferencePtr _connectionCached(bool) const;
686 [[nodiscard]] IceInternal::ReferencePtr _connectionId(std::string) const;
687 [[nodiscard]] IceInternal::ReferencePtr _context(Context) const;
688 [[nodiscard]] IceInternal::ReferencePtr _datagram() const;
689 [[nodiscard]] IceInternal::ReferencePtr _encodingVersion(EncodingVersion) const;
690 [[nodiscard]] IceInternal::ReferencePtr _endpointSelection(EndpointSelectionType) const;
691 [[nodiscard]] IceInternal::ReferencePtr _endpoints(EndpointSeq) const;
692 [[nodiscard]] IceInternal::ReferencePtr _identity(Identity) const;
693 [[nodiscard]] IceInternal::ReferencePtr _facet(std::string) const;
694 [[nodiscard]] IceInternal::ReferencePtr _fixed(ConnectionPtr) const;
695 [[nodiscard]] IceInternal::ReferencePtr _invocationTimeout(std::chrono::milliseconds) const;
696 [[nodiscard]] IceInternal::ReferencePtr _locator(const std::optional<LocatorPrx>&) const;
697 [[nodiscard]] IceInternal::ReferencePtr _locatorCacheTimeout(std::chrono::milliseconds) const;
698 [[nodiscard]] IceInternal::ReferencePtr _oneway() const;
699 [[nodiscard]] IceInternal::ReferencePtr _router(const std::optional<RouterPrx>&) const;
700 [[nodiscard]] IceInternal::ReferencePtr _twoway() const;
701
702 // Only the assignment operators can change these fields. All other member functions must be const.
703 IceInternal::ReferencePtr _reference;
704 IceInternal::RequestHandlerCachePtr _requestHandlerCache;
705 };
706
707 /// Outputs the stringified version of a proxy to a stream.
708 /// @param os The output stream.
709 /// @param proxy The proxy to output.
710 /// @return The output stream.
711 ICE_API std::ostream& operator<<(std::ostream& os, const ObjectPrx& proxy);
712
713 /// Outputs the stringified version of a proxy to a stream.
714 /// @tparam Prx The proxy type.
715 /// @param os The output stream.
716 /// @param proxy The proxy to output.
717 /// @return The output stream.
718 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
719 inline std::ostream& operator<<(std::ostream& os, const std::optional<Prx>& proxy)
720 {
721 if (proxy)
722 {
723 os << *proxy;
724 }
725 else
726 {
727 os << "";
728 }
729 return os;
730 }
731}
732
733namespace std
734{
735 /// Specialization of std::hash for Ice::ObjectPrx.
736 template<> struct hash<Ice::ObjectPrx>
737 {
738 std::size_t operator()(const Ice::ObjectPrx& p) const noexcept { return p._hash(); }
739 };
740}
741
742#endif
Client applications use the Locator object to resolve Ice indirect proxies.
Definition Locator.h:38
bool ice_isFixed() const noexcept
Determines whether this proxy is a fixed proxy.
std::string ice_getConnectionId() const
Gets the connection ID of this proxy.
const std::string & ice_getFacet() const noexcept
Gets the facet for this proxy.
std::vector< std::string > ice_ids(const Ice::Context &context=Ice::noExplicitContext) const
Gets the Slice interfaces supported by this object as a list of type IDs.
ObjectPrx(ObjectPrx &&other) noexcept=default
Move constructor.
bool ice_isTwoway() const noexcept
Determines whether this proxy uses twoway invocations.
bool ice_isA(std::string_view typeId, const Ice::Context &context=Ice::noExplicitContext) const
Tests whether this object supports a specific Slice interface.
void ice_ping(const Ice::Context &context=Ice::noExplicitContext) const
Tests whether the target object of this proxy can be reached.
std::string ice_toString() const
Creates a stringified version of this proxy.
ObjectPrx & operator=(ObjectPrx &&rhs) noexcept=default
Move assignment operator.
std::future< void > ice_pingAsync(const Ice::Context &context=Ice::noExplicitContext) const
Tests whether the target object of this proxy can be reached.
Prx ice_identity(Ice::Identity id) const
Creates a proxy that is identical to this proxy, except for the identity.
Definition Proxy.h:542
ObjectPrx(const Ice::CommunicatorPtr &communicator, std::string_view proxyString)
Constructs a proxy from a Communicator and a proxy string.
std::function< void()> ice_idAsync(std::function< void(std::string)> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr, const Ice::Context &context=Ice::noExplicitContext) const
Gets the type ID of the most-derived Slice interface supported by this object.
Ice::Context ice_getContext() const
Gets the per-proxy context for this proxy.
std::chrono::milliseconds ice_getInvocationTimeout() const noexcept
Gets the invocation timeout of this proxy.
Ice::CommunicatorPtr ice_getCommunicator() const noexcept
Gets the communicator that created this proxy.
Ice::ConnectionPtr ice_getCachedConnection() const noexcept
Gets the cached Connection for this proxy.
Ice::ConnectionPtr ice_getConnection() const
Gets the connection for this proxy.
std::future< std::tuple< bool, std::vector< std::byte > > > ice_invokeAsync(std::string_view operation, Ice::OperationMode mode, const std::vector< std::byte > &inParams, const Ice::Context &context=Ice::noExplicitContext) const
Invokes an operation asynchronously.
bool ice_invoke(std::string_view operation, Ice::OperationMode mode, std::pair< const std::byte *, const std::byte * > inParams, std::vector< std::byte > &outParams, const Ice::Context &context=Ice::noExplicitContext) const
Invokes an operation.
void ice_flushBatchRequests() const
Flushes any pending batched requests for this communicator. The call blocks until the flush is comple...
bool ice_isConnectionCached() const noexcept
Determines whether this proxy caches connections.
bool ice_isBatchOneway() const noexcept
Determines whether this proxy uses batch oneway invocations.
std::function< void()> ice_flushBatchRequestsAsync(std::function< void(std::exception_ptr)> ex, std::function< void(bool)> sent=nullptr) const
Flushes asynchronously any pending batched requests for this communicator.
std::function< void()> ice_idsAsync(std::function< void(std::vector< std::string >)> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr, const Ice::Context &context=Ice::noExplicitContext) const
Gets the Slice interfaces supported by this object as a list of type IDs.
std::future< std::tuple< bool, std::vector< std::byte > > > ice_invokeAsync(std::string_view operation, Ice::OperationMode mode, std::pair< const std::byte *, const std::byte * > inParams, const Ice::Context &context=Ice::noExplicitContext) const
Invokes an operation asynchronously.
bool ice_isBatchDatagram() const noexcept
Determines whether this proxy uses batch datagram invocations.
std::function< void()> ice_getConnectionAsync(std::function< void(Ice::ConnectionPtr)> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr) const
Gets the connection for this proxy.
std::optional< LocatorPrx > ice_getLocator() const noexcept
Gets the locator for this proxy.
std::future< bool > ice_isAAsync(std::string_view typeId, const Ice::Context &context=Ice::noExplicitContext) const
Tests whether this object supports a specific Slice interface.
Ice::EncodingVersion ice_getEncodingVersion() const noexcept
Gets the encoding version used to marshal request parameters.
std::function< void()> ice_invokeAsync(std::string_view operation, Ice::OperationMode mode, std::pair< const std::byte *, const std::byte * > inParams, std::function< void(bool, std::pair< const std::byte *, const std::byte * >)> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr, const Ice::Context &context=Ice::noExplicitContext) const
Invokes an operation asynchronously.
std::function< void()> ice_pingAsync(std::function< void()> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr, const Ice::Context &context=Ice::noExplicitContext) const
Tests whether the target object of this proxy can be reached.
bool ice_isDatagram() const noexcept
Determines whether this proxy uses datagram invocations.
bool ice_isOneway() const noexcept
Determines whether this proxy uses oneway invocations.
ObjectPrx & operator=(const ObjectPrx &rhs) noexcept=default
Copy assignment operator.
std::string ice_id(const Ice::Context &context=Ice::noExplicitContext) const
Gets the type ID of the most-derived Slice interface supported by this object.
const Ice::Identity & ice_getIdentity() const noexcept
Gets the identity embedded in this proxy.
ObjectPrx(const ObjectPrx &other) noexcept=default
Copy constructor.
std::function< void()> ice_isAAsync(std::string_view typeId, std::function< void(bool)> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr, const Ice::Context &context=Ice::noExplicitContext) const
Tests whether this object supports a specific Slice interface.
static const char * ice_staticId() noexcept
Returns the Slice type ID associated with this type.
std::optional< bool > ice_getCompress() const noexcept
Gets the compression override setting of this proxy.
Ice::EndpointSeq ice_getEndpoints() const
Gets the endpoints used by this proxy.
bool ice_isCollocationOptimized() const noexcept
Determines whether this proxy uses collocation optimization.
std::future< Ice::ConnectionPtr > ice_getConnectionAsync() const
Gets the connection for this proxy.
std::future< std::vector< std::string > > ice_idsAsync(const Ice::Context &context=Ice::noExplicitContext) const
Gets the Slice interfaces supported by this object as a list of type IDs.
std::string ice_getAdapterId() const
Gets the adapter ID for this proxy.
Ice::EndpointSelectionType ice_getEndpointSelection() const noexcept
Gets the endpoint selection policy for this proxy (randomly or ordered).
std::optional< RouterPrx > ice_getRouter() const noexcept
Gets the router for this proxy.
bool ice_invoke(std::string_view operation, Ice::OperationMode mode, const std::vector< std::byte > &inParams, std::vector< std::byte > &outParams, const Ice::Context &context=Ice::noExplicitContext) const
Invokes an operation.
Prx ice_facet(std::string facet) const
Creates a proxy that is identical to this proxy, except for the facet.
Definition Proxy.h:559
std::function< void()> ice_invokeAsync(std::string_view operation, Ice::OperationMode mode, const std::vector< std::byte > &inParams, std::function< void(bool, std::vector< std::byte >)> response, std::function< void(std::exception_ptr)> ex=nullptr, std::function< void(bool)> sent=nullptr, const Ice::Context &context=Ice::noExplicitContext) const
Invokes an operation asynchronously.
std::future< std::string > ice_idAsync(const Ice::Context &context=Ice::noExplicitContext) const
Gets the type ID of the most-derived Slice interface supported by this object.
std::chrono::milliseconds ice_getLocatorCacheTimeout() const noexcept
Gets the locator cache timeout of this proxy.
The base class for all Ice proxies.
Definition Proxy.h:232
Represents a byte buffer used for marshaling data using the Slice encoding.
Prx ice_invocationTimeout(const std::chrono::duration< Rep, Period > &timeout) const
Creates a proxy that is identical to this proxy, except for the invocation timeout.
Definition Proxy.h:158
Prx ice_endpointSelection(EndpointSelectionType type) const
Creates a proxy that is identical to this proxy, except for the endpoint selection policy.
Definition Proxy.h:125
Prx ice_locatorCacheTimeout(int timeout) const
Creates a proxy that is identical to this proxy, except for the locator cache timeout.
Definition Proxy.h:175
Prx ice_fixed(ConnectionPtr connection) const
Creates a proxy that is identical to this proxy, except it's a fixed proxy bound to the given connect...
Definition Proxy.h:141
Prx ice_encodingVersion(EncodingVersion version) const
Creates a proxy that is identical to this proxy, except for the encoding used to marshal parameters.
Definition Proxy.h:117
Prx ice_twoway() const
Creates a proxy that is identical to this proxy, but uses twoway invocations.
Definition Proxy.h:204
const Prx * operator->() const noexcept
The arrow operator.
Definition Proxy.h:55
Prx ice_invocationTimeout(int timeout) const
Creates a proxy that is identical to this proxy, except for the invocation timeout.
Definition Proxy.h:149
Prx ice_collocationOptimized(bool b) const
Creates a proxy that is identical to this proxy, except for collocation optimization.
Definition Proxy.h:78
Prx ice_batchOneway() const
Creates a proxy that is identical to this proxy, but uses batch oneway invocations.
Definition Proxy.h:73
Prx ice_compress(bool b) const
Creates a proxy that is identical to this proxy, except for its compression setting which overrides t...
Definition Proxy.h:87
Prx ice_connectionId(std::string id) const
Creates a proxy that is identical to this proxy, except for its connection ID.
Definition Proxy.h:97
Prx ice_context(Context context) const
Creates a proxy that is identical to this proxy, except for the per-proxy context.
Definition Proxy.h:105
Prx ice_datagram() const
Creates a proxy that is identical to this proxy, but uses datagram invocations.
Definition Proxy.h:112
Prx ice_batchDatagram() const
Creates a proxy that is identical to this proxy, but uses batch datagram invocations.
Definition Proxy.h:69
Prx ice_connectionCached(bool b) const
Creates a proxy that is identical to this proxy, except for connection caching.
Definition Proxy.h:92
Prx ice_router(const std::optional< RouterPrx > &router) const
Creates a proxy that is identical to this proxy, except for the router.
Definition Proxy.h:197
Prx ice_adapterId(std::string id) const
Creates a proxy that is identical to this proxy, except for the adapter ID.
Definition Proxy.h:62
Prx ice_locatorCacheTimeout(const std::chrono::duration< Rep, Period > &timeout) const
Creates a proxy that is identical to this proxy, except for the locator cache timeout.
Definition Proxy.h:184
Prx ice_locator(const std::optional< LocatorPrx > &locator) const
Creates a proxy that is identical to this proxy, except for the locator.
Definition Proxy.h:167
Prx ice_oneway() const
Creates a proxy that is identical to this proxy, but uses oneway invocations.
Definition Proxy.h:192
Prx ice_endpoints(EndpointSeq endpoints) const
Creates a proxy that is identical to this proxy, except for the endpoints.
Definition Proxy.h:133
Provides typed proxy functions.
Definition Proxy.h:45
Represents an intermediary object that routes requests and replies between clients and Ice objects th...
Definition Router.h:35
std::shared_ptr< Communicator > CommunicatorPtr
A shared pointer to a Communicator.
const Context noExplicitContext
Marker value used to indicate that no explicit request context was passed to a proxy invocation.
std::vector< EndpointPtr > EndpointSeq
A sequence of endpoints.
Definition EndpointF.h:41
EndpointSelectionType
Determines how the Ice runtime sorts proxy endpoints when establishing a connection.
OperationMode
Specifies if an operation is idempotent, which affects the retry behavior of the Ice client runtime.
std::shared_ptr< Connection > ConnectionPtr
A shared pointer to a Connection.
Definition ConnectionF.h:18
std::map< std::string, std::string, std::less<> > Context
Represents additional information carried by an Ice request.
Definition Context.h:28
The Ice RPC framework.
Definition SampleEvent.h:59
Represents a version of the Slice encoding.
Definition Version.h:65
Represents the identity of an Ice object.
Definition Identity.h:40