Commit | Line | Data |
---|---|---|
5cd6d0e5 | 1 | /* |
e2f7325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5cd6d0e5 PP |
3 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
4 | * | |
5cd6d0e5 PP |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
24 | #define BT_LOG_TAG "FIELD-CLASSES" | |
25 | #include <babeltrace/lib-logging-internal.h> | |
26 | ||
27 | #include <babeltrace/assert-pre-internal.h> | |
c6bd8523 PP |
28 | #include <babeltrace/trace-ir/field-class.h> |
29 | #include <babeltrace/trace-ir/field-class-const.h> | |
30 | #include <babeltrace/trace-ir/field-class-internal.h> | |
5cd6d0e5 | 31 | #include <babeltrace/trace-ir/field-path-internal.h> |
c6bd8523 PP |
32 | #include <babeltrace/trace-ir/field-internal.h> |
33 | #include <babeltrace/trace-ir/field-const.h> | |
34 | #include <babeltrace/trace-ir/field.h> | |
5cd6d0e5 | 35 | #include <babeltrace/trace-ir/utils-internal.h> |
5cd6d0e5 PP |
36 | #include <babeltrace/trace-ir/clock-class.h> |
37 | #include <babeltrace/trace-ir/clock-class-internal.h> | |
38 | #include <babeltrace/object-internal.h> | |
5cd6d0e5 PP |
39 | #include <babeltrace/compiler-internal.h> |
40 | #include <babeltrace/endian-internal.h> | |
41 | #include <babeltrace/assert-internal.h> | |
42 | #include <babeltrace/compat/glib-internal.h> | |
43 | #include <float.h> | |
44 | #include <inttypes.h> | |
45 | #include <stdlib.h> | |
46 | ||
40f4ba76 PP |
47 | enum bt_field_class_type bt_field_class_get_type( |
48 | const struct bt_field_class *fc) | |
5cd6d0e5 PP |
49 | { |
50 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 51 | return fc->type; |
5cd6d0e5 PP |
52 | } |
53 | ||
54 | static | |
864cad70 | 55 | void init_field_class(struct bt_field_class *fc, enum bt_field_class_type type, |
5cd6d0e5 PP |
56 | bt_object_release_func release_func) |
57 | { | |
58 | BT_ASSERT(fc); | |
864cad70 | 59 | BT_ASSERT(bt_field_class_has_known_type(fc)); |
5cd6d0e5 PP |
60 | BT_ASSERT(release_func); |
61 | bt_object_init_shared(&fc->base, release_func); | |
864cad70 | 62 | fc->type = type; |
5cd6d0e5 PP |
63 | } |
64 | ||
65 | static | |
864cad70 PP |
66 | void init_integer_field_class(struct bt_field_class_integer *fc, |
67 | enum bt_field_class_type type, | |
5cd6d0e5 PP |
68 | bt_object_release_func release_func) |
69 | { | |
864cad70 | 70 | init_field_class((void *) fc, type, release_func); |
5cd6d0e5 PP |
71 | fc->range = 64; |
72 | fc->base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL; | |
73 | } | |
74 | ||
75 | static | |
76 | void destroy_integer_field_class(struct bt_object *obj) | |
77 | { | |
78 | BT_ASSERT(obj); | |
e5be10ef | 79 | BT_LIB_LOGD("Destroying integer field class object: %!+F", obj); |
5cd6d0e5 PP |
80 | g_free(obj); |
81 | } | |
82 | ||
83 | static inline | |
1122a43a PP |
84 | struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class, |
85 | enum bt_field_class_type type) | |
5cd6d0e5 PP |
86 | { |
87 | struct bt_field_class_integer *int_fc = NULL; | |
88 | ||
1122a43a | 89 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 90 | BT_LOGD("Creating default integer field class object: type=%s", |
864cad70 | 91 | bt_common_field_class_type_string(type)); |
5cd6d0e5 PP |
92 | int_fc = g_new0(struct bt_field_class_integer, 1); |
93 | if (!int_fc) { | |
e5be10ef | 94 | BT_LOGE_STR("Failed to allocate one integer field class."); |
5cd6d0e5 PP |
95 | goto error; |
96 | } | |
97 | ||
864cad70 | 98 | init_integer_field_class(int_fc, type, destroy_integer_field_class); |
e5be10ef | 99 | BT_LIB_LOGD("Created integer field class object: %!+F", int_fc); |
5cd6d0e5 PP |
100 | goto end; |
101 | ||
102 | error: | |
65300d60 | 103 | BT_OBJECT_PUT_REF_AND_RESET(int_fc); |
5cd6d0e5 PP |
104 | |
105 | end: | |
106 | return (void *) int_fc; | |
107 | } | |
108 | ||
1122a43a PP |
109 | struct bt_field_class *bt_field_class_unsigned_integer_create( |
110 | bt_trace_class *trace_class) | |
5cd6d0e5 | 111 | { |
1122a43a | 112 | return create_integer_field_class(trace_class, |
e5be10ef | 113 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
5cd6d0e5 PP |
114 | } |
115 | ||
1122a43a PP |
116 | struct bt_field_class *bt_field_class_signed_integer_create( |
117 | bt_trace_class *trace_class) | |
5cd6d0e5 | 118 | { |
1122a43a | 119 | return create_integer_field_class(trace_class, |
e5be10ef | 120 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); |
5cd6d0e5 PP |
121 | } |
122 | ||
123 | uint64_t bt_field_class_integer_get_field_value_range( | |
40f4ba76 | 124 | const struct bt_field_class *fc) |
5cd6d0e5 | 125 | { |
40f4ba76 | 126 | const struct bt_field_class_integer *int_fc = (const void *) fc; |
5cd6d0e5 PP |
127 | |
128 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
129 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
130 | return int_fc->range; | |
131 | } | |
132 | ||
133 | BT_ASSERT_PRE_FUNC | |
134 | static | |
135 | bool size_is_valid_for_enumeration_field_class(struct bt_field_class *fc, | |
136 | uint64_t size) | |
137 | { | |
138 | // TODO | |
139 | return true; | |
140 | } | |
141 | ||
40f4ba76 PP |
142 | void bt_field_class_integer_set_field_value_range( |
143 | struct bt_field_class *fc, uint64_t size) | |
5cd6d0e5 PP |
144 | { |
145 | struct bt_field_class_integer *int_fc = (void *) fc; | |
146 | ||
147 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
148 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
149 | BT_ASSERT_PRE_FC_HOT(fc, "Field class"); | |
150 | BT_ASSERT_PRE(size <= 64, | |
e5be10ef | 151 | "Unsupported size for integer field class's field value range " |
5cd6d0e5 | 152 | "(maximum is 64): size=%" PRIu64, size); |
864cad70 PP |
153 | BT_ASSERT_PRE( |
154 | int_fc->common.type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || | |
155 | int_fc->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || | |
5cd6d0e5 | 156 | size_is_valid_for_enumeration_field_class(fc, size), |
e5be10ef | 157 | "Invalid field value range for enumeration field class: " |
5cd6d0e5 PP |
158 | "at least one of the current mapping ranges contains values " |
159 | "which are outside this range: %!+F, size=%" PRIu64, fc, size); | |
160 | int_fc->range = size; | |
e5be10ef | 161 | BT_LIB_LOGV("Set integer field class's field value range: %!+F", fc); |
5cd6d0e5 PP |
162 | } |
163 | ||
164 | enum bt_field_class_integer_preferred_display_base | |
40f4ba76 | 165 | bt_field_class_integer_get_preferred_display_base(const struct bt_field_class *fc) |
5cd6d0e5 | 166 | { |
40f4ba76 | 167 | const struct bt_field_class_integer *int_fc = (const void *) fc; |
5cd6d0e5 PP |
168 | |
169 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
170 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
171 | return int_fc->base; | |
172 | } | |
173 | ||
40f4ba76 PP |
174 | void bt_field_class_integer_set_preferred_display_base( |
175 | struct bt_field_class *fc, | |
5cd6d0e5 PP |
176 | enum bt_field_class_integer_preferred_display_base base) |
177 | { | |
178 | struct bt_field_class_integer *int_fc = (void *) fc; | |
179 | ||
180 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
181 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
182 | BT_ASSERT_PRE_FC_HOT(fc, "Field class"); | |
183 | int_fc->base = base; | |
e5be10ef | 184 | BT_LIB_LOGV("Set integer field class's preferred display base: %!+F", fc); |
5cd6d0e5 PP |
185 | } |
186 | ||
187 | static | |
188 | void finalize_enumeration_field_class_mapping( | |
189 | struct bt_field_class_enumeration_mapping *mapping) | |
190 | { | |
191 | BT_ASSERT(mapping); | |
192 | ||
193 | if (mapping->label) { | |
194 | g_string_free(mapping->label, TRUE); | |
195 | } | |
196 | ||
197 | if (mapping->ranges) { | |
198 | g_array_free(mapping->ranges, TRUE); | |
199 | } | |
200 | } | |
201 | ||
202 | static | |
203 | void destroy_enumeration_field_class(struct bt_object *obj) | |
204 | { | |
205 | struct bt_field_class_enumeration *fc = (void *) obj; | |
206 | ||
207 | BT_ASSERT(fc); | |
e5be10ef | 208 | BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc); |
5cd6d0e5 PP |
209 | |
210 | if (fc->mappings) { | |
211 | uint64_t i; | |
212 | ||
213 | for (i = 0; i < fc->mappings->len; i++) { | |
214 | finalize_enumeration_field_class_mapping( | |
215 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, i)); | |
216 | } | |
217 | ||
218 | g_array_free(fc->mappings, TRUE); | |
238b7404 | 219 | fc->mappings = NULL; |
5cd6d0e5 PP |
220 | } |
221 | ||
222 | if (fc->label_buf) { | |
223 | g_ptr_array_free(fc->label_buf, TRUE); | |
238b7404 | 224 | fc->label_buf = NULL; |
5cd6d0e5 PP |
225 | } |
226 | ||
227 | g_free(fc); | |
228 | } | |
229 | ||
230 | static | |
40f4ba76 | 231 | struct bt_field_class *create_enumeration_field_class( |
1122a43a | 232 | bt_trace_class *trace_class, enum bt_field_class_type type) |
5cd6d0e5 PP |
233 | { |
234 | struct bt_field_class_enumeration *enum_fc = NULL; | |
235 | ||
1122a43a | 236 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 237 | BT_LOGD("Creating default enumeration field class object: type=%s", |
864cad70 | 238 | bt_common_field_class_type_string(type)); |
5cd6d0e5 PP |
239 | enum_fc = g_new0(struct bt_field_class_enumeration, 1); |
240 | if (!enum_fc) { | |
e5be10ef | 241 | BT_LOGE_STR("Failed to allocate one enumeration field class."); |
5cd6d0e5 PP |
242 | goto error; |
243 | } | |
244 | ||
864cad70 | 245 | init_integer_field_class((void *) enum_fc, type, |
5cd6d0e5 PP |
246 | destroy_enumeration_field_class); |
247 | enum_fc->mappings = g_array_new(FALSE, TRUE, | |
248 | sizeof(struct bt_field_class_enumeration_mapping)); | |
249 | if (!enum_fc->mappings) { | |
250 | BT_LOGE_STR("Failed to allocate a GArray."); | |
251 | goto error; | |
252 | } | |
253 | ||
254 | enum_fc->label_buf = g_ptr_array_new(); | |
255 | if (!enum_fc->label_buf) { | |
256 | BT_LOGE_STR("Failed to allocate a GArray."); | |
257 | goto error; | |
258 | } | |
259 | ||
e5be10ef | 260 | BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc); |
5cd6d0e5 PP |
261 | goto end; |
262 | ||
263 | error: | |
65300d60 | 264 | BT_OBJECT_PUT_REF_AND_RESET(enum_fc); |
5cd6d0e5 PP |
265 | |
266 | end: | |
267 | return (void *) enum_fc; | |
268 | } | |
269 | ||
1122a43a PP |
270 | struct bt_field_class *bt_field_class_unsigned_enumeration_create( |
271 | bt_trace_class *trace_class) | |
5cd6d0e5 | 272 | { |
1122a43a | 273 | return create_enumeration_field_class(trace_class, |
864cad70 | 274 | BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); |
5cd6d0e5 PP |
275 | } |
276 | ||
1122a43a PP |
277 | struct bt_field_class *bt_field_class_signed_enumeration_create( |
278 | bt_trace_class *trace_class) | |
5cd6d0e5 | 279 | { |
1122a43a | 280 | return create_enumeration_field_class(trace_class, |
864cad70 | 281 | BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); |
5cd6d0e5 PP |
282 | } |
283 | ||
40f4ba76 PP |
284 | uint64_t bt_field_class_enumeration_get_mapping_count( |
285 | const struct bt_field_class *fc) | |
5cd6d0e5 | 286 | { |
40f4ba76 | 287 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 PP |
288 | |
289 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
290 | BT_ASSERT_PRE_FC_IS_ENUM(fc, "Field class"); | |
291 | return (uint64_t) enum_fc->mappings->len; | |
292 | } | |
293 | ||
40f4ba76 PP |
294 | void bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( |
295 | const struct bt_field_class *fc, uint64_t index, | |
5cd6d0e5 | 296 | const char **name, |
40f4ba76 | 297 | const struct bt_field_class_unsigned_enumeration_mapping_ranges **ranges) |
5cd6d0e5 | 298 | { |
40f4ba76 PP |
299 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
300 | const struct bt_field_class_enumeration_mapping *mapping; | |
5cd6d0e5 PP |
301 | |
302 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
303 | BT_ASSERT_PRE_NON_NULL(name, "Name (output)"); | |
304 | BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)"); | |
305 | BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len); | |
864cad70 | 306 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
5cd6d0e5 PP |
307 | "Field class"); |
308 | mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); | |
309 | *name = mapping->label->str; | |
310 | *ranges = (void *) mapping; | |
311 | } | |
312 | ||
40f4ba76 PP |
313 | void bt_field_class_signed_enumeration_borrow_mapping_by_index_const( |
314 | const struct bt_field_class *fc, uint64_t index, | |
5cd6d0e5 | 315 | const char **name, |
40f4ba76 | 316 | const struct bt_field_class_signed_enumeration_mapping_ranges **ranges) |
5cd6d0e5 | 317 | { |
40f4ba76 PP |
318 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
319 | const struct bt_field_class_enumeration_mapping *mapping; | |
5cd6d0e5 PP |
320 | |
321 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
322 | BT_ASSERT_PRE_NON_NULL(name, "Name (output)"); | |
323 | BT_ASSERT_PRE_NON_NULL(ranges, "Ranges (output)"); | |
324 | BT_ASSERT_PRE_VALID_INDEX(index, enum_fc->mappings->len); | |
864cad70 | 325 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
5cd6d0e5 PP |
326 | "Field class"); |
327 | mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); | |
328 | *name = mapping->label->str; | |
329 | *ranges = (void *) mapping; | |
330 | } | |
331 | ||
332 | static inline | |
333 | uint64_t get_enumeration_field_class_mapping_range_count( | |
40f4ba76 | 334 | const struct bt_field_class_enumeration_mapping *mapping) |
5cd6d0e5 PP |
335 | { |
336 | BT_ASSERT_PRE_NON_NULL(mapping, "Ranges"); | |
337 | return (uint64_t) mapping->ranges->len; | |
338 | } | |
339 | ||
340 | uint64_t bt_field_class_unsigned_enumeration_mapping_ranges_get_range_count( | |
40f4ba76 | 341 | const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges) |
5cd6d0e5 | 342 | { |
40f4ba76 PP |
343 | return get_enumeration_field_class_mapping_range_count( |
344 | (const void *) ranges); | |
5cd6d0e5 PP |
345 | } |
346 | ||
347 | uint64_t bt_field_class_signed_enumeration_mapping_ranges_get_range_count( | |
40f4ba76 | 348 | const struct bt_field_class_signed_enumeration_mapping_ranges *ranges) |
5cd6d0e5 | 349 | { |
40f4ba76 PP |
350 | return get_enumeration_field_class_mapping_range_count( |
351 | (const void *) ranges); | |
5cd6d0e5 PP |
352 | } |
353 | ||
354 | static inline | |
355 | void get_enumeration_field_class_mapping_range_at_index( | |
40f4ba76 | 356 | const struct bt_field_class_enumeration_mapping *mapping, |
5cd6d0e5 PP |
357 | uint64_t index, uint64_t *lower, uint64_t *upper) |
358 | { | |
40f4ba76 | 359 | const struct bt_field_class_enumeration_mapping_range *range; |
5cd6d0e5 PP |
360 | |
361 | BT_ASSERT_PRE_NON_NULL(mapping, "Ranges"); | |
362 | BT_ASSERT_PRE_NON_NULL(lower, "Range's lower (output)"); | |
363 | BT_ASSERT_PRE_NON_NULL(upper, "Range's upper (output)"); | |
364 | BT_ASSERT_PRE_VALID_INDEX(index, mapping->ranges->len); | |
365 | range = BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(mapping, index); | |
366 | *lower = range->lower.u; | |
367 | *upper = range->upper.u; | |
368 | } | |
369 | ||
370 | void bt_field_class_unsigned_enumeration_mapping_ranges_get_range_by_index( | |
40f4ba76 | 371 | const struct bt_field_class_unsigned_enumeration_mapping_ranges *ranges, |
5cd6d0e5 PP |
372 | uint64_t index, uint64_t *lower, uint64_t *upper) |
373 | { | |
40f4ba76 PP |
374 | get_enumeration_field_class_mapping_range_at_index( |
375 | (const void *) ranges, index, lower, upper); | |
5cd6d0e5 PP |
376 | } |
377 | ||
378 | void bt_field_class_signed_enumeration_mapping_ranges_get_range_by_index( | |
1998d1ab | 379 | const struct bt_field_class_signed_enumeration_mapping_ranges *ranges, |
5cd6d0e5 PP |
380 | uint64_t index, int64_t *lower, int64_t *upper) |
381 | { | |
40f4ba76 PP |
382 | get_enumeration_field_class_mapping_range_at_index( |
383 | (const void *) ranges, index, | |
384 | (uint64_t *) lower, (uint64_t *) upper); | |
5cd6d0e5 PP |
385 | } |
386 | ||
387 | ||
388 | ||
4295b9e0 PP |
389 | enum bt_field_class_status |
390 | bt_field_class_unsigned_enumeration_get_mapping_labels_by_value( | |
40f4ba76 | 391 | const struct bt_field_class *fc, uint64_t value, |
5cd6d0e5 PP |
392 | bt_field_class_enumeration_mapping_label_array *label_array, |
393 | uint64_t *count) | |
394 | { | |
40f4ba76 | 395 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 PP |
396 | uint64_t i; |
397 | ||
398 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
399 | BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)"); | |
400 | BT_ASSERT_PRE_NON_NULL(count, "Count (output)"); | |
864cad70 | 401 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
5cd6d0e5 PP |
402 | "Field class"); |
403 | g_ptr_array_set_size(enum_fc->label_buf, 0); | |
404 | ||
405 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
406 | uint64_t j; | |
40f4ba76 | 407 | const struct bt_field_class_enumeration_mapping *mapping = |
5cd6d0e5 PP |
408 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); |
409 | ||
410 | for (j = 0; j < mapping->ranges->len; j++) { | |
40f4ba76 | 411 | const struct bt_field_class_enumeration_mapping_range *range = |
5cd6d0e5 PP |
412 | BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX( |
413 | mapping, j); | |
414 | ||
415 | if (value >= range->lower.u && | |
416 | value <= range->upper.u) { | |
417 | g_ptr_array_add(enum_fc->label_buf, | |
418 | mapping->label->str); | |
419 | break; | |
420 | } | |
421 | } | |
422 | } | |
423 | ||
424 | *label_array = (void *) enum_fc->label_buf->pdata; | |
425 | *count = (uint64_t) enum_fc->label_buf->len; | |
4295b9e0 | 426 | return BT_FIELD_CLASS_STATUS_OK; |
5cd6d0e5 PP |
427 | } |
428 | ||
4295b9e0 PP |
429 | enum bt_field_class_status |
430 | bt_field_class_signed_enumeration_get_mapping_labels_by_value( | |
40f4ba76 | 431 | const struct bt_field_class *fc, int64_t value, |
5cd6d0e5 PP |
432 | bt_field_class_enumeration_mapping_label_array *label_array, |
433 | uint64_t *count) | |
434 | { | |
40f4ba76 | 435 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
5cd6d0e5 PP |
436 | uint64_t i; |
437 | ||
438 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
439 | BT_ASSERT_PRE_NON_NULL(label_array, "Label array (output)"); | |
440 | BT_ASSERT_PRE_NON_NULL(count, "Count (output)"); | |
864cad70 | 441 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
5cd6d0e5 PP |
442 | "Field class"); |
443 | g_ptr_array_set_size(enum_fc->label_buf, 0); | |
444 | ||
445 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
446 | uint64_t j; | |
40f4ba76 | 447 | const struct bt_field_class_enumeration_mapping *mapping = |
5cd6d0e5 PP |
448 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); |
449 | ||
450 | for (j = 0; j < mapping->ranges->len; j++) { | |
40f4ba76 | 451 | const struct bt_field_class_enumeration_mapping_range *range = |
5cd6d0e5 PP |
452 | BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX( |
453 | mapping, j); | |
454 | ||
455 | if (value >= range->lower.i && | |
456 | value <= range->upper.i) { | |
457 | g_ptr_array_add(enum_fc->label_buf, | |
458 | mapping->label->str); | |
459 | break; | |
460 | } | |
461 | } | |
462 | } | |
463 | ||
464 | *label_array = (void *) enum_fc->label_buf->pdata; | |
465 | *count = (uint64_t) enum_fc->label_buf->len; | |
4295b9e0 | 466 | return BT_FIELD_CLASS_STATUS_OK; |
5cd6d0e5 PP |
467 | } |
468 | ||
469 | static inline | |
4295b9e0 PP |
470 | enum bt_field_class_status add_mapping_to_enumeration_field_class( |
471 | struct bt_field_class *fc, | |
5cd6d0e5 PP |
472 | const char *label, uint64_t lower, uint64_t upper) |
473 | { | |
4295b9e0 | 474 | int ret = BT_FIELD_CLASS_STATUS_OK; |
5cd6d0e5 PP |
475 | uint64_t i; |
476 | struct bt_field_class_enumeration *enum_fc = (void *) fc; | |
477 | struct bt_field_class_enumeration_mapping *mapping = NULL; | |
478 | struct bt_field_class_enumeration_mapping_range *range; | |
479 | ||
480 | BT_ASSERT(fc); | |
481 | BT_ASSERT_PRE_NON_NULL(label, "Label"); | |
482 | ||
483 | /* Find existing mapping identified by this label */ | |
484 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
485 | struct bt_field_class_enumeration_mapping *mapping_candidate = | |
486 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); | |
487 | ||
488 | if (strcmp(mapping_candidate->label->str, label) == 0) { | |
489 | mapping = mapping_candidate; | |
490 | break; | |
491 | } | |
492 | } | |
493 | ||
494 | if (!mapping) { | |
495 | /* Create new mapping for this label */ | |
496 | g_array_set_size(enum_fc->mappings, enum_fc->mappings->len + 1); | |
497 | mapping = BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, | |
498 | enum_fc->mappings->len - 1); | |
499 | mapping->ranges = g_array_new(FALSE, TRUE, | |
500 | sizeof(struct bt_field_class_enumeration_mapping_range)); | |
501 | if (!mapping->ranges) { | |
502 | finalize_enumeration_field_class_mapping(mapping); | |
503 | g_array_set_size(enum_fc->mappings, | |
504 | enum_fc->mappings->len - 1); | |
4295b9e0 | 505 | ret = BT_FIELD_CLASS_STATUS_NOMEM; |
5cd6d0e5 PP |
506 | goto end; |
507 | } | |
508 | ||
509 | mapping->label = g_string_new(label); | |
510 | if (!mapping->label) { | |
511 | finalize_enumeration_field_class_mapping(mapping); | |
512 | g_array_set_size(enum_fc->mappings, | |
513 | enum_fc->mappings->len - 1); | |
4295b9e0 | 514 | ret = BT_FIELD_CLASS_STATUS_NOMEM; |
5cd6d0e5 PP |
515 | goto end; |
516 | } | |
517 | } | |
518 | ||
519 | /* Add range */ | |
520 | BT_ASSERT(mapping); | |
521 | g_array_set_size(mapping->ranges, mapping->ranges->len + 1); | |
522 | range = BT_FIELD_CLASS_ENUM_MAPPING_RANGE_AT_INDEX(mapping, | |
523 | mapping->ranges->len - 1); | |
524 | range->lower.u = lower; | |
525 | range->upper.u = upper; | |
e5be10ef | 526 | BT_LIB_LOGV("Added mapping to enumeration field class: " |
5cd6d0e5 PP |
527 | "%![fc-]+F, label=\"%s\", lower-unsigned=%" PRIu64 ", " |
528 | "upper-unsigned=%" PRIu64, fc, label, lower, upper); | |
529 | ||
530 | end: | |
531 | return ret; | |
532 | } | |
533 | ||
4295b9e0 | 534 | enum bt_field_class_status bt_field_class_unsigned_enumeration_map_range( |
40f4ba76 | 535 | struct bt_field_class *fc, const char *label, |
5cd6d0e5 PP |
536 | uint64_t range_lower, uint64_t range_upper) |
537 | { | |
538 | struct bt_field_class_enumeration *enum_fc = (void *) fc; | |
539 | ||
540 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 541 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
5cd6d0e5 PP |
542 | "Field class"); |
543 | BT_ASSERT_PRE(range_lower <= range_upper, | |
544 | "Range's upper bound is less than lower bound: " | |
545 | "upper=%" PRIu64 ", lower=%" PRIu64, | |
546 | range_lower, range_upper); | |
547 | BT_ASSERT_PRE(bt_util_value_is_in_range_unsigned(enum_fc->common.range, | |
548 | range_lower), | |
e5be10ef | 549 | "Range's lower bound is outside the enumeration field class's value range: " |
5cd6d0e5 PP |
550 | "%![fc-]+F, lower=%" PRIu64, fc, range_lower); |
551 | BT_ASSERT_PRE(bt_util_value_is_in_range_unsigned(enum_fc->common.range, | |
552 | range_upper), | |
e5be10ef | 553 | "Range's upper bound is outside the enumeration field class's value range: " |
5cd6d0e5 PP |
554 | "%![fc-]+F, upper=%" PRIu64, fc, range_upper); |
555 | return add_mapping_to_enumeration_field_class(fc, label, range_lower, | |
556 | range_upper); | |
557 | } | |
558 | ||
4295b9e0 | 559 | enum bt_field_class_status bt_field_class_signed_enumeration_map_range( |
40f4ba76 | 560 | struct bt_field_class *fc, const char *label, |
5cd6d0e5 PP |
561 | int64_t range_lower, int64_t range_upper) |
562 | { | |
563 | struct bt_field_class_enumeration *enum_fc = (void *) fc; | |
564 | ||
565 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 566 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
5cd6d0e5 PP |
567 | "Field class"); |
568 | BT_ASSERT_PRE(range_lower <= range_upper, | |
569 | "Range's upper bound is less than lower bound: " | |
570 | "upper=%" PRId64 ", lower=%" PRId64, | |
571 | range_lower, range_upper); | |
572 | BT_ASSERT_PRE(bt_util_value_is_in_range_signed(enum_fc->common.range, | |
573 | range_lower), | |
e5be10ef | 574 | "Range's lower bound is outside the enumeration field class's value range: " |
5cd6d0e5 PP |
575 | "%![fc-]+F, lower=%" PRId64, fc, range_lower); |
576 | BT_ASSERT_PRE(bt_util_value_is_in_range_signed(enum_fc->common.range, | |
577 | range_upper), | |
e5be10ef | 578 | "Range's upper bound is outside the enumeration field class's value range: " |
5cd6d0e5 PP |
579 | "%![fc-]+F, upper=%" PRId64, fc, range_upper); |
580 | return add_mapping_to_enumeration_field_class(fc, label, range_lower, | |
581 | range_upper); | |
582 | } | |
583 | ||
584 | static | |
585 | void destroy_real_field_class(struct bt_object *obj) | |
586 | { | |
587 | BT_ASSERT(obj); | |
e5be10ef | 588 | BT_LIB_LOGD("Destroying real field class object: %!+F", obj); |
5cd6d0e5 PP |
589 | g_free(obj); |
590 | } | |
591 | ||
1122a43a | 592 | struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class) |
5cd6d0e5 PP |
593 | { |
594 | struct bt_field_class_real *real_fc = NULL; | |
595 | ||
1122a43a | 596 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 597 | BT_LOGD_STR("Creating default real field class object."); |
5cd6d0e5 PP |
598 | real_fc = g_new0(struct bt_field_class_real, 1); |
599 | if (!real_fc) { | |
e5be10ef | 600 | BT_LOGE_STR("Failed to allocate one real field class."); |
5cd6d0e5 PP |
601 | goto error; |
602 | } | |
603 | ||
864cad70 | 604 | init_field_class((void *) real_fc, BT_FIELD_CLASS_TYPE_REAL, |
5cd6d0e5 | 605 | destroy_real_field_class); |
e5be10ef | 606 | BT_LIB_LOGD("Created real field class object: %!+F", real_fc); |
5cd6d0e5 PP |
607 | goto end; |
608 | ||
609 | error: | |
65300d60 | 610 | BT_OBJECT_PUT_REF_AND_RESET(real_fc); |
5cd6d0e5 PP |
611 | |
612 | end: | |
613 | return (void *) real_fc; | |
614 | } | |
615 | ||
40f4ba76 | 616 | bt_bool bt_field_class_real_is_single_precision(const struct bt_field_class *fc) |
5cd6d0e5 | 617 | { |
40f4ba76 | 618 | const struct bt_field_class_real *real_fc = (const void *) fc; |
5cd6d0e5 PP |
619 | |
620 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 621 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_REAL, "Field class"); |
5cd6d0e5 PP |
622 | return real_fc->is_single_precision; |
623 | } | |
624 | ||
40f4ba76 | 625 | void bt_field_class_real_set_is_single_precision(struct bt_field_class *fc, |
5cd6d0e5 PP |
626 | bt_bool is_single_precision) |
627 | { | |
628 | struct bt_field_class_real *real_fc = (void *) fc; | |
629 | ||
630 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 631 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_REAL, "Field class"); |
5cd6d0e5 PP |
632 | BT_ASSERT_PRE_FC_HOT(fc, "Field class"); |
633 | real_fc->is_single_precision = (bool) is_single_precision; | |
e5be10ef | 634 | BT_LIB_LOGV("Set real field class's \"is single precision\" property: " |
5cd6d0e5 | 635 | "%!+F", fc); |
5cd6d0e5 PP |
636 | } |
637 | ||
638 | static | |
639 | int init_named_field_classes_container( | |
640 | struct bt_field_class_named_field_class_container *fc, | |
40f4ba76 PP |
641 | enum bt_field_class_type type, |
642 | bt_object_release_func release_func) | |
5cd6d0e5 PP |
643 | { |
644 | int ret = 0; | |
645 | ||
864cad70 | 646 | init_field_class((void *) fc, type, release_func); |
5cd6d0e5 PP |
647 | fc->named_fcs = g_array_new(FALSE, TRUE, |
648 | sizeof(struct bt_named_field_class)); | |
649 | if (!fc->named_fcs) { | |
650 | BT_LOGE_STR("Failed to allocate a GArray."); | |
651 | ret = -1; | |
652 | goto end; | |
653 | } | |
654 | ||
655 | fc->name_to_index = g_hash_table_new(g_str_hash, g_str_equal); | |
656 | if (!fc->name_to_index) { | |
657 | BT_LOGE_STR("Failed to allocate a GHashTable."); | |
658 | ret = -1; | |
659 | goto end; | |
660 | } | |
661 | ||
662 | end: | |
663 | return ret; | |
664 | } | |
665 | ||
666 | static | |
667 | void finalize_named_field_class(struct bt_named_field_class *named_fc) | |
668 | { | |
669 | BT_ASSERT(named_fc); | |
e5be10ef | 670 | BT_LIB_LOGD("Finalizing named field class: " |
5cd6d0e5 PP |
671 | "addr=%p, name=\"%s\", %![fc-]+F", |
672 | named_fc, named_fc->name ? named_fc->name->str : NULL, | |
673 | named_fc->fc); | |
674 | ||
675 | if (named_fc->name) { | |
676 | g_string_free(named_fc->name, TRUE); | |
677 | } | |
678 | ||
e5be10ef | 679 | BT_LOGD_STR("Putting named field class's field class."); |
238b7404 | 680 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->fc); |
5cd6d0e5 PP |
681 | } |
682 | ||
683 | static | |
684 | void finalize_named_field_classes_container( | |
685 | struct bt_field_class_named_field_class_container *fc) | |
686 | { | |
687 | uint64_t i; | |
688 | ||
689 | BT_ASSERT(fc); | |
690 | ||
691 | if (fc->named_fcs) { | |
692 | for (i = 0; i < fc->named_fcs->len; i++) { | |
693 | finalize_named_field_class( | |
694 | &g_array_index(fc->named_fcs, | |
695 | struct bt_named_field_class, i)); | |
696 | } | |
697 | ||
698 | g_array_free(fc->named_fcs, TRUE); | |
699 | } | |
700 | ||
701 | if (fc->name_to_index) { | |
702 | g_hash_table_destroy(fc->name_to_index); | |
703 | } | |
704 | } | |
705 | ||
706 | static | |
707 | void destroy_structure_field_class(struct bt_object *obj) | |
708 | { | |
709 | BT_ASSERT(obj); | |
1998d1ab | 710 | BT_LIB_LOGD("Destroying structure field class object: %!+F", obj); |
5cd6d0e5 PP |
711 | finalize_named_field_classes_container((void *) obj); |
712 | g_free(obj); | |
713 | } | |
714 | ||
1122a43a PP |
715 | struct bt_field_class *bt_field_class_structure_create( |
716 | bt_trace_class *trace_class) | |
5cd6d0e5 PP |
717 | { |
718 | int ret; | |
719 | struct bt_field_class_structure *struct_fc = NULL; | |
720 | ||
1122a43a | 721 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 722 | BT_LOGD_STR("Creating default structure field class object."); |
5cd6d0e5 PP |
723 | struct_fc = g_new0(struct bt_field_class_structure, 1); |
724 | if (!struct_fc) { | |
e5be10ef | 725 | BT_LOGE_STR("Failed to allocate one structure field class."); |
5cd6d0e5 PP |
726 | goto error; |
727 | } | |
728 | ||
729 | ret = init_named_field_classes_container((void *) struct_fc, | |
864cad70 | 730 | BT_FIELD_CLASS_TYPE_STRUCTURE, destroy_structure_field_class); |
5cd6d0e5 PP |
731 | if (ret) { |
732 | goto error; | |
733 | } | |
734 | ||
e5be10ef | 735 | BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc); |
5cd6d0e5 PP |
736 | goto end; |
737 | ||
738 | error: | |
65300d60 | 739 | BT_OBJECT_PUT_REF_AND_RESET(struct_fc); |
5cd6d0e5 PP |
740 | |
741 | end: | |
742 | return (void *) struct_fc; | |
743 | } | |
744 | ||
745 | static | |
4295b9e0 | 746 | enum bt_field_class_status append_named_field_class_to_container_field_class( |
5cd6d0e5 PP |
747 | struct bt_field_class_named_field_class_container *container_fc, |
748 | const char *name, struct bt_field_class *fc) | |
749 | { | |
4295b9e0 | 750 | int ret = BT_FIELD_CLASS_STATUS_OK; |
5cd6d0e5 PP |
751 | struct bt_named_field_class *named_fc; |
752 | GString *name_str; | |
753 | ||
754 | BT_ASSERT(container_fc); | |
755 | BT_ASSERT_PRE_FC_HOT(container_fc, "Field class"); | |
756 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
757 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
758 | BT_ASSERT_PRE(!bt_g_hash_table_contains(container_fc->name_to_index, | |
759 | name), | |
e5be10ef | 760 | "Duplicate member/option name in structure/variant field class: " |
5cd6d0e5 PP |
761 | "%![container-fc-]+F, name=\"%s\"", container_fc, name); |
762 | name_str = g_string_new(name); | |
763 | if (!name_str) { | |
764 | BT_LOGE_STR("Failed to allocate a GString."); | |
4295b9e0 | 765 | ret = BT_FIELD_CLASS_STATUS_NOMEM; |
5cd6d0e5 PP |
766 | goto end; |
767 | } | |
768 | ||
769 | g_array_set_size(container_fc->named_fcs, | |
770 | container_fc->named_fcs->len + 1); | |
771 | named_fc = &g_array_index(container_fc->named_fcs, | |
772 | struct bt_named_field_class, container_fc->named_fcs->len - 1); | |
773 | named_fc->name = name_str; | |
398454ed PP |
774 | named_fc->fc = fc; |
775 | bt_object_get_no_null_check(fc); | |
5cd6d0e5 PP |
776 | g_hash_table_insert(container_fc->name_to_index, named_fc->name->str, |
777 | GUINT_TO_POINTER(container_fc->named_fcs->len - 1)); | |
1e6fd1d7 PP |
778 | |
779 | /* | |
780 | * Freeze the field class, but not the named field class (the | |
781 | * user can still modify it, if possible, until the container | |
782 | * itself is frozen). | |
783 | */ | |
5cd6d0e5 PP |
784 | bt_field_class_freeze(fc); |
785 | ||
786 | end: | |
787 | return ret; | |
788 | } | |
789 | ||
4295b9e0 PP |
790 | enum bt_field_class_status bt_field_class_structure_append_member( |
791 | struct bt_field_class *fc, const char *name, | |
792 | struct bt_field_class *member_fc) | |
5cd6d0e5 | 793 | { |
e5be10ef | 794 | |
5cd6d0e5 | 795 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
740faaf4 PP |
796 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, |
797 | "Field class"); | |
5cd6d0e5 | 798 | return append_named_field_class_to_container_field_class((void *) fc, |
40f4ba76 | 799 | name, member_fc); |
5cd6d0e5 PP |
800 | } |
801 | ||
40f4ba76 PP |
802 | uint64_t bt_field_class_structure_get_member_count( |
803 | const struct bt_field_class *fc) | |
5cd6d0e5 PP |
804 | { |
805 | struct bt_field_class_structure *struct_fc = (void *) fc; | |
806 | ||
807 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
740faaf4 PP |
808 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, |
809 | "Field class"); | |
5cd6d0e5 PP |
810 | return (uint64_t) struct_fc->common.named_fcs->len; |
811 | } | |
812 | ||
813 | static | |
1e6fd1d7 PP |
814 | struct bt_named_field_class * |
815 | borrow_named_field_class_from_container_field_class_at_index( | |
740faaf4 | 816 | struct bt_field_class_named_field_class_container *fc, |
1e6fd1d7 | 817 | uint64_t index) |
5cd6d0e5 | 818 | { |
5cd6d0e5 | 819 | BT_ASSERT(fc); |
5cd6d0e5 | 820 | BT_ASSERT_PRE_VALID_INDEX(index, fc->named_fcs->len); |
1e6fd1d7 | 821 | return BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index); |
5cd6d0e5 PP |
822 | } |
823 | ||
1e6fd1d7 PP |
824 | const struct bt_field_class_structure_member * |
825 | bt_field_class_structure_borrow_member_by_index_const( | |
826 | const struct bt_field_class *fc, uint64_t index) | |
5cd6d0e5 PP |
827 | { |
828 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
740faaf4 PP |
829 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, |
830 | "Field class"); | |
1e6fd1d7 PP |
831 | return (const void *) |
832 | borrow_named_field_class_from_container_field_class_at_index( | |
833 | (void *) fc, index); | |
740faaf4 PP |
834 | } |
835 | ||
1e6fd1d7 PP |
836 | struct bt_field_class_structure_member * |
837 | bt_field_class_structure_borrow_member_by_index( | |
838 | struct bt_field_class *fc, uint64_t index) | |
740faaf4 PP |
839 | { |
840 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
841 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
842 | "Field class"); | |
1e6fd1d7 PP |
843 | return (void *) |
844 | borrow_named_field_class_from_container_field_class_at_index( | |
845 | (void *) fc, index); | |
e5be10ef PP |
846 | } |
847 | ||
5cd6d0e5 | 848 | static |
1e6fd1d7 PP |
849 | struct bt_named_field_class * |
850 | borrow_named_field_class_from_container_field_class_by_name( | |
740faaf4 | 851 | struct bt_field_class_named_field_class_container *fc, |
5cd6d0e5 PP |
852 | const char *name) |
853 | { | |
1e6fd1d7 | 854 | struct bt_named_field_class *named_fc = NULL; |
5cd6d0e5 PP |
855 | gpointer orig_key; |
856 | gpointer value; | |
857 | ||
858 | BT_ASSERT(fc); | |
859 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
860 | if (!g_hash_table_lookup_extended(fc->name_to_index, name, &orig_key, | |
861 | &value)) { | |
862 | goto end; | |
863 | } | |
864 | ||
865 | named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, | |
866 | GPOINTER_TO_UINT(value)); | |
5cd6d0e5 PP |
867 | |
868 | end: | |
1e6fd1d7 | 869 | return named_fc; |
5cd6d0e5 PP |
870 | } |
871 | ||
1e6fd1d7 | 872 | const struct bt_field_class_structure_member * |
7c06e353 | 873 | bt_field_class_structure_borrow_member_by_name_const( |
40f4ba76 | 874 | const struct bt_field_class *fc, const char *name) |
5cd6d0e5 PP |
875 | { |
876 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
740faaf4 PP |
877 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, |
878 | "Field class"); | |
1e6fd1d7 PP |
879 | return (const void *) |
880 | borrow_named_field_class_from_container_field_class_by_name( | |
740faaf4 PP |
881 | (void *) fc, name); |
882 | } | |
883 | ||
1e6fd1d7 | 884 | struct bt_field_class_structure_member * |
7c06e353 | 885 | bt_field_class_structure_borrow_class_by_name( |
740faaf4 PP |
886 | struct bt_field_class *fc, const char *name) |
887 | { | |
888 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
889 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
890 | "Field class"); | |
1e6fd1d7 PP |
891 | return (void *) |
892 | borrow_named_field_class_from_container_field_class_by_name( | |
40f4ba76 | 893 | (void *) fc, name); |
e5be10ef PP |
894 | } |
895 | ||
1e6fd1d7 PP |
896 | const char *bt_field_class_structure_member_get_name( |
897 | const struct bt_field_class_structure_member *member) | |
898 | { | |
899 | const struct bt_named_field_class *named_fc = (const void *) member; | |
900 | ||
901 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
902 | return named_fc->name->str; | |
903 | } | |
904 | ||
905 | const struct bt_field_class * | |
906 | bt_field_class_structure_member_borrow_field_class_const( | |
907 | const struct bt_field_class_structure_member *member) | |
908 | { | |
909 | const struct bt_named_field_class *named_fc = (const void *) member; | |
910 | ||
911 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
912 | return named_fc->fc; | |
913 | } | |
914 | ||
915 | struct bt_field_class * | |
916 | bt_field_class_structure_member_borrow_field_class( | |
917 | struct bt_field_class_structure_member *member) | |
918 | { | |
919 | struct bt_named_field_class *named_fc = (void *) member; | |
920 | ||
921 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
922 | return named_fc->fc; | |
923 | } | |
924 | ||
5cd6d0e5 PP |
925 | static |
926 | void destroy_variant_field_class(struct bt_object *obj) | |
927 | { | |
928 | struct bt_field_class_variant *fc = (void *) obj; | |
929 | ||
930 | BT_ASSERT(fc); | |
e5be10ef | 931 | BT_LIB_LOGD("Destroying variant field class object: %!+F", fc); |
5cd6d0e5 PP |
932 | finalize_named_field_classes_container((void *) fc); |
933 | BT_LOGD_STR("Putting selector field path."); | |
238b7404 PP |
934 | BT_OBJECT_PUT_REF_AND_RESET(fc->selector_field_path); |
935 | BT_LOGD_STR("Putting selector field class."); | |
936 | BT_OBJECT_PUT_REF_AND_RESET(fc->selector_fc); | |
5cd6d0e5 PP |
937 | g_free(fc); |
938 | } | |
939 | ||
1122a43a PP |
940 | struct bt_field_class *bt_field_class_variant_create( |
941 | bt_trace_class *trace_class) | |
5cd6d0e5 PP |
942 | { |
943 | int ret; | |
944 | struct bt_field_class_variant *var_fc = NULL; | |
945 | ||
1122a43a | 946 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 947 | BT_LOGD_STR("Creating default variant field class object."); |
5cd6d0e5 PP |
948 | var_fc = g_new0(struct bt_field_class_variant, 1); |
949 | if (!var_fc) { | |
e5be10ef | 950 | BT_LOGE_STR("Failed to allocate one variant field class."); |
5cd6d0e5 PP |
951 | goto error; |
952 | } | |
953 | ||
954 | ret = init_named_field_classes_container((void *) var_fc, | |
864cad70 | 955 | BT_FIELD_CLASS_TYPE_VARIANT, destroy_variant_field_class); |
5cd6d0e5 PP |
956 | if (ret) { |
957 | goto error; | |
958 | } | |
959 | ||
e5be10ef | 960 | BT_LIB_LOGD("Created variant field class object: %!+F", var_fc); |
5cd6d0e5 PP |
961 | goto end; |
962 | ||
963 | error: | |
65300d60 | 964 | BT_OBJECT_PUT_REF_AND_RESET(var_fc); |
5cd6d0e5 PP |
965 | |
966 | end: | |
967 | return (void *) var_fc; | |
968 | } | |
969 | ||
4295b9e0 | 970 | enum bt_field_class_status bt_field_class_variant_set_selector_field_class( |
40f4ba76 PP |
971 | struct bt_field_class *fc, |
972 | struct bt_field_class *selector_fc) | |
5cd6d0e5 PP |
973 | { |
974 | struct bt_field_class_variant *var_fc = (void *) fc; | |
975 | ||
e5be10ef PP |
976 | BT_ASSERT_PRE_NON_NULL(fc, "Variant field class"); |
977 | BT_ASSERT_PRE_NON_NULL(selector_fc, "Selector field class"); | |
864cad70 | 978 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); |
e5be10ef PP |
979 | BT_ASSERT_PRE_FC_IS_ENUM(selector_fc, "Selector field class"); |
980 | BT_ASSERT_PRE_FC_HOT(fc, "Variant field class"); | |
40f4ba76 | 981 | var_fc->selector_fc = selector_fc; |
398454ed | 982 | bt_object_get_no_null_check(selector_fc); |
40f4ba76 | 983 | bt_field_class_freeze(selector_fc); |
4295b9e0 | 984 | return BT_FIELD_CLASS_STATUS_OK; |
5cd6d0e5 PP |
985 | } |
986 | ||
4295b9e0 | 987 | enum bt_field_class_status bt_field_class_variant_append_option( |
40f4ba76 PP |
988 | struct bt_field_class *fc, |
989 | const char *name, struct bt_field_class *option_fc) | |
5cd6d0e5 | 990 | { |
e5be10ef | 991 | |
5cd6d0e5 | 992 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
864cad70 | 993 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); |
5cd6d0e5 | 994 | return append_named_field_class_to_container_field_class((void *) fc, |
40f4ba76 | 995 | name, option_fc); |
5cd6d0e5 PP |
996 | } |
997 | ||
1e6fd1d7 | 998 | const struct bt_field_class_variant_option * |
7c06e353 | 999 | bt_field_class_variant_borrow_option_by_name_const( |
40f4ba76 | 1000 | const struct bt_field_class *fc, const char *name) |
5cd6d0e5 PP |
1001 | { |
1002 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 1003 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); |
1e6fd1d7 PP |
1004 | return (const void *) |
1005 | borrow_named_field_class_from_container_field_class_by_name( | |
1006 | (void *) fc, name); | |
740faaf4 PP |
1007 | } |
1008 | ||
1e6fd1d7 | 1009 | struct bt_field_class_variant_option * |
7c06e353 | 1010 | bt_field_class_variant_borrow_option_by_name( |
740faaf4 PP |
1011 | struct bt_field_class *fc, const char *name) |
1012 | { | |
1013 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1014 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); | |
1e6fd1d7 PP |
1015 | return (void *) |
1016 | borrow_named_field_class_from_container_field_class_by_name( | |
1017 | (void *) fc, name); | |
e5be10ef PP |
1018 | } |
1019 | ||
40f4ba76 | 1020 | uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc) |
5cd6d0e5 | 1021 | { |
40f4ba76 | 1022 | const struct bt_field_class_variant *var_fc = (const void *) fc; |
5cd6d0e5 PP |
1023 | |
1024 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 1025 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); |
5cd6d0e5 PP |
1026 | return (uint64_t) var_fc->common.named_fcs->len; |
1027 | } | |
1028 | ||
1e6fd1d7 PP |
1029 | const struct bt_field_class_variant_option * |
1030 | bt_field_class_variant_borrow_option_by_index_const( | |
1031 | const struct bt_field_class *fc, uint64_t index) | |
5cd6d0e5 PP |
1032 | { |
1033 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 1034 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); |
1e6fd1d7 PP |
1035 | return (const void *) |
1036 | borrow_named_field_class_from_container_field_class_at_index( | |
1037 | (void *) fc, index); | |
740faaf4 PP |
1038 | } |
1039 | ||
1e6fd1d7 PP |
1040 | struct bt_field_class_variant_option * |
1041 | bt_field_class_variant_borrow_option_by_index( | |
1042 | struct bt_field_class *fc, uint64_t index) | |
740faaf4 PP |
1043 | { |
1044 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1045 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); | |
1e6fd1d7 PP |
1046 | return (void *) |
1047 | borrow_named_field_class_from_container_field_class_at_index( | |
1048 | (void *) fc, index); | |
1049 | } | |
1050 | ||
1051 | const char *bt_field_class_variant_option_get_name( | |
1052 | const struct bt_field_class_variant_option *option) | |
1053 | { | |
1054 | const struct bt_named_field_class *named_fc = (const void *) option; | |
1055 | ||
1056 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
1057 | return named_fc->name->str; | |
1058 | } | |
1059 | ||
1060 | const struct bt_field_class * | |
1061 | bt_field_class_variant_option_borrow_field_class_const( | |
1062 | const struct bt_field_class_variant_option *option) | |
1063 | { | |
1064 | const struct bt_named_field_class *named_fc = (const void *) option; | |
1065 | ||
1066 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
1067 | return named_fc->fc; | |
1068 | } | |
1069 | ||
1070 | struct bt_field_class * | |
1071 | bt_field_class_variant_option_borrow_field_class( | |
1072 | struct bt_field_class_variant_option *option) | |
1073 | { | |
1074 | struct bt_named_field_class *named_fc = (void *) option; | |
1075 | ||
1076 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
1077 | return named_fc->fc; | |
5cd6d0e5 PP |
1078 | } |
1079 | ||
40f4ba76 PP |
1080 | const struct bt_field_path * |
1081 | bt_field_class_variant_borrow_selector_field_path_const( | |
1082 | const struct bt_field_class *fc) | |
e5be10ef | 1083 | { |
40f4ba76 | 1084 | const struct bt_field_class_variant *var_fc = (const void *) fc; |
5cd6d0e5 PP |
1085 | |
1086 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 1087 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, |
5cd6d0e5 PP |
1088 | "Field class"); |
1089 | return var_fc->selector_field_path; | |
1090 | } | |
1091 | ||
1092 | static | |
1093 | void init_array_field_class(struct bt_field_class_array *fc, | |
864cad70 | 1094 | enum bt_field_class_type type, bt_object_release_func release_func, |
5cd6d0e5 PP |
1095 | struct bt_field_class *element_fc) |
1096 | { | |
1097 | BT_ASSERT(element_fc); | |
864cad70 | 1098 | init_field_class((void *) fc, type, release_func); |
398454ed PP |
1099 | fc->element_fc = element_fc; |
1100 | bt_object_get_no_null_check(element_fc); | |
5cd6d0e5 PP |
1101 | bt_field_class_freeze(element_fc); |
1102 | } | |
1103 | ||
1104 | static | |
1105 | void finalize_array_field_class(struct bt_field_class_array *array_fc) | |
1106 | { | |
1107 | BT_ASSERT(array_fc); | |
e5be10ef | 1108 | BT_LOGD_STR("Putting element field class."); |
238b7404 | 1109 | BT_OBJECT_PUT_REF_AND_RESET(array_fc->element_fc); |
5cd6d0e5 PP |
1110 | } |
1111 | ||
1112 | static | |
1113 | void destroy_static_array_field_class(struct bt_object *obj) | |
1114 | { | |
1115 | BT_ASSERT(obj); | |
e5be10ef | 1116 | BT_LIB_LOGD("Destroying static array field class object: %!+F", obj); |
5cd6d0e5 PP |
1117 | finalize_array_field_class((void *) obj); |
1118 | g_free(obj); | |
1119 | } | |
1120 | ||
40f4ba76 | 1121 | struct bt_field_class * |
1122a43a PP |
1122 | bt_field_class_static_array_create(bt_trace_class *trace_class, |
1123 | struct bt_field_class *element_fc, uint64_t length) | |
5cd6d0e5 PP |
1124 | { |
1125 | struct bt_field_class_static_array *array_fc = NULL; | |
1126 | ||
1122a43a | 1127 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef PP |
1128 | BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); |
1129 | BT_LOGD_STR("Creating default static array field class object."); | |
5cd6d0e5 PP |
1130 | array_fc = g_new0(struct bt_field_class_static_array, 1); |
1131 | if (!array_fc) { | |
e5be10ef | 1132 | BT_LOGE_STR("Failed to allocate one static array field class."); |
5cd6d0e5 PP |
1133 | goto error; |
1134 | } | |
1135 | ||
864cad70 | 1136 | init_array_field_class((void *) array_fc, BT_FIELD_CLASS_TYPE_STATIC_ARRAY, |
5cd6d0e5 PP |
1137 | destroy_static_array_field_class, element_fc); |
1138 | array_fc->length = length; | |
e5be10ef | 1139 | BT_LIB_LOGD("Created static array field class object: %!+F", array_fc); |
5cd6d0e5 PP |
1140 | goto end; |
1141 | ||
1142 | error: | |
65300d60 | 1143 | BT_OBJECT_PUT_REF_AND_RESET(array_fc); |
5cd6d0e5 PP |
1144 | |
1145 | end: | |
1146 | return (void *) array_fc; | |
1147 | } | |
1148 | ||
40f4ba76 PP |
1149 | const struct bt_field_class * |
1150 | bt_field_class_array_borrow_element_field_class_const( | |
1151 | const struct bt_field_class *fc) | |
5cd6d0e5 | 1152 | { |
40f4ba76 | 1153 | const struct bt_field_class_array *array_fc = (const void *) fc; |
5cd6d0e5 PP |
1154 | |
1155 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1156 | BT_ASSERT_PRE_FC_IS_ARRAY(fc, "Field class"); | |
1157 | return array_fc->element_fc; | |
1158 | } | |
1159 | ||
740faaf4 PP |
1160 | struct bt_field_class * |
1161 | bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc) | |
1162 | { | |
1163 | struct bt_field_class_array *array_fc = (void *) fc; | |
1164 | ||
1165 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1166 | BT_ASSERT_PRE_FC_IS_ARRAY(fc, "Field class"); | |
1167 | return array_fc->element_fc; | |
1168 | } | |
1169 | ||
40f4ba76 | 1170 | uint64_t bt_field_class_static_array_get_length(const struct bt_field_class *fc) |
e5be10ef | 1171 | { |
40f4ba76 | 1172 | const struct bt_field_class_static_array *array_fc = (const void *) fc; |
5cd6d0e5 PP |
1173 | |
1174 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 1175 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STATIC_ARRAY, |
5cd6d0e5 PP |
1176 | "Field class"); |
1177 | return (uint64_t) array_fc->length; | |
1178 | } | |
1179 | ||
1180 | static | |
1181 | void destroy_dynamic_array_field_class(struct bt_object *obj) | |
1182 | { | |
1183 | struct bt_field_class_dynamic_array *fc = (void *) obj; | |
1184 | ||
1185 | BT_ASSERT(fc); | |
e5be10ef | 1186 | BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc); |
5cd6d0e5 PP |
1187 | finalize_array_field_class((void *) fc); |
1188 | BT_LOGD_STR("Putting length field path."); | |
238b7404 PP |
1189 | BT_OBJECT_PUT_REF_AND_RESET(fc->length_field_path); |
1190 | BT_LOGD_STR("Putting length field class."); | |
1191 | BT_OBJECT_PUT_REF_AND_RESET(fc->length_fc); | |
5cd6d0e5 PP |
1192 | g_free(fc); |
1193 | } | |
1194 | ||
40f4ba76 | 1195 | struct bt_field_class *bt_field_class_dynamic_array_create( |
1122a43a | 1196 | bt_trace_class *trace_class, |
40f4ba76 | 1197 | struct bt_field_class *element_fc) |
5cd6d0e5 PP |
1198 | { |
1199 | struct bt_field_class_dynamic_array *array_fc = NULL; | |
1200 | ||
1122a43a | 1201 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef PP |
1202 | BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); |
1203 | BT_LOGD_STR("Creating default dynamic array field class object."); | |
5cd6d0e5 PP |
1204 | array_fc = g_new0(struct bt_field_class_dynamic_array, 1); |
1205 | if (!array_fc) { | |
e5be10ef | 1206 | BT_LOGE_STR("Failed to allocate one dynamic array field class."); |
5cd6d0e5 PP |
1207 | goto error; |
1208 | } | |
1209 | ||
40f4ba76 PP |
1210 | init_array_field_class((void *) array_fc, |
1211 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, | |
5cd6d0e5 | 1212 | destroy_dynamic_array_field_class, element_fc); |
e5be10ef | 1213 | BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc); |
5cd6d0e5 PP |
1214 | goto end; |
1215 | ||
1216 | error: | |
65300d60 | 1217 | BT_OBJECT_PUT_REF_AND_RESET(array_fc); |
5cd6d0e5 PP |
1218 | |
1219 | end: | |
1220 | return (void *) array_fc; | |
1221 | } | |
1222 | ||
4295b9e0 | 1223 | enum bt_field_class_status bt_field_class_dynamic_array_set_length_field_class( |
40f4ba76 PP |
1224 | struct bt_field_class *fc, |
1225 | struct bt_field_class *length_fc) | |
5cd6d0e5 PP |
1226 | { |
1227 | struct bt_field_class_dynamic_array *array_fc = (void *) fc; | |
1228 | ||
e5be10ef PP |
1229 | BT_ASSERT_PRE_NON_NULL(fc, "Dynamic array field class"); |
1230 | BT_ASSERT_PRE_NON_NULL(length_fc, "Length field class"); | |
864cad70 | 1231 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, |
5cd6d0e5 | 1232 | "Field class"); |
e5be10ef PP |
1233 | BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, "Length field class"); |
1234 | BT_ASSERT_PRE_FC_HOT(fc, "Dynamic array field class"); | |
40f4ba76 | 1235 | array_fc->length_fc = length_fc; |
398454ed | 1236 | bt_object_get_no_null_check(length_fc); |
5cd6d0e5 | 1237 | bt_field_class_freeze(length_fc); |
4295b9e0 | 1238 | return BT_FIELD_CLASS_STATUS_OK; |
5cd6d0e5 PP |
1239 | } |
1240 | ||
40f4ba76 PP |
1241 | const struct bt_field_path * |
1242 | bt_field_class_dynamic_array_borrow_length_field_path_const( | |
1243 | const struct bt_field_class *fc) | |
5cd6d0e5 | 1244 | { |
40f4ba76 | 1245 | const struct bt_field_class_dynamic_array *seq_fc = (const void *) fc; |
5cd6d0e5 PP |
1246 | |
1247 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
864cad70 | 1248 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY, |
5cd6d0e5 PP |
1249 | "Field class"); |
1250 | return seq_fc->length_field_path; | |
1251 | } | |
1252 | ||
1253 | static | |
1254 | void destroy_string_field_class(struct bt_object *obj) | |
1255 | { | |
1256 | BT_ASSERT(obj); | |
e5be10ef | 1257 | BT_LIB_LOGD("Destroying string field class object: %!+F", obj); |
5cd6d0e5 PP |
1258 | g_free(obj); |
1259 | } | |
1260 | ||
1122a43a | 1261 | struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class) |
5cd6d0e5 PP |
1262 | { |
1263 | struct bt_field_class_string *string_fc = NULL; | |
1264 | ||
1122a43a | 1265 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
e5be10ef | 1266 | BT_LOGD_STR("Creating default string field class object."); |
5cd6d0e5 PP |
1267 | string_fc = g_new0(struct bt_field_class_string, 1); |
1268 | if (!string_fc) { | |
e5be10ef | 1269 | BT_LOGE_STR("Failed to allocate one string field class."); |
5cd6d0e5 PP |
1270 | goto error; |
1271 | } | |
1272 | ||
864cad70 | 1273 | init_field_class((void *) string_fc, BT_FIELD_CLASS_TYPE_STRING, |
5cd6d0e5 | 1274 | destroy_string_field_class); |
e5be10ef | 1275 | BT_LIB_LOGD("Created string field class object: %!+F", string_fc); |
5cd6d0e5 PP |
1276 | goto end; |
1277 | ||
1278 | error: | |
65300d60 | 1279 | BT_OBJECT_PUT_REF_AND_RESET(string_fc); |
5cd6d0e5 PP |
1280 | |
1281 | end: | |
1282 | return (void *) string_fc; | |
1283 | } | |
1284 | ||
1285 | BT_HIDDEN | |
1e6fd1d7 | 1286 | void _bt_field_class_freeze(const struct bt_field_class *c_fc) |
5cd6d0e5 | 1287 | { |
1e6fd1d7 PP |
1288 | struct bt_field_class *fc = (void *) c_fc; |
1289 | ||
5cd6d0e5 PP |
1290 | /* |
1291 | * Element/member/option field classes are frozen when added to | |
1292 | * their owner. | |
1293 | */ | |
1294 | BT_ASSERT(fc); | |
1e6fd1d7 PP |
1295 | fc->frozen = true; |
1296 | ||
1297 | switch (fc->type) { | |
1298 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
1299 | case BT_FIELD_CLASS_TYPE_VARIANT: | |
1300 | { | |
1301 | struct bt_field_class_named_field_class_container *container_fc = | |
1302 | (void *) fc; | |
1303 | uint64_t i; | |
1304 | ||
1305 | for (i = 0; i < container_fc->named_fcs->len; i++) { | |
1306 | struct bt_named_field_class *named_fc = | |
1307 | BT_FIELD_CLASS_NAMED_FC_AT_INDEX( | |
1308 | container_fc, i); | |
1309 | ||
1310 | bt_named_field_class_freeze(named_fc); | |
1311 | } | |
1312 | ||
1313 | break; | |
1314 | } | |
1315 | default: | |
1316 | break; | |
1317 | } | |
1318 | } | |
1319 | ||
1320 | BT_HIDDEN | |
1321 | void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc) | |
1322 | { | |
1323 | BT_ASSERT(named_fc); | |
1324 | ((struct bt_named_field_class *) named_fc)->frozen = true; | |
1325 | bt_field_class_freeze(named_fc->fc); | |
5cd6d0e5 PP |
1326 | } |
1327 | ||
1328 | BT_HIDDEN | |
862ca4ed | 1329 | void _bt_field_class_make_part_of_trace_class(const struct bt_field_class *c_fc) |
5cd6d0e5 | 1330 | { |
40f4ba76 PP |
1331 | struct bt_field_class *fc = (void *) c_fc; |
1332 | ||
5cd6d0e5 | 1333 | BT_ASSERT(fc); |
862ca4ed | 1334 | BT_ASSERT_PRE(!fc->part_of_trace_class, |
5cd6d0e5 | 1335 | "Field class is already part of a trace: %!+F", fc); |
862ca4ed | 1336 | fc->part_of_trace_class = true; |
5cd6d0e5 | 1337 | |
864cad70 PP |
1338 | switch (fc->type) { |
1339 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
1340 | case BT_FIELD_CLASS_TYPE_VARIANT: | |
5cd6d0e5 PP |
1341 | { |
1342 | struct bt_field_class_named_field_class_container *container_fc = | |
1343 | (void *) fc; | |
1344 | uint64_t i; | |
1345 | ||
1346 | for (i = 0; i < container_fc->named_fcs->len; i++) { | |
1347 | struct bt_named_field_class *named_fc = | |
1348 | BT_FIELD_CLASS_NAMED_FC_AT_INDEX( | |
1349 | container_fc, i); | |
1350 | ||
862ca4ed | 1351 | bt_field_class_make_part_of_trace_class(named_fc->fc); |
5cd6d0e5 PP |
1352 | } |
1353 | ||
1354 | break; | |
1355 | } | |
864cad70 PP |
1356 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
1357 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: | |
5cd6d0e5 PP |
1358 | { |
1359 | struct bt_field_class_array *array_fc = (void *) fc; | |
1360 | ||
862ca4ed | 1361 | bt_field_class_make_part_of_trace_class(array_fc->element_fc); |
5cd6d0e5 PP |
1362 | break; |
1363 | } | |
1364 | default: | |
1365 | break; | |
1366 | } | |
1367 | } | |
c5b9b441 PP |
1368 | |
1369 | void bt_field_class_get_ref(const struct bt_field_class *field_class) | |
1370 | { | |
1371 | bt_object_get_ref(field_class); | |
1372 | } | |
1373 | ||
1374 | void bt_field_class_put_ref(const struct bt_field_class *field_class) | |
1375 | { | |
1376 | bt_object_put_ref(field_class); | |
1377 | } |