2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
11 #include <babeltrace2/babeltrace.h>
15 #include "common/assert.h"
16 #include "cpp-common/nlohmann/json.hpp"
18 #include "../utils/run-in.hpp"
20 static void run_trigger(const struct cond_trigger
*trigger
)
22 switch (trigger
->func_type
) {
23 case COND_TRIGGER_FUNC_TYPE_BASIC
:
24 trigger
->func
.basic();
26 case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT
:
27 runInCompClsInit(trigger
->func
.run_in_comp_cls_init
);
34 static void list_triggers(const struct cond_trigger triggers
[], size_t trigger_count
)
36 nlohmann::json trigger_array
= nlohmann::json::array();
38 for (size_t i
= 0; i
< trigger_count
; i
++) {
39 nlohmann::json trigger_obj
= nlohmann::json::object();
40 const cond_trigger
& trigger
= triggers
[i
];
43 trigger_obj
["cond-id"] = trigger
.cond_id
;
45 /* Name starts with condition ID */
46 std::string name
= trigger
.cond_id
;
50 name
+= trigger
.suffix
;
53 trigger_obj
["name"] = std::move(name
);
54 trigger_array
.push_back(std::move(trigger_obj
));
57 auto str
= trigger_array
.dump();
59 std::flush(std::cout
);
62 void cond_main(int argc
, const char *argv
[], const struct cond_trigger triggers
[],
67 if (strcmp(argv
[1], "list") == 0) {
68 list_triggers(triggers
, trigger_count
);
69 } else if (strcmp(argv
[1], "run") == 0) {
73 index
= atoi(argv
[2]);
74 BT_ASSERT(index
>= 0 && index
< trigger_count
);
75 run_trigger(&triggers
[index
]);