Skip to content

Commit

Permalink
[eclipse-iceoryx#264] Add update_connection call to C++ API with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Sep 19, 2024
1 parent f0bf0ff commit d37104a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
8 changes: 7 additions & 1 deletion iceoryx2-ffi/cxx/include/iox2/publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ inline auto Publisher<S, Payload, UserHeader>::loan_slice_uninit(const uint64_t

template <ServiceType S, typename Payload, typename UserHeader>
inline auto Publisher<S, Payload, UserHeader>::update_connections() -> iox::expected<void, ConnectionFailure> {
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<ConnectionFailure>(result));
}

return iox::ok();
}
} // namespace iox2

Expand Down
9 changes: 8 additions & 1 deletion iceoryx2-ffi/cxx/include/iox2/subscriber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "iox2/service_type.hpp"
#include "iox2/subscriber_error.hpp"
#include "iox2/unique_port_id.hpp"
#include <cinttypes>

namespace iox2 {
/// The receiving endpoint of a publish-subscribe communication.
Expand Down Expand Up @@ -149,7 +150,13 @@ inline auto Subscriber<S, Payload, UserHeader>::receive() const

template <ServiceType S, typename Payload, typename UserHeader>
inline auto Subscriber<S, Payload, UserHeader>::update_connections() const -> iox::expected<void, ConnectionFailure> {
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<ConnectionFailure>(result));
}

return iox::ok();
}

} // namespace iox2
Expand Down
25 changes: 25 additions & 0 deletions iceoryx2-ffi/cxx/tests/src/service_publish_subscribe_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SERVICE_TYPE>().expect("");
auto service = node.service_builder(service_name).template publish_subscribe<uint64_t>().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;
Expand Down
8 changes: 4 additions & 4 deletions iceoryx2-ffi/ffi/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@ pub unsafe extern "C" fn iox2_publisher_loan(
///
/// # Arguments
///
/// * `subscriber_handle` - Must be a valid [`iox2_subscriber_ref_h`]
/// obtained by [`iox2_port_factory_subscriber_builder_create`](crate::iox2_port_factory_subscriber_builder_create) and
/// casted by [`iox2_cast_subscriber_ref_h`].
/// * `publisher_handle` - Must be a valid [`iox2_publisher_ref_h`]
/// obtained by [`iox2_port_factory_publisher_builder_create`](crate::iox2_port_factory_publisher_builder_create) and
/// casted by [`iox2_cast_publisher_ref_h`].
///
/// # Safety
///
/// * The `subscriber_handle` is still valid after the return of this function and can be use in another function call.
/// * The `publisher_handle` is still valid after the return of this function and can be use in another function call.
#[no_mangle]
pub unsafe extern "C" fn iox2_publisher_update_connections(
publisher_handle: iox2_publisher_ref_h,
Expand Down

0 comments on commit d37104a

Please sign in to comment.