2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
14 #include <babeltrace2/babeltrace.h>
16 #include "common/assert.h"
17 #include "cpp-common/vendor/nlohmann/json.hpp"
19 #include "../utils/run-in.hpp"
22 static void run_trigger(const struct cond_trigger
*trigger
)
24 switch (trigger
->func_type
) {
25 case COND_TRIGGER_FUNC_TYPE_BASIC
:
26 trigger
->func
.basic();
28 case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT
:
29 runInCompClsInit(trigger
->func
.run_in_comp_cls_init
);
36 static void list_triggers(const struct cond_trigger triggers
[], size_t trigger_count
)
38 nlohmann::json trigger_array
= nlohmann::json::array();
40 for (size_t i
= 0; i
< trigger_count
; i
++) {
41 nlohmann::json trigger_obj
= nlohmann::json::object();
42 const cond_trigger
& trigger
= triggers
[i
];
45 trigger_obj
["cond-id"] = trigger
.cond_id
;
47 /* Name starts with condition ID */
48 std::string name
= trigger
.cond_id
;
52 name
+= trigger
.suffix
;
55 trigger_obj
["name"] = std::move(name
);
56 trigger_array
.push_back(std::move(trigger_obj
));
59 auto str
= trigger_array
.dump();
61 std::flush(std::cout
);
64 void cond_main(int argc
, const char *argv
[], const struct cond_trigger triggers
[],
69 if (strcmp(argv
[1], "list") == 0) {
70 list_triggers(triggers
, trigger_count
);
71 } else if (strcmp(argv
[1], "run") == 0) {
75 index
= atoi(argv
[2]);
76 BT_ASSERT(index
>= 0 && index
< trigger_count
);
77 run_trigger(&triggers
[index
]);