.gitignore: add some missing files
[babeltrace.git] / src / lib / trace-ir / field-class.h
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8#ifndef BABELTRACE_LIB_TRACE_IR_FIELD_CLASS_H
9#define BABELTRACE_LIB_TRACE_IR_FIELD_CLASS_H
10
11#include <babeltrace2/trace-ir/clock-class.h>
12#include <babeltrace2/trace-ir/field-class.h>
13#include "common/macros.h"
14#include "lib/object.h"
15#include <babeltrace2/types.h>
16#include <stdbool.h>
17#include <stdint.h>
18#include <glib.h>
19
20#define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \
21 (&bt_g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \
22 struct bt_field_class_enumeration_mapping, (_index)))
23
24#define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \
25 (&bt_g_array_index((_mapping)->ranges, \
26 struct bt_field_class_enumeration_mapping_range, (_index)))
27
28enum field_xref_kind {
29 /*
30 * Start at 1 to be able to differentiate a zero-initialized field from
31 * an initialized field.
32 */
33 FIELD_XREF_KIND_PATH = 1,
34 FIELD_XREF_KIND_LOCATION,
35};
36
37struct bt_field_class {
38 struct bt_object base;
39 enum bt_field_class_type type;
40 bool frozen;
41
42 /* Owned by this */
43 struct bt_value *user_attributes;
44
45 /*
46 * This flag indicates whether or not this field class is part
47 * of a trace class.
48 */
49 bool part_of_trace_class;
50
51 /* Effective MIP version for this field class */
52 uint64_t mip_version;
53};
54
55struct bt_field_class_bool {
56 struct bt_field_class common;
57};
58
59struct bt_field_class_bit_array_flag {
60 /* Owned by this */
61 gchar *label;
62
63 /* Strong reference */
64 const bt_integer_range_set_unsigned *range_set;
65
66 /*
67 * Mask to apply to the field's value to determine if this flag is
68 * active.
69 */
70 uint64_t mask;
71};
72
73struct bt_field_class_bit_array {
74 struct bt_field_class common;
75 uint64_t length;
76
77 /* Array of `bt_field_class_bit_array_flag`, owned by this */
78 GPtrArray *flags;
79
80 /*
81 * This is an array of `const char *` which acts as a temporary
82 * (potentially growing) buffer for
83 * bt_field_class_bit_array_get_active_flag_labels_for_value_as_integer().
84 *
85 * The actual strings are owned by the flags above.
86 */
87 GPtrArray *label_buf;
88};
89
90struct bt_field_class_integer {
91 struct bt_field_class common;
92
93 /*
94 * Value range of fields built from this integer field class:
95 * this is an equivalent integer size in bits. More formally,
96 * `range` is `n` in:
97 *
98 * Unsigned range: [0, 2^n - 1]
99 * Signed range: [-2^(n - 1), 2^(n - 1) - 1]
100 */
101 uint64_t range;
102
103 enum bt_field_class_integer_preferred_display_base base;
104};
105
106struct bt_field_class_enumeration_mapping {
107 GString *label;
108
109 /* Owner by this */
110 const struct bt_integer_range_set *range_set;
111};
112
113struct bt_field_class_enumeration_unsigned_mapping;
114struct bt_field_class_enumeration_signed_mapping;
115
116struct bt_field_class_enumeration {
117 struct bt_field_class_integer common;
118
119 /* Array of `struct bt_field_class_enumeration_mapping *` */
120 GArray *mappings;
121
122 /*
123 * This is an array of `const char *` which acts as a temporary
124 * (potentially growing) buffer for
125 * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value()
126 * and
127 * bt_field_class_enumeration_signed_get_mapping_labels_for_value().
128 *
129 * The actual strings are owned by the mappings above.
130 */
131 GPtrArray *label_buf;
132};
133
134struct bt_field_class_real {
135 struct bt_field_class common;
136};
137
138struct bt_field_class_string {
139 struct bt_field_class common;
140};
141
142/* A named field class is a (name, field class) pair */
143struct bt_named_field_class {
144 /* MIP > 0: `NULL` if not set */
145 GString *name;
146
147 /* Owned by this */
148 struct bt_value *user_attributes;
149
150 /* Owned by this */
151 struct bt_field_class *fc;
152
153 bool frozen;
154};
155
156struct bt_field_class_structure_member;
157struct bt_field_class_variant_option;
158struct bt_field_class_variant_with_selector_field_integer_unsigned_option;
159struct bt_field_class_variant_with_selector_field_integer_signed_option;
160
161struct bt_field_class_named_field_class_container {
162 struct bt_field_class common;
163
164 /*
165 * Key: `const char *`, not owned by this (owned by named field
166 * class objects contained in `named_fcs` below).
167 *
168 * MIP > 0: the size of this hash table may be less than the
169 * size of `named_fcs` below because, for a variant field class,
170 * its option names are optional.
171 */
172 GHashTable *name_to_index;
173
174 /* Array of `struct bt_named_field_class *` */
175 GPtrArray *named_fcs;
176};
177
178struct bt_field_class_structure {
179 struct bt_field_class_named_field_class_container common;
180};
181
182struct bt_field_class_array {
183 struct bt_field_class common;
184
185 /* Owned by this */
186 struct bt_field_class *element_fc;
187};
188
189struct bt_field_class_array_static {
190 struct bt_field_class_array common;
191 uint64_t length;
192};
193
194struct bt_field_class_array_dynamic {
195 struct bt_field_class_array common;
196
197 /* Used with BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD */
198 struct {
199 enum field_xref_kind xref_kind;
200
201 union {
202 /* Used with FIELD_XREF_KIND_PATH */
203 struct {
204 /* Owned by this */
205 struct bt_field_class *class;
206
207 /* Owned by this */
208 struct bt_field_path *path;
209 } path;
210
211 /* Used with FIELD_XREF_KIND_LOCATION, owned by this */
212 const struct bt_field_location *location;
213 };
214 } length_field;
215};
216
217struct bt_field_class_option {
218 struct bt_field_class common;
219
220 /* Owned by this */
221 struct bt_field_class *content_fc;
222};
223
224struct bt_field_class_option_with_selector_field {
225 struct bt_field_class_option common;
226
227 enum field_xref_kind selector_field_xref_kind;
228
229 union {
230 /* Used with FIELD_XREF_KIND_PATH */
231 struct {
232 /* Owned by this */
233 struct bt_field_class *class;
234
235 /* Owned by this */
236 struct bt_field_path *path;
237 } path;
238
239 /* Used with FIELD_XREF_KIND_LOCATION, owned by this */
240 const struct bt_field_location *location;
241 } selector_field;
242};
243
244struct bt_field_class_option_with_selector_field_bool {
245 struct bt_field_class_option_with_selector_field common;
246
247 /* Owned by this */
248 bool sel_is_reversed;
249};
250
251struct bt_field_class_option_with_selector_field_integer {
252 struct bt_field_class_option_with_selector_field common;
253
254 /* Owned by this */
255 const struct bt_integer_range_set *range_set;
256};
257
258/* Variant FC (with selector) option: named field class + range set */
259struct bt_field_class_variant_with_selector_field_option {
260 struct bt_named_field_class common;
261
262 /* Owned by this */
263 const struct bt_integer_range_set *range_set;
264};
265
266struct bt_field_class_variant {
267 /*
268 * Depending on the variant field class type, the contained
269 * named field classes are of type
270 * `struct bt_named_field_class *` if the variant field class
271 * doesn't have a selector, or
272 * `struct bt_field_class_variant_with_selector_field_option *`
273 * if it has.
274 */
275 struct bt_field_class_named_field_class_container common;
276};
277
278struct bt_field_class_variant_with_selector_field {
279 struct bt_field_class_variant common;
280
281 enum field_xref_kind selector_field_xref_kind;
282
283 union {
284 /* Used with FIELD_XREF_KIND_PATH */
285 struct {
286 /*
287 * Owned by this, but never dereferenced: only use to find it
288 * elsewhere.
289 */
290 const struct bt_field_class *class;
291
292 /* Owned by this */
293 struct bt_field_path *path;
294 } path;
295
296 /* Used with FIELD_XREF_KIND_LOCATION, owned by this */
297 const struct bt_field_location *location;
298 } selector_field;
299};
300
301struct bt_field_class_blob {
302 struct bt_field_class common;
303
304 GString *media_type;
305};
306
307struct bt_field_class_blob_static {
308 struct bt_field_class_blob common;
309 uint64_t length;
310};
311
312struct bt_field_class_blob_dynamic {
313 struct bt_field_class_blob common;
314 const struct bt_field_location *length_fl;
315};
316
317void _bt_field_class_freeze(const struct bt_field_class *field_class);
318
319#ifdef BT_DEV_MODE
320# define bt_field_class_freeze _bt_field_class_freeze
321#else
322# define bt_field_class_freeze(_fc) ((void) _fc)
323#endif
324
325void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc);
326
327#ifdef BT_DEV_MODE
328# define bt_named_field_class_freeze _bt_named_field_class_freeze
329#else
330# define bt_named_field_class_freeze(_named_fc) ((void) _named_fc)
331#endif
332
333/*
334 * This function recursively marks `field_class` and its children as
335 * being part of a trace. This is used to validate that all field classes
336 * are used at a single location within trace objects even if they are
337 * shared objects for other purposes.
338 */
339void bt_field_class_make_part_of_trace_class(
340 const struct bt_field_class *field_class);
341
342#endif /* BABELTRACE_LIB_TRACE_IR_FIELD_CLASS_H */
This page took 0.0283330000000001 seconds and 5 git commands to generate.