1414#include < libcyphal/application/node.hpp>
1515#include < libcyphal/presentation/presentation.hpp>
1616#include < libcyphal/time_provider.hpp>
17+ #include < libcyphal/transport/transfer_id_map.hpp>
1718#include < libcyphal/transport/transport.hpp>
1819#include < libcyphal/transport/types.hpp>
1920#include < libcyphal/types.hpp>
2425#include < algorithm>
2526#include < array>
2627#include < cstdint>
28+ #include < functional>
2729#include < iomanip>
2830#include < ios>
2931#include < iostream>
3032#include < unistd.h>
33+ #include < unordered_map>
3134#include < utility>
3235
3336using namespace std ::chrono_literals;
@@ -131,6 +134,36 @@ enum class ExitCode : std::uint8_t
131134
132135}; // ExitCode
133136
137+ class TransferIdMap final : public libcyphal::transport::ITransferIdMap
138+ {
139+ public:
140+ explicit TransferIdMap (cetl::pmr::memory_resource& memory) noexcept
141+ : session_spec_to_transfer_id_{&memory}
142+ {
143+ }
144+
145+ private:
146+ using TransferId = libcyphal::transport::TransferId;
147+ using PmvAlloc = cetl::pmr::polymorphic_allocator<std::pair<const SessionSpec, TransferId>>;
148+ using PmrMap = std::unordered_map<SessionSpec, TransferId, std::hash<SessionSpec>, std::equal_to<>, PmvAlloc>;
149+
150+ // ITransferIdMap
151+
152+ TransferId getIdFor (const SessionSpec& session_spec) const noexcept override
153+ {
154+ const auto it = session_spec_to_transfer_id_.find (session_spec);
155+ return it != session_spec_to_transfer_id_.end () ? it->second : 0 ;
156+ }
157+
158+ void setIdFor (const SessionSpec& session_spec, const TransferId transfer_id) noexcept override
159+ {
160+ session_spec_to_transfer_id_[session_spec] = transfer_id;
161+ }
162+
163+ PmrMap session_spec_to_transfer_id_;
164+
165+ }; // TransferIdMap
166+
134167void PrintUniqueIdTo (const std::array<std::uint8_t , 16 >& unique_id, std::ostream& os)
135168{
136169 const auto original_flags = os.flags ();
@@ -169,6 +202,7 @@ libcyphal::Expected<bool, ExitCode> run_application(const char* const root_path)
169202 std::cerr << " ❌ Failed to create any transport.\n " ;
170203 return ExitCode::TransportCreationFailure;
171204 }
205+ TransferIdMap transfer_id_map{general_mr};
172206
173207 // 2. Create the presentation layer object.
174208 //
@@ -179,7 +213,9 @@ libcyphal::Expected<bool, ExitCode> run_application(const char* const root_path)
179213 std::cout << " Unique-ID : " ;
180214 PrintUniqueIdTo (unique_id, std::cout);
181215 std::cout << " \n " ;
216+ //
182217 libcyphal::presentation::Presentation presentation{general_mr, executor, *transport_iface};
218+ presentation.setTransferIdMap (&transfer_id_map);
183219
184220 // 3. Create the node object with name.
185221 //
0 commit comments