diff --git a/crt/aws-crt-cpp b/crt/aws-crt-cpp index dfdd59a78..6ff68c5fa 160000 --- a/crt/aws-crt-cpp +++ b/crt/aws-crt-cpp @@ -1 +1 @@ -Subproject commit dfdd59a7896ccab047d630cd6f38a588857fbcae +Subproject commit 6ff68c5fa0f151cb59a781227f3c66770046487a diff --git a/identity/include/aws/iotidentity/IotIdentityClientV2.h b/identity/include/aws/iotidentity/IotIdentityClientV2.h new file mode 100644 index 000000000..1a75ff97e --- /dev/null +++ b/identity/include/aws/iotidentity/IotIdentityClientV2.h @@ -0,0 +1,177 @@ +#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 + +#include + +namespace Aws +{ + namespace Crt + { + namespace Mqtt + { + class MqttConnection; + } + namespace Mqtt5 + { + class Mqtt5Client; + } + } // namespace Crt +} // namespace Aws + +namespace Aws +{ + namespace Iotidentity + { + + template class ServiceErrorV2 + { + public: + ServiceErrorV2() = delete; + ServiceErrorV2(const ServiceErrorV2 &rhs) = default; + ServiceErrorV2(ServiceErrorV2 &&rhs) = default; + + explicit ServiceErrorV2(int errorCode) : m_errorCode(errorCode), m_modeledError() {} + + ServiceErrorV2(int errorCode, E &&modeledError) + : m_errorCode(errorCode), m_modeledError(std::move(modeledError)) + { + } + + ~ServiceErrorV2() = default; + + ServiceErrorV2 &operator=(const ServiceErrorV2 &rhs) = default; + ServiceErrorV2 &operator=(ServiceErrorV2 &&rhs) = default; + + int GetErrorCode() const { return m_errorCode; } + + bool HasModeledError() const { return m_modeledError.has_value(); } + const E &GetModeledError() const { return m_modeledError.value(); } + + private: + int m_errorCode; + + Aws::Crt::Optional m_modeledError; + }; + + class CreateCertificateFromCsrRequest; + class CreateCertificateFromCsrResponse; + class CreateKeysAndCertificateRequest; + class CreateKeysAndCertificateResponse; + class RegisterThingRequest; + class RegisterThingResponse; + class V2ServiceError; + + using CreateCertificateFromCsrResultHandler = std::function> &&)>; + using CreateKeysAndCertificateResultHandler = std::function> &&)>; + using RegisterThingResultHandler = std::function> &&)>; + + /** + * An AWS IoT service that assists with provisioning a device and installing unique client certificates on it + * + * https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html + * + */ + class AWS_IOTIDENTITY_API IClientV2 + { + public: + virtual ~IClientV2() = default; + + /** + * Creates a certificate from a certificate signing request (CSR). AWS IoT provides client certificates that + * are signed by the Amazon Root certificate authority (CA). The new certificate has a PENDING_ACTIVATION + * status. When you call RegisterThing to provision a thing with this certificate, the certificate status + * changes to ACTIVE or INACTIVE as described in the template. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#fleet-provision-api + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool CreateCertificateFromCsr( + const CreateCertificateFromCsrRequest &request, + const CreateCertificateFromCsrResultHandler &handler) = 0; + + /** + * Creates new keys and a certificate. AWS IoT provides client certificates that are signed by the Amazon + * Root certificate authority (CA). The new certificate has a PENDING_ACTIVATION status. When you call + * RegisterThing to provision a thing with this certificate, the certificate status changes to ACTIVE or + * INACTIVE as described in the template. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#fleet-provision-api + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool CreateKeysAndCertificate( + const CreateKeysAndCertificateRequest &request, + const CreateKeysAndCertificateResultHandler &handler) = 0; + + /** + * Provisions an AWS IoT thing using a pre-defined template. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/provision-wo-cert.html#fleet-provision-api + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool RegisterThing( + const RegisterThingRequest &request, + const RegisterThingResultHandler &handler) = 0; + }; + + /** + * Creates a new service client that uses an SDK MQTT5 client for transport. + * + * @param protocolClient MQTT client to use as transport + * @param options request-response MQTT client configuration options + * @param allocator memory allocator to use for all client functionality + * + * @return a new service client + */ + AWS_IOTIDENTITY_API std::shared_ptr NewClientFrom5( + const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator = Aws::Crt::ApiAllocator()); + + /** + * Creates a new service client that uses an SDK MQTT311 client for transport. + * + * @param protocolClient MQTT client to use as transport + * @param options request-response MQTT client configuration options + * @param allocator memory allocator to use for all client functionality + * + * @return a new service client + */ + AWS_IOTIDENTITY_API std::shared_ptr NewClientFrom311( + const Aws::Crt::Mqtt::MqttConnection &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator = Aws::Crt::ApiAllocator()); + + } // namespace Iotidentity +} // namespace Aws diff --git a/identity/include/aws/iotidentity/V2ServiceError.h b/identity/include/aws/iotidentity/V2ServiceError.h new file mode 100644 index 000000000..c4b0b9a9b --- /dev/null +++ b/identity/include/aws/iotidentity/V2ServiceError.h @@ -0,0 +1,55 @@ +#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 + +namespace Aws +{ + namespace Iotidentity + { + + /** + * Response document containing details about a failed request. + * + */ + class AWS_IOTIDENTITY_API V2ServiceError final + { + public: + V2ServiceError() = default; + + V2ServiceError(const Crt::JsonView &doc); + V2ServiceError &operator=(const Crt::JsonView &doc); + + void SerializeToObject(Crt::JsonObject &doc) const; + + /** + * Response status code + * + */ + Aws::Crt::Optional StatusCode; + + /** + * Response error code + * + */ + Aws::Crt::Optional ErrorCode; + + /** + * Response error message + * + */ + Aws::Crt::Optional ErrorMessage; + + private: + static void LoadFromObject(V2ServiceError &obj, const Crt::JsonView &doc); + }; + } // namespace Iotidentity +} // namespace Aws diff --git a/identity/source/CreateKeysAndCertificateRequest.cpp b/identity/source/CreateKeysAndCertificateRequest.cpp index 6761a1f29..fa29f2d2b 100644 --- a/identity/source/CreateKeysAndCertificateRequest.cpp +++ b/identity/source/CreateKeysAndCertificateRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void CreateKeysAndCertificateRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void CreateKeysAndCertificateRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } CreateKeysAndCertificateRequest::CreateKeysAndCertificateRequest(const Crt::JsonView &doc) { diff --git a/identity/source/ErrorResponse.cpp b/identity/source/ErrorResponse.cpp index ac8d83742..f835e0555 100644 --- a/identity/source/ErrorResponse.cpp +++ b/identity/source/ErrorResponse.cpp @@ -51,7 +51,10 @@ namespace Aws } } - ErrorResponse::ErrorResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ErrorResponse::ErrorResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ErrorResponse &ErrorResponse::operator=(const Crt::JsonView &doc) { diff --git a/identity/source/IotIdentityClient.cpp b/identity/source/IotIdentityClient.cpp index 2b25fba33..93d3f0f2c 100644 --- a/identity/source/IotIdentityClient.cpp +++ b/identity/source/IotIdentityClient.cpp @@ -31,9 +31,15 @@ namespace Aws m_connection = Aws::Crt::Mqtt::MqttConnection::NewConnectionFromMqtt5Client(mqtt5Client); } - IotIdentityClient::operator bool() const noexcept { return m_connection && *m_connection; } + IotIdentityClient::operator bool() const noexcept + { + return m_connection && *m_connection; + } - int IotIdentityClient::GetLastError() const noexcept { return aws_last_error(); } + int IotIdentityClient::GetLastError() const noexcept + { + return aws_last_error(); + } bool IotIdentityClient::SubscribeToCreateCertificateFromCsrAccepted( const Aws::Iotidentity::CreateCertificateFromCsrSubscriptionRequest &request, @@ -47,7 +53,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -61,24 +68,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotidentity::CreateCertificateFromCsrResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotidentity::CreateCertificateFromCsrResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "certificates" - << "/" - << "create-from-csr" - << "/" - << "json" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/certificates/create-from-csr/json/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -99,7 +98,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -113,24 +113,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotidentity::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotidentity::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "certificates" - << "/" - << "create-from-csr" - << "/" - << "json" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/certificates/create-from-csr/json/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -151,7 +143,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -165,24 +158,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotidentity::CreateKeysAndCertificateResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotidentity::CreateKeysAndCertificateResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "certificates" - << "/" - << "create" - << "/" - << "json" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/certificates/create/json/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -203,7 +188,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -217,24 +203,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotidentity::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotidentity::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "certificates" - << "/" - << "create" - << "/" - << "json" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/certificates/create/json/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -255,7 +233,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -269,24 +248,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotidentity::RegisterThingResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotidentity::RegisterThingResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "provisioning-templates" - << "/" << *request.TemplateName << "/" - << "provision" - << "/" - << "json" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/provisioning-templates/" << *request.TemplateName << "/provision/json/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -307,7 +278,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -321,24 +293,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotidentity::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotidentity::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "provisioning-templates" - << "/" << *request.TemplateName << "/" - << "provision" - << "/" - << "json" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/provisioning-templates/" << *request.TemplateName << "/provision/json/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -353,13 +317,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "certificates" - << "/" - << "create-from-csr" - << "/" - << "json"; + publishTopicSStr << "$aws/certificates/create-from-csr/json"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -367,7 +325,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -382,13 +341,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "certificates" - << "/" - << "create" - << "/" - << "json"; + publishTopicSStr << "$aws/certificates/create/json"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -396,7 +349,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -411,13 +365,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "provisioning-templates" - << "/" << *request.TemplateName << "/" - << "provision" - << "/" - << "json"; + publishTopicSStr << "$aws/provisioning-templates/" << *request.TemplateName << "/provision/json"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -425,7 +373,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; diff --git a/identity/source/IotIdentityClientV2.cpp b/identity/source/IotIdentityClientV2.cpp new file mode 100644 index 000000000..726121bbc --- /dev/null +++ b/identity/source/IotIdentityClientV2.cpp @@ -0,0 +1,470 @@ +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + * + * This file is generated + */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace Aws +{ + namespace Iotidentity + { + + class ClientV2 : public IClientV2 + { + public: + ClientV2( + Aws::Crt::Allocator *allocator, + std::shared_ptr bindingClient); + virtual ~ClientV2() = default; + + bool CreateCertificateFromCsr( + const CreateCertificateFromCsrRequest &request, + const CreateCertificateFromCsrResultHandler &handler) override; + + bool CreateKeysAndCertificate( + const CreateKeysAndCertificateRequest &request, + const CreateKeysAndCertificateResultHandler &handler) override; + + bool RegisterThing(const RegisterThingRequest &request, const RegisterThingResultHandler &handler) override; + + private: + Aws::Crt::Allocator *m_allocator; + + std::shared_ptr m_bindingClient; + }; + + ClientV2::ClientV2( + Aws::Crt::Allocator *allocator, + std::shared_ptr bindingClient) + : m_allocator(allocator), m_bindingClient(std::move(bindingClient)) + { + // It's simpler to do this than branch the codegen based on the presence of streaming operations + (void)m_allocator; + } + + template + static void s_applyUnmodeledErrorToHandler(const std::function &handler, int errorCode) + { + ServiceErrorV2 error(errorCode); + R finalResult(std::move(error)); + handler(std::move(finalResult)); + } + + template + static void s_applyModeledErrorToHandler(const std::function &handler, E &&modeledError) + { + ServiceErrorV2 error(AWS_ERROR_MQTT_REQUEST_RESPONSE_MODELED_SERVICE_ERROR, std::move(modeledError)); + R finalResult(std::move(error)); + handler(std::move(finalResult)); + } + + static void s_CreateCertificateFromCsrResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const CreateCertificateFromCsrResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + CreateCertificateFromCsrResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::CreateCertificateFromCsr( + const CreateCertificateFromCsrRequest &request, + const CreateCertificateFromCsrResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/certificates/create-from-csr/json"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/certificates/create-from-csr/json/accepted"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + Aws::Crt::StringStream subscriptionTopicStream1; + subscriptionTopicStream1 << "$aws/certificates/create-from-csr/json/rejected"; + Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); + + struct aws_byte_cursor subscriptionTopicFilters[2] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + Aws::Crt::ByteCursorFromString(subscriptionTopic1), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + + 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 = 2; + options.response_paths = responsePaths; + options.response_path_count = 2; + options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_CreateCertificateFromCsrResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_CreateKeysAndCertificateResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const CreateKeysAndCertificateResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + CreateKeysAndCertificateResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::CreateKeysAndCertificate( + const CreateKeysAndCertificateRequest &request, + const CreateKeysAndCertificateResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/certificates/create/json"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/certificates/create/json/accepted"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + Aws::Crt::StringStream subscriptionTopicStream1; + subscriptionTopicStream1 << "$aws/certificates/create/json/rejected"; + Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); + + struct aws_byte_cursor subscriptionTopicFilters[2] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + Aws::Crt::ByteCursorFromString(subscriptionTopic1), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + + 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 = 2; + options.response_paths = responsePaths; + options.response_path_count = 2; + options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_CreateKeysAndCertificateResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_RegisterThingResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const RegisterThingResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + RegisterThingResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::RegisterThing(const RegisterThingRequest &request, const RegisterThingResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/provisioning-templates/" << *request.TemplateName << "/provision/json"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/provisioning-templates/" << *request.TemplateName + << "/provision/json/accepted"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + Aws::Crt::StringStream subscriptionTopicStream1; + subscriptionTopicStream1 << "$aws/provisioning-templates/" << *request.TemplateName + << "/provision/json/rejected"; + Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); + + struct aws_byte_cursor subscriptionTopicFilters[2] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + Aws::Crt::ByteCursorFromString(subscriptionTopic1), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + + 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 = 2; + options.response_paths = responsePaths; + options.response_path_count = 2; + options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_RegisterThingResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + template class ServiceStreamingOperation : public Aws::Iot::RequestResponse::IStreamingOperation + { + public: + explicit ServiceStreamingOperation(std::shared_ptr stream) + : m_stream(std::move(stream)) + { + } + + static std::shared_ptr Create( + Aws::Crt::Allocator *allocator, + const std::shared_ptr &bindingClient, + const Aws::Crt::String &subscriptionTopicFilter, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + + std::function unmodeledHandler = + [options](Aws::Iot::RequestResponse::IncomingPublishEvent &&event) + { + const auto &payload = event.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + return; + } + + T modeledEvent(jsonObject); + options.GetStreamHandler()(std::move(modeledEvent)); + }; + + Aws::Iot::RequestResponse::StreamingOperationOptionsInternal internalOptions; + internalOptions.subscriptionTopicFilter = Aws::Crt::ByteCursorFromString(subscriptionTopicFilter); + internalOptions.subscriptionStatusEventHandler = options.GetSubscriptionStatusEventHandler(); + internalOptions.incomingPublishEventHandler = unmodeledHandler; + + auto unmodeledStream = bindingClient->CreateStream(internalOptions); + if (!unmodeledStream) + { + return nullptr; + } + + return Aws::Crt::MakeShared>(allocator, unmodeledStream); + } + + void Open() override { m_stream->Open(); } + + private: + std::shared_ptr m_stream; + }; + + std::shared_ptr NewClientFrom5( + const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator) + { + + std::shared_ptr bindingClient = + Aws::Iot::RequestResponse::NewClientFrom5(protocolClient, options, allocator); + if (nullptr == bindingClient) + { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + std::shared_ptr NewClientFrom311( + const Aws::Crt::Mqtt::MqttConnection &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator) + { + + std::shared_ptr bindingClient = + Aws::Iot::RequestResponse::NewClientFrom311(protocolClient, options, allocator); + if (nullptr == bindingClient) + { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + } // namespace Iotidentity +} // namespace Aws diff --git a/identity/source/RegisterThingRequest.cpp b/identity/source/RegisterThingRequest.cpp index 981aa7550..130b823ce 100644 --- a/identity/source/RegisterThingRequest.cpp +++ b/identity/source/RegisterThingRequest.cpp @@ -55,7 +55,10 @@ namespace Aws } } - RegisterThingRequest::RegisterThingRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + RegisterThingRequest::RegisterThingRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } RegisterThingRequest &RegisterThingRequest::operator=(const Crt::JsonView &doc) { diff --git a/identity/source/RegisterThingResponse.cpp b/identity/source/RegisterThingResponse.cpp index 180d5d92d..ca7ebbb61 100644 --- a/identity/source/RegisterThingResponse.cpp +++ b/identity/source/RegisterThingResponse.cpp @@ -57,7 +57,10 @@ namespace Aws } } - RegisterThingResponse::RegisterThingResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + RegisterThingResponse::RegisterThingResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } RegisterThingResponse &RegisterThingResponse::operator=(const Crt::JsonView &doc) { diff --git a/identity/source/RegisterThingSubscriptionRequest.cpp b/identity/source/RegisterThingSubscriptionRequest.cpp index 67f10f152..21d601ea0 100644 --- a/identity/source/RegisterThingSubscriptionRequest.cpp +++ b/identity/source/RegisterThingSubscriptionRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void RegisterThingSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void RegisterThingSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } RegisterThingSubscriptionRequest::RegisterThingSubscriptionRequest(const Crt::JsonView &doc) { diff --git a/identity/source/V2ServiceError.cpp b/identity/source/V2ServiceError.cpp new file mode 100644 index 000000000..1d2d7d668 --- /dev/null +++ b/identity/source/V2ServiceError.cpp @@ -0,0 +1,66 @@ +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + * + * This file is generated + */ +#include + +namespace Aws +{ + namespace Iotidentity + { + + void V2ServiceError::LoadFromObject(V2ServiceError &val, const Aws::Crt::JsonView &doc) + { + (void)val; + (void)doc; + + if (doc.ValueExists("statusCode")) + { + val.StatusCode = doc.GetInteger("statusCode"); + } + + if (doc.ValueExists("errorCode")) + { + val.ErrorCode = doc.GetString("errorCode"); + } + + if (doc.ValueExists("errorMessage")) + { + val.ErrorMessage = doc.GetString("errorMessage"); + } + } + + void V2ServiceError::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + + if (StatusCode) + { + object.WithInteger("statusCode", *StatusCode); + } + + if (ErrorCode) + { + object.WithString("errorCode", *ErrorCode); + } + + if (ErrorMessage) + { + object.WithString("errorMessage", *ErrorMessage); + } + } + + V2ServiceError::V2ServiceError(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } + + V2ServiceError &V2ServiceError::operator=(const Crt::JsonView &doc) + { + *this = V2ServiceError(doc); + return *this; + } + + } // namespace Iotidentity +} // namespace Aws diff --git a/jobs/include/aws/iotjobs/IotJobsClientV2.h b/jobs/include/aws/iotjobs/IotJobsClientV2.h new file mode 100644 index 000000000..ab9944810 --- /dev/null +++ b/jobs/include/aws/iotjobs/IotJobsClientV2.h @@ -0,0 +1,232 @@ +#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 + +#include + +namespace Aws +{ + namespace Crt + { + namespace Mqtt + { + class MqttConnection; + } + namespace Mqtt5 + { + class Mqtt5Client; + } + } // namespace Crt +} // namespace Aws + +namespace Aws +{ + namespace Iotjobs + { + + template class ServiceErrorV2 + { + public: + ServiceErrorV2() = delete; + ServiceErrorV2(const ServiceErrorV2 &rhs) = default; + ServiceErrorV2(ServiceErrorV2 &&rhs) = default; + + explicit ServiceErrorV2(int errorCode) : m_errorCode(errorCode), m_modeledError() {} + + ServiceErrorV2(int errorCode, E &&modeledError) + : m_errorCode(errorCode), m_modeledError(std::move(modeledError)) + { + } + + ~ServiceErrorV2() = default; + + ServiceErrorV2 &operator=(const ServiceErrorV2 &rhs) = default; + ServiceErrorV2 &operator=(ServiceErrorV2 &&rhs) = default; + + int GetErrorCode() const { return m_errorCode; } + + bool HasModeledError() const { return m_modeledError.has_value(); } + const E &GetModeledError() const { return m_modeledError.value(); } + + private: + int m_errorCode; + + Aws::Crt::Optional m_modeledError; + }; + + class DescribeJobExecutionRequest; + class DescribeJobExecutionResponse; + class GetPendingJobExecutionsRequest; + class GetPendingJobExecutionsResponse; + class JobExecutionsChangedEvent; + class JobExecutionsChangedSubscriptionRequest; + class NextJobExecutionChangedEvent; + class NextJobExecutionChangedSubscriptionRequest; + class StartNextJobExecutionResponse; + class StartNextPendingJobExecutionRequest; + class UpdateJobExecutionRequest; + class UpdateJobExecutionResponse; + class V2ServiceError; + + using DescribeJobExecutionResultHandler = std::function> &&)>; + using GetPendingJobExecutionsResultHandler = std::function> &&)>; + using StartNextPendingJobExecutionResultHandler = std::function> &&)>; + using UpdateJobExecutionResultHandler = std::function> &&)>; + + /** + * The AWS IoT jobs service can be used to define a set of remote operations that are sent to and executed on + * one or more devices connected to AWS IoT. + * + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#jobs-mqtt-api + * + */ + class AWS_IOTJOBS_API IClientV2 + { + public: + virtual ~IClientV2() = default; + + /** + * Gets detailed information about a job execution. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-describejobexecution + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool DescribeJobExecution( + const DescribeJobExecutionRequest &request, + const DescribeJobExecutionResultHandler &handler) = 0; + + /** + * Gets the list of all jobs for a thing that are not in a terminal state. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-getpendingjobexecutions + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool GetPendingJobExecutions( + const GetPendingJobExecutionsRequest &request, + const GetPendingJobExecutionsResultHandler &handler) = 0; + + /** + * Gets and starts the next pending job execution for a thing (status IN_PROGRESS or QUEUED). + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-startnextpendingjobexecution + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool StartNextPendingJobExecution( + const StartNextPendingJobExecutionRequest &request, + const StartNextPendingJobExecutionResultHandler &handler) = 0; + + /** + * Updates the status of a job execution. You can optionally create a step timer by setting a value for the + * stepTimeoutInMinutes property. If you don't update the value of this property by running + * UpdateJobExecution again, the job execution times out when the step timer expires. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-updatejobexecution + * + * @param request operation to perform + * @param handler function object to invoke upon operation completion + * + * @returns success/failure + */ + virtual bool UpdateJobExecution( + const UpdateJobExecutionRequest &request, + const UpdateJobExecutionResultHandler &handler) = 0; + + /** + * Creates a stream of JobExecutionsChanged notifications for a given IoT thing. + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-jobexecutionschanged + * + * @param request modeled streaming operation subscription configuration + * @param options + * + * @returns a streaming operation which will emit a modeled event every time a message is received on the + * associated MQTT topic + */ + virtual std::shared_ptr CreateJobExecutionsChangedStream( + const JobExecutionsChangedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; + + /** + * + * + * + * AWS documentation: + * https://docs.aws.amazon.com/iot/latest/developerguide/jobs-api.html#mqtt-nextjobexecutionchanged + * + * @param request modeled streaming operation subscription configuration + * @param options + * + * @returns a streaming operation which will emit a modeled event every time a message is received on the + * associated MQTT topic + */ + virtual std::shared_ptr CreateNextJobExecutionChangedStream( + const NextJobExecutionChangedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; + }; + + /** + * Creates a new service client that uses an SDK MQTT5 client for transport. + * + * @param protocolClient MQTT client to use as transport + * @param options request-response MQTT client configuration options + * @param allocator memory allocator to use for all client functionality + * + * @return a new service client + */ + AWS_IOTJOBS_API std::shared_ptr NewClientFrom5( + const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator = Aws::Crt::ApiAllocator()); + + /** + * Creates a new service client that uses an SDK MQTT311 client for transport. + * + * @param protocolClient MQTT client to use as transport + * @param options request-response MQTT client configuration options + * @param allocator memory allocator to use for all client functionality + * + * @return a new service client + */ + AWS_IOTJOBS_API std::shared_ptr NewClientFrom311( + const Aws::Crt::Mqtt::MqttConnection &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator = Aws::Crt::ApiAllocator()); + + } // namespace Iotjobs +} // namespace Aws diff --git a/jobs/include/aws/iotjobs/JobStatus.h b/jobs/include/aws/iotjobs/JobStatus.h index 7655b5f30..0fa69859e 100644 --- a/jobs/include/aws/iotjobs/JobStatus.h +++ b/jobs/include/aws/iotjobs/JobStatus.h @@ -61,5 +61,5 @@ namespace Aws AWS_IOTJOBS_API const char *ToString(JobStatus val); AWS_IOTJOBS_API JobStatus FromString(const Aws::Crt::String &val); } // namespace JobStatusMarshaller - } // namespace Iotjobs + } // namespace Iotjobs } // namespace Aws diff --git a/jobs/include/aws/iotjobs/RejectedErrorCode.h b/jobs/include/aws/iotjobs/RejectedErrorCode.h index 83228c402..1fc115c76 100644 --- a/jobs/include/aws/iotjobs/RejectedErrorCode.h +++ b/jobs/include/aws/iotjobs/RejectedErrorCode.h @@ -76,5 +76,5 @@ namespace Aws AWS_IOTJOBS_API const char *ToString(RejectedErrorCode val); AWS_IOTJOBS_API RejectedErrorCode FromString(const Aws::Crt::String &val); } // namespace RejectedErrorCodeMarshaller - } // namespace Iotjobs + } // namespace Iotjobs } // namespace Aws diff --git a/jobs/include/aws/iotjobs/V2ServiceError.h b/jobs/include/aws/iotjobs/V2ServiceError.h new file mode 100644 index 000000000..27702c3e8 --- /dev/null +++ b/jobs/include/aws/iotjobs/V2ServiceError.h @@ -0,0 +1,72 @@ +#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 + +#include +#include + +namespace Aws +{ + namespace Iotjobs + { + + /** + * Response document containing details about a failed request. + * + */ + class AWS_IOTJOBS_API V2ServiceError final + { + public: + V2ServiceError() = default; + + V2ServiceError(const Crt::JsonView &doc); + V2ServiceError &operator=(const Crt::JsonView &doc); + + void SerializeToObject(Crt::JsonObject &doc) const; + + /** + * Opaque token that can correlate this response to the original request. + * + */ + Aws::Crt::Optional ClientToken; + + /** + * Indicates the type of error. + * + */ + Aws::Crt::Optional Code; + + /** + * A text message that provides additional information. + * + */ + Aws::Crt::Optional Message; + + /** + * The date and time the response was generated by AWS IoT. + * + */ + Aws::Crt::Optional Timestamp; + + /** + * A JobExecutionState object. This field is included only when the code field has the value + * InvalidStateTransition or VersionMismatch. + * + */ + Aws::Crt::Optional ExecutionState; + + private: + static void LoadFromObject(V2ServiceError &obj, const Crt::JsonView &doc); + }; + } // namespace Iotjobs +} // namespace Aws diff --git a/jobs/source/IotJobsClient.cpp b/jobs/source/IotJobsClient.cpp index c0cb1cf0c..0f3189bfa 100644 --- a/jobs/source/IotJobsClient.cpp +++ b/jobs/source/IotJobsClient.cpp @@ -38,9 +38,15 @@ namespace Aws m_connection = Aws::Crt::Mqtt::MqttConnection::NewConnectionFromMqtt5Client(mqtt5Client); } - IotJobsClient::operator bool() const noexcept { return m_connection && *m_connection; } + IotJobsClient::operator bool() const noexcept + { + return m_connection && *m_connection; + } - int IotJobsClient::GetLastError() const noexcept { return aws_last_error(); } + int IotJobsClient::GetLastError() const noexcept + { + return aws_last_error(); + } bool IotJobsClient::SubscribeToDescribeJobExecutionAccepted( const Aws::Iotjobs::DescribeJobExecutionSubscriptionRequest &request, @@ -54,7 +60,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -68,24 +75,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::DescribeJobExecutionResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::DescribeJobExecutionResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" << *request.JobId << "/" - << "get" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/get/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -106,7 +105,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -120,24 +120,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::RejectedError response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::RejectedError response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" << *request.JobId << "/" - << "get" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/get/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -158,7 +150,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -172,24 +165,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::GetPendingJobExecutionsResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::GetPendingJobExecutionsResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "get" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/get/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -210,7 +195,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -224,24 +210,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::RejectedError response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::RejectedError response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "get" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/get/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -262,7 +240,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -276,22 +255,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::JobExecutionsChangedEvent response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::JobExecutionsChangedEvent response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "notify"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/notify"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -312,7 +285,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -326,22 +300,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::NextJobExecutionChangedEvent response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::NextJobExecutionChangedEvent response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "notify-next"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/notify-next"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -362,7 +330,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -376,24 +345,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::StartNextJobExecutionResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::StartNextJobExecutionResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "start-next" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/start-next/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -414,7 +375,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -428,24 +390,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::RejectedError response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::RejectedError response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "start-next" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/start-next/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -466,7 +420,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -480,24 +435,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::UpdateJobExecutionResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::UpdateJobExecutionResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" << *request.JobId << "/" - << "update" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId + << "/update/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -518,7 +466,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -532,24 +481,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotjobs::RejectedError response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotjobs::RejectedError response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" << *request.JobId << "/" - << "update" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId + << "/update/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -564,13 +506,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" << *request.JobId << "/" - << "get"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/get"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -578,7 +514,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -593,13 +530,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "get"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/get"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -607,7 +538,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -622,13 +554,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" - << "start-next"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/start-next"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -636,7 +562,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -651,13 +578,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "jobs" - << "/" << *request.JobId << "/" - << "update"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/update"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -665,7 +586,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; diff --git a/jobs/source/IotJobsClientV2.cpp b/jobs/source/IotJobsClientV2.cpp new file mode 100644 index 000000000..0185e4938 --- /dev/null +++ b/jobs/source/IotJobsClientV2.cpp @@ -0,0 +1,630 @@ +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + * + * This file is generated + */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Aws +{ + namespace Iotjobs + { + + class ClientV2 : public IClientV2 + { + public: + ClientV2( + Aws::Crt::Allocator *allocator, + std::shared_ptr bindingClient); + virtual ~ClientV2() = default; + + bool DescribeJobExecution( + const DescribeJobExecutionRequest &request, + const DescribeJobExecutionResultHandler &handler) override; + + bool GetPendingJobExecutions( + const GetPendingJobExecutionsRequest &request, + const GetPendingJobExecutionsResultHandler &handler) override; + + bool StartNextPendingJobExecution( + const StartNextPendingJobExecutionRequest &request, + const StartNextPendingJobExecutionResultHandler &handler) override; + + bool UpdateJobExecution( + const UpdateJobExecutionRequest &request, + const UpdateJobExecutionResultHandler &handler) override; + + std::shared_ptr CreateJobExecutionsChangedStream( + const JobExecutionsChangedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + override; + + std::shared_ptr CreateNextJobExecutionChangedStream( + const NextJobExecutionChangedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + override; + + private: + Aws::Crt::Allocator *m_allocator; + + std::shared_ptr m_bindingClient; + }; + + ClientV2::ClientV2( + Aws::Crt::Allocator *allocator, + std::shared_ptr bindingClient) + : m_allocator(allocator), m_bindingClient(std::move(bindingClient)) + { + // It's simpler to do this than branch the codegen based on the presence of streaming operations + (void)m_allocator; + } + + template + static void s_applyUnmodeledErrorToHandler(const std::function &handler, int errorCode) + { + ServiceErrorV2 error(errorCode); + R finalResult(std::move(error)); + handler(std::move(finalResult)); + } + + template + static void s_applyModeledErrorToHandler(const std::function &handler, E &&modeledError) + { + ServiceErrorV2 error(AWS_ERROR_MQTT_REQUEST_RESPONSE_MODELED_SERVICE_ERROR, std::move(modeledError)); + R finalResult(std::move(error)); + handler(std::move(finalResult)); + } + + static void s_DescribeJobExecutionResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const DescribeJobExecutionResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + DescribeJobExecutionResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::DescribeJobExecution( + const DescribeJobExecutionRequest &request, + const DescribeJobExecutionResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/get"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/get/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_DescribeJobExecutionResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_GetPendingJobExecutionsResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const GetPendingJobExecutionsResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + GetPendingJobExecutionsResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::GetPendingJobExecutions( + const GetPendingJobExecutionsRequest &request, + const GetPendingJobExecutionsResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/jobs/get"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/jobs/get/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_GetPendingJobExecutionsResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_StartNextPendingJobExecutionResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const StartNextPendingJobExecutionResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + StartNextJobExecutionResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::StartNextPendingJobExecution( + const StartNextPendingJobExecutionRequest &request, + const StartNextPendingJobExecutionResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/jobs/start-next"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/jobs/start-next/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_StartNextPendingJobExecutionResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_UpdateJobExecutionResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const UpdateJobExecutionResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + UpdateJobExecutionResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::UpdateJobExecution( + const UpdateJobExecutionRequest &request, + const UpdateJobExecutionResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId << "/update"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/jobs/" << *request.JobId + << "/update/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_UpdateJobExecutionResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + template class ServiceStreamingOperation : public Aws::Iot::RequestResponse::IStreamingOperation + { + public: + explicit ServiceStreamingOperation(std::shared_ptr stream) + : m_stream(std::move(stream)) + { + } + + static std::shared_ptr Create( + Aws::Crt::Allocator *allocator, + const std::shared_ptr &bindingClient, + const Aws::Crt::String &subscriptionTopicFilter, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + + std::function unmodeledHandler = + [options](Aws::Iot::RequestResponse::IncomingPublishEvent &&event) + { + const auto &payload = event.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + return; + } + + T modeledEvent(jsonObject); + options.GetStreamHandler()(std::move(modeledEvent)); + }; + + Aws::Iot::RequestResponse::StreamingOperationOptionsInternal internalOptions; + internalOptions.subscriptionTopicFilter = Aws::Crt::ByteCursorFromString(subscriptionTopicFilter); + internalOptions.subscriptionStatusEventHandler = options.GetSubscriptionStatusEventHandler(); + internalOptions.incomingPublishEventHandler = unmodeledHandler; + + auto unmodeledStream = bindingClient->CreateStream(internalOptions); + if (!unmodeledStream) + { + return nullptr; + } + + return Aws::Crt::MakeShared>(allocator, unmodeledStream); + } + + void Open() override { m_stream->Open(); } + + private: + std::shared_ptr m_stream; + }; + + std::shared_ptr ClientV2::CreateJobExecutionsChangedStream( + const JobExecutionsChangedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + Aws::Crt::StringStream topicStream; + topicStream << "$aws/things/" << *request.ThingName << "/jobs/notify"; + Aws::Crt::String topic = topicStream.str(); + + return ServiceStreamingOperation::Create( + m_allocator, m_bindingClient, topic, options); + } + + std::shared_ptr ClientV2::CreateNextJobExecutionChangedStream( + const NextJobExecutionChangedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + Aws::Crt::StringStream topicStream; + topicStream << "$aws/things/" << *request.ThingName << "/jobs/notify-next"; + Aws::Crt::String topic = topicStream.str(); + + return ServiceStreamingOperation::Create( + m_allocator, m_bindingClient, topic, options); + } + + std::shared_ptr NewClientFrom5( + const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator) + { + + std::shared_ptr bindingClient = + Aws::Iot::RequestResponse::NewClientFrom5(protocolClient, options, allocator); + if (nullptr == bindingClient) + { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + std::shared_ptr NewClientFrom311( + const Aws::Crt::Mqtt::MqttConnection &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator) + { + + std::shared_ptr bindingClient = + Aws::Iot::RequestResponse::NewClientFrom311(protocolClient, options, allocator); + if (nullptr == bindingClient) + { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + } // namespace Iotjobs +} // namespace Aws diff --git a/jobs/source/JobExecutionData.cpp b/jobs/source/JobExecutionData.cpp index 9e39e0f14..4dba0a662 100644 --- a/jobs/source/JobExecutionData.cpp +++ b/jobs/source/JobExecutionData.cpp @@ -132,7 +132,10 @@ namespace Aws } } - JobExecutionData::JobExecutionData(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + JobExecutionData::JobExecutionData(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } JobExecutionData &JobExecutionData::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/JobExecutionState.cpp b/jobs/source/JobExecutionState.cpp index 3a25e08c8..641244c98 100644 --- a/jobs/source/JobExecutionState.cpp +++ b/jobs/source/JobExecutionState.cpp @@ -65,7 +65,10 @@ namespace Aws } } - JobExecutionState::JobExecutionState(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + JobExecutionState::JobExecutionState(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } JobExecutionState &JobExecutionState::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/JobExecutionSummary.cpp b/jobs/source/JobExecutionSummary.cpp index 1f7936e69..4181e9c4e 100644 --- a/jobs/source/JobExecutionSummary.cpp +++ b/jobs/source/JobExecutionSummary.cpp @@ -81,7 +81,10 @@ namespace Aws } } - JobExecutionSummary::JobExecutionSummary(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + JobExecutionSummary::JobExecutionSummary(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } JobExecutionSummary &JobExecutionSummary::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/JobExecutionsChangedEvent.cpp b/jobs/source/JobExecutionsChangedEvent.cpp index d8e1f0684..0b82e095d 100644 --- a/jobs/source/JobExecutionsChangedEvent.cpp +++ b/jobs/source/JobExecutionsChangedEvent.cpp @@ -73,7 +73,10 @@ namespace Aws } } - JobExecutionsChangedEvent::JobExecutionsChangedEvent(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + JobExecutionsChangedEvent::JobExecutionsChangedEvent(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } JobExecutionsChangedEvent &JobExecutionsChangedEvent::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/JobStatus.cpp b/jobs/source/JobStatus.cpp index 06169d17f..1b7603bb2 100644 --- a/jobs/source/JobStatus.cpp +++ b/jobs/source/JobStatus.cpp @@ -100,5 +100,5 @@ namespace Aws return static_cast(-1); } } // namespace JobStatusMarshaller - } // namespace Iotjobs + } // namespace Iotjobs } // namespace Aws diff --git a/jobs/source/RejectedError.cpp b/jobs/source/RejectedError.cpp index 00c2cd188..a487d7f35 100644 --- a/jobs/source/RejectedError.cpp +++ b/jobs/source/RejectedError.cpp @@ -73,7 +73,10 @@ namespace Aws } } - RejectedError::RejectedError(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + RejectedError::RejectedError(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } RejectedError &RejectedError::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/RejectedErrorCode.cpp b/jobs/source/RejectedErrorCode.cpp index 4e792a57c..d1fe072bc 100644 --- a/jobs/source/RejectedErrorCode.cpp +++ b/jobs/source/RejectedErrorCode.cpp @@ -108,5 +108,5 @@ namespace Aws return static_cast(-1); } } // namespace RejectedErrorCodeMarshaller - } // namespace Iotjobs + } // namespace Iotjobs } // namespace Aws diff --git a/jobs/source/UpdateJobExecutionRequest.cpp b/jobs/source/UpdateJobExecutionRequest.cpp index 8ac18844d..19f250897 100644 --- a/jobs/source/UpdateJobExecutionRequest.cpp +++ b/jobs/source/UpdateJobExecutionRequest.cpp @@ -115,7 +115,10 @@ namespace Aws } } - UpdateJobExecutionRequest::UpdateJobExecutionRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + UpdateJobExecutionRequest::UpdateJobExecutionRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } UpdateJobExecutionRequest &UpdateJobExecutionRequest::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/UpdateJobExecutionResponse.cpp b/jobs/source/UpdateJobExecutionResponse.cpp index d6a919924..43b66ec6d 100644 --- a/jobs/source/UpdateJobExecutionResponse.cpp +++ b/jobs/source/UpdateJobExecutionResponse.cpp @@ -63,7 +63,10 @@ namespace Aws } } - UpdateJobExecutionResponse::UpdateJobExecutionResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + UpdateJobExecutionResponse::UpdateJobExecutionResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } UpdateJobExecutionResponse &UpdateJobExecutionResponse::operator=(const Crt::JsonView &doc) { diff --git a/jobs/source/V2ServiceError.cpp b/jobs/source/V2ServiceError.cpp new file mode 100644 index 000000000..3e2bb5444 --- /dev/null +++ b/jobs/source/V2ServiceError.cpp @@ -0,0 +1,88 @@ +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + * + * This file is generated + */ +#include + +namespace Aws +{ + namespace Iotjobs + { + + void V2ServiceError::LoadFromObject(V2ServiceError &val, const Aws::Crt::JsonView &doc) + { + (void)val; + (void)doc; + + if (doc.ValueExists("clientToken")) + { + val.ClientToken = doc.GetString("clientToken"); + } + + if (doc.ValueExists("code")) + { + val.Code = RejectedErrorCodeMarshaller::FromString(doc.GetString("code")); + } + + if (doc.ValueExists("message")) + { + val.Message = doc.GetString("message"); + } + + if (doc.ValueExists("timestamp")) + { + val.Timestamp = doc.GetDouble("timestamp"); + } + + if (doc.ValueExists("executionState")) + { + val.ExecutionState = doc.GetJsonObject("executionState"); + } + } + + void V2ServiceError::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + + if (ClientToken) + { + object.WithString("clientToken", *ClientToken); + } + + if (Code) + { + object.WithString("code", RejectedErrorCodeMarshaller::ToString(*Code)); + } + + if (Message) + { + object.WithString("message", *Message); + } + + if (Timestamp) + { + object.WithDouble("timestamp", Timestamp->SecondsWithMSPrecision()); + } + + if (ExecutionState) + { + Aws::Crt::JsonObject jsonObject; + ExecutionState->SerializeToObject(jsonObject); + object.WithObject("executionState", std::move(jsonObject)); + } + } + + V2ServiceError::V2ServiceError(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } + + V2ServiceError &V2ServiceError::operator=(const Crt::JsonView &doc) + { + *this = V2ServiceError(doc); + return *this; + } + + } // namespace Iotjobs +} // namespace Aws diff --git a/shadow/include/aws/iotshadow/IotShadowClientV2.h b/shadow/include/aws/iotshadow/IotShadowClientV2.h index d125e870d..2ce41b594 100644 --- a/shadow/include/aws/iotshadow/IotShadowClientV2.h +++ b/shadow/include/aws/iotshadow/IotShadowClientV2.h @@ -79,6 +79,7 @@ namespace Aws class UpdateNamedShadowRequest; class UpdateShadowRequest; class UpdateShadowResponse; + class V2ServiceError; using DeleteNamedShadowResultHandler = std::function> &&)>; @@ -211,7 +212,7 @@ namespace Aws */ virtual std::shared_ptr CreateNamedShadowDeltaUpdatedStream( const NamedShadowDeltaUpdatedSubscriptionRequest &request, - const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; /** * Create a stream for ShadowUpdated events for a named shadow of an AWS IoT thing. @@ -228,7 +229,7 @@ namespace Aws */ virtual std::shared_ptr CreateNamedShadowUpdatedStream( const NamedShadowUpdatedSubscriptionRequest &request, - const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; /** * Create a stream for ShadowDelta events for the (classic) shadow of an AWS IoT thing. @@ -245,7 +246,7 @@ namespace Aws */ virtual std::shared_ptr CreateShadowDeltaUpdatedStream( const ShadowDeltaUpdatedSubscriptionRequest &request, - const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; /** * Create a stream for ShadowUpdated events for the (classic) shadow of an AWS IoT thing. @@ -262,7 +263,7 @@ namespace Aws */ virtual std::shared_ptr CreateShadowUpdatedStream( const ShadowUpdatedSubscriptionRequest &request, - const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) = 0; }; /** diff --git a/shadow/include/aws/iotshadow/V2ServiceError.h b/shadow/include/aws/iotshadow/V2ServiceError.h new file mode 100644 index 000000000..8e013a9b8 --- /dev/null +++ b/shadow/include/aws/iotshadow/V2ServiceError.h @@ -0,0 +1,64 @@ +#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 Iotshadow + { + + /** + * Response document containing details about a failed request. + * + */ + class AWS_IOTSHADOW_API V2ServiceError final + { + public: + V2ServiceError() = default; + + V2ServiceError(const Crt::JsonView &doc); + V2ServiceError &operator=(const Crt::JsonView &doc); + + void SerializeToObject(Crt::JsonObject &doc) const; + + /** + * Opaque request-response correlation data. Present only if a client token was used in the request. + * + */ + Aws::Crt::Optional ClientToken; + + /** + * An HTTP response code that indicates the type of error. + * + */ + Aws::Crt::Optional Code; + + /** + * A text message that provides additional information. + * + */ + Aws::Crt::Optional Message; + + /** + * The date and time the response was generated by AWS IoT. This property is not present in all error + * response documents. + * + */ + Aws::Crt::Optional Timestamp; + + private: + static void LoadFromObject(V2ServiceError &obj, const Crt::JsonView &doc); + }; + } // namespace Iotshadow +} // namespace Aws diff --git a/shadow/source/DeleteNamedShadowRequest.cpp b/shadow/source/DeleteNamedShadowRequest.cpp index e663bb16d..16da220b0 100644 --- a/shadow/source/DeleteNamedShadowRequest.cpp +++ b/shadow/source/DeleteNamedShadowRequest.cpp @@ -31,7 +31,10 @@ namespace Aws } } - DeleteNamedShadowRequest::DeleteNamedShadowRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + DeleteNamedShadowRequest::DeleteNamedShadowRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } DeleteNamedShadowRequest &DeleteNamedShadowRequest::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/DeleteShadowRequest.cpp b/shadow/source/DeleteShadowRequest.cpp index a5f7fa74c..f602bb78a 100644 --- a/shadow/source/DeleteShadowRequest.cpp +++ b/shadow/source/DeleteShadowRequest.cpp @@ -31,7 +31,10 @@ namespace Aws } } - DeleteShadowRequest::DeleteShadowRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + DeleteShadowRequest::DeleteShadowRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } DeleteShadowRequest &DeleteShadowRequest::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/DeleteShadowResponse.cpp b/shadow/source/DeleteShadowResponse.cpp index 6e46fd6e2..5aa22864e 100644 --- a/shadow/source/DeleteShadowResponse.cpp +++ b/shadow/source/DeleteShadowResponse.cpp @@ -51,7 +51,10 @@ namespace Aws } } - DeleteShadowResponse::DeleteShadowResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + DeleteShadowResponse::DeleteShadowResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } DeleteShadowResponse &DeleteShadowResponse::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/DeleteShadowSubscriptionRequest.cpp b/shadow/source/DeleteShadowSubscriptionRequest.cpp index 59dc03eb3..3f91cb255 100644 --- a/shadow/source/DeleteShadowSubscriptionRequest.cpp +++ b/shadow/source/DeleteShadowSubscriptionRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void DeleteShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void DeleteShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } DeleteShadowSubscriptionRequest::DeleteShadowSubscriptionRequest(const Crt::JsonView &doc) { diff --git a/shadow/source/ErrorResponse.cpp b/shadow/source/ErrorResponse.cpp index c501b2b22..bf782bb69 100644 --- a/shadow/source/ErrorResponse.cpp +++ b/shadow/source/ErrorResponse.cpp @@ -61,7 +61,10 @@ namespace Aws } } - ErrorResponse::ErrorResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ErrorResponse::ErrorResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ErrorResponse &ErrorResponse::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/GetNamedShadowRequest.cpp b/shadow/source/GetNamedShadowRequest.cpp index b3c87a3d0..3a9383768 100644 --- a/shadow/source/GetNamedShadowRequest.cpp +++ b/shadow/source/GetNamedShadowRequest.cpp @@ -31,7 +31,10 @@ namespace Aws } } - GetNamedShadowRequest::GetNamedShadowRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + GetNamedShadowRequest::GetNamedShadowRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } GetNamedShadowRequest &GetNamedShadowRequest::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/GetNamedShadowSubscriptionRequest.cpp b/shadow/source/GetNamedShadowSubscriptionRequest.cpp index 19c80b2cd..38f7c3689 100644 --- a/shadow/source/GetNamedShadowSubscriptionRequest.cpp +++ b/shadow/source/GetNamedShadowSubscriptionRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void GetNamedShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void GetNamedShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } GetNamedShadowSubscriptionRequest::GetNamedShadowSubscriptionRequest(const Crt::JsonView &doc) { diff --git a/shadow/source/GetShadowRequest.cpp b/shadow/source/GetShadowRequest.cpp index 021666594..0250b1b8d 100644 --- a/shadow/source/GetShadowRequest.cpp +++ b/shadow/source/GetShadowRequest.cpp @@ -31,7 +31,10 @@ namespace Aws } } - GetShadowRequest::GetShadowRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + GetShadowRequest::GetShadowRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } GetShadowRequest &GetShadowRequest::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/GetShadowResponse.cpp b/shadow/source/GetShadowResponse.cpp index 17330d27a..2275c1e81 100644 --- a/shadow/source/GetShadowResponse.cpp +++ b/shadow/source/GetShadowResponse.cpp @@ -75,7 +75,10 @@ namespace Aws } } - GetShadowResponse::GetShadowResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + GetShadowResponse::GetShadowResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } GetShadowResponse &GetShadowResponse::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/GetShadowSubscriptionRequest.cpp b/shadow/source/GetShadowSubscriptionRequest.cpp index 50398d135..2007e3b00 100644 --- a/shadow/source/GetShadowSubscriptionRequest.cpp +++ b/shadow/source/GetShadowSubscriptionRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void GetShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void GetShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } GetShadowSubscriptionRequest::GetShadowSubscriptionRequest(const Crt::JsonView &doc) { diff --git a/shadow/source/IotShadowClient.cpp b/shadow/source/IotShadowClient.cpp index b9bac21a9..a72e28c0d 100644 --- a/shadow/source/IotShadowClient.cpp +++ b/shadow/source/IotShadowClient.cpp @@ -43,9 +43,15 @@ namespace Aws m_connection = Aws::Crt::Mqtt::MqttConnection::NewConnectionFromMqtt5Client(mqtt5Client); } - IotShadowClient::operator bool() const noexcept { return m_connection && *m_connection; } + IotShadowClient::operator bool() const noexcept + { + return m_connection && *m_connection; + } - int IotShadowClient::GetLastError() const noexcept { return aws_last_error(); } + int IotShadowClient::GetLastError() const noexcept + { + return aws_last_error(); + } bool IotShadowClient::SubscribeToDeleteNamedShadowAccepted( const Aws::Iotshadow::DeleteNamedShadowSubscriptionRequest &request, @@ -59,7 +65,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -73,26 +80,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::DeleteShadowResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::DeleteShadowResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "delete" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/delete/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -113,7 +111,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -127,26 +126,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "delete" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/delete/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -167,7 +157,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -181,24 +172,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::DeleteShadowResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::DeleteShadowResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "delete" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/delete/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -219,7 +202,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -233,24 +217,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "delete" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/delete/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -271,7 +247,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -285,26 +262,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::GetShadowResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::GetShadowResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "get" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/get/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -325,7 +293,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -339,26 +308,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "get" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/get/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -379,7 +339,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -393,24 +354,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::GetShadowResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::GetShadowResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "get" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/get/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -431,7 +384,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -445,24 +399,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "get" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/get/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -483,7 +429,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -497,26 +444,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ShadowDeltaUpdatedEvent response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ShadowDeltaUpdatedEvent response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "update" - << "/" - << "delta"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/delta"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -537,7 +475,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -551,26 +490,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ShadowUpdatedEvent response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ShadowUpdatedEvent response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "update" - << "/" - << "documents"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/documents"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -591,7 +521,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -605,24 +536,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ShadowDeltaUpdatedEvent response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ShadowDeltaUpdatedEvent response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "update" - << "/" - << "delta"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/update/delta"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -643,7 +566,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -657,24 +581,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ShadowUpdatedEvent response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ShadowUpdatedEvent response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "update" - << "/" - << "documents"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/update/documents"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -695,7 +611,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -709,26 +626,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::UpdateShadowResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::UpdateShadowResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "update" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -749,7 +657,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -763,26 +672,17 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "update" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -803,7 +703,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -817,24 +718,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::UpdateShadowResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::UpdateShadowResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "update" - << "/" - << "accepted"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/update/accepted"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -855,7 +748,8 @@ namespace Aws uint16_t, const Aws::Crt::String &topic, Aws::Crt::Mqtt::QOS, - int errorCode) { + int errorCode) + { (void)topic; if (errorCode) { @@ -869,24 +763,16 @@ namespace Aws }; auto onSubscribePublish = - [handler]( - Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) { - Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - Aws::Iotshadow::ErrorResponse response(jsonObject); - handler(&response, AWS_ERROR_SUCCESS); - }; + [handler](Aws::Crt::Mqtt::MqttConnection &, const Aws::Crt::String &, const Aws::Crt::ByteBuf &payload) + { + Aws::Crt::String objectStr(reinterpret_cast(payload.buffer), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + Aws::Iotshadow::ErrorResponse response(jsonObject); + handler(&response, AWS_ERROR_SUCCESS); + }; Aws::Crt::StringStream subscribeTopicSStr; - subscribeTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "update" - << "/" - << "rejected"; + subscribeTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/update/rejected"; return m_connection->Subscribe( subscribeTopicSStr.str().c_str(), @@ -901,15 +787,8 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "delete"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/delete"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -917,7 +796,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -932,13 +812,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "delete"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/delete"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -946,7 +820,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -961,15 +836,8 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "get"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/get"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -977,7 +845,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -992,13 +861,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "get"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/get"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -1006,7 +869,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -1021,15 +885,8 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "name" - << "/" << *request.ShadowName << "/" - << "update"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -1037,7 +894,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; @@ -1052,13 +910,7 @@ namespace Aws const OnPublishComplete &onPubAck) { Aws::Crt::StringStream publishTopicSStr; - publishTopicSStr << "$aws" - << "/" - << "things" - << "/" << *request.ThingName << "/" - << "shadow" - << "/" - << "update"; + publishTopicSStr << "$aws/things/" << *request.ThingName << "/shadow/update"; Aws::Crt::JsonObject jsonObject; request.SerializeToObject(jsonObject); @@ -1066,7 +918,8 @@ namespace Aws Aws::Crt::ByteBuf buf = Aws::Crt::ByteBufNewCopy( Aws::Crt::g_allocator, reinterpret_cast(outgoingJson.data()), outgoingJson.length()); - auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) { + auto onPublishComplete = [buf, onPubAck](Aws::Crt::Mqtt::MqttConnection &, uint16_t, int errorCode) + { onPubAck(errorCode); Aws::Crt::ByteBufDelete(const_cast(buf)); }; diff --git a/shadow/source/IotShadowClientV2.cpp b/shadow/source/IotShadowClientV2.cpp index 433f2c517..48a6163b8 100644 --- a/shadow/source/IotShadowClientV2.cpp +++ b/shadow/source/IotShadowClientV2.cpp @@ -22,721 +22,865 @@ #include #include #include +#include namespace Aws { -namespace Iotshadow -{ + namespace Iotshadow + { -class ClientV2 : public IClientV2 -{ - public: - ClientV2(Aws::Crt::Allocator *allocator, std::shared_ptr bindingClient); - virtual ~ClientV2() = default; + class ClientV2 : public IClientV2 + { + public: + ClientV2( + Aws::Crt::Allocator *allocator, + std::shared_ptr bindingClient); + virtual ~ClientV2() = default; - bool DeleteNamedShadow(const DeleteNamedShadowRequest &request, const DeleteNamedShadowResultHandler &handler) override; + bool DeleteNamedShadow( + const DeleteNamedShadowRequest &request, + const DeleteNamedShadowResultHandler &handler) override; - bool DeleteShadow(const DeleteShadowRequest &request, const DeleteShadowResultHandler &handler) override; + bool DeleteShadow(const DeleteShadowRequest &request, const DeleteShadowResultHandler &handler) override; - bool GetNamedShadow(const GetNamedShadowRequest &request, const GetNamedShadowResultHandler &handler) override; + bool GetNamedShadow(const GetNamedShadowRequest &request, const GetNamedShadowResultHandler &handler) + override; - bool GetShadow(const GetShadowRequest &request, const GetShadowResultHandler &handler) override; + bool GetShadow(const GetShadowRequest &request, const GetShadowResultHandler &handler) override; - bool UpdateNamedShadow(const UpdateNamedShadowRequest &request, const UpdateNamedShadowResultHandler &handler) override; + bool UpdateNamedShadow( + const UpdateNamedShadowRequest &request, + const UpdateNamedShadowResultHandler &handler) override; - bool UpdateShadow(const UpdateShadowRequest &request, const UpdateShadowResultHandler &handler) override; + bool UpdateShadow(const UpdateShadowRequest &request, const UpdateShadowResultHandler &handler) override; + std::shared_ptr CreateNamedShadowDeltaUpdatedStream( + const NamedShadowDeltaUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; - std::shared_ptr CreateNamedShadowDeltaUpdatedStream(const NamedShadowDeltaUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; + std::shared_ptr CreateNamedShadowUpdatedStream( + const NamedShadowUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; - std::shared_ptr CreateNamedShadowUpdatedStream(const NamedShadowUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; + std::shared_ptr CreateShadowDeltaUpdatedStream( + const ShadowDeltaUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; - std::shared_ptr CreateShadowDeltaUpdatedStream(const ShadowDeltaUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; + std::shared_ptr CreateShadowUpdatedStream( + const ShadowUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; - std::shared_ptr CreateShadowUpdatedStream(const ShadowUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) override; + private: + Aws::Crt::Allocator *m_allocator; + std::shared_ptr m_bindingClient; + }; - private: + ClientV2::ClientV2( + Aws::Crt::Allocator *allocator, + std::shared_ptr bindingClient) + : m_allocator(allocator), m_bindingClient(std::move(bindingClient)) + { + // It's simpler to do this than branch the codegen based on the presence of streaming operations + (void)m_allocator; + } - Aws::Crt::Allocator *m_allocator; + template + static void s_applyUnmodeledErrorToHandler(const std::function &handler, int errorCode) + { + ServiceErrorV2 error(errorCode); + R finalResult(std::move(error)); + handler(std::move(finalResult)); + } - std::shared_ptr m_bindingClient; -}; + template + static void s_applyModeledErrorToHandler(const std::function &handler, E &&modeledError) + { + ServiceErrorV2 error(AWS_ERROR_MQTT_REQUEST_RESPONSE_MODELED_SERVICE_ERROR, std::move(modeledError)); + R finalResult(std::move(error)); + handler(std::move(finalResult)); + } -ClientV2::ClientV2(Aws::Crt::Allocator *allocator, std::shared_ptr bindingClient) : - m_allocator(allocator), - m_bindingClient(std::move(bindingClient)) -{ -} - -template -static void s_applyUnmodeledErrorToHandler(const std::function &handler, int errorCode) { - ServiceErrorV2 error(errorCode); - R finalResult(std::move(error)); - handler(std::move(finalResult)); -} - -template -static void s_applyModeledErrorToHandler(const std::function &handler, E &&modeledError) { - ServiceErrorV2 error(AWS_ERROR_MQTT_REQUEST_RESPONSE_MODELED_SERVICE_ERROR, std::move(modeledError)); - R finalResult(std::move(error)); - handler(std::move(finalResult)); -} - - - -static void s_DeleteNamedShadowResponseHandler(Aws::Iot::RequestResponse::UnmodeledResult &&result, const std::function &handler, const Aws::Crt::String &successPathTopic, const Aws::Crt::String &failurePathTopic) { - using E = V2ServiceError; - using R = Aws::Iot::RequestResponse::Result>; - - if (!result.IsSuccess()) { - s_applyUnmodeledErrorToHandler(handler, result.GetError()); - return; - } - - auto response = result.GetResponse(); - const auto &payload = response.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); - return; - } - - const auto &topic = response.GetTopic(); - auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); - if (responseTopic == successPathTopic) { - DeleteShadowResponse modeledResponse(jsonObject); - Aws::Iot::RequestResponse::Result> finalResult(std::move(modeledResponse)); - handler(std::move(finalResult)); - } else if (responseTopic == failurePathTopic) { - V2ServiceError modeledError(jsonObject); - s_applyModeledErrorToHandler(handler, std::move(modeledError)); - } else { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); - } -} - -bool ClientV2::DeleteNamedShadow(const DeleteNamedShadowRequest &request, const DeleteNamedShadowResultHandler &handler) { - Aws::Crt::StringStream publishTopicStream; - publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/delete"; - Aws::Crt::String publishTopic = publishTopicStream.str(); - - Aws::Crt::StringStream subscriptionTopicStream; - subscriptionTopicStream << publishTopic << "/+"; - Aws::Crt::String subscriptionTopic = subscriptionTopicStream.str(); - - - struct aws_byte_cursor subscriptionTopicFilters[1] = { - Aws::Crt::ByteCursorFromString(subscriptionTopic) - }; - - Aws::Crt::StringStream responsePathTopicAcceptedStream; - responsePathTopicAcceptedStream << publishTopic << "/accepted"; - Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); - - Aws::Crt::StringStream responsePathTopicRejectedStream; - responsePathTopicRejectedStream << publishTopic << "/rejected"; - Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); - - struct aws_mqtt_request_operation_response_path responsePaths[2]; - responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); - responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); - responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - - Aws::Crt::JsonObject jsonObject; - request.SerializeToObject(jsonObject); - - auto uuid = Aws::Crt::UUID().ToString(); - jsonObject.WithString("clientToken", uuid); - - 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); - options.serialized_request = - Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); - - options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); - - auto resultHandler = - [handler, responsePathTopicAccepted, responsePathTopicRejected](Aws::Iot::RequestResponse::UnmodeledResult &&result) - { s_DeleteNamedShadowResponseHandler(std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); }; - - int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); - - return submitResult == AWS_OP_SUCCESS; -} - - -static void s_DeleteShadowResponseHandler(Aws::Iot::RequestResponse::UnmodeledResult &&result, const std::function &handler, const Aws::Crt::String &successPathTopic, const Aws::Crt::String &failurePathTopic) { - using E = V2ServiceError; - using R = Aws::Iot::RequestResponse::Result>; - - if (!result.IsSuccess()) { - s_applyUnmodeledErrorToHandler(handler, result.GetError()); - return; - } - - auto response = result.GetResponse(); - const auto &payload = response.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); - return; - } - - const auto &topic = response.GetTopic(); - auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); - if (responseTopic == successPathTopic) { - DeleteShadowResponse modeledResponse(jsonObject); - Aws::Iot::RequestResponse::Result> finalResult(std::move(modeledResponse)); - handler(std::move(finalResult)); - } else if (responseTopic == failurePathTopic) { - V2ServiceError modeledError(jsonObject); - s_applyModeledErrorToHandler(handler, std::move(modeledError)); - } else { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); - } -} - -bool ClientV2::DeleteShadow(const DeleteShadowRequest &request, const DeleteShadowResultHandler &handler) { - Aws::Crt::StringStream publishTopicStream; - publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/delete"; - Aws::Crt::String publishTopic = publishTopicStream.str(); - - Aws::Crt::StringStream subscriptionTopicStream; - subscriptionTopicStream << publishTopic << "/+"; - Aws::Crt::String subscriptionTopic = subscriptionTopicStream.str(); - - - struct aws_byte_cursor subscriptionTopicFilters[1] = { - Aws::Crt::ByteCursorFromString(subscriptionTopic) - }; - - Aws::Crt::StringStream responsePathTopicAcceptedStream; - responsePathTopicAcceptedStream << publishTopic << "/accepted"; - Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); - - Aws::Crt::StringStream responsePathTopicRejectedStream; - responsePathTopicRejectedStream << publishTopic << "/rejected"; - Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); - - struct aws_mqtt_request_operation_response_path responsePaths[2]; - responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); - responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); - responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - - Aws::Crt::JsonObject jsonObject; - request.SerializeToObject(jsonObject); - - auto uuid = Aws::Crt::UUID().ToString(); - jsonObject.WithString("clientToken", uuid); - - 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); - options.serialized_request = - Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); - - options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); - - auto resultHandler = - [handler, responsePathTopicAccepted, responsePathTopicRejected](Aws::Iot::RequestResponse::UnmodeledResult &&result) - { s_DeleteShadowResponseHandler(std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); }; - - int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); - - return submitResult == AWS_OP_SUCCESS; -} - - -static void s_GetNamedShadowResponseHandler(Aws::Iot::RequestResponse::UnmodeledResult &&result, const std::function &handler, const Aws::Crt::String &successPathTopic, const Aws::Crt::String &failurePathTopic) { - using E = V2ServiceError; - using R = Aws::Iot::RequestResponse::Result>; - - if (!result.IsSuccess()) { - s_applyUnmodeledErrorToHandler(handler, result.GetError()); - return; - } - - auto response = result.GetResponse(); - const auto &payload = response.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); - return; - } - - const auto &topic = response.GetTopic(); - auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); - if (responseTopic == successPathTopic) { - GetShadowResponse modeledResponse(jsonObject); - Aws::Iot::RequestResponse::Result> finalResult(std::move(modeledResponse)); - handler(std::move(finalResult)); - } else if (responseTopic == failurePathTopic) { - V2ServiceError modeledError(jsonObject); - s_applyModeledErrorToHandler(handler, std::move(modeledError)); - } else { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); - } -} - -bool ClientV2::GetNamedShadow(const GetNamedShadowRequest &request, const GetNamedShadowResultHandler &handler) { - Aws::Crt::StringStream publishTopicStream; - publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/get"; - Aws::Crt::String publishTopic = publishTopicStream.str(); - - Aws::Crt::StringStream subscriptionTopicStream; - subscriptionTopicStream << publishTopic << "/+"; - Aws::Crt::String subscriptionTopic = subscriptionTopicStream.str(); - - - struct aws_byte_cursor subscriptionTopicFilters[1] = { - Aws::Crt::ByteCursorFromString(subscriptionTopic) - }; - - Aws::Crt::StringStream responsePathTopicAcceptedStream; - responsePathTopicAcceptedStream << publishTopic << "/accepted"; - Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); - - Aws::Crt::StringStream responsePathTopicRejectedStream; - responsePathTopicRejectedStream << publishTopic << "/rejected"; - Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); - - struct aws_mqtt_request_operation_response_path responsePaths[2]; - responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); - responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); - responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - - Aws::Crt::JsonObject jsonObject; - request.SerializeToObject(jsonObject); - - auto uuid = Aws::Crt::UUID().ToString(); - jsonObject.WithString("clientToken", uuid); - - 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); - options.serialized_request = - Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); - - options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); - - auto resultHandler = - [handler, responsePathTopicAccepted, responsePathTopicRejected](Aws::Iot::RequestResponse::UnmodeledResult &&result) - { s_GetNamedShadowResponseHandler(std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); }; - - int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); - - return submitResult == AWS_OP_SUCCESS; -} - - -static void s_GetShadowResponseHandler(Aws::Iot::RequestResponse::UnmodeledResult &&result, const std::function &handler, const Aws::Crt::String &successPathTopic, const Aws::Crt::String &failurePathTopic) { - using E = V2ServiceError; - using R = Aws::Iot::RequestResponse::Result>; - - if (!result.IsSuccess()) { - s_applyUnmodeledErrorToHandler(handler, result.GetError()); - return; - } - - auto response = result.GetResponse(); - const auto &payload = response.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); - return; - } - - const auto &topic = response.GetTopic(); - auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); - if (responseTopic == successPathTopic) { - GetShadowResponse modeledResponse(jsonObject); - Aws::Iot::RequestResponse::Result> finalResult(std::move(modeledResponse)); - handler(std::move(finalResult)); - } else if (responseTopic == failurePathTopic) { - V2ServiceError modeledError(jsonObject); - s_applyModeledErrorToHandler(handler, std::move(modeledError)); - } else { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); - } -} - -bool ClientV2::GetShadow(const GetShadowRequest &request, const GetShadowResultHandler &handler) { - Aws::Crt::StringStream publishTopicStream; - publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/get"; - Aws::Crt::String publishTopic = publishTopicStream.str(); - - Aws::Crt::StringStream subscriptionTopicStream; - subscriptionTopicStream << publishTopic << "/+"; - Aws::Crt::String subscriptionTopic = subscriptionTopicStream.str(); - - - struct aws_byte_cursor subscriptionTopicFilters[1] = { - Aws::Crt::ByteCursorFromString(subscriptionTopic) - }; - - Aws::Crt::StringStream responsePathTopicAcceptedStream; - responsePathTopicAcceptedStream << publishTopic << "/accepted"; - Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); - - Aws::Crt::StringStream responsePathTopicRejectedStream; - responsePathTopicRejectedStream << publishTopic << "/rejected"; - Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); - - struct aws_mqtt_request_operation_response_path responsePaths[2]; - responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); - responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); - responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - - Aws::Crt::JsonObject jsonObject; - request.SerializeToObject(jsonObject); - - auto uuid = Aws::Crt::UUID().ToString(); - jsonObject.WithString("clientToken", uuid); - - 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); - options.serialized_request = - Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); - - options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); - - auto resultHandler = - [handler, responsePathTopicAccepted, responsePathTopicRejected](Aws::Iot::RequestResponse::UnmodeledResult &&result) - { s_GetShadowResponseHandler(std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); }; - - int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); - - return submitResult == AWS_OP_SUCCESS; -} - - -static void s_UpdateNamedShadowResponseHandler(Aws::Iot::RequestResponse::UnmodeledResult &&result, const std::function &handler, const Aws::Crt::String &successPathTopic, const Aws::Crt::String &failurePathTopic) { - using E = V2ServiceError; - using R = Aws::Iot::RequestResponse::Result>; - - if (!result.IsSuccess()) { - s_applyUnmodeledErrorToHandler(handler, result.GetError()); - return; - } - - auto response = result.GetResponse(); - const auto &payload = response.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); - return; - } - - const auto &topic = response.GetTopic(); - auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); - if (responseTopic == successPathTopic) { - UpdateShadowResponse modeledResponse(jsonObject); - Aws::Iot::RequestResponse::Result> finalResult(std::move(modeledResponse)); - handler(std::move(finalResult)); - } else if (responseTopic == failurePathTopic) { - V2ServiceError modeledError(jsonObject); - s_applyModeledErrorToHandler(handler, std::move(modeledError)); - } else { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); - } -} - -bool ClientV2::UpdateNamedShadow(const UpdateNamedShadowRequest &request, const UpdateNamedShadowResultHandler &handler) { - Aws::Crt::StringStream publishTopicStream; - publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/update"; - Aws::Crt::String publishTopic = publishTopicStream.str(); - - Aws::Crt::StringStream subscriptionTopicStream0; - subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/update"; - Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); - - Aws::Crt::StringStream subscriptionTopicStream1; - subscriptionTopicStream1 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/update"; - Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); - - - struct aws_byte_cursor subscriptionTopicFilters[2] = { - Aws::Crt::ByteCursorFromString(subscriptionTopic0), - Aws::Crt::ByteCursorFromString(subscriptionTopic1), - }; - - Aws::Crt::StringStream responsePathTopicAcceptedStream; - responsePathTopicAcceptedStream << publishTopic << "/accepted"; - Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); - - Aws::Crt::StringStream responsePathTopicRejectedStream; - responsePathTopicRejectedStream << publishTopic << "/rejected"; - Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); - - struct aws_mqtt_request_operation_response_path responsePaths[2]; - responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); - responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); - responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - - Aws::Crt::JsonObject jsonObject; - request.SerializeToObject(jsonObject); - - auto uuid = Aws::Crt::UUID().ToString(); - jsonObject.WithString("clientToken", uuid); - - 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 = 2; - options.response_paths = responsePaths; - options.response_path_count = 2; - options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); - options.serialized_request = - Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); - - options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); - - auto resultHandler = - [handler, responsePathTopicAccepted, responsePathTopicRejected](Aws::Iot::RequestResponse::UnmodeledResult &&result) - { s_UpdateNamedShadowResponseHandler(std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); }; - - int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); - - return submitResult == AWS_OP_SUCCESS; -} - - -static void s_UpdateShadowResponseHandler(Aws::Iot::RequestResponse::UnmodeledResult &&result, const std::function &handler, const Aws::Crt::String &successPathTopic, const Aws::Crt::String &failurePathTopic) { - using E = V2ServiceError; - using R = Aws::Iot::RequestResponse::Result>; - - if (!result.IsSuccess()) { - s_applyUnmodeledErrorToHandler(handler, result.GetError()); - return; - } - - auto response = result.GetResponse(); - const auto &payload = response.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); - return; - } - - const auto &topic = response.GetTopic(); - auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); - if (responseTopic == successPathTopic) { - UpdateShadowResponse modeledResponse(jsonObject); - Aws::Iot::RequestResponse::Result> finalResult(std::move(modeledResponse)); - handler(std::move(finalResult)); - } else if (responseTopic == failurePathTopic) { - V2ServiceError modeledError(jsonObject); - s_applyModeledErrorToHandler(handler, std::move(modeledError)); - } else { - s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); - } -} - -bool ClientV2::UpdateShadow(const UpdateShadowRequest &request, const UpdateShadowResultHandler &handler) { - Aws::Crt::StringStream publishTopicStream; - publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/update"; - Aws::Crt::String publishTopic = publishTopicStream.str(); + static void s_DeleteNamedShadowResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const DeleteNamedShadowResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; - Aws::Crt::StringStream subscriptionTopicStream0; - subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/update"; - Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } - Aws::Crt::StringStream subscriptionTopicStream1; - subscriptionTopicStream1 << "$aws/things/" << *request.ThingName << "/shadow/update"; - Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + DeleteShadowResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } - struct aws_byte_cursor subscriptionTopicFilters[2] = { - Aws::Crt::ByteCursorFromString(subscriptionTopic0), - Aws::Crt::ByteCursorFromString(subscriptionTopic1), - }; + bool ClientV2::DeleteNamedShadow( + const DeleteNamedShadowRequest &request, + const DeleteNamedShadowResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/delete"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/delete/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; - Aws::Crt::StringStream responsePathTopicAcceptedStream; - responsePathTopicAcceptedStream << publishTopic << "/accepted"; - Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_DeleteNamedShadowResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; - Aws::Crt::StringStream responsePathTopicRejectedStream; - responsePathTopicRejectedStream << publishTopic << "/rejected"; - Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); - struct aws_mqtt_request_operation_response_path responsePaths[2]; - responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); - responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); - responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); - - Aws::Crt::JsonObject jsonObject; - request.SerializeToObject(jsonObject); + return submitResult == AWS_OP_SUCCESS; + } - auto uuid = Aws::Crt::UUID().ToString(); - jsonObject.WithString("clientToken", uuid); + static void s_DeleteShadowResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const DeleteShadowResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; - Aws::Crt::String outgoingJson = jsonObject.View().WriteCompact(true); + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } - struct aws_mqtt_request_operation_options options; - AWS_ZERO_STRUCT(options); - options.subscription_topic_filters = subscriptionTopicFilters; - options.subscription_topic_filter_count = 2; - options.response_paths = responsePaths; - options.response_path_count = 2; - options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); - options.serialized_request = - Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } - options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + DeleteShadowResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } - auto resultHandler = - [handler, responsePathTopicAccepted, responsePathTopicRejected](Aws::Iot::RequestResponse::UnmodeledResult &&result) - { s_UpdateShadowResponseHandler(std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); }; + bool ClientV2::DeleteShadow(const DeleteShadowRequest &request, const DeleteShadowResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/delete"; + Aws::Crt::String publishTopic = publishTopicStream.str(); - int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/delete/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); - return submitResult == AWS_OP_SUCCESS; -} + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_DeleteShadowResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); -template class ServiceStreamingOperation : public Aws::Iot::RequestResponse::IStreamingOperation { - public: + return submitResult == AWS_OP_SUCCESS; + } - explicit ShadowStreamingOperation(std::shared_ptr stream) : - m_stream(std::move(stream)) + static void s_GetNamedShadowResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const GetNamedShadowResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + GetShadowResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } } - static std::shared_ptr Create(Aws::Crt::Allocator *allocator, const std::shared_ptr &bindingClient, const Aws::Crt::String &subscriptionTopicFilter, const Aws::Iot::RequestResponse::StreamingOperationOptions &options) { + bool ClientV2::GetNamedShadow(const GetNamedShadowRequest &request, const GetNamedShadowResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/get"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/get/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + }; - std::function unmodeledHandler = [options](Aws::Iot::RequestResponse::IncomingPublishEvent &&event){ - const auto &payload = event.GetPayload(); - Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); - Aws::Crt::JsonObject jsonObject(objectStr); - if (!jsonObject.WasParseSuccessful()) { - return; - } + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_GetNamedShadowResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_GetShadowResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const GetShadowResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } + + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + GetShadowResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } + + bool ClientV2::GetShadow(const GetShadowRequest &request, const GetShadowResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/get"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/get/+"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); - T modeledEvent(jsonObject); - options.GetStreamHandler()(std::move(modeledEvent)); + struct aws_byte_cursor subscriptionTopicFilters[1] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), }; - Aws::Iot::RequestResponse::StreamingOperationOptionsInternal internalOptions; - internalOptions.subscriptionTopicFilter = Aws::Crt::ByteCursorFromString(subscriptionTopicFilter); - internalOptions.subscriptionStatusEventHandler = options.GetSubscriptionStatusEventHandler(); - internalOptions.incomingPublishEventHandler = unmodeledHandler; + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_GetShadowResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; - auto unmodeledStream = bindingClient->CreateStream(internalOptions); - if (!unmodeledStream) { - return nullptr; + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; + } + + static void s_UpdateNamedShadowResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const UpdateNamedShadowResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; + + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } + + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; } - return Aws::Crt::MakeShared(allocator, unmodeledStream); + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + UpdateShadowResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } } - void Open() override { - m_stream->Open(); + bool ClientV2::UpdateNamedShadow( + const UpdateNamedShadowRequest &request, + const UpdateNamedShadowResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update"; + Aws::Crt::String publishTopic = publishTopicStream.str(); + + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/accepted"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); + + Aws::Crt::StringStream subscriptionTopicStream1; + subscriptionTopicStream1 << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/rejected"; + Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); + + struct aws_byte_cursor subscriptionTopicFilters[2] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + Aws::Crt::ByteCursorFromString(subscriptionTopic1), + }; + + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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 = 2; + options.response_paths = responsePaths; + options.response_path_count = 2; + options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_UpdateNamedShadowResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; + + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + + return submitResult == AWS_OP_SUCCESS; } - private: + static void s_UpdateShadowResponseHandler( + Aws::Iot::RequestResponse::UnmodeledResult &&result, + const UpdateShadowResultHandler &handler, + const Aws::Crt::String &successPathTopic, + const Aws::Crt::String &failurePathTopic) + { + using E = V2ServiceError; + using R = Aws::Iot::RequestResponse::Result>; - std::shared_ptr m_stream; -}; + if (!result.IsSuccess()) + { + s_applyUnmodeledErrorToHandler(handler, result.GetError()); + return; + } -std::shared_ptr ClientV2::CreateNamedShadowDeltaUpdatedStream(const NamedShadowDeltaUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) { - Aws::Crt::StringStream topicStream; - topicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/update/delta"; - Aws::Crt::String topic = topicStream.str(); + auto response = result.GetResponse(); + const auto &payload = response.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_PAYLOAD_PARSE_ERROR); + return; + } - return ServiceStreamingOperation::Create(m_allocator, m_bindingClient, topic, options); -} + const auto &topic = response.GetTopic(); + auto responseTopic = Aws::Crt::String((const char *)topic.ptr, topic.len); + if (responseTopic == successPathTopic) + { + UpdateShadowResponse modeledResponse(jsonObject); + Aws::Iot::RequestResponse::Result> finalResult( + std::move(modeledResponse)); + handler(std::move(finalResult)); + } + else if (responseTopic == failurePathTopic) + { + V2ServiceError modeledError(jsonObject); + s_applyModeledErrorToHandler(handler, std::move(modeledError)); + } + else + { + s_applyUnmodeledErrorToHandler(handler, AWS_ERROR_MQTT_REQUEST_RESPONSE_INVALID_RESPONSE_PATH); + } + } -std::shared_ptr ClientV2::CreateNamedShadowUpdatedStream(const NamedShadowUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) { - Aws::Crt::StringStream topicStream; - topicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName << "/update/documents"; - Aws::Crt::String topic = topicStream.str(); + bool ClientV2::UpdateShadow(const UpdateShadowRequest &request, const UpdateShadowResultHandler &handler) + { + Aws::Crt::StringStream publishTopicStream; + publishTopicStream << "$aws/things/" << *request.ThingName << "/shadow/update"; + Aws::Crt::String publishTopic = publishTopicStream.str(); - return ServiceStreamingOperation::Create(m_allocator, m_bindingClient, topic, options); -} + Aws::Crt::StringStream subscriptionTopicStream0; + subscriptionTopicStream0 << "$aws/things/" << *request.ThingName << "/shadow/update/accepted"; + Aws::Crt::String subscriptionTopic0 = subscriptionTopicStream0.str(); -std::shared_ptr ClientV2::CreateShadowDeltaUpdatedStream(const ShadowDeltaUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) { - Aws::Crt::StringStream topicStream; - topicStream << "$aws/things/" << *request.ThingName << "/shadow/update/delta"; - Aws::Crt::String topic = topicStream.str(); + Aws::Crt::StringStream subscriptionTopicStream1; + subscriptionTopicStream1 << "$aws/things/" << *request.ThingName << "/shadow/update/rejected"; + Aws::Crt::String subscriptionTopic1 = subscriptionTopicStream1.str(); - return ServiceStreamingOperation::Create(m_allocator, m_bindingClient, topic, options); -} + struct aws_byte_cursor subscriptionTopicFilters[2] = { + Aws::Crt::ByteCursorFromString(subscriptionTopic0), + Aws::Crt::ByteCursorFromString(subscriptionTopic1), + }; -std::shared_ptr ClientV2::CreateShadowUpdatedStream(const ShadowUpdatedSubscriptionRequest &request, const const Aws::Iot::RequestResponse::StreamingOperationOptions &options) { - Aws::Crt::StringStream topicStream; - topicStream << "$aws/things/" << *request.ThingName << "/shadow/update/documents"; - Aws::Crt::String topic = topicStream.str(); + Aws::Crt::StringStream responsePathTopicAcceptedStream; + responsePathTopicAcceptedStream << publishTopic << "/accepted"; + Aws::Crt::String responsePathTopicAccepted = responsePathTopicAcceptedStream.str(); + + Aws::Crt::StringStream responsePathTopicRejectedStream; + responsePathTopicRejectedStream << publishTopic << "/rejected"; + Aws::Crt::String responsePathTopicRejected = responsePathTopicRejectedStream.str(); + + struct aws_mqtt_request_operation_response_path responsePaths[2]; + responsePaths[0].topic = Aws::Crt::ByteCursorFromString(responsePathTopicAccepted); + responsePaths[1].topic = Aws::Crt::ByteCursorFromString(responsePathTopicRejected); + responsePaths[0].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + responsePaths[1].correlation_token_json_path = Aws::Crt::ByteCursorFromCString("clientToken"); + + Aws::Crt::JsonObject jsonObject; + request.SerializeToObject(jsonObject); + + auto uuid = Aws::Crt::UUID().ToString(); + jsonObject.WithString("clientToken", uuid); + + 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 = 2; + options.response_paths = responsePaths; + options.response_path_count = 2; + options.publish_topic = Aws::Crt::ByteCursorFromString(publishTopic); + options.serialized_request = + Aws::Crt::ByteCursorFromArray((uint8_t *)outgoingJson.data(), outgoingJson.length()); + + options.correlation_token = Aws::Crt::ByteCursorFromString(uuid); + + auto resultHandler = [handler, responsePathTopicAccepted, responsePathTopicRejected]( + Aws::Iot::RequestResponse::UnmodeledResult &&result) + { + s_UpdateShadowResponseHandler( + std::move(result), handler, responsePathTopicAccepted, responsePathTopicRejected); + }; - return ServiceStreamingOperation::Create(m_allocator, m_bindingClient, topic, options); -} + int submitResult = m_bindingClient->SubmitRequest(options, std::move(resultHandler)); + return submitResult == AWS_OP_SUCCESS; + } + template class ServiceStreamingOperation : public Aws::Iot::RequestResponse::IStreamingOperation + { + public: + explicit ServiceStreamingOperation(std::shared_ptr stream) + : m_stream(std::move(stream)) + { + } -std::shared_ptr NewClientFrom5(const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, - const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, - Aws::Crt::Allocator *allocator) { + static std::shared_ptr Create( + Aws::Crt::Allocator *allocator, + const std::shared_ptr &bindingClient, + const Aws::Crt::String &subscriptionTopicFilter, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + + std::function unmodeledHandler = + [options](Aws::Iot::RequestResponse::IncomingPublishEvent &&event) + { + const auto &payload = event.GetPayload(); + Aws::Crt::String objectStr(reinterpret_cast(payload.ptr), payload.len); + Aws::Crt::JsonObject jsonObject(objectStr); + if (!jsonObject.WasParseSuccessful()) + { + return; + } + + T modeledEvent(jsonObject); + options.GetStreamHandler()(std::move(modeledEvent)); + }; + + Aws::Iot::RequestResponse::StreamingOperationOptionsInternal internalOptions; + internalOptions.subscriptionTopicFilter = Aws::Crt::ByteCursorFromString(subscriptionTopicFilter); + internalOptions.subscriptionStatusEventHandler = options.GetSubscriptionStatusEventHandler(); + internalOptions.incomingPublishEventHandler = unmodeledHandler; + + auto unmodeledStream = bindingClient->CreateStream(internalOptions); + if (!unmodeledStream) + { + return nullptr; + } + + return Aws::Crt::MakeShared>(allocator, unmodeledStream); + } + + void Open() override { m_stream->Open(); } + + private: + std::shared_ptr m_stream; + }; + + std::shared_ptr ClientV2::CreateNamedShadowDeltaUpdatedStream( + const NamedShadowDeltaUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + Aws::Crt::StringStream topicStream; + topicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/delta"; + Aws::Crt::String topic = topicStream.str(); + + return ServiceStreamingOperation::Create( + m_allocator, m_bindingClient, topic, options); + } + + std::shared_ptr ClientV2::CreateNamedShadowUpdatedStream( + const NamedShadowUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + Aws::Crt::StringStream topicStream; + topicStream << "$aws/things/" << *request.ThingName << "/shadow/name/" << *request.ShadowName + << "/update/documents"; + Aws::Crt::String topic = topicStream.str(); + + return ServiceStreamingOperation::Create(m_allocator, m_bindingClient, topic, options); + } + + std::shared_ptr ClientV2::CreateShadowDeltaUpdatedStream( + const ShadowDeltaUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + Aws::Crt::StringStream topicStream; + topicStream << "$aws/things/" << *request.ThingName << "/shadow/update/delta"; + Aws::Crt::String topic = topicStream.str(); - std::shared_ptr bindingClient = Aws::Iot::RequestResponse::NewClientFrom5(protocolClient, options, allocator); - if (nullptr == bindingClient) { - return nullptr; - } + return ServiceStreamingOperation::Create( + m_allocator, m_bindingClient, topic, options); + } + + std::shared_ptr ClientV2::CreateShadowUpdatedStream( + const ShadowUpdatedSubscriptionRequest &request, + const Aws::Iot::RequestResponse::StreamingOperationOptions &options) + { + Aws::Crt::StringStream topicStream; + topicStream << "$aws/things/" << *request.ThingName << "/shadow/update/documents"; + Aws::Crt::String topic = topicStream.str(); - return Aws::Crt::MakeShared(allocator, allocator, bindingClient); -} + return ServiceStreamingOperation::Create(m_allocator, m_bindingClient, topic, options); + } -std::shared_ptr NewClientFrom311(const Aws::Crt::Mqtt::MqttConnection &protocolClient, - const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, - Aws::Crt::Allocator *allocator) { + std::shared_ptr NewClientFrom5( + const Aws::Crt::Mqtt5::Mqtt5Client &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator) + { - std::shared_ptr bindingClient = Aws::Iot::RequestResponse::NewClientFrom311(protocolClient, options, allocator); - if (nullptr == bindingClient) { - return nullptr; - } + std::shared_ptr bindingClient = + Aws::Iot::RequestResponse::NewClientFrom5(protocolClient, options, allocator); + if (nullptr == bindingClient) + { + return nullptr; + } - return Aws::Crt::MakeShared(allocator, allocator, bindingClient); -} + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } + + std::shared_ptr NewClientFrom311( + const Aws::Crt::Mqtt::MqttConnection &protocolClient, + const Aws::Iot::RequestResponse::RequestResponseClientOptions &options, + Aws::Crt::Allocator *allocator) + { + + std::shared_ptr bindingClient = + Aws::Iot::RequestResponse::NewClientFrom311(protocolClient, options, allocator); + if (nullptr == bindingClient) + { + return nullptr; + } + + return Aws::Crt::MakeShared(allocator, allocator, bindingClient); + } -} -} + } // namespace Iotshadow +} // namespace Aws diff --git a/shadow/source/ShadowDeltaUpdatedEvent.cpp b/shadow/source/ShadowDeltaUpdatedEvent.cpp index 0585bfce5..fef4415f1 100644 --- a/shadow/source/ShadowDeltaUpdatedEvent.cpp +++ b/shadow/source/ShadowDeltaUpdatedEvent.cpp @@ -71,7 +71,10 @@ namespace Aws } } - ShadowDeltaUpdatedEvent::ShadowDeltaUpdatedEvent(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ShadowDeltaUpdatedEvent::ShadowDeltaUpdatedEvent(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ShadowDeltaUpdatedEvent &ShadowDeltaUpdatedEvent::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/ShadowMetadata.cpp b/shadow/source/ShadowMetadata.cpp index 31e3bba32..8909ec834 100644 --- a/shadow/source/ShadowMetadata.cpp +++ b/shadow/source/ShadowMetadata.cpp @@ -41,7 +41,10 @@ namespace Aws } } - ShadowMetadata::ShadowMetadata(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ShadowMetadata::ShadowMetadata(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ShadowMetadata &ShadowMetadata::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/ShadowState.cpp b/shadow/source/ShadowState.cpp index f32d829f9..e7c94ca1b 100644 --- a/shadow/source/ShadowState.cpp +++ b/shadow/source/ShadowState.cpp @@ -41,7 +41,10 @@ namespace Aws } } - ShadowState::ShadowState(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ShadowState::ShadowState(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ShadowState &ShadowState::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/ShadowStateWithDelta.cpp b/shadow/source/ShadowStateWithDelta.cpp index 42ec67a4d..df9c31f4f 100644 --- a/shadow/source/ShadowStateWithDelta.cpp +++ b/shadow/source/ShadowStateWithDelta.cpp @@ -51,7 +51,10 @@ namespace Aws } } - ShadowStateWithDelta::ShadowStateWithDelta(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ShadowStateWithDelta::ShadowStateWithDelta(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ShadowStateWithDelta &ShadowStateWithDelta::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/ShadowUpdatedEvent.cpp b/shadow/source/ShadowUpdatedEvent.cpp index 550674d7c..d8054c914 100644 --- a/shadow/source/ShadowUpdatedEvent.cpp +++ b/shadow/source/ShadowUpdatedEvent.cpp @@ -55,7 +55,10 @@ namespace Aws } } - ShadowUpdatedEvent::ShadowUpdatedEvent(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ShadowUpdatedEvent::ShadowUpdatedEvent(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ShadowUpdatedEvent &ShadowUpdatedEvent::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/ShadowUpdatedSnapshot.cpp b/shadow/source/ShadowUpdatedSnapshot.cpp index 493baa1f5..4c774e70a 100644 --- a/shadow/source/ShadowUpdatedSnapshot.cpp +++ b/shadow/source/ShadowUpdatedSnapshot.cpp @@ -55,7 +55,10 @@ namespace Aws } } - ShadowUpdatedSnapshot::ShadowUpdatedSnapshot(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + ShadowUpdatedSnapshot::ShadowUpdatedSnapshot(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } ShadowUpdatedSnapshot &ShadowUpdatedSnapshot::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/ShadowUpdatedSubscriptionRequest.cpp b/shadow/source/ShadowUpdatedSubscriptionRequest.cpp index d026f1037..4042363cb 100644 --- a/shadow/source/ShadowUpdatedSubscriptionRequest.cpp +++ b/shadow/source/ShadowUpdatedSubscriptionRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void ShadowUpdatedSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void ShadowUpdatedSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } ShadowUpdatedSubscriptionRequest::ShadowUpdatedSubscriptionRequest(const Crt::JsonView &doc) { diff --git a/shadow/source/UpdateNamedShadowRequest.cpp b/shadow/source/UpdateNamedShadowRequest.cpp index 81c2a005d..540420064 100644 --- a/shadow/source/UpdateNamedShadowRequest.cpp +++ b/shadow/source/UpdateNamedShadowRequest.cpp @@ -53,7 +53,10 @@ namespace Aws } } - UpdateNamedShadowRequest::UpdateNamedShadowRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + UpdateNamedShadowRequest::UpdateNamedShadowRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } UpdateNamedShadowRequest &UpdateNamedShadowRequest::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/UpdateShadowRequest.cpp b/shadow/source/UpdateShadowRequest.cpp index c1746bdc0..8230a0c50 100644 --- a/shadow/source/UpdateShadowRequest.cpp +++ b/shadow/source/UpdateShadowRequest.cpp @@ -53,7 +53,10 @@ namespace Aws } } - UpdateShadowRequest::UpdateShadowRequest(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + UpdateShadowRequest::UpdateShadowRequest(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } UpdateShadowRequest &UpdateShadowRequest::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/UpdateShadowResponse.cpp b/shadow/source/UpdateShadowResponse.cpp index cd0703f77..3df213d1f 100644 --- a/shadow/source/UpdateShadowResponse.cpp +++ b/shadow/source/UpdateShadowResponse.cpp @@ -75,7 +75,10 @@ namespace Aws } } - UpdateShadowResponse::UpdateShadowResponse(const Crt::JsonView &doc) { LoadFromObject(*this, doc); } + UpdateShadowResponse::UpdateShadowResponse(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } UpdateShadowResponse &UpdateShadowResponse::operator=(const Crt::JsonView &doc) { diff --git a/shadow/source/UpdateShadowSubscriptionRequest.cpp b/shadow/source/UpdateShadowSubscriptionRequest.cpp index 7c4cee2ac..a2af81d2a 100644 --- a/shadow/source/UpdateShadowSubscriptionRequest.cpp +++ b/shadow/source/UpdateShadowSubscriptionRequest.cpp @@ -18,7 +18,10 @@ namespace Aws (void)doc; } - void UpdateShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const { (void)object; } + void UpdateShadowSubscriptionRequest::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + } UpdateShadowSubscriptionRequest::UpdateShadowSubscriptionRequest(const Crt::JsonView &doc) { diff --git a/shadow/source/V2ServiceError.cpp b/shadow/source/V2ServiceError.cpp new file mode 100644 index 000000000..84d32553c --- /dev/null +++ b/shadow/source/V2ServiceError.cpp @@ -0,0 +1,76 @@ +/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + * + * This file is generated + */ +#include + +namespace Aws +{ + namespace Iotshadow + { + + void V2ServiceError::LoadFromObject(V2ServiceError &val, const Aws::Crt::JsonView &doc) + { + (void)val; + (void)doc; + + if (doc.ValueExists("clientToken")) + { + val.ClientToken = doc.GetString("clientToken"); + } + + if (doc.ValueExists("code")) + { + val.Code = doc.GetInteger("code"); + } + + if (doc.ValueExists("message")) + { + val.Message = doc.GetString("message"); + } + + if (doc.ValueExists("timestamp")) + { + val.Timestamp = doc.GetDouble("timestamp"); + } + } + + void V2ServiceError::SerializeToObject(Aws::Crt::JsonObject &object) const + { + (void)object; + + if (ClientToken) + { + object.WithString("clientToken", *ClientToken); + } + + if (Code) + { + object.WithInteger("code", *Code); + } + + if (Message) + { + object.WithString("message", *Message); + } + + if (Timestamp) + { + object.WithDouble("timestamp", Timestamp->SecondsWithMSPrecision()); + } + } + + V2ServiceError::V2ServiceError(const Crt::JsonView &doc) + { + LoadFromObject(*this, doc); + } + + V2ServiceError &V2ServiceError::operator=(const Crt::JsonView &doc) + { + *this = V2ServiceError(doc); + return *this; + } + + } // namespace Iotshadow +} // namespace Aws