2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
15 #include <babeltrace2/babeltrace.h>
17 #include "common/assert.h"
18 #include "cpp-common/nlohmann/json.hpp"
20 #include "../utils/run-in.hpp"
23 static void run_trigger(const struct cond_trigger
*trigger
)
25 switch (trigger
->func_type
) {
26 case COND_TRIGGER_FUNC_TYPE_BASIC
:
27 trigger
->func
.basic();
29 case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT
:
30 runInCompClsInit(trigger
->func
.run_in_comp_cls_init
);
37 static void list_triggers(const struct cond_trigger triggers
[], size_t trigger_count
)
39 nlohmann::json trigger_array
= nlohmann::json::array();
41 for (size_t i
= 0; i
< trigger_count
; i
++) {
42 nlohmann::json trigger_obj
= nlohmann::json::object();
43 const cond_trigger
& trigger
= triggers
[i
];
46 trigger_obj
["cond-id"] = trigger
.cond_id
;
48 /* Name starts with condition ID */
49 std::string name
= trigger
.cond_id
;
53 name
+= trigger
.suffix
;
56 trigger_obj
["name"] = std::move(name
);
57 trigger_array
.push_back(std::move(trigger_obj
));
60 auto str
= trigger_array
.dump();
62 std::flush(std::cout
);
65 void cond_main(int argc
, const char *argv
[], const struct cond_trigger triggers
[],
70 if (strcmp(argv
[1], "list") == 0) {
71 list_triggers(triggers
, trigger_count
);
72 } else if (strcmp(argv
[1], "run") == 0) {
76 index
= atoi(argv
[2]);
77 BT_ASSERT(index
>= 0 && index
< trigger_count
);
78 run_trigger(&triggers
[index
]);