Skip to content

Commit

Permalink
Merge pull request #382 from elBoberido/iox2-264-extend-service-build…
Browse files Browse the repository at this point in the history
…er-pub-sub-parameters

[#264] Extend service builder pub sub parameter
  • Loading branch information
elBoberido authored Sep 18, 2024
2 parents 4b2f409 + 0b37e7a commit 104a197
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ inline void ServiceBuilderPublishSubscribe<Payload, UserHeader, S>::set_paramete
m_payload_alignment.and_then([](auto) { IOX_TODO(); });
m_enable_safe_overflow.and_then(
[&](auto value) { iox2_service_builder_pub_sub_set_enable_safe_overflow(ref_handle, value); });
m_subscriber_max_borrowed_samples.and_then([](auto) { IOX_TODO(); });
m_history_size.and_then([](auto) { IOX_TODO(); });
m_subscriber_max_buffer_size.and_then([](auto) { IOX_TODO(); });
m_subscriber_max_borrowed_samples.and_then(
[&](auto value) { iox2_service_builder_pub_sub_set_subscriber_max_borrowed_samples(ref_handle, value); });
m_history_size.and_then([&](auto value) { iox2_service_builder_pub_sub_set_history_size(ref_handle, value); });
m_subscriber_max_buffer_size.and_then(
[&](auto value) { iox2_service_builder_pub_sub_set_subscriber_max_buffer_size(ref_handle, value); });
m_max_subscribers.and_then(
[&](auto value) { iox2_service_builder_pub_sub_set_max_subscribers(ref_handle, value); });
m_max_publishers.and_then([&](auto value) { iox2_service_builder_pub_sub_set_max_publishers(ref_handle, value); });
m_max_nodes.and_then([](auto) { IOX_TODO(); });
m_max_nodes.and_then([&](auto value) { iox2_service_builder_pub_sub_set_max_nodes(ref_handle, value); });

// payload type details
const auto* payload_type_name = typeid(Payload).name();
Expand Down
12 changes: 12 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 @@ -232,24 +232,36 @@ TYPED_TEST(ServicePublishSubscribeTest, loan_send_receive_works) {

TYPED_TEST(ServicePublishSubscribeTest, setting_service_properties_works) {
constexpr ServiceType SERVICE_TYPE = TestFixture::TYPE;
constexpr uint64_t NUMBER_OF_NODES = 10;
constexpr uint64_t NUMBER_OF_PUBLISHERS = 11;
constexpr uint64_t NUMBER_OF_SUBSCRIBERS = 12;
constexpr uint64_t HISTORY_SIZE = 13;
constexpr uint64_t SUBSCRIBER_MAX_BUFFER_SIZE = 14;
constexpr uint64_t SUBSCRIBER_MAX_BORROWED_SAMPLES = 15;

const auto* name_value = "I am floating through the galaxy of my brain. Oh the colors!";
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>()
.max_nodes(NUMBER_OF_NODES)
.max_publishers(NUMBER_OF_PUBLISHERS)
.max_subscribers(NUMBER_OF_SUBSCRIBERS)
.history_size(HISTORY_SIZE)
.subscriber_max_buffer_size(SUBSCRIBER_MAX_BUFFER_SIZE)
.subscriber_max_borrowed_samples(SUBSCRIBER_MAX_BORROWED_SAMPLES)
.create()
.expect("");

auto static_config = service.static_config();

ASSERT_THAT(static_config.max_nodes(), Eq(NUMBER_OF_NODES));
ASSERT_THAT(static_config.max_publishers(), Eq(NUMBER_OF_PUBLISHERS));
ASSERT_THAT(static_config.max_subscribers(), Eq(NUMBER_OF_SUBSCRIBERS));
ASSERT_THAT(static_config.history_size(), Eq(HISTORY_SIZE));
ASSERT_THAT(static_config.subscriber_max_buffer_size(), Eq(SUBSCRIBER_MAX_BUFFER_SIZE));
ASSERT_THAT(static_config.subscriber_max_borrowed_samples(), Eq(SUBSCRIBER_MAX_BORROWED_SAMPLES));
ASSERT_THAT(static_config.message_type_details().payload().size(), Eq(sizeof(uint64_t)));
ASSERT_THAT(static_config.message_type_details().payload().alignment(), Eq(alignof(uint64_t)));
ASSERT_THAT(static_config.message_type_details().payload().type_name(), StrEq(typeid(uint64_t).name()));
Expand Down
172 changes: 172 additions & 0 deletions iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,49 @@ pub unsafe extern "C" fn iox2_service_builder_pub_sub_set_payload_type_details(
IOX2_OK
}

/// Sets the max nodes for the builder
///
/// # Arguments
///
/// * `service_builder_handle` - Must be a valid [`iox2_service_builder_pub_sub_ref_h`]
/// obtained by [`iox2_service_builder_pub_sub`](crate::iox2_service_builder_pub_sub) and
/// casted by [`iox2_cast_service_builder_pub_sub_ref_h`](crate::iox2_cast_service_builder_pub_sub_ref_h).
/// * `value` - The value to set the max nodes to
///
/// # Safety
///
/// * `service_builder_handle` must be valid handles
#[no_mangle]
pub unsafe extern "C" fn iox2_service_builder_pub_sub_set_max_nodes(
service_builder_handle: iox2_service_builder_pub_sub_ref_h,
value: c_size_t,
) {
debug_assert!(!service_builder_handle.is_null());

let service_builder_struct = unsafe { &mut *service_builder_handle.as_type() };

match service_builder_struct.service_type {
iox2_service_type_e::IPC => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_pub_sub(
service_builder.max_nodes(value),
));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_local_pub_sub(
service_builder.max_nodes(value),
));
}
}
}

/// Sets the max publishers for the builder
///
/// # Arguments
Expand Down Expand Up @@ -442,6 +485,135 @@ pub unsafe extern "C" fn iox2_service_builder_pub_sub_set_max_subscribers(
}
}

/// Sets the history size
///
/// # Arguments
///
/// * `service_builder_handle` - Must be a valid [`iox2_service_builder_pub_sub_ref_h`]
/// obtained by [`iox2_service_builder_pub_sub`](crate::iox2_service_builder_pub_sub) and
/// casted by [`iox2_cast_service_builder_pub_sub_ref_h`](crate::iox2_cast_service_builder_pub_sub_ref_h).
/// * `value` - The value to set the history size to
///
/// # Safety
///
/// * `service_builder_handle` must be valid handles
#[no_mangle]
pub unsafe extern "C" fn iox2_service_builder_pub_sub_set_history_size(
service_builder_handle: iox2_service_builder_pub_sub_ref_h,
value: c_size_t,
) {
debug_assert!(!service_builder_handle.is_null());

let service_builder_struct = unsafe { &mut *service_builder_handle.as_type() };

match service_builder_struct.service_type {
iox2_service_type_e::IPC => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_pub_sub(
service_builder.history_size(value),
));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_local_pub_sub(
service_builder.history_size(value),
));
}
}
}

/// Sets the subscriber max buffer size
///
/// # Arguments
///
/// * `service_builder_handle` - Must be a valid [`iox2_service_builder_pub_sub_ref_h`]
/// obtained by [`iox2_service_builder_pub_sub`](crate::iox2_service_builder_pub_sub) and
/// casted by [`iox2_cast_service_builder_pub_sub_ref_h`](crate::iox2_cast_service_builder_pub_sub_ref_h).
/// * `value` - The value to set the subscriber max buffer size to
///
/// # Safety
///
/// * `service_builder_handle` must be valid handles
#[no_mangle]
pub unsafe extern "C" fn iox2_service_builder_pub_sub_set_subscriber_max_buffer_size(
service_builder_handle: iox2_service_builder_pub_sub_ref_h,
value: c_size_t,
) {
debug_assert!(!service_builder_handle.is_null());

let service_builder_struct = unsafe { &mut *service_builder_handle.as_type() };

match service_builder_struct.service_type {
iox2_service_type_e::IPC => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_pub_sub(
service_builder.subscriber_max_buffer_size(value),
));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_local_pub_sub(
service_builder.subscriber_max_buffer_size(value),
));
}
}
}

/// Sets the subscriber max borrowed samples
///
/// # Arguments
///
/// * `service_builder_handle` - Must be a valid [`iox2_service_builder_pub_sub_ref_h`]
/// obtained by [`iox2_service_builder_pub_sub`](crate::iox2_service_builder_pub_sub) and
/// casted by [`iox2_cast_service_builder_pub_sub_ref_h`](crate::iox2_cast_service_builder_pub_sub_ref_h).
/// * `value` - The value to set the subscriber max borrowed samples to
///
/// # Safety
///
/// * `service_builder_handle` must be valid handles
#[no_mangle]
pub unsafe extern "C" fn iox2_service_builder_pub_sub_set_subscriber_max_borrowed_samples(
service_builder_handle: iox2_service_builder_pub_sub_ref_h,
value: c_size_t,
) {
debug_assert!(!service_builder_handle.is_null());

let service_builder_struct = unsafe { &mut *service_builder_handle.as_type() };

match service_builder_struct.service_type {
iox2_service_type_e::IPC => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().ipc);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_ipc_pub_sub(
service_builder.subscriber_max_borrowed_samples(value),
));
}
iox2_service_type_e::LOCAL => {
let service_builder =
ManuallyDrop::take(&mut service_builder_struct.value.as_mut().local);

let service_builder = ManuallyDrop::into_inner(service_builder.pub_sub);
service_builder_struct.set(ServiceBuilderUnion::new_local_pub_sub(
service_builder.subscriber_max_borrowed_samples(value),
));
}
}
}

/// Enables/disables safe overflow for the service
///
/// # Arguments
Expand Down

0 comments on commit 104a197

Please sign in to comment.