diff options
author | Maurice Kalinowski <maurice.kalinowski@qt.io> | 2018-08-10 15:54:44 +0200 |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@qt.io> | 2018-08-15 10:00:40 +0000 |
commit | a216985e6a5943b442b6b01e0cb06e9ecfbf9d28 (patch) | |
tree | 622694ded11a1c60f0f5db28570d78a031f5d94d | |
parent | c4edb58edcfeea89cf4bb68d72138594a912de40 (diff) |
Add reason code support for subscriptions
Change-Id: I13064ac4bbd3a42d70485b5055825a824472f9af
Reviewed-by: hjk <hjk@qt.io>
-rw-r--r-- | src/mqtt/qmqttconnection.cpp | 52 | ||||
-rw-r--r-- | src/mqtt/qmqttglobal.h | 9 | ||||
-rw-r--r-- | src/mqtt/qmqttsubscription.cpp | 18 | ||||
-rw-r--r-- | src/mqtt/qmqttsubscription.h | 2 | ||||
-rw-r--r-- | src/mqtt/qmqttsubscription_p.h | 1 |
5 files changed, 30 insertions, 52 deletions
diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp index a93a727..fc0ac13 100644 --- a/src/mqtt/qmqttconnection.cpp +++ b/src/mqtt/qmqttconnection.cpp @@ -1441,6 +1441,7 @@ void QMqttConnection::finalize_suback() while (m_missingData > 0) { quint8 reason = readBufferTyped<quint8>(&m_missingData); + sub->d_func()->m_reasonCode = QMqtt::ReasonCode(reason); qCDebug(lcMqttConnectionVerbose) << "Finalize SUBACK: id:" << id << "qos:" << reason; if (reason <= 2) { // The broker might have a different support level for QoS than what @@ -1450,56 +1451,9 @@ void QMqttConnection::finalize_suback() emit sub->qosChanged(reason); } sub->setState(QMqttSubscription::Subscribed); - } else if (reason == 0x80) { - qCDebug(lcMqttConnection) << "Subscription for id " << id << " failed."; - sub->setState(QMqttSubscription::Error); } else { - bool mqtt5reason = false; - if (m_clientPrivate->m_protocolVersion == QMqttClient::MQTT_5_0) { - mqtt5reason = true; - switch (reason) { - case 0x83: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Implementation specific error for id:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0x87: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Not authorized for id:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0x8F: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Topic filter invalid:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0x91: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Packet identifier in use:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0x97: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Quota exceeded:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0x9E: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Shared subscriptions not supported:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0xA1: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Subscription Identifiers not supported:" << id; - sub->setState(QMqttSubscription::Error); - break; - case 0xA2: - qCDebug(lcMqttConnection) << "SUBACK Reason code: Wildcard subscriptions not supported:" << id; - sub->setState(QMqttSubscription::Error); - break; - default: - mqtt5reason = false; - break; - } - } - - if (!mqtt5reason) { - qCDebug(lcMqttConnection) << "Received invalid SUBACK result value:" << reason; - sub->setState(QMqttSubscription::Error); - } + qCDebug(lcMqttConnection) << "Subscription for id " << id << " failed. Reason Code:" << reason; + sub->setState(QMqttSubscription::Error); } } } diff --git a/src/mqtt/qmqttglobal.h b/src/mqtt/qmqttglobal.h index 28a91e8..8386a7c 100644 --- a/src/mqtt/qmqttglobal.h +++ b/src/mqtt/qmqttglobal.h @@ -62,6 +62,9 @@ enum class MessageStatus : quint8 { enum class ReasonCode : quint16 { Success = 0, + SubscriptionQoSLevel0 = 0, + SubscriptionQoSLevel1 = 0x01, + SubscriptionQoSLevel2 = 0x02, NoMatchingSubscriber = 0x10, UnspecifiedError = 0x80, MalformedPacket = 0x81, @@ -75,6 +78,7 @@ enum class ReasonCode : quint16 { ServerBusy = 0x89, ClientBanned = 0x8A, InvalidAuthenticationMethod = 0x8C, + InvalidTopicFilter = 0x8F, InvalidTopicName = 0x90, MessageIdInUse = 0x91, MessageIdNotFound = 0x92, @@ -85,7 +89,10 @@ enum class ReasonCode : quint16 { QoSNotSupported = 0x9B, UseAnotherServer = 0x9C, ServerMoved = 0x9D, - ExceededConnectionRate = 0x9F + SharedSubscriptionsNotSupported = 0x9E, + ExceededConnectionRate = 0x9F, + SubscriptionIdsNotSupported = 0xA1, + WildCardSubscriptionsNotSupported = 0xA2 }; } QT_END_NAMESPACE diff --git a/src/mqtt/qmqttsubscription.cpp b/src/mqtt/qmqttsubscription.cpp index 74e9d21..35f3e52 100644 --- a/src/mqtt/qmqttsubscription.cpp +++ b/src/mqtt/qmqttsubscription.cpp @@ -89,14 +89,22 @@ QT_BEGIN_NAMESPACE /*! \property QMqttSubscription::reason \since 5.12 - \brief This property holds the reason string after subscription has - been established. + \brief This property holds the reason string for the subscription. A reason string is used by the server to provide additional information about the subscription. It is optional for the server to send it. */ /*! + \property QMqttSubscription::reasonCode + \since 5.12 + \brief This property holds the reason code for the subscription. + + The reason code specifies the error type if a subscription has failed, + or the level of QoS for success. +*/ + +/*! \property QMqttSubscription::shared \since 5.12 \brief This property holds whether the subscription is shared. @@ -148,6 +156,12 @@ QString QMqttSubscription::reason() const return d->m_reasonString; } +QMqtt::ReasonCode QMqttSubscription::reasonCode() const +{ + Q_D(const QMqttSubscription); + return d->m_reasonCode; +} + /*! \since 5.12 diff --git a/src/mqtt/qmqttsubscription.h b/src/mqtt/qmqttsubscription.h index 4c24d86..ad10d37 100644 --- a/src/mqtt/qmqttsubscription.h +++ b/src/mqtt/qmqttsubscription.h @@ -49,6 +49,7 @@ class Q_MQTT_EXPORT QMqttSubscription : public QObject Q_PROPERTY(quint8 qos READ qos NOTIFY qosChanged) Q_PROPERTY(QMqttTopicFilter topic READ topic) Q_PROPERTY(QString reason READ reason) + Q_PROPERTY(QMqtt::ReasonCode reasonCode READ reasonCode) Q_PROPERTY(bool shared READ isShared) Q_PROPERTY(QString shareName READ shareName) public: @@ -65,6 +66,7 @@ public: QMqttTopicFilter topic() const; quint8 qos() const; QString reason() const; + QMqtt::ReasonCode reasonCode() const; QMqttUserProperties userProperties() const; bool isShared() const; diff --git a/src/mqtt/qmqttsubscription_p.h b/src/mqtt/qmqttsubscription_p.h index d737d27..f56c404 100644 --- a/src/mqtt/qmqttsubscription_p.h +++ b/src/mqtt/qmqttsubscription_p.h @@ -58,6 +58,7 @@ public: QMqttUserProperties m_userProperties; QString m_shareName; QMqttSubscription::SubscriptionState m_state{QMqttSubscription::Unsubscribed}; + QMqtt::ReasonCode m_reasonCode{QMqtt::ReasonCode::Success}; quint8 m_qos{0}; bool m_shared{false}; }; |