Skip to content

Commit d073770

Browse files
authored
Update USER_GUIDE.md (#42)
1 parent a5aa998 commit d073770

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

USER_GUIDE.md

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
concept is written, it will be *italic*. Whenever a C++ type or function is
1111
written, it will be formatted as `code`.
1212

13+
- Component
14+
- Service
15+
- Metadata
16+
- Builder
17+
- Implementaion
18+
- Feature
19+
- Nexus
20+
1321
### Services
1422

1523
> A *service* is something that can be *extended* with new functionality.
@@ -53,6 +61,9 @@ struct runtime_init : public cib::callback_meta<>{};
5361
5462
/// Invoked each iteration through the main loop
5563
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<>{};
5667
```
5768

5869
*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.
6172
```c++
6273
struct board_component {
6374
constexpr static auto config =
64-
cib::exports<serial_port_rx, runtime_init, main_loop>;
75+
cib::exports<serial_port_interrupt, runtime_init, main_loop>;
6576
};
6677
```
6778
@@ -97,7 +108,14 @@ the application is entirely contained within the components it comprises.
97108
Only a small amount of startup and glue-code is necessary outside *cib*
98109
*components*.
99110

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`
101119
102120
> The `cib::nexus` combines all the *services* and *features* within a project.
103121
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
121139
been created, using the `cib::nexus` is easy:
122140
123141
```c++
124-
cib::nexus<hello_world> nexus{};
142+
cib::nexus<my_project> nexus{};
125143
126144
int main() {
127145
nexus.init();
@@ -131,9 +149,66 @@ int main() {
131149
nexus.service<main_loop>();
132150
}
133151
}
152+
153+
INTERRUPT void serial_port_isr() {
154+
nexus.service<serial_port_interrupt>();
155+
}
134156
```
135157

136158
Services can be accessed with the `service<...>` template variable on a
137159
`cib::nexus` instance. Because the `runtime_init` and `main_loop` services
138160
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

Comments
 (0)