Skip to content

Commit

Permalink
[eclipse-iceoryx#264] Add config setter to node
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Sep 13, 2024
1 parent 4f795f8 commit e5e74a4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace iox2 {
class Config;
class NodeBuilder;

namespace config {
class Global;
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion iceoryx2-ffi/cxx/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ auto NodeBuilder::create() const&& -> iox::expected<Node<T>, 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 {};
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-ffi/ffi/src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config>,
pub(crate) value: ManuallyDrop<Config>,
}

/// A storage object that has the size to store a config
Expand All @@ -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),
}

Expand Down
24 changes: 20 additions & 4 deletions iceoryx2-ffi/ffi/src/api/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e5e74a4

Please sign in to comment.