From 359a7937ac578489f2e82daa51a0a78f8f714d26 Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Mon, 16 Sep 2024 16:59:14 -0700 Subject: [PATCH] Checkpoint --- crt/aws-crt-cpp | 2 +- .../include/aws/iotshadow/IotShadowClientv2.h | 61 ++++++++++ shadow/source/IotShadowClientv2.cpp | 111 ++++++++++++++++++ 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 shadow/include/aws/iotshadow/IotShadowClientv2.h create mode 100644 shadow/source/IotShadowClientv2.cpp diff --git a/crt/aws-crt-cpp b/crt/aws-crt-cpp index 17e30acb7..5f2268cd7 160000 --- a/crt/aws-crt-cpp +++ b/crt/aws-crt-cpp @@ -1 +1 @@ -Subproject commit 17e30acb7d6338a7b180c0cd522de0b4c51ceadd +Subproject commit 5f2268cd7c0d5b08b169a60094ff4cc66214d4eb diff --git a/shadow/include/aws/iotshadow/IotShadowClientv2.h b/shadow/include/aws/iotshadow/IotShadowClientv2.h new file mode 100644 index 000000000..fca0e0766 --- /dev/null +++ b/shadow/include/aws/iotshadow/IotShadowClientv2.h @@ -0,0 +1,61 @@ +#pragma once + +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + * + * This file is generated + */ + +#include + +#include +#include + + +#include + +namespace Aws +{ + namespace Crt { + namespace Mqtt { + class MqttConnection; + } + namespace Mqtt5 { + class Mqtt5Client; + } + } + + template class Error { + public: + + private: + Aws::Crt::Variant rawError; + }; + + namespace Iotshadow + { + class ErrorResponse; + class GetNamedShadowRequest; + class GetNamedShadowResponse; + + using GetNamedShadowResult = Aws::Iot::RequestResponse::Result>; + + class AWS_IOTSHADOW_API IClientv2 + { + public: + + virtual ~IClientv2() = 0; + + static std::shared_ptr newFrom5(const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + Aws::Iot::RequestResponse::RequestResponseClientOptions &&options, + Aws::Crt::Allocator *allocator = Aws::Crt::ApiAllocator()); + + static std::shared_ptr newFrom311(const Aws::Crt::Mqtt::MqttConnection &protocolClient, + Aws::Iot::RequestResponse::RequestResponseClientOptions &&options, + Aws::Crt::Allocator *allocator = Aws::Crt::ApiAllocator()); + + virtual bool GetNamedShadow(const Aws::Iotshadow::GetNamedShadowRequest &request, const std::function &handler) = 0; + + }; + } +} \ No newline at end of file diff --git a/shadow/source/IotShadowClientv2.cpp b/shadow/source/IotShadowClientv2.cpp new file mode 100644 index 000000000..82e55bd67 --- /dev/null +++ b/shadow/source/IotShadowClientv2.cpp @@ -0,0 +1,111 @@ +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +* SPDX-License-Identifier: Apache-2.0. +* +* This file is generated +*/ + +#include + +#include +#include + +namespace Aws +{ + namespace Iotshadow + { + + class Clientv2 : public IClientv2 { + public: + + Clientv2(Aws::Crt::Allocator *allocator, Aws::Iot::RequestResponse::IMqttRequestResponseClient *bindingClient); + virtual ~Clientv2(); + + virtual bool GetNamedShadow(const Aws::Iotshadow::GetNamedShadowRequest &request, std::function &&handler); + + private: + + Aws::Crt::ScopedResource m_bindingClient; + }; + + Clientv2::Clientv2(Aws::Crt::Allocator *allocator, Aws::Iot::RequestResponse::IMqttRequestResponseClient *bindingClient) : + m_bindingClient(bindingClient, [allocator](Aws::Iot::RequestResponse::IMqttRequestResponseClient *bindingClient) { Aws::Crt::Delete(bindingClient, allocator); }) + { + } + + Clientv2::~Clientv2() { + } + + bool Clientv2::GetNamedShadow(const Aws::Iotshadow::GetNamedShadowRequest &request, const std::function &handler) { + Aws::Crt::StringStream publishTopic; + publishTopic << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/get"; + + Aws::Crt::StringStream subscriptionTopic; + subscriptionTopic << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/get/+"; + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic.str()) + }; + + Aws::Crt::StringStream responsePathTopic1; + responsePathTopic1 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/get/accepted"; + + Aws::Crt::StringStream responsePathTopic2; + responsePathTopic2 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/get/rejected"; + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopic1.str()); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopic2.str()); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + auto uuid = Aws::Crt::UUID().ToString(); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + Aws::Crt::String outgoingJson = jsonObject.View().WriteCompact(true); + + struct aws_mqtt_request_operation_options options; + AWS_ZERO_STRUCT(options); + options.subscription_topic_filters = subscriptionTopicFilters; + options.subscription_topic_filter_count = 1; + options.response_paths = responsePaths; + options.response_path_count = 2; + options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic.str()); + options.serialized_request = Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [](Aws::Iot::RequestResponse::UnmodeledResult &&result){ + + }; + + int submitResult = m_bindingClient->submitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + std::shared_ptr IClientv2::newFrom5(const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + Aws::Iot::RequestResponse::RequestResponseClientOptions &&options, + Aws::Crt::Allocator *allocator) { + + Aws::Iot::RequestResponse::IMqttRequestResponseClient *bindingClient = Aws::Iot::RequestResponse::IMqttRequestResponseClient::newFrom5(protocolClient, std::move(options), allocator); + if (!bindingClient) { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + std::shared_ptr IClientv2::newFrom311(const Aws::Crt::Mqtt::MqttConnection &protocolClient, + Aws::Iot::RequestResponse::RequestResponseClientOptions &&options, + Aws::Crt::Allocator *allocator) { + + Aws::Iot::RequestResponse::IMqttRequestResponseClient *bindingClient = Aws::Iot::RequestResponse::IMqttRequestResponseClient::newFrom311(protocolClient, std::move(options), allocator); + if (!bindingClient) { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + } +} \ No newline at end of file