1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QGRPCOPERATIONCONTEXT_H |
5 | #define QGRPCOPERATIONCONTEXT_H |
6 | |
7 | #include <QtGrpc/qtgrpcglobal.h> |
8 | |
9 | #include <QtProtobuf/qabstractprotobufserializer.h> |
10 | |
11 | #include <QtCore/qhash.h> |
12 | #include <QtCore/qobject.h> |
13 | #include <QtCore/qstringfwd.h> |
14 | |
15 | #include <memory> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QGrpcCallOptions; |
20 | class QGrpcOperationContextPrivate; |
21 | class QGrpcStatus; |
22 | |
23 | class Q_GRPC_EXPORT QGrpcOperationContext final : public QObject |
24 | { |
25 | Q_OBJECT |
26 | QT_DEFINE_TAG_STRUCT(PrivateConstructor); |
27 | |
28 | public: |
29 | explicit QGrpcOperationContext(QLatin1StringView method, QLatin1StringView service, |
30 | QByteArrayView argument, const QGrpcCallOptions &options, |
31 | std::shared_ptr<QAbstractProtobufSerializer> serializer, |
32 | PrivateConstructor); |
33 | ~QGrpcOperationContext() override; |
34 | |
35 | [[nodiscard]] QLatin1StringView method() const noexcept; |
36 | [[nodiscard]] QLatin1StringView service() const noexcept; |
37 | [[nodiscard]] QByteArrayView argument() const noexcept; |
38 | |
39 | void callOptions() && = delete; |
40 | [[nodiscard]] const QGrpcCallOptions &callOptions() const & noexcept; |
41 | |
42 | void serverMetadata() && = delete; |
43 | [[nodiscard]] const QHash<QByteArray, QByteArray> &serverMetadata() const & noexcept; |
44 | void setServerMetadata(const QHash<QByteArray, QByteArray> &metadata); |
45 | void setServerMetadata(QHash<QByteArray, QByteArray> &&metadata); |
46 | |
47 | [[nodiscard]] std::shared_ptr<const QAbstractProtobufSerializer> serializer() const; |
48 | |
49 | Q_SIGNALS: |
50 | // Outgoing signals of the channel. |
51 | void finished(const QGrpcStatus &status); |
52 | void messageReceived(const QByteArray &data); |
53 | // Icoming signals from the client. |
54 | void cancelRequested(); |
55 | void writeMessageRequested(const QByteArray &data); |
56 | void writesDoneRequested(); |
57 | |
58 | private: |
59 | Q_DISABLE_COPY_MOVE(QGrpcOperationContext) |
60 | Q_DECLARE_PRIVATE(QGrpcOperationContext) |
61 | |
62 | friend class QAbstractGrpcChannel; |
63 | |
64 | public: |
65 | bool event(QEvent *event) override; |
66 | }; |
67 | |
68 | QT_END_NAMESPACE |
69 | |
70 | #endif // QGRPCOPERATIONCONTEXT_H |
71 | |