| 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 | #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: |
| 62 | return "UNKNOWN"; |
| 63 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT: |
| 64 | return "COMPONENT"; |
| 65 | case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS: |
| 66 | return "COMPONENT_CLASS"; |
| 67 | case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR: |
| 68 | return "MESSAGE_ITERATOR"; |
| 69 | default: |
| 70 | return "(unknown)"; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | struct bt_error *bt_error_create(void); |
| 75 | |
| 76 | void bt_error_destroy(struct bt_error *error); |
| 77 | |
| 78 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
| 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 | |
| 83 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
| 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 | |
| 89 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
| 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 | |
| 96 | __BT_ATTR_FORMAT_PRINTF(5, 0) |
| 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 */ |