1 | // Copyright (C) 2022 The Qt Company Ltd. |
2 | // Copyright (C) 2019 Alexey Edelev <semlanik@gmail.com> |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QABSTRACTGRPCCHANNEL_H |
6 | #define QABSTRACTGRPCCHANNEL_H |
7 | |
8 | #include <QtGrpc/qtgrpcglobal.h> |
9 | |
10 | #include <QtCore/qmetatype.h> |
11 | #include <QtCore/qstringfwd.h> |
12 | #include <QtCore/qtclasshelpermacros.h> |
13 | |
14 | #include <memory> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class QAbstractProtobufSerializer; |
19 | class QGrpcBidiStream; |
20 | class QGrpcCallReply; |
21 | class QGrpcOperationContext; |
22 | class QGrpcChannelOptions; |
23 | class QGrpcCallOptions; |
24 | class QGrpcClientBase; |
25 | class QGrpcClientStream; |
26 | class QGrpcServerStream; |
27 | |
28 | class QAbstractGrpcChannelPrivate; |
29 | class Q_GRPC_EXPORT QAbstractGrpcChannel |
30 | { |
31 | public: |
32 | virtual ~QAbstractGrpcChannel(); |
33 | |
34 | [[nodiscard]] virtual std::shared_ptr<QAbstractProtobufSerializer> serializer() const = 0; |
35 | |
36 | [[nodiscard]] const QGrpcChannelOptions &channelOptions() const & noexcept; |
37 | void channelOptions() && = delete; |
38 | |
39 | void setChannelOptions(const QGrpcChannelOptions &options); |
40 | void setChannelOptions(QGrpcChannelOptions &&options); |
41 | |
42 | protected: |
43 | QAbstractGrpcChannel(); |
44 | explicit QAbstractGrpcChannel(QAbstractGrpcChannelPrivate &dd); |
45 | explicit QAbstractGrpcChannel(const QGrpcChannelOptions &options); |
46 | |
47 | private: |
48 | virtual void call(std::shared_ptr<QGrpcOperationContext> operationContext) = 0; |
49 | virtual void serverStream(std::shared_ptr<QGrpcOperationContext> operationContext) = 0; |
50 | virtual void clientStream(std::shared_ptr<QGrpcOperationContext> operationContext) = 0; |
51 | virtual void bidiStream(std::shared_ptr<QGrpcOperationContext> operationContext) = 0; |
52 | |
53 | private: |
54 | std::unique_ptr<QGrpcCallReply> call(QLatin1StringView method, QLatin1StringView service, |
55 | QByteArrayView arg, const QGrpcCallOptions &options); |
56 | std::unique_ptr<QGrpcServerStream> serverStream(QLatin1StringView method, |
57 | QLatin1StringView service, QByteArrayView arg, |
58 | const QGrpcCallOptions &options); |
59 | std::unique_ptr<QGrpcClientStream> clientStream(QLatin1StringView method, |
60 | QLatin1StringView service, QByteArrayView arg, |
61 | const QGrpcCallOptions &options); |
62 | std::unique_ptr<QGrpcBidiStream> bidiStream(QLatin1StringView method, QLatin1StringView service, |
63 | QByteArrayView arg, |
64 | const QGrpcCallOptions &options); |
65 | |
66 | private: |
67 | friend class QGrpcClientBase; |
68 | friend class QGrpcClientBasePrivate; |
69 | |
70 | std::unique_ptr<QAbstractGrpcChannelPrivate> d_ptr; |
71 | |
72 | Q_DISABLE_COPY_MOVE(QAbstractGrpcChannel) |
73 | Q_DECLARE_PRIVATE(QAbstractGrpcChannel) |
74 | }; |
75 | |
76 | QT_END_NAMESPACE |
77 | |
78 | #endif // QABSTRACTGRPCCHANNEL_H |
79 | |