Commit | Line | Data |
---|---|---|
553c4bab 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> | |
28 | #include <babeltrace2/error-const.h> | |
29 | #include <babeltrace2/error-cause-const.h> | |
30 | #include "lib/object.h" | |
31 | #include "common/macros.h" | |
32 | ||
33 | struct bt_error_cause { | |
34 | enum bt_error_cause_actor_type actor_type; | |
35 | GString *module_name; | |
36 | GString *message; | |
37 | GString *file_name; | |
38 | uint64_t line_no; | |
39 | }; | |
40 | ||
41 | struct bt_error_cause_component_class_id { | |
42 | GString *name; | |
43 | bt_component_class_type type; | |
44 | GString *plugin_name; | |
45 | }; | |
46 | ||
47 | struct bt_error_cause_component_actor { | |
48 | struct bt_error_cause base; | |
49 | GString *comp_name; | |
50 | struct bt_error_cause_component_class_id comp_class_id; | |
51 | }; | |
52 | ||
53 | struct bt_error_cause_component_class_actor { | |
54 | struct bt_error_cause base; | |
55 | struct bt_error_cause_component_class_id comp_class_id; | |
56 | }; | |
57 | ||
58 | struct bt_error_cause_message_iterator_actor { | |
59 | struct bt_error_cause base; | |
60 | GString *comp_name; | |
61 | GString *output_port_name; | |
62 | struct bt_error_cause_component_class_id comp_class_id; | |
63 | }; | |
64 | ||
65 | struct bt_error { | |
66 | /* | |
67 | * Array of `struct bt_error_cause *` (or an extension); owned | |
68 | * by this. | |
69 | */ | |
70 | GPtrArray *causes; | |
71 | }; | |
72 | ||
73 | static inline | |
74 | const char *bt_error_cause_actor_type_string( | |
75 | enum bt_error_cause_actor_type actor_type) | |
76 | { | |
77 | switch (actor_type) { | |
78 | case BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN: | |
79 | return "BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN"; | |
80 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: | |
81 | return "BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT"; | |
82 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: | |
83 | return "BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS"; | |
84 | case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: | |
85 | return "BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR"; | |
86 | default: | |
87 | return "(unknown)"; | |
88 | } | |
89 | }; | |
90 | ||
91 | BT_HIDDEN | |
92 | struct bt_error *bt_error_create(void); | |
93 | ||
94 | BT_HIDDEN | |
95 | void bt_error_destroy(struct bt_error *error); | |
96 | ||
97 | BT_HIDDEN | |
98 | int bt_error_append_cause_from_unknown(struct bt_error *error, | |
99 | const char *module_name, const char *file_name, | |
100 | uint64_t line_no, const char *msg_fmt, va_list args); | |
101 | ||
102 | BT_HIDDEN | |
103 | int bt_error_append_cause_from_component( | |
104 | struct bt_error *error, bt_self_component *self_comp, | |
105 | const char *file_name, uint64_t line_no, | |
106 | const char *msg_fmt, va_list args); | |
107 | ||
108 | BT_HIDDEN | |
109 | int bt_error_append_cause_from_component_class( | |
110 | struct bt_error *error, | |
111 | bt_self_component_class *self_comp_class, | |
112 | const char *file_name, uint64_t line_no, | |
113 | const char *msg_fmt, va_list args); | |
114 | ||
115 | BT_HIDDEN | |
116 | int bt_error_append_cause_from_message_iterator( | |
117 | struct bt_error *error, bt_self_message_iterator *self_iter, | |
118 | const char *file_name, uint64_t line_no, | |
119 | const char *msg_fmt, va_list args); | |
120 | ||
121 | #endif /* BABELTRACE_ERROR_INTERNAL_H */ |