Skip to content

Commit

Permalink
std::unique_ptr is cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
sfodagain committed Sep 11, 2024
1 parent ed8c9ed commit ff68251
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 22 deletions.
5 changes: 2 additions & 3 deletions samples/device_defender/mqtt5_basic_report/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ int main(int argc, char *argv[])
Utils::cmdData cmdData = Utils::parseSampleInputDeviceDefender(argc, argv, &apiHandle);

// Create the MQTT builder and populate it with data from cmdData.
auto clientConfigBuilder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto clientConfigBuilder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()));
if (clientConfigBuilder == nullptr)
{
fprintf(
Expand Down
5 changes: 2 additions & 3 deletions samples/fleet_provisioning/mqtt5_fleet_provisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ struct RegisterThingContext
std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> createMqtt5Client(const Utils::cmdData &cmdData, Mqtt5ClientContext &ctx)
{
// Create the MQTT5 builder and populate it with data from cmdData.
auto builder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto builder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()));

// Check if the builder setup correctly.
if (builder == nullptr)
Expand Down
5 changes: 2 additions & 3 deletions samples/jobs/mqtt5_job_execution/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ int main(int argc, char *argv[])
Utils::cmdData cmdData = Utils::parseSampleInputJobs(argc, argv, &apiHandle);

// Create the MQTT5 builder and populate it with data from cmdData.
auto builder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto builder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()));

// Check if the builder setup correctly.
if (builder == nullptr)
Expand Down
5 changes: 2 additions & 3 deletions samples/mqtt5/mqtt5_pubsub/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ int main(int argc, char *argv[])
Utils::cmdData cmdData = Utils::parseSampleInputPubSub(argc, argv, &apiHandle, "mqtt5-pubsub");

// Create the MQTT5 builder and populate it with data from cmdData.
auto builder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto builder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()));

// Check if the builder setup correctly.
if (builder == nullptr)
Expand Down
5 changes: 2 additions & 3 deletions samples/mqtt5/mqtt5_shared_subscription/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ class sample_mqtt5_client
std::shared_ptr<sample_mqtt5_client> result = std::make_shared<sample_mqtt5_client>();
result->name = input_clientName;

auto builder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto builder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
input_endpoint, input_cert.c_str(), input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
input_endpoint, input_cert.c_str(), input_key.c_str()));
if (builder == nullptr)
{
return nullptr;
Expand Down
5 changes: 2 additions & 3 deletions samples/shadow/mqtt5_shadow_sync/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ int main(int argc, char *argv[])
Utils::cmdData cmdData = Utils::parseSampleInputShadow(argc, argv, &apiHandle);

// Create the MQTT5 builder and populate it with data from cmdData.
auto builder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto builder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()));
// Check if the builder setup correctly.
if (builder == nullptr)
{
Expand Down
6 changes: 2 additions & 4 deletions servicetests/tests/FleetProvisioning/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ struct RegisterThingContext
std::shared_ptr<Aws::Crt::Mqtt5::Mqtt5Client> createMqtt5Client(const Utils::cmdData &cmdData, Mqtt5ClientContext &ctx)
{
// Create the MQTT5 builder and populate it with data from cmdData.
// Create the MQTT5 builder and populate it with data from cmdData.
auto builder = Aws::Crt::ScopedResource<Aws::Iot::Mqtt5ClientBuilder>(
auto builder = std::unique_ptr<Aws::Iot::Mqtt5ClientBuilder>(
Aws::Iot::Mqtt5ClientBuilder::NewMqtt5ClientBuilderWithMtlsFromPath(
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()),
[](Aws::Iot::Mqtt5ClientBuilder *ptr) { delete ptr; });
cmdData.input_endpoint, cmdData.input_cert.c_str(), cmdData.input_key.c_str()));

// Check if the builder setup correctly.
if (builder == nullptr)
Expand Down

0 comments on commit ff68251

Please sign in to comment.