From a7467dc15d2404b7da32db8d1199ea1bc4b1910a Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Thu, 19 Sep 2024 17:49:51 +0200 Subject: [PATCH] [#264] Add update_connection call to C++ API with tests --- iceoryx2-ffi/cxx/include/iox2/publisher.hpp | 8 +++++- iceoryx2-ffi/cxx/include/iox2/subscriber.hpp | 9 ++++++- .../src/service_publish_subscribe_tests.cpp | 25 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/iceoryx2-ffi/cxx/include/iox2/publisher.hpp b/iceoryx2-ffi/cxx/include/iox2/publisher.hpp index a915b8a44..b4e0c10bd 100644 --- a/iceoryx2-ffi/cxx/include/iox2/publisher.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/publisher.hpp @@ -202,7 +202,13 @@ inline auto Publisher::loan_slice_uninit(const uint64_t template inline auto Publisher::update_connections() -> iox::expected { - IOX_TODO(); + auto* ref_handle = iox2_cast_publisher_ref_h(m_handle); + auto result = iox2_publisher_update_connections(ref_handle); + if (result != IOX2_OK) { + return iox::err(iox::into(result)); + } + + return iox::ok(); } } // namespace iox2 diff --git a/iceoryx2-ffi/cxx/include/iox2/subscriber.hpp b/iceoryx2-ffi/cxx/include/iox2/subscriber.hpp index e937081f4..bb723b566 100644 --- a/iceoryx2-ffi/cxx/include/iox2/subscriber.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/subscriber.hpp @@ -23,6 +23,7 @@ #include "iox2/service_type.hpp" #include "iox2/subscriber_error.hpp" #include "iox2/unique_port_id.hpp" +#include namespace iox2 { /// The receiving endpoint of a publish-subscribe communication. @@ -149,7 +150,13 @@ inline auto Subscriber::receive() const template inline auto Subscriber::update_connections() const -> iox::expected { - IOX_TODO(); + auto* ref_handle = iox2_cast_subscriber_ref_h(m_handle); + auto result = iox2_subscriber_update_connections(ref_handle); + if (result != IOX2_OK) { + return iox::err(iox::into(result)); + } + + return iox::ok(); } } // namespace iox2 diff --git a/iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp b/iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp index 8c29b6bcc..46e1b59fa 100644 --- a/iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp +++ b/iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp @@ -230,6 +230,31 @@ TYPED_TEST(ServicePublishSubscribeTest, loan_send_receive_works) { ASSERT_THAT(**recv_sample, Eq(payload)); } +TYPED_TEST(ServicePublishSubscribeTest, update_connections_delivers_history) { + constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE; + + const auto* name_value = "Whoop here it is - the publishers historyyyy!"; + const auto service_name = ServiceName::create(name_value).expect(""); + + auto node = NodeBuilder().create().expect(""); + auto service = node.service_builder(service_name).template publish_subscribe().create().expect(""); + + auto sut_publisher = service.publisher_builder().create().expect(""); + const uint64_t payload = 123; + sut_publisher.send_copy(payload).expect(""); + + auto sut_subscriber = service.subscriber_builder().create().expect(""); + auto sample = sut_subscriber.receive().expect(""); + + ASSERT_FALSE(sample.has_value()); + + ASSERT_TRUE(sut_publisher.update_connections().has_value()); + sample = sut_subscriber.receive().expect(""); + + ASSERT_TRUE(sample.has_value()); + ASSERT_THAT(**sample, Eq(payload)); +} + TYPED_TEST(ServicePublishSubscribeTest, setting_service_properties_works) { constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE; constexpr uint64_t NUMBER_OF_NODES = 10;