Skip to content

Commit 9525534

Browse files
committed
🎨 💥 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.
1 parent 1dd5170 commit 9525534

File tree

13 files changed

+61
-57
lines changed

13 files changed

+61
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ a simple example takes a few more lines than a typical "Hello, world!"
8282
#include <cib/cib.hpp>
8383
#include <iostream>
8484

85-
struct say_message : public cib::callback_meta<>{};
85+
struct say_message : public callback::service<>{};
8686

8787
// the 'core' component exposes the 'say_message' service for others to extend
8888
struct core {

USER_GUIDE.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ functionality.
3333

3434
```c++
3535
/// Invoked for each byte of data received on the serial port
36-
struct serial_port_rx : public cib::callback_meta<0, std::uint8_t>{};
36+
struct serial_port_rx : public callback::service<0, std::uint8_t>{};
3737
```
3838
3939
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`
5757
5858
```c++
5959
/// Invoked once on startup before interrupts are enabled
60-
struct runtime_init : public cib::callback_meta<>{};
60+
struct runtime_init : public callback::service<>{};
6161
6262
/// Invoked each iteration through the main loop
63-
struct main_loop : public cib::callback_meta<>{};
63+
struct main_loop : public callback::service<>{};
6464
6565
/// Invoked each time the serial port interrupt is triggered
66-
struct serial_port_interrupt : public cib::callback_meta<>{};
66+
struct serial_port_interrupt : public callback::service<>{};
6767
```
6868

6969
*Components* use `cib::exports` in their configuration to *export* services to
@@ -157,7 +157,7 @@ INTERRUPT void serial_port_isr() {
157157

158158
Services can be accessed with the `service<...>` template variable on a
159159
`cib::nexus` instance. Because the `runtime_init` and `main_loop` services
160-
extend `cib::callback_meta`, their *service implementation* is a simple
160+
extend `callback::service`, their *service implementation* is a simple
161161
function pointer.
162162

163163
### `cib::service`
@@ -170,7 +170,7 @@ instance is not available. For example, when registering interrupts with
170170
an interrupt service.
171171

172172
```c++
173-
struct serial_port_rx : public cib::callback_meta<0, char>{};
173+
struct serial_port_rx : public callback::service<0, char>{};
174174

175175
struct serial_component {
176176
constexpr static auto config =
@@ -193,12 +193,12 @@ struct serial_component {
193193
### `cib::service_meta`
194194
195195
The *service metadata* describes to *cib* how a *service* is built and its
196-
type-erased implementation interface. (`cib::callback_meta`)[include/cib/callback.hpp]
196+
type-erased implementation interface. (`callback::service`)[include/cib/callback.hpp]
197197
is an example of *service metadata*. Services that use the callback *service*
198-
type extend `cib::callback_meta`.
198+
type extend `callback::service`.
199199
200200
```c++
201-
struct main_loop : public cib::callback_meta<> {};
201+
struct main_loop : public callback::service<> {};
202202
```
203203

204204
### Service Builder

benchmark/big_nexus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
template <int Id> [[maybe_unused]] static bool is_callback_invoked = false;
44

55
template <int Id, typename... Args>
6-
struct TestCallback : public cib::callback_meta<Args...> {};
6+
struct TestCallback : public callback::service<Args...> {};
77

88
template <int Id> struct TestComponent {
99
constexpr static auto offset = Id * 100;

examples/cib_serial_port/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
// Services - basically like a function prototypes.
66
// - callback function declaration.
7-
struct send_byte_t : public cib::callback_meta<uint8_t> {};
7+
struct send_byte_t : public callback::service<uint8_t> {};
88

9-
struct get_byte_t : public cib::callback_meta<> {};
9+
struct get_byte_t : public callback::service<> {};
1010

11-
struct serial_port_init_t : public cib::callback_meta<> {};
11+
struct serial_port_init_t : public callback::service<> {};
1212

13-
struct run_t : public cib::callback_meta<> {};
13+
struct run_t : public callback::service<> {};
1414

1515
// components defintion
1616
struct core_component_t {

examples/flow_daily_routine/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
4343
Note::
4444
services can be defined using
45-
+ cib::callback_meta<> - can have only one function pointer assigned to
45+
+ callback::service<> - can have only one function pointer assigned to
4646
execute.
4747
+ flow::service<> - set of actions/milestones which are to be
4848
executed in specific order. So basically sequential execution of multiple

examples/hello_world/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ attention to the `#include` directives in each file.
1212
```c++
1313
#include <cib/cib.hpp>
1414

15-
struct say_message : public cib::callback_meta<>{};
15+
struct say_message : public callback::service<>{};
1616

1717
struct core {
1818
constexpr static auto config =

examples/hello_world/core.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <cib/cib.hpp>
44

5-
struct say_message : public cib::callback_meta<> {};
5+
struct say_message : public callback::service<> {};
66

77
struct core {
88
constexpr static auto config = cib::config(cib::exports<say_message>);

include/cib/builder_meta.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace cib {
1717
*
1818
* @see cib::built
1919
*
20-
* @example cib::callback_meta
20+
* @example callback::service
2121
*/
2222
template <typename Builder, typename Interface> struct builder_meta {
2323
using builder_t = Builder;

include/cib/callback.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cstddef>
1010
#include <utility>
1111

12-
namespace cib {
12+
namespace callback {
1313
/**
1414
* Builder for simple callbacks.
1515
*
@@ -23,9 +23,9 @@ namespace cib {
2323
* List of argument types that must be passed into the callback when it is
2424
* invoked.
2525
*
26-
* @see cib::callback_meta
26+
* @see callback::service
2727
*/
28-
template <int NumFuncs = 0, typename... ArgTypes> struct callback {
28+
template <int NumFuncs = 0, typename... ArgTypes> struct builder {
2929
using func_ptr_t = void (*)(ArgTypes...);
3030
std::array<func_ptr_t, NumFuncs> funcs{};
3131

@@ -44,7 +44,7 @@ template <int NumFuncs = 0, typename... ArgTypes> struct callback {
4444
*/
4545
template <std::convertible_to<func_ptr_t>... Fs>
4646
[[nodiscard]] constexpr auto add(Fs &&...fs) const {
47-
callback<NumFuncs + sizeof...(Fs), ArgTypes...> cb;
47+
builder<NumFuncs + sizeof...(Fs), ArgTypes...> cb;
4848
auto i = std::size_t{};
4949
while (i < NumFuncs) {
5050
cb.funcs[i] = funcs[i];
@@ -117,6 +117,7 @@ template <int NumFuncs = 0, typename... ArgTypes> struct callback {
117117
* @see cib::extend
118118
*/
119119
template <typename... ArgTypes>
120-
struct callback_meta : public cib::builder_meta<callback<0, ArgTypes...>,
121-
void (*)(ArgTypes...)> {};
122-
} // namespace cib
120+
struct service
121+
: public cib::builder_meta<builder<0, ArgTypes...>, void (*)(ArgTypes...)> {
122+
};
123+
} // namespace callback

test/cib/callback.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#include <cib/cib.hpp>
1+
#include <cib/callback.hpp>
2+
3+
#include <stdx/tuple.hpp>
24

35
#include <catch2/catch_test_macros.hpp>
46

@@ -9,33 +11,33 @@ template <typename BuilderValue> constexpr static auto build() {
911
}
1012

1113
template <typename BuilderMeta, typename BuiltCallback>
12-
constexpr static bool built_is_convertable_to_interface(BuiltCallback) {
14+
constexpr static bool built_is_convertible_to_interface(BuiltCallback) {
1315
using interface_type = cib::interface_t<BuilderMeta>;
1416
return std::is_convertible_v<BuiltCallback, interface_type>;
1517
}
1618

1719
struct EmptyCallbackNoArgs {
18-
using meta = cib::callback_meta<>;
19-
constexpr static auto value = cib::builder_t<meta>{};
20+
using service = callback::service<>;
21+
constexpr static auto value = cib::builder_t<service>{};
2022
};
2123

2224
TEST_CASE("empty callback with no args", "[callback]") {
2325
constexpr auto built_callback = build<EmptyCallbackNoArgs>();
2426

2527
SECTION("can be called without issue") { built_callback(); }
2628

27-
SECTION("built type is convertable to the interface type") {
28-
REQUIRE(built_is_convertable_to_interface<EmptyCallbackNoArgs::meta>(
29+
SECTION("built type is convertible to the interface type") {
30+
REQUIRE(built_is_convertible_to_interface<EmptyCallbackNoArgs::service>(
2931
built_callback));
3032
}
3133
}
3234

3335
template <int Id> static bool is_callback_invoked = false;
3436

3537
struct CallbackNoArgsWithSingleExtension {
36-
using meta = cib::callback_meta<>;
38+
using service = callback::service<>;
3739
constexpr static auto value = []() {
38-
auto const builder = cib::builder_t<meta>{};
40+
auto const builder = cib::builder_t<service>{};
3941
return builder.add([]() { is_callback_invoked<0> = true; });
4042
}();
4143
};
@@ -50,14 +52,14 @@ TEST_CASE("callback with no args with single extension", "[callback]") {
5052
REQUIRE(is_callback_invoked<0>);
5153
}
5254

53-
SECTION("built type is convertable to the interface type") {
54-
REQUIRE(built_is_convertable_to_interface<
55-
CallbackNoArgsWithSingleExtension::meta>(built_callback));
55+
SECTION("built type is convertible to the interface type") {
56+
REQUIRE(built_is_convertible_to_interface<
57+
CallbackNoArgsWithSingleExtension::service>(built_callback));
5658
}
5759
}
5860

5961
struct CallbackNoArgsWithMultipleExtensions {
60-
using meta = cib::callback_meta<>;
62+
using service = callback::service<>;
6163

6264
static void extension_one() { is_callback_invoked<1> = true; }
6365

@@ -66,7 +68,7 @@ struct CallbackNoArgsWithMultipleExtensions {
6668
};
6769

6870
constexpr static auto value = []() {
69-
auto const builder = cib::builder_t<meta>{};
71+
auto const builder = cib::builder_t<service>{};
7072

7173
return builder.add([]() { is_callback_invoked<0> = true; })
7274
.add(extension_one)
@@ -89,33 +91,33 @@ TEST_CASE("callback with no args with multiple extensions", "[callback]") {
8991
REQUIRE(is_callback_invoked<2>);
9092
}
9193

92-
SECTION("built type is convertable to the interface type") {
93-
REQUIRE(built_is_convertable_to_interface<
94-
CallbackNoArgsWithMultipleExtensions::meta>(built_callback));
94+
SECTION("built type is convertible to the interface type") {
95+
REQUIRE(built_is_convertible_to_interface<
96+
CallbackNoArgsWithMultipleExtensions::service>(built_callback));
9597
}
9698
}
9799

98100
struct CallbackWithArgsWithNoExtensions {
99-
using meta = cib::callback_meta<int, bool>;
100-
constexpr static auto value = cib::builder_t<meta>{};
101+
using service = callback::service<int, bool>;
102+
constexpr static auto value = cib::builder_t<service>{};
101103
};
102104

103105
TEST_CASE("callback with args with no extensions", "[callback]") {
104106
constexpr auto built_callback = build<CallbackWithArgsWithNoExtensions>();
105107

106108
SECTION("can be called") { built_callback(42, true); }
107109

108-
SECTION("built type is convertable to the interface type") {
109-
REQUIRE(built_is_convertable_to_interface<
110-
CallbackWithArgsWithNoExtensions::meta>(built_callback));
110+
SECTION("built type is convertible to the interface type") {
111+
REQUIRE(built_is_convertible_to_interface<
112+
CallbackWithArgsWithNoExtensions::service>(built_callback));
111113
}
112114
}
113115

114116
template <int Id, typename... ArgTypes>
115117
static stdx::tuple<ArgTypes...> callback_args{};
116118

117119
struct CallbackWithArgsWithMultipleExtensions {
118-
using meta = cib::callback_meta<int, bool>;
120+
using service = callback::service<int, bool>;
119121

120122
static void extension_one(int a, bool b) {
121123
is_callback_invoked<1> = true;
@@ -128,7 +130,7 @@ struct CallbackWithArgsWithMultipleExtensions {
128130
};
129131

130132
constexpr static auto value = []() {
131-
auto const builder = cib::builder_t<meta>{};
133+
auto const builder = cib::builder_t<service>{};
132134

133135
return builder
134136
.add([](int a, bool b) {
@@ -168,8 +170,9 @@ TEST_CASE("callback with args with multiple extensions", "[callback]") {
168170
REQUIRE(get<1>(callback_args<2, int, bool>) == false);
169171
}
170172

171-
SECTION("built type is convertable to the interface type") {
172-
REQUIRE(built_is_convertable_to_interface<
173-
CallbackWithArgsWithMultipleExtensions::meta>(built_callback));
173+
SECTION("built type is convertible to the interface type") {
174+
REQUIRE(built_is_convertible_to_interface<
175+
CallbackWithArgsWithMultipleExtensions::service>(
176+
built_callback));
174177
}
175178
}

0 commit comments

Comments
 (0)