From 11fb6c0936013d6c36e44cdef265548822034d59 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Wed, 29 Jan 2025 15:48:50 -0800 Subject: [PATCH 1/3] Add topic argument to publish callback in request-response stream client (#703) --- crt/aws-c-mqtt | 2 +- include/aws/iot/MqttRequestResponseClient.h | 28 +++++++++++++++++++-- source/iot/MqttRequestResponseClient.cpp | 12 ++++++--- tests/MqttRequestResponse.cpp | 21 ++++++++++++---- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index 627c3334e..9c093c403 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit 627c3334e52021aa8d5772b6ca076884610f3219 +Subproject commit 9c093c4039478c04c7e55a1825c391dd4742fd61 diff --git a/include/aws/iot/MqttRequestResponseClient.h b/include/aws/iot/MqttRequestResponseClient.h index 805db22c3..35123d6c6 100644 --- a/include/aws/iot/MqttRequestResponseClient.h +++ b/include/aws/iot/MqttRequestResponseClient.h @@ -121,12 +121,28 @@ namespace Aws /** * Default constructor */ - IncomingPublishEvent() : m_payload() { AWS_ZERO_STRUCT(m_payload); } + IncomingPublishEvent() : m_topic(), m_payload() + { + AWS_ZERO_STRUCT(m_topic); + AWS_ZERO_STRUCT(m_payload); + } + + /** + * Sets the message response topic associated with this event. The event does not own this topic. + * + * @param topic the message response topic associated with this event + * @return reference to this + */ + IncomingPublishEvent &WithTopic(Aws::Crt::ByteCursor topic) + { + m_topic = topic; + return *this; + } /** * Sets the message payload associated with this event. The event does not own this payload. * - * @param payload he message payload associated with this event + * @param payload the message payload associated with this event * @return reference to this */ IncomingPublishEvent &WithPayload(Aws::Crt::ByteCursor payload) @@ -135,6 +151,13 @@ namespace Aws return *this; } + /** + * Gets the message response topic associated with this event. + * + * @return the message response topic associated with this event + */ + Aws::Crt::ByteCursor GetTopic() const { return m_topic; } + /** * Gets the message payload associated with this event. * @@ -143,6 +166,7 @@ namespace Aws Aws::Crt::ByteCursor GetPayload() const { return m_payload; } private: + Aws::Crt::ByteCursor m_topic; Aws::Crt::ByteCursor m_payload; }; diff --git a/source/iot/MqttRequestResponseClient.cpp b/source/iot/MqttRequestResponseClient.cpp index 2bdcb960f..cb142797b 100644 --- a/source/iot/MqttRequestResponseClient.cpp +++ b/source/iot/MqttRequestResponseClient.cpp @@ -89,7 +89,10 @@ namespace Aws int error_code, void *user_data); - static void OnIncomingPublishCallback(struct aws_byte_cursor payload, void *user_data); + static void OnIncomingPublishCallback( + struct aws_byte_cursor payload, + struct aws_byte_cursor topic, + void *user_data); static void OnTerminatedCallback(void *user_data); @@ -187,7 +190,10 @@ namespace Aws } } - void StreamingOperationImpl::OnIncomingPublishCallback(struct aws_byte_cursor payload, void *user_data) + void StreamingOperationImpl::OnIncomingPublishCallback( + struct aws_byte_cursor payload, + struct aws_byte_cursor topic, + void *user_data) { auto *handle = static_cast(user_data); StreamingOperationImpl *impl = handle->m_impl.get(); @@ -198,7 +204,7 @@ namespace Aws if (!impl->m_closed && impl->m_config.incomingPublishEventHandler) { IncomingPublishEvent event; - event.WithPayload(payload); + event.WithTopic(topic).WithPayload(payload); impl->m_config.incomingPublishEventHandler(std::move(event)); } diff --git a/tests/MqttRequestResponse.cpp b/tests/MqttRequestResponse.cpp index f701d208d..0658713be 100644 --- a/tests/MqttRequestResponse.cpp +++ b/tests/MqttRequestResponse.cpp @@ -40,6 +40,12 @@ struct ResponseTracker bool complete; }; +struct TestPublishEvent +{ + Aws::Crt::String topic; + Aws::Crt::String payload; +}; + struct TestState { TestState(Aws::Crt::Allocator *allocator) : allocator(allocator) {} @@ -54,7 +60,7 @@ struct TestState Aws::Crt::Vector> responseTrackers; Aws::Crt::Vector subscriptionStatusEvents; - Aws::Crt::Vector incomingPublishEvents; + Aws::Crt::Vector incomingPublishEvents; }; static void s_waitForConnected(struct TestState *state) @@ -168,17 +174,20 @@ static void s_onIncomingPublishEvent(Aws::Iot::RequestResponse::IncomingPublishE { std::unique_lock lock(state->lock); + auto topicCursor = event.GetTopic(); + Aws::Crt::String topicAsString((const char *)topicCursor.ptr, topicCursor.len); + auto payloadCursor = event.GetPayload(); Aws::Crt::String payloadAsString((const char *)payloadCursor.ptr, payloadCursor.len); - state->incomingPublishEvents.push_back(payloadAsString); + state->incomingPublishEvents.push_back({std::move(topicAsString), std::move(payloadAsString)}); } state->signal.notify_one(); } static void s_waitForIncomingPublishWithPredicate( TestState *state, - const std::function &predicate) + const std::function &predicate) { { std::unique_lock lock(state->lock); @@ -189,7 +198,7 @@ static void s_waitForIncomingPublishWithPredicate( return std::any_of( state->incomingPublishEvents.cbegin(), state->incomingPublishEvents.cend(), - [=](const Aws::Crt::String &payload) { return predicate(payload); }); + [=](const TestPublishEvent &publishEvent) { return predicate(publishEvent); }); }); } } @@ -1077,7 +1086,9 @@ static int s_doShadowUpdatedStreamIncomingPublishTest(Aws::Crt::Allocator *alloc s_publishToProtocolClient(context, uuid, s_publishPayload, allocator); s_waitForIncomingPublishWithPredicate( - &state, [](const Aws::Crt::String &payload) { return payload == Aws::Crt::String(s_publishPayload); }); + &state, + [&uuid](const TestPublishEvent &publishEvent) + { return publishEvent.topic == uuid && publishEvent.payload == Aws::Crt::String(s_publishPayload); }); return AWS_OP_SUCCESS; } From ca3a2a65418f8c568189f5316a317ded27319364 Mon Sep 17 00:00:00 2001 From: Igor Abdrakhimov Date: Thu, 30 Jan 2025 10:32:12 -0800 Subject: [PATCH 2/3] Cmake modules (#702) --- CMakeLists.txt | 63 ++++++++++--------------------- bin/elasticurl_cpp/CMakeLists.txt | 4 +- bin/mqtt5_app/CMakeLists.txt | 4 +- bin/mqtt5_canary/CMakeLists.txt | 4 +- crt/aws-c-auth | 2 +- crt/aws-c-cal | 2 +- crt/aws-c-common | 2 +- crt/aws-c-compression | 2 +- crt/aws-c-event-stream | 2 +- crt/aws-c-http | 2 +- crt/aws-c-io | 2 +- crt/aws-c-mqtt | 2 +- crt/aws-c-s3 | 2 +- crt/aws-c-sdkutils | 2 +- crt/aws-checksums | 2 +- 15 files changed, 33 insertions(+), 64 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4127d0714..b0409fc9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,4 @@ -cmake_minimum_required(VERSION 3.9) - -if(POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif() +cmake_minimum_required(VERSION 3.9...3.31) option(BUILD_DEPS "Builds aws common runtime dependencies as part of build. Turn off if you want to control your dependency chain." ON) option(BYO_CRYPTO "Don't build a tls implementation or link against a crypto interface. This feature is only for unix builds currently" OFF) @@ -30,24 +26,7 @@ project("aws-crt-cpp" VERSION ${SIMPLE_VERSION}) include(CTest) - -if(DEFINED CMAKE_PREFIX_PATH) - file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH) -endif() - -if(DEFINED CMAKE_INSTALL_PREFIX) - file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX) -endif() - -if(UNIX AND NOT APPLE) - include(GNUInstallDirs) -elseif(NOT DEFINED CMAKE_INSTALL_LIBDIR) - set(CMAKE_INSTALL_LIBDIR "lib") -endif() - -if(${CMAKE_INSTALL_LIBDIR} STREQUAL "lib64") - set(FIND_LIBRARY_USE_LIB64_PATHS true) -endif() +include(GNUInstallDirs) if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 11) @@ -65,13 +44,6 @@ set(GENERATED_INCLUDE_DIR "${GENERATED_ROOT_DIR}/include") set(GENERATED_CONFIG_HEADER "${GENERATED_INCLUDE_DIR}/aws/crt/Config.h") configure_file(include/aws/crt/Config.h.in ${GENERATED_CONFIG_HEADER} @ONLY) -# This is required in order to append /lib/cmake to each element in CMAKE_PREFIX_PATH -set(AWS_MODULE_DIR "/${CMAKE_INSTALL_LIBDIR}/cmake") -string(REPLACE ";" "${AWS_MODULE_DIR};" AWS_MODULE_PATH "${CMAKE_PREFIX_PATH}${AWS_MODULE_DIR}") - -# Append that generated list to the module search path -list(APPEND CMAKE_MODULE_PATH ${AWS_MODULE_PATH}) - if(BUILD_DEPS) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/crt/aws-c-common/cmake") @@ -132,6 +104,9 @@ if(BUILD_DEPS) add_subdirectory(crt/aws-c-s3) set(BUILD_TESTING ${BUILD_TESTING_PREV}) else() + # this is required so we can use aws-c-common's CMake modules + find_package(aws-c-common REQUIRED) + include(AwsFindPackage) set(IN_SOURCE_BUILD OFF) endif() @@ -356,23 +331,23 @@ aws_add_sanitizers(${PROJECT_NAME}) target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_AWS_LIBS}) -install(FILES ${AWS_CRT_HEADERS} DESTINATION "include/aws/crt" COMPONENT Development) -install(FILES ${AWS_CRT_AUTH_HEADERS} DESTINATION "include/aws/crt/auth" COMPONENT Development) -install(FILES ${AWS_CRT_CHECKSUM_HEADERS} DESTINATION "include/aws/crt/checksum" COMPONENT Development) -install(FILES ${AWS_CRT_CRYPTO_HEADERS} DESTINATION "include/aws/crt/crypto" COMPONENT Development) -install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "include/aws/crt/io" COMPONENT Development) -install(FILES ${AWS_CRT_IOT_HEADERS} DESTINATION "include/aws/iot" COMPONENT Development) -install(FILES ${AWS_CRT_MQTT_HEADERS} DESTINATION "include/aws/crt/mqtt" COMPONENT Development) -install(FILES ${AWS_CRT_HTTP_HEADERS} DESTINATION "include/aws/crt/http" COMPONENT Development) -install(FILES ${AWS_CRT_ENDPOINT_HEADERS} DESTINATION "include/aws/crt/endpoints" COMPONENT Development) -install(FILES ${AWS_CRT_CBOR_HEADERS} DESTINATION "include/aws/crt/cbor" COMPONENT Development) +install(FILES ${AWS_CRT_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt" COMPONENT Development) +install(FILES ${AWS_CRT_AUTH_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/auth" COMPONENT Development) +install(FILES ${AWS_CRT_CHECKSUM_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/checksum" COMPONENT Development) +install(FILES ${AWS_CRT_CRYPTO_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/crypto" COMPONENT Development) +install(FILES ${AWS_CRT_IO_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/io" COMPONENT Development) +install(FILES ${AWS_CRT_IOT_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/iot" COMPONENT Development) +install(FILES ${AWS_CRT_MQTT_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/mqtt" COMPONENT Development) +install(FILES ${AWS_CRT_HTTP_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/http" COMPONENT Development) +install(FILES ${AWS_CRT_ENDPOINT_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/endpoints" COMPONENT Development) +install(FILES ${AWS_CRT_CBOR_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/aws/crt/cbor" COMPONENT Development) install( TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development - RUNTIME DESTINATION bin COMPONENT Runtime + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime ) if(BUILD_SHARED_LIBS) @@ -382,7 +357,7 @@ else() endif() install(EXPORT "${PROJECT_NAME}-targets" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/${TARGET_DIR}" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/${TARGET_DIR}" NAMESPACE AWS:: COMPONENT Development) @@ -398,11 +373,11 @@ write_basic_package_version_file( ) install(FILES "${GENERATED_ROOT_DIR}/${PROJECT_NAME}-config.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" COMPONENT Development) install(FILES "${GENERATED_ROOT_DIR}/${PROJECT_NAME}-config-version.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/cmake/" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" COMPONENT Development) if(NOT CMAKE_CROSSCOMPILING) diff --git a/bin/elasticurl_cpp/CMakeLists.txt b/bin/elasticurl_cpp/CMakeLists.txt index 36185c15c..a96f94e8b 100644 --- a/bin/elasticurl_cpp/CMakeLists.txt +++ b/bin/elasticurl_cpp/CMakeLists.txt @@ -1,7 +1,5 @@ project(elasticurl_cpp CXX) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/lib/cmake") - file(GLOB ELASTICURL_CPP_SRC "*.cpp" ) @@ -43,5 +41,5 @@ install(TARGETS ${ELASTICURL_CPP_PROJECT_NAME} EXPORT ${ELASTICURL_CPP_PROJECT_NAME}-targets COMPONENT Runtime RUNTIME - DESTINATION bin + DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime) diff --git a/bin/mqtt5_app/CMakeLists.txt b/bin/mqtt5_app/CMakeLists.txt index e4637d6d1..931e07e7c 100644 --- a/bin/mqtt5_app/CMakeLists.txt +++ b/bin/mqtt5_app/CMakeLists.txt @@ -1,7 +1,5 @@ project(mqtt5_app CXX) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/lib/cmake") - file(GLOB MQTT5_APP_SRC "*.cpp" ) @@ -43,5 +41,5 @@ install(TARGETS ${MQTT5_APP_PROJECT_NAME} EXPORT ${MQTT5_APP_PROJECT_NAME}-targets COMPONENT Runtime RUNTIME - DESTINATION bin + DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime) diff --git a/bin/mqtt5_canary/CMakeLists.txt b/bin/mqtt5_canary/CMakeLists.txt index 87c594cc5..4426053d4 100644 --- a/bin/mqtt5_canary/CMakeLists.txt +++ b/bin/mqtt5_canary/CMakeLists.txt @@ -1,7 +1,5 @@ project(mqtt5_canary CXX) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/lib/cmake") - file(GLOB MQTT5_CANARY_SRC "*.cpp" ) @@ -43,5 +41,5 @@ install(TARGETS ${MQTT5_CANARY_PROJECT_NAME} EXPORT ${MQTT5_CANARY_PROJECT_NAME}-targets COMPONENT Runtime RUNTIME - DESTINATION bin + DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime) diff --git a/crt/aws-c-auth b/crt/aws-c-auth index 8927de4dc..b513db4bf 160000 --- a/crt/aws-c-auth +++ b/crt/aws-c-auth @@ -1 +1 @@ -Subproject commit 8927de4dcff6faab948e801aeeca3ac9a57caab7 +Subproject commit b513db4bf82429a1134fecbd6d12e5fda45255a6 diff --git a/crt/aws-c-cal b/crt/aws-c-cal index fbbe2612a..7299c6ab9 160000 --- a/crt/aws-c-cal +++ b/crt/aws-c-cal @@ -1 +1 @@ -Subproject commit fbbe2612a3385d1ded02a52d20ad7fd2da4501f4 +Subproject commit 7299c6ab9244595b140d604475cdd6c6921be8ae diff --git a/crt/aws-c-common b/crt/aws-c-common index 5e6c08186..0e7637fa8 160000 --- a/crt/aws-c-common +++ b/crt/aws-c-common @@ -1 +1 @@ -Subproject commit 5e6c08186fa5d8c7679acf95b86ada4119ca23b8 +Subproject commit 0e7637fa852a472bd4c37fc07a325a09c942a5fc diff --git a/crt/aws-c-compression b/crt/aws-c-compression index c6c1191e5..f951ab2b8 160000 --- a/crt/aws-c-compression +++ b/crt/aws-c-compression @@ -1 +1 @@ -Subproject commit c6c1191e525e5aa6ead9e1afc392e35d3b50331e +Subproject commit f951ab2b819fc6993b6e5e6cfef64b1a1554bfc8 diff --git a/crt/aws-c-event-stream b/crt/aws-c-event-stream index d2dcc9344..9422ef78a 160000 --- a/crt/aws-c-event-stream +++ b/crt/aws-c-event-stream @@ -1 +1 @@ -Subproject commit d2dcc9344dae24de320866045d85166d8a91a0d1 +Subproject commit 9422ef78aac566414d1bebb1a5431a4c53a7547c diff --git a/crt/aws-c-http b/crt/aws-c-http index fc3eded24..590c7b597 160000 --- a/crt/aws-c-http +++ b/crt/aws-c-http @@ -1 +1 @@ -Subproject commit fc3eded2465c37d07fd9cc15e9b5b011224c9c9a +Subproject commit 590c7b597f87e5edc080b8b77418690c30319832 diff --git a/crt/aws-c-io b/crt/aws-c-io index fcb38c804..3041dabfc 160000 --- a/crt/aws-c-io +++ b/crt/aws-c-io @@ -1 +1 @@ -Subproject commit fcb38c804364dd627c335da752a99a125a88f6e9 +Subproject commit 3041dabfc13fe9bc9a0467e15aa1d5a09c7fc06f diff --git a/crt/aws-c-mqtt b/crt/aws-c-mqtt index 9c093c403..83247bde8 160000 --- a/crt/aws-c-mqtt +++ b/crt/aws-c-mqtt @@ -1 +1 @@ -Subproject commit 9c093c4039478c04c7e55a1825c391dd4742fd61 +Subproject commit 83247bde8268905018327891fcf0147f3e438a80 diff --git a/crt/aws-c-s3 b/crt/aws-c-s3 index aef075b7d..6eb8be530 160000 --- a/crt/aws-c-s3 +++ b/crt/aws-c-s3 @@ -1 +1 @@ -Subproject commit aef075b7db620cd32fbe1ec19a819c1b0acd2e79 +Subproject commit 6eb8be530b100fed5c6d24ca48a57ee2e6098fbf diff --git a/crt/aws-c-sdkutils b/crt/aws-c-sdkutils index 1ae8664f9..ba6a28fab 160000 --- a/crt/aws-c-sdkutils +++ b/crt/aws-c-sdkutils @@ -1 +1 @@ -Subproject commit 1ae8664f90cb5ab5e23b161a31e021c6d3a28e72 +Subproject commit ba6a28fab7ed5d7f1b3b1d12eb672088be093824 diff --git a/crt/aws-checksums b/crt/aws-checksums index 3e4101b9f..fb8bd0b8c 160000 --- a/crt/aws-checksums +++ b/crt/aws-checksums @@ -1 +1 @@ -Subproject commit 3e4101b9f85a2c090774d27ae2131fca1082f522 +Subproject commit fb8bd0b8cff00c8c24a35d601fce1b4c611df6da From 89078a6ebd79a1dd124faddf53855a843c6f1bf4 Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Thu, 30 Jan 2025 10:57:43 -0800 Subject: [PATCH 3/3] AutoTag PR for v0.30.0 (#704) Co-authored-by: GitHub Actions --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0fca64ce4..c25c8e5b7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.29.9 +0.30.0