Skip to content

Commit

Permalink
[eclipse-iceoryx#264] Finalize C++ Node API
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jul 9, 2024
1 parent 2ab112f commit cd78d5c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 14 deletions.
8 changes: 3 additions & 5 deletions examples/cxx/publish_subscribe/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include "iox2/node.hpp"
#include "transmission_data.hpp"

int main() {
using namespace iox2;
auto node =
NodeBuilder()
.name(NodeName::create("hello world").expect("valid node name"))
.template create<NodeType::ZERO_COPY>()
.expect("successful node creation");
auto node = NodeBuilder().template create<NodeType::ZERO_COPY>().expect(
"successful node creation");

// Node<NodeType::ZERO_COPY>::list(
// Config{}, [](auto) { return iox::ok(CallbackProgression::Continue);
Expand Down
23 changes: 23 additions & 0 deletions examples/cxx/publish_subscribe/src/transmission_data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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_EXAMPLES_TRANSMISSION_DATA_HPP_
#define IOX2_EXAMPLES_TRANSMISSION_DATA_HPP_

#include <cstdint>

struct TransmissionData {
std::int32_t x;
std::int32_t y;
double funky;
};

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

namespace iox2 {
enum class CallbackProgression { Continue, Stop };
}

#endif
19 changes: 19 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/config.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_CONFIG_HPP_
#define IOX2_CONFIG_HPP_

namespace iox2 {
class Config {};
} // namespace iox2

#endif
Empty file.
16 changes: 7 additions & 9 deletions iceoryx2-ffi/cxx/include/iox2/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@
#include <iox/function.hpp>
#include <iox/optional.hpp>

#include "callback_progression.hpp"
#include "config.hpp"
#include "internal/iceoryx2.hpp"
#include "node_name.hpp"

namespace iox2 {

enum class NodeListFailure {};

enum class CallbackProgression { Continue, Stop };

enum class NodeCreationFailure { InsufficientPermissions, InternalError };

enum class NodeCleanupFailure {};

enum class NodeType { PROCESS_LOCAL, ZERO_COPY };

class Config {};

class NodeId {};
class ServiceName {
public:
Expand Down Expand Up @@ -69,8 +66,10 @@ class DeadNodeView {
template <NodeType T>
class NodeState {
public:
NodeState& if_alive(iox::function<void(AliveNodeView<T>&)> callback);
NodeState& is_dead(iox::function<void(DeadNodeView<T>&)> callback);
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 <NodeType T>
Expand All @@ -82,8 +81,7 @@ class Node {

static iox::expected<void, NodeListFailure> list(
const Config& config,
const iox::function<iox::expected<CallbackProgression, NodeListFailure>(
iox::expected<NodeState<T>, NodeListFailure>)>& callback);
const iox::function<CallbackProgression(NodeState<T>)>& callback);

private:
friend class NodeBuilder;
Expand Down

0 comments on commit cd78d5c

Please sign in to comment.