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 QGRPCLIENTBASE_H
6#define QGRPCLIENTBASE_H
7
8#include <QtGrpc/qabstractgrpcchannel.h>
9#include <QtGrpc/qgrpccalloptions.h>
10#include <QtGrpc/qgrpccallreply.h>
11#include <QtGrpc/qgrpcstatus.h>
12#include <QtGrpc/qgrpcstream.h>
13#include <QtGrpc/qtgrpcglobal.h>
14
15#include <QtCore/qobject.h>
16#include <QtCore/qstringfwd.h>
17#include <QtCore/qtclasshelpermacros.h>
18
19#include <memory>
20
21QT_BEGIN_NAMESPACE
22
23class QProtobufMessage;
24
25class QGrpcClientBasePrivate;
26class Q_GRPC_EXPORT QGrpcClientBase : public QObject
27{
28 Q_OBJECT
29 Q_PROPERTY(std::shared_ptr<QAbstractGrpcChannel> channel READ channel WRITE attachChannel NOTIFY
30 channelChanged)
31
32public:
33 ~QGrpcClientBase() override;
34
35 bool attachChannel(std::shared_ptr<QAbstractGrpcChannel> channel);
36 [[nodiscard]] std::shared_ptr<QAbstractGrpcChannel> channel() const;
37
38Q_SIGNALS:
39 void channelChanged();
40
41protected:
42 explicit QGrpcClientBase(QLatin1StringView service, QObject *parent = nullptr);
43
44 std::unique_ptr<QGrpcCallReply> call(QLatin1StringView method, const QProtobufMessage &arg,
45 const QGrpcCallOptions &options);
46
47 std::unique_ptr<QGrpcServerStream> serverStream(QLatin1StringView method,
48 const QProtobufMessage &arg,
49 const QGrpcCallOptions &options);
50
51 std::unique_ptr<QGrpcClientStream> clientStream(QLatin1StringView method,
52 const QProtobufMessage &arg,
53 const QGrpcCallOptions &options);
54
55 std::unique_ptr<QGrpcBidiStream> bidiStream(QLatin1StringView method,
56 const QProtobufMessage &arg,
57 const QGrpcCallOptions &options);
58
59private:
60 Q_DISABLE_COPY_MOVE(QGrpcClientBase)
61 Q_DECLARE_PRIVATE(QGrpcClientBase)
62
63public:
64 bool event(QEvent *event) override;
65};
66
67QT_END_NAMESPACE
68
69#endif // QGRPCLIENTBASE_H
70

source code of qtgrpc/src/grpc/qgrpcclientbase.h