cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / error.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef BABELTRACE_ERROR_INTERNAL_H
8 #define BABELTRACE_ERROR_INTERNAL_H
9
10 #include <stdarg.h>
11 #include <glib.h>
12 #include <babeltrace2/babeltrace.h>
13
14 struct bt_error_cause {
15 enum bt_error_cause_actor_type actor_type;
16 GString *module_name;
17 GString *message;
18 GString *file_name;
19 uint64_t line_no;
20 };
21
22 struct bt_error_cause_component_class_id {
23 GString *name;
24 bt_component_class_type type;
25 GString *plugin_name;
26 };
27
28 struct bt_error_cause_component_actor {
29 struct bt_error_cause base;
30 GString *comp_name;
31 struct bt_error_cause_component_class_id comp_class_id;
32 };
33
34 struct bt_error_cause_component_class_actor {
35 struct bt_error_cause base;
36 struct bt_error_cause_component_class_id comp_class_id;
37 };
38
39 struct bt_error_cause_message_iterator_actor {
40 struct bt_error_cause base;
41 GString *comp_name;
42 GString *output_port_name;
43 struct bt_error_cause_component_class_id comp_class_id;
44 };
45
46 struct bt_error {
47 /*
48 * Array of `struct bt_error_cause *` (or an extension); owned
49 * by this.
50 */
51 GPtrArray *causes;
52 };
53
54 static inline
55 const char *bt_error_cause_actor_type_string(
56 enum bt_error_cause_actor_type actor_type)
57 {
58 switch (actor_type) {
59 case BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN:
60 return "UNKNOWN";
61 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT:
62 return "COMPONENT";
63 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS:
64 return "COMPONENT_CLASS";
65 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR:
66 return "MESSAGE_ITERATOR";
67 default:
68 return "(unknown)";
69 }
70 };
71
72 struct bt_error *bt_error_create(void);
73
74 void bt_error_destroy(struct bt_error *error);
75
76 __BT_ATTR_FORMAT_PRINTF(5, 0)
77 int bt_error_append_cause_from_unknown(struct bt_error *error,
78 const char *module_name, const char *file_name,
79 uint64_t line_no, const char *msg_fmt, va_list args);
80
81 __BT_ATTR_FORMAT_PRINTF(5, 0)
82 int bt_error_append_cause_from_component(
83 struct bt_error *error, bt_self_component *self_comp,
84 const char *file_name, uint64_t line_no,
85 const char *msg_fmt, va_list args);
86
87 __BT_ATTR_FORMAT_PRINTF(5, 0)
88 int bt_error_append_cause_from_component_class(
89 struct bt_error *error,
90 bt_self_component_class *self_comp_class,
91 const char *file_name, uint64_t line_no,
92 const char *msg_fmt, va_list args);
93
94 __BT_ATTR_FORMAT_PRINTF(5, 0)
95 int bt_error_append_cause_from_message_iterator(
96 struct bt_error *error, bt_self_message_iterator *self_iter,
97 const char *file_name, uint64_t line_no,
98 const char *msg_fmt, va_list args);
99
100 #endif /* BABELTRACE_ERROR_INTERNAL_H */
This page took 0.031751 seconds and 5 git commands to generate.