Commit | Line | Data |
---|---|---|
5d7e8359 PP |
1 | /* |
2 | * SPDX-License-Identifier: GPL-2.0-only | |
3 | * | |
4 | * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com> | |
5 | */ | |
6 | ||
7 | #ifndef TESTS_LIB_CONDS_UTILS_H | |
8 | #define TESTS_LIB_CONDS_UTILS_H | |
9 | ||
fb10c90e SM |
10 | #include <babeltrace2/babeltrace.h> |
11 | ||
5d15e4ca SM |
12 | #include "cpp-common/bt2/self-component-port.hpp" |
13 | ||
486428e8 SM |
14 | enum cond_trigger_func_type |
15 | { | |
16 | COND_TRIGGER_FUNC_TYPE_BASIC, | |
17 | COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, | |
5d7e8359 PP |
18 | }; |
19 | ||
486428e8 SM |
20 | enum cond_trigger_type |
21 | { | |
22 | COND_TRIGGER_TYPE_PRE, | |
23 | COND_TRIGGER_TYPE_POST, | |
5d7e8359 PP |
24 | }; |
25 | ||
486428e8 | 26 | typedef void (*cond_trigger_basic_func)(void); |
5d15e4ca | 27 | typedef void (*cond_trigger_run_in_comp_cls_init_func)(bt2::SelfComponent); |
5d7e8359 | 28 | |
486428e8 SM |
29 | struct cond_trigger |
30 | { | |
31 | enum cond_trigger_type type; | |
32 | enum cond_trigger_func_type func_type; | |
33 | const char *cond_id; | |
34 | const char *suffix; | |
35 | union | |
36 | { | |
37 | cond_trigger_basic_func basic; | |
38 | cond_trigger_run_in_comp_cls_init_func run_in_comp_cls_init; | |
39 | } func; | |
5d7e8359 PP |
40 | }; |
41 | ||
486428e8 SM |
42 | #define COND_TRIGGER_PRE_BASIC(_cond_id, _suffix, _func) \ |
43 | { \ | |
44 | .type = COND_TRIGGER_TYPE_PRE, .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ | |
45 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
46 | .basic = _func, \ | |
47 | } \ | |
48 | } | |
5d7e8359 | 49 | |
486428e8 SM |
50 | #define COND_TRIGGER_POST_BASIC(_cond_id, _suffix, _func) \ |
51 | { \ | |
52 | .type = COND_TRIGGER_TYPE_POST, .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ | |
53 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
54 | .basic = _func, \ | |
55 | } \ | |
56 | } | |
5d7e8359 | 57 | |
486428e8 SM |
58 | #define COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ |
59 | { \ | |
60 | .type = COND_TRIGGER_TYPE_PRE, .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ | |
61 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
62 | .run_in_comp_cls_init = _func, \ | |
63 | } \ | |
64 | } | |
5d7e8359 | 65 | |
486428e8 SM |
66 | #define COND_TRIGGER_POST_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ |
67 | { \ | |
68 | .type = COND_TRIGGER_TYPE_POST, .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ | |
69 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
70 | .run_in_comp_cls_init = _func, \ | |
71 | } \ | |
72 | } | |
5d7e8359 | 73 | |
486428e8 SM |
74 | void cond_main(int argc, const char *argv[], const struct cond_trigger triggers[], |
75 | size_t trigger_count); | |
5d7e8359 PP |
76 | |
77 | #endif /* TESTS_LIB_CONDS_UTILS_H */ |