| 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 | #include <QtCoap/qcoapglobal.h> |
| 6 | #include <QtCore/qobject.h> |
| 7 | #include <QtCore/qrandom.h> |
| 8 | |
| 9 | #ifndef QCOAPNAMESPACE_H |
| 10 | #define QCOAPNAMESPACE_H |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | #define FOR_EACH_COAP_ERROR(X) \ |
| 15 | X(BadRequest, 0x80) X(Unauthorized, 0x81) X(BadOption, 0x82) X(Forbidden, 0x83) \ |
| 16 | X(NotFound, 0x84) X(MethodNotAllowed, 0x85) X(NotAcceptable, 0x86) \ |
| 17 | X(RequestEntityIncomplete, 0x88) X(PreconditionFailed, 0x8C) X(RequestEntityTooLarge, 0x8D) \ |
| 18 | X(UnsupportedContentFormat, 0x8E) X(InternalServerFault, 0xA0) X(NotImplemented, 0xA1) \ |
| 19 | X(BadGateway, 0xA2) X(ServiceUnavailable, 0xA3) X(GatewayTimeout, 0xA4) \ |
| 20 | X(ProxyingNotSupported, 0xA5) |
| 21 | |
| 22 | namespace QtCoap |
| 23 | { |
| 24 | Q_NAMESPACE_EXPORT(Q_COAP_EXPORT) |
| 25 | |
| 26 | enum class ResponseCode : quint8 { |
| 27 | EmptyMessage = 0x00, |
| 28 | Created = 0x41, // 2.01 |
| 29 | Deleted = 0x42, // 2.02 |
| 30 | Valid = 0x43, // 2.03 |
| 31 | Changed = 0x44, // 2.04 |
| 32 | Content = 0x45, // 2.05 |
| 33 | Continue = 0x5F, // 2.31 |
| 34 | |
| 35 | #define SINGLE_CODE(name, value) name = value, |
| 36 | FOR_EACH_COAP_ERROR(SINGLE_CODE) |
| 37 | #undef SINGLE_CODE |
| 38 | |
| 39 | InvalidCode = 0xFF |
| 40 | }; |
| 41 | Q_ENUM_NS(ResponseCode) |
| 42 | |
| 43 | enum class Error : quint8 { |
| 44 | Ok, |
| 45 | HostNotFound, |
| 46 | AddressInUse, |
| 47 | TimeOut, |
| 48 | |
| 49 | #define SINGLE_ERROR(name, ignored) name, |
| 50 | FOR_EACH_COAP_ERROR(SINGLE_ERROR) |
| 51 | #undef SINGLE_ERROR |
| 52 | |
| 53 | Unknown |
| 54 | }; |
| 55 | Q_ENUM_NS(Error) |
| 56 | |
| 57 | enum class Method : quint8 { |
| 58 | Invalid, |
| 59 | Get, |
| 60 | Post, |
| 61 | Put, |
| 62 | Delete, |
| 63 | #if 0 |
| 64 | //! TODO Support other methods included in RFC 8132 |
| 65 | //! https://tools.ietf.org/html/rfc8132 |
| 66 | Fetch, |
| 67 | Patch, |
| 68 | IPatch, |
| 69 | #endif |
| 70 | Other |
| 71 | }; |
| 72 | Q_ENUM_NS(Method) |
| 73 | |
| 74 | enum Port { |
| 75 | DefaultPort = 5683, |
| 76 | DefaultSecurePort = 5684 |
| 77 | }; |
| 78 | Q_ENUM_NS(Port) |
| 79 | |
| 80 | enum class SecurityMode : quint8 { |
| 81 | NoSecurity = 0, |
| 82 | PreSharedKey, |
| 83 | RawPublicKey, |
| 84 | Certificate |
| 85 | }; |
| 86 | Q_ENUM_NS(SecurityMode) |
| 87 | |
| 88 | enum class MulticastGroup : quint8 { |
| 89 | AllCoapNodesIPv4, |
| 90 | AllCoapNodesIPv6LinkLocal, |
| 91 | AllCoapNodesIPv6SiteLocal |
| 92 | }; |
| 93 | Q_ENUM_NS(MulticastGroup) |
| 94 | |
| 95 | Q_CLASSINFO("RegisterEnumClassesUnscoped" , "false" ) |
| 96 | } |
| 97 | |
| 98 | QT_END_NAMESPACE |
| 99 | |
| 100 | Q_DECLARE_METATYPE(QtCoap::ResponseCode) |
| 101 | Q_DECLARE_METATYPE(QtCoap::Error) |
| 102 | Q_DECLARE_METATYPE(QtCoap::Method) |
| 103 | Q_DECLARE_METATYPE(QtCoap::SecurityMode) |
| 104 | Q_DECLARE_METATYPE(QtCoap::MulticastGroup) |
| 105 | |
| 106 | #endif // QCOAPNAMESPACE_H |
| 107 | |