Skip to content

Commit

Permalink
[eclipse-iceoryx#210] Better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Sep 27, 2024
1 parent bf19ee1 commit 3870c48
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions iceoryx2-ffi/cxx/src/node_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
namespace iox2 {
auto NodeNameView::to_string() const -> iox::string<IOX2_NODE_NAME_LENGTH> {
size_t len = 0;
const auto* c_ptr = iox2_node_name_as_str(m_ptr, &len);
return { iox::TruncateToCapacity, c_ptr, len };
const auto* chars = iox2_node_name_as_chars(m_ptr, &len);
return { iox::TruncateToCapacity, chars, len };
}

auto NodeNameView::to_owned() const -> NodeName {
size_t len = 0;
const auto* c_ptr = iox2_node_name_as_str(m_ptr, &len);
return NodeName::create_impl(c_ptr, len).expect("NodeNameView contains always valid NodeName");
const auto* chars = iox2_node_name_as_chars(m_ptr, &len);
return NodeName::create_impl(chars, len).expect("NodeNameView contains always valid NodeName");
}

NodeNameView::NodeNameView(iox2_node_name_ptr ptr)
Expand Down Expand Up @@ -68,8 +68,8 @@ auto NodeName::operator=(const NodeName& rhs) -> NodeName& {

const auto* ptr = iox2_cast_node_name_ptr(rhs.m_handle);
size_t len = 0;
const auto* c_ptr = iox2_node_name_as_str(ptr, &len);
IOX_ASSERT(iox2_node_name_new(nullptr, c_ptr, len, &m_handle) == IOX2_OK,
const auto* chars = iox2_node_name_as_chars(ptr, &len);
IOX_ASSERT(iox2_node_name_new(nullptr, chars, len, &m_handle) == IOX2_OK,
"NodeName shall always contain a valid value.");
}

Expand Down
12 changes: 6 additions & 6 deletions iceoryx2-ffi/cxx/src/service_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
namespace iox2 {
auto ServiceNameView::to_string() const -> iox::string<IOX2_NODE_NAME_LENGTH> {
size_t len = 0;
const auto* c_ptr = iox2_service_name_as_str(m_ptr, &len);
return { iox::TruncateToCapacity, c_ptr, len };
const auto* chars = iox2_service_name_as_chars(m_ptr, &len);
return { iox::TruncateToCapacity, chars, len };
}

auto ServiceNameView::to_owned() const -> ServiceName {
size_t len = 0;
const auto* c_ptr = iox2_service_name_as_str(m_ptr, &len);
return ServiceName::create_impl(c_ptr, len).expect("ServiceNameView always contains valid ServiceName");
const auto* chars = iox2_service_name_as_chars(m_ptr, &len);
return ServiceName::create_impl(chars, len).expect("ServiceNameView always contains valid ServiceName");
}

ServiceNameView::ServiceNameView(iox2_service_name_ptr ptr)
Expand Down Expand Up @@ -67,8 +67,8 @@ auto ServiceName::operator=(const ServiceName& rhs) -> ServiceName& {

const auto* ptr = iox2_cast_service_name_ptr(rhs.m_handle);
size_t len = 0;
const auto* c_ptr = iox2_service_name_as_str(ptr, &len);
IOX_ASSERT(iox2_service_name_new(nullptr, c_ptr, len, &m_handle) == IOX2_OK,
const auto* chars = iox2_service_name_as_chars(ptr, &len);
IOX_ASSERT(iox2_service_name_new(nullptr, chars, len, &m_handle) == IOX2_OK,
"ServiceName shall always contain a valid value.");
}

Expand Down
8 changes: 4 additions & 4 deletions iceoryx2-ffi/ffi/src/api/node_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ pub unsafe extern "C" fn iox2_cast_node_name_ptr(
(*node_name_handle.as_type()).value.as_ref()
}

/// This function gives access to the node name as a non-zero-terminated char string
/// This function gives access to the node name as a non-zero-terminated char array
///
/// # Arguments
///
/// * `node_name_ptr` obtained by e.g. [`iox2_cast_node_name_ptr`] or a function returning a [`iox2_node_name_ptr`]
/// * `node_name_len` must be used to get the length of the char string
/// * `node_name_len` must be used to get the length of the char array
///
/// Returns a non-zero-terminated char string
/// Returns a non-zero-terminated char array
///
/// # Safety
///
/// * The `node_name_ptr` must be a valid pointer to a node name.
/// * The `node_name_len` must be a valid pointer to a size_t.
#[no_mangle]
pub unsafe extern "C" fn iox2_node_name_as_str(
pub unsafe extern "C" fn iox2_node_name_as_chars(
node_name_ptr: iox2_node_name_ptr,
node_name_len: *mut c_size_t,
) -> *const c_char {
Expand Down
8 changes: 4 additions & 4 deletions iceoryx2-ffi/ffi/src/api/service_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ pub unsafe extern "C" fn iox2_cast_service_name_ptr(
(*service_name_handle.as_type()).value.as_ref()
}

/// This function gives access to the node name as a non-zero-terminated char string
/// This function gives access to the node name as a non-zero-terminated char array
///
/// # Arguments
///
/// * `service_name_ptr` obtained by e.g. [`iox2_cast_service_name_ptr`] or a function returning a [`iox2_service_name_ptr`]
/// * `service_name_len` must be used to get the length of the char string
/// * `service_name_len` must be used to get the length of the char array
///
/// Returns non-zero-terminated char string
/// Returns non-zero-terminated char array
///
/// # Safety
///
/// * The `service_name_ptr` must be a valid pointer to a node name.
/// * The `service_name_len` must be a valid pointer to a size_t.
#[no_mangle]
pub unsafe extern "C" fn iox2_service_name_as_str(
pub unsafe extern "C" fn iox2_service_name_as_chars(
service_name_ptr: iox2_service_name_ptr,
service_name_len: *mut c_size_t,
) -> *const c_char {
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-ffi/ffi/src/tests/node_name_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ fn basic_node_name_test() -> Result<(), Box<dyn std::error::Error>> {
assert_that!(ret_val, eq(IOX2_OK));

let mut node_name_len = 0;
let node_name_c_ptr = iox2_node_name_as_str(
let node_name_chars = iox2_node_name_as_chars(
iox2_cast_node_name_ptr(node_name_handle),
&mut node_name_len,
);

let slice = slice::from_raw_parts(node_name_c_ptr as *const _, node_name_len as _);
let slice = slice::from_raw_parts(node_name_chars as *const _, node_name_len as _);
let node_name = str::from_utf8(slice)?;

assert_that!(node_name, eq(expected_node_name.as_str()));
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-ffi/ffi/src/tests/node_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ mod node {
let node_name = iox2_node_name(iox2_cast_node_ref_h(node_handle));

let mut node_name_len = 0;
let node_name_c_ptr = iox2_node_name_as_str(node_name, &mut node_name_len);
let node_name_chars = iox2_node_name_as_chars(node_name, &mut node_name_len);

let slice = slice::from_raw_parts(node_name_c_ptr as *const _, node_name_len as _);
let slice = slice::from_raw_parts(node_name_chars as *const _, node_name_len as _);
let node_name_str = str::from_utf8(slice)?;

assert_that!(node_name_str, eq("hypnotoad"));
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2-ffi/ffi/src/tests/service_name_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ fn basic_service_name_test() -> Result<(), Box<dyn std::error::Error>> {
assert_that!(ret_val, eq(IOX2_OK));

let mut service_name_len = 0;
let service_name_c_ptr = iox2_service_name_as_str(
let service_name_chars = iox2_service_name_as_chars(
iox2_cast_service_name_ptr(service_name_handle),
&mut service_name_len,
);

let slice = slice::from_raw_parts(service_name_c_ptr as *const _, service_name_len as _);
let slice = slice::from_raw_parts(service_name_chars as *const _, service_name_len as _);
let service_name = str::from_utf8(slice)?;

assert_that!(service_name, eq(expected_service_name.as_str()));
Expand Down

0 comments on commit 3870c48

Please sign in to comment.