Commit | Line | Data |
---|---|---|
553c4bab | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
553c4bab | 3 | * |
0235b0db | 4 | * Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com> |
553c4bab PP |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef BABELTRACE_ERROR_INTERNAL_H |
8 | #define BABELTRACE_ERROR_INTERNAL_H | |
9 | ||
553c4bab PP |
10 | #include <stdarg.h> |
11 | #include <glib.h> | |
4fa90f32 | 12 | #include <babeltrace2/babeltrace.h> |
553c4bab PP |
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: | |
8a432889 | 60 | return "UNKNOWN"; |
553c4bab | 61 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: |
8a432889 | 62 | return "COMPONENT"; |
553c4bab | 63 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: |
8a432889 | 64 | return "COMPONENT_CLASS"; |
553c4bab | 65 | case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: |
8a432889 | 66 | return "MESSAGE_ITERATOR"; |
553c4bab PP |
67 | default: |
68 | return "(unknown)"; | |
69 | } | |
70 | }; | |
71 | ||
553c4bab PP |
72 | struct bt_error *bt_error_create(void); |
73 | ||
553c4bab PP |
74 | void bt_error_destroy(struct bt_error *error); |
75 | ||
1353b066 | 76 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
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 | ||
1353b066 | 81 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
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 | ||
1353b066 | 87 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
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 | ||
1353b066 | 94 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
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 */ |