Skip to content

Commit

Permalink
WIP: Propagate errors from iceoryx2
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Oct 25, 2024
1 parent 42835d7 commit 9438add
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
13 changes: 13 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ constexpr auto from<int, iox2::SemanticStringError>(const int value) noexcept ->
IOX_UNREACHABLE();
}

template <>
constexpr auto from<iox2::SemanticStringError, iox2_semantic_string_error_e>(
const iox2::SemanticStringError value) noexcept -> iox2_semantic_string_error_e {
switch (value) {
case iox2::SemanticStringError::InvalidContent:
return iox2_semantic_string_error_e_INVALID_CONTENT;
case iox2::SemanticStringError::ExceedsMaximumLength:
return iox2_semantic_string_error_e_EXCEEDS_MAXIMUM_LENGTH;
}

IOX_UNREACHABLE();
}

template <>
constexpr auto from<int, iox2::ServiceType>(const int value) noexcept -> iox2::ServiceType {
const auto service_type = static_cast<iox2_service_type_e>(value);
Expand Down
4 changes: 4 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ enum class SemanticStringError : uint8_t {
/// @brief The added content would exceed the maximum capacity of the [`SemanticString`]
ExceedsMaximumLength
};


auto error_string(const iox2::SemanticStringError& error) -> const char*;

} // namespace iox2

#endif
5 changes: 5 additions & 0 deletions iceoryx2-ffi/cxx/src/error_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "iox2/node_wait_failure.hpp"
#include "iox2/notifier_error.hpp"
#include "iox2/publisher_error.hpp"
#include "iox2/semantic_string.hpp"
#include "iox2/service_builder_event_error.hpp"
#include "iox2/service_builder_publish_subscribe_error.hpp"
#include "iox2/service_error_enums.hpp"
Expand Down Expand Up @@ -94,6 +95,10 @@ auto error_string(const iox2::PublishSubscribeOpenOrCreateError& error) -> const
return iox2_pub_sub_open_or_create_error_string(iox::into<iox2_pub_sub_open_or_create_error_e>(error));
}

auto error_string(const iox2::SemanticStringError& error) -> const char* {
return iox2_semantic_string_error_string(iox::into<iox2_semantic_string_error_e>(error));
}

auto error_string(const iox2::EventOpenError& error) -> const char* {
return iox2_event_open_or_create_error_string(iox::into<iox2_event_open_or_create_error_e>(error));
}
Expand Down
13 changes: 11 additions & 2 deletions iceoryx2-ffi/ffi/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

use iceoryx2::prelude::*;
use iceoryx2_bb_container::semantic_string::SemanticStringError;
use iceoryx2_bb_derive_macros::StaticStringRepresentation;
use iceoryx2_bb_elementary::AsStaticString;

use core::ffi::{c_int, c_void};
use core::ffi::{c_char, c_int, c_void};

mod config;
mod event_id;
Expand Down Expand Up @@ -119,7 +121,7 @@ impl From<iox2_callback_progression_e> for CallbackProgression {
}

#[repr(C)]
#[derive(Copy, Clone)]
#[derive(Copy, Clone, StaticStringRepresentation)]
pub enum iox2_semantic_string_error_e {
INVALID_CONTENT = IOX2_OK as isize + 1,
EXCEEDS_MAXIMUM_LENGTH,
Expand Down Expand Up @@ -186,3 +188,10 @@ trait HandleToType {
trait AssertNonNullHandle {
fn assert_non_null(self);
}

#[no_mangle]
pub unsafe extern "C" fn iox2_semantic_string_error_string(
error: iox2_semantic_string_error_e,
) -> *const c_char {
error.as_static_str().as_ptr() as *const c_char
}

0 comments on commit 9438add

Please sign in to comment.