Skip to content

Commit

Permalink
[eclipse-iceoryx#264] CPP-Node creation API
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Jul 10, 2024
1 parent ecd6422 commit b134ab4
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 30 deletions.
9 changes: 5 additions & 4 deletions examples/c/publish_subscribe/src/publisher.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

#include "iox2/iceoryx2.h"

#include <stdint.h>
#include <stdio.h>

#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;
}
Expand Down
9 changes: 5 additions & 4 deletions examples/cxx/publish_subscribe/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

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()
.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);
Expand Down
1 change: 1 addition & 0 deletions iceoryx2-ffi/cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/internal/iceoryx2.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_INTERNAL_ICEORYX2_HPP_
#define IOX2_INTERNAL_ICEORYX2_HPP_

extern "C" {
#include <iox2/iceoryx2.h>
}

#endif
26 changes: 9 additions & 17 deletions iceoryx2-ffi/cxx/include/iox2/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
#ifndef IOX2_NODE_HPP_
#define IOX2_NODE_HPP_

#include <iox2/iceoryx2.h>

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

#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 {};

Expand All @@ -36,18 +35,6 @@ 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:
iox2_node_name_storage_t value;
};

class ServiceName {
public:
static iox::expected<ServiceName, SemanticStringError> create(
Expand Down Expand Up @@ -99,6 +86,11 @@ class Node {
iox::expected<NodeState<T>, NodeListFailure>)>& callback);

private:
friend class NodeBuilder;

Node(iox2_node_h handle);

iox2_node_h m_handle;
};

class NodeBuilder {
Expand Down
34 changes: 34 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/node_name.hpp
Original file line number Diff line number Diff line change
@@ -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 <string>

#include "internal/iceoryx2.hpp"
#include "iox/expected.hpp"
#include "semantic_string.hpp"

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

const std::string& as_string() const;

private:
iox2_node_name_storage_t value;
};
} // namespace iox2

#endif
20 changes: 20 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/semantic_string.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_SEMANTIC_STRING_HPP_
#define IOX2_SEMANTIC_STRING_HPP_

namespace iox2 {
enum class SemanticStringError {};
}

#endif
45 changes: 40 additions & 5 deletions iceoryx2-ffi/cxx/src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,49 @@

#include <iox2/iceoryx2.h>

namespace iox2 {
iox::expected<NodeName, SemanticStringError> NodeName::create(
const char* value) {}
#include "iox/into.hpp"

namespace iox {
using namespace ::iox2;
template <>
constexpr NodeCreationFailure
from<iox2_node_creation_failure_e, NodeCreationFailure>(
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 <NodeType T>
Node<T>::Node(iox2_node_h handle) : m_handle{handle} {}

NodeBuilder::NodeBuilder() : m_handle{iox2_node_builder_new(nullptr)} {}

template <NodeType T>
iox::expected<Node<T>, NodeCreationFailure> NodeBuilder::create() const&& {}
iox::expected<Node<T>, 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<iox2_node_creation_failure_e, NodeCreationFailure>(
static_cast<iox2_node_creation_failure_e>(ret_val)));
}

return iox::ok(Node<T>(node_handle));
}

template iox::expected<Node<NodeType::ZERO_COPY>, NodeCreationFailure>
NodeBuilder::create() const&&;

template iox::expected<Node<NodeType::PROCESS_LOCAL>, NodeCreationFailure>
NodeBuilder::create() const&&;
} // namespace iox2
21 changes: 21 additions & 0 deletions iceoryx2-ffi/cxx/src/node_name.cpp
Original file line number Diff line number Diff line change
@@ -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, SemanticStringError> NodeName::create(
const char* value) {}

const std::string& NodeName::as_string() const {}

} // namespace iox2
5 changes: 5 additions & 0 deletions iceoryx2-ffi/ffi/src/node_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b134ab4

Please sign in to comment.