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

No CETL_NODISCARD for most of the public api #359

Merged
merged 171 commits into from
May 14, 2024

Conversation

serges147
Copy link
Collaborator

@serges147 serges147 commented May 13, 2024

No CETL_NODISCARD for the most of public api (issue #350), but private (aka detail) stuff stays under strict [[nodiscard]] policy for all non-void returning functions.

Also:

  • Less NOSONAR-s by switching some internal void*-s → cetl::byte*-s.
  • Eliminated IMultiplexer at CAN - no use of it; but will be at UDP.
  • More docs for public api.
  • Fixed Build Status and Sonar Cloud badges at README.md.

serges147 and others added 30 commits April 11, 2024 08:30
@serges147 serges147 self-assigned this May 13, 2024
[![Sonarqube Badge](https://sonarcloud.io/api/project_badges/measure?project=UAVCAN_libuavcan&metric=alert_status)](https://sonarcloud.io/dashboard?id=UAVCAN_libuavcan)
[![Sonarqube Coverage](https://sonarcloud.io/api/project_badges/measure?project=UAVCAN_libuavcan&metric=coverage)](https://sonarcloud.io/dashboard?id=UAVCAN_libuavcan)
[![Sonarqube Badge](https://sonarcloud.io/api/project_badges/measure?project=OpenCyphal-Garage_libcyphal&metric=alert_status)](https://sonarcloud.io/project/overview?id=OpenCyphal-Garage_libcyphal)
[![Sonarqube Coverage](https://sonarcloud.io/api/project_badges/measure?project=OpenCyphal-Garage_libcyphal&metric=coverage)](https://sonarcloud.io/project/overview?id=OpenCyphal-Garage_libcyphal)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When time comes we of course will quickly search/replace "OpenCyphal-Garage" to → "OpenCyphal" everywhere in this repo.


/// @brief Takes the next payload fragment (aka CAN frame) from the reception queue unless it's empty.
///
/// @param payload_buffer The payload of the frame will be written into the mutable `payload_buffer` (aka span).
/// @return Description of a received fragment if available; otherwise an empty optional is returned immediately.
/// `nodiscard` is used to prevent ignoring the return value, which contains not only possible media error,
/// but also important metadata (like `payload_size` field for further parsing of the result payload).
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO this is the only public method which has little sense with discarding its result. All other methods could be used without checking results (f.e. if you don't care about possible errors and etc.) - anyway, no leaks or dangerous behavior will happen.

include/libcyphal/transport/can/transport.hpp Outdated Show resolved Hide resolved
include/libcyphal/transport/can/transport.hpp Outdated Show resolved Hide resolved
Comment on lines 70 to 72
/// @param params Various initial parameters for the message RX session (like subject id and extent size).
/// @return Either a unique interface pointer to the message RX session, or an error.
///
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// @param params Various initial parameters for the message RX session (like subject id and extent size).
/// @return Either a unique interface pointer to the message RX session, or an error.
///

Do these comments serve any purpose at all? It is evident from the type of the method that it takes params and returns either an interface unique ptr or an error, why spell it out? For better SNR we should only write things that are worth writing.

@thirtytwobits this is an example of an unhelpful doc comment; I suggest we avoid these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I need them for two purposes:

  1. Please see that, in addition to "obvious" stuff, there is also extra note about lifetime of result sessions regarding parent transport.
  2. Doxygen - docs generation is just bad without explicit mentioning of public functions.
  3. Last but not least - there is less confusion in rules what we document and what we don't - it's much easier to go with "always document public stuff" comparing to fuzzy "it is evident from ..."

Copy link
Member

Choose a reason for hiding this comment

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

My objection applies only to the two lines I commented on -- the ones that begin with @param and @return; the rest is useful and should be kept. I think this addresses points 1 and 2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, ok, got it - will remove these pairs of lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

serges147 and others added 2 commits May 13, 2024 13:13
Co-authored-by: Pavel Kirienko <pavel.kirienko@gmail.com>
Co-authored-by: Pavel Kirienko <pavel.kirienko@gmail.com>
Copy link

sonarcloud bot commented May 13, 2024

CETL_NODISCARD std::size_t copy(const std::size_t offset_bytes,
void* const destination,
const std::size_t length_bytes) const
/// NOSONAR cpp:S5008 below currently unavoidable. Could be fixed if nunavut provides `cetl::byte*` support.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we're using cetl::byte* in other places in this PR now. Does this comment still apply?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this comment still applies. Public facing ScatteredBuffer still uses void* as a second parameter. Internal stuff (aka detail) is switched to cetl::byte*.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it, thanks

@lydia-at-amazon
Copy link
Collaborator

nit: Title of PR: No CETL_NODISCARD for the most of public api --> No CETL_NODISCARD for most of the public api

@serges147 serges147 changed the title No CETL_NODISCARD for the most of public api No CETL_NODISCARD for most of the public api May 13, 2024

/// @brief Makes a message receive (RX) session.
///
/// Lifetime of the RX session must never outlive this transport interface.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Lifetime of the RX session must never outlive this transport interface.
/// The RX session must never outlive this transport interface.

Copy link

sonarcloud bot commented May 14, 2024

@serges147 serges147 merged commit abcfc14 into issue/346_can_sessions May 14, 2024
21 checks passed
@serges147 serges147 deleted the sshirokov/350_nodiscard2 branch May 14, 2024 12:40
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.

None yet

4 participants