diff --git a/src/mqtt/qmqtt_client.h b/src/mqtt/qmqtt_client.h index 95930fb..9ec5941 100644 --- a/src/mqtt/qmqtt_client.h +++ b/src/mqtt/qmqtt_client.h @@ -67,16 +67,6 @@ enum ConnectionState STATE_CONNECTED, STATE_DISCONNECTED }; -namespace MqttError { - enum MqttError { - UnknownError = 0, - MqttUnacceptableProtocolVersionError, - MqttIdentifierRejectedError, - MqttServerUnavailableError, - MqttVadUserNameOrPasswordError, - MqttNotAuthorizedError - }; -} enum ClientError { @@ -107,7 +97,7 @@ enum ClientError MqttUnacceptableProtocolVersionError=1<<16, MqttIdentifierRejectedError, MqttServerUnavailableError, - MqttVadUserNameOrPasswordError, + MqttBadUserNameOrPasswordError, MqttNotAuthorizedError }; diff --git a/src/mqtt/qmqtt_client_p.cpp b/src/mqtt/qmqtt_client_p.cpp index ce55bde..f7d4b76 100644 --- a/src/mqtt/qmqtt_client_p.cpp +++ b/src/mqtt/qmqtt_client_p.cpp @@ -39,7 +39,6 @@ #include #include #endif // QT_NO_SSL -#include Q_LOGGING_CATEGORY(client, "qmqtt.client") @@ -176,13 +175,6 @@ void QMQTT::ClientPrivate::initializeErrorHash() _socketErrorHash.insert(QAbstractSocket::SslInternalError, SocketSslInternalError); _socketErrorHash.insert(QAbstractSocket::SslInvalidUserDataError, SocketSslInvalidUserDataError); _socketErrorHash.insert(QAbstractSocket::TemporaryError, SocketTemporaryError); - - _mqttErrorHash.insert(MqttError::MqttUnacceptableProtocolVersionError, MqttUnacceptableProtocolVersionError); - _mqttErrorHash.insert(MqttError::MqttIdentifierRejectedError, MqttIdentifierRejectedError); - _mqttErrorHash.insert(MqttError::MqttServerUnavailableError, MqttServerUnavailableError); - _mqttErrorHash.insert(MqttError::MqttVadUserNameOrPasswordError, MqttVadUserNameOrPasswordError); - _mqttErrorHash.insert(MqttError::MqttNotAuthorizedError, MqttNotAuthorizedError); - } void QMQTT::ClientPrivate::connectToHost() @@ -437,11 +429,31 @@ void QMQTT::ClientPrivate::onNetworkReceived(const QMQTT::Frame& frm) void QMQTT::ClientPrivate::handleConnack(const quint8 ack) { Q_Q(Client); - if (ack==0) { + + switch (ack) + { + case 0: emit q->connected(); + break; + case 1: + emit q->error(MqttUnacceptableProtocolVersionError); + break; + case 2: + emit q->error(MqttIdentifierRejectedError); + break; + case 3: + emit q->error(MqttServerUnavailableError); + break; + case 4: + emit q->error(MqttBadUserNameOrPasswordError); + break; + case 5: + emit q->error(MqttNotAuthorizedError); + break; + default: + emit q->error(UnknownError); + break; } - emit q->error(_mqttErrorHash.value(MqttError::MqttError (ack), UnknownError)); - } void QMQTT::ClientPrivate::handlePublish(const Message& message) diff --git a/src/mqtt/qmqtt_client_p.h b/src/mqtt/qmqtt_client_p.h index 73df324..a393dd3 100644 --- a/src/mqtt/qmqtt_client_p.h +++ b/src/mqtt/qmqtt_client_p.h @@ -89,7 +89,6 @@ class ClientPrivate bool _willRetain; QByteArray _willMessage; QHash _socketErrorHash; - QHash _mqttErrorHash; QHash _midToTopic; QHash _midToMessage;