diff --git a/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp b/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp index 6e186fd46..54af04053 100644 --- a/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp @@ -299,6 +299,8 @@ 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(); @@ -347,6 +349,8 @@ constexpr auto from( 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; + case iox2::EventCreateError::OldConnectionsStillActive: + return iox2_event_open_or_create_error_e_C_OLD_CONNECTION_STILL_ACTIVE; default: IOX_UNREACHABLE(); } @@ -518,6 +524,8 @@ constexpr auto from(const int valu return iox2::PublishSubscribeOpenOrCreateError::CreateIsBeingCreatedByAnotherInstance; case iox2_pub_sub_open_or_create_error_e_C_HANGS_IN_CREATION: return iox2::PublishSubscribeOpenOrCreateError::CreateHangsInCreation; + case iox2_pub_sub_open_or_create_error_e_C_OLD_CONNECTION_STILL_ACTIVE: + return iox2::PublishSubscribeOpenOrCreateError::CreateOldConnectionsStillActive; } IOX_UNREACHABLE(); @@ -708,6 +716,8 @@ constexpr auto from(const int value) noexcept -> io IOX_UNREACHABLE(); } +template <> +constexpr auto from(const iox2::WaitSetRunResult value) noexcept + -> iox2_waitset_run_result_e { + switch (value) { + case iox2::WaitSetRunResult::Interrupt: + return iox2_waitset_run_result_e_INTERRUPT; + case iox2::WaitSetRunResult::TerminationRequest: + return iox2_waitset_run_result_e_TERMINATION_REQUEST; + case iox2::WaitSetRunResult::StopRequest: + return iox2_waitset_run_result_e_STOP_REQUEST; + case iox2::WaitSetRunResult::AllEventsHandled: + return iox2_waitset_run_result_e_ALL_EVENTS_HANDLED; + } + + IOX_UNREACHABLE(); +} + template <> constexpr auto from(const int value) noexcept -> iox2::WaitSetAttachmentError { const auto variant = static_cast(value); diff --git a/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp b/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp index 05aea58c2..991651adf 100644 --- a/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/waitset_enums.hpp @@ -60,6 +60,7 @@ enum class WaitSetRunError : uint8_t { }; auto error_string(const iox2::WaitSetCreateError& error) -> const char*; +auto error_string(const iox2::WaitSetRunResult& error) -> const char*; auto error_string(const iox2::WaitSetAttachmentError& error) -> const char*; auto error_string(const iox2::WaitSetRunError& error) -> const char*; diff --git a/iceoryx2-ffi/cxx/src/error_string.cpp b/iceoryx2-ffi/cxx/src/error_string.cpp index 56f54b473..81a3d0fb8 100644 --- a/iceoryx2-ffi/cxx/src/error_string.cpp +++ b/iceoryx2-ffi/cxx/src/error_string.cpp @@ -132,4 +132,8 @@ auto error_string(const iox2::WaitSetRunError& error) -> const char* { return iox2_waitset_run_error_string(iox::into(error)); } +auto error_string(const iox2::WaitSetRunResult& error) -> const char* { + return iox2_waitset_run_result_string(iox::into(error)); +} + } // namespace iox2 diff --git a/iceoryx2-ffi/cxx/tests/src/error_string_tests.cpp b/iceoryx2-ffi/cxx/tests/src/error_string_tests.cpp new file mode 100644 index 000000000..a481f6363 --- /dev/null +++ b/iceoryx2-ffi/cxx/tests/src/error_string_tests.cpp @@ -0,0 +1,284 @@ +// 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 "test.hpp" + +#include "iox2/config_creation_error.hpp" +#include "iox2/connection_failure.hpp" +#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/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 { + +using iox2::error_string; + +TEST(ErrorStringTest, config_creation_error_string) { + using Sut = iox2::ConfigCreationError; + ASSERT_GT(strlen(error_string(Sut::FailedToOpenConfigFile)), 1U); + ASSERT_GT(strlen(error_string(Sut::UnableToDeserializeContents)), 1U); + ASSERT_GT(strlen(error_string(Sut::FailedToReadConfigFileContents)), 1U); +} + +TEST(ErrorStringTest, connection_failure_string) { + using Sut = iox2::ConnectionFailure; + ASSERT_GT(strlen(error_string(Sut::FailedToEstablishConnection)), 1U); + ASSERT_GT(strlen(error_string(Sut::UnableToMapPublishersDataSegment)), 1U); +} + +TEST(ErrorStringTest, listener_create_error_string) { + using Sut = iox2::ListenerCreateError; + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxSupportedListeners)), 1U); + ASSERT_GT(strlen(error_string(Sut::ResourceCreationFailed)), 1U); +} + +TEST(ErrorStringTest, listener_wait_error_string) { + using Sut = iox2::ListenerWaitError; + ASSERT_GT(strlen(error_string(Sut::ContractViolation)), 1U); + ASSERT_GT(strlen(error_string(Sut::InterruptSignal)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalFailure)), 1U); +} + +TEST(ErrorStringTest, node_list_failure_string) { + using Sut = iox2::NodeListFailure; + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); + ASSERT_GT(strlen(error_string(Sut::Interrupt)), 1U); +} + +TEST(ErrorStringTest, node_creation_failure_string) { + using Sut = iox2::NodeCreationFailure; + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); +} + +TEST(ErrorStringTest, node_wait_failure_string) { + using Sut = iox2::NodeWaitFailure; + ASSERT_GT(strlen(error_string(Sut::TerminationRequest)), 1U); + ASSERT_GT(strlen(error_string(Sut::Interrupt)), 1U); +} + +TEST(ErrorStringTest, notifier_create_error_string) { + using Sut = iox2::NotifierCreateError; + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxSupportedNotifiers)), 1U); +} + +TEST(ErrorStringTest, notifier_notify_error_string) { + using Sut = iox2::NotifierNotifyError; + ASSERT_GT(strlen(error_string(Sut::EventIdOutOfBounds)), 1U); +} + +TEST(ErrorStringTest, publisher_create_error_string) { + using Sut = iox2::PublisherCreateError; + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxSupportedPublishers)), 1U); + ASSERT_GT(strlen(error_string(Sut::UnableToCreateDataSegment)), 1U); +} + +TEST(ErrorStringTest, publisher_loan_error_string) { + using Sut = iox2::PublisherLoanError; + ASSERT_GT(strlen(error_string(Sut::OutOfMemory)), 1U); + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxLoanedSamples)), 1U); + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxLoanSize)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalFailure)), 1U); +} + +TEST(ErrorStringTest, publisher_send_error_string) { + using Sut = iox2::PublisherSendError; + ASSERT_GT(strlen(error_string(Sut::ConnectionBrokenSincePublisherNoLongerExists)), 1U); + ASSERT_GT(strlen(error_string(Sut::ConnectionCorrupted)), 1U); + ASSERT_GT(strlen(error_string(Sut::LoanErrorOutOfMemory)), 1U); + ASSERT_GT(strlen(error_string(Sut::LoanErrorExceedsMaxLoanedSamples)), 1U); + ASSERT_GT(strlen(error_string(Sut::LoanErrorExceedsMaxLoanSize)), 1U); + ASSERT_GT(strlen(error_string(Sut::LoanErrorInternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::ConnectionError)), 1U); +} + +TEST(ErrorStringTest, event_open_error_string) { + using Sut = iox2::EventOpenError; + ASSERT_GT(strlen(error_string(Sut::DoesNotExist)), 1U); + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::ServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::IncompatibleMessagingPattern)), 1U); + ASSERT_GT(strlen(error_string(Sut::IncompatibleAttributes)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::HangsInCreation)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedAmountOfNotifiers)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedAmountOfListeners)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedMaxEventId)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedAmountOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxNumberOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::IsMarkedForDestruction)), 1U); +} + +TEST(ErrorStringTest, event_create_error_string) { + using Sut = iox2::EventCreateError; + ASSERT_GT(strlen(error_string(Sut::ServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::IsBeingCreatedByAnotherInstance)), 1U); + ASSERT_GT(strlen(error_string(Sut::AlreadyExists)), 1U); + ASSERT_GT(strlen(error_string(Sut::HangsInCreation)), 1U); + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::OldConnectionsStillActive)), 1U); +} + +TEST(ErrorStringTest, event_open_or_create_error_string) { + using Sut = iox2::EventOpenOrCreateError; + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotExist)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenInsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIncompatibleMessagingPattern)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIncompatibleAttributes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenInternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenHangsInCreation)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedAmountOfNotifiers)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedAmountOfListeners)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedMaxEventId)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedAmountOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenExceedsMaxNumberOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIsMarkedForDestruction)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateInternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateIsBeingCreatedByAnotherInstance)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateAlreadyExists)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateHangsInCreation)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateInsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateOldConnectionsStillActive)), 1U); +} + +TEST(ErrorStringTest, publish_subscribe_open_error_string) { + using Sut = iox2::PublishSubscribeOpenError; + ASSERT_GT(strlen(error_string(Sut::DoesNotExist)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::IncompatibleTypes)), 1U); + ASSERT_GT(strlen(error_string(Sut::IncompatibleMessagingPattern)), 1U); + ASSERT_GT(strlen(error_string(Sut::IncompatibleAttributes)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedMinBufferSize)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedMinHistorySize)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedMinSubscriberBorrowedSamples)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedAmountOfPublishers)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedAmountOfSubscribers)), 1U); + ASSERT_GT(strlen(error_string(Sut::DoesNotSupportRequestedAmountOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::IncompatibleOverflowBehavior)), 1U); + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::ServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::HangsInCreation)), 1U); + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxNumberOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::IsMarkedForDestruction)), 1U); +} + +TEST(ErrorStringTest, publish_subscribe_create_error_string) { + using Sut = iox2::PublishSubscribeCreateError; + ASSERT_GT(strlen(error_string(Sut::ServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::SubscriberBufferMustBeLargerThanHistorySize)), 1U); + ASSERT_GT(strlen(error_string(Sut::AlreadyExists)), 1U); + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::IsBeingCreatedByAnotherInstance)), 1U); + ASSERT_GT(strlen(error_string(Sut::HangsInCreation)), 1U); +} + +TEST(ErrorStringTest, publish_subscribe_open_or_create_error_string) { + using Sut = iox2::PublishSubscribeOpenOrCreateError; + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotExist)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenInternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIncompatibleTypes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIncompatibleMessagingPattern)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIncompatibleAttributes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedMinBufferSize)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedMinHistorySize)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedMinSubscriberBorrowedSamples)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedAmountOfPublishers)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedAmountOfSubscribers)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenDoesNotSupportRequestedAmountOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIncompatibleOverflowBehavior)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenInsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenHangsInCreation)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenExceedsMaxNumberOfNodes)), 1U); + ASSERT_GT(strlen(error_string(Sut::OpenIsMarkedForDestruction)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateServiceInCorruptedState)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateSubscriberBufferMustBeLargerThanHistorySize)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateAlreadyExists)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateInsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateInternalFailure)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateIsBeingCreatedByAnotherInstance)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateOldConnectionsStillActive)), 1U); + ASSERT_GT(strlen(error_string(Sut::CreateHangsInCreation)), 1U); +} + +TEST(ErrorStringTest, service_details_error_string) { + using Sut = iox2::ServiceDetailsError; + ASSERT_GT(strlen(error_string(Sut::FailedToOpenStaticServiceInfo)), 1U); + ASSERT_GT(strlen(error_string(Sut::FailedToReadStaticServiceInfo)), 1U); + ASSERT_GT(strlen(error_string(Sut::FailedToDeserializeStaticServiceInfo)), 1U); + ASSERT_GT(strlen(error_string(Sut::ServiceInInconsistentState)), 1U); + ASSERT_GT(strlen(error_string(Sut::VersionMismatch)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); + ASSERT_GT(strlen(error_string(Sut::FailedToAcquireNodeState)), 1U); +} + +TEST(ErrorStringTest, service_list_error_string) { + using Sut = iox2::ServiceListError; + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); +} + +TEST(ErrorStringTest, subscriber_receive_error_string) { + using Sut = iox2::SubscriberReceiveError; + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxBorrowedSamples)), 1U); + ASSERT_GT(strlen(error_string(Sut::FailedToEstablishConnection)), 1U); + ASSERT_GT(strlen(error_string(Sut::UnableToMapPublishersDataSegment)), 1U); +} + +TEST(ErrorStringTest, subscriber_create_error_string) { + using Sut = iox2::SubscriberCreateError; + ASSERT_GT(strlen(error_string(Sut::ExceedsMaxSupportedSubscribers)), 1U); + ASSERT_GT(strlen(error_string(Sut::BufferSizeExceedsMaxSupportedBufferSizeOfService)), 1U); +} + +TEST(ErrorStringTest, waitset_create_error_string) { + using Sut = iox2::WaitSetCreateError; + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); +} + +TEST(ErrorStringTest, waitset_run_result_string) { + using Sut = iox2::WaitSetRunResult; + ASSERT_GT(strlen(error_string(Sut::TerminationRequest)), 1U); + ASSERT_GT(strlen(error_string(Sut::Interrupt)), 1U); + ASSERT_GT(strlen(error_string(Sut::StopRequest)), 1U); + ASSERT_GT(strlen(error_string(Sut::AllEventsHandled)), 1U); +} + +TEST(ErrorStringTest, waitset_attachment_error_string) { + using Sut = iox2::WaitSetAttachmentError; + ASSERT_GT(strlen(error_string(Sut::InsufficientCapacity)), 1U); + ASSERT_GT(strlen(error_string(Sut::AlreadyAttached)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); +} + +TEST(ErrorStringTest, waitset_run_error_string) { + using Sut = iox2::WaitSetRunError; + ASSERT_GT(strlen(error_string(Sut::InsufficientPermissions)), 1U); + ASSERT_GT(strlen(error_string(Sut::InternalError)), 1U); + ASSERT_GT(strlen(error_string(Sut::NoAttachments)), 1U); + ASSERT_GT(strlen(error_string(Sut::TerminationRequest)), 1U); + ASSERT_GT(strlen(error_string(Sut::Interrupt)), 1U); +} + +} // namespace diff --git a/iceoryx2-ffi/ffi/src/api/waitset.rs b/iceoryx2-ffi/ffi/src/api/waitset.rs index d01b6e359..b5835cb1f 100644 --- a/iceoryx2-ffi/ffi/src/api/waitset.rs +++ b/iceoryx2-ffi/ffi/src/api/waitset.rs @@ -57,7 +57,7 @@ impl IntoCInt for WaitSetRunError { } #[repr(C)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, StringLiteral)] pub enum iox2_waitset_run_result_e { TERMINATION_REQUEST = IOX2_OK as isize + 1, INTERRUPT, @@ -225,6 +225,13 @@ pub unsafe extern "C" fn iox2_waitset_attachment_error_string( error.as_str_literal().as_ptr() as *const c_char } +#[no_mangle] +pub unsafe extern "C" fn iox2_waitset_run_result_string( + error: iox2_waitset_run_result_e, +) -> *const c_char { + error.as_str_literal().as_ptr() as *const c_char +} + #[no_mangle] pub unsafe extern "C" fn iox2_waitset_run_error_string( error: iox2_waitset_run_error_e,