2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
10 #include <babeltrace2/babeltrace.h>
12 #include "common/assert.h"
13 #include "cpp-common/vendor/fmt/core.h"
14 #include "cpp-common/vendor/nlohmann/json.hpp"
16 #include "../utils/run-in.hpp"
21 void runTrigger(const cond_trigger
& trigger
) noexcept
23 switch (trigger
.func_type
) {
24 case COND_TRIGGER_FUNC_TYPE_BASIC
:
27 case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT
:
28 runInCompClsInit(trigger
.func
.run_in_comp_cls_init
);
35 void listTriggers(const bt2s::span
<const cond_trigger
> triggers
) noexcept
37 auto triggerArray
= nlohmann::json::array();
39 for (auto& trigger
: triggers
) {
40 auto triggerObj
= nlohmann::json::object();
43 triggerObj
["cond-id"] = trigger
.cond_id
;
45 /* Name starts with condition ID */
46 std::string name
= trigger
.cond_id
;
50 name
+= trigger
.suffix
;
53 triggerObj
["name"] = std::move(name
);
54 triggerArray
.push_back(std::move(triggerObj
));
57 fmt::println("{}", triggerArray
.dump());
62 void condMain(const int argc
, const char ** const argv
,
63 const bt2s::span
<const cond_trigger
> triggers
) noexcept
67 if (strcmp(argv
[1], "list") == 0) {
68 listTriggers(triggers
);
69 } else if (strcmp(argv
[1], "run") == 0) {
73 index
= atoi(argv
[2]);
74 BT_ASSERT(index
>= 0 && index
< triggers
.size());
75 runTrigger(triggers
[index
]);