Remove some unused includes in C++ files
[babeltrace.git] / tests / lib / conds / utils.cpp
CommitLineData
5d7e8359
PP
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com>
5 */
6
c802cacb
SM
7#include <iostream>
8
c802cacb 9#include <glib.h>
5d7e8359 10#include <stdio.h>
c802cacb 11#include <stdlib.h>
5d7e8359 12#include <string.h>
c802cacb 13
5d7e8359 14#include <babeltrace2/babeltrace.h>
5d7e8359
PP
15
16#include "common/assert.h"
4b4f3ca6 17#include "cpp-common/nlohmann/json.hpp"
c802cacb 18
366250bb 19#include "../utils/run-in.hpp"
c802cacb 20#include "utils.hpp"
5d7e8359 21
486428e8 22static void run_trigger(const struct cond_trigger *trigger)
5d7e8359 23{
486428e8
SM
24 switch (trigger->func_type) {
25 case COND_TRIGGER_FUNC_TYPE_BASIC:
26 trigger->func.basic();
27 break;
28 case COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT:
366250bb 29 runInCompClsInit(trigger->func.run_in_comp_cls_init);
486428e8
SM
30 break;
31 default:
32 abort();
33 }
5d7e8359
PP
34}
35
486428e8 36static void list_triggers(const struct cond_trigger triggers[], size_t trigger_count)
5d7e8359 37{
4b4f3ca6 38 nlohmann::json trigger_array = nlohmann::json::array();
5d7e8359 39
4b4f3ca6
SM
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];
5d7e8359 43
486428e8 44 /* Condition ID */
4b4f3ca6 45 trigger_obj["cond-id"] = trigger.cond_id;
5d7e8359 46
486428e8 47 /* Name starts with condition ID */
4b4f3ca6 48 std::string name = trigger.cond_id;
5d7e8359 49
4b4f3ca6
SM
50 if (trigger.suffix) {
51 name += '-';
52 name += trigger.suffix;
486428e8 53 }
5d7e8359 54
4b4f3ca6
SM
55 trigger_obj["name"] = std::move(name);
56 trigger_array.push_back(std::move(trigger_obj));
486428e8 57 }
5d7e8359 58
4b4f3ca6
SM
59 auto str = trigger_array.dump();
60 std::cout << str;
61 std::flush(std::cout);
5d7e8359
PP
62}
63
486428e8
SM
64void cond_main(int argc, const char *argv[], const struct cond_trigger triggers[],
65 size_t trigger_count)
5d7e8359 66{
486428e8
SM
67 BT_ASSERT(argc >= 2);
68
69 if (strcmp(argv[1], "list") == 0) {
70 list_triggers(triggers, trigger_count);
71 } else if (strcmp(argv[1], "run") == 0) {
72 int index;
73
74 BT_ASSERT(argc >= 3);
75 index = atoi(argv[2]);
76 BT_ASSERT(index >= 0 && index < trigger_count);
77 run_trigger(&triggers[index]);
78 }
5d7e8359 79}
This page took 0.038529 seconds and 4 git commands to generate.