Skip to content

Commit

Permalink
[eclipse-iceoryx#264] First final C++ API draft finished
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jul 9, 2024
1 parent 93f3bea commit 036d1bf
Show file tree
Hide file tree
Showing 28 changed files with 921 additions and 41 deletions.
3 changes: 3 additions & 0 deletions examples/cxx/publish_subscribe/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ int main() {
.open_or_create()
.expect("successful service creation/opening");

auto publisher = service.publisher_builder().create().expect(
"successful publisher creation");

// Node<NodeType::ZERO_COPY>::list(
// Config{}, [](auto) { return iox::ok(CallbackProgression::Continue);
// });
Expand Down
25 changes: 25 additions & 0 deletions iceoryx2-ffi/cxx/include/iox/layout.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 IOX_LAYOUT_HPP_
#define IOX_LAYOUT_HPP_

#include <cstdint>

namespace iox {
class Layout {
public:
uint64_t size() const {}
uint64_t alignment() const {}
};
} // namespace iox

#endif
19 changes: 19 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/connection_failure.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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_CONNECTION_FAILURE_HPP_
#define IOX2_CONNECTION_FAILURE_HPP_

namespace iox2 {
enum class ConnectionFailure {};
}

#endif
25 changes: 25 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/dynamic_config_event.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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_DYNAMIC_CONFIG_EVENT_HPP_
#define IOX2_DYNAMIC_CONFIG_EVENT_HPP_

#include <cstdint>

namespace iox2 {
class DynamicConfigEvent {
public:
uint64_t number_of_listeners() const {}
uint64_t number_of_notifiers() const {}
};
} // namespace iox2

#endif
25 changes: 25 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/dynamic_config_publish_subscribe.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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_DYNAMIC_CONFIG_PUBLISH_SUBSCRIBE_HPP_
#define IOX2_DYNAMIC_CONFIG_PUBLISH_SUBSCRIBE_HPP_

#include <cstdint>

namespace iox2 {
class DynamicConfigPublishSubscribe {
public:
uint64_t number_of_publishers() const {}
uint64_t number_of_subscribers() const {}
};
} // namespace iox2

#endif
28 changes: 28 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/event_id.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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_EVENT_ID_HPP_
#define IOX2_EVENT_ID_HPP_

#include <cstdint>

namespace iox2 {
class EventId {
public:
EventId(const uint64_t value) : m_value{value} {}
uint64_t as_value() const { return m_value; }

private:
uint64_t m_value;
};
} // namespace iox2

#endif
27 changes: 27 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/header_publish_subscribe.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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_HEADER_PUBLISH_SUBSCRIBE_HPP_
#define IOX2_HEADER_PUBLISH_SUBSCRIBE_HPP_

#include "iox/layout.hpp"
#include "service_type.hpp"
#include "unique_port_id.hpp"

namespace iox2 {
class HeaderPublishSubscribe {
public:
UniquePublisherId publisher_id() const {}
iox::Layout payload_type_layout() const {}
};
} // namespace iox2

#endif
63 changes: 63 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/listener.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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_LISTENER_HPP_
#define IOX2_LISTENER_HPP_

#include "event_id.hpp"
#include "iox/duration.hpp"
#include "iox/expected.hpp"
#include "iox/function.hpp"
#include "iox/optional.hpp"
#include "service_type.hpp"
#include "unique_port_id.hpp"

namespace iox2 {
enum class ListenerCreateError {
/// The maximum amount of [`Listener`]s that can connect to a
/// [`Service`](crate::service::Service) is
/// defined in [`crate::config::Config`]. When this is exceeded no more
/// [`Listener`]s
/// can be created for a specific [`Service`](crate::service::Service).
ExceedsMaxSupportedListeners,
/// An underlying resource of the [`Service`](crate::service::Service) could
/// not be created
ResourceCreationFailed,
};

enum class ListenerWaitError {
ContractViolation,
InternalFailure,
InterruptSignal,
};

template <ServiceType>
class Listener {
public:
UniqueListenerId id() const {}

iox::expected<void, ListenerWaitError> try_wait_all(
const iox::function<void(EventId)>& callback) {}
iox::expected<void, ListenerWaitError> timed_wait_all(
const iox::function<void(EventId)>& callback,
const iox::units::Duration& timeout) {}
iox::expected<void, ListenerWaitError> blocking_wait_all(
const iox::function<void(EventId)>& callback) {}

iox::expected<iox::optional<EventId>, ListenerWaitError> try_wait_one() {}
iox::expected<iox::optional<EventId>, ListenerWaitError> timed_wait_one(
const iox::units::Duration& timeout) {}
iox::expected<iox::optional<EventId>, ListenerWaitError>
blocking_wait_one() {}
};
} // namespace iox2

#endif
54 changes: 54 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/message_type_details.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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_MESSAGE_TYPE_DETAILS_HPP_
#define IOX2_MESSAGE_TYPE_DETAILS_HPP_

#include <cstdint>
#include <string>

namespace iox2 {
/// Defines if the type is a slice with a runtime-size
/// ([`TypeVariant::Dynamic`]) or if its a type that satisfies [`Sized`]
/// ([`TypeVariant::FixedSize`]).
enum class TypeVariant {
/// A fixed size type like [`u64`]
FixedSize,
/// A dynamic sized type like a slice
Dynamic,
};

/// Contains all type details required to connect to a
/// [`crate::service::Service`]
struct TypeDetail {
/// The [`TypeVariant`] of the type
TypeVariant variant;
/// Contains the output of [`core::any::type_name()`].
std::string type_name;
/// The size of the underlying type.
uint64_t size;
/// The alignment of the underlying type.
uint64_t alignment;
};

struct MessageTypeDetails {
/// The [`TypeDetail`] of the header of a message, the first iceoryx2
/// internal part.
TypeDetail header;
/// The [`TypeDetail`] of the user_header or the custom header, is located
/// directly after the header.
TypeDetail user_header;
/// The [`TypeDetail`] of the payload of the message, the last part.
TypeDetail payload;
};
} // namespace iox2

#endif
39 changes: 2 additions & 37 deletions iceoryx2-ffi/cxx/include/iox2/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,14 @@
#include "callback_progression.hpp"
#include "config.hpp"
#include "internal/iceoryx2.hpp"
#include "node_id.hpp"
#include "node_name.hpp"
#include "node_state.hpp"
#include "service_builder.hpp"
#include "service_name.hpp"
#include "service_type.hpp"

namespace iox2 {
enum class NodeListFailure {};

enum class NodeCreationFailure { InsufficientPermissions, InternalError };

enum class NodeCleanupFailure {};

class NodeId {};
class NodeDetails {
public:
const NodeName& name() const;
const Config& config() const;
};

template <ServiceType>
class AliveNodeView {
public:
const NodeId& id() const;
const iox::optional<NodeDetails> details() const;
};

template <ServiceType>
class DeadNodeView {
public:
const NodeId& id() const;
const iox::optional<NodeDetails> details() const;
iox::expected<bool, NodeCleanupFailure> remove_stale_resources();
};

template <ServiceType T>
class NodeState {
public:
NodeState& if_alive(const iox::function<void(AliveNodeView<T>&)>& callback);
NodeState& is_dead(const iox::function<void(DeadNodeView<T>&)>& callback);
NodeState& is_inaccessible(const iox::function<void(NodeId&)>& callback);
NodeState& is_undefined(const iox::function<void(NodeId&)>& callback);
};

template <ServiceType T>
class Node {
public:
Expand Down
26 changes: 26 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/node_details.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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_NODE_DETAILS_HPP_
#define IOX2_NODE_DETAILS_HPP_

#include "config.hpp"
#include "node_name.hpp"

namespace iox2 {
class NodeDetails {
public:
const NodeName& name() const;
const Config& config() const;
};
} // namespace iox2

#endif
24 changes: 24 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/node_failure_enums.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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_NODE_FAILURE_ENUMS_HPP_
#define IOX2_NODE_FAILURE_ENUMS_HPP_

namespace iox2 {
enum class NodeListFailure {};

enum class NodeCreationFailure { InsufficientPermissions, InternalError };

enum class NodeCleanupFailure {};

} // namespace iox2

#endif
Loading

0 comments on commit 036d1bf

Please sign in to comment.