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#include "qgrpcstatus.h"
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \class QGrpcStatus
11 \inmodule QtGrpc
12
13 \brief The QGrpcStatus class contains information about last gRPC operation.
14
15 In case of error in call/stream processing QGrpcStatus will contain code
16 any of non-Ok QGrpcStatus::StatusCode.
17 This class combines QGrpcStatus::StatusCode and message returned from
18 channel or QGrpc framework.
19*/
20
21/*!
22 \enum QGrpcStatus::StatusCode
23
24 \brief Channel's status codes.
25
26 \value Ok No error
27 \value Cancelled The operation was cancelled, typically by the caller.
28 \omitvalue Unknown
29 \value InvalidArgument The client specified an invalid argument,
30 \value DeadlineExceeded The deadline expired before the operation
31 could complete,
32 \value NotFound Some requested entity (e.g., file or directory) was
33 not found.
34 \value AlreadyExists The entity that a client attempted to create
35 (e.g., file or directory) already exists.
36 \value PermissionDenied The caller does not have permission to execute
37 the specified operation.
38 \c PermissionDenied must not be used for rejections caused by exhausting
39 some resource (use \c ResourceExhausted instead for those errors).
40 \c PermissionDenied must not be used if the caller can not be identified
41 (use \c Unauthenticated instead for those errors).
42 This error code does not imply the request is valid or the requested
43 entity exists or satisfies other pre-conditions.
44 \value ResourceExhausted Some resource has been exhausted, perhaps
45 a per-user quota, or perhaps the entire file system is out of space.
46 \value FailedPrecondition The operation was rejected because the system
47 is not in a state required for the operation's execution.
48 \value Aborted The operation was aborted, typically due to
49 a concurrency issue such as a sequencer check failure or transaction abort.
50 \value OutOfRange The operation was attempted past the valid range.
51 \value Unimplemented The operation is not implemented or is
52 not supported/enabled in this service.
53 \value Internal This means that some invariants expected by
54 the underlying system have been broken.
55 \value Unavailable The service is currently unavailable.
56 This is most likely a transient condition, which can be corrected
57 by retrying with a backoff. Note that it is not always safe
58 to retry non-idempotent operations.
59 \value DataLoss Unrecoverable data loss or corruption.
60 \value Unauthenticated The request does not have valid authentication
61 credentials for the operation.
62
63 \sa{https://github.com/grpc/grpc/blob/master/doc/statuscodes.md}{gRPC status codes}
64*/
65
66/*!
67 \fn bool QGrpcStatus::operator==(const QGrpcStatus &lhs, QGrpcStatus::StatusCode code)
68 Returns \c true if \a lhs status code and \a code are equal.
69*/
70
71/*!
72 \fn bool QGrpcStatus::operator!=(const QGrpcStatus &lhs, QGrpcStatus::StatusCode code)
73 Returns \c true if \a lhs status code and \a code are not equal.
74*/
75
76/*!
77 \fn bool QGrpcStatus::operator==(const QGrpcStatus &lhs, const QGrpcStatus &rhs)
78 Returns \c true if \a lhs status code and \a rhs status code are equal.
79*/
80
81/*!
82 \fn bool QGrpcStatus::operator!=(const QGrpcStatus &lhs, const QGrpcStatus &rhs)
83 Returns \c true if \a lhs status code and \a rhs status code are not equal.
84*/
85
86class QGrpcStatusPrivate
87{
88public:
89 QGrpcStatusPrivate(QGrpcStatus::StatusCode code, const QString &message)
90 : m_code(code), m_message(message)
91 {
92 }
93
94 ~QGrpcStatusPrivate() = default;
95
96 QGrpcStatus::StatusCode m_code;
97 QString m_message;
98};
99
100/*!
101 Creates an instance of QGrpcStatus with a status \a code and a \a message.
102*/
103QGrpcStatus::QGrpcStatus(StatusCode code, const QString &message)
104 : dPtr(std::make_unique<QGrpcStatusPrivate>(args&: code, args: message))
105{
106}
107
108/*!
109 Copies the \a other QGrpcStatus to this QGrpcStatus.
110*/
111QGrpcStatus::QGrpcStatus(const QGrpcStatus &other)
112 : dPtr(std::make_unique<QGrpcStatusPrivate>(args&: other.dPtr->m_code, args&: other.dPtr->m_message))
113{
114}
115
116/*!
117 Moves \a other into new instance of QGrpcStatus.
118*/
119QGrpcStatus::QGrpcStatus(QGrpcStatus &&other) : dPtr(std::move(other.dPtr))
120{
121}
122
123/*!
124 Assigns the \a other QGrpcStatus into this QGrpcStatus.
125*/
126QGrpcStatus &QGrpcStatus::operator=(const QGrpcStatus &other)
127{
128 dPtr->m_code = other.dPtr->m_code;
129 dPtr->m_message = other.dPtr->m_message;
130 return *this;
131}
132
133/*!
134 Move assigns \a other into new instance of QGrpcStatus.
135*/
136QGrpcStatus &QGrpcStatus::operator=(QGrpcStatus &&other)
137{
138 dPtr = std::move(other.dPtr);
139 return *this;
140}
141
142/*!
143 Destroys the QGrpcStatus.
144*/
145QGrpcStatus::~QGrpcStatus() = default;
146
147/*!
148 \property QGrpcStatus::code
149 \brief QGrpcStatus::StatusCode received for prior gRPC call.
150*/
151QGrpcStatus::StatusCode QGrpcStatus::code() const
152{
153 return dPtr->m_code;
154}
155
156/*!
157 \property QGrpcStatus::message
158 \brief Status message received for prior gRPC call.
159*/
160QString QGrpcStatus::message() const
161{
162 return dPtr->m_message;
163}
164
165QT_END_NAMESPACE
166
167#include "moc_qgrpcstatus.cpp"
168

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