diff --git a/iceoryx2-ffi/cxx/CMakeLists.txt b/iceoryx2-ffi/cxx/CMakeLists.txt index 6a56ec0dc..85730b0ff 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_as_string.cpp src/event_id.cpp src/file_descriptor.cpp src/header_publish_subscribe.cpp diff --git a/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp b/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp index 5a36cc762..48ca6e7b8 100644 --- a/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp @@ -222,13 +222,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 +310,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 +361,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 +439,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 +489,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 +549,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 +556,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); 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..870d336a0 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,12 @@ enum class EventOpenOrCreateError : uint8_t { /// [`SampleMut`] in use. CreateOldConnectionsStillActive, }; + + +auto as_string(const iox2::EventOpenError& error) -> const char*; +auto as_string(const iox2::EventCreateError& error) -> const char*; +auto as_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..8ffa8a048 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 as_string(const iox2::PublishSubscribeOpenError& error) -> const char*; +auto as_string(const iox2::PublishSubscribeCreateError& error) -> const char*; +auto as_string(const iox2::PublishSubscribeOpenOrCreateError& error) -> const char*; + } // namespace iox2 #endif diff --git a/iceoryx2-ffi/cxx/src/error_as_string.cpp b/iceoryx2-ffi/cxx/src/error_as_string.cpp new file mode 100644 index 000000000..8f9099d62 --- /dev/null +++ b/iceoryx2-ffi/cxx/src/error_as_string.cpp @@ -0,0 +1,43 @@ +// 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/enum_translation.hpp" +#include "iox2/service_builder_event_error.hpp" +#include "iox2/service_builder_publish_subscribe_error.hpp" + +namespace iox2 { + +auto as_string(const iox2::PublishSubscribeOpenError& error) -> const char* { + return iox2_pub_sub_open_or_create_error_string(iox::into(error)); +} + +auto as_string(const iox2::PublishSubscribeCreateError& error) -> const char* { + return iox2_pub_sub_open_or_create_error_string(iox::into(error)); +} + +auto as_string(const iox2::PublishSubscribeOpenOrCreateError& error) -> const char* { + return iox2_pub_sub_open_or_create_error_string(iox::into(error)); +} + +auto as_string(const iox2::EventOpenError& error) -> const char* { + return iox2_event_open_or_create_error_string(iox::into(error)); +} + +auto as_string(const iox2::EventCreateError& error) -> const char* { + return iox2_event_open_or_create_error_string(iox::into(error)); +} + +auto as_string(const iox2::EventOpenOrCreateError& error) -> const char* { + return iox2_event_open_or_create_error_string(iox::into(error)); +} + +} // namespace iox2 diff --git a/iceoryx2-ffi/ffi/src/api/error.rs b/iceoryx2-ffi/ffi/src/api/error.rs new file mode 100644 index 000000000..d05c67a30 --- /dev/null +++ b/iceoryx2-ffi/ffi/src/api/error.rs @@ -0,0 +1,144 @@ +// 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 9790b1875..ea8f1b4ba 100644 --- a/iceoryx2-ffi/ffi/src/api/mod.rs +++ b/iceoryx2-ffi/ffi/src/api/mod.rs @@ -18,6 +18,7 @@ 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; @@ -58,6 +59,7 @@ 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 a55496a9e..887c3f0f4 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, HandleToType, - IntoCInt, PortFactoryEventUnion, ServiceBuilderUnion, IOX2_OK, + iox2_service_builder_event_h_ref, iox2_service_type_e, AssertNonNullHandle, ErrorAsString, + HandleToType, IntoCInt, PortFactoryEventUnion, ServiceBuilderUnion, IOX2_OK, }; use iceoryx2::prelude::*; @@ -24,7 +24,7 @@ use iceoryx2::service::builder::event::{ }; use iceoryx2::service::port_factory::event::PortFactory; -use core::ffi::c_int; +use core::ffi::{c_char, c_int}; use core::mem::ManuallyDrop; // BEGIN types definition @@ -51,7 +51,70 @@ pub enum iox2_event_open_or_create_error_e { C_ALREADY_EXISTS, C_HANGS_IN_CREATION, C_INSUFFICIENT_PERMISSIONS, - C_OLD_CONNECTION_STILL_ACTIVE, +} + +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 { @@ -135,6 +198,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_cstr() +} + /// 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 e954797a3..d0a3cba7a 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, HandleToType, IntoCInt, PayloadFfi, PortFactoryPubSubUnion, + AssertNonNullHandle, ErrorAsString, HandleToType, IntoCInt, PayloadFfi, PortFactoryPubSubUnion, ServiceBuilderUnion, UserHeaderFfi, IOX2_OK, }; @@ -61,10 +61,40 @@ pub enum iox2_pub_sub_open_or_create_error_e { C_INSUFFICIENT_PERMISSIONS, C_INTERNAL_FAILURE, C_IS_BEING_CREATED_BY_ANOTHER_INSTANCE, - C_OLD_CONNECTION_STILL_ACTIVE, 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 { @@ -200,6 +230,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_cstr() +} + /// Sets the user header type details for the builder /// /// # Arguments