Skip to content

Commit

Permalink
Remove Mqtt::ConnectionState enum (aws#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
graebm authored May 31, 2019
1 parent 8fa6c2a commit c1e9cf5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 40 deletions.
11 changes: 0 additions & 11 deletions include/aws/crt/mqtt/MqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ namespace Aws
class MqttClient;
class MqttConnection;

enum class ConnectionState
{
Init,
Connecting,
Connected,
Disconnected,
Error,
};

/**
* Invoked Upon Connection loss.
*/
Expand Down Expand Up @@ -112,7 +103,6 @@ namespace Aws

operator bool() const noexcept;
int LastError() const noexcept;
inline ConnectionState GetConnectionState() const noexcept { return m_connectionState; }

/**
* Sets LastWill for the connection. The memory backing payload must outlive the connection.
Expand Down Expand Up @@ -191,7 +181,6 @@ namespace Aws
private:
aws_mqtt_client *m_owningClient;
aws_mqtt_client_connection *m_underlyingConnection;
std::atomic<ConnectionState> m_connectionState;
String m_hostName;
uint16_t m_port;
Io::TlsConnectionOptions m_tlsOptions;
Expand Down
4 changes: 2 additions & 2 deletions samples/mqtt_pub_sub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ int main(int argc, char *argv[])
else
{
fprintf(stdout, "Connection completed with return code %d\n", returnCode);
fprintf(stdout, "Connection state %d\n", static_cast<int>(connection->GetConnectionState()));
connectionSucceeded = true;
}
{
Expand All @@ -200,7 +199,7 @@ int main(int argc, char *argv[])
*/
auto onDisconnect = [&](Mqtt::MqttConnection &conn) {
{
fprintf(stdout, "Connection state %d\n", static_cast<int>(conn.GetConnectionState()));
fprintf(stdout, "Disconnect completed\n");
std::lock_guard<std::mutex> lockGuard(mutex);
connectionClosed = true;
}
Expand All @@ -217,6 +216,7 @@ int main(int argc, char *argv[])
* This will use default ping behavior of 1 hour and 3 second timeouts.
* If you want different behavior, those arguments go into slots 3 & 4.
*/
fprintf(stdout, "Connecting...\n");
if (!connection->Connect(clientId.c_str(), false))
{
fprintf(stderr, "MQTT Connection failed with error %s\n", ErrorDebugString(connection->LastError()));
Expand Down
36 changes: 9 additions & 27 deletions source/mqtt/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace Aws
void MqttConnection::s_onConnectionInterrupted(aws_mqtt_client_connection *, int errorCode, void *userData)
{
auto connWrapper = reinterpret_cast<MqttConnection *>(userData);
connWrapper->m_connectionState = ConnectionState::Connecting;
if (connWrapper->OnConnectionInterrupted)
{
connWrapper->OnConnectionInterrupted(*connWrapper, errorCode);
Expand All @@ -42,7 +41,6 @@ namespace Aws
void *userData)
{
auto connWrapper = reinterpret_cast<MqttConnection *>(userData);
connWrapper->m_connectionState = ConnectionState::Connected;
if (connWrapper->OnConnectionResumed)
{
connWrapper->OnConnectionResumed(*connWrapper, returnCode, sessionPresent);
Expand All @@ -57,16 +55,6 @@ namespace Aws
void *userData)
{
auto connWrapper = reinterpret_cast<MqttConnection *>(userData);

if (returnCode == AWS_MQTT_CONNECT_ACCEPTED)
{
connWrapper->m_connectionState = ConnectionState::Connected;
}
else
{
connWrapper->m_connectionState = ConnectionState::Error;
}

if (connWrapper->OnConnectionCompleted)
{
connWrapper->OnConnectionCompleted(*connWrapper, errorCode, returnCode, sessionPresent);
Expand All @@ -76,9 +64,6 @@ namespace Aws
void MqttConnection::s_onDisconnect(aws_mqtt_client_connection *, void *userData)
{
auto connWrapper = reinterpret_cast<MqttConnection *>(userData);

connWrapper->m_connectionState = ConnectionState::Disconnected;

if (connWrapper->OnDisconnect)
{
connWrapper->OnDisconnect(*connWrapper);
Expand Down Expand Up @@ -242,17 +227,15 @@ namespace Aws

self->m_underlyingConnection = aws_mqtt_client_connection_new(self->m_owningClient);

if (!self->m_underlyingConnection)
if (self->m_underlyingConnection)
{
self->m_connectionState = ConnectionState::Error;
aws_mqtt_client_connection_set_connection_interruption_handlers(
self->m_underlyingConnection,
MqttConnection::s_onConnectionInterrupted,
self,
MqttConnection::s_onConnectionResumed,
self);
}

aws_mqtt_client_connection_set_connection_interruption_handlers(
self->m_underlyingConnection,
MqttConnection::s_onConnectionInterrupted,
self,
MqttConnection::s_onConnectionResumed,
self);
}

MqttConnection::MqttConnection(
Expand All @@ -261,7 +244,7 @@ namespace Aws
uint16_t port,
const Io::SocketOptions &socketOptions,
const Io::TlsConnectionOptions &tlsConnOptions) noexcept
: m_owningClient(client), m_connectionState(ConnectionState::Init), m_useTls(true)
: m_owningClient(client), m_useTls(true)
{
s_connectionInit(this, hostName, port, socketOptions, &tlsConnOptions);
}
Expand All @@ -271,7 +254,7 @@ namespace Aws
const char *hostName,
uint16_t port,
const Io::SocketOptions &socketOptions) noexcept
: m_owningClient(client), m_connectionState(ConnectionState::Init), m_useTls(false)
: m_owningClient(client), m_useTls(false)
{
s_connectionInit(this, hostName, port, socketOptions, nullptr);
}
Expand Down Expand Up @@ -340,7 +323,6 @@ namespace Aws
return false;
}

m_connectionState = ConnectionState::Connecting;
return true;
}

Expand Down

0 comments on commit c1e9cf5

Please sign in to comment.