Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / error.h
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 BT_HIDDEN
75 struct bt_error *bt_error_create(void);
76
77 BT_HIDDEN
78 void bt_error_destroy(struct bt_error *error);
79
80 BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
81 int bt_error_append_cause_from_unknown(struct bt_error *error,
82 const char *module_name, const char *file_name,
83 uint64_t line_no, const char *msg_fmt, va_list args);
84
85 BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
86 int bt_error_append_cause_from_component(
87 struct bt_error *error, bt_self_component *self_comp,
88 const char *file_name, uint64_t line_no,
89 const char *msg_fmt, va_list args);
90
91 BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
92 int bt_error_append_cause_from_component_class(
93 struct bt_error *error,
94 bt_self_component_class *self_comp_class,
95 const char *file_name, uint64_t line_no,
96 const char *msg_fmt, va_list args);
97
98 BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
99 int bt_error_append_cause_from_message_iterator(
100 struct bt_error *error, bt_self_message_iterator *self_iter,
101 const char *file_name, uint64_t line_no,
102 const char *msg_fmt, va_list args);
103
104 #endif /* BABELTRACE_ERROR_INTERNAL_H */
This page took 0.030552 seconds and 4 git commands to generate.