From 952553451d5f6e9c2f7052c6432d6daf56cb149e Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Mon, 18 Nov 2024 14:29:34 -0700 Subject: [PATCH] :art: :boom: Apply consistent naming between callback and flow Problem: - `flow` constructs are called `flow::builder` and `flow::service`. - `callback` constructs are called `cib::callback` and `cib::callback_meta`, which is confusing. Solution: - Rename the `callback` constructs to `callback::builder` and `callback::service` to match the `flow` pattern. --- README.md | 2 +- USER_GUIDE.md | 18 ++++----- benchmark/big_nexus.cpp | 2 +- examples/cib_serial_port/main.cpp | 8 ++-- examples/flow_daily_routine/main.cpp | 2 +- examples/hello_world/README.md | 2 +- examples/hello_world/core.hpp | 2 +- include/cib/builder_meta.hpp | 2 +- include/cib/callback.hpp | 15 ++++---- test/cib/callback.cpp | 55 +++++++++++++++------------- test/cib/nexus.cpp | 2 +- test/cib/readme_hello_world.cpp | 2 +- test/msg/indexed_builder.cpp | 6 +-- 13 files changed, 61 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index f62951fb..72c75377 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ a simple example takes a few more lines than a typical "Hello, world!" #include #include -struct say_message : public cib::callback_meta<>{}; +struct say_message : public callback::service<>{}; // the 'core' component exposes the 'say_message' service for others to extend struct core { diff --git a/USER_GUIDE.md b/USER_GUIDE.md index e2a22779..e4cdead2 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -33,7 +33,7 @@ functionality. ```c++ /// Invoked for each byte of data received on the serial port -struct serial_port_rx : public cib::callback_meta<0, std::uint8_t>{}; +struct serial_port_rx : public callback::service<0, std::uint8_t>{}; ``` In *cib*, *features* have source-code dependencies on *services*. This follows @@ -57,13 +57,13 @@ initialized before they can be used. The `runtime_init` and `main_loop` ```c++ /// Invoked once on startup before interrupts are enabled -struct runtime_init : public cib::callback_meta<>{}; +struct runtime_init : public callback::service<>{}; /// Invoked each iteration through the main loop -struct main_loop : public cib::callback_meta<>{}; +struct main_loop : public callback::service<>{}; /// Invoked each time the serial port interrupt is triggered -struct serial_port_interrupt : public cib::callback_meta<>{}; +struct serial_port_interrupt : public callback::service<>{}; ``` *Components* use `cib::exports` in their configuration to *export* services to @@ -157,7 +157,7 @@ INTERRUPT void serial_port_isr() { Services can be accessed with the `service<...>` template variable on a `cib::nexus` instance. Because the `runtime_init` and `main_loop` services -extend `cib::callback_meta`, their *service implementation* is a simple +extend `callback::service`, their *service implementation* is a simple function pointer. ### `cib::service` @@ -170,7 +170,7 @@ instance is not available. For example, when registering interrupts with an interrupt service. ```c++ -struct serial_port_rx : public cib::callback_meta<0, char>{}; +struct serial_port_rx : public callback::service<0, char>{}; struct serial_component { constexpr static auto config = @@ -193,12 +193,12 @@ struct serial_component { ### `cib::service_meta` The *service metadata* describes to *cib* how a *service* is built and its -type-erased implementation interface. (`cib::callback_meta`)[include/cib/callback.hpp] +type-erased implementation interface. (`callback::service`)[include/cib/callback.hpp] is an example of *service metadata*. Services that use the callback *service* -type extend `cib::callback_meta`. +type extend `callback::service`. ```c++ -struct main_loop : public cib::callback_meta<> {}; +struct main_loop : public callback::service<> {}; ``` ### Service Builder diff --git a/benchmark/big_nexus.cpp b/benchmark/big_nexus.cpp index a287c24a..fda22d24 100644 --- a/benchmark/big_nexus.cpp +++ b/benchmark/big_nexus.cpp @@ -3,7 +3,7 @@ template [[maybe_unused]] static bool is_callback_invoked = false; template -struct TestCallback : public cib::callback_meta {}; +struct TestCallback : public callback::service {}; template struct TestComponent { constexpr static auto offset = Id * 100; diff --git a/examples/cib_serial_port/main.cpp b/examples/cib_serial_port/main.cpp index 739be36b..46d3e506 100644 --- a/examples/cib_serial_port/main.cpp +++ b/examples/cib_serial_port/main.cpp @@ -4,13 +4,13 @@ // Services - basically like a function prototypes. // - callback function declaration. -struct send_byte_t : public cib::callback_meta {}; +struct send_byte_t : public callback::service {}; -struct get_byte_t : public cib::callback_meta<> {}; +struct get_byte_t : public callback::service<> {}; -struct serial_port_init_t : public cib::callback_meta<> {}; +struct serial_port_init_t : public callback::service<> {}; -struct run_t : public cib::callback_meta<> {}; +struct run_t : public callback::service<> {}; // components defintion struct core_component_t { diff --git a/examples/flow_daily_routine/main.cpp b/examples/flow_daily_routine/main.cpp index 7b94d43c..b1c1338b 100644 --- a/examples/flow_daily_routine/main.cpp +++ b/examples/flow_daily_routine/main.cpp @@ -42,7 +42,7 @@ Note:: services can be defined using - + cib::callback_meta<> - can have only one function pointer assigned to + + callback::service<> - can have only one function pointer assigned to execute. + flow::service<> - set of actions/milestones which are to be executed in specific order. So basically sequential execution of multiple diff --git a/examples/hello_world/README.md b/examples/hello_world/README.md index 85d39a57..f5c8f09a 100644 --- a/examples/hello_world/README.md +++ b/examples/hello_world/README.md @@ -12,7 +12,7 @@ attention to the `#include` directives in each file. ```c++ #include -struct say_message : public cib::callback_meta<>{}; +struct say_message : public callback::service<>{}; struct core { constexpr static auto config = diff --git a/examples/hello_world/core.hpp b/examples/hello_world/core.hpp index 93c33524..f501748a 100644 --- a/examples/hello_world/core.hpp +++ b/examples/hello_world/core.hpp @@ -2,7 +2,7 @@ #include -struct say_message : public cib::callback_meta<> {}; +struct say_message : public callback::service<> {}; struct core { constexpr static auto config = cib::config(cib::exports); diff --git a/include/cib/builder_meta.hpp b/include/cib/builder_meta.hpp index 396eb5d1..f2c22f58 100644 --- a/include/cib/builder_meta.hpp +++ b/include/cib/builder_meta.hpp @@ -17,7 +17,7 @@ namespace cib { * * @see cib::built * - * @example cib::callback_meta + * @example callback::service */ template struct builder_meta { using builder_t = Builder; diff --git a/include/cib/callback.hpp b/include/cib/callback.hpp index 16b0786f..efc678e5 100644 --- a/include/cib/callback.hpp +++ b/include/cib/callback.hpp @@ -9,7 +9,7 @@ #include #include -namespace cib { +namespace callback { /** * Builder for simple callbacks. * @@ -23,9 +23,9 @@ namespace cib { * List of argument types that must be passed into the callback when it is * invoked. * - * @see cib::callback_meta + * @see callback::service */ -template struct callback { +template struct builder { using func_ptr_t = void (*)(ArgTypes...); std::array funcs{}; @@ -44,7 +44,7 @@ template struct callback { */ template ... Fs> [[nodiscard]] constexpr auto add(Fs &&...fs) const { - callback cb; + builder cb; auto i = std::size_t{}; while (i < NumFuncs) { cb.funcs[i] = funcs[i]; @@ -117,6 +117,7 @@ template struct callback { * @see cib::extend */ template -struct callback_meta : public cib::builder_meta, - void (*)(ArgTypes...)> {}; -} // namespace cib +struct service + : public cib::builder_meta, void (*)(ArgTypes...)> { +}; +} // namespace callback diff --git a/test/cib/callback.cpp b/test/cib/callback.cpp index 9620d7db..f819415e 100644 --- a/test/cib/callback.cpp +++ b/test/cib/callback.cpp @@ -1,4 +1,6 @@ -#include +#include + +#include #include @@ -9,14 +11,14 @@ template constexpr static auto build() { } template -constexpr static bool built_is_convertable_to_interface(BuiltCallback) { +constexpr static bool built_is_convertible_to_interface(BuiltCallback) { using interface_type = cib::interface_t; return std::is_convertible_v; } struct EmptyCallbackNoArgs { - using meta = cib::callback_meta<>; - constexpr static auto value = cib::builder_t{}; + using service = callback::service<>; + constexpr static auto value = cib::builder_t{}; }; TEST_CASE("empty callback with no args", "[callback]") { @@ -24,8 +26,8 @@ TEST_CASE("empty callback with no args", "[callback]") { SECTION("can be called without issue") { built_callback(); } - SECTION("built type is convertable to the interface type") { - REQUIRE(built_is_convertable_to_interface( + SECTION("built type is convertible to the interface type") { + REQUIRE(built_is_convertible_to_interface( built_callback)); } } @@ -33,9 +35,9 @@ TEST_CASE("empty callback with no args", "[callback]") { template static bool is_callback_invoked = false; struct CallbackNoArgsWithSingleExtension { - using meta = cib::callback_meta<>; + using service = callback::service<>; constexpr static auto value = []() { - auto const builder = cib::builder_t{}; + auto const builder = cib::builder_t{}; return builder.add([]() { is_callback_invoked<0> = true; }); }(); }; @@ -50,14 +52,14 @@ TEST_CASE("callback with no args with single extension", "[callback]") { REQUIRE(is_callback_invoked<0>); } - SECTION("built type is convertable to the interface type") { - REQUIRE(built_is_convertable_to_interface< - CallbackNoArgsWithSingleExtension::meta>(built_callback)); + SECTION("built type is convertible to the interface type") { + REQUIRE(built_is_convertible_to_interface< + CallbackNoArgsWithSingleExtension::service>(built_callback)); } } struct CallbackNoArgsWithMultipleExtensions { - using meta = cib::callback_meta<>; + using service = callback::service<>; static void extension_one() { is_callback_invoked<1> = true; } @@ -66,7 +68,7 @@ struct CallbackNoArgsWithMultipleExtensions { }; constexpr static auto value = []() { - auto const builder = cib::builder_t{}; + auto const builder = cib::builder_t{}; return builder.add([]() { is_callback_invoked<0> = true; }) .add(extension_one) @@ -89,15 +91,15 @@ TEST_CASE("callback with no args with multiple extensions", "[callback]") { REQUIRE(is_callback_invoked<2>); } - SECTION("built type is convertable to the interface type") { - REQUIRE(built_is_convertable_to_interface< - CallbackNoArgsWithMultipleExtensions::meta>(built_callback)); + SECTION("built type is convertible to the interface type") { + REQUIRE(built_is_convertible_to_interface< + CallbackNoArgsWithMultipleExtensions::service>(built_callback)); } } struct CallbackWithArgsWithNoExtensions { - using meta = cib::callback_meta; - constexpr static auto value = cib::builder_t{}; + using service = callback::service; + constexpr static auto value = cib::builder_t{}; }; TEST_CASE("callback with args with no extensions", "[callback]") { @@ -105,9 +107,9 @@ TEST_CASE("callback with args with no extensions", "[callback]") { SECTION("can be called") { built_callback(42, true); } - SECTION("built type is convertable to the interface type") { - REQUIRE(built_is_convertable_to_interface< - CallbackWithArgsWithNoExtensions::meta>(built_callback)); + SECTION("built type is convertible to the interface type") { + REQUIRE(built_is_convertible_to_interface< + CallbackWithArgsWithNoExtensions::service>(built_callback)); } } @@ -115,7 +117,7 @@ template static stdx::tuple callback_args{}; struct CallbackWithArgsWithMultipleExtensions { - using meta = cib::callback_meta; + using service = callback::service; static void extension_one(int a, bool b) { is_callback_invoked<1> = true; @@ -128,7 +130,7 @@ struct CallbackWithArgsWithMultipleExtensions { }; constexpr static auto value = []() { - auto const builder = cib::builder_t{}; + auto const builder = cib::builder_t{}; return builder .add([](int a, bool b) { @@ -168,8 +170,9 @@ TEST_CASE("callback with args with multiple extensions", "[callback]") { REQUIRE(get<1>(callback_args<2, int, bool>) == false); } - SECTION("built type is convertable to the interface type") { - REQUIRE(built_is_convertable_to_interface< - CallbackWithArgsWithMultipleExtensions::meta>(built_callback)); + SECTION("built type is convertible to the interface type") { + REQUIRE(built_is_convertible_to_interface< + CallbackWithArgsWithMultipleExtensions::service>( + built_callback)); } } diff --git a/test/cib/nexus.cpp b/test/cib/nexus.cpp index 777cf6c3..05a2f157 100644 --- a/test/cib/nexus.cpp +++ b/test/cib/nexus.cpp @@ -14,7 +14,7 @@ TEST_CASE("an empty configuration should compile and initialize") { template static bool is_callback_invoked = false; template -struct TestCallback : public cib::callback_meta {}; +struct TestCallback : public callback::service {}; struct SimpleConfig { constexpr static auto config = cib::config( diff --git a/test/cib/readme_hello_world.cpp b/test/cib/readme_hello_world.cpp index 32bf29b7..be4c3004 100644 --- a/test/cib/readme_hello_world.cpp +++ b/test/cib/readme_hello_world.cpp @@ -4,7 +4,7 @@ #include -struct say_message : public cib::callback_meta<> {}; +struct say_message : public callback::service<> {}; // the 'core' component exposes the 'say_message' service for others to extend struct core { diff --git a/test/msg/indexed_builder.cpp b/test/msg/indexed_builder.cpp index d891a045..49f4f87c 100644 --- a/test/msg/indexed_builder.cpp +++ b/test/msg/indexed_builder.cpp @@ -33,7 +33,7 @@ struct test_service : indexed_service {}; bool callback_success; -constexpr auto test_callback = callback<"TestCallback", msg_defn>( +constexpr auto test_callback = msg::callback<"TestCallback", msg_defn>( msg::in, [](auto) { callback_success = true; }); struct test_project { @@ -430,7 +430,7 @@ struct raw_service : indexed_service {}; int callback_count{}; -constexpr auto raw_view_callback = callback<"raw view", msg_defn>( +constexpr auto raw_view_callback = msg::callback<"raw view", msg_defn>( msg::in, [](msg::const_view) { ++callback_count; }); @@ -451,7 +451,7 @@ TEST_CASE("handle raw message by view", "[indexed_builder]") { } namespace { -constexpr auto raw_owning_callback = callback<"raw owning", msg_defn>( +constexpr auto raw_owning_callback = msg::callback<"raw owning", msg_defn>( msg::in, [](msg::owning) { ++callback_count; });