22
33#include < conc/concurrency.hpp>
44#include < log/catalog/catalog.hpp>
5+ #include < log/catalog/mipi_builder.hpp>
6+ #include < log/catalog/mipi_messages.hpp>
57#include < log/log.hpp>
68#include < log/module.hpp>
7- #include < msg/message.hpp>
89
910#include < stdx/bit.hpp>
1011#include < stdx/compiler.hpp>
@@ -37,68 +38,6 @@ template <stdx::ct_string S> constexpr auto to_module() {
3738}
3839} // namespace detail
3940
40- namespace defn {
41- using msg::at;
42- using msg::dword_index_t ;
43- using msg::field;
44- using msg::message;
45- using msg::operator " " _msb;
46- using msg::operator " " _lsb;
47-
48- enum struct type : uint8_t { Build = 0 , Short32 = 1 , Catalog = 3 };
49- enum struct build_subtype : uint8_t { Compact32 = 0 , Compact64 = 1 , Long = 2 };
50- enum struct catalog_subtype : uint8_t { Id32_Pack32 = 1 };
51-
52- using type_f = field<" type" , type>::located<at{dword_index_t {0 }, 3_msb, 0_lsb}>;
53- using opt_len_f =
54- field<" opt_len" , bool >::located<at{dword_index_t {0 }, 9_msb, 9_lsb}>;
55- using payload_len_f =
56- field<" payload_len" ,
57- std::uint16_t >::located<at{dword_index_t {1 }, 15_msb, 0_lsb}>;
58-
59- using build_subtype_f =
60- field<" subtype" ,
61- build_subtype>::located<at{dword_index_t {0 }, 29_msb, 24_lsb}>;
62- using compact32_build_id_f = field<" build_id" , std::uint32_t >::located<
63- at{dword_index_t {0 }, 31_msb, 30_lsb}, at{dword_index_t {0 }, 23_msb, 4_lsb}>;
64- using compact64_build_id_f = field<" build_id" , std::uint64_t >::located<
65- at{dword_index_t {1 }, 31_msb, 0_lsb}, at{dword_index_t {0 }, 31_msb, 30_lsb},
66- at{dword_index_t {0 }, 23_msb, 4_lsb}>;
67-
68- using normal_build_msg_t =
69- message<" normal_build" , type_f::with_required<type::Build>,
70- opt_len_f::with_required<true >,
71- build_subtype_f::with_required<build_subtype::Long>, payload_len_f>;
72- using compact32_build_msg_t =
73- message<" compact32_build" , type_f::with_required<type::Build>,
74- build_subtype_f::with_required<build_subtype::Compact32>,
75- compact32_build_id_f>;
76- using compact64_build_msg_t =
77- message<" compact64_build" , type_f::with_required<type::Build>,
78- build_subtype_f::with_required<build_subtype::Compact64>,
79- compact64_build_id_f>;
80-
81- using short32_payload_f =
82- field<" payload" ,
83- std::uint32_t >::located<at{dword_index_t {0 }, 31_msb, 4_lsb}>;
84- using short32_msg_t =
85- message<" short32" , type_f::with_required<type::Short32>, short32_payload_f>;
86-
87- using catalog_subtype_f =
88- field<" subtype" ,
89- catalog_subtype>::located<at{dword_index_t {0 }, 29_msb, 24_lsb}>;
90- using severity_f = field<" severity" , std::uint8_t >::located<at{dword_index_t {0 },
91- 6_msb, 4_lsb}>;
92- using module_id_f =
93- field<" module_id" ,
94- std::uint8_t >::located<at{dword_index_t {0 }, 22_msb, 16_lsb}>;
95-
96- using catalog_msg_t =
97- message<" catalog" , type_f::with_required<type::Catalog>, severity_f,
98- module_id_f,
99- catalog_subtype_f::with_required<catalog_subtype::Id32_Pack32>>;
100- } // namespace defn
101-
10241template <typename TDestinations> struct log_handler {
10342 constexpr explicit log_handler (TDestinations &&ds) : dests{std::move (ds)} {}
10443
@@ -116,8 +55,10 @@ template <typename TDestinations> struct log_handler {
11655 using Message = decltype (detail::to_message<S, Args...>());
11756 using Module =
11857 decltype (detail::to_module<get_module (Env{}).value >());
119- dispatch_message<L>(catalog<Message>(), module <Module>(),
120- static_cast <std::uint32_t >(args)...);
58+ auto builder = get_builder (Env{}).value ;
59+ write (
60+ builder.template build <L>(catalog<Message>(), module <Module>(),
61+ static_cast <std::uint32_t >(args)...));
12162 });
12263 }
12364
@@ -126,11 +67,11 @@ template <typename TDestinations> struct log_handler {
12667 if constexpr (S.empty () and stdx::bit_width (Version) <= 22 ) {
12768 owning<defn::compact32_build_msg_t > message{" build_id" _field =
12869 Version};
129- dispatch_pass_by_args (message. data ()[ 0 ] );
70+ write (message);
13071 } else if constexpr (S.empty () and stdx::bit_width (Version) <= 54 ) {
13172 owning<defn::compact64_build_msg_t > message{" build_id" _field =
13273 Version};
133- dispatch_pass_by_args (message. data ()[ 0 ], message. data ()[ 1 ] );
74+ write (message);
13475 } else {
13576 constexpr auto header_size =
13677 defn::normal_build_msg_t ::size<std::uint8_t >::value;
@@ -146,25 +87,13 @@ template <typename TDestinations> struct log_handler {
14687 dest = std::copy_n (stdx::bit_cast<std::uint8_t const *>(&ver),
14788 sizeof (std::uint64_t ), dest);
14889 std::copy_n (std::cbegin (S.value ), S.size (), dest);
149- dispatch_pass_by_buffer (message. data () );
90+ write (message);
15091 }
15192 }
15293
15394 private:
154- template <typename ... MsgDataTypes>
155- NEVER_INLINE auto
156- dispatch_pass_by_args (MsgDataTypes &&...msg_data) -> void {
157- stdx::for_each (
158- [&]<typename Dest>(Dest &dest) {
159- conc::call_in_critical_section<Dest>([&] {
160- dest.log_by_args (std::forward<MsgDataTypes>(msg_data)...);
161- });
162- },
163- dests);
164- }
165-
166- NEVER_INLINE auto
167- dispatch_pass_by_buffer (stdx::span<std::uint8_t const > msg) -> void {
95+ template <std::size_t N>
96+ NEVER_INLINE auto write (stdx::span<std::uint8_t const , N> msg) -> void {
16897 stdx::for_each (
16998 [&]<typename Dest>(Dest &dest) {
17099 conc::call_in_critical_section<Dest>(
@@ -173,42 +102,20 @@ template <typename TDestinations> struct log_handler {
173102 dests);
174103 }
175104
176- template <auto Level, std::same_as<std::uint32_t >... MsgDataTypes>
177- ALWAYS_INLINE auto dispatch_message (string_id id,
178- [[maybe_unused]] module_id m,
179- MsgDataTypes... msg_data) -> void {
180- using namespace msg ;
181- if constexpr (sizeof ...(msg_data) == 0u ) {
182- owning<defn::short32_msg_t > message{" payload" _field = id};
183- dispatch_pass_by_args (message.data ()[0 ]);
184- } else if constexpr (sizeof ...(MsgDataTypes) <= 2u ) {
185- owning<defn::catalog_msg_t > message{" severity" _field = Level,
186- " module_id" _field = m};
187- dispatch_pass_by_args (
188- message.data ()[0 ], stdx::to_le (id),
189- stdx::to_le (std::forward<MsgDataTypes>(msg_data))...);
190- } else {
191- constexpr auto header_size =
192- defn::catalog_msg_t ::size<std::uint8_t >::value;
193- constexpr auto payload_len =
194- (sizeof (id) + ... + sizeof (MsgDataTypes));
195- using storage_t =
196- std::array<std::uint8_t , header_size + payload_len>;
197-
198- defn::catalog_msg_t ::owner_t <storage_t > message{
199- " severity" _field = Level, " module_id" _field = m};
200-
201- constexpr auto copy_arg = [](std::uint32_t arg, auto &dest) {
202- std::memcpy (dest, &arg, sizeof (std::uint32_t ));
203- dest += sizeof (std::uint32_t );
204- };
205- auto dest = &message.data ()[header_size];
206- copy_arg (stdx::to_le (id), dest);
207- (copy_arg (stdx::to_le (msg_data), dest), ...);
208- dispatch_pass_by_buffer (message.data ());
209- }
105+ template <std::size_t N>
106+ NEVER_INLINE auto write (stdx::span<std::uint32_t const , N> msg) -> void {
107+ [&]<std::size_t ... Is>(std::index_sequence<Is...>) {
108+ stdx::for_each (
109+ [&]<typename Dest>(Dest &dest) {
110+ conc::call_in_critical_section<Dest>(
111+ [&] { dest.log_by_args (msg[Is]...); });
112+ },
113+ dests);
114+ }(std::make_index_sequence<N>{});
210115 }
211116
117+ auto write (auto const &msg) -> void { write (msg.as_const_view ().data ()); }
118+
212119 TDestinations dests;
213120};
214121
0 commit comments