QGrpcOperationContext Class | Qt GRPC 6.8.0
Description: The QGrpcOperationContext class implements common logic to handle the gRPC communication from the channel side.

- Qt 6.8
- Qt GRPC
- C++ Classes
- QtGrpc (Technical Preview)
- QGrpcOperationContext
- Qt 6.8.0 Reference Documentation

# QGrpcOperationContext Class

The QGrpcOperationContext class implements common logic to handle the gRPC communication from the channel side. More...

Header: | `#include <QGrpcOperationContext>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Grpc)` `target_link_libraries(mytarget PRIVATE Qt6::Grpc)`
Since: | Qt 6.7
Inherits: | QObject
Status: | Technical Preview

- List of all members, including inherited members

## Public Functions

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 | setArgument(QByteArrayView arg)
void | setCallOptions(const QGrpcCallOptions &options)
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

## Member Function Documentation

### `[noexcept]` QByteArrayView QGrpcOperationContext::argument() const

Returns the serialized arguments that are used for this operation.

See also setArgument().

### `[noexcept]` const QGrpcCallOptions &QGrpcOperationContext::callOptions() const &

Return the options that are assigned to this operation.

See also setCallOptions().

### `[signal]` void QGrpcOperationContext::cancelRequested()

The signal is emitted when client requests to terminate the communication.

The signal should only be emitted from the client counterpart. Implementations of QAbstractGrpcChannel should attempt to close connection client-server connection and return immediately. The successful connection break is not guarateed. Further processing of the data received from a channel is not required and is not recommended.

The client side will be notificated by the QGrpcOperationContext::finished signal with QtGrpc::StatusCode::Cancelled status code.

The signal is implicitly connected to the QGrpcOperation counterpart.

### `[signal]` void QGrpcOperationContext::messageReceived(const QByteArray &data)

The signal should be emitted by the channel when the new chunk of data is received.

For client streams and unary calls, this means that the response is received from the server, and communication will be successfully finished. For server and bidi streams this signal should be called by channel to signalize that receiving of new message is completed and user business logic now can process it at the client side.

The signal is implicitly connected to the QGrpcOperation counterpart.

### `[noexcept]` QLatin1StringView QGrpcOperationContext::method() const

Returns the method name that is assigned to this operation.

### `[noexcept]` std::shared_ptr<const QAbstractProtobufSerializer> QGrpcOperationContext::serializer() const

Return the serializer that is assigned to this operation.

### `[noexcept]` const QHash<QByteArray, QByteArray> &QGrpcOperationContext::serverMetadata() const &

Returns the metadata that is received from server.

The method is used implicitly by QGrpcOperation counterpart.

See also setServerMetadata().

### `[noexcept]` QLatin1StringView QGrpcOperationContext::service() const

Returns the service name that is assigned to this operation.

### void QGrpcOperationContext::setArgument(QByteArrayView arg)

Updates the arg attribute that will be used for this operation.

The method expects arg to be serialized data.

See also argument().

### void QGrpcOperationContext::setCallOptions(const QGrpcCallOptions &options)

Updates the call options attribute.

See also callOptions().

### void QGrpcOperationContext::setServerMetadata(QHash<QByteArray, QByteArray> &&metadata)

Stores the recently received server metadata.

The metadata then can be processed on the client side.

See also serverMetadata().

### void QGrpcOperationContext::setServerMetadata(const QHash<QByteArray, QByteArray> &metadata)

Stores the recently received server metadata.

The metadata then can be processed on the client side.

### `[signal]` void QGrpcOperationContext::writeMessageRequested(const QByteArray &data)

The signal is emitted when the client tries to send a new message to the channel.

This signal can only be emitted by client or bidi streams. Implementations of QAbstractGrpcChannel should connect the sending logic to this signal. The data should be wrapped with the channel-related headers and sent to the wire.

The signal is implicitly connected to the QGrpcOperation counterpart.

### `[signal]` void QGrpcOperationContext::writesDoneRequested()

T.B.A