QGrpcOperationContext Class
The QGrpcOperationContext class provides context for communication between an individual gRPC operation and a channel. More...
Header: | #include <QGrpcOperationContext> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Grpc) target_link_libraries(mytarget PRIVATE Qt6::Grpc) |
Since: | Qt 6.7 |
Inherits: | QObject |
Public Functions
virtual | ~QGrpcOperationContext() override |
QByteArrayView | argument() const |
const QGrpcCallOptions & | callOptions() const & |
QLatin1StringView | method() const |
std::shared_ptr<const QAbstractProtobufSerializer> | serializer() const |
const QHash<QByteArray, QByteArray> & | serverMetadata() const & |
QLatin1StringView | service() const |
void | setServerMetadata(QHash<QByteArray, QByteArray> &&metadata) |
void | setServerMetadata(const QHash<QByteArray, QByteArray> &metadata) |
Signals
void | cancelRequested() |
void | messageReceived(const QByteArray &data) |
void | writeMessageRequested(const QByteArray &data) |
void | writesDoneRequested() |
Detailed Description
QGrpcOperationContext is constructed internally when a remote procedure call (RPC) is requested, mediating interaction between the client's operation request and the channel's operation outcome.
RPCs requested on the client interface return specializations of QGrpcOperation, such as QGrpcCallReply, QGrpcServerStream, QGrpcClientStream, or QGrpcBidiStream. These classes are implicitly integrated with the underlying QGrpcOperationContext counterpart.
Note: Don't use this class directly unless implementing a custom channel.
The signals contained within this class are used to build the communication between the client-facing QGrpcOperation and the QAbstractGrpcChannel implementation. These operations are asynchronous in nature, and multiple RPCs can operate on the same channel concurrently. Channels typically treat all operations the same, and it is the channel's responsibility to correctly support and restrict the subset of features its RPC type supports.
Signals which should only be emitted by the channel's implementation are:
- finished()
- messageReceived()
Signals which will be emitted by QGrpcOperation and its specializations are:
Custom implementations of QAbstractGrpcChannel must handle the client's signals, as no default signal handling is provided, and emit their own signals accordingly.
Member Function Documentation
void QGrpcOperationContext::setServerMetadata(QHash<QByteArray, QByteArray> &&metadata)
void QGrpcOperationContext::setServerMetadata(const QHash<QByteArray, QByteArray> &metadata)
Sets the server metadata received from the service.
[override virtual noexcept]
QGrpcOperationContext::~QGrpcOperationContext()
Destroys the operation-context.
[noexcept]
QByteArrayView QGrpcOperationContext::argument() const
Returns the serialized argument that is utilized by this operation-context.
[noexcept]
const QGrpcCallOptions &QGrpcOperationContext::callOptions() const &
Returns the call options that is utilized by this operation-context.
For channel-wide options, see QGrpcChannelOptions.
[signal]
void QGrpcOperationContext::cancelRequested()
This signal is emitted by QGrpcOperation when requesting cancellation of the communication.
The channel is expected to connect its cancellation logic to this signal and attempt to cancel the RPC and return immediately. Successful cancellation cannot be guaranteed. Further processing of the data received from a channel is not required and should be avoided.
See also QGrpcOperation::cancel.
[signal]
void QGrpcOperationContext::messageReceived(const QByteArray &data)
This signal should be emitted by the channel when a new chunk of data is received from the server.
For client streams and unary calls, this means that the single and final response has arrived and communication is about to finish.
For server and bidirectional streams, this signal should be continuously emitted by the channel upon receiving each new messages.
Note: This signal is implicitly connected to the QGrpcOperation counterpart.
See also QGrpcServerStream::messageReceived and QGrpcBidiStream::messageReceived.
[noexcept]
QLatin1StringView QGrpcOperationContext::method() const
Returns the method name of the service associated with this operation-context.
std::shared_ptr<const QAbstractProtobufSerializer> QGrpcOperationContext::serializer() const
Returns the serializer of this operation-context
[noexcept]
const QHash<QByteArray, QByteArray> &QGrpcOperationContext::serverMetadata() const &
Returns the metadata received from the server.
Note: This method is used implicitly by the QGrpcOperation counterpart.
See also setServerMetadata().
[noexcept]
QLatin1StringView QGrpcOperationContext::service() const
Returns the service name associated with this operation-context.
[signal]
void QGrpcOperationContext::writeMessageRequested(const QByteArray &data)
This signal is emitted by QGrpcClientStream or QGrpcBidiStream when it has serialized data ready for a channel to deliver.
The channel is expected to connect its writing logic to this signal and wrap the serialized data in channel-related headers before writing it to the wire.
See also QGrpcClientStream::writeMessage and QGrpcBidiStream::writeMessage.
[signal]
void QGrpcOperationContext::writesDoneRequested()
This signal is emitted by QGrpcClientStream or QGrpcBidiStream to indicate that it's done writing messages. The channel should respond to this by half-closing the stream.
Note: After receiving this signal no more write operations are permitted for the streaming RPCs. The server can still send messages, which should be forwarded with messageReceived().
See also QGrpcClientStream::writesDone and QGrpcBidiStream::writesDone.
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.