Skip to content

Commit 890ec25

Browse files
committed
added msg type id
1 parent 286eeb1 commit 890ec25

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/common/ipc/channel.hpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <nunavut/support/serialization.hpp>
1313

1414
#include <cetl/pf17/cetlpf.hpp>
15+
#include <libcyphal/common/crc.hpp>
1516

1617
#include <cstddef>
1718
#include <functional>
@@ -33,11 +34,19 @@ class AnyChannel
3334
struct Disconnected
3435
{};
3536

36-
template <typename Input>
37-
using EventVar = cetl::variant<Input, Connected, Disconnected>;
37+
template <typename Message>
38+
using EventVar = cetl::variant<Message, Connected, Disconnected>;
3839

39-
template <typename Input>
40-
using EventHandler = std::function<void(const EventVar<Input>&)>;
40+
template <typename Message>
41+
using EventHandler = std::function<void(const EventVar<Message>&)>;
42+
43+
template <typename Message>
44+
static detail::MsgTypeId getTypeId() noexcept
45+
{
46+
const cetl::string_view type_name{Message::_traits_::FullNameAndVersion()};
47+
const libcyphal::common::CRC64WE crc64{type_name.cbegin(), type_name.cend()};
48+
return crc64.get();
49+
}
4150

4251
protected:
4352
AnyChannel() = default;
@@ -57,6 +66,7 @@ class Channel final : public AnyChannel
5766
: memory_{other.memory_}
5867
, gateway_{std::move(other.gateway_)}
5968
, event_handler_{std::move(other.event_handler_)}
69+
, output_type_id_{other.output_type_id_}
6070
{
6171
setupEventHandler();
6272
}
@@ -83,7 +93,7 @@ class Channel final : public AnyChannel
8393
output,
8494
[this](const auto payload) {
8595
//
86-
gateway_->send(payload);
96+
gateway_->send(output_type_id_, payload);
8797
return cetl::nullopt;
8898
});
8999
}
@@ -95,6 +105,7 @@ class Channel final : public AnyChannel
95105
: memory_{memory}
96106
, gateway_{std::move(gateway)}
97107
, event_handler_{std::move(event_handler)}
108+
, output_type_id_{getTypeId<Output>()}
98109
{
99110
CETL_DEBUG_ASSERT(gateway_, "");
100111
CETL_DEBUG_ASSERT(event_handler_, "");
@@ -139,6 +150,7 @@ class Channel final : public AnyChannel
139150
cetl::pmr::memory_resource& memory_;
140151
detail::Gateway::Ptr gateway_;
141152
EventHandler event_handler_;
153+
detail::MsgTypeId output_type_id_;
142154

143155
}; // Channel
144156

src/common/ipc/client_router.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ class ClientRouterImpl final : public ClientRouter
106106
setEventHandler(nullptr);
107107
}
108108

109-
void send(const pipe::Payload payload) override
109+
void send(const detail::MsgTypeId type_id, const pipe::Payload payload) override
110110
{
111111
Route_1_0 route{&router_.memory_};
112112
auto& channel_msg = route.set_channel_msg();
113113
channel_msg.tag = tag_;
114+
channel_msg.type_id = type_id;
114115

115116
tryPerformOnSerialized(route, [this, payload](const auto prefix) {
116117
//

src/common/ipc/gateway.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace ipc
2424
namespace detail
2525
{
2626

27+
using MsgTypeId = std::uint64_t;
28+
2729
class Gateway
2830
{
2931
public:
@@ -52,9 +54,9 @@ class Gateway
5254
Gateway& operator=(const Gateway&) = delete;
5355
Gateway& operator=(Gateway&&) noexcept = delete;
5456

55-
virtual void send(const pipe::Payload payload) = 0;
56-
virtual void event(const Event::Var& event) = 0;
57-
virtual void setEventHandler(EventHandler event_handler) = 0;
57+
virtual void send(const MsgTypeId type_id, const pipe::Payload payload) = 0;
58+
virtual void event(const Event::Var& event) = 0;
59+
virtual void setEventHandler(EventHandler event_handler) = 0;
5860

5961
protected:
6062
Gateway() = default;

0 commit comments

Comments
 (0)