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 QGRPCSTATUS_H
6#define QGRPCSTATUS_H
7
8#include <QtCore/QMetaType>
9#include <QtCore/QString>
10#include <QtCore/qobjectdefs.h>
11#include <QtGrpc/qtgrpcglobal.h>
12
13#include <memory>
14
15QT_BEGIN_NAMESPACE
16
17class QGrpcStatusPrivate;
18
19class Q_GRPC_EXPORT QGrpcStatus final
20{
21 Q_GADGET
22 Q_PROPERTY(StatusCode code READ code CONSTANT)
23 Q_PROPERTY(QString message READ message CONSTANT)
24
25public:
26 enum StatusCode : uint8_t {
27 Ok = 0,
28 Cancelled = 1,
29 Unknown = 2,
30 InvalidArgument = 3,
31 DeadlineExceeded = 4,
32 NotFound = 5,
33 AlreadyExists = 6,
34 PermissionDenied = 7,
35 Unauthenticated = 16,
36 ResourceExhausted = 8,
37 FailedPrecondition = 9,
38 Aborted = 10,
39 OutOfRange = 11,
40 Unimplemented = 12,
41 Internal = 13,
42 Unavailable = 14,
43 DataLoss = 15,
44 };
45
46 Q_ENUM(StatusCode)
47
48 QGrpcStatus(StatusCode code = StatusCode::Ok, const QString &message = QString());
49 ~QGrpcStatus();
50
51 StatusCode code() const;
52 QString message() const;
53
54 QGrpcStatus(const QGrpcStatus &other);
55 QGrpcStatus &operator=(const QGrpcStatus &other);
56
57 QGrpcStatus(QGrpcStatus &&other);
58 QGrpcStatus &operator=(QGrpcStatus &&other);
59
60private:
61 friend bool operator==(const QGrpcStatus &lhs, QGrpcStatus::StatusCode code)
62 {
63 return lhs.code() == code;
64 }
65 friend bool operator!=(const QGrpcStatus &lhs, QGrpcStatus::StatusCode code)
66 {
67 return lhs.code() != code;
68 }
69 friend bool operator==(const QGrpcStatus &lhs, const QGrpcStatus &rhs)
70 {
71 return lhs.code() == rhs.code();
72 }
73 friend bool operator!=(const QGrpcStatus &lhs, const QGrpcStatus &rhs)
74 {
75 return lhs.code() == rhs.code();
76 }
77
78 std::unique_ptr<QGrpcStatusPrivate> dPtr;
79};
80
81QT_END_NAMESPACE
82
83Q_DECLARE_METATYPE(QGrpcStatus)
84
85#endif // QGRPCSTATUS_H
86

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