Skip to content

Commit

Permalink
[eclipse-iceoryx#264] Create Node C++ skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jul 9, 2024
1 parent 0a852fe commit 6ba8291
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
10 changes: 10 additions & 0 deletions examples/cxx/publish_subscribe/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,15 @@
#include "iox2/node.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");

Node<NodeType::ZERO_COPY>::list(
Config{}, [](auto) { return iox::ok(CallbackProgression::Continue); });

return 0;
}
103 changes: 102 additions & 1 deletion iceoryx2-ffi/cxx/include/iox2/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,106 @@
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
#ifndef IOX2_NODE_HPP_
#define IOX2_NODE_HPP_

// TODO: [#210] implement
#include <iox2/iceoryx2.h>

#include <iox/builder.hpp>
#include <iox/expected.hpp>
#include <iox/function.hpp>
#include <iox/optional.hpp>
#include <string>

namespace iox2 {
enum class SemanticStringError {};

enum class NodeListFailure {};

enum class CallbackProgression { Continue, Stop };

enum class NodeCreationFailure {};

enum class NodeCleanupFailure {};

enum class NodeType { PROCESS_LOCAL, ZERO_COPY };

class Config {};

class NodeId {};

class NodeName {
public:
static iox::expected<NodeName, SemanticStringError> create(
const char* value);

const std::string& as_string() const;

private:
std::string value;
};

class ServiceName {
public:
static iox::expected<ServiceName, SemanticStringError> create(
const char* value);
const std::string& as_string() const;
};

template <NodeType>
class Builder {};

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

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

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

template <NodeType T>
class NodeState {
public:
NodeState& if_alive(iox::function<void(AliveNodeView<T>&)> callback);
NodeState& is_dead(iox::function<void(DeadNodeView<T>&)> callback);
};

template <NodeType T>
class Node {
public:
NodeName& name() const;
NodeId& id() const;
Builder<T> service_builder(const ServiceName& name) const;

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

private:
};

class NodeBuilder {
IOX_BUILDER_PARAMETER(NodeName, name, NodeName::create("").expect(""))
IOX_BUILDER_PARAMETER(Config, config, Config{})

public:
template <NodeType T>
iox::expected<Node<T>, NodeCreationFailure> create() const;
};
} // namespace iox2

#endif

0 comments on commit 6ba8291

Please sign in to comment.