2
2
3
3
#include < conc/concurrency.hpp>
4
4
#include < log/catalog/catalog.hpp>
5
+ #include < log/catalog/mipi_builder.hpp>
6
+ #include < log/catalog/mipi_messages.hpp>
5
7
#include < log/log.hpp>
6
8
#include < log/module.hpp>
7
- #include < msg/message.hpp>
8
9
9
10
#include < stdx/bit.hpp>
10
11
#include < stdx/compiler.hpp>
@@ -37,68 +38,6 @@ template <stdx::ct_string S> constexpr auto to_module() {
37
38
}
38
39
} // namespace detail
39
40
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
-
102
41
template <typename TDestinations> struct log_handler {
103
42
constexpr explicit log_handler (TDestinations &&ds) : dests{std::move (ds)} {}
104
43
@@ -116,8 +55,10 @@ template <typename TDestinations> struct log_handler {
116
55
using Message = decltype (detail::to_message<S, Args...>());
117
56
using Module =
118
57
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)...));
121
62
});
122
63
}
123
64
@@ -126,11 +67,11 @@ template <typename TDestinations> struct log_handler {
126
67
if constexpr (S.empty () and stdx::bit_width (Version) <= 22 ) {
127
68
owning<defn::compact32_build_msg_t > message{" build_id" _field =
128
69
Version};
129
- dispatch_pass_by_args (message. data ()[ 0 ] );
70
+ write (message);
130
71
} else if constexpr (S.empty () and stdx::bit_width (Version) <= 54 ) {
131
72
owning<defn::compact64_build_msg_t > message{" build_id" _field =
132
73
Version};
133
- dispatch_pass_by_args (message. data ()[ 0 ], message. data ()[ 1 ] );
74
+ write (message);
134
75
} else {
135
76
constexpr auto header_size =
136
77
defn::normal_build_msg_t ::size<std::uint8_t >::value;
@@ -146,25 +87,13 @@ template <typename TDestinations> struct log_handler {
146
87
dest = std::copy_n (stdx::bit_cast<std::uint8_t const *>(&ver),
147
88
sizeof (std::uint64_t ), dest);
148
89
std::copy_n (std::cbegin (S.value ), S.size (), dest);
149
- dispatch_pass_by_buffer (message. data () );
90
+ write (message);
150
91
}
151
92
}
152
93
153
94
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 {
168
97
stdx::for_each (
169
98
[&]<typename Dest>(Dest &dest) {
170
99
conc::call_in_critical_section<Dest>(
@@ -173,42 +102,20 @@ template <typename TDestinations> struct log_handler {
173
102
dests);
174
103
}
175
104
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>{});
210
115
}
211
116
117
+ auto write (auto const &msg) -> void { write (msg.as_const_view ().data ()); }
118
+
212
119
TDestinations dests;
213
120
};
214
121
0 commit comments