2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
9 #include <babeltrace2/babeltrace.h>
11 #include "cpp-common/bt2/graph.hpp"
12 #include "cpp-common/bt2c/c-string-view.hpp"
13 #include "cpp-common/bt2c/span.hpp"
14 #include "cpp-common/bt2s/make-unique.hpp"
16 #include "clk-cls-compat-postconds-triggers.hpp"
22 * Creates a simple condition trigger, calling `func`.
24 template <typename FuncT
>
25 CondTrigger::UP
makeSimpleTrigger(FuncT
&& func
, const CondTrigger::Type type
,
26 const std::string
& condId
,
27 const bt2c::CStringView nameSuffix
= {})
29 return bt2s::make_unique
<SimpleCondTrigger
>(std::forward
<FuncT
>(func
), type
, condId
,
33 using OnCompInitFunc
= std::function
<void(bt2::SelfComponent
)>;
36 * A "run in" class that delegates the execution to stored callables.
38 * Use the makeRunIn*Trigger() helpers below.
40 class RunInDelegator final
: public RunIn
43 static RunInDelegator
makeOnCompInit(OnCompInitFunc func
)
45 return RunInDelegator
{std::move(func
)};
48 void onCompInit(const bt2::SelfComponent self
) override
50 if (_mOnCompInitFunc
) {
51 _mOnCompInitFunc(self
);
56 explicit RunInDelegator(OnCompInitFunc onCompInitFunc
) :
57 _mOnCompInitFunc
{std::move(onCompInitFunc
)}
61 OnCompInitFunc _mOnCompInitFunc
;
65 * Creates a condition trigger, calling `func` in a component
66 * initialization context.
68 CondTrigger::UP
makeRunInCompInitTrigger(OnCompInitFunc func
, const CondTrigger::Type type
,
69 const std::string
& condId
,
70 const bt2c::CStringView nameSuffix
= {})
72 return bt2s::make_unique
<RunInCondTrigger
<RunInDelegator
>>(
73 RunInDelegator::makeOnCompInit(std::move(func
)), type
, condId
, nameSuffix
);
76 bt2::IntegerFieldClass::Shared
createUIntFc(const bt2::SelfComponent self
)
78 return self
.createTraceClass()->createUnsignedIntegerFieldClass();
83 int main(const int argc
, const char ** const argv
)
85 CondTriggers triggers
;
87 triggers
.emplace_back(makeSimpleTrigger(
89 bt2::Graph::create(292);
91 CondTrigger::Type::PRE
, "graph-create:valid-mip-version"));
93 triggers
.emplace_back(makeRunInCompInitTrigger(
94 [](const bt2::SelfComponent self
) {
95 createUIntFc(self
)->fieldValueRange(0);
97 CondTrigger::Type::PRE
, "field-class-integer-set-field-value-range:valid-n", "0"));
99 triggers
.emplace_back(makeRunInCompInitTrigger(
100 [](const bt2::SelfComponent self
) {
101 createUIntFc(self
)->fieldValueRange(65);
103 CondTrigger::Type::PRE
, "field-class-integer-set-field-value-range:valid-n", "gt-64"));
105 triggers
.emplace_back(makeSimpleTrigger(
107 bt_field_class_integer_set_field_value_range(nullptr, 23);
109 CondTrigger::Type::PRE
, "field-class-integer-set-field-value-range:not-null:field-class"));
111 addClkClsCompatTriggers(triggers
);
112 condMain(bt2c::makeSpan(argv
, argc
), triggers
);