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

Service RX/TX Request/Response sessions #356

Merged
merged 82 commits into from
May 3, 2024

Conversation

serges147
Copy link
Collaborator

@serges147 serges147 commented May 2, 2024

  • Added Svc RX & TX sessions (both for Request & Response).
  • Now that we have more sessions, ContiguousPayload building moved to transport impl:
    • less code duplication
    • less to verify by unit tests
    • sessions now more like facade for RX/TX - they do necessary params validation/conversion, but ultimately delegate to the transport
  • switch to cetl::unbounded_variant (instead of former cetl::any)

Also:

  • minor changes for previous PR requests
  • more docs for stable api; excluding *::detail::* from generated docs

Codo coverage:
Screenshot 2024-05-02 at 09 53 11

serges147 and others added 30 commits April 11, 2024 08:30
WarningsAsErrors: '*'
HeaderFilterRegex: '.*\.hpp'
AnalyzeTemporaryDtors: false
FormatStyle: file
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not yet integrated, but just initial version of the config according issue #226

@@ -6,7 +6,7 @@

include(FetchContent)
set(cetl_GIT_REPOSITORY "https://github.com/OpenCyphal/cetl.git")
set(cetl_GIT_TAG "886a0d227a043511eed6b252ea0f788590c50e75")
set(cetl_GIT_TAG "10fbb2b7b89473d68e73db7235848b0692169e5a")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CETL's main (with recently merged cetl::unbounded_variant.

@@ -1071,7 +1071,7 @@ EXCLUDE_PATTERNS =
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# ANamespace::AClass, ANamespace::*Test

EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = *::detail::*
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Internal implementation detail won't go to generated docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

///
class SessionDelegate
class IRxSessionDelegate
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding I prefix for anything like an interface (regardless whether it's internal or public stuff) - as it was requested in previous PR.

if (params.subject_id > CANARD_SUBJECT_ID_MAX)
{
return ArgumentError{};
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Parameters are const (see params_ below), and their subject_id won't change. So, it makes sense fail early (at make phase) rather than later during transmissions. The same story for other session factories.

/// Could be either `CanardTransferKindRequest` or `CanardTransferKindResponse`.
///
template <typename Interface_, typename Params, CanardTransferKind TransferKind>
class SvcRxSession final : public Interface_, private IRxSessionDelegate
Copy link
Collaborator Author

@serges147 serges147 May 2, 2024

Choose a reason for hiding this comment

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

Both service RX sessions (rx request and rx response) are almost the same in terms of structure and functionality. The only slight difference is their interface name, params type and "kind" of canard transfer. So, IMO making template here is fine and justifiable b/c ...:

  1. it's detail-s, not exposed to a user
  2. no code duplication
  3. both instantiations (see below just after the template) are 100% covered by unit tests (at line, function and branches level). Please see attached (to the PR description) screenshot of coverage stats.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

BTW, MessageRxSession is also very similar, BUT still has its differences (in terms of params validation and anonymous case handling), so it does not fit into such RX template IMO (hence there is minor code duplication - all covered of course by tests).

&subscription_);
(void) result;
CETL_DEBUG_ASSERT(result >= 0, "There is no way currently to get an error here.");
CETL_DEBUG_ASSERT(result > 0, "New subscription supposed to be made.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no currently path to fail - pre-validation done at factory.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, why can't this fail?

Copy link
Member

Choose a reason for hiding this comment

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

@thirtytwobits the only possible error condition occurs if we feed invalid arguments, which we pre-validate and know are correct; hence, it can't fail.

{
::canardRxUnsubscribe(&delegate_.canard_instance(),
TransferKind,
static_cast<CanardPortID>(params_.service_id));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No path fail as well, but if you think its worth to assert I can do it (here and for msg rx session).

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the debug asserts as long as we are able to verify them.

///
/// @see ScatteredBuffer::ScatteredBuffer(AnyStorage&& any_storage)
///
class IStorage : public cetl::rtti_helper<IStorageTypeIdType>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here and there (including in the design doc) we use word "storage" when we talk about Lizard-specific implementation of actual (potentially) scattered storage this "facade" ScatteredBuffer is using. So, I decided to rename nested Interface to IMO more meaningful IStorage.

auto locale = os->imbue(std::locale("en_US"));
*os << std::chrono::duration_cast<std::chrono::microseconds>(duration).count() << "_us";
auto locale = os->imbue(std::locale(""));
*os << std::chrono::duration_cast<std::chrono::microseconds>(duration).count() << " us";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Previous version failed on my "Estonian only" Ubuntu (b/c there is no "en_US" locale there) ;)
BTW, locale stuff here is just to have more human friendly gtest failure output (like 1'000'000 us vs 1000000 us without it).

{
return DestinationNodeCanIdMatcher(node_id);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All these gmock matchers (and PrintTo helpers) have no use when all the tests are green (b/c there is no output), but it makes big difference when something goes wrong. Using them (in conjunction with EXPECT_THAT macro) gives you nice print of what was expected and what actually is. Stay tuned, even more will be added...

@serges147 serges147 changed the title Sshirokov/346 svc tx rx Service RX/TX Request/Response sessions May 2, 2024
@serges147 serges147 self-assigned this May 2, 2024
@@ -1071,7 +1071,7 @@ EXCLUDE_PATTERNS =
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# ANamespace::AClass, ANamespace::*Test

EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = *::detail::*
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

&subscription_);
(void) result;
CETL_DEBUG_ASSERT(result >= 0, "There is no way currently to get an error here.");
CETL_DEBUG_ASSERT(result > 0, "New subscription supposed to be made.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, why can't this fail?

{
::canardRxUnsubscribe(&delegate_.canard_instance(),
TransferKind,
static_cast<CanardPortID>(params_.service_id));
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the debug asserts as long as we are able to verify them.


void run(const TimePoint) final
{
// Nothing to do here currently.
Copy link
Contributor

Choose a reason for hiding this comment

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

image

/// This value may change arbitrarily at runtime. The transport implementation will query it before every
/// transmission on the port. This value has no effect on the reception pipeline as it can accept arbitrary MTU.
///
CETL_NODISCARD virtual std::size_t getMtu() const noexcept = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a public API and nothing catastrophic happens if the value isn't used. Please omit CETL_NODISCARD value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, I will do it. But there is separate issue about revising everything in terms of "to discard or not to discard" question.

@thirtytwobits thirtytwobits merged commit e271e12 into issue/346_can_sessions May 3, 2024
18 checks passed
@thirtytwobits thirtytwobits deleted the sshirokov/346_svc_tx_rx branch May 3, 2024 18:44
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.

4 participants