Skip to content

Commit

Permalink
[eclipse-iceoryx#528] Add C++ binding
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Nov 26, 2024
1 parent 065d024 commit 6d6b8cf
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
27 changes: 27 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/enum_translation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "iox2/service_builder_publish_subscribe_error.hpp"
#include "iox2/service_error_enums.hpp"
#include "iox2/service_type.hpp"
#include "iox2/signal_handling_mode.hpp"
#include "iox2/subscriber_error.hpp"
#include "iox2/type_variant.hpp"
#include "iox2/unable_to_deliver_strategy.hpp"
Expand Down Expand Up @@ -1432,6 +1433,32 @@ inline auto from<iox2::WaitSetRunError, const char*>(const iox2::WaitSetRunError
return iox2_waitset_run_error_string(iox::into<iox2_waitset_run_error_e>(value));
}

template <>
inline constexpr auto from<iox2::SignalHandlingMode, iox2_signal_handling_mode_e>(
const iox2::SignalHandlingMode value) noexcept -> iox2_signal_handling_mode_e {
switch (value) {
case iox2::SignalHandlingMode::Disabled:
return iox2_signal_handling_mode_e_DISABLED;
case iox2::SignalHandlingMode::HandleTerminationRequests:
return iox2_signal_handling_mode_e_HANDLE_TERMINATION_REQUESTS;
}

IOX_UNREACHABLE();
}

template <>
inline constexpr auto from<int, iox2::SignalHandlingMode>(const int value) noexcept -> iox2::SignalHandlingMode {
const auto variant = static_cast<iox2_signal_handling_mode_e>(value);

switch (variant) {
case iox2_signal_handling_mode_e_DISABLED:
return iox2::SignalHandlingMode::Disabled;
case iox2_signal_handling_mode_e_HANDLE_TERMINATION_REQUESTS:
return iox2::SignalHandlingMode::HandleTerminationRequests;
}

IOX_UNREACHABLE();
}
} // namespace iox

#endif
5 changes: 5 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "iox2/service_builder.hpp"
#include "iox2/service_name.hpp"
#include "iox2/service_type.hpp"
#include "iox2/signal_handling_mode.hpp"

namespace iox2 {
/// The central entry point of iceoryx2. Represents a node of the iceoryx2
Expand Down Expand Up @@ -84,6 +85,10 @@ class NodeBuilder {
/// is specified the [`Config::global_config()`] is used.
IOX_BUILDER_OPTIONAL(Config, config);

/// Defines the [`SignalHandlingMode`] for the [`Node`]. It affects the [`Node::wait()`] call
/// that returns any received signal via its [`NodeWaitFailure`]
IOX_BUILDER_OPTIONAL(SignalHandlingMode, signal_handling_mode);

public:
NodeBuilder();
NodeBuilder(NodeBuilder&&) = default;
Expand Down
30 changes: 30 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/signal_handling_mode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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

#ifndef IOX2_SIGNAL_HANDLING_MODE_HPP
#define IOX2_SIGNAL_HANDLING_MODE_HPP

#include <cstdint>

namespace iox2 {
/// Defines how signals are handled by constructs that might register a custom
/// [`SignalHandler`]
enum class SignalHandlingMode : uint8_t {
/// The signals `SIGINT` and `SIGTERM` are registered and handled. If such a Signal is received
/// the user will be notified.
HandleTerminationRequests,
/// No signal handler will be registered.
Disabled,
};
} // namespace iox2

#endif
7 changes: 7 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/waitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#ifndef IOX2_WAITSET_HPP
#define IOX2_WAITSET_HPP

#include "iox/builder_addendum.hpp"
#include "iox/duration.hpp"
#include "iox/expected.hpp"
#include "iox2/callback_progression.hpp"
#include "iox2/file_descriptor.hpp"
#include "iox2/internal/iceoryx2.hpp"
#include "iox2/listener.hpp"
#include "iox2/service_type.hpp"
#include "iox2/signal_handling_mode.hpp"
#include "iox2/waitset_enums.hpp"

namespace iox2 {
Expand Down Expand Up @@ -230,6 +232,11 @@ class WaitSet {

/// The builder for the [`WaitSet`].
class WaitSetBuilder {
/// Defines the [`SignalHandlingMode`] for the [`WaitSet`]. It affects the
/// [`WaitSet::wait_and_process()`] and [`WaitSet::wait_and_process_once()`] calls
/// that returns any received [`Signal`] via its [`WaitSetRunResult`] return value.
IOX_BUILDER_OPTIONAL(SignalHandlingMode, signal_handling_mode);

public:
WaitSetBuilder();
~WaitSetBuilder() = default;
Expand Down
5 changes: 5 additions & 0 deletions iceoryx2-ffi/cxx/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ auto NodeBuilder::create() const&& -> iox::expected<Node<T>, NodeCreationFailure
iox2_node_builder_set_config(&m_handle, &m_config.value().m_handle);
}

if (m_signal_handling_mode.has_value()) {
iox2_node_builder_set_signal_handling_mode(
&m_handle, iox::into<iox2_signal_handling_mode_e>(m_signal_handling_mode.value()));
}

iox2_node_h node_handle {};
const auto ret_val = iox2_node_builder_create(m_handle, nullptr, iox::into<iox2_service_type_e>(T), &node_handle);

Expand Down
7 changes: 7 additions & 0 deletions iceoryx2-ffi/cxx/src/waitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include "iox2/waitset.hpp"
#include "iox/into.hpp"
#include "iox2/enum_translation.hpp"
#include "iox2/internal/callback_context.hpp"

namespace iox2 {
Expand Down Expand Up @@ -153,6 +155,11 @@ WaitSetBuilder::WaitSetBuilder()

template <ServiceType S>
auto WaitSetBuilder::create() const&& -> iox::expected<WaitSet<S>, WaitSetCreateError> {
if (m_signal_handling_mode.has_value()) {
iox2_waitset_builder_set_signal_handling_mode(
&m_handle, iox::into<iox2_signal_handling_mode_e>(m_signal_handling_mode.value()));
}

iox2_waitset_h waitset_handle {};
auto result = iox2_waitset_builder_create(m_handle, iox::into<iox2_service_type_e>(S), nullptr, &waitset_handle);

Expand Down

0 comments on commit 6d6b8cf

Please sign in to comment.