Skip to content

Commit 69595ab

Browse files
authored
Merge pull request #660 from elbeno/decouple-service
Refactor `cib` library structure
2 parents c2639b4 + 5b88897 commit 69595ab

File tree

15 files changed

+218
-139
lines changed

15 files changed

+218
-139
lines changed

CMakeLists.txt

Lines changed: 108 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,43 @@ target_sources(
133133
include/log/level.hpp
134134
include/log/log.hpp)
135135

136+
add_library(cib_msg INTERFACE)
137+
target_compile_features(cib_msg INTERFACE cxx_std_20)
138+
target_link_libraries_system(
139+
cib_msg
140+
INTERFACE
141+
async
142+
cib_log
143+
cib_lookup
144+
cib_match
145+
cib_sc
146+
stdx)
147+
148+
target_sources(
149+
cib_msg
150+
INTERFACE FILE_SET
151+
msg
152+
TYPE
153+
HEADERS
154+
BASE_DIRS
155+
include
156+
FILES
157+
include/msg/callback.hpp
158+
include/msg/detail/indexed_builder_common.hpp
159+
include/msg/detail/indexed_handler_common.hpp
160+
include/msg/detail/separate_sum_terms.hpp
161+
include/msg/field.hpp
162+
include/msg/field_matchers.hpp
163+
include/msg/handler_builder.hpp
164+
include/msg/handler.hpp
165+
include/msg/handler_interface.hpp
166+
include/msg/indexed_builder.hpp
167+
include/msg/indexed_handler.hpp
168+
include/msg/indexed_service.hpp
169+
include/msg/message.hpp
170+
include/msg/send.hpp
171+
include/msg/service.hpp)
172+
136173
add_library(cib_log_fmt INTERFACE)
137174
target_compile_features(cib_log_fmt INTERFACE cxx_std_20)
138175
target_link_libraries_system(cib_log_fmt INTERFACE cib_log fmt::fmt-header-only
@@ -149,24 +186,31 @@ target_sources(
149186
FILES
150187
include/log/fmt/logger.hpp)
151188

152-
add_library(cib INTERFACE)
153-
target_compile_features(cib INTERFACE cxx_std_20)
154-
target_link_libraries_system(
155-
cib
156-
INTERFACE
157-
async
158-
cib_interrupt
159-
cib_lookup
160-
cib_match
161-
cib_sc
162-
concurrency
163-
fmt::fmt-header-only
164-
stdx)
189+
add_library(cib_log_mipi INTERFACE)
190+
target_compile_features(cib_log_mipi INTERFACE cxx_std_20)
191+
target_link_libraries_system(cib_log_mipi INTERFACE cib_log cib_msg concurrency
192+
stdx)
165193

166194
target_sources(
167-
cib
195+
cib_log_mipi
168196
INTERFACE FILE_SET
169-
cib
197+
log
198+
TYPE
199+
HEADERS
200+
BASE_DIRS
201+
include
202+
FILES
203+
include/log/catalog/catalog.hpp
204+
include/log/catalog/mipi_encoder.hpp)
205+
206+
add_library(cib_nexus INTERFACE)
207+
target_compile_features(cib_nexus INTERFACE cxx_std_20)
208+
target_link_libraries_system(cib_nexus INTERFACE stdx)
209+
210+
target_sources(
211+
cib_nexus
212+
INTERFACE FILE_SET
213+
nexus
170214
TYPE
171215
HEADERS
172216
BASE_DIRS
@@ -175,7 +219,6 @@ target_sources(
175219
include/cib/builder_meta.hpp
176220
include/cib/built.hpp
177221
include/cib/callback.hpp
178-
include/cib/cib.hpp
179222
include/cib/config.hpp
180223
include/cib/detail/components.hpp
181224
include/cib/detail/constexpr_conditional.hpp
@@ -186,11 +229,14 @@ target_sources(
186229
include/cib/detail/extend.hpp
187230
include/cib/detail/nexus_details.hpp
188231
include/cib/func_decl.hpp
189-
include/cib/nexus.hpp
190-
include/cib/top.hpp)
232+
include/cib/nexus.hpp)
233+
234+
add_library(cib_flow INTERFACE)
235+
target_compile_features(cib_flow INTERFACE cxx_std_20)
236+
target_link_libraries_system(cib_flow INTERFACE cib_log cib_nexus cib_sc stdx)
191237

192238
target_sources(
193-
cib
239+
cib_flow
194240
INTERFACE FILE_SET
195241
flow
196242
TYPE
@@ -210,33 +256,19 @@ target_sources(
210256
include/flow/run.hpp
211257
include/flow/step.hpp)
212258

213-
target_sources(
214-
cib
215-
INTERFACE FILE_SET
216-
msg
217-
TYPE
218-
HEADERS
219-
BASE_DIRS
220-
include
221-
FILES
222-
include/msg/callback.hpp
223-
include/msg/detail/indexed_builder_common.hpp
224-
include/msg/detail/indexed_handler_common.hpp
225-
include/msg/detail/separate_sum_terms.hpp
226-
include/msg/field.hpp
227-
include/msg/field_matchers.hpp
228-
include/msg/handler_builder.hpp
229-
include/msg/handler.hpp
230-
include/msg/handler_interface.hpp
231-
include/msg/indexed_builder.hpp
232-
include/msg/indexed_handler.hpp
233-
include/msg/indexed_service.hpp
234-
include/msg/message.hpp
235-
include/msg/send.hpp
236-
include/msg/service.hpp)
259+
add_library(cib_seq INTERFACE)
260+
target_compile_features(cib_seq INTERFACE cxx_std_20)
261+
target_link_libraries_system(
262+
cib_seq
263+
INTERFACE
264+
cib_flow
265+
cib_log
266+
cib_nexus
267+
cib_sc
268+
stdx)
237269

238270
target_sources(
239-
cib
271+
cib_seq
240272
INTERFACE FILE_SET
241273
seq
242274
TYPE
@@ -248,29 +280,53 @@ target_sources(
248280
include/seq/impl.hpp
249281
include/seq/step.hpp)
250282

251-
add_library(cib_log_mipi INTERFACE)
252-
target_compile_features(cib_log_mipi INTERFACE cxx_std_20)
253-
target_link_libraries_system(cib_log_mipi INTERFACE cib cib_log concurrency
254-
stdx)
283+
add_library(cib INTERFACE)
284+
target_compile_features(cib INTERFACE cxx_std_20)
285+
target_link_libraries_system(
286+
cib
287+
INTERFACE
288+
async
289+
cib_flow
290+
cib_interrupt
291+
cib_log
292+
cib_log_fmt
293+
cib_log_mipi
294+
cib_lookup
295+
cib_match
296+
cib_msg
297+
cib_nexus
298+
cib_sc
299+
cib_seq
300+
concurrency
301+
fmt::fmt-header-only
302+
stdx)
255303

256304
target_sources(
257-
cib_log_mipi
305+
cib
258306
INTERFACE FILE_SET
259-
log
307+
cib
260308
TYPE
261309
HEADERS
262310
BASE_DIRS
263311
include
264312
FILES
265-
include/log/catalog/catalog.hpp
266-
include/log/catalog/mipi_encoder.hpp)
313+
include/cib/cib.hpp
314+
include/cib/top.hpp)
267315

268316
if(PROJECT_IS_TOP_LEVEL)
269317
add_docs(docs)
270318
clang_tidy_interface(cib)
319+
clang_tidy_interface(cib_flow)
271320
clang_tidy_interface(cib_interrupt)
321+
clang_tidy_interface(cib_lookup)
322+
clang_tidy_interface(cib_log)
323+
clang_tidy_interface(cib_log_fmt)
324+
clang_tidy_interface(cib_log_mipi)
272325
clang_tidy_interface(cib_match)
326+
clang_tidy_interface(cib_msg)
327+
clang_tidy_interface(cib_nexus)
273328
clang_tidy_interface(cib_sc)
329+
clang_tidy_interface(cib_seq)
274330

275331
# Enable functional and performance test suites.
276332
add_subdirectory(test)

docs/flows.adoc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ namespace example_component {
339339
==== `operator*`
340340

341341
Explicitly add an action to the flow. Actions used in flow extensions without
342-
the `*` will be treated as references only and will not be added to the
342+
the `\*` will be treated as references only and will not be added to the
343343
flow at that location. It is a compilation error if an action is not added
344344
with a `*` in exactly one location in the overall config.
345345

@@ -388,8 +388,12 @@ what happens by default when we run the flow.
388388
// the default flow builder and service
389389
template <stdx::ct_string Name = "">
390390
using builder = flow::graph<Name, flow::graph_builder<impl>>;
391+
391392
template <stdx::ct_string Name = "">
392-
struct service : cib::builder_meta<builder<Name>, flow::FunctionPtr> {};
393+
struct service {
394+
using builder_t = builder<Name>;
395+
using interface_t = flow::FunctionPtr;
396+
};
393397
394398
// declare a flow service
395399
struct MorningRoutine : public service<"MorningRoutine"> {};
@@ -410,8 +414,12 @@ But given a flow, other renderings are possible.
410414
// a flow builder and service that produces a graphviz rendering
411415
template <stdx::ct_string Name = "">
412416
using viz_builder = flow::graph<Name, flow::graphviz_builder>;
417+
413418
template <stdx::ct_string Name = "">
414-
struct viz_service : cib::builder_meta<builder<Name>, flow::VizFunctionPtr> {};
419+
struct viz_service {
420+
using builder_t = builder<Name>;
421+
using interface_t = flow::VizFunctionPtr;
422+
};
415423
----
416424

417425
Here, `viz_service` will produce a graphviz rendering of a flow using the

docs/intro.adoc

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,47 @@ The library dependencies are:
3434

3535
- https://github.com/boostorg/mp11[Boost.MP11]
3636
- https://github.com/intel/cpp-std-extensions[C++ std extensions (`stdx`)]
37-
- https://github.com/intel/cpp-baremetal-concurrency[Baremetal Concurrency]
37+
- https://github.com/intel/cpp-baremetal-concurrency[Baremetal Concurrency (`conc`)]
38+
- https://github.com/intel/cpp-senders-and-receivers[Baremetal Senders and Receivers (`async`)]
3839
- https://github.com/fmtlib/fmt[fmt]
3940

40-
=== Libraries
41+
=== Functionality
4142

42-
_cib_ contains several libraries that work together:
43+
_cib_ contains several parts that work together:
4344

4445
- xref:flow.adoc#_the_flow_library[`flow`]
4546
- xref:logging.adoc#_the_logging_library[`logging`]
4647
- xref:interrupt.adoc#_the_interrupt_library[`interrupt`]
4748
- xref:match.adoc#_the_match_library[`match`]
4849
- xref:message.adoc#_the_message_library[`message`]
4950
- xref:sc.adoc#_the_sc_string_constant_library[`sc` (string constant)]
51+
52+
=== Sub-library DAG
53+
54+
Various sub-libraries within CIB form a dependency graph. `cib` is an omnibus
55+
library that contains all the functionality.
56+
57+
[mermaid, format="svg"]
58+
----
59+
flowchart BT
60+
sc(cib_sc)
61+
nexus(cib_nexus)
62+
lookup(cib_lookup)
63+
64+
flow(cib_flow) --> nexus
65+
flow --> log
66+
67+
interrupt(cib_interrupt) --> sc
68+
match(cib_match) --> sc
69+
log(cib_log) --> sc
70+
71+
72+
log_fmt(cib_log_fmt) --> log
73+
msg(cib_msg) --> log & match
74+
msg --> lookup
75+
76+
log_mipi(cib_log_mipi) --> msg
77+
seq(cib_seq) --> flow
78+
79+
cib --> interrupt & seq & log_fmt & log_mipi
80+
----

include/cib/builder_meta.hpp

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,12 @@
11
#pragma once
22

33
namespace cib {
4-
/**
5-
* Describe a builder to cib.
6-
*
7-
* @tparam Builder
8-
* The initial builder type cib should use when creating a builder.
9-
* This is only the initial type, the Builder::add(...) function
10-
* may return a different type and cib will track that correctly.
11-
*
12-
* @tparam Interface
13-
* The type-erased interface services built with this builder
14-
* will implement. For example, cib::callback allows many other
15-
* callables to get executed when its service gets invoked. The
16-
* type-erased interface for cib::callback is a function pointer.
17-
*
18-
* @see cib::built
19-
*
20-
* @example callback::service
21-
*/
22-
template <typename Builder, typename Interface> struct builder_meta {
23-
using builder_t = Builder;
24-
using interface_t = Interface;
4+
template <typename T>
5+
concept builder_meta = requires {
6+
typename T::builder_t;
7+
typename T::interface_t;
258
};
269

27-
template <typename BuilderMeta>
28-
using builder_t = typename BuilderMeta::builder_t;
29-
30-
template <typename BuilderMeta>
31-
using interface_t = typename BuilderMeta::interface_t;
10+
template <builder_meta T> using builder_t = typename T::builder_t;
11+
template <builder_meta T> using interface_t = typename T::interface_t;
3212
} // namespace cib

include/cib/built.hpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,5 @@
33
#include <cib/builder_meta.hpp>
44

55
namespace cib {
6-
/**
7-
* Pointer to a built service implementation.
8-
*
9-
* @tparam ServiceMeta
10-
* Tag name of the service.
11-
*
12-
* @see cib::builder_meta
13-
*/
14-
template <typename ServiceMeta> interface_t<ServiceMeta> service;
6+
template <builder_meta ServiceMeta> interface_t<ServiceMeta> service;
157
} // namespace cib

include/cib/callback.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ template <int NumFuncs = 0, typename... ArgTypes> struct builder {
105105
/**
106106
* Extend this to create named callback services.
107107
*
108-
* Types that extend callback_meta can be used as unique names with
108+
* Types that extend service can be used as unique names with
109109
* cib::exports and cib::extend.
110110
*
111111
* @tparam ArgTypes
@@ -116,8 +116,8 @@ template <int NumFuncs = 0, typename... ArgTypes> struct builder {
116116
* @see cib::exports
117117
* @see cib::extend
118118
*/
119-
template <typename... ArgTypes>
120-
struct service
121-
: public cib::builder_meta<builder<0, ArgTypes...>, void (*)(ArgTypes...)> {
119+
template <typename... ArgTypes> struct service {
120+
using builder_t = builder<0, ArgTypes...>;
121+
using interface_t = void (*)(ArgTypes...);
122122
};
123123
} // namespace callback

include/cib/config.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <cib/builder_meta.hpp>
43
#include <cib/detail/components.hpp>
54
#include <cib/detail/config_details.hpp>
65
#include <cib/detail/config_item.hpp>

0 commit comments

Comments
 (0)