1010
1111#include " libcyphal/errors.hpp"
1212#include " libcyphal/transport/errors.hpp"
13+ #include " libcyphal/transport/svc_rx_session_base.hpp"
1314#include " libcyphal/transport/svc_sessions.hpp"
14- #include " libcyphal/transport/types.hpp"
1515#include " libcyphal/types.hpp"
1616
1717#include < canard.h>
1818#include < cetl/cetl.hpp>
1919#include < cetl/pf17/cetlpf.hpp>
2020
2121#include < chrono>
22- #include < cstdint>
23- #include < utility>
2422
2523namespace libcyphal
2624{
@@ -35,85 +33,11 @@ namespace can
3533namespace detail
3634{
3735
38- // / @brief A base class to represent a service RX session.
39- // /
40- template <typename Interface_, typename Params>
41- class SvcRxSessionBase : public IRxSessionDelegate , public Interface_
42- {
43- public:
44- SvcRxSessionBase (TransportDelegate& delegate, const Params& params)
45- : delegate_{delegate}
46- , params_{params}
47- {
48- }
49-
50- SvcRxSessionBase (const SvcRxSessionBase&) = delete ;
51- SvcRxSessionBase (SvcRxSessionBase&&) noexcept = delete ;
52- SvcRxSessionBase& operator =(const SvcRxSessionBase&) = delete ;
53- SvcRxSessionBase& operator =(SvcRxSessionBase&&) noexcept = delete ;
54-
55- protected:
56- ~SvcRxSessionBase () = default ;
57-
58- TransportDelegate& delegate ()
59- {
60- return delegate_;
61- }
62-
63- // MARK: Interface
64-
65- CETL_NODISCARD Params getParams () const noexcept final
66- {
67- return params_;
68- }
69-
70- CETL_NODISCARD cetl::optional<ServiceRxTransfer> receive () final
71- {
72- if (last_rx_transfer_)
73- {
74- auto transfer = std::move (*last_rx_transfer_);
75- last_rx_transfer_.reset ();
76- return transfer;
77- }
78- return cetl::nullopt ;
79- }
80-
81- void setOnReceiveCallback (ISvcRxSession::OnReceiveCallback::Function&& function) final
82- {
83- on_receive_cb_fn_ = std::move (function);
84- }
85-
86- // MARK: IRxSessionDelegate
87-
88- void acceptRxTransfer (CanardMemory&& canard_memory,
89- const TransferRxMetadata& rx_metadata,
90- const CanardNodeID source_node_id) final
91- {
92- const ServiceRxMetadata meta{rx_metadata, source_node_id};
93- ServiceRxTransfer svc_rx_transfer{meta, ScatteredBuffer{std::move (canard_memory)}};
94- if (on_receive_cb_fn_)
95- {
96- on_receive_cb_fn_ (ISvcRxSession::OnReceiveCallback::Arg{svc_rx_transfer});
97- return ;
98- }
99- (void ) last_rx_transfer_.emplace (std::move (svc_rx_transfer));
100- }
101-
102- private:
103- // MARK: Data members:
104-
105- TransportDelegate& delegate_;
106- const Params params_;
107- cetl::optional<ServiceRxTransfer> last_rx_transfer_;
108- ISvcRxSession::OnReceiveCallback::Function on_receive_cb_fn_;
109-
110- }; // SvcRxSessionBase
111-
112- // MARK: -
113-
11436// / @brief A concrete class to represent a service request RX session (aka server side).
11537// /
116- class SvcRequestRxSession final : public SvcRxSessionBase<IRequestRxSession, RequestRxParams>
38+ class SvcRequestRxSession final
39+ : public transport::detail:: //
40+ SvcRxSessionBase<IRequestRxSession, IRxSessionDelegate, TransportDelegate, RequestRxParams, CanardMemory>
11741{
11842 // / @brief Defines private specification for making interface unique ptr.
11943 // /
@@ -191,7 +115,9 @@ class SvcRequestRxSession final : public SvcRxSessionBase<IRequestRxSession, Req
191115
192116// / @brief A concrete class to represent a service response RX session (aka client side).
193117// /
194- class SvcResponseRxSession final : public SvcRxSessionBase<IResponseRxSession, ResponseRxParams>
118+ class SvcResponseRxSession final
119+ : public transport::detail:: //
120+ SvcRxSessionBase<IResponseRxSession, IRxSessionDelegate, TransportDelegate, ResponseRxParams, CanardMemory>
195121{
196122 // / @brief Defines private specification for making interface unique ptr.
197123 // /
0 commit comments