14
14
#include < libcyphal/application/node.hpp>
15
15
#include < libcyphal/presentation/presentation.hpp>
16
16
#include < libcyphal/time_provider.hpp>
17
+ #include < libcyphal/transport/transfer_id_map.hpp>
17
18
#include < libcyphal/transport/transport.hpp>
18
19
#include < libcyphal/transport/types.hpp>
19
20
#include < libcyphal/types.hpp>
24
25
#include < algorithm>
25
26
#include < array>
26
27
#include < cstdint>
28
+ #include < functional>
27
29
#include < iomanip>
28
30
#include < ios>
29
31
#include < iostream>
30
32
#include < unistd.h>
33
+ #include < unordered_map>
31
34
#include < utility>
32
35
33
36
using namespace std ::chrono_literals;
@@ -131,6 +134,36 @@ enum class ExitCode : std::uint8_t
131
134
132
135
}; // ExitCode
133
136
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
+
134
167
void PrintUniqueIdTo (const std::array<std::uint8_t , 16 >& unique_id, std::ostream& os)
135
168
{
136
169
const auto original_flags = os.flags ();
@@ -169,6 +202,7 @@ libcyphal::Expected<bool, ExitCode> run_application(const char* const root_path)
169
202
std::cerr << " ❌ Failed to create any transport.\n " ;
170
203
return ExitCode::TransportCreationFailure;
171
204
}
205
+ TransferIdMap transfer_id_map{general_mr};
172
206
173
207
// 2. Create the presentation layer object.
174
208
//
@@ -179,7 +213,9 @@ libcyphal::Expected<bool, ExitCode> run_application(const char* const root_path)
179
213
std::cout << " Unique-ID : " ;
180
214
PrintUniqueIdTo (unique_id, std::cout);
181
215
std::cout << " \n " ;
216
+ //
182
217
libcyphal::presentation::Presentation presentation{general_mr, executor, *transport_iface};
218
+ presentation.setTransferIdMap (&transfer_id_map);
183
219
184
220
// 3. Create the node object with name.
185
221
//
0 commit comments