Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All changes for ros2 support #2

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Add `PeriodicTimer` into POSIX building blocks [#425](https://github.com/eclipse-iceoryx/iceoryx2/issues/425)
* Developer permissions for resources [#460](https://github.com/eclipse-iceoryx/iceoryx2/issues/460)
* Add `--send-copy` flag to Benchmark to consider mem operations [#483](https://github.com/eclipse-iceoryx/iceoryx2/issues/483)
* Support for slices in the C++ bindings [#490](https://github.com/eclipse-iceoryx/iceoryx2/issues/490)

### Bugfixes

Expand All @@ -38,6 +39,7 @@
* Rename `NodeEvent` into `WaitEvent` [#390](https://github.com/eclipse-iceoryx/iceoryx2/issues/390)
* Bazel support for the Rust crates [#349](https://github.com/eclipse-iceoryx/iceoryx2/issues/349)
* Remove ACL dependency [#457](https://github.com/eclipse-iceoryx/iceoryx2/issues/457)
* Publish Subscribe Header contains number of elements contained in a `Sample` [#498](https://github.com/eclipse-iceoryx/iceoryx2/issues/498)

### Workflow

Expand All @@ -55,7 +57,7 @@
conflicts when merging.
-->

* Example text [#1](https://github.com/eclipse-iceoryx/iceoryx2/issues/1)
* APIs to support slices in the C++ bindings [#490](https://github.com/eclipse-iceoryx/iceoryx2/issues/490)

### API Breaking Changes

Expand All @@ -72,3 +74,5 @@
// ...
}
```

2. Removed `payload_type_layout()` from `publish_subscribe::Header`.
94 changes: 93 additions & 1 deletion iceoryx2-bb/derive-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern crate proc_macro;

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Data, DeriveInput, Fields};
use syn::{parse_macro_input, Data, DeriveInput, Expr, ExprLit, Fields, Lit};

/// Implements the [`iceoryx2_bb_elementary::placement_default::PlacementDefault`] trait when all
/// fields of the struct implement it.
Expand Down Expand Up @@ -99,3 +99,95 @@ pub fn placement_default_derive(input: TokenStream) -> TokenStream {

TokenStream::from(expanded)
}

#[proc_macro_derive(StaticStringRepresentation, attributes(StaticString))]
pub fn as_static_string_derive(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();

let static_string_impl = match input.data {
Data::Enum(ref data_enum) => {
let match_arms = data_enum.variants.iter().map(|variant| {
let variant_ident = &variant.ident;

// Get the StaticString attribute if it exists
let static_string = variant
.attrs
.iter()
.find_map(|attr| {
if !attr.path().is_ident("StaticString") {
return None;
}

match attr.meta.require_name_value() {
Ok(meta) => {
if let Expr::Lit(ExprLit {
lit: Lit::Str(lit), ..
}) = &meta.value
{
Some(lit.value())
} else {
None
}
}
_ => None,
}
})
.unwrap_or_else(|| {
let variant_str = variant_ident.to_string();
variant_str
.chars()
.enumerate()
.map(|(_, c)| {
if c == '_' {
' '
} else {
c.to_ascii_lowercase()
}
})
.collect::<String>()
});

match &variant.fields {
Fields::Unit => {
quote! {
Self::#variant_ident => concat!(#static_string, "\0")
}
}
Fields::Unnamed(_) => {
quote! {
Self::#variant_ident(..) => concat!(#static_string, "\0")
}
}
Fields::Named(_) => {
quote! {
Self::#variant_ident{..} => concat!(#static_string, "\0")
}
}
}
});

quote! {
fn as_static_str(&self) -> &'static str {
match self {
#(#match_arms,)*
}
}
}
}
_ => {
let err =
syn::Error::new_spanned(&input, "AsStaticString can only be derived for enums");
return err.to_compile_error().into();
}
};

let expanded = quote! {
impl #impl_generics AsStaticString for #name #ty_generics #where_clause {
#static_string_impl
}
};

TokenStream::from(expanded)
}
15 changes: 15 additions & 0 deletions iceoryx2-bb/elementary/src/as_static_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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

pub trait AsStaticString {
fn as_static_str(&self) -> &'static str;
}
5 changes: 4 additions & 1 deletion iceoryx2-bb/elementary/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
#[macro_use]
pub mod enum_gen;

/// A strong type that represents the alignment part of [`std::alloc::Layout`]
mod as_static_string;
pub use as_static_string::*;

pub mod alignment;
pub mod allocator;
/// A strong type that represents the alignment part of [`std::alloc::Layout`]
pub mod bump_allocator;
pub mod lazy_singleton;
pub mod math;
Expand Down
1 change: 0 additions & 1 deletion iceoryx2-bb/posix/tests/unix_datagram_socket_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use iceoryx2_bb_container::semantic_string::SemanticString;
use iceoryx2_bb_posix::barrier::*;
use iceoryx2_bb_posix::config::*;
use iceoryx2_bb_posix::creation_mode::*;
use iceoryx2_bb_posix::directory::Directory;
use iceoryx2_bb_posix::file::*;
use iceoryx2_bb_posix::file_descriptor::*;
use iceoryx2_bb_posix::socket_ancillary::*;
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 @@ -37,6 +37,7 @@ target_include_directories(includes-only-cxx

add_library(iceoryx2-cxx-object-lib OBJECT
src/config.cpp
src/error_string.cpp
src/event_id.cpp
src/file_descriptor.cpp
src/header_publish_subscribe.cpp
Expand Down
102 changes: 81 additions & 21 deletions iceoryx2-ffi/cxx/include/iox/slice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "iox/assertions_addendum.hpp"

#include <cstdint>
#include <type_traits>

namespace iox {
template <typename T>
Expand All @@ -25,29 +26,88 @@ class Slice {
using ConstIterator = const T*;
using ValueType = T;

auto size() const -> uint64_t {
IOX_TODO();
}
auto operator[](const uint64_t n) const -> const T& {
IOX_TODO();
}
auto operator[](const uint64_t n) -> T& {
IOX_TODO();
}
auto begin() -> Iterator {
IOX_TODO();
}
auto begin() const -> ConstIterator {
IOX_TODO();
}
auto end() -> Iterator {
IOX_TODO();
}
auto end() const -> ConstIterator {
IOX_TODO();
}
Slice(const T* data, uint64_t number_of_elements);

auto size() const -> uint64_t;
auto number_of_elements() const -> uint64_t;

auto operator[](uint64_t n) const -> const T&;
auto operator[](uint64_t n) -> T&;

auto begin() -> Iterator;
auto begin() const -> ConstIterator;
auto end() -> Iterator;
auto end() const -> ConstIterator;

auto data() -> T*;
auto data() const -> const T*;

private:
T* m_data;
uint64_t m_number_of_elements;
};

template <typename T>
Slice<T>::Slice(const T* data, uint64_t number_of_elements)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast) constness protected by const class specification
: m_data { const_cast<T*>(data) }
, m_number_of_elements { number_of_elements } {
}

template <typename T>
auto Slice<T>::size() const -> uint64_t {
return (sizeof(ValueType) * m_number_of_elements + alignof(ValueType) - 1) & ~(alignof(ValueType) - 1);
}

template <typename T>
auto Slice<T>::number_of_elements() const -> uint64_t {
return m_number_of_elements;
}

template <typename T>
auto Slice<T>::operator[](const uint64_t n) const -> const T& {
IOX_ASSERT(n < m_number_of_elements, "Index out of bounds");
return *(m_data + n);
}

template <typename T>
auto Slice<T>::operator[](const uint64_t n) -> T& {
IOX_ASSERT(n < m_number_of_elements, "Index out of bounds");
return *(m_data + n);
}

template <typename T>
auto Slice<T>::begin() -> Iterator {
return m_data;
}

template <typename T>
auto Slice<T>::begin() const -> ConstIterator {
return m_data;
}

template <typename T>
auto Slice<T>::end() -> Iterator {
static_assert(!std::is_same_v<T, void>, "Slice<void> is not allowed");
return m_data + m_number_of_elements;
}

template <typename T>
auto Slice<T>::end() const -> ConstIterator {
static_assert(!std::is_same_v<T, void>, "Slice<void> is not allowed");
return m_data + m_number_of_elements;
}

template <typename T>
auto Slice<T>::data() -> T* {
return m_data;
}

template <typename T>
auto Slice<T>::data() const -> const T* {
return m_data;
}

template <typename>
struct IsSlice {
static constexpr bool VALUE = false;
Expand Down
3 changes: 3 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/config_creation_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ enum class ConfigCreationError : uint8_t {
/// Parts of the config file could not be deserialized. Indicates some kind of syntax error.
UnableToDeserializeContents
};

auto error_string(const iox2::ConfigCreationError& error) -> const char*;

} // namespace iox2

#endif
4 changes: 4 additions & 0 deletions iceoryx2-ffi/cxx/include/iox2/connection_failure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ enum class ConnectionFailure : uint8_t {
/// Failures when mapping the corresponding data segment
UnableToMapPublishersDataSegment
};


auto error_string(const iox2::ConnectionFailure& error) -> const char*;

} // namespace iox2

#endif
Loading
Loading