diff --git a/Cargo.lock b/Cargo.lock index 3e5da2f0c..d590b4b45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -758,6 +758,7 @@ dependencies = [ "generic-tests", "iceoryx2", "iceoryx2-bb-container", + "iceoryx2-bb-derive-macros", "iceoryx2-bb-elementary", "iceoryx2-bb-log", "iceoryx2-bb-posix", diff --git a/iceoryx2-bb/derive-macros/src/lib.rs b/iceoryx2-bb/derive-macros/src/lib.rs index 1b338048c..1fd348dfd 100644 --- a/iceoryx2-bb/derive-macros/src/lib.rs +++ b/iceoryx2-bb/derive-macros/src/lib.rs @@ -16,7 +16,7 @@ extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, Data, DeriveInput, Fields}; +use syn::{parse_macro_input, Data, DeriveInput, Expr, ExprLit, Fields, Lit}; /// Implements the [`iceoryx2_bb_elementary::placement_default::PlacementDefault`] trait when all /// fields of the struct implement it. @@ -99,3 +99,95 @@ pub fn placement_default_derive(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } + +#[proc_macro_derive(StaticStringRepresentation, attributes(StaticString))] +pub fn as_static_string_derive(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let name = &input.ident; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + + let static_string_impl = match input.data { + Data::Enum(ref data_enum) => { + let match_arms = data_enum.variants.iter().map(|variant| { + let variant_ident = &variant.ident; + + // Get the StaticString attribute if it exists + let static_string = variant + .attrs + .iter() + .find_map(|attr| { + if !attr.path().is_ident("StaticString") { + return None; + } + + match attr.meta.require_name_value() { + Ok(meta) => { + if let Expr::Lit(ExprLit { + lit: Lit::Str(lit), .. + }) = &meta.value + { + Some(lit.value()) + } else { + None + } + } + _ => None, + } + }) + .unwrap_or_else(|| { + let variant_str = variant_ident.to_string(); + variant_str + .chars() + .enumerate() + .map(|(_, c)| { + if c == '_' { + ' ' + } else { + c.to_ascii_lowercase() + } + }) + .collect::() + }); + + match &variant.fields { + Fields::Unit => { + quote! { + Self::#variant_ident => concat!(#static_string, "\0") + } + } + Fields::Unnamed(_) => { + quote! { + Self::#variant_ident(..) => concat!(#static_string, "\0") + } + } + Fields::Named(_) => { + quote! { + Self::#variant_ident{..} => concat!(#static_string, "\0") + } + } + } + }); + + quote! { + fn as_static_str(&self) -> &'static str { + match self { + #(#match_arms,)* + } + } + } + } + _ => { + let err = + syn::Error::new_spanned(&input, "AsStaticString can only be derived for enums"); + return err.to_compile_error().into(); + } + }; + + let expanded = quote! { + impl #impl_generics AsStaticString for #name #ty_generics #where_clause { + #static_string_impl + } + }; + + TokenStream::from(expanded) +} diff --git a/iceoryx2-bb/elementary/src/as_static_string.rs b/iceoryx2-bb/elementary/src/as_static_string.rs new file mode 100644 index 000000000..9e7cfd545 --- /dev/null +++ b/iceoryx2-bb/elementary/src/as_static_string.rs @@ -0,0 +1,15 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +pub trait AsStaticString { + fn as_static_str(&self) -> &'static str; +} diff --git a/iceoryx2-bb/elementary/src/lib.rs b/iceoryx2-bb/elementary/src/lib.rs index 3b1bfb0df..87931e1ec 100644 --- a/iceoryx2-bb/elementary/src/lib.rs +++ b/iceoryx2-bb/elementary/src/lib.rs @@ -15,9 +15,12 @@ #[macro_use] pub mod enum_gen; -/// A strong type that represents the alignment part of [`std::alloc::Layout`] +mod as_static_string; +pub use as_static_string::*; + pub mod alignment; pub mod allocator; +/// A strong type that represents the alignment part of [`std::alloc::Layout`] pub mod bump_allocator; pub mod lazy_singleton; pub mod math; diff --git a/iceoryx2-ffi/cxx/CMakeLists.txt b/iceoryx2-ffi/cxx/CMakeLists.txt index 20d2b114c..386a7b830 100644 --- a/iceoryx2-ffi/cxx/CMakeLists.txt +++ b/iceoryx2-ffi/cxx/CMakeLists.txt @@ -37,6 +37,7 @@ target_include_directories(includes-only-cxx add_library(iceoryx2-cxx-object-lib OBJECT src/config.cpp + src/error_string.cpp src/event_id.cpp src/file_descriptor.cpp src/header_publish_subscribe.cpp diff --git a/iceoryx2-ffi/cxx/include/iox2/config_creation_error.hpp b/iceoryx2-ffi/cxx/include/iox2/config_creation_error.hpp index a25e4029e..62fbef861 100644 --- a/iceoryx2-ffi/cxx/include/iox2/config_creation_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/config_creation_error.hpp @@ -25,6 +25,9 @@ enum class ConfigCreationError : uint8_t { /// Parts of the config file could not be deserialized. Indicates some kind of syntax error. UnableToDeserializeContents }; + +auto error_string(const iox2::ConfigCreationError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/connection_failure.hpp b/iceoryx2-ffi/cxx/include/iox2/connection_failure.hpp index 297e2b5a1..1f967a1a7 100644 --- a/iceoryx2-ffi/cxx/include/iox2/connection_failure.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/connection_failure.hpp @@ -25,6 +25,10 @@ enum class ConnectionFailure : uint8_t { /// Failures when mapping the corresponding data segment UnableToMapPublishersDataSegment }; + + +auto error_string(const iox2::ConnectionFailure& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp b/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp index 22b3c6397..6e186fd46 100644 --- a/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp @@ -50,6 +50,19 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + 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(const int value) noexcept -> iox2::ServiceType { const auto service_type = static_cast(value); @@ -89,6 +102,19 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::NodeCreationFailure value) noexcept -> iox2_node_creation_failure_e { + switch (value) { + case iox2::NodeCreationFailure::InsufficientPermissions: + return iox2_node_creation_failure_e_INSUFFICIENT_PERMISSIONS; + case iox2::NodeCreationFailure::InternalError: + return iox2_node_creation_failure_e_INTERNAL_ERROR; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::CallbackProgression { const auto error = static_cast(value); @@ -130,6 +156,21 @@ constexpr auto from(const int value) noexcept -> iox IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::NodeListFailure value) noexcept + -> iox2_node_list_failure_e { + switch (value) { + case iox2::NodeListFailure::InsufficientPermissions: + return iox2_node_list_failure_e_INSUFFICIENT_PERMISSIONS; + case iox2::NodeListFailure::InternalError: + return iox2_node_list_failure_e_INTERNAL_ERROR; + case iox2::NodeListFailure::Interrupt: + return iox2_node_list_failure_e_INTERRUPT; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::NodeWaitFailure { const auto error = static_cast(value); @@ -143,6 +184,19 @@ constexpr auto from(const int value) noexcept -> iox IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::NodeWaitFailure value) noexcept + -> iox2_node_wait_failure_e { + switch (value) { + case iox2::NodeWaitFailure::TerminationRequest: + return iox2_node_wait_failure_e_TERMINATION_REQUEST; + case iox2::NodeWaitFailure::Interrupt: + return iox2_node_wait_failure_e_INTERRUPT; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const iox2::MessagingPattern value) noexcept -> iox2_messaging_pattern_e { @@ -179,6 +233,29 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::ServiceDetailsError value) noexcept -> iox2_service_details_error_e { + switch (value) { + case iox2::ServiceDetailsError::FailedToOpenStaticServiceInfo: + return iox2_service_details_error_e_FAILED_TO_OPEN_STATIC_SERVICE_INFO; + case iox2::ServiceDetailsError::FailedToReadStaticServiceInfo: + return iox2_service_details_error_e_FAILED_TO_READ_STATIC_SERVICE_INFO; + case iox2::ServiceDetailsError::FailedToAcquireNodeState: + return iox2_service_details_error_e_FAILED_TO_ACQUIRE_NODE_STATE; + case iox2::ServiceDetailsError::FailedToDeserializeStaticServiceInfo: + return iox2_service_details_error_e_FAILED_TO_DESERIALIZE_STATIC_SERVICE_INFO; + case iox2::ServiceDetailsError::InternalError: + return iox2_service_details_error_e_INTERNAL_ERROR; + case iox2::ServiceDetailsError::ServiceInInconsistentState: + return iox2_service_details_error_e_SERVICE_IN_INCONSISTENT_STATE; + case iox2::ServiceDetailsError::VersionMismatch: + return iox2_service_details_error_e_VERSION_MISMATCH; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::EventOpenOrCreateError { const auto error = static_cast(value); @@ -222,13 +299,59 @@ constexpr auto from(const int value) noexcept return iox2::EventOpenOrCreateError::CreateHangsInCreation; case iox2_event_open_or_create_error_e_C_INSUFFICIENT_PERMISSIONS: return iox2::EventOpenOrCreateError::CreateInsufficientPermissions; - case iox2_event_open_or_create_error_e_C_OLD_CONNECTION_STILL_ACTIVE: - return iox2::EventOpenOrCreateError::CreateOldConnectionsStillActive; } IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::EventOpenOrCreateError value) noexcept -> iox2_event_open_or_create_error_e { + switch (value) { + case iox2::EventOpenOrCreateError::OpenDoesNotExist: + return iox2_event_open_or_create_error_e_O_DOES_NOT_EXIST; + case iox2::EventOpenOrCreateError::OpenInsufficientPermissions: + return iox2_event_open_or_create_error_e_O_INSUFFICIENT_PERMISSIONS; + case iox2::EventOpenOrCreateError::OpenServiceInCorruptedState: + return iox2_event_open_or_create_error_e_O_SERVICE_IN_CORRUPTED_STATE; + case iox2::EventOpenOrCreateError::OpenIncompatibleMessagingPattern: + return iox2_event_open_or_create_error_e_O_INCOMPATIBLE_MESSAGING_PATTERN; + case iox2::EventOpenOrCreateError::OpenIncompatibleAttributes: + return iox2_event_open_or_create_error_e_O_INCOMPATIBLE_ATTRIBUTES; + case iox2::EventOpenOrCreateError::OpenInternalFailure: + return iox2_event_open_or_create_error_e_O_INTERNAL_FAILURE; + case iox2::EventOpenOrCreateError::OpenHangsInCreation: + return iox2_event_open_or_create_error_e_O_HANGS_IN_CREATION; + case iox2::EventOpenOrCreateError::OpenDoesNotSupportRequestedAmountOfNotifiers: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NOTIFIERS; + case iox2::EventOpenOrCreateError::OpenDoesNotSupportRequestedAmountOfListeners: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_LISTENERS; + case iox2::EventOpenOrCreateError::OpenDoesNotSupportRequestedMaxEventId: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MAX_EVENT_ID; + case iox2::EventOpenOrCreateError::OpenDoesNotSupportRequestedAmountOfNodes: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES; + case iox2::EventOpenOrCreateError::OpenExceedsMaxNumberOfNodes: + return iox2_event_open_or_create_error_e_O_EXCEEDS_MAX_NUMBER_OF_NODES; + case iox2::EventOpenOrCreateError::OpenIsMarkedForDestruction: + return iox2_event_open_or_create_error_e_O_IS_MARKED_FOR_DESTRUCTION; + + case iox2::EventOpenOrCreateError::CreateServiceInCorruptedState: + return iox2_event_open_or_create_error_e_C_SERVICE_IN_CORRUPTED_STATE; + case iox2::EventOpenOrCreateError::CreateInternalFailure: + return iox2_event_open_or_create_error_e_C_INTERNAL_FAILURE; + case iox2::EventOpenOrCreateError::CreateIsBeingCreatedByAnotherInstance: + return iox2_event_open_or_create_error_e_C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE; + case iox2::EventOpenOrCreateError::CreateAlreadyExists: + return iox2_event_open_or_create_error_e_C_ALREADY_EXISTS; + case iox2::EventOpenOrCreateError::CreateHangsInCreation: + return iox2_event_open_or_create_error_e_C_HANGS_IN_CREATION; + case iox2::EventOpenOrCreateError::CreateInsufficientPermissions: + return iox2_event_open_or_create_error_e_C_INSUFFICIENT_PERMISSIONS; + default: + IOX_UNREACHABLE(); + } +} + template <> constexpr auto from(const int value) noexcept -> iox2::EventOpenError { const auto error = static_cast(value); @@ -264,6 +387,41 @@ constexpr auto from(const int value) noexcept -> iox2 } } +template <> +constexpr auto from(const iox2::EventOpenError value) noexcept + -> iox2_event_open_or_create_error_e { + switch (value) { + case iox2::EventOpenError::DoesNotExist: + return iox2_event_open_or_create_error_e_O_DOES_NOT_EXIST; + case iox2::EventOpenError::InsufficientPermissions: + return iox2_event_open_or_create_error_e_O_INSUFFICIENT_PERMISSIONS; + case iox2::EventOpenError::ServiceInCorruptedState: + return iox2_event_open_or_create_error_e_O_SERVICE_IN_CORRUPTED_STATE; + case iox2::EventOpenError::IncompatibleMessagingPattern: + return iox2_event_open_or_create_error_e_O_INCOMPATIBLE_MESSAGING_PATTERN; + case iox2::EventOpenError::IncompatibleAttributes: + return iox2_event_open_or_create_error_e_O_INCOMPATIBLE_ATTRIBUTES; + case iox2::EventOpenError::InternalFailure: + return iox2_event_open_or_create_error_e_O_INTERNAL_FAILURE; + case iox2::EventOpenError::HangsInCreation: + return iox2_event_open_or_create_error_e_O_HANGS_IN_CREATION; + case iox2::EventOpenError::DoesNotSupportRequestedAmountOfNotifiers: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NOTIFIERS; + case iox2::EventOpenError::DoesNotSupportRequestedAmountOfListeners: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_LISTENERS; + case iox2::EventOpenError::DoesNotSupportRequestedMaxEventId: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MAX_EVENT_ID; + case iox2::EventOpenError::DoesNotSupportRequestedAmountOfNodes: + return iox2_event_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES; + case iox2::EventOpenError::ExceedsMaxNumberOfNodes: + return iox2_event_open_or_create_error_e_O_EXCEEDS_MAX_NUMBER_OF_NODES; + case iox2::EventOpenError::IsMarkedForDestruction: + return iox2_event_open_or_create_error_e_O_IS_MARKED_FOR_DESTRUCTION; + default: + IOX_UNREACHABLE(); + } +} + template <> constexpr auto from(const int value) noexcept -> iox2::EventCreateError { const auto error = static_cast(value); @@ -280,8 +438,27 @@ constexpr auto from(const int value) noexcept -> io return iox2::EventCreateError::HangsInCreation; case iox2_event_open_or_create_error_e_C_INSUFFICIENT_PERMISSIONS: return iox2::EventCreateError::InsufficientPermissions; - case iox2_event_open_or_create_error_e_C_OLD_CONNECTION_STILL_ACTIVE: - return iox2::EventCreateError::OldConnectionsStillActive; + default: + IOX_UNREACHABLE(); + } +} + +template <> +constexpr auto from( + const iox2::EventCreateError value) noexcept -> iox2_event_open_or_create_error_e { + switch (value) { + case iox2::EventCreateError::InsufficientPermissions: + return iox2_event_open_or_create_error_e_C_INSUFFICIENT_PERMISSIONS; + case iox2::EventCreateError::HangsInCreation: + return iox2_event_open_or_create_error_e_C_HANGS_IN_CREATION; + case iox2::EventCreateError::AlreadyExists: + return iox2_event_open_or_create_error_e_C_ALREADY_EXISTS; + case iox2::EventCreateError::IsBeingCreatedByAnotherInstance: + return iox2_event_open_or_create_error_e_C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE; + case iox2::EventCreateError::InternalFailure: + return iox2_event_open_or_create_error_e_C_INTERNAL_FAILURE; + case iox2::EventCreateError::ServiceInCorruptedState: + return iox2_event_open_or_create_error_e_C_SERVICE_IN_CORRUPTED_STATE; default: IOX_UNREACHABLE(); } @@ -339,8 +516,6 @@ constexpr auto from(const int valu return iox2::PublishSubscribeOpenOrCreateError::CreateInternalFailure; case iox2_pub_sub_open_or_create_error_e_C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE: return iox2::PublishSubscribeOpenOrCreateError::CreateIsBeingCreatedByAnotherInstance; - case iox2_pub_sub_open_or_create_error_e_C_OLD_CONNECTION_STILL_ACTIVE: - return iox2::PublishSubscribeOpenOrCreateError::CreateOldConnectionsStillActive; case iox2_pub_sub_open_or_create_error_e_C_HANGS_IN_CREATION: return iox2::PublishSubscribeOpenOrCreateError::CreateHangsInCreation; } @@ -391,6 +566,49 @@ constexpr auto from(const int value) noexc } } +template <> +constexpr auto from( + const iox2::PublishSubscribeOpenError value) noexcept -> iox2_pub_sub_open_or_create_error_e { + switch (value) { + case iox2::PublishSubscribeOpenError::DoesNotExist: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_EXIST; + case iox2::PublishSubscribeOpenError::InternalFailure: + return iox2_pub_sub_open_or_create_error_e_O_INTERNAL_FAILURE; + case iox2::PublishSubscribeOpenError::IncompatibleTypes: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_TYPES; + case iox2::PublishSubscribeOpenError::IncompatibleMessagingPattern: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_MESSAGING_PATTERN; + case iox2::PublishSubscribeOpenError::IncompatibleAttributes: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_ATTRIBUTES; + case iox2::PublishSubscribeOpenError::DoesNotSupportRequestedMinBufferSize: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MIN_BUFFER_SIZE; + case iox2::PublishSubscribeOpenError::DoesNotSupportRequestedMinHistorySize: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MIN_HISTORY_SIZE; + case iox2::PublishSubscribeOpenError::DoesNotSupportRequestedMinSubscriberBorrowedSamples: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MIN_SUBSCRIBER_BORROWED_SAMPLES; + case iox2::PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfPublishers: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_PUBLISHERS; + case iox2::PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfSubscribers: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_SUBSCRIBERS; + case iox2::PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfNodes: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES; + case iox2::PublishSubscribeOpenError::IncompatibleOverflowBehavior: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_OVERFLOW_BEHAVIOR; + case iox2::PublishSubscribeOpenError::InsufficientPermissions: + return iox2_pub_sub_open_or_create_error_e_O_INSUFFICIENT_PERMISSIONS; + case iox2::PublishSubscribeOpenError::ServiceInCorruptedState: + return iox2_pub_sub_open_or_create_error_e_O_SERVICE_IN_CORRUPTED_STATE; + case iox2::PublishSubscribeOpenError::HangsInCreation: + return iox2_pub_sub_open_or_create_error_e_O_HANGS_IN_CREATION; + case iox2::PublishSubscribeOpenError::ExceedsMaxNumberOfNodes: + return iox2_pub_sub_open_or_create_error_e_O_EXCEEDS_MAX_NUMBER_OF_NODES; + case iox2::PublishSubscribeOpenError::IsMarkedForDestruction: + return iox2_pub_sub_open_or_create_error_e_O_IS_MARKED_FOR_DESTRUCTION; + default: + IOX_UNREACHABLE(); + } +} + template <> constexpr auto from(const int value) noexcept -> iox2::PublishSubscribeCreateError { @@ -408,8 +626,6 @@ from(const int value) noexcept -> iox2:: return iox2::PublishSubscribeCreateError::InternalFailure; case iox2_pub_sub_open_or_create_error_e_C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE: return iox2::PublishSubscribeCreateError::IsBeingCreatedByAnotherInstance; - case iox2_pub_sub_open_or_create_error_e_C_OLD_CONNECTION_STILL_ACTIVE: - return iox2::PublishSubscribeCreateError::OldConnectionsStillActive; case iox2_pub_sub_open_or_create_error_e_C_HANGS_IN_CREATION: return iox2::PublishSubscribeCreateError::HangsInCreation; default: @@ -417,6 +633,86 @@ from(const int value) noexcept -> iox2:: } } +template <> +constexpr auto from( + const iox2::PublishSubscribeCreateError value) noexcept -> iox2_pub_sub_open_or_create_error_e { + switch (value) { + case iox2::PublishSubscribeCreateError::ServiceInCorruptedState: + return iox2_pub_sub_open_or_create_error_e_C_SERVICE_IN_CORRUPTED_STATE; + case iox2::PublishSubscribeCreateError::SubscriberBufferMustBeLargerThanHistorySize: + return iox2_pub_sub_open_or_create_error_e_C_SUBSCRIBER_BUFFER_MUST_BE_LARGER_THAN_HISTORY_SIZE; + case iox2::PublishSubscribeCreateError::AlreadyExists: + return iox2_pub_sub_open_or_create_error_e_C_ALREADY_EXISTS; + case iox2::PublishSubscribeCreateError::InsufficientPermissions: + return iox2_pub_sub_open_or_create_error_e_C_INSUFFICIENT_PERMISSIONS; + case iox2::PublishSubscribeCreateError::InternalFailure: + return iox2_pub_sub_open_or_create_error_e_C_INTERNAL_FAILURE; + case iox2::PublishSubscribeCreateError::IsBeingCreatedByAnotherInstance: + return iox2_pub_sub_open_or_create_error_e_C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE; + case iox2::PublishSubscribeCreateError::HangsInCreation: + return iox2_pub_sub_open_or_create_error_e_C_HANGS_IN_CREATION; + default: + IOX_UNREACHABLE(); + } +} + +template <> +constexpr auto from( + const iox2::PublishSubscribeOpenOrCreateError value) noexcept -> iox2_pub_sub_open_or_create_error_e { + switch (value) { + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotExist: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_EXIST; + case iox2::PublishSubscribeOpenOrCreateError::OpenInternalFailure: + return iox2_pub_sub_open_or_create_error_e_O_INTERNAL_FAILURE; + case iox2::PublishSubscribeOpenOrCreateError::OpenIncompatibleTypes: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_TYPES; + case iox2::PublishSubscribeOpenOrCreateError::OpenIncompatibleMessagingPattern: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_MESSAGING_PATTERN; + case iox2::PublishSubscribeOpenOrCreateError::OpenIncompatibleAttributes: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_ATTRIBUTES; + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotSupportRequestedMinBufferSize: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MIN_BUFFER_SIZE; + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotSupportRequestedMinHistorySize: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MIN_HISTORY_SIZE; + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotSupportRequestedMinSubscriberBorrowedSamples: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_MIN_SUBSCRIBER_BORROWED_SAMPLES; + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotSupportRequestedAmountOfPublishers: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_PUBLISHERS; + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotSupportRequestedAmountOfSubscribers: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_SUBSCRIBERS; + case iox2::PublishSubscribeOpenOrCreateError::OpenDoesNotSupportRequestedAmountOfNodes: + return iox2_pub_sub_open_or_create_error_e_O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES; + case iox2::PublishSubscribeOpenOrCreateError::OpenIncompatibleOverflowBehavior: + return iox2_pub_sub_open_or_create_error_e_O_INCOMPATIBLE_OVERFLOW_BEHAVIOR; + case iox2::PublishSubscribeOpenOrCreateError::OpenInsufficientPermissions: + return iox2_pub_sub_open_or_create_error_e_O_INSUFFICIENT_PERMISSIONS; + case iox2::PublishSubscribeOpenOrCreateError::OpenServiceInCorruptedState: + return iox2_pub_sub_open_or_create_error_e_O_SERVICE_IN_CORRUPTED_STATE; + case iox2::PublishSubscribeOpenOrCreateError::OpenHangsInCreation: + return iox2_pub_sub_open_or_create_error_e_O_HANGS_IN_CREATION; + case iox2::PublishSubscribeOpenOrCreateError::OpenExceedsMaxNumberOfNodes: + return iox2_pub_sub_open_or_create_error_e_O_EXCEEDS_MAX_NUMBER_OF_NODES; + case iox2::PublishSubscribeOpenOrCreateError::OpenIsMarkedForDestruction: + return iox2_pub_sub_open_or_create_error_e_O_IS_MARKED_FOR_DESTRUCTION; + case iox2::PublishSubscribeOpenOrCreateError::CreateServiceInCorruptedState: + return iox2_pub_sub_open_or_create_error_e_C_SERVICE_IN_CORRUPTED_STATE; + case iox2::PublishSubscribeOpenOrCreateError::CreateSubscriberBufferMustBeLargerThanHistorySize: + return iox2_pub_sub_open_or_create_error_e_C_SUBSCRIBER_BUFFER_MUST_BE_LARGER_THAN_HISTORY_SIZE; + case iox2::PublishSubscribeOpenOrCreateError::CreateAlreadyExists: + return iox2_pub_sub_open_or_create_error_e_C_ALREADY_EXISTS; + case iox2::PublishSubscribeOpenOrCreateError::CreateInsufficientPermissions: + return iox2_pub_sub_open_or_create_error_e_C_INSUFFICIENT_PERMISSIONS; + case iox2::PublishSubscribeOpenOrCreateError::CreateInternalFailure: + return iox2_pub_sub_open_or_create_error_e_C_INTERNAL_FAILURE; + case iox2::PublishSubscribeOpenOrCreateError::CreateIsBeingCreatedByAnotherInstance: + return iox2_pub_sub_open_or_create_error_e_C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE; + case iox2::PublishSubscribeOpenOrCreateError::CreateHangsInCreation: + return iox2_pub_sub_open_or_create_error_e_C_HANGS_IN_CREATION; + default: + IOX_UNREACHABLE(); + } +} + template <> constexpr auto from(const int value) noexcept -> iox2::NotifierCreateError { const auto error = static_cast(value); @@ -428,6 +724,17 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::NotifierCreateError value) noexcept -> iox2_notifier_create_error_e { + switch (value) { + case iox2::NotifierCreateError::ExceedsMaxSupportedNotifiers: + return iox2_notifier_create_error_e_EXCEEDS_MAX_SUPPORTED_NOTIFIERS; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::ListenerCreateError { const auto error = static_cast(value); @@ -441,6 +748,19 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::ListenerCreateError value) noexcept -> iox2_listener_create_error_e { + switch (value) { + case iox2::ListenerCreateError::ExceedsMaxSupportedListeners: + return iox2_listener_create_error_e_EXCEEDS_MAX_SUPPORTED_LISTENERS; + case iox2::ListenerCreateError::ResourceCreationFailed: + return iox2_listener_create_error_e_RESOURCE_CREATION_FAILED; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::NotifierNotifyError { const auto error = static_cast(value); @@ -452,6 +772,17 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::NotifierNotifyError value) noexcept -> iox2_notifier_notify_error_e { + switch (value) { + case iox2::NotifierNotifyError::EventIdOutOfBounds: + return iox2_notifier_notify_error_e_EVENT_ID_OUT_OF_BOUNDS; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::ListenerWaitError { const auto error = static_cast(value); @@ -467,6 +798,21 @@ constexpr auto from(const int value) noexcept -> i IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::ListenerWaitError value) noexcept + -> iox2_listener_wait_error_e { + switch (value) { + case iox2::ListenerWaitError::ContractViolation: + return iox2_listener_wait_error_e_CONTRACT_VIOLATION; + case iox2::ListenerWaitError::InterruptSignal: + return iox2_listener_wait_error_e_INTERRUPT_SIGNAL; + case iox2::ListenerWaitError::InternalFailure: + return iox2_listener_wait_error_e_INTERNAL_FAILURE; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::PublisherCreateError { const auto error = static_cast(value); @@ -480,6 +826,19 @@ constexpr auto from(const int value) noexcept - IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::PublisherCreateError value) noexcept -> iox2_publisher_create_error_e { + switch (value) { + case iox2::PublisherCreateError::ExceedsMaxSupportedPublishers: + return iox2_publisher_create_error_e_EXCEEDS_MAX_SUPPORTED_PUBLISHERS; + case iox2::PublisherCreateError::UnableToCreateDataSegment: + return iox2_publisher_create_error_e_UNABLE_TO_CREATE_DATA_SEGMENT; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::SubscriberCreateError { const auto error = static_cast(value); @@ -493,6 +852,19 @@ constexpr auto from(const int value) noexcept IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::SubscriberCreateError value) noexcept -> iox2_subscriber_create_error_e { + switch (value) { + case iox2::SubscriberCreateError::BufferSizeExceedsMaxSupportedBufferSizeOfService: + return iox2_subscriber_create_error_e_BUFFER_SIZE_EXCEEDS_MAX_SUPPORTED_BUFFER_SIZE_OF_SERVICE; + case iox2::SubscriberCreateError::ExceedsMaxSupportedSubscribers: + return iox2_subscriber_create_error_e_EXCEEDS_MAX_SUPPORTED_SUBSCRIBERS; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::PublisherSendError { const auto error = static_cast(value); @@ -516,6 +888,29 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::PublisherSendError value) noexcept -> iox2_publisher_send_error_e { + switch (value) { + case iox2::PublisherSendError::ConnectionBrokenSincePublisherNoLongerExists: + return iox2_publisher_send_error_e_CONNECTION_BROKEN_SINCE_PUBLISHER_NO_LONGER_EXISTS; + case iox2::PublisherSendError::ConnectionCorrupted: + return iox2_publisher_send_error_e_CONNECTION_CORRUPTED; + case iox2::PublisherSendError::LoanErrorOutOfMemory: + return iox2_publisher_send_error_e_LOAN_ERROR_OUT_OF_MEMORY; + case iox2::PublisherSendError::LoanErrorExceedsMaxLoanedSamples: + return iox2_publisher_send_error_e_LOAN_ERROR_EXCEEDS_MAX_LOANED_SAMPLES; + case iox2::PublisherSendError::LoanErrorExceedsMaxLoanSize: + return iox2_publisher_send_error_e_LOAN_ERROR_EXCEEDS_MAX_LOAN_SIZE; + case iox2::PublisherSendError::LoanErrorInternalFailure: + return iox2_publisher_send_error_e_LOAN_ERROR_INTERNAL_FAILURE; + case iox2::PublisherSendError::ConnectionError: + return iox2_publisher_send_error_e_CONNECTION_ERROR; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::SubscriberReceiveError { const auto error = static_cast(value); @@ -531,6 +926,21 @@ constexpr auto from(const int value) noexcept IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::SubscriberReceiveError value) noexcept -> iox2_subscriber_receive_error_e { + switch (value) { + case iox2::SubscriberReceiveError::FailedToEstablishConnection: + return iox2_subscriber_receive_error_e_FAILED_TO_ESTABLISH_CONNECTION; + case iox2::SubscriberReceiveError::UnableToMapPublishersDataSegment: + return iox2_subscriber_receive_error_e_UNABLE_TO_MAP_PUBLISHERS_DATA_SEGMENT; + case iox2::SubscriberReceiveError::ExceedsMaxBorrowedSamples: + return iox2_subscriber_receive_error_e_EXCEEDS_MAX_BORROWED_SAMPLES; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::PublisherLoanError { const auto error = static_cast(value); @@ -548,6 +958,23 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::PublisherLoanError value) noexcept -> iox2_publisher_loan_error_e { + switch (value) { + case iox2::PublisherLoanError::ExceedsMaxLoanedSamples: + return iox2_publisher_loan_error_e_EXCEEDS_MAX_LOANED_SAMPLES; + case iox2::PublisherLoanError::OutOfMemory: + return iox2_publisher_loan_error_e_OUT_OF_MEMORY; + case iox2::PublisherLoanError::ExceedsMaxLoanSize: + return iox2_publisher_loan_error_e_EXCEEDS_MAX_LOAN_SIZE; + case iox2::PublisherLoanError::InternalFailure: + return iox2_publisher_loan_error_e_INTERNAL_FAILURE; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::TypeVariant { const auto variant = static_cast(value); @@ -574,6 +1001,19 @@ constexpr auto from(const int value) noexcept -> io IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::ServiceListError value) noexcept + -> iox2_service_list_error_e { + switch (value) { + case iox2::ServiceListError::InsufficientPermissions: + return iox2_service_list_error_e_INSUFFICIENT_PERMISSIONS; + case iox2::ServiceListError::InternalError: + return iox2_service_list_error_e_INTERNAL_ERROR; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::MessagingPattern { const auto variant = static_cast(value); @@ -625,6 +1065,19 @@ constexpr auto from(const int value) noexcept -> i IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::ConnectionFailure value) noexcept + -> iox2_connection_failure_e { + switch (value) { + case iox2::ConnectionFailure::FailedToEstablishConnection: + return iox2_connection_failure_e_FAILED_TO_ESTABLISH_CONNECTION; + case iox2::ConnectionFailure::UnableToMapPublishersDataSegment: + return iox2_connection_failure_e_UNABLE_TO_MAP_PUBLISHERS_DATA_SEGMENT; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::ConfigCreationError { const auto variant = static_cast(value); @@ -643,6 +1096,21 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::ConfigCreationError value) noexcept -> iox2_config_creation_error_e { + switch (value) { + case iox2::ConfigCreationError::FailedToOpenConfigFile: + return iox2_config_creation_error_e_FAILED_TO_OPEN_CONFIG_FILE; + case iox2::ConfigCreationError::FailedToReadConfigFileContents: + return iox2_config_creation_error_e_FAILED_TO_READ_CONFIG_FILE_CONTENTS; + case iox2::ConfigCreationError::UnableToDeserializeContents: + return iox2_config_creation_error_e_UNABLE_TO_DESERIALIZE_CONTENTS; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(iox2::LogLevel value) noexcept -> iox2_log_level_e { switch (value) { @@ -694,6 +1162,17 @@ constexpr auto from(const int value) noexcept -> IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::WaitSetCreateError value) noexcept -> iox2_waitset_create_error_e { + switch (value) { + case iox2::WaitSetCreateError::InternalError: + return iox2_waitset_create_error_e_INTERNAL_ERROR; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::WaitSetRunResult { const auto variant = static_cast(value); @@ -726,6 +1205,21 @@ constexpr auto from(const int value) noexcept IOX_UNREACHABLE(); } +template <> +constexpr auto from( + const iox2::WaitSetAttachmentError value) noexcept -> iox2_waitset_attachment_error_e { + switch (value) { + case iox2::WaitSetAttachmentError::AlreadyAttached: + return iox2_waitset_attachment_error_e_ALREADY_ATTACHED; + case iox2::WaitSetAttachmentError::InsufficientCapacity: + return iox2_waitset_attachment_error_e_INSUFFICIENT_CAPACITY; + case iox2::WaitSetAttachmentError::InternalError: + return iox2_waitset_attachment_error_e_INTERNAL_ERROR; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::WaitSetRunError { const auto variant = static_cast(value); @@ -745,6 +1239,25 @@ constexpr auto from(const int value) noexcept -> iox IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::WaitSetRunError value) noexcept + -> iox2_waitset_run_error_e { + switch (value) { + case iox2::WaitSetRunError::InsufficientPermissions: + return iox2_waitset_run_error_e_INSUFFICIENT_PERMISSIONS; + case iox2::WaitSetRunError::InternalError: + return iox2_waitset_run_error_e_INTERNAL_ERROR; + case iox2::WaitSetRunError::NoAttachments: + return iox2_waitset_run_error_e_NO_ATTACHMENTS; + case iox2::WaitSetRunError::TerminationRequest: + return iox2_waitset_run_error_e_TERMINATION_REQUEST; + case iox2::WaitSetRunError::Interrupt: + return iox2_waitset_run_error_e_INTERRUPT; + } + + IOX_UNREACHABLE(); +} + } // namespace iox #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/listener_error.hpp b/iceoryx2-ffi/cxx/include/iox2/listener_error.hpp index 2dc4b8753..61bea4130 100644 --- a/iceoryx2-ffi/cxx/include/iox2/listener_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/listener_error.hpp @@ -41,6 +41,10 @@ enum class ListenerWaitError : uint8_t { /// configured system. InternalFailure, }; + +auto error_string(const iox2::ListenerCreateError& error) -> const char*; +auto error_string(const iox2::ListenerWaitError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/node_failure_enums.hpp b/iceoryx2-ffi/cxx/include/iox2/node_failure_enums.hpp index 0b6ab338c..d27a65eb8 100644 --- a/iceoryx2-ffi/cxx/include/iox2/node_failure_enums.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/node_failure_enums.hpp @@ -39,6 +39,9 @@ enum class NodeCreationFailure : uint8_t { enum class NodeCleanupFailure : uint8_t { }; +auto error_string(const iox2::NodeListFailure& error) -> const char*; +auto error_string(const iox2::NodeCreationFailure& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/node_wait_failure.hpp b/iceoryx2-ffi/cxx/include/iox2/node_wait_failure.hpp index e6fc0f28d..cec0feae2 100644 --- a/iceoryx2-ffi/cxx/include/iox2/node_wait_failure.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/node_wait_failure.hpp @@ -16,6 +16,7 @@ #include namespace iox2 { + /// Defines all possible errors that can occur during [`Node::wait()`]. enum class NodeWaitFailure : uint8_t { /// SIGTERM signal was received @@ -23,6 +24,10 @@ enum class NodeWaitFailure : uint8_t { /// SIGINT signal was received Interrupt, }; + + +auto error_string(const iox2::NodeWaitFailure& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/notifier_error.hpp b/iceoryx2-ffi/cxx/include/iox2/notifier_error.hpp index 5bdc95c0c..8cf0c4069 100644 --- a/iceoryx2-ffi/cxx/include/iox2/notifier_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/notifier_error.hpp @@ -35,6 +35,10 @@ enum class NotifierNotifyError : uint8_t { /// [`Service`] EventIdOutOfBounds, }; + +auto error_string(const iox2::NotifierCreateError& error) -> const char*; +auto error_string(const iox2::NotifierNotifyError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/publisher_error.hpp b/iceoryx2-ffi/cxx/include/iox2/publisher_error.hpp index 27118a78d..cda7b80dc 100644 --- a/iceoryx2-ffi/cxx/include/iox2/publisher_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/publisher_error.hpp @@ -82,6 +82,11 @@ enum class PublisherSendError : uint8_t { /// [`Subscriber`] ConnectionError, }; + +auto error_string(const iox2::PublisherCreateError& error) -> const char*; +auto error_string(const iox2::PublisherLoanError& error) -> const char*; +auto error_string(const iox2::PublisherSendError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp b/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp index 3b70b877b..dd243032d 100644 --- a/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp @@ -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 diff --git a/iceoryx2-ffi/cxx/include/iox2/service_builder_event_error.hpp b/iceoryx2-ffi/cxx/include/iox2/service_builder_event_error.hpp index 2087b4f6f..b4c0bd1bf 100644 --- a/iceoryx2-ffi/cxx/include/iox2/service_builder_event_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/service_builder_event_error.hpp @@ -157,6 +157,11 @@ enum class EventOpenOrCreateError : uint8_t { /// [`SampleMut`] in use. CreateOldConnectionsStillActive, }; + +auto error_string(const iox2::EventOpenError& error) -> const char*; +auto error_string(const iox2::EventCreateError& error) -> const char*; +auto error_string(const iox2::EventOpenOrCreateError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe_error.hpp b/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe_error.hpp index 2347909c0..d3867bb74 100644 --- a/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/service_builder_publish_subscribe_error.hpp @@ -13,6 +13,7 @@ #ifndef IOX2_SERVICE_BUILDER_PUBLISH_SUBSCRIBE_ERROR_HPP #define IOX2_SERVICE_BUILDER_PUBLISH_SUBSCRIBE_ERROR_HPP +#include "iox2/iceoryx2.h" #include namespace iox2 { @@ -87,13 +88,6 @@ enum class PublishSubscribeCreateError : uint8_t { InternalFailure, /// Multiple processes are trying to create the same [`Service`]. IsBeingCreatedByAnotherInstance, - /// The system has cleaned up the [`Service`] but there are still endpoints - /// like - /// [`Publisher`] or - /// [`Subscriber`] alive or - /// [`Sample`] or - /// [`SampleMut`] in use. - OldConnectionsStillActive, /// The [`Service`]s creation timeout has passed and it is still not /// initialized. Can be caused /// by a process that crashed during [`Service`] creation. @@ -181,6 +175,11 @@ enum class PublishSubscribeOpenOrCreateError : uint8_t { /// by a process that crashed during [`Service`] creation. CreateHangsInCreation, }; + +auto error_string(const iox2::PublishSubscribeOpenError& error) -> const char*; +auto error_string(const iox2::PublishSubscribeCreateError& error) -> const char*; +auto error_string(const iox2::PublishSubscribeOpenOrCreateError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/service_error_enums.hpp b/iceoryx2-ffi/cxx/include/iox2/service_error_enums.hpp index a96d61eec..e24b2e482 100644 --- a/iceoryx2-ffi/cxx/include/iox2/service_error_enums.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/service_error_enums.hpp @@ -43,6 +43,10 @@ enum class ServiceListError : uint8_t { /// configured system. InternalError, }; + +auto error_string(const iox2::ServiceDetailsError& error) -> const char*; +auto error_string(const iox2::ServiceListError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/subscriber_error.hpp b/iceoryx2-ffi/cxx/include/iox2/subscriber_error.hpp index c4c611105..6e8b46da3 100644 --- a/iceoryx2-ffi/cxx/include/iox2/subscriber_error.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/subscriber_error.hpp @@ -43,6 +43,10 @@ enum class SubscriberCreateError : uint8_t { /// [`Service`] offers the creation will fail. BufferSizeExceedsMaxSupportedBufferSizeOfService, }; + +auto error_string(const iox2::SubscriberCreateError& error) -> const char*; +auto error_string(const iox2::SubscriberReceiveError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp b/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp index 8bf03b444..05aea58c2 100644 --- a/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp @@ -58,6 +58,11 @@ enum class WaitSetRunError : uint8_t { /// An interrupt signal `SIGINT` was received. Interrupt }; + +auto error_string(const iox2::WaitSetCreateError& error) -> const char*; +auto error_string(const iox2::WaitSetAttachmentError& error) -> const char*; +auto error_string(const iox2::WaitSetRunError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/src/error_string.cpp b/iceoryx2-ffi/cxx/src/error_string.cpp new file mode 100644 index 000000000..56f54b473 --- /dev/null +++ b/iceoryx2-ffi/cxx/src/error_string.cpp @@ -0,0 +1,135 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +#include "iox2/config_creation_error.hpp" +#include "iox2/connection_failure.hpp" +#include "iox2/enum_translation.hpp" +#include "iox2/iceoryx2.h" +#include "iox2/listener_error.hpp" +#include "iox2/node_failure_enums.hpp" +#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" +#include "iox2/subscriber_error.hpp" +#include "iox2/waitset_enums.hpp" + +namespace iox2 { + +auto error_string(const iox2::ConfigCreationError& error) -> const char* { + return iox2_config_creation_error_string(iox::into(error)); +} + +auto error_string(const iox2::ConnectionFailure& error) -> const char* { + return iox2_connection_failure_string(iox::into(error)); +} + +auto error_string(const iox2::ServiceDetailsError& error) -> const char* { + return iox2_service_details_error_string(iox::into(error)); +} + +auto error_string(const iox2::ServiceListError& error) -> const char* { + return iox2_service_list_error_string(iox::into(error)); +} + +auto error_string(const iox2::ListenerCreateError& error) -> const char* { + return iox2_listener_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::ListenerWaitError& error) -> const char* { + return iox2_listener_wait_error_string(iox::into(error)); +} + +auto error_string(const iox2::NodeListFailure& error) -> const char* { + return iox2_node_list_failure_string(iox::into(error)); +} + +auto error_string(const iox2::NodeCreationFailure& error) -> const char* { + return iox2_node_creation_failure_string(iox::into(error)); +} + +auto error_string(const iox2::NodeWaitFailure& error) -> const char* { + return iox2_node_wait_failure_string(iox::into(error)); +} + +auto error_string(const iox2::NotifierCreateError& error) -> const char* { + return iox2_notifier_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::NotifierNotifyError& error) -> const char* { + return iox2_notifier_notify_error_string(iox::into(error)); +} + +auto error_string(const iox2::PublisherCreateError& error) -> const char* { + return iox2_publisher_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::PublisherLoanError& error) -> const char* { + return iox2_publisher_loan_error_string(iox::into(error)); +} + +auto error_string(const iox2::PublisherSendError& error) -> const char* { + return iox2_publisher_send_error_string(iox::into(error)); +} + +auto error_string(const iox2::PublishSubscribeOpenError& error) -> const char* { + return iox2_pub_sub_open_or_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::PublishSubscribeCreateError& error) -> const char* { + return iox2_pub_sub_open_or_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::PublishSubscribeOpenOrCreateError& error) -> const char* { + return iox2_pub_sub_open_or_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::SemanticStringError& error) -> const char* { + return iox2_semantic_string_error_string(iox::into(error)); +} + +auto error_string(const iox2::EventOpenError& error) -> const char* { + return iox2_event_open_or_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::EventCreateError& error) -> const char* { + return iox2_event_open_or_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::EventOpenOrCreateError& error) -> const char* { + return iox2_event_open_or_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::SubscriberCreateError& error) -> const char* { + return iox2_subscriber_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::SubscriberReceiveError& error) -> const char* { + return iox2_subscriber_receive_error_string(iox::into(error)); +} + +auto error_string(const iox2::WaitSetCreateError& error) -> const char* { + return iox2_waitset_create_error_string(iox::into(error)); +} + +auto error_string(const iox2::WaitSetAttachmentError& error) -> const char* { + return iox2_waitset_attachment_error_string(iox::into(error)); +} + +auto error_string(const iox2::WaitSetRunError& error) -> const char* { + return iox2_waitset_run_error_string(iox::into(error)); +} + +} // namespace iox2 diff --git a/iceoryx2-ffi/ffi/Cargo.toml b/iceoryx2-ffi/ffi/Cargo.toml index a3de200b5..240183aa0 100644 --- a/iceoryx2-ffi/ffi/Cargo.toml +++ b/iceoryx2-ffi/ffi/Cargo.toml @@ -24,6 +24,7 @@ cbindgen = { workspace = true } [dependencies] iceoryx2 = { workspace = true } iceoryx2-bb-container = { workspace = true } +iceoryx2-bb-derive-macros = { workspace = true } iceoryx2-bb-elementary = { workspace = true } iceoryx2-bb-log = { workspace = true } iceoryx2-bb-system-types = { workspace = true } diff --git a/iceoryx2-ffi/ffi/cbindgen.toml b/iceoryx2-ffi/ffi/cbindgen.toml index 5ce9db295..a682fa831 100644 --- a/iceoryx2-ffi/ffi/cbindgen.toml +++ b/iceoryx2-ffi/ffi/cbindgen.toml @@ -24,10 +24,18 @@ header = """// Copyright (c) 2024 Contributors to the Eclipse Foundation // SPDX-License-Identifier: Apache-2.0 OR MIT // NOTE: This file is generated by cbindgen! Don't modify manually! + +#ifdef __cplusplus +extern "C" { +#endif """ # default: "" -trailer = "" +trailer = """ +#ifdef __cplusplus +} +#endif +""" # default: "" include_guard = "IOX2_C_BINDINGS_H" diff --git a/iceoryx2-ffi/ffi/src/api/config.rs b/iceoryx2-ffi/ffi/src/api/config.rs index ae3b8e21c..b6ff7e290 100644 --- a/iceoryx2-ffi/ffi/src/api/config.rs +++ b/iceoryx2-ffi/ffi/src/api/config.rs @@ -17,7 +17,9 @@ use core::ffi::{c_char, c_int}; use core::time::Duration; use iceoryx2::config::{Config, ConfigCreationError}; use iceoryx2_bb_container::semantic_string::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_bb_system_types::file_name::FileName; use iceoryx2_bb_system_types::file_path::FilePath; use iceoryx2_bb_system_types::path::Path; @@ -32,7 +34,7 @@ use super::{HandleToType, IntoCInt}; /// Failures occurring while creating a new [`iox2_config_t`] object with [`iox2_config_from_file()`]. #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_config_creation_error_e { /// The config file could not be opened. FAILED_TO_OPEN_CONFIG_FILE = IOX2_OK as isize + 1, @@ -134,6 +136,13 @@ impl HandleToType for iox2_config_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_config_creation_error_string( + error: iox2_config_creation_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// This function casts a [`iox2_config_h`] into a [`iox2_config_ptr`] /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/listener.rs b/iceoryx2-ffi/ffi/src/api/listener.rs index 94ea89b74..e184e78f9 100644 --- a/iceoryx2-ffi/ffi/src/api/listener.rs +++ b/iceoryx2-ffi/ffi/src/api/listener.rs @@ -20,19 +20,21 @@ use crate::iox2_file_descriptor_ptr; use iceoryx2::port::listener::Listener; use iceoryx2::prelude::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_bb_posix::file_descriptor::{FileDescriptor, FileDescriptorBased}; use iceoryx2_cal::event::ListenerWaitError; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; use core::time::Duration; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_listener_wait_error_e { CONTRACT_VIOLATION = IOX2_OK as isize + 1, INTERNAL_FAILURE, @@ -138,6 +140,13 @@ pub type iox2_listener_wait_all_callback = // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_listener_wait_error_string( + error: iox2_listener_wait_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// This function needs to be called to destroy the listener! /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/mod.rs b/iceoryx2-ffi/ffi/src/api/mod.rs index 9790b1875..a2f49e99d 100644 --- a/iceoryx2-ffi/ffi/src/api/mod.rs +++ b/iceoryx2-ffi/ffi/src/api/mod.rs @@ -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; @@ -119,7 +121,7 @@ impl From 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, @@ -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 +} diff --git a/iceoryx2-ffi/ffi/src/api/node.rs b/iceoryx2-ffi/ffi/src/api/node.rs index 3ece99722..91eb72046 100644 --- a/iceoryx2-ffi/ffi/src/api/node.rs +++ b/iceoryx2-ffi/ffi/src/api/node.rs @@ -20,17 +20,19 @@ use crate::api::{ use iceoryx2::node::{NodeId, NodeListFailure, NodeView, NodeWaitFailure}; use iceoryx2::prelude::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; use std::time::Duration; // BEGIN type definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_node_list_failure_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERRUPT, @@ -50,7 +52,7 @@ impl IntoCInt for NodeListFailure { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_node_wait_failure_e { INTERRUPT = IOX2_OK as isize + 1, TERMINATION_REQUEST, @@ -185,6 +187,20 @@ pub type iox2_node_list_callback = extern "C" fn( // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_node_list_failure_string( + error: iox2_node_list_failure_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + +#[no_mangle] +pub unsafe extern "C" fn iox2_node_wait_failure_string( + error: iox2_node_wait_failure_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Returns the [`iox2_node_name_ptr`](crate::iox2_node_name_ptr), an immutable pointer to the node name. /// /// # Safety diff --git a/iceoryx2-ffi/ffi/src/api/node_builder.rs b/iceoryx2-ffi/ffi/src/api/node_builder.rs index d24b8109f..efdbdd9e5 100644 --- a/iceoryx2-ffi/ffi/src/api/node_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/node_builder.rs @@ -19,16 +19,18 @@ use crate::api::{ use iceoryx2::node::NodeCreationFailure; use iceoryx2::prelude::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_bb_log::fatal_panic; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_node_creation_failure_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -99,6 +101,13 @@ impl HandleToType for iox2_node_builder_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_node_creation_failure_string( + error: iox2_node_creation_failure_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Creates a builder for nodes /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/notifier.rs b/iceoryx2-ffi/ffi/src/api/notifier.rs index 345b61c5e..0e3e491d7 100644 --- a/iceoryx2-ffi/ffi/src/api/notifier.rs +++ b/iceoryx2-ffi/ffi/src/api/notifier.rs @@ -19,16 +19,18 @@ use crate::api::{ use iceoryx2::port::notifier::{Notifier, NotifierNotifyError}; use iceoryx2::prelude::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_notifier_notify_error_e { EVENT_ID_OUT_OF_BOUNDS = IOX2_OK as isize + 1, } @@ -129,6 +131,13 @@ impl HandleToType for iox2_notifier_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_notifier_notify_error_string( + error: iox2_notifier_notify_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Returns the unique port id of the notifier. /// /// # Safety diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs index 681972675..a9ec63199 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_listener_builder.rs @@ -20,16 +20,18 @@ use crate::api::{ use iceoryx2::port::listener::ListenerCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::listener::PortFactoryListener; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_listener_create_error_e { EXCEEDS_MAX_SUPPORTED_LISTENERS = IOX2_OK as isize + 1, RESOURCE_CREATION_FAILED, @@ -134,6 +136,13 @@ impl HandleToType for iox2_port_factory_listener_builder_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_listener_create_error_string( + error: iox2_listener_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + // TODO [#210] add all the other setter methods /// Creates a listener and consumes the builder diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs index 57964dfae..18ae20acf 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_notifier_builder.rs @@ -20,16 +20,18 @@ use crate::api::{ use iceoryx2::port::notifier::NotifierCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::notifier::PortFactoryNotifier; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_notifier_create_error_e { EXCEEDS_MAX_SUPPORTED_NOTIFIERS = IOX2_OK as isize + 1, } @@ -130,6 +132,13 @@ impl HandleToType for iox2_port_factory_notifier_builder_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_notifier_create_error_string( + error: iox2_notifier_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Sets the default event id for the builder /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs index c3f68d9ee..fcd7b2be7 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_publisher_builder.rs @@ -20,16 +20,18 @@ use crate::api::{ use iceoryx2::port::publisher::PublisherCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::publisher::PortFactoryPublisher; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_publisher_create_error_e { EXCEEDS_MAX_SUPPORTED_PUBLISHERS = IOX2_OK as isize + 1, UNABLE_TO_CREATE_DATA_SEGMENT, @@ -173,6 +175,13 @@ impl HandleToType for iox2_port_factory_publisher_builder_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_publisher_create_error_string( + error: iox2_publisher_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Sets the max slice length for the publisher /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs b/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs index 93325eaef..3bff0cc99 100644 --- a/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs +++ b/iceoryx2-ffi/ffi/src/api/port_factory_subscriber_builder.rs @@ -20,16 +20,18 @@ use crate::api::{ use iceoryx2::port::subscriber::SubscriberCreateError; use iceoryx2::prelude::*; use iceoryx2::service::port_factory::subscriber::PortFactorySubscriber; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_subscriber_create_error_e { EXCEEDS_MAX_SUPPORTED_SUBSCRIBERS = IOX2_OK as isize + 1, BUFFER_SIZE_EXCEEDS_MAX_SUPPORTED_BUFFER_SIZE_OF_SERVICE, @@ -138,6 +140,13 @@ impl HandleToType for iox2_port_factory_subscriber_builder_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_subscriber_create_error_string( + error: iox2_subscriber_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Sets the buffer size for the subscriber /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/publisher.rs b/iceoryx2-ffi/ffi/src/api/publisher.rs index c7562eedd..657b045fe 100644 --- a/iceoryx2-ffi/ffi/src/api/publisher.rs +++ b/iceoryx2-ffi/ffi/src/api/publisher.rs @@ -21,18 +21,20 @@ use crate::api::{ use iceoryx2::port::publisher::{Publisher, PublisherLoanError, PublisherSendError}; use iceoryx2::port::update_connections::UpdateConnections; use iceoryx2::prelude::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; use super::{iox2_sample_mut_h, iox2_sample_mut_t, IntoCInt}; -use core::ffi::{c_int, c_void}; +use core::ffi::{c_char, c_int, c_void}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_publisher_send_error_e { CONNECTION_BROKEN_SINCE_PUBLISHER_NO_LONGER_EXISTS = IOX2_OK as isize + 1, CONNECTION_CORRUPTED, @@ -85,7 +87,7 @@ impl IntoCInt for PublisherLoanError { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_publisher_loan_error_e { OUT_OF_MEMORY = IOX2_OK as isize + 1, EXCEEDS_MAX_LOANED_SAMPLES, @@ -244,6 +246,20 @@ unsafe fn send_slice_copy( // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_publisher_send_error_string( + error: iox2_publisher_send_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + +#[no_mangle] +pub unsafe extern "C" fn iox2_publisher_loan_error_string( + error: iox2_publisher_loan_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Returns the strategy the publisher follows when a sample cannot be delivered /// since the subscribers buffer is full. /// diff --git a/iceoryx2-ffi/ffi/src/api/service.rs b/iceoryx2-ffi/ffi/src/api/service.rs index e7e2df02b..1547f71e5 100644 --- a/iceoryx2-ffi/ffi/src/api/service.rs +++ b/iceoryx2-ffi/ffi/src/api/service.rs @@ -15,12 +15,14 @@ // BEGIN type definition -use std::ffi::c_int; +use core::ffi::{c_char, c_int}; use iceoryx2::service::{ ipc, local, messaging_pattern::MessagingPattern, Service, ServiceDetails, ServiceDetailsError, ServiceListError, }; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_bb_elementary::CallbackProgression; use crate::{ @@ -70,7 +72,7 @@ impl From<&iceoryx2::service::static_config::messaging_pattern::MessagingPattern } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_service_details_error_e { FAILED_TO_OPEN_STATIC_SERVICE_INFO = IOX2_OK as isize + 1, FAILED_TO_READ_STATIC_SERVICE_INFO, @@ -106,7 +108,7 @@ impl IntoCInt for ServiceDetailsError { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_service_list_error_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -130,6 +132,22 @@ pub type iox2_service_list_callback = extern "C" fn( // END type definition +// BEGIN C API + +#[no_mangle] +pub unsafe extern "C" fn iox2_service_details_error_string( + error: iox2_service_details_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + +#[no_mangle] +pub unsafe extern "C" fn iox2_service_list_error_string( + error: iox2_service_list_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Checks if a specified service exists. If the service exists `does_exist` will contain /// true, otherwise false after the call. On error it returns `iox2_service_details_error_e`, on /// success `IOX2_OK`. @@ -236,3 +254,5 @@ pub unsafe extern "C" fn iox2_service_list( Err(e) => e.into_c_int(), } } + +// END C API diff --git a/iceoryx2-ffi/ffi/src/api/service_builder_event.rs b/iceoryx2-ffi/ffi/src/api/service_builder_event.rs index a55496a9e..cf3676641 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_event.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_event.rs @@ -23,35 +23,55 @@ use iceoryx2::service::builder::event::{ Builder, EventCreateError, EventOpenError, EventOpenOrCreateError, }; use iceoryx2::service::port_factory::event::PortFactory; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_elementary::AsStaticString; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_event_open_or_create_error_e { + #[StaticString = "does not exist"] O_DOES_NOT_EXIST = IOX2_OK as isize + 1, + #[StaticString = "insufficient permissions"] O_INSUFFICIENT_PERMISSIONS, + #[StaticString = "service in corrupted state"] O_SERVICE_IN_CORRUPTED_STATE, + #[StaticString = "incompatible messaging pattern"] O_INCOMPATIBLE_MESSAGING_PATTERN, + #[StaticString = "incompatible attributes"] O_INCOMPATIBLE_ATTRIBUTES, + #[StaticString = "internal failure"] O_INTERNAL_FAILURE, + #[StaticString = "hangs in creation"] O_HANGS_IN_CREATION, + #[StaticString = "does not support requested amount of notifiers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NOTIFIERS, + #[StaticString = "does not support requested amount of listeners"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_LISTENERS, + #[StaticString = "does not support requested max event id"] O_DOES_NOT_SUPPORT_REQUESTED_MAX_EVENT_ID, + #[StaticString = "does not support requested amount of nodes"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES, + #[StaticString = "exceeds max number of nodes"] O_EXCEEDS_MAX_NUMBER_OF_NODES, + #[StaticString = "is marked for destruction"] O_IS_MARKED_FOR_DESTRUCTION, + #[StaticString = "service in corrupted state"] C_SERVICE_IN_CORRUPTED_STATE, + #[StaticString = "internal failure"] C_INTERNAL_FAILURE, + #[StaticString = "is being created by another instance"] C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, + #[StaticString = "already exists"] C_ALREADY_EXISTS, + #[StaticString = "hangs in creation"] C_HANGS_IN_CREATION, + #[StaticString = "insufficient permissions"] C_INSUFFICIENT_PERMISSIONS, - C_OLD_CONNECTION_STILL_ACTIVE, } impl IntoCInt for EventOpenError { @@ -135,6 +155,13 @@ impl IntoCInt for EventOpenOrCreateError { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_event_open_or_create_error_string( + error: iox2_event_open_or_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Sets the max notifiers for the builder /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs b/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs index b87464509..86ec52398 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs @@ -26,6 +26,8 @@ use iceoryx2::service::builder::publish_subscribe::{ }; use iceoryx2::service::port_factory::publish_subscribe::PortFactory; use iceoryx2::service::static_config::message_type_details::{TypeDetail, TypeVariant}; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_bb_log::fatal_panic; use core::ffi::{c_char, c_int}; @@ -36,32 +38,55 @@ use std::alloc::Layout; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_pub_sub_open_or_create_error_e { + #[StaticString = "does not exist"] O_DOES_NOT_EXIST = IOX2_OK as isize + 1, + #[StaticString = "internal failure"] O_INTERNAL_FAILURE, + #[StaticString = "incompatible types"] O_INCOMPATIBLE_TYPES, + #[StaticString = "incompatible messaging pattern"] O_INCOMPATIBLE_MESSAGING_PATTERN, + #[StaticString = "incompatible attributes"] O_INCOMPATIBLE_ATTRIBUTES, + #[StaticString = "does not support requested min buffer size"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_BUFFER_SIZE, + #[StaticString = "does not support requested min history size"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_HISTORY_SIZE, + #[StaticString = "does not support requested min subscriber borrowed samples"] O_DOES_NOT_SUPPORT_REQUESTED_MIN_SUBSCRIBER_BORROWED_SAMPLES, + #[StaticString = "does not support requested amount of publishers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_PUBLISHERS, + #[StaticString = "does not support requested amount of subscribers"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_SUBSCRIBERS, + #[StaticString = "does not support requested amount of nodes"] O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES, + #[StaticString = "incompatible overflow behavior"] O_INCOMPATIBLE_OVERFLOW_BEHAVIOR, + #[StaticString = "insufficient permissions"] O_INSUFFICIENT_PERMISSIONS, + #[StaticString = "service in corrupted state"] O_SERVICE_IN_CORRUPTED_STATE, + #[StaticString = "hangs in creation"] O_HANGS_IN_CREATION, + #[StaticString = "exceeds max number of nodes"] O_EXCEEDS_MAX_NUMBER_OF_NODES, + #[StaticString = "is marked for destruction"] O_IS_MARKED_FOR_DESTRUCTION, + #[StaticString = "service in corrupted state"] C_SERVICE_IN_CORRUPTED_STATE, + #[StaticString = "subscriber buffer must be larger than history size"] C_SUBSCRIBER_BUFFER_MUST_BE_LARGER_THAN_HISTORY_SIZE, + #[StaticString = "already exists"] C_ALREADY_EXISTS, + #[StaticString = "insufficient permissions"] C_INSUFFICIENT_PERMISSIONS, + #[StaticString = "internal failure"] C_INTERNAL_FAILURE, + #[StaticString = "is being created by another instance"] C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, - C_OLD_CONNECTION_STILL_ACTIVE, + #[StaticString = "hangs in creation"] C_HANGS_IN_CREATION, } @@ -200,6 +225,13 @@ pub enum iox2_type_detail_error_e { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_pub_sub_open_or_create_error_string( + error: iox2_pub_sub_open_or_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Sets the user header type details for the builder /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/subscriber.rs b/iceoryx2-ffi/ffi/src/api/subscriber.rs index e041c6ad1..62957d9ea 100644 --- a/iceoryx2-ffi/ffi/src/api/subscriber.rs +++ b/iceoryx2-ffi/ffi/src/api/subscriber.rs @@ -21,16 +21,18 @@ use crate::api::{ use iceoryx2::port::subscriber::{Subscriber, SubscriberReceiveError}; use iceoryx2::port::update_connections::{ConnectionFailure, UpdateConnections}; use iceoryx2::prelude::*; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_subscriber_receive_error_e { EXCEEDS_MAX_BORROWED_SAMPLES = IOX2_OK as isize + 1, FAILED_TO_ESTABLISH_CONNECTION, @@ -54,7 +56,7 @@ impl IntoCInt for SubscriberReceiveError { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_connection_failure_e { FAILED_TO_ESTABLISH_CONNECTION, UNABLE_TO_MAP_PUBLISHERS_DATA_SEGMENT, @@ -161,6 +163,20 @@ impl HandleToType for iox2_subscriber_h_ref { // BEGIN C API +#[no_mangle] +pub unsafe extern "C" fn iox2_subscriber_receive_error_string( + error: iox2_subscriber_receive_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + +#[no_mangle] +pub unsafe extern "C" fn iox2_connection_failure_string( + error: iox2_connection_failure_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Returns the buffer size of the subscriber /// /// # Arguments diff --git a/iceoryx2-ffi/ffi/src/api/waitset.rs b/iceoryx2-ffi/ffi/src/api/waitset.rs index 2a41bb975..8674de625 100644 --- a/iceoryx2-ffi/ffi/src/api/waitset.rs +++ b/iceoryx2-ffi/ffi/src/api/waitset.rs @@ -12,7 +12,7 @@ #![allow(non_camel_case_types)] -use std::{ffi::c_int, mem::ManuallyDrop, time::Duration}; +use std::{ffi::c_char, ffi::c_int, mem::ManuallyDrop, time::Duration}; use crate::{ c_size_t, iox2_callback_context, iox2_callback_progression_e, iox2_file_descriptor_ptr, @@ -27,13 +27,15 @@ use iceoryx2::{ }, service::{ipc, local}, }; +use iceoryx2_bb_derive_macros::StaticStringRepresentation; use iceoryx2_bb_elementary::static_assert::*; +use iceoryx2_bb_elementary::AsStaticString; use iceoryx2_ffi_macros::iceoryx2_ffi; // BEGIN types definition #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_waitset_run_error_e { INSUFFICIENT_PERMISSIONS = IOX2_OK as isize + 1, INTERNAL_ERROR, @@ -81,7 +83,7 @@ impl From for iox2_waitset_run_result_e { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_waitset_attachment_error_e { INSUFFICIENT_CAPACITY = IOX2_OK as isize + 1, ALREADY_ATTACHED, @@ -105,7 +107,7 @@ impl IntoCInt for WaitSetAttachmentError { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StaticStringRepresentation)] pub enum iox2_waitset_create_error_e { INTERNAL_ERROR = IOX2_OK as isize + 1, } @@ -208,6 +210,28 @@ pub type iox2_waitset_run_callback = extern "C" fn( // END type definition // BEGIN C API + +#[no_mangle] +pub unsafe extern "C" fn iox2_waitset_create_error_string( + error: iox2_waitset_create_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + +#[no_mangle] +pub unsafe extern "C" fn iox2_waitset_attachment_error_string( + error: iox2_waitset_attachment_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + +#[no_mangle] +pub unsafe extern "C" fn iox2_waitset_run_error_string( + error: iox2_waitset_run_error_e, +) -> *const c_char { + error.as_static_str().as_ptr() as *const c_char +} + /// Drops a [`iox2_waitset_h`] and calls all corresponding cleanup functions. /// /// # Safety