Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt5to3 adapter #528

Merged
merged 6 commits into from
Aug 4, 2023
Merged

Mqtt5to3 adapter #528

merged 6 commits into from
Aug 4, 2023

Conversation

xiazhvera
Copy link
Contributor

@xiazhvera xiazhvera commented Aug 3, 2023

Issue #, if available:

Description of changes:
Bind out the Mqtt5 to Mqtt3 adapter.
(Still need update submodules: awslabs/aws-c-mqtt#313)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xiazhvera xiazhvera marked this pull request as ready for review August 3, 2023 22:21
@xiazhvera xiazhvera mentioned this pull request Aug 3, 2023
@@ -324,6 +334,47 @@ namespace Aws
std::shared_ptr<Mqtt5ClientCore> m_client_core;

Mqtt5ClientOperationStatistics m_operationStatistics;

Mqtt5to3AdapterOptions *m_mqtt5to3AdapterOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be clarified as I get further in but just wondering if we'll only ever have one of these adapter options per Mqtt5Client. Thinking of a scenario where we have a number of different adapters from a single Mqtt5 client. e.g. if someone makes a bunch to feed to different service clients instead of using the same one for them all. May be a non-issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only have one adapter options for each Mqtt5Client. When we create MqttConnection from the Mqtt5Client, we will pass the options in the MqttConnection, which will copy the options over.

include/aws/crt/mqtt/MqttClient.h Outdated Show resolved Hide resolved
{
if (m_client_core == nullptr)
{
AWS_LOGF_DEBUG(AWS_LS_MQTT5_CLIENT, "Failed to create mqtt3 connection: Mqtt5 Client is invalid.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be the ERROR log level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a good idea to set the error level to ERROR for those "invalid mqtt5 client" issue here. As if the issue happened (the client core is nullptr), it usually means the Mqtt5Client is unusable, and we should expose it to user.
Since we've been using DEBUG log for all other operations, I will keep it here for now and create a separate PR to update the log level all together.

@@ -233,6 +247,36 @@ namespace Aws

Mqtt5ClientOptions::~Mqtt5ClientOptions() {}

Mqtt5to3AdapterOptions *Mqtt5ClientOptions::NewMqtt5to3AdapterOptions() const noexcept
{
Mqtt5to3AdapterOptions *adapterOptions = new Mqtt5to3AdapterOptions();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debatable: If m_mqtt5to3AdapterOptions is populated directly in this method, then there will be no need in allocating m_mqtt5to3AdapterOptions on the heap or even making it a pointer.
My main concern is a new call in the code: there is no issue with it, but it always enforces you to make sure that corresponding delete will be called. Maybe at least replace it with std::unique_ptr?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the crt we always pair *_destroy() for anything that has a *_new() that takes an allocator to make sure we clean up anything we allocate. Unsure if we have the same for something with New in cpp but I feel like I've seen New used that returns a pointer or a null with no corresponding delete or destroy. Good to stay consistent though so worth investigating.

source/mqtt/Mqtt5Client.cpp Outdated Show resolved Hide resolved
@sbSteveK
Copy link
Contributor

sbSteveK commented Aug 4, 2023

Trivial: The comment in Mqtt5ClientCore.cpp currently on line 524 /* Copied from MqttClient.cpp:ln754 (MqttClient::NewConnection) */ Doesn't point to the proper place anymore due to changes in MqttClient.cpp. Let's remove the line reference in that comment.

source/mqtt/MqttClient.cpp Outdated Show resolved Hide resolved
source/mqtt/MqttClient.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@sbSteveK sbSteveK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. May want to wait for Igor to also check over changes tho.

@sfod
Copy link
Contributor

sfod commented Aug 4, 2023

Looks good to me too

@xiazhvera xiazhvera merged commit 3dc6b3d into main Aug 4, 2023
52 checks passed
@xiazhvera xiazhvera deleted the mqtt5to3Adapter2 branch August 4, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants