Commit | Line | Data |
---|---|---|
c0e90f23 PP |
1 | #ifndef BABELTRACE_ERROR_INTERNAL_H |
2 | #define BABELTRACE_ERROR_INTERNAL_H | |
3 | ||
4 | /* | |
5 | * Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com> | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
24 | */ | |
25 | ||
26 | #include <stdarg.h> | |
27 | #include <glib.h> | |
9df34b44 | 28 | #include <babeltrace2/babeltrace.h> |
c0e90f23 PP |
29 | #include "lib/object.h" |
30 | #include "common/macros.h" | |
31 | ||
32 | struct bt_error_cause { | |
33 | enum bt_error_cause_actor_type actor_type; | |
34 | GString *module_name; | |
35 | GString *message; | |
36 | GString *file_name; | |
37 | uint64_t line_no; | |
38 | }; | |
39 | ||
40 | struct bt_error_cause_component_class_id { | |
41 | GString *name; | |
42 | bt_component_class_type type; | |
43 | GString *plugin_name; | |
44 | }; | |
45 | ||
46 | struct bt_error_cause_component_actor { | |
47 | struct bt_error_cause base; | |
48 | GString *comp_name; | |
49 | struct bt_error_cause_component_class_id comp_class_id; | |
50 | }; | |
51 | ||
52 | struct bt_error_cause_component_class_actor { | |
53 | struct bt_error_cause base; | |
54 | struct bt_error_cause_component_class_id comp_class_id; | |
55 | }; | |
56 | ||
57 | struct bt_error_cause_message_iterator_actor { | |
58 | struct bt_error_cause base; | |
59 | GString *comp_name; | |
60 | GString *output_port_name; | |
61 | struct bt_error_cause_component_class_id comp_class_id; | |
62 | }; | |
63 | ||
64 | struct bt_error { | |
65 | /* | |
66 | * Array of `struct bt_error_cause *` (or an extension); owned | |
67 | * by this. | |
68 | */ | |
69 | GPtrArray *causes; | |
70 | }; | |
71 | ||
72 | static inline | |
73 | const char *bt_error_cause_actor_type_string( | |
74 | enum bt_error_cause_actor_type actor_type) | |
75 | { | |
76 | switch (actor_type) { | |
77 | case BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN: | |
e05f8464 | 78 | return "UNKNOWN"; |
c0e90f23 | 79 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: |
e05f8464 | 80 | return "COMPONENT"; |
c0e90f23 | 81 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: |
e05f8464 | 82 | return "COMPONENT_CLASS"; |
c0e90f23 | 83 | case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: |
e05f8464 | 84 | return "MESSAGE_ITERATOR"; |
c0e90f23 PP |
85 | default: |
86 | return "(unknown)"; | |
87 | } | |
88 | }; | |
89 | ||
90 | BT_HIDDEN | |
91 | struct bt_error *bt_error_create(void); | |
92 | ||
93 | BT_HIDDEN | |
94 | void bt_error_destroy(struct bt_error *error); | |
95 | ||
96 | BT_HIDDEN | |
97 | int bt_error_append_cause_from_unknown(struct bt_error *error, | |
98 | const char *module_name, const char *file_name, | |
99 | uint64_t line_no, const char *msg_fmt, va_list args); | |
100 | ||
101 | BT_HIDDEN | |
102 | int bt_error_append_cause_from_component( | |
103 | struct bt_error *error, bt_self_component *self_comp, | |
104 | const char *file_name, uint64_t line_no, | |
105 | const char *msg_fmt, va_list args); | |
106 | ||
107 | BT_HIDDEN | |
108 | int bt_error_append_cause_from_component_class( | |
109 | struct bt_error *error, | |
110 | bt_self_component_class *self_comp_class, | |
111 | const char *file_name, uint64_t line_no, | |
112 | const char *msg_fmt, va_list args); | |
113 | ||
114 | BT_HIDDEN | |
115 | int bt_error_append_cause_from_message_iterator( | |
116 | struct bt_error *error, bt_self_message_iterator *self_iter, | |
117 | const char *file_name, uint64_t line_no, | |
118 | const char *msg_fmt, va_list args); | |
119 | ||
120 | #endif /* BABELTRACE_ERROR_INTERNAL_H */ |