1 | // Copyright (C) 2017 Witekio. |
2 | // Copyright (C) 2018 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QCOAPINTERNALREQUEST_H |
6 | #define QCOAPINTERNALREQUEST_H |
7 | |
8 | #include <private/qcoapinternalmessage_p.h> |
9 | |
10 | #include <QtCoap/qcoapglobal.h> |
11 | #include <QtCoap/qcoapnamespace.h> |
12 | #include <private/qcoapconnection_p.h> |
13 | |
14 | #include <QtCore/qglobal.h> |
15 | #include <QtCore/qtimer.h> |
16 | #include <QtCore/qurl.h> |
17 | |
18 | // |
19 | // W A R N I N G |
20 | // ------------- |
21 | // |
22 | // This file is not part of the Qt API. It exists purely as an |
23 | // implementation detail. This header file may change from version to |
24 | // version without notice, or even be removed. |
25 | // |
26 | // We mean it. |
27 | // |
28 | |
29 | QT_BEGIN_NAMESPACE |
30 | |
31 | class QCoapRequest; |
32 | class QCoapInternalRequestPrivate; |
33 | class Q_AUTOTEST_EXPORT QCoapInternalRequest : public QCoapInternalMessage |
34 | { |
35 | Q_OBJECT |
36 | public: |
37 | explicit QCoapInternalRequest(QObject *parent = nullptr); |
38 | explicit QCoapInternalRequest(const QCoapRequest &request, QObject *parent = nullptr); |
39 | |
40 | bool isValid() const override; |
41 | |
42 | void initEmptyMessage(quint16 messageId, QCoapMessage::Type type); |
43 | |
44 | QByteArray toQByteArray() const; |
45 | void setMessageId(quint16); |
46 | void setToken(const QCoapToken&); |
47 | void setToRequestBlock(uint blockNumber, uint blockSize); |
48 | void setToSendBlock(uint blockNumber, uint blockSize); |
49 | bool checkBlockNumber(uint blockNumber); |
50 | |
51 | using QCoapInternalMessage::addOption; |
52 | void addOption(const QCoapOption &option) override; |
53 | bool addUriOptions(QUrl uri, const QUrl &proxyUri = QUrl()); |
54 | |
55 | QCoapToken token() const; |
56 | QUrl targetUri() const; |
57 | QtCoap::Method method() const; |
58 | bool isObserve() const; |
59 | bool isObserveCancelled() const; |
60 | bool isMulticast() const; |
61 | QCoapConnection *connection() const; |
62 | uint retransmissionCounter() const; |
63 | void setMethod(QtCoap::Method method); |
64 | void setConnection(QCoapConnection *connection); |
65 | void setObserveCancelled(); |
66 | |
67 | void setTargetUri(QUrl targetUri); |
68 | void setTimeout(uint timeout); |
69 | void setMaxTransmissionWait(uint timeout); |
70 | void setMulticastTimeout(uint responseDelay); |
71 | void restartTransmission(); |
72 | void startMulticastTransmission(); |
73 | void stopTransmission(); |
74 | |
75 | Q_SIGNALS: |
76 | void timeout(QCoapInternalRequest*); |
77 | void maxTransmissionSpanReached(QCoapInternalRequest*); |
78 | void multicastRequestExpired(QCoapInternalRequest*); |
79 | |
80 | protected: |
81 | QCoapOption uriHostOption(const QUrl &uri) const; |
82 | QCoapOption blockOption(QCoapOption::OptionName name, uint blockNumber, uint blockSize) const; |
83 | |
84 | private: |
85 | Q_DECLARE_PRIVATE(QCoapInternalRequest) |
86 | }; |
87 | |
88 | class Q_AUTOTEST_EXPORT QCoapInternalRequestPrivate : public QCoapInternalMessagePrivate |
89 | { |
90 | public: |
91 | QCoapInternalRequestPrivate() = default; |
92 | |
93 | QUrl targetUri; |
94 | QtCoap::Method method = QtCoap::Method::Invalid; |
95 | QCoapConnection *connection = nullptr; |
96 | QByteArray fullPayload; |
97 | |
98 | uint timeout = 0; |
99 | uint retransmissionCounter = 0; |
100 | QTimer *timeoutTimer = nullptr; |
101 | QTimer *maxTransmitWaitTimer = nullptr; |
102 | QTimer *multicastExpireTimer = nullptr; |
103 | |
104 | bool observeCancelled = false; |
105 | bool transmissionInProgress = false; |
106 | |
107 | Q_DECLARE_PUBLIC(QCoapInternalRequest) |
108 | }; |
109 | |
110 | QT_END_NAMESPACE |
111 | |
112 | #endif // QCOAPINTERNALREQUEST_H |
113 | |