| 1 | /* |
| 2 | * SPDX-License-Identifier: GPL-2.0-only |
| 3 | * |
| 4 | * Copyright (C) 2020-2023 EfficiOS, inc. |
| 5 | */ |
| 6 | |
| 7 | #ifndef TESTS_LIB_UTILS_H |
| 8 | #define TESTS_LIB_UTILS_H |
| 9 | |
| 10 | #include <functional> |
| 11 | |
| 12 | #include <babeltrace2/babeltrace.h> |
| 13 | |
| 14 | #include "cpp-common/bt2/self-component-class.hpp" |
| 15 | #include "cpp-common/bt2/self-component-port.hpp" |
| 16 | #include "cpp-common/bt2/self-message-iterator.hpp" |
| 17 | |
| 18 | using RunInCompClsQueryFunc = std::function<void(bt2::SelfComponentClass)>; |
| 19 | using RunInCompClsInitFunc = std::function<void(bt2::SelfComponent)>; |
| 20 | using RunInMsgIterClsInitFunc = std::function<void(bt2::SelfMessageIterator)>; |
| 21 | |
| 22 | /* |
| 23 | * Runs: |
| 24 | * |
| 25 | * • `compClsCtxFunc` in the context of a component class method, |
| 26 | * if not `nullptr`. |
| 27 | * |
| 28 | * • `compCtxFunc` in the context of a component method, if not |
| 29 | * `nullptr`. |
| 30 | * |
| 31 | * • `msgIterCtxFunc` in the context of a message iterator method, if |
| 32 | * not `nullptr`. |
| 33 | */ |
| 34 | void runIn(RunInCompClsQueryFunc compClsCtxFunc, RunInCompClsInitFunc compCtxFunc, |
| 35 | RunInMsgIterClsInitFunc msgIterCtxFunc); |
| 36 | |
| 37 | /* |
| 38 | * Runs `func` in the context of a component class method. |
| 39 | */ |
| 40 | void runInCompClsQuery(RunInCompClsQueryFunc func); |
| 41 | |
| 42 | /* |
| 43 | * Runs `func` in the context of a component method. |
| 44 | */ |
| 45 | void runInCompClsInit(RunInCompClsInitFunc func); |
| 46 | |
| 47 | /* |
| 48 | * Runs `func` in the context of a message iterator method. |
| 49 | */ |
| 50 | void runInMsgIterClsInit(RunInMsgIterClsInitFunc func); |
| 51 | |
| 52 | #endif /* TESTS_LIB_UTILS_H */ |