@@ -50,15 +50,17 @@ class MessageRxSession final : private IRxSessionDelegate, public IMessageRxSess
5050 };
5151
5252public:
53- CETL_NODISCARD static Expected<UniquePtr<IMessageRxSession>, AnyFailure> make (TransportDelegate& delegate,
54- const MessageRxParams& params)
53+ CETL_NODISCARD static Expected<UniquePtr<IMessageRxSession>, AnyFailure> make ( //
54+ cetl::pmr::memory_resource& memory,
55+ TransportDelegate& delegate,
56+ const MessageRxParams& params)
5557 {
5658 if (params.subject_id > CANARD_SUBJECT_ID_MAX)
5759 {
5860 return ArgumentError{};
5961 }
6062
61- auto session = libcyphal::detail::makeUniquePtr<Spec>(delegate. memory () , Spec{}, delegate, params);
63+ auto session = libcyphal::detail::makeUniquePtr<Spec>(memory, Spec{}, delegate, params);
6264 if (session == nullptr )
6365 {
6466 return MemoryError{};
@@ -72,20 +74,12 @@ class MessageRxSession final : private IRxSessionDelegate, public IMessageRxSess
7274 , params_{params}
7375 , subscription_{}
7476 {
75- const std::int8_t result = ::canardRxSubscribe (&delegate.canardInstance (),
76- CanardTransferKindMessage,
77- params_.subject_id ,
78- params_.extent_bytes ,
79- CANARD_DEFAULT_TRANSFER_ID_TIMEOUT_USEC,
80- &subscription_);
81- (void ) result;
82- CETL_DEBUG_ASSERT (result >= 0 , " There is no way currently to get an error here." );
83- CETL_DEBUG_ASSERT (result > 0 , " New subscription supposed to be made." );
77+ delegate.listenForRxSubscription (subscription_, params);
8478
8579 // No Sonar `cpp:S5356` b/c we integrate here with C libcanard API.
8680 subscription_.user_reference = static_cast <IRxSessionDelegate*>(this ); // NOSONAR cpp:S5356
8781
88- delegate_.onSessionEvent (TransportDelegate::SessionEvent::MsgRxLifetime{ true /* is_added */ });
82+ delegate_.onSessionEvent (TransportDelegate::SessionEvent::MsgCreated{ });
8983 }
9084
9185 MessageRxSession (const MessageRxSession&) = delete ;
@@ -95,13 +89,8 @@ class MessageRxSession final : private IRxSessionDelegate, public IMessageRxSess
9589
9690 ~MessageRxSession ()
9791 {
98- const std::int8_t result =
99- ::canardRxUnsubscribe (&delegate_.canardInstance(), CanardTransferKindMessage, params_.subject_id);
100- (void ) result;
101- CETL_DEBUG_ASSERT (result >= 0 , " There is no way currently to get an error here." );
102- CETL_DEBUG_ASSERT (result > 0 , " Subscription supposed to be made at constructor." );
103-
104- delegate_.onSessionEvent (TransportDelegate::SessionEvent::MsgRxLifetime{false /* is_added */ });
92+ delegate_.cancelRxSubscriptionFor (subscription_, CanardTransferKindMessage);
93+ delegate_.onSessionEvent (TransportDelegate::SessionEvent::MsgDestroyed{});
10594 }
10695
10796private:
@@ -141,26 +130,15 @@ class MessageRxSession final : private IRxSessionDelegate, public IMessageRxSess
141130
142131 // MARK: IRxSessionDelegate
143132
144- void acceptRxTransfer (const CanardRxTransfer& transfer) override
133+ void acceptRxTransfer (CanardMemory&& lizard_memory,
134+ const TransferRxMetadata& rx_metadata,
135+ const NodeId source_node_id) override
145136 {
146- const auto priority = static_cast <Priority>(transfer.metadata .priority );
147- const auto transfer_id = static_cast <TransferId>(transfer.metadata .transfer_id );
148- const auto timestamp = TimePoint{std::chrono::microseconds{transfer.timestamp_usec }};
149-
150137 const cetl::optional<NodeId> publisher_node_id =
151- transfer.metadata .remote_node_id > CANARD_NODE_ID_MAX
152- ? cetl::nullopt
153- : cetl::make_optional<NodeId>(transfer.metadata .remote_node_id );
154-
155- // No Sonar `cpp:S5356` and `cpp:S5357` b/c we need to pass raw data from C libcanard api.
156- auto * const buffer = static_cast <cetl::byte*>(transfer.payload .data ); // NOSONAR cpp:S5356 cpp:S5357
157- TransportDelegate::CanardMemory canard_memory{delegate_,
158- transfer.payload .allocated_size ,
159- buffer,
160- transfer.payload .size };
161-
162- const MessageRxMetadata meta{{{transfer_id, priority}, timestamp}, publisher_node_id};
163- MessageRxTransfer msg_rx_transfer{meta, ScatteredBuffer{std::move (canard_memory)}};
138+ source_node_id > CANARD_NODE_ID_MAX ? cetl::nullopt : cetl::make_optional (source_node_id);
139+
140+ const MessageRxMetadata meta{rx_metadata, publisher_node_id};
141+ MessageRxTransfer msg_rx_transfer{meta, ScatteredBuffer{std::move (lizard_memory)}};
164142 if (on_receive_cb_fn_)
165143 {
166144 on_receive_cb_fn_ (OnReceiveCallback::Arg{msg_rx_transfer});
0 commit comments