Skip to content

Expose SamplePtr age in C++ API#258

Open
Gfilinic wants to merge 4 commits into
eclipse-score:mainfrom
Gfilinic:add_timestamp_accessor_to_sample_ptr
Open

Expose SamplePtr age in C++ API#258
Gfilinic wants to merge 4 commits into
eclipse-score:mainfrom
Gfilinic:add_timestamp_accessor_to_sample_ptr

Conversation

@Gfilinic

Copy link
Copy Markdown

I’m interested in contributing to this project and started by looking into Issue #13.

Changes

  • updated the constructor to carry the necessary context
  • added a GetTimestamp() function as requested
  • implemented a unit test to verify the behavior

Questions

  • Are there any specific commit message or PR guidelines I should follow?
  • Is there a preferred way to assign or request reviewers?

Design question

For the default/null constructors, I currently initialize the internal state (event_data_ctrl_ = nullptr, empty slot_indicator_, etc.) so that GetTimestamp() safely returns a default value.

Does this align with the intended design, or would you prefer a different approach for representing an "invalid" SamplePtr?

I was advised to reach out to @crimson11 for this part of the code, as he likely has deeper insight into the design.

@Gfilinic Gfilinic marked this pull request as ready for review March 30, 2026 13:40
@LittleHuba LittleHuba requested a review from darkwisebear March 30, 2026 13:43
@LittleHuba

Copy link
Copy Markdown
Contributor

Adding @darkwisebear and @bharatGoswami8 for input from Rust API side.

@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from fc8801e to c5defba Compare March 31, 2026 07:49

@castler castler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for your contribution.

I am the opinion that we should not expose this implementation detail - especially not the implementation data types.

We still want to give the opportuntity for a user to sort the samples.
Thus, we propose that the SamplePtr gets an bool IsNewer(SamplePtr<T> other) function instead.

@Gfilinic

Gfilinic commented Apr 1, 2026

Copy link
Copy Markdown
Author

Update: If I understood correctly, the intention is to avoid exposing EventTimeStamp (and related internals) and instead provide a way to compare samples without leaking those details.

With that in mind, I’ve moved GetTimestamp() to a private helper (so it can still be reused internally if needed) and introduced IsNewer() as the public API for comparison.

Unit tests were updated accordingly --> instead of checking timestamps directly, they now verify ordering by sorting SamplePtr instances using std::sort with IsNewer().

Let me know if this matches what you had in mind or if you'd prefer a different comparison approach.

@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from f567315 to 338c43f Compare April 1, 2026 10:07
@Gfilinic Gfilinic requested a review from castler April 1, 2026 13:29
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from 338c43f to d0ce09c Compare April 2, 2026 07:34
@Gfilinic

Gfilinic commented Apr 2, 2026

Copy link
Copy Markdown
Author

Update

  • Updated rust lola binding signature to match the newly proposed sample_ptr signature (noticed after failing workflow)

Comment thread score/mw/com/impl/bindings/lola/sample_ptr.h Outdated
Comment thread score/mw/com/impl/bindings/lola/sample_ptr.h Outdated
Comment thread score/mw/com/impl/bindings/lola/sample_ptr_test.cpp Outdated
Comment thread score/mw/com/impl/bindings/lola/sample_ptr_test.cpp Outdated
Comment thread score/mw/com/impl/bindings/lola/sample_ptr_test.cpp Outdated
@Gfilinic

Gfilinic commented Apr 8, 2026

Copy link
Copy Markdown
Author

Update

  • Add API documentation for newly introduced functions
  • Use std::uint8_t instead of uint8_t
  • Return false in SamplePtr::IsNewer() if either instance is invalid
  • Add test helper for creating SamplePtr instances
  • Refactor tests into focused cases:
    • newer vs. older comparisons
    • ordering via std::sort
    • invalid SamplePtr scenarios

@Gfilinic Gfilinic requested a review from castler April 8, 2026 10:25
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from 6ad242b to a392c6e Compare April 8, 2026 13:58
Comment thread score/mw/com/impl/bindings/lola/sample_ptr.h Outdated
Comment thread score/mw/com/impl/bindings/lola/sample_ptr.h Outdated
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch 2 times, most recently from 1246105 to a0db01f Compare April 10, 2026 10:12
@Gfilinic

Copy link
Copy Markdown
Author

Thanks for the feedback and the discussion so far.

I revisited the implementation and reworked the approach based on the suggestions.

Changes

  • Replaced the initially proposed dedicated function (IsNewer) with standard comparison operators:

    • operator<
    • operator>
  • Simplified the internal representation:

    • Instead of storing multiple internal members, the implementation now only keeps the timestamp (EventTimeStamp, underlying uint32_t)
    • Timestamp is captured once during construction
  • Updated impl::SamplePtr accordingly to expose the same comparison operators at the abstraction level

Notes on testing (impl::SamplePtr)

I did not introduce additional comparison tests for impl::SamplePtr.

The current plumbing tests rely on mock_binding::SamplePtr, which is defined as a std::unique_ptr alias and does not provide timestamp or comparison semantics.

Because of that:

  • comparisons in the plumbing layer would always evaluate to false
  • meaningful tests would require turning the mock binding into a full class with timestamp support

I intentionally did not extend the mock binding in this PR to keep the scope focused.

Additional notes

I force-pushed the branch with only these changes to clean up the git history, but I do have a backup branch with the previous implementation in case that approach is preferred.

@Gfilinic Gfilinic requested a review from crimson11 April 10, 2026 10:19
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from a0db01f to 6174fd1 Compare April 15, 2026 09:17
Comment thread score/mw/com/impl/plumbing/sample_ptr.h
Comment thread score/mw/com/impl/plumbing/sample_ptr.h Outdated
@Gfilinic Gfilinic requested a review from crimson11 April 16, 2026 11:15
Comment thread score/mw/com/impl/plumbing/sample_ptr.h
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from a62ae18 to 703d6a4 Compare April 22, 2026 09:03
@Gfilinic Gfilinic requested a review from crimson11 April 22, 2026 09:05
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from 703d6a4 to 77aec48 Compare April 28, 2026 09:51
@Gfilinic

Gfilinic commented May 5, 2026

Copy link
Copy Markdown
Author

Update

Added test in impl by implementing actual sampleptr instead of using generic mock pointer.

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If this PR is still relevant, please leave a comment or push new changes to keep it open.

@github-actions github-actions Bot added the stale label May 22, 2026
@Gfilinic Gfilinic force-pushed the add_timestamp_accessor_to_sample_ptr branch from 77aec48 to eb7b917 Compare May 26, 2026 09:28
@Gfilinic

Copy link
Copy Markdown
Author

Will there be more discussion in this PR or should I leave it be?

@github-actions github-actions Bot removed the stale label May 30, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. If this PR is still relevant, please leave a comment or push new changes to keep it open.

@LittleHuba

Copy link
Copy Markdown
Contributor

Hi @Gfilinic,
sorry for the extended silence. The colleague that did the reviews so far is on sick leave and this PR slipped through on the take over. I'll take the review up and will provide you feedback ASAP.

@LittleHuba LittleHuba assigned LittleHuba and unassigned Gfilinic Jun 18, 2026

@LittleHuba LittleHuba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @Gfilinic,
your PR looks good now. It can be merged as it currently is.
Though, ideally I would like an immediate follow-up that provides the implementation of this API in the mock_binding. Otherwise we have an API that is not mockable...
Are you interested in working on that?

@LittleHuba LittleHuba dismissed stale reviews from crimson11 and castler June 19, 2026 06:52

All remarks resolved.

Gfilinic added 4 commits June 19, 2026 12:06
Introduce operator< and operator> for comparing SamplePtr instances based on their timestamp.

As part of this change, the previous approach of storing additional internal state for indirect access was removed.
SamplePtr now stores only a local uint32_t timestamp value, which keeps the implementation simpler
and reduces memory overhead.

The operators return true only when both instances are valid and the comparison can be performed.
In all other cases (e.g. invalid or default-constructed instances), false is returned.
add comparison operators (< and >) for SamplePtr with safe variant handling via std::visit
@LittleHuba LittleHuba force-pushed the add_timestamp_accessor_to_sample_ptr branch from eb7b917 to d8d7c1b Compare June 19, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

5 participants