Packet API: use status
[babeltrace.git] / include / babeltrace / trace-ir / field-class-internal.h
CommitLineData
5cd6d0e5
PP
1#ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
2#define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H
3
4/*
e2f7325d 5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5cd6d0e5
PP
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
5cd6d0e5
PP
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
27#include <babeltrace/assert-pre-internal.h>
28#include <babeltrace/trace-ir/clock-class.h>
c6bd8523 29#include <babeltrace/trace-ir/field-class.h>
5cd6d0e5
PP
30#include <babeltrace/babeltrace-internal.h>
31#include <babeltrace/object-internal.h>
32#include <babeltrace/types.h>
33#include <stdint.h>
34#include <glib.h>
35
36#define BT_ASSERT_PRE_FC_IS_INT(_fc, _name) \
37 BT_ASSERT_PRE( \
40f4ba76
PP
38 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
39 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || \
40 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
41 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
5cd6d0e5
PP
42 _name " is not an integer field class: %![fc-]+F", (_fc))
43
44#define BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(_fc, _name) \
45 BT_ASSERT_PRE( \
40f4ba76
PP
46 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || \
47 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, \
5cd6d0e5
PP
48 _name " is not an unsigned integer field class: %![fc-]+F", (_fc))
49
50#define BT_ASSERT_PRE_FC_IS_ENUM(_fc, _name) \
51 BT_ASSERT_PRE( \
40f4ba76
PP
52 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION || \
53 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, \
5cd6d0e5
PP
54 _name " is not an enumeration field class: %![fc-]+F", (_fc))
55
56#define BT_ASSERT_PRE_FC_IS_ARRAY(_fc, _name) \
57 BT_ASSERT_PRE( \
40f4ba76
PP
58 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY || \
59 ((const struct bt_field_class *) (_fc))->type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, \
5cd6d0e5
PP
60 _name " is not an array field class: %![fc-]+F", (_fc))
61
864cad70 62#define BT_ASSERT_PRE_FC_HAS_ID(_fc, _type, _name) \
40f4ba76 63 BT_ASSERT_PRE(((const struct bt_field_class *) (_fc))->type == (_type), \
864cad70
PP
64 _name " has the wrong type: expected-type=%s, " \
65 "%![fc-]+F", bt_common_field_class_type_string(_type), (_fc))
5cd6d0e5
PP
66
67#define BT_ASSERT_PRE_FC_HOT(_fc, _name) \
40f4ba76 68 BT_ASSERT_PRE_HOT((const struct bt_field_class *) (_fc), \
5cd6d0e5
PP
69 (_name), ": %!+F", (_fc))
70
71#define BT_FIELD_CLASS_NAMED_FC_AT_INDEX(_fc, _index) \
72 (&g_array_index(((struct bt_field_class_named_field_class_container *) (_fc))->named_fcs, \
73 struct bt_named_field_class, (_index)))
74
75#define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
76 (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
77 struct bt_field_class_enumeration_mapping, (_index)))
78
79#define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
80 (&g_array_index((_mapping)->ranges, \
81 struct bt_field_class_enumeration_mapping_range, (_index)))
82
83struct bt_field;
84struct bt_field_class;
85
86struct bt_field_class {
87 struct bt_object base;
864cad70 88 enum bt_field_class_type type;
5cd6d0e5
PP
89 bool frozen;
90
91 /*
92 * Only used in developer mode, this flag indicates whether or
862ca4ed 93 * not this field class is part of a trace class.
5cd6d0e5 94 */
862ca4ed 95 bool part_of_trace_class;
5cd6d0e5
PP
96};
97
98struct bt_field_class_integer {
99 struct bt_field_class common;
100
101 /*
102 * Value range of fields built from this integer field class:
103 * this is an equivalent integer size in bits. More formally,
104 * `range` is `n` in:
105 *
106 * Unsigned range: [0, 2^n - 1]
107 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
108 */
109 uint64_t range;
110
111 enum bt_field_class_integer_preferred_display_base base;
112};
113
114struct bt_field_class_enumeration_mapping_range {
115 union {
116 uint64_t u;
117 int64_t i;
118 } lower;
119
120 union {
121 uint64_t u;
122 int64_t i;
123 } upper;
124};
125
126struct bt_field_class_enumeration_mapping {
127 GString *label;
128
129 /* Array of `struct bt_field_class_enumeration_mapping_range` */
130 GArray *ranges;
131};
132
133struct bt_field_class_enumeration {
134 struct bt_field_class_integer common;
135
136 /* Array of `struct bt_field_class_enumeration_mapping *` */
137 GArray *mappings;
138
139 /*
140 * This is an array of `const char *` which acts as a temporary
141 * (potentially growing) buffer for
142 * bt_field_class_unsigned_enumeration_get_mapping_labels_by_value()
143 * and
144 * bt_field_class_signed_enumeration_get_mapping_labels_by_value().
145 *
146 * The actual strings are owned by the mappings above.
147 */
148 GPtrArray *label_buf;
149};
150
151struct bt_field_class_real {
152 struct bt_field_class common;
153 bool is_single_precision;
154};
155
156struct bt_field_class_string {
157 struct bt_field_class common;
158};
159
160/* A named field class is a (name, field class) pair */
161struct bt_named_field_class {
162 GString *name;
163
164 /* Owned by this */
165 struct bt_field_class *fc;
166};
167
168/*
169 * This is the base field class for a container of named field classes.
170 * Structure and variant field classes inherit this.
171 */
172struct bt_field_class_named_field_class_container {
173 struct bt_field_class common;
174
175 /*
176 * Key: `const char *`, not owned by this (owned by named field
177 * type objects contained in `named_fcs` below).
178 */
179 GHashTable *name_to_index;
180
181 /* Array of `struct bt_named_field_class` */
182 GArray *named_fcs;
183};
184
185struct bt_field_class_structure {
186 struct bt_field_class_named_field_class_container common;
187};
188
189struct bt_field_class_array {
190 struct bt_field_class common;
191
192 /* Owned by this */
193 struct bt_field_class *element_fc;
194};
195
196struct bt_field_class_static_array {
197 struct bt_field_class_array common;
198 uint64_t length;
199};
200
201struct bt_field_class_dynamic_array {
202 struct bt_field_class_array common;
203
204 /* Weak: never dereferenced, only use to find it elsewhere */
205 struct bt_field_class *length_fc;
206
207 /* Owned by this */
208 struct bt_field_path *length_field_path;
209};
210
211struct bt_field_class_variant {
212 struct bt_field_class_named_field_class_container common;
213
214 /* Weak: never dereferenced, only use to find it elsewhere */
215 struct bt_field_class *selector_fc;
216
217 /* Owned by this */
218 struct bt_field_path *selector_field_path;
219};
220
221static inline
40f4ba76 222bool bt_field_class_has_known_type(const struct bt_field_class *fc)
5cd6d0e5 223{
864cad70
PP
224 return fc->type >= BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER &&
225 fc->type <= BT_FIELD_CLASS_TYPE_VARIANT;
5cd6d0e5
PP
226}
227
228BT_HIDDEN
40f4ba76 229void _bt_field_class_freeze(const struct bt_field_class *field_class);
5cd6d0e5
PP
230
231#ifdef BT_DEV_MODE
232# define bt_field_class_freeze _bt_field_class_freeze
233#else
234# define bt_field_class_freeze(_fc)
235#endif
236
237/*
238 * This function recursively marks `field_class` and its children as
239 * being part of a trace. This is used to validate that all field classes
240 * are used at a single location within trace objects even if they are
241 * shared objects for other purposes.
242 */
243BT_HIDDEN
862ca4ed
PP
244void _bt_field_class_make_part_of_trace_class(
245 const struct bt_field_class *field_class);
5cd6d0e5
PP
246
247#ifdef BT_DEV_MODE
862ca4ed 248# define bt_field_class_make_part_of_trace_class _bt_field_class_make_part_of_trace_class
5cd6d0e5 249#else
862ca4ed 250# define bt_field_class_make_part_of_trace_class(_fc) ((void) _fc)
5cd6d0e5
PP
251#endif
252
253#endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */
This page took 0.035657 seconds and 4 git commands to generate.