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 QGRPCOPERATION_H
6#define QGRPCOPERATION_H
7
8#include <QtCore/QObject>
9#include <QtGrpc/qgrpcstatus.h>
10#include <QtGrpc/qtgrpcglobal.h>
11#include <QtGrpc/qgrpcmetadata.h>
12#include <QtProtobuf/qabstractprotobufserializer.h>
13
14QT_BEGIN_NAMESPACE
15
16class QGrpcOperationPrivate;
17class Q_GRPC_EXPORT QGrpcOperation : public QObject
18{
19 Q_OBJECT
20
21public:
22 template <typename T>
23 T read() const
24 {
25 T value;
26 if (auto ser = serializer(); ser)
27 ser->deserialize(&value, data());
28 return value;
29 }
30
31 void setData(const QByteArray &data);
32 void setData(QByteArray &&data);
33
34 virtual void abort() = 0;
35
36 void setMetadata(const QGrpcMetadata &metadata);
37 void setMetadata(QGrpcMetadata &&metadata);
38 QGrpcMetadata metadata() const;
39Q_SIGNALS:
40 void finished();
41 void errorOccurred(const QGrpcStatus &status);
42
43protected:
44 explicit QGrpcOperation(std::shared_ptr<QAbstractProtobufSerializer> serializer);
45 ~QGrpcOperation() override;
46
47private:
48 Q_DISABLE_COPY_MOVE(QGrpcOperation)
49
50 QByteArray data() const;
51 std::shared_ptr<QAbstractProtobufSerializer> serializer() const;
52
53 Q_DECLARE_PRIVATE(QGrpcOperation)
54};
55
56QT_END_NAMESPACE
57
58#endif // QGRPCOPERATION_H
59

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