10
10
concept is written, it will be * italic* . Whenever a C++ type or function is
11
11
written, it will be formatted as ` code ` .
12
12
13
+ - Component
14
+ - Service
15
+ - Metadata
16
+ - Builder
17
+ - Implementaion
18
+ - Feature
19
+ - Nexus
20
+
13
21
### Services
14
22
15
23
> A * service* is something that can be * extended* with new functionality.
@@ -53,6 +61,9 @@ struct runtime_init : public cib::callback_meta<>{};
53
61
54
62
/// Invoked each iteration through the main loop
55
63
struct main_loop : public cib::callback_meta<>{};
64
+
65
+ /// Invoked each time the serial port interrupt is triggered
66
+ struct serial_port_interrupt : public cib::callback_meta<>{};
56
67
```
57
68
58
69
* Components* use ` cib::exports ` in their configuration to * export* services to
@@ -61,7 +72,7 @@ features. All *services* must be exported for them to be extended.
61
72
``` c++
62
73
struct board_component {
63
74
constexpr static auto config =
64
- cib::exports<serial_port_rx , runtime_init, main_loop>;
75
+ cib::exports<serial_port_interrupt , runtime_init, main_loop>;
65
76
};
66
77
```
67
78
@@ -97,7 +108,14 @@ the application is entirely contained within the components it comprises.
97
108
Only a small amount of startup and glue-code is necessary outside *cib*
98
109
*components*.
99
110
100
- ### Nexus
111
+ ```c++
112
+ struct my_project {
113
+ constexpr static auto config =
114
+ cib::components<board_component, serial_component, echo_component>;
115
+ };
116
+ ```
117
+
118
+ ### `cib::nexus`
101
119
102
120
> The `cib::nexus` combines all the *services* and *features* within a project.
103
121
It performs the compile-time initialization and build process across all
@@ -121,7 +139,7 @@ The `cib::nexus` implements the heart of *cib*. Once a *cib* configuration has
121
139
been created, using the `cib::nexus` is easy:
122
140
123
141
```c++
124
- cib::nexus<hello_world > nexus{};
142
+ cib::nexus<my_project > nexus{};
125
143
126
144
int main() {
127
145
nexus.init();
@@ -131,9 +149,66 @@ int main() {
131
149
nexus.service<main_loop>();
132
150
}
133
151
}
152
+
153
+ INTERRUPT void serial_port_isr() {
154
+ nexus.service<serial_port_interrupt>();
155
+ }
134
156
```
135
157
136
158
Services can be accessed with the ` service<...> ` template variable on a
137
159
` cib::nexus ` instance. Because the ` runtime_init ` and ` main_loop ` services
138
160
extend ` cib::callback_meta ` , their * service implementation* is a simple
139
- function pointer.
161
+ function pointer.
162
+
163
+ ### ` cib::service `
164
+
165
+ > `cib::service` is a type-erased template variable pointer to a *service
166
+ implementation*.
167
+
168
+ There are cases in which a *service* must be invoked but the `cib::nexus`
169
+ instance is not available. For example, when registering interrupts with
170
+ an interrupt service.
171
+
172
+ ```c++
173
+ struct serial_port_rx : public cib ::callback_meta<0, char>{};
174
+
175
+ struct serial_component {
176
+ constexpr static auto config =
177
+ cib::config(
178
+ cib::exports<serial_port_rx>,
179
+
180
+ cib::extend<serial_port_interrupt>([ ] ( ) {
181
+ auto const rx_byte = pop_serial_data();
182
+
183
+ // it is impossible to reference the "nexus" variable in
184
+ // "main.cpp". cib::service can be used instead.
185
+ cib::service<serial_port_rx>(rx_byte);
186
+ }),
187
+
188
+ cib::extend<runtime_init>(&serial_port_init())
189
+ );
190
+ };
191
+ ```
192
+
193
+ ### `cib::service_meta`
194
+
195
+ 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]
197
+ is an example of *service metadata*. Services that use the callback *service*
198
+ type extend `cib::callback_meta`.
199
+
200
+ ```c++
201
+ struct main_loop : public cib::callback_meta<> {};
202
+ ```
203
+
204
+ ### Service Builder
205
+
206
+ A * service builder* is responsible for building up the * service* during
207
+ the initialization and build process. Every time the ` cib::extend<T>(feature) `
208
+ declaration is used, the * builder* for the * service* named ` T ` will have its
209
+ ` add(feature) ` method called. This registers the * feature* with the * service* .
210
+
211
+ ### Service Implementation Interface
212
+
213
+ The * service implementation interface* is the type-erased interface that can be used
214
+ to invoke the * service* through ` cib::service<T> ` .
0 commit comments