1 | // Copyright (C) 2023 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <qtgrpcglobal_p.h> |
5 | |
6 | #include "qgrpccalloptions.h" |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | using namespace Qt::StringLiterals; |
11 | |
12 | /*! |
13 | \class QGrpcCallOptions |
14 | \inmodule QtGrpc |
15 | \brief The QGrpcCallOptions is an storage class used by set additional call options. |
16 | |
17 | QGrpcCallOptions provides a set of functions to access the call options |
18 | that are used by gRPC channels to communicate with the services. |
19 | */ |
20 | |
21 | struct QGrpcCallOptionsPrivate |
22 | { |
23 | public: |
24 | std::optional<QUrl> host; |
25 | std::optional<std::chrono::milliseconds> deadline; |
26 | QGrpcMetadata metadata; |
27 | std::optional<qint64> maxRetryAttempts; |
28 | }; |
29 | |
30 | /*! |
31 | Constructs an empty QGrpcCallOptions object. |
32 | */ |
33 | QGrpcCallOptions::QGrpcCallOptions() : dPtr(std::make_unique<QGrpcCallOptionsPrivate>()) |
34 | { |
35 | } |
36 | |
37 | /*! |
38 | Destroys the QGrpcCallOptions object. |
39 | */ |
40 | QGrpcCallOptions::~QGrpcCallOptions() = default; |
41 | |
42 | /*! |
43 | Construct a copy of QGrpcCallOptions with \a other object. |
44 | */ |
45 | QGrpcCallOptions::QGrpcCallOptions(const QGrpcCallOptions &other) |
46 | : dPtr(std::make_unique<QGrpcCallOptionsPrivate>(args&: *other.dPtr)) |
47 | { |
48 | } |
49 | |
50 | /*! |
51 | Assigns \a other to this QGrpcCallOptions and returns a reference to this |
52 | QGrpcCallOptions. |
53 | */ |
54 | QGrpcCallOptions &QGrpcCallOptions::operator=(const QGrpcCallOptions &other) |
55 | { |
56 | *dPtr = *other.dPtr; |
57 | return *this; |
58 | } |
59 | |
60 | /*! |
61 | Sets deadline value with \a deadline and returns updated QGrpcCallOptions object. |
62 | */ |
63 | QGrpcCallOptions &QGrpcCallOptions::withDeadline(std::chrono::milliseconds deadline) |
64 | { |
65 | dPtr->deadline = deadline; |
66 | return *this; |
67 | } |
68 | |
69 | /*! |
70 | Sets maximum retry attempts value with \a maxRetryAttempts and returns updated QGrpcCallOptions object. |
71 | */ |
72 | QGrpcCallOptions &QGrpcCallOptions::withMaxRetryAttempts(qint64 maxRetryAttempts) |
73 | { |
74 | dPtr->maxRetryAttempts = maxRetryAttempts; |
75 | return *this; |
76 | } |
77 | |
78 | /*! |
79 | Sets \a metadata for a call and returns updated QGrpcCallOptions object. |
80 | |
81 | For HTTP2-based channels, \a metadata is converted into HTTP/2 headers, that |
82 | added to the corresponding HTTP/2 request. |
83 | */ |
84 | QGrpcCallOptions &QGrpcCallOptions::withMetadata(const QGrpcMetadata &metadata) |
85 | { |
86 | dPtr->metadata = metadata; |
87 | return *this; |
88 | } |
89 | |
90 | /*! |
91 | Returns deadline value for a call. |
92 | |
93 | Deadline value controls the maximum execution time of an call or a stream. |
94 | This value overrides value set by QGrpcChannelOptions::deadline() |
95 | for a specific call or stream. |
96 | |
97 | If value was not set returns empty std::optional. |
98 | */ |
99 | std::optional<std::chrono::milliseconds> QGrpcCallOptions::deadline() const |
100 | { |
101 | return dPtr->deadline; |
102 | } |
103 | |
104 | /*! |
105 | Returns maximum retry attempts value for a call. |
106 | |
107 | If value was not set returns empty std::optional. |
108 | */ |
109 | std::optional<qint64> QGrpcCallOptions::maxRetryAttempts() const |
110 | { |
111 | return dPtr->maxRetryAttempts; |
112 | } |
113 | |
114 | /*! |
115 | Returns metadata used for a call. |
116 | |
117 | If value was not set returns empty QGrpcMetadata. |
118 | */ |
119 | QGrpcMetadata QGrpcCallOptions::metadata() const |
120 | { |
121 | return dPtr->metadata; |
122 | } |
123 | |
124 | QT_END_NAMESPACE |
125 |