| 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 QCOAPMESSAGE_H |
| 6 | #define QCOAPMESSAGE_H |
| 7 | |
| 8 | #include <QtCore/qglobal.h> |
| 9 | #include <QtCoap/qcoapglobal.h> |
| 10 | #include <QtCoap/qcoapoption.h> |
| 11 | #include <QtCore/qlist.h> |
| 12 | #include <QtCore/qobject.h> |
| 13 | #include <QtCore/qshareddata.h> |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | class QCoapMessagePrivate; |
| 18 | class Q_COAP_EXPORT QCoapMessage |
| 19 | { |
| 20 | public: |
| 21 | enum class Type : quint8 { |
| 22 | Confirmable, |
| 23 | NonConfirmable, |
| 24 | Acknowledgment, |
| 25 | Reset |
| 26 | }; |
| 27 | |
| 28 | QCoapMessage(); |
| 29 | QCoapMessage(const QCoapMessage &other); |
| 30 | ~QCoapMessage(); |
| 31 | |
| 32 | void swap(QCoapMessage &other) noexcept; |
| 33 | QCoapMessage &operator=(const QCoapMessage &other); |
| 34 | QCoapMessage &operator=(QCoapMessage &&other) noexcept; |
| 35 | |
| 36 | quint8 version() const; |
| 37 | Type type() const; |
| 38 | QByteArray token() const; |
| 39 | quint8 tokenLength() const; |
| 40 | quint16 messageId() const; |
| 41 | QByteArray payload() const; |
| 42 | void setVersion(quint8 version); |
| 43 | void setType(const Type &type); |
| 44 | void setToken(const QByteArray &token); |
| 45 | void setMessageId(quint16); |
| 46 | void setPayload(const QByteArray &payload); |
| 47 | void setOptions(const QList<QCoapOption> &options); |
| 48 | |
| 49 | QCoapOption optionAt(int index) const; |
| 50 | QCoapOption option(QCoapOption::OptionName name) const; |
| 51 | bool hasOption(QCoapOption::OptionName name) const; |
| 52 | const QList<QCoapOption> &options() const; |
| 53 | QList<QCoapOption> options(QCoapOption::OptionName name) const; |
| 54 | int optionCount() const; |
| 55 | void addOption(QCoapOption::OptionName name, const QByteArray &value = QByteArray()); |
| 56 | void addOption(const QCoapOption &option); |
| 57 | void removeOption(const QCoapOption &option); |
| 58 | void removeOption(QCoapOption::OptionName name); |
| 59 | void clearOptions(); |
| 60 | |
| 61 | protected: |
| 62 | explicit QCoapMessage(QCoapMessagePrivate &dd); |
| 63 | |
| 64 | QSharedDataPointer<QCoapMessagePrivate> d_ptr; |
| 65 | |
| 66 | // Q_DECLARE_PRIVATE equivalent for shared data pointers |
| 67 | inline QCoapMessagePrivate *d_func(); |
| 68 | const QCoapMessagePrivate *d_func() const { return d_ptr.constData(); } |
| 69 | }; |
| 70 | |
| 71 | Q_DECLARE_SHARED(QCoapMessage) |
| 72 | |
| 73 | QT_END_NAMESPACE |
| 74 | |
| 75 | Q_DECLARE_METATYPE(QCoapMessage) |
| 76 | Q_DECLARE_METATYPE(QCoapMessage::Type) |
| 77 | |
| 78 | #endif // QCOAPMESSAGE_H |
| 79 |
