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 | #include "lib/object.h" |
14 | #include "common/macros.h" | |
15 | ||
16 | struct bt_error_cause { | |
17 | enum bt_error_cause_actor_type actor_type; | |
18 | GString *module_name; | |
19 | GString *message; | |
20 | GString *file_name; | |
21 | uint64_t line_no; | |
22 | }; | |
23 | ||
24 | struct bt_error_cause_component_class_id { | |
25 | GString *name; | |
26 | bt_component_class_type type; | |
27 | GString *plugin_name; | |
28 | }; | |
29 | ||
30 | struct bt_error_cause_component_actor { | |
31 | struct bt_error_cause base; | |
32 | GString *comp_name; | |
33 | struct bt_error_cause_component_class_id comp_class_id; | |
34 | }; | |
35 | ||
36 | struct bt_error_cause_component_class_actor { | |
37 | struct bt_error_cause base; | |
38 | struct bt_error_cause_component_class_id comp_class_id; | |
39 | }; | |
40 | ||
41 | struct bt_error_cause_message_iterator_actor { | |
42 | struct bt_error_cause base; | |
43 | GString *comp_name; | |
44 | GString *output_port_name; | |
45 | struct bt_error_cause_component_class_id comp_class_id; | |
46 | }; | |
47 | ||
48 | struct bt_error { | |
49 | /* | |
50 | * Array of `struct bt_error_cause *` (or an extension); owned | |
51 | * by this. | |
52 | */ | |
53 | GPtrArray *causes; | |
54 | }; | |
55 | ||
56 | static inline | |
57 | const char *bt_error_cause_actor_type_string( | |
58 | enum bt_error_cause_actor_type actor_type) | |
59 | { | |
60 | switch (actor_type) { | |
61 | case BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN: | |
8a432889 | 62 | return "UNKNOWN"; |
553c4bab | 63 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: |
8a432889 | 64 | return "COMPONENT"; |
553c4bab | 65 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: |
8a432889 | 66 | return "COMPONENT_CLASS"; |
553c4bab | 67 | case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: |
8a432889 | 68 | return "MESSAGE_ITERATOR"; |
553c4bab PP |
69 | default: |
70 | return "(unknown)"; | |
71 | } | |
72 | }; | |
73 | ||
553c4bab PP |
74 | struct bt_error *bt_error_create(void); |
75 | ||
553c4bab PP |
76 | void bt_error_destroy(struct bt_error *error); |
77 | ||
1353b066 | 78 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
79 | int bt_error_append_cause_from_unknown(struct bt_error *error, |
80 | const char *module_name, const char *file_name, | |
81 | uint64_t line_no, const char *msg_fmt, va_list args); | |
82 | ||
1353b066 | 83 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
84 | int bt_error_append_cause_from_component( |
85 | struct bt_error *error, bt_self_component *self_comp, | |
86 | const char *file_name, uint64_t line_no, | |
87 | const char *msg_fmt, va_list args); | |
88 | ||
1353b066 | 89 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
90 | int bt_error_append_cause_from_component_class( |
91 | struct bt_error *error, | |
92 | bt_self_component_class *self_comp_class, | |
93 | const char *file_name, uint64_t line_no, | |
94 | const char *msg_fmt, va_list args); | |
95 | ||
1353b066 | 96 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
553c4bab PP |
97 | int bt_error_append_cause_from_message_iterator( |
98 | struct bt_error *error, bt_self_message_iterator *self_iter, | |
99 | const char *file_name, uint64_t line_no, | |
100 | const char *msg_fmt, va_list args); | |
101 | ||
102 | #endif /* BABELTRACE_ERROR_INTERNAL_H */ |