Skip to content

Commit

Permalink
Pull request emqx#136 review
Browse files Browse the repository at this point in the history
  • Loading branch information
ejvr committed May 6, 2018
1 parent 829a36e commit b12e1e4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
12 changes: 1 addition & 11 deletions src/mqtt/qmqtt_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ enum ConnectionState
STATE_CONNECTED,
STATE_DISCONNECTED
};
namespace MqttError {
enum MqttError {
UnknownError = 0,
MqttUnacceptableProtocolVersionError,
MqttIdentifierRejectedError,
MqttServerUnavailableError,
MqttVadUserNameOrPasswordError,
MqttNotAuthorizedError
};
}

enum ClientError
{
Expand Down Expand Up @@ -107,7 +97,7 @@ enum ClientError
MqttUnacceptableProtocolVersionError=1<<16,
MqttIdentifierRejectedError,
MqttServerUnavailableError,
MqttVadUserNameOrPasswordError,
MqttBadUserNameOrPasswordError,
MqttNotAuthorizedError
};

Expand Down
34 changes: 23 additions & 11 deletions src/mqtt/qmqtt_client_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QSslConfiguration>
#include <QSslKey>
#endif // QT_NO_SSL
#include <QDebug>

Q_LOGGING_CATEGORY(client, "qmqtt.client")

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/mqtt/qmqtt_client_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class ClientPrivate
bool _willRetain;
QByteArray _willMessage;
QHash<QAbstractSocket::SocketError, ClientError> _socketErrorHash;
QHash<MqttError::MqttError, ClientError> _mqttErrorHash;
QHash<quint16, QString> _midToTopic;
QHash<quint16, Message> _midToMessage;

Expand Down

0 comments on commit b12e1e4

Please sign in to comment.