Skip to content

Commit

Permalink
[eclipse-iceoryx#491] Document new C functions
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Nov 19, 2024
1 parent 0b0bebe commit f57bb27
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 19 deletions.
4 changes: 0 additions & 4 deletions iceoryx2-ffi/cxx/src/error_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,4 @@ auto error_string(const iox2::WaitSetRunError& error) -> const char* {
return iox2_waitset_run_error_string(iox::into<iox2_waitset_run_error_e>(error));
}

auto error_string(const iox2::WaitSetRunResult& error) -> const char* {
return iox2_waitset_run_result_string(iox::into<iox2_waitset_run_result_e>(error));
}

} // namespace iox2
8 changes: 0 additions & 8 deletions iceoryx2-ffi/cxx/tests/src/error_string_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,6 @@ TEST(ErrorStringTest, waitset_create_error_string) {
ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U);
}

TEST(ErrorStringTest, waitset_run_result_string) {
using Sut = iox2::WaitSetRunResult;
ASSERT_GT(strlen(error_string(Sut::TerminationRequest)), 1U);
ASSERT_GT(strlen(error_string(Sut::Interrupt)), 1U);
ASSERT_GT(strlen(error_string(Sut::StopRequest)), 1U);
ASSERT_GT(strlen(error_string(Sut::AllEventsHandled)), 1U);
}

TEST(ErrorStringTest, waitset_attachment_error_string) {
using Sut = iox2::WaitSetAttachmentError;
ASSERT_GT(strlen(error_string(Sut::InsufficientCapacity)), 1U);
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ impl HandleToType for iox2_config_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_config_creation_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_config_creation_error_string(
error: iox2_config_creation_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ pub type iox2_listener_wait_all_callback =

// BEGIN C API

/// Returns a string representation of the provided [`iox2_listener_wait_error_e`] error code.
///
/// # Arguments
///
/// * `error` - The error code that should be converted into a string
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// * The returned pointer must not be modified or freed and is only valid as long as the program runs
#[no_mangle]
pub unsafe extern "C" fn iox2_listener_wait_error_string(
error: iox2_listener_wait_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ trait AssertNonNullHandle {
fn assert_non_null(self);
}

/// Returns a string literal describing the provided [`iox2_semantic_string_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_semantic_string_error_string(
error: iox2_semantic_string_error_e,
Expand Down
25 changes: 25 additions & 0 deletions iceoryx2-ffi/ffi/src/api/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,38 @@ pub type iox2_node_list_callback = extern "C" fn(

// BEGIN C API

/// Returns a string representation of the [`iox2_node_list_failure_e`] error code.
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// Returns a pointer to a null-terminated string containing the error description.
///
/// # Safety
///
/// * The returned pointer is valid as long as the program runs and must not be modified or freed
#[no_mangle]
pub unsafe extern "C" fn iox2_node_list_failure_string(
error: iox2_node_list_failure_e,
) -> *const c_char {
error.as_str_literal().as_ptr() as *const c_char
}

/// Returns a string representation of the [`iox2_node_wait_failure_e`] error code.
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// * The returned pointer is valid as long as the program runs and must not be modified or freed
#[no_mangle]
pub unsafe extern "C" fn iox2_node_wait_failure_string(
error: iox2_node_wait_failure_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ impl HandleToType for iox2_node_builder_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_node_creation_failure_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_node_creation_failure_string(
error: iox2_node_creation_failure_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ impl HandleToType for iox2_notifier_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_notifier_notify_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_notifier_notify_error_string(
error: iox2_notifier_notify_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ impl HandleToType for iox2_port_factory_listener_builder_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_listener_create_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_listener_create_error_string(
error: iox2_listener_create_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ impl HandleToType for iox2_port_factory_notifier_builder_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_notifier_create_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_notifier_create_error_string(
error: iox2_notifier_create_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ impl HandleToType for iox2_port_factory_publisher_builder_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_publisher_create_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_publisher_create_error_string(
error: iox2_publisher_create_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ impl HandleToType for iox2_port_factory_subscriber_builder_h_ref {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_subscriber_create_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_subscriber_create_error_string(
error: iox2_subscriber_create_error_e,
Expand Down
28 changes: 28 additions & 0 deletions iceoryx2-ffi/ffi/src/api/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,41 @@ unsafe fn send_slice_copy<S: Service>(

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_publisher_send_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_publisher_send_error_string(
error: iox2_publisher_send_error_e,
) -> *const c_char {
error.as_str_literal().as_ptr() as *const c_char
}

/// Returns a string literal describing the provided [`iox2_publisher_loan_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_publisher_loan_error_string(
error: iox2_publisher_loan_error_e,
Expand Down
28 changes: 28 additions & 0 deletions iceoryx2-ffi/ffi/src/api/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,41 @@ pub type iox2_service_list_callback = extern "C" fn(

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_service_details_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_service_details_error_string(
error: iox2_service_details_error_e,
) -> *const c_char {
error.as_str_literal().as_ptr() as *const c_char
}

/// Returns a string literal describing the provided [`iox2_service_list_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_service_list_error_string(
error: iox2_service_list_error_e,
Expand Down
14 changes: 14 additions & 0 deletions iceoryx2-ffi/ffi/src/api/service_builder_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ impl IntoCInt for EventOpenOrCreateError {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_event_open_or_create_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_event_open_or_create_error_string(
error: iox2_event_open_or_create_error_e,
Expand Down
14 changes: 14 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 @@ -227,6 +227,20 @@ pub enum iox2_type_detail_error_e {

// BEGIN C API

/// Returns a string literal describing the provided [`iox2_pub_sub_open_or_create_error_e`].
///
/// # Arguments
///
/// * `error` - The error value for which a description should be returned
///
/// # Returns
///
/// A pointer to a null-terminated string containing the error message.
/// The string is stored in the .rodata section of the binary.
///
/// # Safety
///
/// The returned pointer must not be modified or freed and is valid as long as the program runs.
#[no_mangle]
pub unsafe extern "C" fn iox2_pub_sub_open_or_create_error_string(
error: iox2_pub_sub_open_or_create_error_e,
Expand Down
Loading

0 comments on commit f57bb27

Please sign in to comment.