-
Notifications
You must be signed in to change notification settings - Fork 502
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
Changes from 80 commits
08a337d
88c4478
74d030c
bff389e
a90c2fe
47c4218
e9c5133
ec91d2a
dd2e74c
ec53ae0
a34dd90
fdb7480
f56d006
478e36d
34b6422
9a4703b
d318b1e
7b729e1
b92db32
4952f81
6e1c79b
a68fadb
a705deb
96b65ae
c4e478b
27a04f5
b0c2876
11bdbea
9e2a394
784665a
7c0a538
cdeedd4
7847d92
2ccfbf9
8d9ff46
de03c56
56d77e5
445c3d0
0f9ad7c
e2d38fa
01cfe9d
b8696a6
362dafb
769f23f
15a950d
1d62193
090b34f
05388d9
9404519
9baad4b
865fe6e
2b12f90
e69f8af
f104f7d
98a3934
3a0a6b9
50f26be
960dc20
dfe95f1
99a4bb7
08f036c
3aa2aa1
296f699
1f2d744
b94e0c8
85aa367
1786912
6d66d69
9c711df
b41fac8
05c4ad5
db0c796
6065693
e366c98
ffa98c5
814de68
03a1e60
377f0e0
a4c8ff1
03e1da1
975e6a7
2b06c32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Checks: >- | ||
boost-*, | ||
bugprone-*, | ||
cert-*, | ||
clang-analyzer-*, | ||
cppcoreguidelines-*, | ||
google-*, | ||
hicpp-*, | ||
llvm-*, | ||
misc-*, | ||
modernize-*, | ||
performance-*, | ||
portability-*, | ||
readability-*, | ||
-cppcoreguidelines-avoid-const-or-ref-data-members, | ||
-google-readability-todo, | ||
-readability-avoid-const-params-in-decls, | ||
-readability-identifier-length, | ||
-llvm-header-guard, | ||
-llvm-include-order, | ||
-*-use-trailing-return-type, | ||
-*-named-parameter, | ||
CheckOptions: | ||
- key: readability-function-cognitive-complexity.Threshold | ||
value: '90' | ||
- key: readability-magic-numbers.IgnoredIntegerValues | ||
value: '1;2;3;4;5;8;10;16;20;32;60;64;100;128;256;500;512;1000' | ||
WarningsAsErrors: '*' | ||
HeaderFilterRegex: '.*\.hpp' | ||
AnalyzeTemporaryDtors: false | ||
FormatStyle: file | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CETL's |
||
|
||
FetchContent_Declare( | ||
cetl | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1071,7 +1071,7 @@ EXCLUDE_PATTERNS = | |
# wildcard * is used, a substring. Examples: ANamespace, AClass, | ||
# ANamespace::AClass, ANamespace::*Test | ||
|
||
EXCLUDE_SYMBOLS = | ||
EXCLUDE_SYMBOLS = *::detail::* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Internal implementation detail won't go to generated docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
|
||
# The EXAMPLE_PATH tag can be used to specify one or more files or directories | ||
# that contain example code fragments that are included (see the \include | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#ifndef LIBCYPHAL_TRANSPORT_CAN_DELEGATE_HPP_INCLUDED | ||
#define LIBCYPHAL_TRANSPORT_CAN_DELEGATE_HPP_INCLUDED | ||
|
||
#include <libcyphal/transport/types.hpp> | ||
#include <libcyphal/transport/errors.hpp> | ||
#include <libcyphal/transport/scattered_buffer.hpp> | ||
|
||
|
@@ -29,7 +30,7 @@ namespace detail | |
/// This internal transport delegate class serves the following purposes: | ||
/// 1. It provides memory management functions for the Canard library. | ||
/// 2. It provides a way to convert Canard error codes to `AnyError` type. | ||
/// 3. It provides interface to access the transport from various session classes. | ||
/// 3. It provides an interface to access the transport from various session classes. | ||
/// | ||
class TransportDelegate | ||
{ | ||
|
@@ -40,7 +41,7 @@ class TransportDelegate | |
public: | ||
/// @brief RAII class to manage memory allocated by Canard library. | ||
/// | ||
class CanardMemory final : public cetl::rtti_helper<CanardMemoryTypeIdType, ScatteredBuffer::Interface> | ||
class CanardMemory final : public cetl::rtti_helper<CanardMemoryTypeIdType, ScatteredBuffer::IStorage> | ||
{ | ||
public: | ||
CanardMemory(TransportDelegate& delegate, void* const buffer, const std::size_t payload_size) | ||
|
@@ -70,7 +71,7 @@ class TransportDelegate | |
CanardMemory& operator=(const CanardMemory&) = delete; | ||
CanardMemory& operator=(CanardMemory&&) noexcept = delete; | ||
|
||
// MARK: ScatteredBuffer::Interface | ||
// MARK: ScatteredBuffer::Storage | ||
|
||
CETL_NODISCARD std::size_t size() const noexcept final | ||
{ | ||
|
@@ -161,10 +162,9 @@ class TransportDelegate | |
/// | ||
/// Internal method which is in use by TX session implementations to delegate actual sending to transport. | ||
/// | ||
CETL_NODISCARD virtual cetl::optional<AnyError> sendTransfer(const CanardMicrosecond deadline, | ||
CETL_NODISCARD virtual cetl::optional<AnyError> sendTransfer(const TimePoint deadline, | ||
const CanardTransferMetadata& metadata, | ||
const void* const payload, | ||
const std::size_t payload_size) = 0; | ||
const PayloadFragments payload_fragments) = 0; | ||
|
||
protected: | ||
~TransportDelegate() = default; | ||
|
@@ -230,26 +230,28 @@ class TransportDelegate | |
|
||
}; // TransportDelegate | ||
|
||
/// This internal session delegate class serves the following purpose: it provides interface | ||
/// to access a session from transport (by casting canard's `user_reference` member to this class). | ||
// MARK: - | ||
|
||
/// This internal session delegate class serves the following purpose: it provides an interface (aka gateway) | ||
/// to access RX session from transport (by casting canard's `user_reference` member to this class). | ||
/// | ||
class SessionDelegate | ||
class IRxSessionDelegate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding |
||
{ | ||
public: | ||
SessionDelegate(const SessionDelegate&) = delete; | ||
SessionDelegate(SessionDelegate&&) noexcept = delete; | ||
SessionDelegate& operator=(const SessionDelegate&) = delete; | ||
SessionDelegate& operator=(SessionDelegate&&) noexcept = delete; | ||
IRxSessionDelegate(const IRxSessionDelegate&) = delete; | ||
IRxSessionDelegate(IRxSessionDelegate&&) noexcept = delete; | ||
IRxSessionDelegate& operator=(const IRxSessionDelegate&) = delete; | ||
IRxSessionDelegate& operator=(IRxSessionDelegate&&) noexcept = delete; | ||
|
||
/// @brief Accepts a received transfer from the transport dedicated to this RX session. | ||
/// | ||
virtual void acceptRxTransfer(const CanardRxTransfer& transfer) = 0; | ||
|
||
protected: | ||
SessionDelegate() = default; | ||
~SessionDelegate() = default; | ||
IRxSessionDelegate() = default; | ||
~IRxSessionDelegate() = default; | ||
|
||
}; // SessionDelegate | ||
}; // IRxSessionDelegate | ||
|
||
} // namespace detail | ||
} // namespace can | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,22 +25,33 @@ namespace can | |
/// | ||
namespace detail | ||
{ | ||
class MessageRxSession final : public IMessageRxSession, private SessionDelegate | ||
|
||
/// @brief A class to represent a message subscriber RX session. | ||
/// | ||
class MessageRxSession final : public IMessageRxSession, private IRxSessionDelegate | ||
{ | ||
// In use to disable public construction. | ||
// See https://seanmiddleditch.github.io/enabling-make-unique-with-private-constructors/ | ||
struct Tag | ||
/// @brief Defines specification for making interface unique ptr. | ||
/// | ||
struct Spec | ||
{ | ||
explicit Tag() = default; | ||
using Interface = IMessageRxSession; | ||
using Concrete = MessageRxSession; | ||
|
||
// In use to disable public construction. | ||
// See https://seanmiddleditch.github.io/enabling-make-unique-with-private-constructors/ | ||
explicit Spec() = default; | ||
}; | ||
|
||
public: | ||
CETL_NODISCARD static Expected<UniquePtr<IMessageRxSession>, AnyError> make(TransportDelegate& delegate, | ||
const MessageRxParams& params) | ||
{ | ||
auto session = libcyphal::detail::makeUniquePtr<Tag>(delegate.memory(), Tag{}, delegate, params); | ||
if (params.subject_id > CANARD_SUBJECT_ID_MAX) | ||
{ | ||
return ArgumentError{}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameters are const (see |
||
|
||
auto session = libcyphal::detail::makeUniquePtr<Spec>(delegate.memory(), Spec{}, delegate, params); | ||
if (session == nullptr) | ||
{ | ||
return MemoryError{}; | ||
|
@@ -49,7 +60,7 @@ class MessageRxSession final : public IMessageRxSession, private SessionDelegate | |
return session; | ||
} | ||
|
||
MessageRxSession(Tag, TransportDelegate& delegate, const MessageRxParams& params) | ||
MessageRxSession(Spec, TransportDelegate& delegate, const MessageRxParams& params) | ||
: delegate_{delegate} | ||
, params_{params} | ||
, subscription_{} | ||
|
@@ -65,7 +76,7 @@ class MessageRxSession final : public IMessageRxSession, private SessionDelegate | |
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."); | ||
|
||
subscription_.user_reference = static_cast<SessionDelegate*>(this); | ||
subscription_.user_reference = static_cast<IRxSessionDelegate*>(this); | ||
} | ||
|
||
~MessageRxSession() final | ||
|
@@ -108,7 +119,7 @@ class MessageRxSession final : public IMessageRxSession, private SessionDelegate | |
// Nothing to do here currently. | ||
} | ||
|
||
// MARK: SessionDelegate | ||
// MARK: IRxSessionDelegate | ||
|
||
void acceptRxTransfer(const CanardRxTransfer& transfer) final | ||
{ | ||
|
@@ -129,9 +140,8 @@ class MessageRxSession final : public IMessageRxSession, private SessionDelegate | |
|
||
// MARK: Data members: | ||
|
||
TransportDelegate& delegate_; | ||
const MessageRxParams params_; | ||
|
||
TransportDelegate& delegate_; | ||
const MessageRxParams params_; | ||
CanardRxSubscription subscription_; | ||
cetl::optional<MessageRxTransfer> last_rx_transfer_; | ||
|
||
|
There was a problem hiding this comment.
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