From b25237cbbda9597ec8904538d71d15b488445fc2 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Mon, 8 Jul 2024 14:13:32 +0200 Subject: [PATCH] [#264] Create Node C++ skeleton --- .../cxx/publish_subscribe/src/publisher.cpp | 10 ++ iceoryx2-ffi/cxx/include/iox2/node.hpp | 103 +++++++++++++++++- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/examples/cxx/publish_subscribe/src/publisher.cpp b/examples/cxx/publish_subscribe/src/publisher.cpp index e5cd84508..864df8bb4 100644 --- a/examples/cxx/publish_subscribe/src/publisher.cpp +++ b/examples/cxx/publish_subscribe/src/publisher.cpp @@ -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() + .expect("successful node creation"); + + Node::list( + Config{}, [](auto) { return iox::ok(CallbackProgression::Continue); }); + return 0; } diff --git a/iceoryx2-ffi/cxx/include/iox2/node.hpp b/iceoryx2-ffi/cxx/include/iox2/node.hpp index 6ff4446c5..def34498d 100644 --- a/iceoryx2-ffi/cxx/include/iox2/node.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/node.hpp @@ -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 + +#include +#include +#include +#include +#include + +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 create( + const char* value); + + const std::string& as_string() const; + + private: + std::string value; +}; + +class ServiceName { + public: + static iox::expected create( + const char* value); + const std::string& as_string() const; +}; + +template +class Builder {}; + +class NodeDetails { + public: + const NodeName& name() const; + const Config& config() const; +}; + +template +class AliveNodeView { + public: + const NodeId& id() const; + const iox::optional details() const; +}; + +template +class DeadNodeView { + public: + const NodeId& id() const; + const iox::optional details() const; + iox::expected remove_stale_resources(); +}; + +template +class NodeState { + public: + NodeState& if_alive(iox::function&)> callback); + NodeState& is_dead(iox::function&)> callback); +}; + +template +class Node { + public: + NodeName& name() const; + NodeId& id() const; + Builder service_builder(const ServiceName& name) const; + + static iox::expected list( + const Config& config, + const iox::function( + iox::expected, NodeListFailure>)>& callback); + + private: +}; + +class NodeBuilder { + IOX_BUILDER_PARAMETER(NodeName, name, NodeName::create("").expect("")) + IOX_BUILDER_PARAMETER(Config, config, Config{}) + + public: + template + iox::expected, NodeCreationFailure> create() const; +}; +} // namespace iox2 + +#endif