An upcoming patch needs to dynamically create and append triggers to the
trigger list. Make the container a vector. For simplicity, update
`condMain` to take a reference to a vector of unique pointers of
triggers (rather than inventing some abstraction).
Change-Id: Ic5e2fe6da151434ec515c041d4e1096193d29221
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12115
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
#include "cpp-common/bt2/graph.hpp"
#include "cpp-common/bt2c/c-string-view.hpp"
#include "cpp-common/bt2/graph.hpp"
#include "cpp-common/bt2c/c-string-view.hpp"
+#include "cpp-common/bt2s/make-unique.hpp"
* Creates a simple condition trigger, calling `func`.
*/
template <typename FuncT>
* Creates a simple condition trigger, calling `func`.
*/
template <typename FuncT>
-CondTrigger *makeSimpleTrigger(FuncT&& func, const CondTrigger::Type type,
- const std::string& condId, const bt2c::CStringView nameSuffix = {})
+CondTrigger::UP makeSimpleTrigger(FuncT&& func, const CondTrigger::Type type,
+ const std::string& condId,
+ const bt2c::CStringView nameSuffix = {})
- return new SimpleCondTrigger {std::forward<FuncT>(func), type, condId, nameSuffix};
+ return bt2s::make_unique<SimpleCondTrigger>(std::forward<FuncT>(func), type, condId,
+ nameSuffix);
}
using OnCompInitFunc = std::function<void(bt2::SelfComponent)>;
}
using OnCompInitFunc = std::function<void(bt2::SelfComponent)>;
* Creates a condition trigger, calling `func` in a component
* initialization context.
*/
* Creates a condition trigger, calling `func` in a component
* initialization context.
*/
-CondTrigger *makeRunInCompInitTrigger(OnCompInitFunc func, const CondTrigger::Type type,
- const std::string& condId,
- const bt2c::CStringView nameSuffix = {})
+CondTrigger::UP makeRunInCompInitTrigger(OnCompInitFunc func, const CondTrigger::Type type,
+ const std::string& condId,
+ const bt2c::CStringView nameSuffix = {})
- return new RunInCondTrigger<RunInDelegator> {RunInDelegator::makeOnCompInit(std::move(func)),
- type, condId, nameSuffix};
+ return bt2s::make_unique<RunInCondTrigger<RunInDelegator>>(
+ RunInDelegator::makeOnCompInit(std::move(func)), type, condId, nameSuffix);
}
bt2::IntegerFieldClass::Shared createUIntFc(const bt2::SelfComponent self)
}
bt2::IntegerFieldClass::Shared createUIntFc(const bt2::SelfComponent self)
return self.createTraceClass()->createUnsignedIntegerFieldClass();
}
return self.createTraceClass()->createUnsignedIntegerFieldClass();
}
-/* Our condition triggers */
-CondTrigger * const triggers[] = {
- makeSimpleTrigger(
+} /* namespace */
+
+int main(const int argc, const char ** const argv)
+{
+ CondTriggers triggers;
+
+ triggers.emplace_back(makeSimpleTrigger(
[] {
bt2::Graph::create(292);
},
[] {
bt2::Graph::create(292);
},
- CondTrigger::Type::PRE, "graph-create:valid-mip-version"),
+ CondTrigger::Type::PRE, "graph-create:valid-mip-version"));
- makeRunInCompInitTrigger(
+ triggers.emplace_back(makeRunInCompInitTrigger(
[](const bt2::SelfComponent self) {
createUIntFc(self)->fieldValueRange(0);
},
[](const bt2::SelfComponent self) {
createUIntFc(self)->fieldValueRange(0);
},
- CondTrigger::Type::PRE, "field-class-integer-set-field-value-range:valid-n", "0"),
+ CondTrigger::Type::PRE, "field-class-integer-set-field-value-range:valid-n", "0"));
- makeRunInCompInitTrigger(
+ triggers.emplace_back(makeRunInCompInitTrigger(
[](const bt2::SelfComponent self) {
createUIntFc(self)->fieldValueRange(65);
},
[](const bt2::SelfComponent self) {
createUIntFc(self)->fieldValueRange(65);
},
- CondTrigger::Type::PRE, "field-class-integer-set-field-value-range:valid-n", "gt-64"),
+ CondTrigger::Type::PRE, "field-class-integer-set-field-value-range:valid-n", "gt-64"));
+ triggers.emplace_back(makeSimpleTrigger(
[] {
bt_field_class_integer_set_field_value_range(nullptr, 23);
},
[] {
bt_field_class_integer_set_field_value_range(nullptr, 23);
},
- CondTrigger::Type::PRE, "field-class-integer-set-field-value-range:not-null:field-class"),
-};
-
-} /* namespace */
+ CondTrigger::Type::PRE, "field-class-integer-set-field-value-range:not-null:field-class"));
-int main(const int argc, const char ** const argv)
-{
condMain(argc, argv, triggers);
}
condMain(argc, argv, triggers);
}
-void listCondTriggers(const CondTriggers condTriggers) noexcept
+void listCondTriggers(const CondTriggers& condTriggers) noexcept
{
auto condTriggerArray = nlohmann::json::array();
{
auto condTriggerArray = nlohmann::json::array();
- for (const auto condTrigger : condTriggers) {
+ for (const auto& condTrigger : condTriggers) {
condTriggerArray.push_back(nlohmann::json {
{"cond-id", condTrigger->condId()},
{"name", condTrigger->name()},
condTriggerArray.push_back(nlohmann::json {
{"cond-id", condTrigger->condId()},
{"name", condTrigger->name()},
-void condMain(const int argc, const char ** const argv, const CondTriggers condTriggers) noexcept
+void condMain(const int argc, const char ** const argv, const CondTriggers& condTriggers) noexcept
#define TESTS_LIB_CONDS_UTILS_HPP
#include <functional>
#define TESTS_LIB_CONDS_UTILS_HPP
#include <functional>
#include <string>
#include <utility>
#include <string>
#include <utility>
#include <babeltrace2/babeltrace.h>
#include "cpp-common/bt2c/c-string-view.hpp"
#include <babeltrace2/babeltrace.h>
#include "cpp-common/bt2c/c-string-view.hpp"
-#include "cpp-common/bt2s/span.hpp"
#include "../utils/run-in.hpp"
#include "../utils/run-in.hpp"
class CondTrigger
{
public:
class CondTrigger
{
public:
+ using UP = std::unique_ptr<CondTrigger>;
+
/*
* List of condition triggers.
*/
/*
* List of condition triggers.
*/
-using CondTriggers = bt2s::span<CondTrigger * const>;
+using CondTriggers = std::vector<CondTrigger::UP>;
/*
* The entry point of a condition trigger program.
/*
* The entry point of a condition trigger program.
* The program is expected to abort through a libbabeltrace2
* condition failure.
*/
* The program is expected to abort through a libbabeltrace2
* condition failure.
*/
-void condMain(int argc, const char **argv, CondTriggers triggers) noexcept;
+void condMain(int argc, const char **argv, const CondTriggers& triggers) noexcept;
#endif /* TESTS_LIB_CONDS_UTILS_HPP */
#endif /* TESTS_LIB_CONDS_UTILS_HPP */