diff --git a/examples/c/publish_subscribe/src/publisher.c b/examples/c/publish_subscribe/src/publisher.c index 1401e7421..fc1926dfa 100644 --- a/examples/c/publish_subscribe/src/publisher.c +++ b/examples/c/publish_subscribe/src/publisher.c @@ -10,16 +10,17 @@ // // SPDX-License-Identifier: Apache-2.0 OR MIT -#include "iox2/iceoryx2.h" - #include #include +#include "iox2/iceoryx2.h" + int main(void) { iox2_node_builder_h node_builder_handle = iox2_node_builder_new(NULL); iox2_node_h node_handle; - int ret_val = iox2_node_builder_create(node_builder_handle, NULL, iox2_node_type_e_ZERO_COPY, &node_handle); - if(ret_val != IOX2_OK) { + int ret_val = iox2_node_builder_create( + node_builder_handle, NULL, iox2_node_type_e_ZERO_COPY, &node_handle); + if (ret_val != IOX2_OK) { printf("Could not create node! Error code: %i", ret_val); return -1; } diff --git a/examples/cxx/publish_subscribe/src/publisher.cpp b/examples/cxx/publish_subscribe/src/publisher.cpp index 75cab72e8..59ee5a16a 100644 --- a/examples/cxx/publish_subscribe/src/publisher.cpp +++ b/examples/cxx/publish_subscribe/src/publisher.cpp @@ -14,10 +14,11 @@ int main() { using namespace iox2; - auto node = NodeBuilder(); - // .name(NodeName::create("hello world").expect("valid node name")) - // .template create() - // .expect("successful node creation"); + 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); diff --git a/iceoryx2-ffi/cxx/CMakeLists.txt b/iceoryx2-ffi/cxx/CMakeLists.txt index 3695d586d..d525d4cfb 100644 --- a/iceoryx2-ffi/cxx/CMakeLists.txt +++ b/iceoryx2-ffi/cxx/CMakeLists.txt @@ -38,6 +38,7 @@ target_include_directories(includes-only-cxx add_library(iceoryx2-cxx-object-lib OBJECT src/dummy.cpp src/node.cpp + src/node_name.cpp ) set_target_properties(iceoryx2-cxx-object-lib diff --git a/iceoryx2-ffi/cxx/include/iox2/internal/iceoryx2.hpp b/iceoryx2-ffi/cxx/include/iox2/internal/iceoryx2.hpp new file mode 100644 index 000000000..a50a644bb --- /dev/null +++ b/iceoryx2-ffi/cxx/include/iox2/internal/iceoryx2.hpp @@ -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_INTERNAL_ICEORYX2_HPP_ +#define IOX2_INTERNAL_ICEORYX2_HPP_ + +extern "C" { +#include +} + +#endif diff --git a/iceoryx2-ffi/cxx/include/iox2/node.hpp b/iceoryx2-ffi/cxx/include/iox2/node.hpp index 9d99de262..8867fb8fc 100644 --- a/iceoryx2-ffi/cxx/include/iox2/node.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/node.hpp @@ -12,22 +12,21 @@ #ifndef IOX2_NODE_HPP_ #define IOX2_NODE_HPP_ -#include - #include #include #include #include -#include + +#include "internal/iceoryx2.hpp" +#include "node_name.hpp" namespace iox2 { -enum class SemanticStringError {}; enum class NodeListFailure {}; enum class CallbackProgression { Continue, Stop }; -enum class NodeCreationFailure {}; +enum class NodeCreationFailure { InsufficientPermissions, InternalError }; enum class NodeCleanupFailure {}; @@ -36,18 +35,6 @@ 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: - iox2_node_name_storage_t value; -}; - class ServiceName { public: static iox::expected create( @@ -99,6 +86,11 @@ class Node { iox::expected, NodeListFailure>)>& callback); private: + friend class NodeBuilder; + + Node(iox2_node_h handle); + + iox2_node_h m_handle; }; class NodeBuilder { diff --git a/iceoryx2-ffi/cxx/include/iox2/node_name.hpp b/iceoryx2-ffi/cxx/include/iox2/node_name.hpp new file mode 100644 index 000000000..185b8f738 --- /dev/null +++ b/iceoryx2-ffi/cxx/include/iox2/node_name.hpp @@ -0,0 +1,34 @@ +// 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_NAME_HPP_ +#define IOX2_NODE_NAME_HPP_ + +#include + +#include "internal/iceoryx2.hpp" +#include "iox/expected.hpp" +#include "semantic_string.hpp" + +namespace iox2 { +class NodeName { + public: + static iox::expected create( + const char* value); + + const std::string& as_string() const; + + private: + iox2_node_name_storage_t value; +}; +} // namespace iox2 + +#endif diff --git a/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp b/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp new file mode 100644 index 000000000..918684ea7 --- /dev/null +++ b/iceoryx2-ffi/cxx/include/iox2/semantic_string.hpp @@ -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_SEMANTIC_STRING_HPP_ +#define IOX2_SEMANTIC_STRING_HPP_ + +namespace iox2 { +enum class SemanticStringError {}; +} + +#endif diff --git a/iceoryx2-ffi/cxx/src/node.cpp b/iceoryx2-ffi/cxx/src/node.cpp index 95010bca5..f74c0dbdb 100644 --- a/iceoryx2-ffi/cxx/src/node.cpp +++ b/iceoryx2-ffi/cxx/src/node.cpp @@ -14,14 +14,49 @@ #include -namespace iox2 { -iox::expected NodeName::create( - const char* value) {} +#include "iox/into.hpp" + +namespace iox { +using namespace ::iox2; +template <> +constexpr NodeCreationFailure +from( + iox2_node_creation_failure_e e) noexcept { + switch (e) { + case iox2_node_creation_failure_e:: + iox2_node_creation_failure_e_INSUFFICIENT_PERMISSIONS: + return NodeCreationFailure::InsufficientPermissions; + case iox2_node_creation_failure_e:: + iox2_node_creation_failure_e_INTERNAL_ERROR: + return NodeCreationFailure::InternalError; + } +} +} // namespace iox -const std::string& NodeName::as_string() const {} +namespace iox2 { +template +Node::Node(iox2_node_h handle) : m_handle{handle} {} NodeBuilder::NodeBuilder() : m_handle{iox2_node_builder_new(nullptr)} {} template -iox::expected, NodeCreationFailure> NodeBuilder::create() const&& {} +iox::expected, NodeCreationFailure> NodeBuilder::create() const&& { + iox2_node_h node_handle; + int ret_val = iox2_node_builder_create( + m_handle, nullptr, iox2_node_type_e_ZERO_COPY, &node_handle); + + if (ret_val != IOX2_OK) { + return iox::err( + iox::from( + static_cast(ret_val))); + } + + return iox::ok(Node(node_handle)); +} + +template iox::expected, NodeCreationFailure> +NodeBuilder::create() const&&; + +template iox::expected, NodeCreationFailure> +NodeBuilder::create() const&&; } // namespace iox2 diff --git a/iceoryx2-ffi/cxx/src/node_name.cpp b/iceoryx2-ffi/cxx/src/node_name.cpp new file mode 100644 index 000000000..7fe56b742 --- /dev/null +++ b/iceoryx2-ffi/cxx/src/node_name.cpp @@ -0,0 +1,21 @@ +// 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 + +#include "iox2/node_name.hpp" + +namespace iox2 { +iox::expected NodeName::create( + const char* value) {} + +const std::string& NodeName::as_string() const {} + +} // namespace iox2 diff --git a/iceoryx2-ffi/ffi/src/node_builder.rs b/iceoryx2-ffi/ffi/src/node_builder.rs index 76226cd39..194857abf 100644 --- a/iceoryx2-ffi/ffi/src/node_builder.rs +++ b/iceoryx2-ffi/ffi/src/node_builder.rs @@ -161,6 +161,11 @@ pub extern "C" fn iox2_node_builder_set_config(node_builder_handle: iox2_node_bu // IOX2_OK } +#[no_mangle] +pub extern "C" fn iox2_internal_node_creation_failure_e() -> iox2_node_creation_failure_e { + unimplemented!() +} + /// Creates a node and consumes the builder /// /// # Arguments