diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b54b3ac..a13e9fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,6 +133,43 @@ target_sources( include/log/level.hpp include/log/log.hpp) +add_library(cib_msg INTERFACE) +target_compile_features(cib_msg INTERFACE cxx_std_20) +target_link_libraries_system( + cib_msg + INTERFACE + async + cib_log + cib_lookup + cib_match + cib_sc + stdx) + +target_sources( + cib_msg + INTERFACE FILE_SET + msg + TYPE + HEADERS + BASE_DIRS + include + FILES + include/msg/callback.hpp + include/msg/detail/indexed_builder_common.hpp + include/msg/detail/indexed_handler_common.hpp + include/msg/detail/separate_sum_terms.hpp + include/msg/field.hpp + include/msg/field_matchers.hpp + include/msg/handler_builder.hpp + include/msg/handler.hpp + include/msg/handler_interface.hpp + include/msg/indexed_builder.hpp + include/msg/indexed_handler.hpp + include/msg/indexed_service.hpp + include/msg/message.hpp + include/msg/send.hpp + include/msg/service.hpp) + add_library(cib_log_fmt INTERFACE) target_compile_features(cib_log_fmt INTERFACE cxx_std_20) target_link_libraries_system(cib_log_fmt INTERFACE cib_log fmt::fmt-header-only @@ -149,24 +186,31 @@ target_sources( FILES include/log/fmt/logger.hpp) -add_library(cib INTERFACE) -target_compile_features(cib INTERFACE cxx_std_20) -target_link_libraries_system( - cib - INTERFACE - async - cib_interrupt - cib_lookup - cib_match - cib_sc - concurrency - fmt::fmt-header-only - stdx) +add_library(cib_log_mipi INTERFACE) +target_compile_features(cib_log_mipi INTERFACE cxx_std_20) +target_link_libraries_system(cib_log_mipi INTERFACE cib_log cib_msg concurrency + stdx) target_sources( - cib + cib_log_mipi INTERFACE FILE_SET - cib + log + TYPE + HEADERS + BASE_DIRS + include + FILES + include/log/catalog/catalog.hpp + include/log/catalog/mipi_encoder.hpp) + +add_library(cib_nexus INTERFACE) +target_compile_features(cib_nexus INTERFACE cxx_std_20) +target_link_libraries_system(cib_nexus INTERFACE stdx) + +target_sources( + cib_nexus + INTERFACE FILE_SET + nexus TYPE HEADERS BASE_DIRS @@ -175,7 +219,6 @@ target_sources( include/cib/builder_meta.hpp include/cib/built.hpp include/cib/callback.hpp - include/cib/cib.hpp include/cib/config.hpp include/cib/detail/components.hpp include/cib/detail/constexpr_conditional.hpp @@ -186,11 +229,14 @@ target_sources( include/cib/detail/extend.hpp include/cib/detail/nexus_details.hpp include/cib/func_decl.hpp - include/cib/nexus.hpp - include/cib/top.hpp) + include/cib/nexus.hpp) + +add_library(cib_flow INTERFACE) +target_compile_features(cib_flow INTERFACE cxx_std_20) +target_link_libraries_system(cib_flow INTERFACE cib_log cib_nexus cib_sc stdx) target_sources( - cib + cib_flow INTERFACE FILE_SET flow TYPE @@ -210,33 +256,19 @@ target_sources( include/flow/run.hpp include/flow/step.hpp) -target_sources( - cib - INTERFACE FILE_SET - msg - TYPE - HEADERS - BASE_DIRS - include - FILES - include/msg/callback.hpp - include/msg/detail/indexed_builder_common.hpp - include/msg/detail/indexed_handler_common.hpp - include/msg/detail/separate_sum_terms.hpp - include/msg/field.hpp - include/msg/field_matchers.hpp - include/msg/handler_builder.hpp - include/msg/handler.hpp - include/msg/handler_interface.hpp - include/msg/indexed_builder.hpp - include/msg/indexed_handler.hpp - include/msg/indexed_service.hpp - include/msg/message.hpp - include/msg/send.hpp - include/msg/service.hpp) +add_library(cib_seq INTERFACE) +target_compile_features(cib_seq INTERFACE cxx_std_20) +target_link_libraries_system( + cib_seq + INTERFACE + cib_flow + cib_log + cib_nexus + cib_sc + stdx) target_sources( - cib + cib_seq INTERFACE FILE_SET seq TYPE @@ -248,29 +280,53 @@ target_sources( include/seq/impl.hpp include/seq/step.hpp) -add_library(cib_log_mipi INTERFACE) -target_compile_features(cib_log_mipi INTERFACE cxx_std_20) -target_link_libraries_system(cib_log_mipi INTERFACE cib cib_log concurrency - stdx) +add_library(cib INTERFACE) +target_compile_features(cib INTERFACE cxx_std_20) +target_link_libraries_system( + cib + INTERFACE + async + cib_flow + cib_interrupt + cib_log + cib_log_fmt + cib_log_mipi + cib_lookup + cib_match + cib_msg + cib_nexus + cib_sc + cib_seq + concurrency + fmt::fmt-header-only + stdx) target_sources( - cib_log_mipi + cib INTERFACE FILE_SET - log + cib TYPE HEADERS BASE_DIRS include FILES - include/log/catalog/catalog.hpp - include/log/catalog/mipi_encoder.hpp) + include/cib/cib.hpp + include/cib/top.hpp) if(PROJECT_IS_TOP_LEVEL) add_docs(docs) clang_tidy_interface(cib) + clang_tidy_interface(cib_flow) clang_tidy_interface(cib_interrupt) + clang_tidy_interface(cib_lookup) + clang_tidy_interface(cib_log) + clang_tidy_interface(cib_log_fmt) + clang_tidy_interface(cib_log_mipi) clang_tidy_interface(cib_match) + clang_tidy_interface(cib_msg) + clang_tidy_interface(cib_nexus) clang_tidy_interface(cib_sc) + clang_tidy_interface(cib_seq) # Enable functional and performance test suites. add_subdirectory(test) diff --git a/docs/flows.adoc b/docs/flows.adoc index 74d54596..b58d896a 100644 --- a/docs/flows.adoc +++ b/docs/flows.adoc @@ -339,7 +339,7 @@ namespace example_component { ==== `operator*` Explicitly add an action to the flow. Actions used in flow extensions without -the `*` will be treated as references only and will not be added to the +the `\*` will be treated as references only and will not be added to the flow at that location. It is a compilation error if an action is not added with a `*` in exactly one location in the overall config. @@ -388,8 +388,12 @@ what happens by default when we run the flow. // the default flow builder and service template using builder = flow::graph>; + template -struct service : cib::builder_meta, flow::FunctionPtr> {}; +struct service { + using builder_t = builder; + using interface_t = flow::FunctionPtr; +}; // declare a flow service struct MorningRoutine : public service<"MorningRoutine"> {}; @@ -410,8 +414,12 @@ But given a flow, other renderings are possible. // a flow builder and service that produces a graphviz rendering template using viz_builder = flow::graph; + template -struct viz_service : cib::builder_meta, flow::VizFunctionPtr> {}; +struct viz_service { + using builder_t = builder; + using interface_t = flow::VizFunctionPtr; +}; ---- Here, `viz_service` will produce a graphviz rendering of a flow using the diff --git a/docs/intro.adoc b/docs/intro.adoc index 2c093269..f43bc416 100644 --- a/docs/intro.adoc +++ b/docs/intro.adoc @@ -34,12 +34,13 @@ The library dependencies are: - https://github.com/boostorg/mp11[Boost.MP11] - https://github.com/intel/cpp-std-extensions[C++ std extensions (`stdx`)] -- https://github.com/intel/cpp-baremetal-concurrency[Baremetal Concurrency] +- https://github.com/intel/cpp-baremetal-concurrency[Baremetal Concurrency (`conc`)] +- https://github.com/intel/cpp-senders-and-receivers[Baremetal Senders and Receivers (`async`)] - https://github.com/fmtlib/fmt[fmt] -=== Libraries +=== Functionality -_cib_ contains several libraries that work together: +_cib_ contains several parts that work together: - xref:flow.adoc#_the_flow_library[`flow`] - xref:logging.adoc#_the_logging_library[`logging`] @@ -47,3 +48,33 @@ _cib_ contains several libraries that work together: - xref:match.adoc#_the_match_library[`match`] - xref:message.adoc#_the_message_library[`message`] - xref:sc.adoc#_the_sc_string_constant_library[`sc` (string constant)] + +=== Sub-library DAG + +Various sub-libraries within CIB form a dependency graph. `cib` is an omnibus +library that contains all the functionality. + +[mermaid, format="svg"] +---- +flowchart BT + sc(cib_sc) + nexus(cib_nexus) + lookup(cib_lookup) + + flow(cib_flow) --> nexus + flow --> log + + interrupt(cib_interrupt) --> sc + match(cib_match) --> sc + log(cib_log) --> sc + + + log_fmt(cib_log_fmt) --> log + msg(cib_msg) --> log & match + msg --> lookup + + log_mipi(cib_log_mipi) --> msg + seq(cib_seq) --> flow + + cib --> interrupt & seq & log_fmt & log_mipi +---- diff --git a/include/cib/builder_meta.hpp b/include/cib/builder_meta.hpp index f2c22f58..9761fed6 100644 --- a/include/cib/builder_meta.hpp +++ b/include/cib/builder_meta.hpp @@ -1,32 +1,12 @@ #pragma once namespace cib { -/** - * Describe a builder to cib. - * - * @tparam Builder - * The initial builder type cib should use when creating a builder. - * This is only the initial type, the Builder::add(...) function - * may return a different type and cib will track that correctly. - * - * @tparam Interface - * The type-erased interface services built with this builder - * will implement. For example, cib::callback allows many other - * callables to get executed when its service gets invoked. The - * type-erased interface for cib::callback is a function pointer. - * - * @see cib::built - * - * @example callback::service - */ -template struct builder_meta { - using builder_t = Builder; - using interface_t = Interface; +template +concept builder_meta = requires { + typename T::builder_t; + typename T::interface_t; }; -template -using builder_t = typename BuilderMeta::builder_t; - -template -using interface_t = typename BuilderMeta::interface_t; +template using builder_t = typename T::builder_t; +template using interface_t = typename T::interface_t; } // namespace cib diff --git a/include/cib/built.hpp b/include/cib/built.hpp index e7d58dde..3a64c2e4 100644 --- a/include/cib/built.hpp +++ b/include/cib/built.hpp @@ -3,13 +3,5 @@ #include namespace cib { -/** - * Pointer to a built service implementation. - * - * @tparam ServiceMeta - * Tag name of the service. - * - * @see cib::builder_meta - */ -template interface_t service; +template interface_t service; } // namespace cib diff --git a/include/cib/callback.hpp b/include/cib/callback.hpp index efc678e5..21d44514 100644 --- a/include/cib/callback.hpp +++ b/include/cib/callback.hpp @@ -105,7 +105,7 @@ template struct builder { /** * Extend this to create named callback services. * - * Types that extend callback_meta can be used as unique names with + * Types that extend service can be used as unique names with * cib::exports and cib::extend. * * @tparam ArgTypes @@ -116,8 +116,8 @@ template struct builder { * @see cib::exports * @see cib::extend */ -template -struct service - : public cib::builder_meta, void (*)(ArgTypes...)> { +template struct service { + using builder_t = builder<0, ArgTypes...>; + using interface_t = void (*)(ArgTypes...); }; } // namespace callback diff --git a/include/cib/config.hpp b/include/cib/config.hpp index a6fb1de6..18de5505 100644 --- a/include/cib/config.hpp +++ b/include/cib/config.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/include/flow/builder.hpp b/include/flow/builder.hpp index b9113640..059f0536 100644 --- a/include/flow/builder.hpp +++ b/include/flow/builder.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -11,6 +10,8 @@ namespace flow { template using builder = graph>; -template -struct service : cib::builder_meta, FunctionPtr> {}; +template struct service { + using builder_t = builder; + using interface_t = FunctionPtr; +}; } // namespace flow diff --git a/include/msg/indexed_service.hpp b/include/msg/indexed_service.hpp index a5c92009..ea9dc3be 100644 --- a/include/msg/indexed_service.hpp +++ b/include/msg/indexed_service.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -8,9 +7,10 @@ namespace msg { template -struct indexed_service - : cib::builder_meta< - indexed_builder, MsgBase, - ExtraCallbackArgs...>, - handler_interface const *> {}; +struct indexed_service { + using builder_t = indexed_builder, MsgBase, + ExtraCallbackArgs...>; + using interface_t = + handler_interface const *; +}; } // namespace msg diff --git a/include/msg/service.hpp b/include/msg/service.hpp index 8497ba69..3aa9bd26 100644 --- a/include/msg/service.hpp +++ b/include/msg/service.hpp @@ -1,15 +1,15 @@ #pragma once -#include #include #include #include namespace msg { -template -struct service - : cib::builder_meta< - handler_builder, MsgBase, ExtraCallbackArgs...>, - handler_interface const *> {}; +template struct service { + using builder_t = + handler_builder, MsgBase, ExtraCallbackArgs...>; + using interface_t = + handler_interface const *; +}; } // namespace msg diff --git a/include/seq/builder.hpp b/include/seq/builder.hpp index 12879946..50d69803 100644 --- a/include/seq/builder.hpp +++ b/include/seq/builder.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -11,6 +10,8 @@ namespace seq { template using builder = flow::graph>; -template -struct service : cib::builder_meta, flow::FunctionPtr> {}; +template struct service { + using builder_t = builder; + using interface_t = flow::FunctionPtr; +}; } // namespace seq diff --git a/test/cib/builder_meta.cpp b/test/cib/builder_meta.cpp index eb81729f..c0579f4b 100644 --- a/test/cib/builder_meta.cpp +++ b/test/cib/builder_meta.cpp @@ -8,13 +8,20 @@ namespace { struct TestBuilderTag; struct TestInterfaceTag; -struct test_builder_meta - : public cib::builder_meta {}; +struct test_builder_meta { + using builder_t = TestBuilderTag; + using interface_t = TestInterfaceTag; +}; } // namespace +TEST_CASE("builder_meta concept") { + static_assert(cib::builder_meta); +} + TEST_CASE( "builder_meta builder and interface type traits return correct values") { - REQUIRE(std::is_same_v>); - REQUIRE( + static_assert( + std::is_same_v>); + static_assert( std::is_same_v>); } diff --git a/test/flow/flow.cpp b/test/flow/flow.cpp index 9c4a139d..00ddf806 100644 --- a/test/flow/flow.cpp +++ b/test/flow/flow.cpp @@ -51,9 +51,10 @@ TEST_CASE("run empty flow through cib::nexus", "[flow]") { namespace { template using alt_builder = flow::graph; -template -struct alt_flow_service - : cib::builder_meta, flow::VizFunctionPtr> {}; +template struct alt_flow_service { + using builder_t = alt_builder; + using interface_t = flow::VizFunctionPtr; +}; struct VizFlow : public alt_flow_service<"debug"> {}; struct VizConfig { diff --git a/test/msg/fail/CMakeLists.txt b/test/msg/fail/CMakeLists.txt index 3519ceae..c2c5c650 100644 --- a/test/msg/fail/CMakeLists.txt +++ b/test/msg/fail/CMakeLists.txt @@ -1,16 +1,19 @@ -add_compile_fail_test(callback_bad_field_name.cpp LIBRARIES warnings cib) -add_compile_fail_test(field_location.cpp LIBRARIES warnings cib) -add_compile_fail_test(field_size.cpp LIBRARIES warnings cib) -add_compile_fail_test(impossible_match_callback.cpp LIBRARIES warnings cib) -add_compile_fail_test(impossible_match_field.cpp LIBRARIES warnings cib) +add_compile_fail_test(callback_bad_field_name.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(field_location.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(field_size.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(impossible_match_callback.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(impossible_match_field.cpp LIBRARIES warnings cib_msg) add_compile_fail_test(owning_msg_incompatible_storage.cpp LIBRARIES warnings - cib) -add_compile_fail_test(owning_msg_incompatible_view.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_cmp_owner.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_cmp_view.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_const_field_write.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_dangling_view.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_dup_fieldnames.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_incompatible_matcher.cpp LIBRARIES warnings cib) -add_compile_fail_test(message_uninitialized_field.cpp LIBRARIES warnings cib) -add_compile_fail_test(view_upsize.cpp LIBRARIES warnings cib) + cib_msg) +add_compile_fail_test(owning_msg_incompatible_view.cpp LIBRARIES warnings + cib_msg) +add_compile_fail_test(message_cmp_owner.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(message_cmp_view.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(message_const_field_write.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(message_dangling_view.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(message_dup_fieldnames.cpp LIBRARIES warnings cib_msg) +add_compile_fail_test(message_incompatible_matcher.cpp LIBRARIES warnings + cib_msg) +add_compile_fail_test(message_uninitialized_field.cpp LIBRARIES warnings + cib_msg) +add_compile_fail_test(view_upsize.cpp LIBRARIES warnings cib_msg) diff --git a/test/seq/CMakeLists.txt b/test/seq/CMakeLists.txt index a40433d1..851a9652 100644 --- a/test/seq/CMakeLists.txt +++ b/test/seq/CMakeLists.txt @@ -1 +1 @@ -add_tests(FILES sequencer LIBRARIES cib) +add_tests(FILES sequencer LIBRARIES cib_seq)