configure: enable -Wsuggest-attribute=format
[babeltrace.git] / src / lib / error.h
CommitLineData
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>
4fa90f32 28#include <babeltrace2/babeltrace.h>
553c4bab
PP
29#include "lib/object.h"
30#include "common/macros.h"
31
32struct 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
40struct bt_error_cause_component_class_id {
41 GString *name;
42 bt_component_class_type type;
43 GString *plugin_name;
44};
45
46struct 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
52struct 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
57struct 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
64struct bt_error {
65 /*
66 * Array of `struct bt_error_cause *` (or an extension); owned
67 * by this.
68 */
69 GPtrArray *causes;
70};
71
72static inline
73const 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:
8a432889 78 return "UNKNOWN";
553c4bab 79 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT:
8a432889 80 return "COMPONENT";
553c4bab 81 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS:
8a432889 82 return "COMPONENT_CLASS";
553c4bab 83 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR:
8a432889 84 return "MESSAGE_ITERATOR";
553c4bab
PP
85 default:
86 return "(unknown)";
87 }
88};
89
90BT_HIDDEN
91struct bt_error *bt_error_create(void);
92
93BT_HIDDEN
94void bt_error_destroy(struct bt_error *error);
95
8b305066 96BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
553c4bab
PP
97int 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
8b305066 101BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
553c4bab
PP
102int 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
8b305066 107BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
553c4bab
PP
108int 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
8b305066 114BT_HIDDEN __BT_ATTR_FORMAT_PRINTF(5, 0)
553c4bab
PP
115int 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 */
This page took 0.047014 seconds and 4 git commands to generate.