Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ include(cmake/string_catalog.cmake)
add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
fmt_recipe(11.1.3)
add_versioned_package("gh:intel/cpp-baremetal-concurrency#09c043b")
add_versioned_package("gh:intel/cpp-std-extensions#8e2f948")
add_versioned_package("gh:intel/cpp-std-extensions#ca9e67a")
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#27db6e1")

set(GEN_STR_CATALOG
Expand Down
46 changes: 18 additions & 28 deletions include/log/catalog/encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <log/catalog/arguments.hpp>
#include <log/catalog/builder.hpp>
#include <log/catalog/catalog.hpp>
#include <log/catalog/writer.hpp>
#include <log/log.hpp>
#include <log/module.hpp>
#include <log/module_id.hpp>
Expand Down Expand Up @@ -44,40 +45,23 @@ template <typename S, auto Id> struct to_message_t {
template <typename... Args>
using fn = decltype(to_message<S, Id, Args...>());
};

} // namespace detail

template <typename Destinations> struct log_writer {
template <std::size_t N>
auto operator()(stdx::span<std::uint8_t const, N> msg) -> void {
auto operator()(auto msg) -> void {
stdx::for_each(
[&]<typename Dest>(Dest &dest) {
conc::call_in_critical_section<Dest>(
[&] { dest.log_by_buf(msg); });
conc::call_in_critical_section<Dest>([&] { dest(msg); });
},
dests);
}

template <std::size_t N>
auto operator()(stdx::span<std::uint32_t const, N> msg) -> void {
[&]<std::size_t... Is>(std::index_sequence<Is...>) {
stdx::for_each(
[&]<typename Dest>(Dest &dest) {
conc::call_in_critical_section<Dest>(
[&] { dest.log_by_args(msg[Is]...); });
},
dests);
}(std::make_index_sequence<N>{});
}

auto operator()(auto const &msg) -> void {
this->operator()(msg.as_const_view().data());
}

Destinations dests;
};
template <typename T> log_writer(T) -> log_writer<T>;

template <typename Writer> struct log_handler {
template <writer_like Writer> struct log_handler {
template <typename Env, typename FilenameStringType,
typename LineNumberType, typename FmtResult>
auto log(FilenameStringType, LineNumberType, FmtResult const &fr) -> void {
Expand All @@ -86,8 +70,9 @@ template <typename Writer> struct log_handler {

template <typename Env, typename FmtResult>
auto log_msg(FmtResult const &fr) -> void {
auto builder = get_builder(Env{});
writer_like auto writer = stdx::query<Env>(get_writer, w);
fr.args.apply([&]<typename... Args>(Args &&...args) {
auto builder = get_builder(Env{});
constexpr auto L = stdx::to_underlying(get_level(Env{}));
using Message = typename decltype(builder)::template convert_args<
detail::to_message_t<decltype(fr.str), logging::get_string_id(
Expand All @@ -96,26 +81,31 @@ template <typename Writer> struct log_handler {
using Module =
decltype(detail::to_module<get_module(Env{}),
logging::get_module_id(Env{})>());
w(builder.template build<L>(catalog<Message>(), module<Module>(),
std::forward<Args>(args)...));
auto const pkt =
builder.template build<L>(catalog<Message>(), module<Module>(),
std::forward<Args>(args)...);
writer(pkt.as_const_view().data());
});
}

template <typename Env, auto Version, stdx::ct_string S = "">
auto log_version() -> void {
auto builder = get_builder(Env{});
w(builder.template build_version<Version, S>());
writer_like auto writer = stdx::query<Env>(get_writer, w);
auto const pkt = builder.template build_version<Version, S>();
writer(pkt.as_const_view().data());
}

Writer w;
};

template <typename... TDestinations> struct config {
using destinations_tuple_t = stdx::tuple<TDestinations...>;
constexpr explicit config(TDestinations... dests)
template <writer_like... Dests> struct config {
using destinations_tuple_t = stdx::tuple<Dests...>;
constexpr explicit config(Dests... dests)
: logger{log_writer{stdx::tuple{std::move(dests)...}}} {}

log_handler<log_writer<destinations_tuple_t>> logger;
};

template <typename... Ts> config(Ts...) -> config<Ts...>;
} // namespace logging::binary
24 changes: 7 additions & 17 deletions include/log/catalog/mipi_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,13 @@ template <packer P> struct builder<defn::catalog_msg_t, P> {
using namespace msg;
constexpr auto payload_size =
(sizeof(id) + ... + sizeof(typename P::template pack_as_t<Ts>));
if constexpr (payload_size <= sizeof(uint32_t) * 3) {
constexpr auto header_size =
defn::catalog_msg_t::size<std::uint32_t>::value;
using storage_t =
std::array<std::uint32_t,
header_size +
stdx::sized8{payload_size}.in<std::uint32_t>()>;
return catalog_builder<storage_t, P>{}.template build<Level>(
id, m, args...);
} else {
constexpr auto header_size =
defn::catalog_msg_t::size<std::uint8_t>::value;
using storage_t =
std::array<std::uint8_t, header_size + payload_size>;
return catalog_builder<storage_t, P>{}.template build<Level>(
id, m, args...);
}
constexpr auto header_size =
defn::catalog_msg_t::size<std::uint32_t>::value;
using storage_t =
std::array<std::uint32_t, header_size + stdx::sized8{payload_size}
.in<std::uint32_t>()>;
return catalog_builder<storage_t, P>{}.template build<Level>(id, m,
args...);
}
};

Expand Down
24 changes: 24 additions & 0 deletions include/log/catalog/writer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <log/catalog/mipi_builder.hpp>

#include <stdx/compiler.hpp>
#include <stdx/span.hpp>

#include <cstdint>
#include <utility>

namespace logging::binary {
template <typename T>
concept writer_like =
requires(T &t, stdx::span<std::uint32_t const, 1> data) { t(data); };

[[maybe_unused]] constexpr inline struct get_writer_t {
template <typename T>
CONSTEVAL auto operator()(T &&t) const noexcept(
noexcept(std::forward<T>(t).query(std::declval<get_writer_t>())))
-> decltype(std::forward<T>(t).query(*this)) {
return std::forward<T>(t).query(*this);
}
} get_writer;
} // namespace logging::binary
26 changes: 14 additions & 12 deletions test/log/catalog1_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
#include <stdx/span.hpp>

#include <conc/concurrency.hpp>

Expand All @@ -15,10 +16,11 @@ int log_calls{};
std::uint32_t last_header{};

namespace {
struct test_log_args_destination {
auto log_by_args(std::uint32_t hdr, auto...) -> void {
struct test_log_destination {
template <std::size_t N>
auto operator()(stdx::span<std::uint32_t const, N> pkt) const {
++log_calls;
last_header = hdr;
last_header = pkt[0];
}
};

Expand All @@ -36,40 +38,40 @@ auto log_with_fixed_string_id() -> void;
auto log_with_fixed_module_id() -> void;

auto log_zero_args() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<log_env1>(
stdx::ct_format<"A string with no placeholders">());
}

auto log_one_ct_arg() -> void {
using namespace stdx::literals;
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<log_env1>(
stdx::ct_format<"B string with {} placeholder">("one"_ctst));
}

auto log_one_32bit_rt_arg() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<log_env1>(
stdx::ct_format<"C1 string with {} placeholder">(std::int32_t{1}));
}

auto log_one_64bit_rt_arg() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<log_env1>(
stdx::ct_format<"C2 string with {} placeholder">(std::int64_t{1}));
}

auto log_one_formatted_rt_arg() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<log_env1>(
stdx::ct_format<"C3 string with {:08x} placeholder">(std::int32_t{1}));
}

auto log_with_non_default_module() -> void {
CIB_WITH_LOG_ENV(logging::get_level, logging::level::TRACE,
logging::get_module, "not default") {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<cib_log_env_t>(
stdx::ct_format<"ModuleID string with {} placeholder">(1));
}
Expand All @@ -78,7 +80,7 @@ auto log_with_non_default_module() -> void {
auto log_with_fixed_module() -> void {
CIB_WITH_LOG_ENV(logging::get_level, logging::level::TRACE,
logging::get_module, "fixed") {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<cib_log_env_t>(
stdx::ct_format<"Fixed ModuleID string with {} placeholder">(1));
}
Expand All @@ -87,7 +89,7 @@ auto log_with_fixed_module() -> void {
auto log_with_fixed_string_id() -> void {
CIB_WITH_LOG_ENV(logging::get_level, logging::level::TRACE,
logging::get_string_id, 1337) {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<cib_log_env_t>(
stdx::ct_format<"Fixed StringID string">());
}
Expand All @@ -97,7 +99,7 @@ auto log_with_fixed_module_id() -> void {
CIB_WITH_LOG_ENV(logging::get_level, logging::level::TRACE,
logging::get_module_id, 7, logging::get_module,
"fixed_id") {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<cib_log_env_t>(
stdx::ct_format<"Fixed ModuleID string with {} placeholder">(1));
}
Expand Down
8 changes: 4 additions & 4 deletions test/log/catalog2a_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <log/catalog/encoder.hpp>

#include <stdx/ct_format.hpp>
#include <stdx/span.hpp>

#include <conc/concurrency.hpp>

Expand All @@ -14,10 +15,9 @@ template <> inline auto conc::injected_policy<> = test_conc_policy{};
extern int log_calls;

namespace {
struct test_log_args_destination {
auto log_by_args(std::uint32_t, auto...) -> void { ++log_calls; }
struct test_log_destination {
template <std::size_t N>
auto log_by_buf(stdx::span<std::uint8_t const, N>) const {
auto operator()(stdx::span<std::uint32_t const, N>) const {
++log_calls;
}
};
Expand All @@ -28,7 +28,7 @@ using log_env2a = stdx::make_env_t<logging::get_level, logging::level::TRACE>;
auto log_two_rt_args() -> void;

auto log_two_rt_args() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
cfg.logger.log_msg<log_env2a>(
stdx::ct_format<"D string with {} and {} placeholder">(
std::uint32_t{1}, std::int64_t{2}));
Expand Down
14 changes: 9 additions & 5 deletions test/log/catalog2b_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <log/catalog/encoder.hpp>

#include <stdx/ct_format.hpp>
#include <stdx/span.hpp>

#include <conc/concurrency.hpp>

Expand All @@ -14,8 +15,11 @@ template <> inline auto conc::injected_policy<> = test_conc_policy{};
extern int log_calls;

namespace {
struct test_log_args_destination {
auto log_by_args(std::uint32_t, auto...) -> void { ++log_calls; }
struct test_log_destination {
template <std::size_t N>
auto operator()(stdx::span<std::uint32_t const, N>) const {
++log_calls;
}
};

using log_env2b = stdx::make_env_t<logging::get_level, logging::level::TRACE>;
Expand All @@ -26,21 +30,21 @@ auto log_rt_float_arg() -> void;
auto log_rt_double_arg() -> void;

auto log_rt_enum_arg() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
using namespace ns;
cfg.logger.log_msg<log_env2b>(
stdx::ct_format<"E string with {} placeholder">(E::value));
}

auto log_rt_float_arg() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
using namespace ns;
cfg.logger.log_msg<log_env2b>(
stdx::ct_format<"Float string with {} placeholder">(3.14f));
}

auto log_rt_double_arg() -> void {
auto cfg = logging::binary::config{test_log_args_destination{}};
auto cfg = logging::binary::config{test_log_destination{}};
using namespace ns;
cfg.logger.log_msg<log_env2b>(
stdx::ct_format<"Double string with {} placeholder">(3.14));
Expand Down
Loading
Loading