Commit | Line | Data |
---|---|---|
5cd6d0e5 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5cd6d0e5 | 5 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
5cd6d0e5 PP |
6 | */ |
7 | ||
0235b0db MJ |
8 | #ifndef BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H |
9 | #define BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H | |
10 | ||
d98421f2 | 11 | #include "lib/assert-cond.h" |
3fadfbc0 MJ |
12 | #include <babeltrace2/trace-ir/clock-class.h> |
13 | #include <babeltrace2/trace-ir/field-class.h> | |
91d81473 | 14 | #include "common/macros.h" |
45c51519 | 15 | #include "common/common.h" |
578e048b | 16 | #include "lib/object.h" |
3fadfbc0 | 17 | #include <babeltrace2/types.h> |
c4f23e30 | 18 | #include <stdbool.h> |
5cd6d0e5 PP |
19 | #include <stdint.h> |
20 | #include <glib.h> | |
21 | ||
5cd6d0e5 PP |
22 | #define BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(_fc, _index) \ |
23 | (&g_array_index(((struct bt_field_class_enumeration *) (_fc))->mappings, \ | |
24 | struct bt_field_class_enumeration_mapping, (_index))) | |
25 | ||
26 | #define BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(_mapping, _index) \ | |
27 | (&g_array_index((_mapping)->ranges, \ | |
28 | struct bt_field_class_enumeration_mapping_range, (_index))) | |
29 | ||
5cd6d0e5 PP |
30 | struct bt_field_class { |
31 | struct bt_object base; | |
864cad70 | 32 | enum bt_field_class_type type; |
5cd6d0e5 PP |
33 | bool frozen; |
34 | ||
c6962c96 PP |
35 | /* Owned by this */ |
36 | struct bt_value *user_attributes; | |
37 | ||
5cd6d0e5 | 38 | /* |
bdb288b3 PP |
39 | * This flag indicates whether or not this field class is part |
40 | * of a trace class. | |
5cd6d0e5 | 41 | */ |
862ca4ed | 42 | bool part_of_trace_class; |
5cd6d0e5 PP |
43 | }; |
44 | ||
5cebbe7f PP |
45 | struct bt_field_class_bool { |
46 | struct bt_field_class common; | |
47 | }; | |
48 | ||
1094efa4 PP |
49 | struct bt_field_class_bit_array { |
50 | struct bt_field_class common; | |
51 | uint64_t length; | |
52 | }; | |
53 | ||
5cd6d0e5 PP |
54 | struct bt_field_class_integer { |
55 | struct bt_field_class common; | |
56 | ||
57 | /* | |
58 | * Value range of fields built from this integer field class: | |
59 | * this is an equivalent integer size in bits. More formally, | |
60 | * `range` is `n` in: | |
61 | * | |
62 | * Unsigned range: [0, 2^n - 1] | |
63 | * Signed range: [-2^(n - 1), 2^(n - 1) - 1] | |
64 | */ | |
65 | uint64_t range; | |
66 | ||
67 | enum bt_field_class_integer_preferred_display_base base; | |
68 | }; | |
69 | ||
5cd6d0e5 PP |
70 | struct bt_field_class_enumeration_mapping { |
71 | GString *label; | |
72 | ||
45c51519 PP |
73 | /* Owner by this */ |
74 | const struct bt_integer_range_set *range_set; | |
5cd6d0e5 PP |
75 | }; |
76 | ||
9c08c816 PP |
77 | struct bt_field_class_enumeration_unsigned_mapping; |
78 | struct bt_field_class_enumeration_signed_mapping; | |
8f3ccfbc | 79 | |
5cd6d0e5 PP |
80 | struct bt_field_class_enumeration { |
81 | struct bt_field_class_integer common; | |
82 | ||
83 | /* Array of `struct bt_field_class_enumeration_mapping *` */ | |
84 | GArray *mappings; | |
85 | ||
86 | /* | |
87 | * This is an array of `const char *` which acts as a temporary | |
88 | * (potentially growing) buffer for | |
9c08c816 | 89 | * bt_field_class_enumeration_unsigned_get_mapping_labels_for_value() |
5cd6d0e5 | 90 | * and |
9c08c816 | 91 | * bt_field_class_enumeration_signed_get_mapping_labels_for_value(). |
5cd6d0e5 PP |
92 | * |
93 | * The actual strings are owned by the mappings above. | |
94 | */ | |
95 | GPtrArray *label_buf; | |
96 | }; | |
97 | ||
98 | struct bt_field_class_real { | |
99 | struct bt_field_class common; | |
5cd6d0e5 PP |
100 | }; |
101 | ||
102 | struct bt_field_class_string { | |
103 | struct bt_field_class common; | |
104 | }; | |
105 | ||
106 | /* A named field class is a (name, field class) pair */ | |
107 | struct bt_named_field_class { | |
108 | GString *name; | |
109 | ||
c6962c96 PP |
110 | /* Owned by this */ |
111 | struct bt_value *user_attributes; | |
112 | ||
5cd6d0e5 PP |
113 | /* Owned by this */ |
114 | struct bt_field_class *fc; | |
1e6fd1d7 PP |
115 | |
116 | bool frozen; | |
5cd6d0e5 PP |
117 | }; |
118 | ||
1e6fd1d7 PP |
119 | struct bt_field_class_structure_member; |
120 | struct bt_field_class_variant_option; | |
de821fe5 PP |
121 | struct bt_field_class_variant_with_selector_field_integer_unsigned_option; |
122 | struct bt_field_class_variant_with_selector_field_integer_signed_option; | |
1e6fd1d7 | 123 | |
5cd6d0e5 PP |
124 | struct bt_field_class_named_field_class_container { |
125 | struct bt_field_class common; | |
126 | ||
127 | /* | |
128 | * Key: `const char *`, not owned by this (owned by named field | |
45c51519 | 129 | * class objects contained in `named_fcs` below). |
5cd6d0e5 PP |
130 | */ |
131 | GHashTable *name_to_index; | |
132 | ||
45c51519 PP |
133 | /* Array of `struct bt_named_field_class *` */ |
134 | GPtrArray *named_fcs; | |
5cd6d0e5 PP |
135 | }; |
136 | ||
137 | struct bt_field_class_structure { | |
138 | struct bt_field_class_named_field_class_container common; | |
139 | }; | |
140 | ||
141 | struct bt_field_class_array { | |
142 | struct bt_field_class common; | |
143 | ||
144 | /* Owned by this */ | |
145 | struct bt_field_class *element_fc; | |
146 | }; | |
147 | ||
9c08c816 | 148 | struct bt_field_class_array_static { |
5cd6d0e5 PP |
149 | struct bt_field_class_array common; |
150 | uint64_t length; | |
151 | }; | |
152 | ||
9c08c816 | 153 | struct bt_field_class_array_dynamic { |
5cd6d0e5 PP |
154 | struct bt_field_class_array common; |
155 | ||
b38aea74 | 156 | /* Owned by this */ |
5cd6d0e5 PP |
157 | struct bt_field_class *length_fc; |
158 | ||
159 | /* Owned by this */ | |
160 | struct bt_field_path *length_field_path; | |
161 | }; | |
162 | ||
b38aea74 PP |
163 | struct bt_field_class_option { |
164 | struct bt_field_class common; | |
165 | ||
166 | /* Owned by this */ | |
167 | struct bt_field_class *content_fc; | |
0aa006b7 PP |
168 | }; |
169 | ||
de821fe5 | 170 | struct bt_field_class_option_with_selector_field { |
0aa006b7 | 171 | struct bt_field_class_option common; |
b38aea74 PP |
172 | |
173 | /* Owned by this */ | |
174 | struct bt_field_class *selector_fc; | |
175 | ||
176 | /* Owned by this */ | |
177 | struct bt_field_path *selector_field_path; | |
178 | }; | |
179 | ||
de821fe5 PP |
180 | struct bt_field_class_option_with_selector_field_bool { |
181 | struct bt_field_class_option_with_selector_field common; | |
0aa006b7 PP |
182 | |
183 | /* Owned by this */ | |
184 | bool sel_is_reversed; | |
185 | }; | |
186 | ||
de821fe5 PP |
187 | struct bt_field_class_option_with_selector_field_integer { |
188 | struct bt_field_class_option_with_selector_field common; | |
0aa006b7 PP |
189 | |
190 | /* Owned by this */ | |
191 | const struct bt_integer_range_set *range_set; | |
192 | }; | |
193 | ||
45c51519 | 194 | /* Variant FC (with selector) option: named field class + range set */ |
de821fe5 | 195 | struct bt_field_class_variant_with_selector_field_option { |
45c51519 PP |
196 | struct bt_named_field_class common; |
197 | ||
198 | /* Owned by this */ | |
199 | const struct bt_integer_range_set *range_set; | |
200 | }; | |
201 | ||
5cd6d0e5 | 202 | struct bt_field_class_variant { |
45c51519 PP |
203 | /* |
204 | * Depending on the variant field class type, the contained | |
205 | * named field classes are of type | |
206 | * `struct bt_named_field_class *` if the variant field class | |
207 | * doesn't have a selector, or | |
de821fe5 | 208 | * `struct bt_field_class_variant_with_selector_field_option *` |
45c51519 PP |
209 | * if it has. |
210 | */ | |
5cd6d0e5 | 211 | struct bt_field_class_named_field_class_container common; |
45c51519 | 212 | }; |
5cd6d0e5 | 213 | |
de821fe5 | 214 | struct bt_field_class_variant_with_selector_field { |
45c51519 PP |
215 | struct bt_field_class_variant common; |
216 | ||
217 | /* | |
218 | * Owned by this, but never dereferenced: only use to find it | |
219 | * elsewhere. | |
220 | */ | |
221 | const struct bt_field_class *selector_fc; | |
5cd6d0e5 PP |
222 | |
223 | /* Owned by this */ | |
224 | struct bt_field_path *selector_field_path; | |
225 | }; | |
226 | ||
40f4ba76 | 227 | void _bt_field_class_freeze(const struct bt_field_class *field_class); |
5cd6d0e5 PP |
228 | |
229 | #ifdef BT_DEV_MODE | |
230 | # define bt_field_class_freeze _bt_field_class_freeze | |
231 | #else | |
1d7f91d1 | 232 | # define bt_field_class_freeze(_fc) ((void) _fc) |
5cd6d0e5 PP |
233 | #endif |
234 | ||
1e6fd1d7 PP |
235 | void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc); |
236 | ||
237 | #ifdef BT_DEV_MODE | |
238 | # define bt_named_field_class_freeze _bt_named_field_class_freeze | |
239 | #else | |
1d7f91d1 | 240 | # define bt_named_field_class_freeze(_named_fc) ((void) _named_fc) |
1e6fd1d7 PP |
241 | #endif |
242 | ||
5cd6d0e5 PP |
243 | /* |
244 | * This function recursively marks `field_class` and its children as | |
245 | * being part of a trace. This is used to validate that all field classes | |
246 | * are used at a single location within trace objects even if they are | |
247 | * shared objects for other purposes. | |
248 | */ | |
bdb288b3 | 249 | void bt_field_class_make_part_of_trace_class( |
862ca4ed | 250 | const struct bt_field_class *field_class); |
5cd6d0e5 | 251 | |
5cd6d0e5 | 252 | #endif /* BABELTRACE_TRACE_IR_FIELD_CLASSES_INTERNAL_H */ |