From e5e74a4f3dc0d7c61a81f9ccf3748340f9dbf63a Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Tue, 10 Sep 2024 14:55:09 +0200 Subject: [PATCH] [#264] Add config setter to node --- iceoryx2-ffi/cxx/include/iox2/config.hpp | 2 ++ iceoryx2-ffi/cxx/src/node.cpp | 3 ++- iceoryx2-ffi/ffi/src/api/config.rs | 4 ++-- iceoryx2-ffi/ffi/src/api/node_builder.rs | 24 ++++++++++++++++++++---- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/iceoryx2-ffi/cxx/include/iox2/config.hpp b/iceoryx2-ffi/cxx/include/iox2/config.hpp index 8e7729abb..b16a00c86 100644 --- a/iceoryx2-ffi/cxx/include/iox2/config.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/config.hpp @@ -22,6 +22,7 @@ namespace iox2 { class Config; +class NodeBuilder; namespace config { class Global; @@ -289,6 +290,7 @@ class Config { private: friend class ConfigView; friend class config::Global; + friend class NodeBuilder; explicit Config(iox2_config_h handle); void drop(); diff --git a/iceoryx2-ffi/cxx/src/node.cpp b/iceoryx2-ffi/cxx/src/node.cpp index 1d619eb68..30f181170 100644 --- a/iceoryx2-ffi/cxx/src/node.cpp +++ b/iceoryx2-ffi/cxx/src/node.cpp @@ -137,7 +137,8 @@ auto NodeBuilder::create() const&& -> iox::expected, NodeCreationFailure } if (m_config.has_value()) { - IOX_TODO(); + auto* config_handle_ref = iox2_cast_config_ref_h(m_config.value().m_handle); + iox2_node_builder_set_config(handle_ref, config_handle_ref); } iox2_node_h node_handle {}; diff --git a/iceoryx2-ffi/ffi/src/api/config.rs b/iceoryx2-ffi/ffi/src/api/config.rs index 522303661..0faa66c8f 100644 --- a/iceoryx2-ffi/ffi/src/api/config.rs +++ b/iceoryx2-ffi/ffi/src/api/config.rs @@ -67,7 +67,7 @@ pub type iox2_config_ptr = *const Config; pub type iox2_config_mut_ptr = *mut Config; pub(super) struct ConfigOwner { - value: ManuallyDrop, + pub(crate) value: ManuallyDrop, } /// A storage object that has the size to store a config @@ -81,7 +81,7 @@ pub struct iox2_config_storage_t { #[repr(C)] #[iceoryx2_ffi(ConfigOwner)] pub struct iox2_config_t { - value: iox2_config_storage_t, + pub(crate) value: iox2_config_storage_t, deleter: fn(*mut iox2_config_t), } diff --git a/iceoryx2-ffi/ffi/src/api/node_builder.rs b/iceoryx2-ffi/ffi/src/api/node_builder.rs index 71e297a9b..e00fd186e 100644 --- a/iceoryx2-ffi/ffi/src/api/node_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/node_builder.rs @@ -16,6 +16,7 @@ use crate::api::{ iox2_node_h, iox2_node_name_ptr, iox2_node_t, iox2_service_type_e, HandleToType, IntoCInt, NodeUnion, IOX2_OK, }; +use crate::iox2_config_ref_h; use iceoryx2::node::NodeCreationFailure; use iceoryx2::prelude::*; @@ -169,14 +170,29 @@ pub unsafe extern "C" fn iox2_node_builder_set_name( IOX2_OK } +/// Sets the node config for the builder +/// +/// Returns IOX2_OK +/// +/// # Safety +/// +/// * `node_builder_handle` - Must be a valid [`iox2_node_builder_ref_h`] obtained by [`iox2_node_builder_new`] and casted by [`iox2_cast_node_builder_ref_h`]. +/// * `config_handle` - Must be a valid [`iox2_config_ref_h`] +/// #[no_mangle] -pub extern "C" fn iox2_node_builder_set_config( +pub unsafe extern "C" fn iox2_node_builder_set_config( node_builder_handle: iox2_node_builder_ref_h, -) -> c_int { + config_handle: iox2_config_ref_h, +) { debug_assert!(!node_builder_handle.is_null()); - todo!() // TODO: [#210] implement + debug_assert!(!config_handle.is_null()); + + let node_builder_struct = &mut *node_builder_handle.as_type(); + let config = &*config_handle.as_type(); - // IOX2_OK + let node_builder = node_builder_struct.take().unwrap(); + let node_builder = node_builder.config(&*config.value.as_ref().value); + node_builder_struct.set(node_builder); } // intentionally not public API