Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Object.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_OBJECT_H
4#define ICE_OBJECT_H
5
6#include "IncomingRequest.h"
7#include "ObjectF.h"
8#include "OutgoingResponse.h"
9
10#include <functional>
11#include <string_view>
12
13namespace Ice
14{
15 /// The base class for servants.
16 /// @remark Object is a stateless polymorphic base class. Its copy constructor, move constructor, copy assignment
17 /// operator and move assignment operator are all deleted to prevent accidental slicing. Derived classes can
18 /// define these constructors and assignment operators to reenable copying, moving and slicing.
19 /// @headerfile Ice/Ice.h
20 class ICE_API Object
21 {
22 public:
23 /// Default constructor.
24 Object() noexcept = default;
25
26 virtual ~Object() = default;
27
28 Object(const Object&) = delete;
29 Object& operator=(const Object&) = delete;
30 Object(Object&&) = delete;
31 Object& operator=(Object&&) = delete;
32
33 /// Dispatches an incoming request and returns the corresponding outgoing response.
34 /// @param request The incoming request.
35 /// @param sendResponse A callback that the implementation calls to return the response. @p sendResponse does
36 /// not throw any exception and any @p sendResponse wrapper must not throw any exception. @p sendResponse can be
37 /// called by the thread that called dispatch (the "dispatch thread") or by another thread. The implementation
38 /// must call @p sendResponse exactly once or throw an exception.
39 /// @remark Calling @p sendResponse can be thought of as returning the outgoing response. Just like when you
40 /// return a value from a remote operation, you can only return it once and you don't know if the client
41 /// receives this value. In practice, the Ice-provided @p sendResponse attempts to send the response to the
42 /// client synchronously, but may send it asynchronously. It can also silently fail to send the response back to
43 /// the client. This function is the main building block for the Ice dispatch pipeline. The implementation
44 /// provided by the base class (Object) dispatches incoming requests to the four `Object` operations (`ice_isA`,
45 /// `ice_ping`, `ice_ids` and `ice_id`), and throws OperationNotExistException for all other operations. This
46 /// base implementation is trivial and should be overridden and fully replaced by all derived classes.
47 virtual void dispatch(IncomingRequest& request, std::function<void(OutgoingResponse)> sendResponse);
48
49 /// Tests whether this object supports a specific Slice interface.
50 /// @param typeId The type ID of the Slice interface to test against.
51 /// @param current The Current object of the incoming request.
52 /// @return `true` if this object implements the Slice interface specified by @p typeId or implements a derived
53 /// interface, `false` otherwise.
54 [[nodiscard]] virtual bool ice_isA(std::string typeId, const Current& current) const;
55
56 /// @private
57 void _iceD_ice_isA(IncomingRequest&, std::function<void(OutgoingResponse)>);
58
59 /// Tests whether this object can be reached.
60 /// @param current The Current object of the incoming request.
61 virtual void ice_ping(const Current& current) const;
62
63 /// @private
64 void _iceD_ice_ping(IncomingRequest&, std::function<void(OutgoingResponse)>);
65
66 /// Gets the Slice interfaces supported by this object as a list of Slice type IDs.
67 /// @param current The Current object of the incoming request.
68 /// @return The Slice type IDs of the interfaces supported by this object, in alphabetical order.
69 [[nodiscard]] virtual std::vector<std::string> ice_ids(const Current& current) const;
70
71 /// @private
72 void _iceD_ice_ids(IncomingRequest&, std::function<void(OutgoingResponse)>);
73
74 /// Gets the type ID of the most-derived Slice interface supported by this object.
75 /// @param current The Current object of the incoming request.
76 /// @return The Slice type ID of the most-derived interface.
77 [[nodiscard]] virtual std::string ice_id(const Current& current) const;
78
79 /// @private
80 void _iceD_ice_id(IncomingRequest&, std::function<void(OutgoingResponse)>);
81
82 /// Gets the type ID of the associated Slice interface.
83 /// @return The string `"::Ice::Object"`.
84 static const char* ice_staticId() noexcept;
85 };
86
87 /// Base class for dynamic dispatch servants.
88 /// @remark This class is provided for backward compatibility. You should consider deriving directly from Object
89 /// and overriding the Object::dispatch function.
90 /// @headerfile Ice/Ice.h
91 class ICE_API Blobject : public Object
92 {
93 public:
94 /// Dispatches an incoming request.
95 /// @param inEncaps An encapsulation containing the encoded in-parameters for the operation.
96 /// @param outEncaps An encapsulation containing the encoded result for the operation. You can leave it empty
97 /// when the operation returns no results; the Ice runtime then marshals an empty encapsulation.
98 /// @param current The Current object of the incoming request.
99 /// @return `true` if the dispatch completes successfully, `false` if the dispatch completes with a user
100 /// exception encoded in @p outEncaps.
101 virtual bool
102 ice_invoke(std::vector<std::byte> inEncaps, std::vector<std::byte>& outEncaps, const Current& current) = 0;
103
104 /// @private
105 void dispatch(IncomingRequest& request, std::function<void(OutgoingResponse)> sendResponse) final;
106 };
107
108 /// Base class for dynamic dispatch servants that uses the array mapping.
109 /// @remark This class is provided for backward compatibility. You should consider deriving directly from Object
110 /// and overriding the Object::dispatch function.
111 /// @headerfile Ice/Ice.h
112 class ICE_API BlobjectArray : public Object
113 {
114 public:
115 /// @copydoc Blobject::ice_invoke
116 virtual bool ice_invoke(
117 std::pair<const std::byte*, const std::byte*> inEncaps,
118 std::vector<std::byte>& outEncaps,
119 const Current& current) = 0;
120
121 /// @private
122 void dispatch(IncomingRequest&, std::function<void(OutgoingResponse)>) final;
123 };
124
125 /// Base class for asynchronous dynamic dispatch servants.
126 /// @remark This class is provided for backward compatibility. You should consider deriving directly from Object
127 /// and overriding the Object::dispatch function.
128 /// @headerfile Ice/Ice.h
129 class ICE_API BlobjectAsync : public Object
130 {
131 public:
132 /// Dispatches an incoming request asynchronously.
133 /// @param inEncaps An encapsulation containing the encoded in-parameters for the operation.
134 /// @param response The response callback. It accepts:
135 /// - `returnValue` `true` if the operation completed successfully, `false` if it completed with a user
136 /// exception encoded in @p outEncaps.
137 /// - `outEncaps` An encapsulation containing the encoded result. You can pass an empty byte sequence when
138 /// the operation returns no results; the Ice runtime then marshals an empty encapsulation.
139 /// @param exception The exception callback.
140 /// @param current The Current object of the incoming request.
141 virtual void ice_invokeAsync(
142 std::vector<std::byte> inEncaps,
143 std::function<void(bool, const std::vector<std::byte>&)> response,
144 std::function<void(std::exception_ptr)> exception,
145 const Current& current) = 0;
146
147 /// @private
148 void dispatch(IncomingRequest&, std::function<void(OutgoingResponse)>) final;
149 };
150
151 /// Base class for asynchronous dynamic dispatch servants that uses the array mapping.
152 /// @remark This class is provided for backward compatibility. You should consider deriving directly from Object
153 /// and overriding the Object::dispatch function.
154 /// @headerfile Ice/Ice.h
155 class ICE_API BlobjectArrayAsync : public Object
156 {
157 public:
158 /// @copydoc BlobjectAsync::ice_invokeAsync
159 virtual void ice_invokeAsync(
160 std::pair<const std::byte*, const std::byte*> inEncaps,
161 std::function<void(bool, std::pair<const std::byte*, const std::byte*>)> response,
162 std::function<void(std::exception_ptr)> exception,
163 const Current& current) = 0;
164
165 /// @private
166 void dispatch(IncomingRequest&, std::function<void(OutgoingResponse)>) final;
167 };
168}
169
170#endif
virtual void ice_invokeAsync(std::pair< const std::byte *, const std::byte * > inEncaps, std::function< void(bool, std::pair< const std::byte *, const std::byte * >)> response, std::function< void(std::exception_ptr)> exception, const Current &current)=0
Dispatches an incoming request asynchronously.
Base class for asynchronous dynamic dispatch servants that uses the array mapping.
Definition Object.h:156
virtual bool ice_invoke(std::pair< const std::byte *, const std::byte * > inEncaps, std::vector< std::byte > &outEncaps, const Current &current)=0
Dispatches an incoming request.
Base class for dynamic dispatch servants that uses the array mapping.
Definition Object.h:113
virtual void ice_invokeAsync(std::vector< std::byte > inEncaps, std::function< void(bool, const std::vector< std::byte > &)> response, std::function< void(std::exception_ptr)> exception, const Current &current)=0
Dispatches an incoming request asynchronously.
Base class for asynchronous dynamic dispatch servants.
Definition Object.h:130
virtual bool ice_invoke(std::vector< std::byte > inEncaps, std::vector< std::byte > &outEncaps, const Current &current)=0
Dispatches an incoming request.
Base class for dynamic dispatch servants.
Definition Object.h:92
Represents a request received by a connection.
virtual std::string ice_id(const Current &current) const
Gets the type ID of the most-derived Slice interface supported by this object.
Object() noexcept=default
Default constructor.
virtual void dispatch(IncomingRequest &request, std::function< void(OutgoingResponse)> sendResponse)
Dispatches an incoming request and returns the corresponding outgoing response.
virtual std::vector< std::string > ice_ids(const Current &current) const
Gets the Slice interfaces supported by this object as a list of Slice type IDs.
virtual bool ice_isA(std::string typeId, const Current &current) const
Tests whether this object supports a specific Slice interface.
virtual void ice_ping(const Current &current) const
Tests whether this object can be reached.
static const char * ice_staticId() noexcept
Gets the type ID of the associated Slice interface.
Represents the response to an incoming request.
The Ice RPC framework.
Definition SampleEvent.h:66
Provides information about an incoming request being dispatched.
Definition Current.h:18