From b30336661c0d7df1d51420250dec934d5a0a51c5 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Fri, 25 Oct 2024 05:03:42 +0200 Subject: [PATCH] WIP: Propagate errors from iceoryx2 --- iceoryx2-bb/derive-macros/src/lib.rs | 95 +++++++++++- .../elementary/src/as_static_string.rs | 15 ++ iceoryx2-bb/elementary/src/lib.rs | 5 +- iceoryx2-ffi/ffi/Cargo.toml | 1 + iceoryx2-ffi/ffi/src/api/error.rs | 144 ------------------ iceoryx2-ffi/ffi/src/api/mod.rs | 2 - .../ffi/src/api/service_builder_event.rs | 93 +++-------- .../ffi/src/api/service_builder_pub_sub.rs | 63 ++++---- 8 files changed, 168 insertions(+), 250 deletions(-) create mode 100644 iceoryx2-bb/elementary/src/as_static_string.rs delete mode 100644 iceoryx2-ffi/ffi/src/api/error.rs diff --git a/iceoryx2-bb/derive-macros/src/lib.rs b/iceoryx2-bb/derive-macros/src/lib.rs index 1b338048c..7ffea4954 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,96 @@ 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(|| { + // Default to converting variant name to snake_case with spaces + let variant_str = variant_ident.to_string(); + variant_str + .chars() + .enumerate() + .map(|(i, c)| { + if i > 0 && c.is_uppercase() { + format!(" {}", c.to_lowercase()) + } else { + c.to_lowercase().to_string() + } + }) + .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/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/src/api/error.rs b/iceoryx2-ffi/ffi/src/api/error.rs deleted file mode 100644 index d05c67a30..000000000 --- a/iceoryx2-ffi/ffi/src/api/error.rs +++ /dev/null @@ -1,144 +0,0 @@ -// 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 - -use std::os::raw::c_char; - -use iceoryx2::service::builder::{ - event::{EventCreateError, EventOpenError, EventOpenOrCreateError}, - publish_subscribe::{ - PublishSubscribeCreateError, PublishSubscribeOpenError, PublishSubscribeOpenOrCreateError, - }, -}; - -pub trait ErrorAsString { - fn as_str(&self) -> &'static str; - fn as_cstr(&self) -> *const c_char { - self.as_str().as_ptr() as *const c_char - } -} - -impl ErrorAsString for PublishSubscribeCreateError { - fn as_str(&self) -> &'static str { - match self { - PublishSubscribeCreateError::ServiceInCorruptedState => "ServiceInCorruptedState", - PublishSubscribeCreateError::SubscriberBufferMustBeLargerThanHistorySize => { - "SubscriberBufferMustBeLargerThanHistorySize" - } - PublishSubscribeCreateError::AlreadyExists => "AlreadyExists", - PublishSubscribeCreateError::InsufficientPermissions => "InsufficientPermissions", - PublishSubscribeCreateError::InternalFailure => "InternalFailure", - PublishSubscribeCreateError::IsBeingCreatedByAnotherInstance => { - "IsBeingCreatedByAnotherInstance" - } - PublishSubscribeCreateError::HangsInCreation => "HangsInCreation", - } - } -} - -impl ErrorAsString for PublishSubscribeOpenError { - fn as_str(&self) -> &'static str { - match self { - PublishSubscribeOpenError::DoesNotExist => "DoesNotExist", - PublishSubscribeOpenError::InternalFailure => "InternalFailure", - PublishSubscribeOpenError::IncompatibleTypes => "IncompatibleTypes", - PublishSubscribeOpenError::IncompatibleMessagingPattern => { - "IncompatibleMessagingPattern" - } - PublishSubscribeOpenError::IncompatibleAttributes => "IncompatibleAttributes", - PublishSubscribeOpenError::DoesNotSupportRequestedMinBufferSize => { - "DoesNotSupportRequestedMinBufferSize" - } - PublishSubscribeOpenError::DoesNotSupportRequestedMinHistorySize => { - "DoesNotSupportRequestedMinHistorySize" - } - PublishSubscribeOpenError::DoesNotSupportRequestedMinSubscriberBorrowedSamples => { - "DoesNotSupportRequestedMinSubscriberBorrowedSamples" - } - PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfPublishers => { - "DoesNotSupportRequestedAmountOfPublishers" - } - PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfSubscribers => { - "DoesNotSupportRequestedAmountOfSubscribers" - } - PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfNodes => { - "DoesNotSupportRequestedAmountOfNodes" - } - PublishSubscribeOpenError::IncompatibleOverflowBehavior => { - "IncompatibleOverflowBehavior" - } - PublishSubscribeOpenError::InsufficientPermissions => "InsufficientPermissions", - PublishSubscribeOpenError::ServiceInCorruptedState => "ServiceInCorruptedState", - PublishSubscribeOpenError::HangsInCreation => "HangsInCreation", - PublishSubscribeOpenError::ExceedsMaxNumberOfNodes => "ExceedsMaxNumberOfNodes", - PublishSubscribeOpenError::IsMarkedForDestruction => "IsMarkedForDestruction", - } - } -} - -impl ErrorAsString for PublishSubscribeOpenOrCreateError { - fn as_str(&self) -> &'static str { - match self { - PublishSubscribeOpenOrCreateError::PublishSubscribeOpenError(_) => todo!(), - PublishSubscribeOpenOrCreateError::PublishSubscribeCreateError(_) => todo!(), - } - } -} - -impl ErrorAsString for EventOpenError { - fn as_str(&self) -> &'static str { - match self { - EventOpenError::DoesNotExist => "DoesNotExist", - EventOpenError::InsufficientPermissions => "InsufficientPermissions", - EventOpenError::ServiceInCorruptedState => "ServiceInCorruptedState", - EventOpenError::IncompatibleMessagingPattern => "IncompatibleMessagingPattern", - EventOpenError::IncompatibleAttributes => "IncompatibleAttributes", - EventOpenError::InternalFailure => "InternalFailure", - EventOpenError::HangsInCreation => "HangsInCreation", - EventOpenError::DoesNotSupportRequestedAmountOfNotifiers => { - "DoesNotSupportRequestedAmountOfNotifiers" - } - EventOpenError::DoesNotSupportRequestedAmountOfListeners => { - "DoesNotSupportRequestedAmountOfListeners" - } - EventOpenError::DoesNotSupportRequestedMaxEventId => { - "DoesNotSupportRequestedMaxEventId" - } - EventOpenError::DoesNotSupportRequestedAmountOfNodes => { - "DoesNotSupportRequestedAmountOfNodes" - } - EventOpenError::ExceedsMaxNumberOfNodes => "ExceedsMaxNumberOfNodes", - EventOpenError::IsMarkedForDestruction => "IsMarkedForDestruction", - } - } -} - -impl ErrorAsString for EventCreateError { - fn as_str(&self) -> &'static str { - match self { - EventCreateError::ServiceInCorruptedState => "ServiceInCorruptedState", - EventCreateError::InternalFailure => "InternalFailure", - EventCreateError::IsBeingCreatedByAnotherInstance => "IsBeingCreatedByAnotherInstance", - EventCreateError::AlreadyExists => "AlreadyExists", - EventCreateError::HangsInCreation => "HangsInCreation", - EventCreateError::InsufficientPermissions => "InsufficientPermissions", - } - } -} - -impl ErrorAsString for EventOpenOrCreateError { - fn as_str(&self) -> &'static str { - match self { - EventOpenOrCreateError::EventOpenError(e) => e.as_str(), - EventOpenOrCreateError::EventCreateError(e) => e.as_str(), - } - } -} diff --git a/iceoryx2-ffi/ffi/src/api/mod.rs b/iceoryx2-ffi/ffi/src/api/mod.rs index ea8f1b4ba..9790b1875 100644 --- a/iceoryx2-ffi/ffi/src/api/mod.rs +++ b/iceoryx2-ffi/ffi/src/api/mod.rs @@ -18,7 +18,6 @@ use iceoryx2_bb_container::semantic_string::SemanticStringError; use core::ffi::{c_int, c_void}; mod config; -mod error; mod event_id; mod file_descriptor; mod iceoryx2_settings; @@ -59,7 +58,6 @@ mod waitset_builder; mod waitset_guard; pub use config::*; -pub use error::*; pub use event_id::*; pub use file_descriptor::*; pub use iceoryx2_settings::*; diff --git a/iceoryx2-ffi/ffi/src/api/service_builder_event.rs b/iceoryx2-ffi/ffi/src/api/service_builder_event.rs index 887c3f0f4..cf3676641 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_event.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_event.rs @@ -14,8 +14,8 @@ use crate::api::{ c_size_t, iox2_port_factory_event_h, iox2_port_factory_event_t, iox2_service_builder_event_h, - iox2_service_builder_event_h_ref, iox2_service_type_e, AssertNonNullHandle, ErrorAsString, - HandleToType, IntoCInt, PortFactoryEventUnion, ServiceBuilderUnion, IOX2_OK, + iox2_service_builder_event_h_ref, iox2_service_type_e, AssertNonNullHandle, HandleToType, + IntoCInt, PortFactoryEventUnion, ServiceBuilderUnion, IOX2_OK, }; use iceoryx2::prelude::*; @@ -23,6 +23,8 @@ 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_char, c_int}; use core::mem::ManuallyDrop; @@ -30,93 +32,48 @@ 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, } -impl ErrorAsString for iox2_event_open_or_create_error_e { - fn as_str(&self) -> &'static str { - match self { - iox2_event_open_or_create_error_e::O_DOES_NOT_EXIST => { - EventOpenError::DoesNotExist.as_str() - } - iox2_event_open_or_create_error_e::O_INSUFFICIENT_PERMISSIONS => { - EventOpenError::InsufficientPermissions.as_str() - } - iox2_event_open_or_create_error_e::O_SERVICE_IN_CORRUPTED_STATE => { - EventOpenError::ServiceInCorruptedState.as_str() - } - iox2_event_open_or_create_error_e::O_INCOMPATIBLE_MESSAGING_PATTERN => { - EventOpenError::IncompatibleMessagingPattern.as_str() - } - iox2_event_open_or_create_error_e::O_INCOMPATIBLE_ATTRIBUTES => { - EventOpenError::IncompatibleAttributes.as_str() - } - iox2_event_open_or_create_error_e::O_INTERNAL_FAILURE => { - EventOpenError::InternalFailure.as_str() - } - iox2_event_open_or_create_error_e::O_HANGS_IN_CREATION => { - EventOpenError::HangsInCreation.as_str() - } - iox2_event_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NOTIFIERS => { - EventOpenError::DoesNotSupportRequestedAmountOfNotifiers.as_str() - } - iox2_event_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_LISTENERS => { - EventOpenError::DoesNotSupportRequestedAmountOfListeners.as_str() - } - iox2_event_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_MAX_EVENT_ID => { - EventOpenError::DoesNotSupportRequestedMaxEventId.as_str() - } - iox2_event_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES => { - EventOpenError::DoesNotSupportRequestedAmountOfNodes.as_str() - } - iox2_event_open_or_create_error_e::O_EXCEEDS_MAX_NUMBER_OF_NODES => { - EventOpenError::ExceedsMaxNumberOfNodes.as_str() - } - iox2_event_open_or_create_error_e::O_IS_MARKED_FOR_DESTRUCTION => { - EventOpenError::IsMarkedForDestruction.as_str() - } - iox2_event_open_or_create_error_e::C_SERVICE_IN_CORRUPTED_STATE => { - EventCreateError::ServiceInCorruptedState.as_str() - } - iox2_event_open_or_create_error_e::C_INTERNAL_FAILURE => { - EventCreateError::InternalFailure.as_str() - } - iox2_event_open_or_create_error_e::C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE => { - EventCreateError::IsBeingCreatedByAnotherInstance.as_str() - } - iox2_event_open_or_create_error_e::C_ALREADY_EXISTS => { - EventCreateError::AlreadyExists.as_str() - } - iox2_event_open_or_create_error_e::C_HANGS_IN_CREATION => { - EventCreateError::HangsInCreation.as_str() - } - iox2_event_open_or_create_error_e::C_INSUFFICIENT_PERMISSIONS => { - EventCreateError::InsufficientPermissions.as_str() - } - } - } -} - impl IntoCInt for EventOpenError { fn into_c_int(self) -> c_int { (match self { @@ -202,7 +159,7 @@ impl IntoCInt for EventOpenOrCreateError { 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_cstr() + error.as_static_str().as_ptr() as *const c_char } /// Sets the max notifiers for the builder 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 d0a3cba7a..1468ea153 100644 --- a/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs +++ b/iceoryx2-ffi/ffi/src/api/service_builder_pub_sub.rs @@ -15,7 +15,7 @@ use crate::api::{ c_size_t, iox2_port_factory_pub_sub_h, iox2_port_factory_pub_sub_t, iox2_service_builder_pub_sub_h, iox2_service_builder_pub_sub_h_ref, iox2_service_type_e, - AssertNonNullHandle, ErrorAsString, HandleToType, IntoCInt, PayloadFfi, PortFactoryPubSubUnion, + AssertNonNullHandle, HandleToType, IntoCInt, PayloadFfi, PortFactoryPubSubUnion, ServiceBuilderUnion, UserHeaderFfi, IOX2_OK, }; @@ -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,65 +38,58 @@ 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, + #[StaticString = "hangs in creation"] C_HANGS_IN_CREATION, } -impl ErrorAsString for iox2_pub_sub_open_or_create_error_e { - fn as_str(&self) -> &'static str { - match self { - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_EXIST => PublishSubscribeOpenError::DoesNotExist.as_str(), - iox2_pub_sub_open_or_create_error_e::O_INTERNAL_FAILURE => PublishSubscribeOpenError::InternalFailure.as_str(), - iox2_pub_sub_open_or_create_error_e::O_INCOMPATIBLE_TYPES => PublishSubscribeOpenError::IncompatibleTypes.as_str(), - iox2_pub_sub_open_or_create_error_e::O_INCOMPATIBLE_MESSAGING_PATTERN => PublishSubscribeOpenError::IncompatibleMessagingPattern.as_str(), - iox2_pub_sub_open_or_create_error_e::O_INCOMPATIBLE_ATTRIBUTES => PublishSubscribeOpenError::IncompatibleAttributes.as_str(), - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_MIN_BUFFER_SIZE => PublishSubscribeOpenError::DoesNotSupportRequestedMinBufferSize.as_str(), - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_MIN_HISTORY_SIZE => PublishSubscribeOpenError::DoesNotSupportRequestedMinHistorySize.as_str(), - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_MIN_SUBSCRIBER_BORROWED_SAMPLES => PublishSubscribeOpenError::DoesNotSupportRequestedMinSubscriberBorrowedSamples.as_str(), - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_PUBLISHERS => PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfPublishers.as_str(), - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_SUBSCRIBERS => PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfSubscribers.as_str(), - iox2_pub_sub_open_or_create_error_e::O_DOES_NOT_SUPPORT_REQUESTED_AMOUNT_OF_NODES => PublishSubscribeOpenError::DoesNotSupportRequestedAmountOfNodes.as_str(), - iox2_pub_sub_open_or_create_error_e::O_INCOMPATIBLE_OVERFLOW_BEHAVIOR => PublishSubscribeOpenError::IncompatibleOverflowBehavior.as_str(), - iox2_pub_sub_open_or_create_error_e::O_INSUFFICIENT_PERMISSIONS => PublishSubscribeOpenError::InsufficientPermissions.as_str(), - iox2_pub_sub_open_or_create_error_e::O_SERVICE_IN_CORRUPTED_STATE => PublishSubscribeOpenError::ServiceInCorruptedState.as_str(), - iox2_pub_sub_open_or_create_error_e::O_HANGS_IN_CREATION => PublishSubscribeOpenError::HangsInCreation.as_str(), - iox2_pub_sub_open_or_create_error_e::O_EXCEEDS_MAX_NUMBER_OF_NODES => PublishSubscribeOpenError::ExceedsMaxNumberOfNodes.as_str(), - iox2_pub_sub_open_or_create_error_e::O_IS_MARKED_FOR_DESTRUCTION => PublishSubscribeOpenError::IsMarkedForDestruction.as_str(), - iox2_pub_sub_open_or_create_error_e::C_SERVICE_IN_CORRUPTED_STATE => PublishSubscribeCreateError::ServiceInCorruptedState.as_str(), - iox2_pub_sub_open_or_create_error_e::C_SUBSCRIBER_BUFFER_MUST_BE_LARGER_THAN_HISTORY_SIZE => PublishSubscribeCreateError::SubscriberBufferMustBeLargerThanHistorySize.as_str(), - iox2_pub_sub_open_or_create_error_e::C_ALREADY_EXISTS => PublishSubscribeCreateError::AlreadyExists.as_str(), - iox2_pub_sub_open_or_create_error_e::C_INSUFFICIENT_PERMISSIONS => PublishSubscribeCreateError::InsufficientPermissions.as_str(), - iox2_pub_sub_open_or_create_error_e::C_INTERNAL_FAILURE => PublishSubscribeCreateError::InternalFailure.as_str(), - iox2_pub_sub_open_or_create_error_e::C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE => PublishSubscribeCreateError::IsBeingCreatedByAnotherInstance.as_str(), - iox2_pub_sub_open_or_create_error_e::C_HANGS_IN_CREATION => PublishSubscribeCreateError::HangsInCreation.as_str(), - } - } -} - impl IntoCInt for PublishSubscribeOpenError { fn into_c_int(self) -> c_int { (match self { @@ -234,7 +229,7 @@ pub enum iox2_type_detail_error_e { 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_cstr() + error.as_static_str().as_ptr() as *const c_char } /// Sets the user header type details for the builder