Skip to content

Commit

Permalink
[#390] Add native_handle to FileDescriptorView
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Nov 25, 2024
1 parent b2db0fd commit ec87872
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/file_descriptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class FileDescriptorView : public FileDescriptorBased {
/// Returns a [`FileDescriptorView`] to the underlying [`FileDescriptor`].
auto file_descriptor() const -> FileDescriptorView override;

/// Returns the underlying [`FileDescriptor`] value.
auto native_handle() const -> int32_t;

iox2_file_descriptor_ptr m_handle = nullptr;
};

Expand Down
6 changes: 5 additions & 1 deletion iceoryx2-ffi/cxx/src/file_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ auto FileDescriptorView::file_descriptor() const -> FileDescriptorView {
return *this;
}

auto FileDescriptorView::native_handle() const -> int32_t {
return iox2_file_descriptor_native_handle(m_handle);
}

auto FileDescriptor::create_owning(int32_t file_descriptor) -> iox::optional<FileDescriptor> {
iox2_file_descriptor_h handle = nullptr;
if (iox2_file_descriptor_new(file_descriptor, true, nullptr, &handle)) {
Expand Down Expand Up @@ -69,7 +73,7 @@ void FileDescriptor::drop() {
}

auto FileDescriptor::native_handle() const -> int32_t {
return iox2_file_descriptor_native_handle(&m_handle);
return iox2_file_descriptor_native_handle(iox2_cast_file_descriptor_ptr(m_handle));
}

auto FileDescriptor::as_view() const -> FileDescriptorView {
Expand Down
11 changes: 3 additions & 8 deletions iceoryx2-ffi/ffi/src/api/file_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,10 @@ pub unsafe extern "C" fn iox2_file_descriptor_drop(handle: iox2_file_descriptor_
/// * `handle` must be valid and acquired with [`iox2_file_descriptor_new()`].
#[no_mangle]
pub unsafe extern "C" fn iox2_file_descriptor_native_handle(
handle: iox2_file_descriptor_h_ref,
handle: iox2_file_descriptor_ptr,
) -> i32 {
handle.assert_non_null();

(*handle.as_type())
.value
.as_ref()
.file_descriptor()
.native_handle()
debug_assert!(!handle.is_null());
(*handle).file_descriptor().native_handle()
}

/// Creates a new [`iox2_file_descriptor_t`].
Expand Down

0 comments on commit ec87872

Please sign in to comment.