Skip to content

Commit

Permalink
[eclipse-iceoryx#500] Only copy ID from iceoryx2 into CXX one time
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Nov 2, 2024
1 parent ebc2875 commit e6770d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
13 changes: 9 additions & 4 deletions iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace iox2 {

constexpr uint64_t UNIQUE_PORT_ID_LENGTH = 128;
using RawIdType = std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>;

/// The system-wide unique id of a [`Publisher`].
class UniquePublisherId {
Expand All @@ -31,7 +32,7 @@ class UniquePublisherId {
auto operator=(UniquePublisherId&& rhs) noexcept -> UniquePublisherId&;
~UniquePublisherId();

auto bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>>;
auto bytes() -> iox::optional<RawIdType>&;

private:
template <ServiceType, typename, typename>
Expand All @@ -44,6 +45,7 @@ class UniquePublisherId {
void drop();

iox2_unique_publisher_id_h m_handle = nullptr;
iox::optional<RawIdType> m_raw_id;
};

/// The system-wide unique id of a [`Subscriber`].
Expand All @@ -55,7 +57,7 @@ class UniqueSubscriberId {
auto operator=(UniqueSubscriberId&& rhs) noexcept -> UniqueSubscriberId&;
~UniqueSubscriberId();

auto bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>>;
auto bytes() -> iox::optional<RawIdType>&;

private:
template <ServiceType, typename, typename>
Expand All @@ -67,6 +69,7 @@ class UniqueSubscriberId {
void drop();

iox2_unique_subscriber_id_h m_handle = nullptr;
iox::optional<RawIdType> m_raw_id;
};

/// The system-wide unique id of a [`Notifier`].
Expand All @@ -78,7 +81,7 @@ class UniqueNotifierId {
auto operator=(UniqueNotifierId&& rhs) noexcept -> UniqueNotifierId&;
~UniqueNotifierId();

auto bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>>;
auto bytes() -> iox::optional<RawIdType>&;

private:
template <ServiceType>
Expand All @@ -90,6 +93,7 @@ class UniqueNotifierId {
void drop();

iox2_unique_notifier_id_h m_handle = nullptr;
iox::optional<RawIdType> m_raw_id;
};

/// The system-wide unique id of a [`Listener`].
Expand All @@ -101,7 +105,7 @@ class UniqueListenerId {
auto operator=(UniqueListenerId&& rhs) noexcept -> UniqueListenerId&;
~UniqueListenerId();

auto bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>>;
auto bytes() -> iox::optional<RawIdType>&;

private:
template <ServiceType>
Expand All @@ -113,6 +117,7 @@ class UniqueListenerId {
void drop();

iox2_unique_listener_id_h m_handle = nullptr;
iox::optional<RawIdType> m_raw_id;
};

auto operator==(const UniquePublisherId& lhs, const UniquePublisherId& rhs) -> bool;
Expand Down
40 changes: 20 additions & 20 deletions iceoryx2-ffi/cxx/src/unique_port_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ UniquePublisherId::UniquePublisherId(iox2_unique_publisher_id_h handle)
: m_handle { handle } {
}

auto UniquePublisherId::bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>> {
if (m_handle != nullptr) {
std::array<uint8_t, UNIQUE_PORT_ID_LENGTH> bytes {};
auto UniquePublisherId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
iox2_unique_publisher_id_value(m_handle, bytes.data());
return bytes;
m_raw_id.emplace(std::move(bytes));
}
return iox::nullopt;
return m_raw_id;
};

void UniquePublisherId::drop() {
Expand Down Expand Up @@ -90,13 +90,13 @@ UniqueSubscriberId::UniqueSubscriberId(iox2_unique_subscriber_id_h handle)
: m_handle { handle } {
}

auto UniqueSubscriberId::bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>> {
if (m_handle != nullptr) {
std::array<uint8_t, UNIQUE_PORT_ID_LENGTH> bytes {};
auto UniqueSubscriberId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
iox2_unique_subscriber_id_value(m_handle, bytes.data());
return bytes;
m_raw_id.emplace(std::move(bytes));
}
return iox::nullopt;
return m_raw_id;
};

void UniqueSubscriberId::drop() {
Expand Down Expand Up @@ -136,13 +136,13 @@ UniqueNotifierId::UniqueNotifierId(iox2_unique_notifier_id_h handle)
: m_handle { handle } {
}

auto UniqueNotifierId::bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>> {
if (m_handle != nullptr) {
std::array<uint8_t, UNIQUE_PORT_ID_LENGTH> bytes {};
auto UniqueNotifierId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
iox2_unique_notifier_id_value(m_handle, bytes.data());
return bytes;
m_raw_id.emplace(std::move(bytes));
}
return iox::nullopt;
return m_raw_id;
};

void UniqueNotifierId::drop() {
Expand Down Expand Up @@ -182,13 +182,13 @@ UniqueListenerId::UniqueListenerId(iox2_unique_listener_id_h handle)
: m_handle { handle } {
}

auto UniqueListenerId::bytes() -> iox::optional<std::array<uint8_t, UNIQUE_PORT_ID_LENGTH>> {
if (m_handle != nullptr) {
std::array<uint8_t, UNIQUE_PORT_ID_LENGTH> bytes {};
auto UniqueListenerId::bytes() -> iox::optional<RawIdType>& {
if (!m_raw_id.has_value() && m_handle != nullptr) {
RawIdType bytes {};
iox2_unique_listener_id_value(m_handle, bytes.data());
return bytes;
m_raw_id.emplace(std::move(bytes));
}
return iox::nullopt;
return m_raw_id;
};

void UniqueListenerId::drop() {
Expand Down

0 comments on commit e6770d0

Please sign in to comment.