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

WIP: [#500] Expose UniquePortId bytes in CXX API #501

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

orecham
Copy link
Contributor

@orecham orecham commented Nov 2, 2024

Notes for Reviewer

Provides an API to access the bytes representing a UniquePortId from the CXX API.

Pre-Review Checklist for the PR Author

  1. Add sensible notes for the reviewer
  2. PR title is short, expressive and meaningful
  3. Relevant issues are linked in the References section
  4. Every source code file has a copyright header with SPDX-License-Identifier: Apache-2.0 OR MIT
  5. Branch follows the naming format (iox2-123-introduce-posix-ipc-example)
  6. Commits messages are according to this guideline
  7. Tests follow the best practice for testing
  8. Changelog updated in the unreleased section including API breaking changes
  9. Assign PR to reviewer
  10. All checks have passed (except task-list-completed)

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Unit tests have been written for new behavior
  • Public API is documented
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

Closes #500


let h = &mut *handle.as_type();

if let Some(Some(id)) = (h.value.internal.as_ptr() as *const Option<UniquePublisherId>).as_ref()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of ugly IMO, can anyone suggest any better approaches offered by Rust?

@@ -43,6 +46,15 @@ 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> unique_port_id {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially wanted the Rust layer to just provide a pointer to the ID bytes, however I couldn't work out how to resolve the ownership between the two layers, so I opted for a copy instead.
Do you see any better options?

@orecham orecham changed the title [#500] Expose UniquePortId bytes in CXX API WIP: [#500] Expose UniquePortId bytes in CXX API Nov 2, 2024
@orecham
Copy link
Contributor Author

orecham commented Nov 2, 2024

@elBoberido @elfenpiff

I implemented the API for UniquePublisherId but want to get some feedback before implementing it for the rest. What do you guys think of this approach?

EDIT: I went ahead and implemented a rest to unblock myself. Let me know if you see a better way though.

@orecham orecham force-pushed the iox2-500-expose-unique-id-bytes-in-cxx branch from 33b1d13 to 515da9d Compare November 2, 2024 10:29
#include "iox2/internal/iceoryx2.hpp"

#include <array>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially tried to use iox::vector but didn't work out how to set the bytes properly without vector::empty returning false.

Copy link

codecov bot commented Nov 2, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 79.20%. Comparing base (29c71af) to head (e6770d0).

Files with missing lines Patch % Lines
iceoryx2/src/port/port_identifiers.rs 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
- Coverage   79.21%   79.20%   -0.02%     
==========================================
  Files         200      200              
  Lines       23728    23731       +3     
==========================================
  Hits        18795    18795              
- Misses       4933     4936       +3     
Files with missing lines Coverage Δ
iceoryx2/src/port/port_identifiers.rs 63.63% <0.00%> (-23.87%) ⬇️

... and 3 files with indirect coverage changes

@orecham orecham force-pushed the iox2-500-expose-unique-id-bytes-in-cxx branch from 515da9d to 2d1b857 Compare November 2, 2024 12:36
…queNotifierId UniqueListenerId bytes in CXX API
@orecham orecham force-pushed the iox2-500-expose-unique-id-bytes-in-cxx branch from 2d1b857 to ebc2875 Compare November 2, 2024 12:38
@orecham orecham self-assigned this Nov 2, 2024
@@ -36,9 +45,9 @@ class UniquePublisherId {
void drop();

iox2_unique_publisher_id_h m_handle = nullptr;
iox::optional<RawIdType> m_raw_id;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the ID is const in Rust, it will be copied into the CXX layer on first access and the copy re-used for subsequent calls to bytes().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose UniquePortId value in C/C++ API
1 participant