Commit | Line | Data |
---|---|---|
939190b3 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
939190b3 PP |
3 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
4 | * | |
939190b3 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 | ||
b03487ab | 24 | #define BT_LOG_TAG "LIB/FIELD-CLASS" |
1633ef46 | 25 | #include "lib/logging.h" |
939190b3 | 26 | |
57952005 | 27 | #include "lib/assert-pre.h" |
71c5da58 MJ |
28 | #include <babeltrace2/trace-ir/field-class.h> |
29 | #include <babeltrace2/trace-ir/field-class-const.h> | |
71c5da58 MJ |
30 | #include <babeltrace2/trace-ir/field-const.h> |
31 | #include <babeltrace2/trace-ir/field.h> | |
71c5da58 | 32 | #include <babeltrace2/trace-ir/clock-class.h> |
57952005 MJ |
33 | #include "lib/object.h" |
34 | #include "compat/compiler.h" | |
35 | #include "compat/endian.h" | |
36 | #include "common/assert.h" | |
37 | #include "compat/glib.h" | |
939190b3 PP |
38 | #include <float.h> |
39 | #include <inttypes.h> | |
969c1d8a | 40 | #include <stdbool.h> |
939190b3 PP |
41 | #include <stdlib.h> |
42 | ||
57952005 MJ |
43 | #include "clock-class.h" |
44 | #include "field-class.h" | |
45 | #include "field.h" | |
46 | #include "field-path.h" | |
47 | #include "utils.h" | |
fb25b9e3 | 48 | #include "lib/func-status.h" |
02b61fe0 | 49 | #include "lib/integer-range-set.h" |
af90138b | 50 | #include "lib/value.h" |
57952005 | 51 | |
78cf9df6 PP |
52 | enum bt_field_class_type bt_field_class_get_type( |
53 | const struct bt_field_class *fc) | |
939190b3 | 54 | { |
fa6cfec3 | 55 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
af0c18e3 | 56 | return fc->type; |
939190b3 PP |
57 | } |
58 | ||
59 | static | |
af90138b | 60 | int init_field_class(struct bt_field_class *fc, enum bt_field_class_type type, |
939190b3 PP |
61 | bt_object_release_func release_func) |
62 | { | |
af90138b PP |
63 | int ret = 0; |
64 | ||
939190b3 | 65 | BT_ASSERT(fc); |
939190b3 PP |
66 | BT_ASSERT(release_func); |
67 | bt_object_init_shared(&fc->base, release_func); | |
af0c18e3 | 68 | fc->type = type; |
af90138b PP |
69 | fc->user_attributes = bt_value_map_create(); |
70 | if (!fc->user_attributes) { | |
71 | BT_LIB_LOGE_APPEND_CAUSE( | |
72 | "Failed to create a map value object."); | |
73 | ret = -1; | |
74 | goto end; | |
75 | } | |
76 | ||
77 | end: | |
78 | return ret; | |
79 | } | |
80 | ||
81 | static | |
82 | void finalize_field_class(struct bt_field_class *fc) | |
83 | { | |
84 | BT_OBJECT_PUT_REF_AND_RESET(fc->user_attributes); | |
939190b3 PP |
85 | } |
86 | ||
6943da6a PP |
87 | static |
88 | void destroy_bit_array_field_class(struct bt_object *obj) | |
89 | { | |
90 | BT_ASSERT(obj); | |
91 | BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj); | |
af90138b | 92 | finalize_field_class((void *) obj); |
6943da6a PP |
93 | g_free(obj); |
94 | } | |
95 | ||
96 | struct bt_field_class *bt_field_class_bit_array_create( | |
97 | struct bt_trace_class *trace_class, uint64_t length) | |
98 | { | |
99 | struct bt_field_class_bit_array *ba_fc = NULL; | |
100 | ||
101 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); | |
102 | BT_ASSERT_PRE(length > 0 && length <= 64, | |
103 | "Unsupported length for bit array field class " | |
104 | "(minimum is 1, maximum is 64): length=%" PRIu64, length); | |
105 | BT_LOGD("Creating default bit array field class object."); | |
106 | ba_fc = g_new0(struct bt_field_class_bit_array, 1); | |
107 | if (!ba_fc) { | |
108 | BT_LIB_LOGE_APPEND_CAUSE( | |
109 | "Failed to allocate one bit array field class."); | |
110 | goto error; | |
111 | } | |
112 | ||
af90138b PP |
113 | if (init_field_class((void *) ba_fc, BT_FIELD_CLASS_TYPE_BIT_ARRAY, |
114 | destroy_bit_array_field_class)) { | |
115 | goto error; | |
116 | } | |
117 | ||
6943da6a PP |
118 | ba_fc->length = length; |
119 | BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc); | |
120 | goto end; | |
121 | ||
122 | error: | |
123 | BT_OBJECT_PUT_REF_AND_RESET(ba_fc); | |
124 | ||
125 | end: | |
126 | return (void *) ba_fc; | |
127 | } | |
128 | ||
129 | uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class *fc) | |
130 | { | |
131 | const struct bt_field_class_bit_array *ba_fc = (const void *) fc; | |
132 | ||
133 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
134 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_BIT_ARRAY, | |
135 | "Field class"); | |
136 | return ba_fc->length; | |
137 | } | |
138 | ||
9414b439 PP |
139 | static |
140 | void destroy_bool_field_class(struct bt_object *obj) | |
141 | { | |
142 | BT_ASSERT(obj); | |
143 | BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj); | |
af90138b | 144 | finalize_field_class((void *) obj); |
9414b439 PP |
145 | g_free(obj); |
146 | } | |
147 | ||
148 | struct bt_field_class *bt_field_class_bool_create( | |
149 | bt_trace_class *trace_class) | |
150 | { | |
151 | struct bt_field_class_bool *bool_fc = NULL; | |
152 | ||
153 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); | |
154 | BT_LOGD("Creating default boolean field class object."); | |
155 | bool_fc = g_new0(struct bt_field_class_bool, 1); | |
156 | if (!bool_fc) { | |
157 | BT_LIB_LOGE_APPEND_CAUSE( | |
158 | "Failed to allocate one boolean field class."); | |
159 | goto error; | |
160 | } | |
161 | ||
af90138b PP |
162 | if (init_field_class((void *) bool_fc, BT_FIELD_CLASS_TYPE_BOOL, |
163 | destroy_bool_field_class)) { | |
164 | goto error; | |
165 | } | |
166 | ||
9414b439 PP |
167 | BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc); |
168 | goto end; | |
169 | ||
170 | error: | |
171 | BT_OBJECT_PUT_REF_AND_RESET(bool_fc); | |
172 | ||
173 | end: | |
174 | return (void *) bool_fc; | |
175 | } | |
176 | ||
939190b3 | 177 | static |
af90138b | 178 | int init_integer_field_class(struct bt_field_class_integer *fc, |
af0c18e3 | 179 | enum bt_field_class_type type, |
939190b3 PP |
180 | bt_object_release_func release_func) |
181 | { | |
af90138b PP |
182 | int ret; |
183 | ||
184 | ret = init_field_class((void *) fc, type, release_func); | |
185 | if (ret) { | |
186 | goto end; | |
187 | } | |
188 | ||
939190b3 PP |
189 | fc->range = 64; |
190 | fc->base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL; | |
af90138b PP |
191 | |
192 | end: | |
193 | return ret; | |
939190b3 PP |
194 | } |
195 | ||
196 | static | |
197 | void destroy_integer_field_class(struct bt_object *obj) | |
198 | { | |
199 | BT_ASSERT(obj); | |
9e550e5f | 200 | BT_LIB_LOGD("Destroying integer field class object: %!+F", obj); |
af90138b | 201 | finalize_field_class((void *) obj); |
939190b3 PP |
202 | g_free(obj); |
203 | } | |
204 | ||
205 | static inline | |
b7396828 PP |
206 | struct bt_field_class *create_integer_field_class(bt_trace_class *trace_class, |
207 | enum bt_field_class_type type) | |
939190b3 PP |
208 | { |
209 | struct bt_field_class_integer *int_fc = NULL; | |
210 | ||
b7396828 | 211 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
9e550e5f | 212 | BT_LOGD("Creating default integer field class object: type=%s", |
af0c18e3 | 213 | bt_common_field_class_type_string(type)); |
939190b3 PP |
214 | int_fc = g_new0(struct bt_field_class_integer, 1); |
215 | if (!int_fc) { | |
a8f90e5d PP |
216 | BT_LIB_LOGE_APPEND_CAUSE( |
217 | "Failed to allocate one integer field class."); | |
939190b3 PP |
218 | goto error; |
219 | } | |
220 | ||
af90138b PP |
221 | if (init_integer_field_class(int_fc, type, |
222 | destroy_integer_field_class)) { | |
223 | goto error; | |
224 | } | |
225 | ||
9e550e5f | 226 | BT_LIB_LOGD("Created integer field class object: %!+F", int_fc); |
939190b3 PP |
227 | goto end; |
228 | ||
229 | error: | |
8138bfe1 | 230 | BT_OBJECT_PUT_REF_AND_RESET(int_fc); |
939190b3 PP |
231 | |
232 | end: | |
233 | return (void *) int_fc; | |
234 | } | |
235 | ||
60bbfc7c | 236 | struct bt_field_class *bt_field_class_integer_unsigned_create( |
b7396828 | 237 | bt_trace_class *trace_class) |
939190b3 | 238 | { |
b7396828 | 239 | return create_integer_field_class(trace_class, |
9e550e5f | 240 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER); |
939190b3 PP |
241 | } |
242 | ||
60bbfc7c | 243 | struct bt_field_class *bt_field_class_integer_signed_create( |
b7396828 | 244 | bt_trace_class *trace_class) |
939190b3 | 245 | { |
b7396828 | 246 | return create_integer_field_class(trace_class, |
9e550e5f | 247 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER); |
939190b3 PP |
248 | } |
249 | ||
250 | uint64_t bt_field_class_integer_get_field_value_range( | |
78cf9df6 | 251 | const struct bt_field_class *fc) |
939190b3 | 252 | { |
78cf9df6 | 253 | const struct bt_field_class_integer *int_fc = (const void *) fc; |
939190b3 | 254 | |
fa6cfec3 PP |
255 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
256 | BT_ASSERT_PRE_DEV_FC_IS_INT(fc, "Field class"); | |
939190b3 PP |
257 | return int_fc->range; |
258 | } | |
259 | ||
939190b3 PP |
260 | static |
261 | bool size_is_valid_for_enumeration_field_class(struct bt_field_class *fc, | |
262 | uint64_t size) | |
263 | { | |
264 | // TODO | |
265 | return true; | |
266 | } | |
267 | ||
78cf9df6 PP |
268 | void bt_field_class_integer_set_field_value_range( |
269 | struct bt_field_class *fc, uint64_t size) | |
939190b3 PP |
270 | { |
271 | struct bt_field_class_integer *int_fc = (void *) fc; | |
272 | ||
273 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
274 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
fa6cfec3 | 275 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); |
939190b3 | 276 | BT_ASSERT_PRE(size <= 64, |
9e550e5f | 277 | "Unsupported size for integer field class's field value range " |
939190b3 | 278 | "(maximum is 64): size=%" PRIu64, size); |
af0c18e3 PP |
279 | BT_ASSERT_PRE( |
280 | int_fc->common.type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER || | |
281 | int_fc->common.type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER || | |
939190b3 | 282 | size_is_valid_for_enumeration_field_class(fc, size), |
9e550e5f | 283 | "Invalid field value range for enumeration field class: " |
939190b3 PP |
284 | "at least one of the current mapping ranges contains values " |
285 | "which are outside this range: %!+F, size=%" PRIu64, fc, size); | |
286 | int_fc->range = size; | |
a684a357 | 287 | BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc); |
939190b3 PP |
288 | } |
289 | ||
290 | enum bt_field_class_integer_preferred_display_base | |
78cf9df6 | 291 | bt_field_class_integer_get_preferred_display_base(const struct bt_field_class *fc) |
939190b3 | 292 | { |
78cf9df6 | 293 | const struct bt_field_class_integer *int_fc = (const void *) fc; |
939190b3 | 294 | |
fa6cfec3 PP |
295 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
296 | BT_ASSERT_PRE_DEV_FC_IS_INT(fc, "Field class"); | |
939190b3 PP |
297 | return int_fc->base; |
298 | } | |
299 | ||
78cf9df6 PP |
300 | void bt_field_class_integer_set_preferred_display_base( |
301 | struct bt_field_class *fc, | |
939190b3 PP |
302 | enum bt_field_class_integer_preferred_display_base base) |
303 | { | |
304 | struct bt_field_class_integer *int_fc = (void *) fc; | |
305 | ||
306 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
307 | BT_ASSERT_PRE_FC_IS_INT(fc, "Field class"); | |
fa6cfec3 | 308 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); |
939190b3 | 309 | int_fc->base = base; |
a684a357 | 310 | BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc); |
939190b3 PP |
311 | } |
312 | ||
313 | static | |
314 | void finalize_enumeration_field_class_mapping( | |
315 | struct bt_field_class_enumeration_mapping *mapping) | |
316 | { | |
317 | BT_ASSERT(mapping); | |
318 | ||
319 | if (mapping->label) { | |
320 | g_string_free(mapping->label, TRUE); | |
02b61fe0 | 321 | mapping->label = NULL; |
939190b3 PP |
322 | } |
323 | ||
02b61fe0 | 324 | BT_OBJECT_PUT_REF_AND_RESET(mapping->range_set); |
939190b3 PP |
325 | } |
326 | ||
327 | static | |
328 | void destroy_enumeration_field_class(struct bt_object *obj) | |
329 | { | |
330 | struct bt_field_class_enumeration *fc = (void *) obj; | |
331 | ||
332 | BT_ASSERT(fc); | |
9e550e5f | 333 | BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc); |
af90138b | 334 | finalize_field_class((void *) obj); |
939190b3 PP |
335 | |
336 | if (fc->mappings) { | |
337 | uint64_t i; | |
338 | ||
339 | for (i = 0; i < fc->mappings->len; i++) { | |
340 | finalize_enumeration_field_class_mapping( | |
341 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, i)); | |
342 | } | |
343 | ||
344 | g_array_free(fc->mappings, TRUE); | |
1248f5ea | 345 | fc->mappings = NULL; |
939190b3 PP |
346 | } |
347 | ||
348 | if (fc->label_buf) { | |
349 | g_ptr_array_free(fc->label_buf, TRUE); | |
1248f5ea | 350 | fc->label_buf = NULL; |
939190b3 PP |
351 | } |
352 | ||
353 | g_free(fc); | |
354 | } | |
355 | ||
356 | static | |
78cf9df6 | 357 | struct bt_field_class *create_enumeration_field_class( |
b7396828 | 358 | bt_trace_class *trace_class, enum bt_field_class_type type) |
939190b3 PP |
359 | { |
360 | struct bt_field_class_enumeration *enum_fc = NULL; | |
361 | ||
b7396828 | 362 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
9e550e5f | 363 | BT_LOGD("Creating default enumeration field class object: type=%s", |
af0c18e3 | 364 | bt_common_field_class_type_string(type)); |
939190b3 PP |
365 | enum_fc = g_new0(struct bt_field_class_enumeration, 1); |
366 | if (!enum_fc) { | |
a8f90e5d PP |
367 | BT_LIB_LOGE_APPEND_CAUSE( |
368 | "Failed to allocate one enumeration field class."); | |
939190b3 PP |
369 | goto error; |
370 | } | |
371 | ||
af90138b PP |
372 | if (init_integer_field_class((void *) enum_fc, type, |
373 | destroy_enumeration_field_class)) { | |
374 | goto error; | |
375 | } | |
376 | ||
939190b3 PP |
377 | enum_fc->mappings = g_array_new(FALSE, TRUE, |
378 | sizeof(struct bt_field_class_enumeration_mapping)); | |
379 | if (!enum_fc->mappings) { | |
a8f90e5d | 380 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
939190b3 PP |
381 | goto error; |
382 | } | |
383 | ||
384 | enum_fc->label_buf = g_ptr_array_new(); | |
385 | if (!enum_fc->label_buf) { | |
a8f90e5d | 386 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
939190b3 PP |
387 | goto error; |
388 | } | |
389 | ||
9e550e5f | 390 | BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc); |
939190b3 PP |
391 | goto end; |
392 | ||
393 | error: | |
8138bfe1 | 394 | BT_OBJECT_PUT_REF_AND_RESET(enum_fc); |
939190b3 PP |
395 | |
396 | end: | |
397 | return (void *) enum_fc; | |
398 | } | |
399 | ||
60bbfc7c | 400 | struct bt_field_class *bt_field_class_enumeration_unsigned_create( |
b7396828 | 401 | bt_trace_class *trace_class) |
939190b3 | 402 | { |
b7396828 | 403 | return create_enumeration_field_class(trace_class, |
af0c18e3 | 404 | BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION); |
939190b3 PP |
405 | } |
406 | ||
60bbfc7c | 407 | struct bt_field_class *bt_field_class_enumeration_signed_create( |
b7396828 | 408 | bt_trace_class *trace_class) |
939190b3 | 409 | { |
b7396828 | 410 | return create_enumeration_field_class(trace_class, |
af0c18e3 | 411 | BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION); |
939190b3 PP |
412 | } |
413 | ||
78cf9df6 PP |
414 | uint64_t bt_field_class_enumeration_get_mapping_count( |
415 | const struct bt_field_class *fc) | |
939190b3 | 416 | { |
78cf9df6 | 417 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
939190b3 | 418 | |
fa6cfec3 PP |
419 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
420 | BT_ASSERT_PRE_DEV_FC_IS_ENUM(fc, "Field class"); | |
939190b3 PP |
421 | return (uint64_t) enum_fc->mappings->len; |
422 | } | |
423 | ||
60bbfc7c PP |
424 | const struct bt_field_class_enumeration_unsigned_mapping * |
425 | bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( | |
b6baf3bb | 426 | const struct bt_field_class *fc, uint64_t index) |
939190b3 | 427 | { |
78cf9df6 | 428 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
939190b3 | 429 | |
fa6cfec3 PP |
430 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
431 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, enum_fc->mappings->len); | |
432 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, | |
939190b3 | 433 | "Field class"); |
b6baf3bb | 434 | return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); |
939190b3 PP |
435 | } |
436 | ||
60bbfc7c PP |
437 | const struct bt_field_class_enumeration_signed_mapping * |
438 | bt_field_class_enumeration_signed_borrow_mapping_by_index_const( | |
b6baf3bb | 439 | const struct bt_field_class *fc, uint64_t index) |
939190b3 | 440 | { |
78cf9df6 | 441 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
939190b3 | 442 | |
fa6cfec3 PP |
443 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
444 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, enum_fc->mappings->len); | |
445 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
939190b3 | 446 | "Field class"); |
b6baf3bb | 447 | return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, index); |
939190b3 PP |
448 | } |
449 | ||
02b61fe0 PP |
450 | static |
451 | const struct bt_field_class_enumeration_mapping * | |
452 | borrow_enumeration_field_class_mapping_by_label( | |
453 | const struct bt_field_class_enumeration *fc, const char *label) | |
939190b3 | 454 | { |
02b61fe0 PP |
455 | struct bt_field_class_enumeration_mapping *mapping = NULL; |
456 | uint64_t i; | |
457 | ||
ec4a3354 | 458 | BT_ASSERT_DBG(fc); |
02b61fe0 PP |
459 | BT_ASSERT_PRE_DEV_NON_NULL(label, "Label"); |
460 | ||
461 | for (i = 0; i < fc->mappings->len; i++) { | |
462 | struct bt_field_class_enumeration_mapping *this_mapping = | |
463 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc, i); | |
464 | ||
465 | if (strcmp(this_mapping->label->str, label) == 0) { | |
466 | mapping = this_mapping; | |
467 | goto end; | |
468 | } | |
469 | } | |
470 | ||
471 | end: | |
472 | return mapping; | |
939190b3 PP |
473 | } |
474 | ||
60bbfc7c PP |
475 | const struct bt_field_class_enumeration_signed_mapping * |
476 | bt_field_class_enumeration_signed_borrow_mapping_by_label_const( | |
02b61fe0 | 477 | const struct bt_field_class *fc, const char *label) |
939190b3 | 478 | { |
02b61fe0 PP |
479 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
480 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
481 | "Field class"); | |
482 | return (const void *) borrow_enumeration_field_class_mapping_by_label( | |
483 | (const void *) fc, label); | |
939190b3 PP |
484 | } |
485 | ||
60bbfc7c PP |
486 | const struct bt_field_class_enumeration_unsigned_mapping * |
487 | bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const( | |
02b61fe0 | 488 | const struct bt_field_class *fc, const char *label) |
939190b3 | 489 | { |
02b61fe0 PP |
490 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
491 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, | |
492 | BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field class"); | |
493 | return (const void *) borrow_enumeration_field_class_mapping_by_label( | |
494 | (const void *) fc, label); | |
495 | } | |
939190b3 | 496 | |
02b61fe0 PP |
497 | const char *bt_field_class_enumeration_mapping_get_label( |
498 | const struct bt_field_class_enumeration_mapping *mapping) | |
499 | { | |
500 | BT_ASSERT_PRE_DEV_NON_NULL(mapping, "Enumeration field class mapping"); | |
501 | return mapping->label->str; | |
939190b3 PP |
502 | } |
503 | ||
02b61fe0 | 504 | const struct bt_integer_range_set_unsigned * |
60bbfc7c PP |
505 | bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( |
506 | const struct bt_field_class_enumeration_unsigned_mapping *u_mapping) | |
939190b3 | 507 | { |
02b61fe0 PP |
508 | const struct bt_field_class_enumeration_mapping *mapping = |
509 | (const void *) u_mapping; | |
510 | ||
511 | BT_ASSERT_PRE_DEV_NON_NULL(mapping, "Enumeration field class mapping"); | |
512 | return (const void *) mapping->range_set; | |
939190b3 PP |
513 | } |
514 | ||
02b61fe0 | 515 | const struct bt_integer_range_set_signed * |
60bbfc7c PP |
516 | bt_field_class_enumeration_signed_mapping_borrow_ranges_const( |
517 | const struct bt_field_class_enumeration_signed_mapping *s_mapping) | |
939190b3 | 518 | { |
02b61fe0 PP |
519 | const struct bt_field_class_enumeration_mapping *mapping = |
520 | (const void *) s_mapping; | |
521 | ||
522 | BT_ASSERT_PRE_DEV_NON_NULL(mapping, "Enumeration field class mapping"); | |
523 | return (const void *) mapping->range_set; | |
939190b3 PP |
524 | } |
525 | ||
1091bb60 | 526 | enum bt_field_class_enumeration_get_mapping_labels_for_value_status |
60bbfc7c | 527 | bt_field_class_enumeration_unsigned_get_mapping_labels_for_value( |
78cf9df6 | 528 | const struct bt_field_class *fc, uint64_t value, |
939190b3 PP |
529 | bt_field_class_enumeration_mapping_label_array *label_array, |
530 | uint64_t *count) | |
531 | { | |
78cf9df6 | 532 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
939190b3 PP |
533 | uint64_t i; |
534 | ||
fa6cfec3 PP |
535 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
536 | BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)"); | |
537 | BT_ASSERT_PRE_DEV_NON_NULL(count, "Count (output)"); | |
538 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, | |
939190b3 PP |
539 | "Field class"); |
540 | g_ptr_array_set_size(enum_fc->label_buf, 0); | |
541 | ||
542 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
543 | uint64_t j; | |
78cf9df6 | 544 | const struct bt_field_class_enumeration_mapping *mapping = |
939190b3 PP |
545 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); |
546 | ||
02b61fe0 PP |
547 | for (j = 0; j < mapping->range_set->ranges->len; j++) { |
548 | const struct bt_integer_range *range = (const void *) | |
549 | BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
550 | mapping->range_set, j); | |
939190b3 PP |
551 | |
552 | if (value >= range->lower.u && | |
553 | value <= range->upper.u) { | |
554 | g_ptr_array_add(enum_fc->label_buf, | |
555 | mapping->label->str); | |
556 | break; | |
557 | } | |
558 | } | |
559 | } | |
560 | ||
561 | *label_array = (void *) enum_fc->label_buf->pdata; | |
562 | *count = (uint64_t) enum_fc->label_buf->len; | |
fb25b9e3 | 563 | return BT_FUNC_STATUS_OK; |
939190b3 PP |
564 | } |
565 | ||
1091bb60 | 566 | enum bt_field_class_enumeration_get_mapping_labels_for_value_status |
60bbfc7c | 567 | bt_field_class_enumeration_signed_get_mapping_labels_for_value( |
78cf9df6 | 568 | const struct bt_field_class *fc, int64_t value, |
939190b3 PP |
569 | bt_field_class_enumeration_mapping_label_array *label_array, |
570 | uint64_t *count) | |
571 | { | |
78cf9df6 | 572 | const struct bt_field_class_enumeration *enum_fc = (const void *) fc; |
939190b3 PP |
573 | uint64_t i; |
574 | ||
fa6cfec3 PP |
575 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
576 | BT_ASSERT_PRE_DEV_NON_NULL(label_array, "Label array (output)"); | |
577 | BT_ASSERT_PRE_DEV_NON_NULL(count, "Count (output)"); | |
578 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, | |
939190b3 PP |
579 | "Field class"); |
580 | g_ptr_array_set_size(enum_fc->label_buf, 0); | |
581 | ||
582 | for (i = 0; i < enum_fc->mappings->len; i++) { | |
583 | uint64_t j; | |
78cf9df6 | 584 | const struct bt_field_class_enumeration_mapping *mapping = |
939190b3 PP |
585 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); |
586 | ||
02b61fe0 PP |
587 | for (j = 0; j < mapping->range_set->ranges->len; j++) { |
588 | const struct bt_integer_range *range = (const void *) | |
589 | BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
590 | mapping->range_set, j); | |
939190b3 PP |
591 | |
592 | if (value >= range->lower.i && | |
593 | value <= range->upper.i) { | |
594 | g_ptr_array_add(enum_fc->label_buf, | |
595 | mapping->label->str); | |
596 | break; | |
597 | } | |
598 | } | |
599 | } | |
600 | ||
601 | *label_array = (void *) enum_fc->label_buf->pdata; | |
602 | *count = (uint64_t) enum_fc->label_buf->len; | |
fb25b9e3 | 603 | return BT_FUNC_STATUS_OK; |
939190b3 PP |
604 | } |
605 | ||
02b61fe0 PP |
606 | static |
607 | bool enumeration_field_class_has_mapping_with_label( | |
608 | const struct bt_field_class_enumeration *enum_fc, | |
609 | const char *label) | |
939190b3 | 610 | { |
939190b3 | 611 | uint64_t i; |
02b61fe0 | 612 | bool exists = false; |
939190b3 | 613 | |
02b61fe0 PP |
614 | BT_ASSERT(enum_fc); |
615 | BT_ASSERT(label); | |
939190b3 | 616 | |
939190b3 PP |
617 | for (i = 0; i < enum_fc->mappings->len; i++) { |
618 | struct bt_field_class_enumeration_mapping *mapping_candidate = | |
619 | BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc, i); | |
620 | ||
621 | if (strcmp(mapping_candidate->label->str, label) == 0) { | |
02b61fe0 PP |
622 | exists = true; |
623 | goto end; | |
939190b3 PP |
624 | } |
625 | } | |
626 | ||
02b61fe0 PP |
627 | end: |
628 | return exists; | |
629 | } | |
939190b3 | 630 | |
02b61fe0 PP |
631 | static inline |
632 | enum bt_field_class_enumeration_add_mapping_status | |
633 | add_mapping_to_enumeration_field_class(struct bt_field_class *fc, | |
634 | const char *label, const struct bt_integer_range_set *range_set) | |
635 | { | |
636 | enum bt_field_class_enumeration_add_mapping_status status = | |
637 | BT_FUNC_STATUS_OK; | |
638 | struct bt_field_class_enumeration *enum_fc = (void *) fc; | |
639 | struct bt_field_class_enumeration_mapping mapping = { 0 }; | |
640 | ||
641 | BT_ASSERT(fc); | |
642 | BT_ASSERT_PRE_NON_NULL(label, "Label"); | |
88efd0a7 | 643 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); |
02b61fe0 PP |
644 | BT_ASSERT_PRE(!enumeration_field_class_has_mapping_with_label( |
645 | enum_fc, label), | |
646 | "Duplicate mapping name in enumeration field class: " | |
647 | "%![enum-fc-]+F, label=\"%s\"", fc, label); | |
648 | mapping.range_set = range_set; | |
649 | bt_object_get_ref(mapping.range_set); | |
650 | mapping.label = g_string_new(label); | |
651 | if (!mapping.label) { | |
652 | finalize_enumeration_field_class_mapping(&mapping); | |
653 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
654 | goto end; | |
939190b3 PP |
655 | } |
656 | ||
02b61fe0 | 657 | g_array_append_val(enum_fc->mappings, mapping); |
a684a357 | 658 | BT_LIB_LOGD("Added mapping to enumeration field class: " |
02b61fe0 | 659 | "%![fc-]+F, label=\"%s\"", fc, label); |
939190b3 PP |
660 | |
661 | end: | |
02b61fe0 | 662 | return status; |
939190b3 PP |
663 | } |
664 | ||
02b61fe0 | 665 | enum bt_field_class_enumeration_add_mapping_status |
60bbfc7c | 666 | bt_field_class_enumeration_unsigned_add_mapping( |
78cf9df6 | 667 | struct bt_field_class *fc, const char *label, |
02b61fe0 | 668 | const struct bt_integer_range_set_unsigned *range_set) |
939190b3 | 669 | { |
939190b3 | 670 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
af0c18e3 | 671 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, |
939190b3 | 672 | "Field class"); |
02b61fe0 PP |
673 | return add_mapping_to_enumeration_field_class(fc, label, |
674 | (const void *) range_set); | |
675 | } | |
676 | ||
677 | enum bt_field_class_enumeration_add_mapping_status | |
60bbfc7c | 678 | bt_field_class_enumeration_signed_add_mapping( |
78cf9df6 | 679 | struct bt_field_class *fc, const char *label, |
02b61fe0 | 680 | const struct bt_integer_range_set_signed *range_set) |
939190b3 | 681 | { |
939190b3 | 682 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
af0c18e3 | 683 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, |
939190b3 | 684 | "Field class"); |
02b61fe0 PP |
685 | return add_mapping_to_enumeration_field_class(fc, label, |
686 | (const void *) range_set); | |
939190b3 PP |
687 | } |
688 | ||
689 | static | |
690 | void destroy_real_field_class(struct bt_object *obj) | |
691 | { | |
692 | BT_ASSERT(obj); | |
9e550e5f | 693 | BT_LIB_LOGD("Destroying real field class object: %!+F", obj); |
af90138b | 694 | finalize_field_class((void *) obj); |
939190b3 PP |
695 | g_free(obj); |
696 | } | |
697 | ||
76276a81 FD |
698 | static |
699 | struct bt_field_class *create_real_field_class(bt_trace_class *trace_class, | |
700 | enum bt_field_class_type type) | |
939190b3 PP |
701 | { |
702 | struct bt_field_class_real *real_fc = NULL; | |
703 | ||
b7396828 | 704 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
76276a81 FD |
705 | BT_LOGD("Creating default real field class object: type=%s", |
706 | bt_common_field_class_type_string(type)); | |
939190b3 PP |
707 | real_fc = g_new0(struct bt_field_class_real, 1); |
708 | if (!real_fc) { | |
a8f90e5d | 709 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class."); |
939190b3 PP |
710 | goto error; |
711 | } | |
712 | ||
76276a81 | 713 | if (init_field_class((void *) real_fc, type, destroy_real_field_class)) { |
af90138b PP |
714 | goto error; |
715 | } | |
716 | ||
9e550e5f | 717 | BT_LIB_LOGD("Created real field class object: %!+F", real_fc); |
939190b3 PP |
718 | goto end; |
719 | ||
720 | error: | |
8138bfe1 | 721 | BT_OBJECT_PUT_REF_AND_RESET(real_fc); |
939190b3 PP |
722 | |
723 | end: | |
724 | return (void *) real_fc; | |
725 | } | |
726 | ||
76276a81 FD |
727 | struct bt_field_class *bt_field_class_real_single_precision_create( |
728 | bt_trace_class *trace_class) | |
939190b3 | 729 | { |
76276a81 FD |
730 | return create_real_field_class(trace_class, |
731 | BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL); | |
939190b3 PP |
732 | } |
733 | ||
76276a81 FD |
734 | struct bt_field_class *bt_field_class_real_double_precision_create( |
735 | bt_trace_class *trace_class) | |
939190b3 | 736 | { |
76276a81 FD |
737 | return create_real_field_class(trace_class, |
738 | BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL); | |
939190b3 PP |
739 | } |
740 | ||
741 | static | |
742 | int init_named_field_classes_container( | |
743 | struct bt_field_class_named_field_class_container *fc, | |
78cf9df6 | 744 | enum bt_field_class_type type, |
02b61fe0 PP |
745 | bt_object_release_func fc_release_func, |
746 | GDestroyNotify named_fc_destroy_func) | |
939190b3 PP |
747 | { |
748 | int ret = 0; | |
749 | ||
af90138b PP |
750 | ret = init_field_class((void *) fc, type, fc_release_func); |
751 | if (ret) { | |
752 | goto end; | |
753 | } | |
754 | ||
02b61fe0 | 755 | fc->named_fcs = g_ptr_array_new_with_free_func(named_fc_destroy_func); |
939190b3 | 756 | if (!fc->named_fcs) { |
02b61fe0 | 757 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); |
939190b3 PP |
758 | ret = -1; |
759 | goto end; | |
760 | } | |
761 | ||
762 | fc->name_to_index = g_hash_table_new(g_str_hash, g_str_equal); | |
763 | if (!fc->name_to_index) { | |
a8f90e5d | 764 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable."); |
939190b3 PP |
765 | ret = -1; |
766 | goto end; | |
767 | } | |
768 | ||
769 | end: | |
770 | return ret; | |
771 | } | |
772 | ||
773 | static | |
774 | void finalize_named_field_class(struct bt_named_field_class *named_fc) | |
775 | { | |
776 | BT_ASSERT(named_fc); | |
9e550e5f | 777 | BT_LIB_LOGD("Finalizing named field class: " |
939190b3 PP |
778 | "addr=%p, name=\"%s\", %![fc-]+F", |
779 | named_fc, named_fc->name ? named_fc->name->str : NULL, | |
780 | named_fc->fc); | |
af90138b | 781 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->user_attributes); |
939190b3 PP |
782 | |
783 | if (named_fc->name) { | |
784 | g_string_free(named_fc->name, TRUE); | |
02b61fe0 | 785 | named_fc->name = NULL; |
939190b3 PP |
786 | } |
787 | ||
9e550e5f | 788 | BT_LOGD_STR("Putting named field class's field class."); |
1248f5ea | 789 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->fc); |
939190b3 PP |
790 | } |
791 | ||
02b61fe0 PP |
792 | static |
793 | void destroy_named_field_class(gpointer ptr) | |
794 | { | |
af90138b PP |
795 | struct bt_named_field_class *named_fc = ptr; |
796 | ||
02b61fe0 | 797 | if (ptr) { |
560d197d | 798 | BT_OBJECT_PUT_REF_AND_RESET(named_fc->user_attributes); |
02b61fe0 PP |
799 | finalize_named_field_class(ptr); |
800 | g_free(ptr); | |
801 | } | |
802 | } | |
803 | ||
804 | static | |
8bc207af | 805 | void destroy_variant_with_selector_field_option(gpointer ptr) |
02b61fe0 | 806 | { |
8bc207af | 807 | struct bt_field_class_variant_with_selector_field_option *opt = ptr; |
02b61fe0 PP |
808 | |
809 | if (ptr) { | |
810 | finalize_named_field_class(&opt->common); | |
811 | BT_OBJECT_PUT_REF_AND_RESET(opt->range_set); | |
812 | g_free(ptr); | |
813 | } | |
814 | } | |
815 | ||
939190b3 PP |
816 | static |
817 | void finalize_named_field_classes_container( | |
818 | struct bt_field_class_named_field_class_container *fc) | |
819 | { | |
939190b3 PP |
820 | BT_ASSERT(fc); |
821 | ||
822 | if (fc->named_fcs) { | |
02b61fe0 PP |
823 | g_ptr_array_free(fc->named_fcs, TRUE); |
824 | fc->named_fcs = NULL; | |
939190b3 | 825 | |
939190b3 PP |
826 | } |
827 | ||
828 | if (fc->name_to_index) { | |
829 | g_hash_table_destroy(fc->name_to_index); | |
02b61fe0 | 830 | fc->name_to_index = NULL; |
939190b3 PP |
831 | } |
832 | } | |
833 | ||
834 | static | |
835 | void destroy_structure_field_class(struct bt_object *obj) | |
836 | { | |
837 | BT_ASSERT(obj); | |
2d95225e | 838 | BT_LIB_LOGD("Destroying structure field class object: %!+F", obj); |
af90138b | 839 | finalize_field_class((void *) obj); |
939190b3 PP |
840 | finalize_named_field_classes_container((void *) obj); |
841 | g_free(obj); | |
842 | } | |
843 | ||
b7396828 PP |
844 | struct bt_field_class *bt_field_class_structure_create( |
845 | bt_trace_class *trace_class) | |
939190b3 PP |
846 | { |
847 | int ret; | |
848 | struct bt_field_class_structure *struct_fc = NULL; | |
849 | ||
b7396828 | 850 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
9e550e5f | 851 | BT_LOGD_STR("Creating default structure field class object."); |
939190b3 PP |
852 | struct_fc = g_new0(struct bt_field_class_structure, 1); |
853 | if (!struct_fc) { | |
a8f90e5d PP |
854 | BT_LIB_LOGE_APPEND_CAUSE( |
855 | "Failed to allocate one structure field class."); | |
939190b3 PP |
856 | goto error; |
857 | } | |
858 | ||
859 | ret = init_named_field_classes_container((void *) struct_fc, | |
02b61fe0 PP |
860 | BT_FIELD_CLASS_TYPE_STRUCTURE, destroy_structure_field_class, |
861 | destroy_named_field_class); | |
939190b3 | 862 | if (ret) { |
02b61fe0 | 863 | /* init_named_field_classes_container() logs errors */ |
939190b3 PP |
864 | goto error; |
865 | } | |
866 | ||
9e550e5f | 867 | BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc); |
939190b3 PP |
868 | goto end; |
869 | ||
870 | error: | |
8138bfe1 | 871 | BT_OBJECT_PUT_REF_AND_RESET(struct_fc); |
939190b3 PP |
872 | |
873 | end: | |
874 | return (void *) struct_fc; | |
875 | } | |
876 | ||
877 | static | |
02b61fe0 | 878 | int init_named_field_class(struct bt_named_field_class *named_fc, |
939190b3 PP |
879 | const char *name, struct bt_field_class *fc) |
880 | { | |
02b61fe0 | 881 | int status = BT_FUNC_STATUS_OK; |
939190b3 | 882 | |
02b61fe0 PP |
883 | BT_ASSERT(named_fc); |
884 | BT_ASSERT(name); | |
885 | BT_ASSERT(fc); | |
886 | named_fc->name = g_string_new(name); | |
887 | if (!named_fc->name) { | |
a8f90e5d | 888 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
02b61fe0 | 889 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
939190b3 PP |
890 | goto end; |
891 | } | |
892 | ||
af90138b PP |
893 | named_fc->user_attributes = bt_value_map_create(); |
894 | if (!named_fc->user_attributes) { | |
895 | BT_LIB_LOGE_APPEND_CAUSE( | |
896 | "Failed to create a map value object."); | |
897 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
898 | goto end; | |
899 | } | |
900 | ||
4b70020d | 901 | named_fc->fc = fc; |
864aa43f | 902 | bt_object_get_ref_no_null_check(named_fc->fc); |
e24f271a | 903 | |
02b61fe0 PP |
904 | end: |
905 | return status; | |
906 | } | |
907 | ||
908 | static | |
909 | struct bt_named_field_class *create_named_field_class(const char *name, | |
910 | struct bt_field_class *fc) | |
911 | { | |
912 | struct bt_named_field_class *named_fc = g_new0( | |
913 | struct bt_named_field_class, 1); | |
914 | ||
915 | if (!named_fc) { | |
916 | BT_LIB_LOGE_APPEND_CAUSE( | |
917 | "Failed to allocate a named field class."); | |
918 | goto error; | |
919 | } | |
920 | ||
921 | if (init_named_field_class(named_fc, name, fc)) { | |
922 | /* init_named_field_class() logs errors */ | |
923 | goto error; | |
924 | } | |
925 | ||
926 | goto end; | |
927 | ||
928 | error: | |
929 | destroy_named_field_class(named_fc); | |
930 | named_fc = NULL; | |
939190b3 PP |
931 | |
932 | end: | |
02b61fe0 PP |
933 | return named_fc; |
934 | } | |
935 | ||
936 | static | |
8bc207af PP |
937 | struct bt_field_class_variant_with_selector_field_option * |
938 | create_variant_with_selector_field_option( | |
02b61fe0 PP |
939 | const char *name, struct bt_field_class *fc, |
940 | const struct bt_integer_range_set *range_set) | |
941 | { | |
8bc207af PP |
942 | struct bt_field_class_variant_with_selector_field_option *opt = g_new0( |
943 | struct bt_field_class_variant_with_selector_field_option, 1); | |
02b61fe0 PP |
944 | |
945 | BT_ASSERT(range_set); | |
946 | ||
947 | if (!opt) { | |
948 | BT_LIB_LOGE_APPEND_CAUSE( | |
949 | "Failed to allocate a named field class."); | |
950 | goto error; | |
951 | } | |
952 | ||
953 | if (init_named_field_class(&opt->common, name, fc)) { | |
954 | goto error; | |
955 | } | |
956 | ||
957 | opt->range_set = range_set; | |
864aa43f | 958 | bt_object_get_ref_no_null_check(opt->range_set); |
02b61fe0 PP |
959 | bt_integer_range_set_freeze(range_set); |
960 | goto end; | |
961 | ||
962 | error: | |
8bc207af | 963 | destroy_variant_with_selector_field_option(opt); |
02b61fe0 PP |
964 | opt = NULL; |
965 | ||
966 | end: | |
967 | return opt; | |
968 | } | |
969 | ||
970 | static | |
971 | int append_named_field_class_to_container_field_class( | |
972 | struct bt_field_class_named_field_class_container *container_fc, | |
973 | struct bt_named_field_class *named_fc) | |
974 | { | |
975 | BT_ASSERT(container_fc); | |
976 | BT_ASSERT(named_fc); | |
977 | BT_ASSERT_PRE_DEV_FC_HOT(container_fc, "Field class"); | |
978 | BT_ASSERT_PRE(!bt_g_hash_table_contains(container_fc->name_to_index, | |
979 | named_fc->name->str), | |
980 | "Duplicate member/option name in structure/variant field class: " | |
981 | "%![container-fc-]+F, name=\"%s\"", container_fc, | |
982 | named_fc->name->str); | |
af90138b PP |
983 | |
984 | /* | |
985 | * Freeze the contained field class, but not the named field | |
986 | * class itself, as it's still possible afterwards to modify | |
987 | * properties of the member/option object. | |
988 | */ | |
989 | bt_field_class_freeze(named_fc->fc); | |
02b61fe0 PP |
990 | g_ptr_array_add(container_fc->named_fcs, named_fc); |
991 | g_hash_table_insert(container_fc->name_to_index, named_fc->name->str, | |
992 | GUINT_TO_POINTER(container_fc->named_fcs->len - 1)); | |
993 | return BT_FUNC_STATUS_OK; | |
939190b3 PP |
994 | } |
995 | ||
fb25b9e3 PP |
996 | enum bt_field_class_structure_append_member_status |
997 | bt_field_class_structure_append_member( | |
4b514ab3 PP |
998 | struct bt_field_class *fc, const char *name, |
999 | struct bt_field_class *member_fc) | |
939190b3 | 1000 | { |
02b61fe0 PP |
1001 | enum bt_field_class_structure_append_member_status status; |
1002 | struct bt_named_field_class *named_fc = NULL; | |
9e550e5f | 1003 | |
939190b3 | 1004 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
909d0a89 PP |
1005 | BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, |
1006 | "Field class"); | |
02b61fe0 PP |
1007 | named_fc = create_named_field_class(name, member_fc); |
1008 | if (!named_fc) { | |
1009 | /* create_named_field_class() logs errors */ | |
1010 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1011 | goto end; | |
1012 | } | |
1013 | ||
1014 | status = append_named_field_class_to_container_field_class((void *) fc, | |
1015 | named_fc); | |
1016 | if (status == BT_FUNC_STATUS_OK) { | |
1017 | /* Moved to the container */ | |
1018 | named_fc = NULL; | |
1019 | } | |
1020 | ||
1021 | end: | |
1022 | return status; | |
939190b3 PP |
1023 | } |
1024 | ||
78cf9df6 PP |
1025 | uint64_t bt_field_class_structure_get_member_count( |
1026 | const struct bt_field_class *fc) | |
939190b3 PP |
1027 | { |
1028 | struct bt_field_class_structure *struct_fc = (void *) fc; | |
1029 | ||
fa6cfec3 PP |
1030 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1031 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
909d0a89 | 1032 | "Field class"); |
939190b3 PP |
1033 | return (uint64_t) struct_fc->common.named_fcs->len; |
1034 | } | |
1035 | ||
1036 | static | |
e24f271a PP |
1037 | struct bt_named_field_class * |
1038 | borrow_named_field_class_from_container_field_class_at_index( | |
909d0a89 | 1039 | struct bt_field_class_named_field_class_container *fc, |
e24f271a | 1040 | uint64_t index) |
939190b3 | 1041 | { |
ec4a3354 | 1042 | BT_ASSERT_DBG(fc); |
fa6cfec3 | 1043 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, fc->named_fcs->len); |
02b61fe0 | 1044 | return fc->named_fcs->pdata[index]; |
939190b3 PP |
1045 | } |
1046 | ||
e24f271a PP |
1047 | const struct bt_field_class_structure_member * |
1048 | bt_field_class_structure_borrow_member_by_index_const( | |
1049 | const struct bt_field_class *fc, uint64_t index) | |
939190b3 | 1050 | { |
fa6cfec3 PP |
1051 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1052 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
909d0a89 | 1053 | "Field class"); |
e24f271a PP |
1054 | return (const void *) |
1055 | borrow_named_field_class_from_container_field_class_at_index( | |
1056 | (void *) fc, index); | |
909d0a89 PP |
1057 | } |
1058 | ||
e24f271a PP |
1059 | struct bt_field_class_structure_member * |
1060 | bt_field_class_structure_borrow_member_by_index( | |
1061 | struct bt_field_class *fc, uint64_t index) | |
909d0a89 | 1062 | { |
fa6cfec3 PP |
1063 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1064 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
909d0a89 | 1065 | "Field class"); |
e24f271a PP |
1066 | return (void *) |
1067 | borrow_named_field_class_from_container_field_class_at_index( | |
1068 | (void *) fc, index); | |
9e550e5f PP |
1069 | } |
1070 | ||
939190b3 | 1071 | static |
e24f271a PP |
1072 | struct bt_named_field_class * |
1073 | borrow_named_field_class_from_container_field_class_by_name( | |
909d0a89 | 1074 | struct bt_field_class_named_field_class_container *fc, |
939190b3 PP |
1075 | const char *name) |
1076 | { | |
e24f271a | 1077 | struct bt_named_field_class *named_fc = NULL; |
939190b3 PP |
1078 | gpointer orig_key; |
1079 | gpointer value; | |
1080 | ||
ec4a3354 | 1081 | BT_ASSERT_DBG(fc); |
fa6cfec3 | 1082 | BT_ASSERT_PRE_DEV_NON_NULL(name, "Name"); |
939190b3 PP |
1083 | if (!g_hash_table_lookup_extended(fc->name_to_index, name, &orig_key, |
1084 | &value)) { | |
1085 | goto end; | |
1086 | } | |
1087 | ||
02b61fe0 | 1088 | named_fc = fc->named_fcs->pdata[GPOINTER_TO_UINT(value)]; |
939190b3 PP |
1089 | |
1090 | end: | |
e24f271a | 1091 | return named_fc; |
939190b3 PP |
1092 | } |
1093 | ||
e24f271a | 1094 | const struct bt_field_class_structure_member * |
c0db9072 | 1095 | bt_field_class_structure_borrow_member_by_name_const( |
78cf9df6 | 1096 | const struct bt_field_class *fc, const char *name) |
939190b3 | 1097 | { |
fa6cfec3 PP |
1098 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1099 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
909d0a89 | 1100 | "Field class"); |
e24f271a PP |
1101 | return (const void *) |
1102 | borrow_named_field_class_from_container_field_class_by_name( | |
909d0a89 PP |
1103 | (void *) fc, name); |
1104 | } | |
1105 | ||
e24f271a | 1106 | struct bt_field_class_structure_member * |
fe65b1fe | 1107 | bt_field_class_structure_borrow_member_by_name( |
909d0a89 PP |
1108 | struct bt_field_class *fc, const char *name) |
1109 | { | |
fa6cfec3 PP |
1110 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1111 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, | |
909d0a89 | 1112 | "Field class"); |
e24f271a PP |
1113 | return (void *) |
1114 | borrow_named_field_class_from_container_field_class_by_name( | |
78cf9df6 | 1115 | (void *) fc, name); |
9e550e5f PP |
1116 | } |
1117 | ||
e24f271a PP |
1118 | const char *bt_field_class_structure_member_get_name( |
1119 | const struct bt_field_class_structure_member *member) | |
1120 | { | |
1121 | const struct bt_named_field_class *named_fc = (const void *) member; | |
1122 | ||
fa6cfec3 | 1123 | BT_ASSERT_PRE_DEV_NON_NULL(member, "Structure field class member"); |
e24f271a PP |
1124 | return named_fc->name->str; |
1125 | } | |
1126 | ||
1127 | const struct bt_field_class * | |
1128 | bt_field_class_structure_member_borrow_field_class_const( | |
1129 | const struct bt_field_class_structure_member *member) | |
1130 | { | |
1131 | const struct bt_named_field_class *named_fc = (const void *) member; | |
1132 | ||
fa6cfec3 | 1133 | BT_ASSERT_PRE_DEV_NON_NULL(member, "Structure field class member"); |
e24f271a PP |
1134 | return named_fc->fc; |
1135 | } | |
1136 | ||
87040955 FD |
1137 | struct bt_field_class * |
1138 | bt_field_class_structure_member_borrow_field_class( | |
1139 | struct bt_field_class_structure_member *member) | |
1140 | { | |
1141 | struct bt_named_field_class *named_fc = (void *) member; | |
1142 | ||
1143 | BT_ASSERT_PRE_DEV_NON_NULL(member, "Structure field class member"); | |
1144 | return named_fc->fc; | |
1145 | } | |
1146 | ||
247fa9e3 PP |
1147 | static |
1148 | void destroy_option_field_class(struct bt_object *obj) | |
1149 | { | |
1150 | struct bt_field_class_option *fc = (void *) obj; | |
1151 | ||
1152 | BT_ASSERT(fc); | |
1153 | BT_LIB_LOGD("Destroying option field class object: %!+F", fc); | |
af90138b | 1154 | finalize_field_class((void *) obj); |
247fa9e3 PP |
1155 | BT_LOGD_STR("Putting content field class."); |
1156 | BT_OBJECT_PUT_REF_AND_RESET(fc->content_fc); | |
467673c1 | 1157 | |
8bc207af PP |
1158 | if (fc->common.type != BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD) { |
1159 | struct bt_field_class_option_with_selector_field *with_sel_fc = | |
467673c1 PP |
1160 | (void *) obj; |
1161 | ||
1162 | BT_LOGD_STR("Putting selector field path."); | |
1163 | BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc->selector_field_path); | |
1164 | BT_LOGD_STR("Putting selector field class."); | |
1165 | BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc->selector_fc); | |
1166 | ||
8bc207af PP |
1167 | if (fc->common.type != BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD) { |
1168 | struct bt_field_class_option_with_selector_field_integer *with_int_sel_fc = | |
467673c1 PP |
1169 | (void *) obj; |
1170 | ||
1171 | BT_LOGD_STR("Putting integer range set."); | |
1172 | BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc->range_set); | |
1173 | } | |
1174 | } | |
1175 | ||
247fa9e3 PP |
1176 | g_free(fc); |
1177 | } | |
1178 | ||
467673c1 PP |
1179 | static |
1180 | struct bt_field_class *create_option_field_class( | |
1181 | struct bt_trace_class *trace_class, | |
1182 | enum bt_field_class_type fc_type, | |
1183 | struct bt_field_class *content_fc, | |
1184 | struct bt_field_class *selector_fc) | |
247fa9e3 PP |
1185 | { |
1186 | struct bt_field_class_option *opt_fc = NULL; | |
1187 | ||
1188 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); | |
1189 | BT_ASSERT_PRE_NON_NULL(content_fc, "Content field class"); | |
1190 | BT_LIB_LOGD("Creating option field class: " | |
467673c1 PP |
1191 | "type=%s, %![content-fc-]+F, %![sel-fc-]+F", |
1192 | bt_common_field_class_type_string(fc_type), | |
1193 | content_fc, selector_fc); | |
1194 | ||
8bc207af PP |
1195 | if (fc_type != BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD) { |
1196 | struct bt_field_class_option_with_selector_field *opt_with_sel_fc = NULL; | |
467673c1 PP |
1197 | |
1198 | BT_ASSERT_PRE_NON_NULL(selector_fc, "Selector field class"); | |
1199 | ||
8bc207af | 1200 | if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD) { |
467673c1 PP |
1201 | BT_ASSERT_PRE_FC_HAS_ID(selector_fc, |
1202 | BT_FIELD_CLASS_TYPE_BOOL, | |
1203 | "Selector field class"); | |
1204 | opt_with_sel_fc = (void *) g_new0( | |
8bc207af | 1205 | struct bt_field_class_option_with_selector_field_bool, 1); |
467673c1 PP |
1206 | } else { |
1207 | BT_ASSERT_PRE_FC_IS_INT(selector_fc, | |
1208 | "Selector field class"); | |
1209 | opt_with_sel_fc = (void *) g_new0( | |
8bc207af | 1210 | struct bt_field_class_option_with_selector_field_integer, 1); |
467673c1 PP |
1211 | } |
1212 | ||
1213 | if (!opt_with_sel_fc) { | |
1214 | BT_LIB_LOGE_APPEND_CAUSE( | |
1215 | "Failed to allocate one option with selector field class."); | |
1216 | goto error; | |
1217 | } | |
1218 | ||
1219 | opt_with_sel_fc->selector_fc = selector_fc; | |
864aa43f | 1220 | bt_object_get_ref_no_null_check(opt_with_sel_fc->selector_fc); |
467673c1 PP |
1221 | opt_fc = (void *) opt_with_sel_fc; |
1222 | } else { | |
1223 | opt_fc = g_new0(struct bt_field_class_option, 1); | |
1224 | if (!opt_fc) { | |
1225 | BT_LIB_LOGE_APPEND_CAUSE( | |
1226 | "Failed to allocate one option field class."); | |
1227 | goto error; | |
1228 | } | |
247fa9e3 PP |
1229 | } |
1230 | ||
467673c1 PP |
1231 | BT_ASSERT(opt_fc); |
1232 | ||
1233 | if (init_field_class((void *) opt_fc, fc_type, | |
af90138b PP |
1234 | destroy_option_field_class)) { |
1235 | goto error; | |
1236 | } | |
1237 | ||
247fa9e3 | 1238 | opt_fc->content_fc = content_fc; |
864aa43f | 1239 | bt_object_get_ref_no_null_check(opt_fc->content_fc); |
247fa9e3 PP |
1240 | bt_field_class_freeze(opt_fc->content_fc); |
1241 | ||
1242 | if (selector_fc) { | |
247fa9e3 PP |
1243 | bt_field_class_freeze(selector_fc); |
1244 | } | |
1245 | ||
1246 | BT_LIB_LOGD("Created option field class object: " | |
1247 | "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc, selector_fc); | |
1248 | goto end; | |
1249 | ||
1250 | error: | |
1251 | BT_OBJECT_PUT_REF_AND_RESET(opt_fc); | |
1252 | ||
1253 | end: | |
1254 | return (void *) opt_fc; | |
1255 | } | |
1256 | ||
467673c1 PP |
1257 | struct bt_field_class *bt_field_class_option_without_selector_create( |
1258 | struct bt_trace_class *trace_class, | |
1259 | struct bt_field_class *content_fc) | |
1260 | { | |
1261 | return create_option_field_class(trace_class, | |
8bc207af | 1262 | BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD, |
467673c1 PP |
1263 | content_fc, NULL); |
1264 | } | |
1265 | ||
8bc207af | 1266 | struct bt_field_class *bt_field_class_option_with_selector_field_bool_create( |
467673c1 PP |
1267 | struct bt_trace_class *trace_class, |
1268 | struct bt_field_class *content_fc, | |
1269 | struct bt_field_class *selector_fc) | |
1270 | { | |
8bc207af | 1271 | struct bt_field_class_option_with_selector_field_bool *fc = |
467673c1 | 1272 | (void *) create_option_field_class(trace_class, |
8bc207af | 1273 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, |
467673c1 PP |
1274 | content_fc, selector_fc); |
1275 | ||
1276 | if (!fc) { | |
1277 | goto end; | |
1278 | } | |
1279 | ||
1280 | end: | |
1281 | return (void *) fc; | |
1282 | } | |
1283 | ||
1284 | struct bt_field_class * | |
8bc207af | 1285 | bt_field_class_option_with_selector_field_integer_unsigned_create( |
467673c1 PP |
1286 | struct bt_trace_class *trace_class, |
1287 | struct bt_field_class *content_fc, | |
1288 | struct bt_field_class *selector_fc, | |
1289 | const struct bt_integer_range_set_unsigned *u_range_set) | |
1290 | { | |
8bc207af | 1291 | struct bt_field_class_option_with_selector_field_integer *fc; |
467673c1 PP |
1292 | const struct bt_integer_range_set *range_set = |
1293 | (const void *) u_range_set; | |
1294 | ||
1295 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); | |
1296 | BT_ASSERT_PRE(range_set->ranges->len > 0, | |
1297 | "Integer range set is empty: %!+R", range_set); | |
1298 | fc = (void *) create_option_field_class(trace_class, | |
8bc207af | 1299 | BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
467673c1 PP |
1300 | content_fc, selector_fc); |
1301 | ||
1302 | if (!fc) { | |
1303 | goto end; | |
1304 | } | |
1305 | ||
1306 | fc->range_set = range_set; | |
864aa43f | 1307 | bt_object_get_ref_no_null_check(fc->range_set); |
467673c1 PP |
1308 | bt_integer_range_set_freeze(range_set); |
1309 | ||
1310 | end: | |
1311 | return (void *) fc; | |
1312 | } | |
1313 | ||
1314 | struct bt_field_class * | |
8bc207af | 1315 | bt_field_class_option_with_selector_field_integer_signed_create( |
467673c1 PP |
1316 | struct bt_trace_class *trace_class, |
1317 | struct bt_field_class *content_fc, | |
1318 | struct bt_field_class *selector_fc, | |
1319 | const struct bt_integer_range_set_signed *i_range_set) | |
1320 | { | |
8bc207af | 1321 | struct bt_field_class_option_with_selector_field_integer *fc; |
467673c1 PP |
1322 | const struct bt_integer_range_set *range_set = |
1323 | (const void *) i_range_set; | |
1324 | ||
1325 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); | |
1326 | BT_ASSERT_PRE(range_set->ranges->len > 0, | |
1327 | "Integer range set is empty: %!+R", range_set); | |
1328 | fc = (void *) create_option_field_class(trace_class, | |
8bc207af | 1329 | BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
467673c1 PP |
1330 | content_fc, selector_fc); |
1331 | ||
1332 | if (!fc) { | |
1333 | goto end; | |
1334 | } | |
1335 | ||
1336 | fc->range_set = range_set; | |
864aa43f | 1337 | bt_object_get_ref_no_null_check(fc->range_set); |
467673c1 PP |
1338 | bt_integer_range_set_freeze(range_set); |
1339 | ||
1340 | end: | |
1341 | return (void *) fc; | |
1342 | } | |
1343 | ||
247fa9e3 PP |
1344 | const struct bt_field_class *bt_field_class_option_borrow_field_class_const( |
1345 | const struct bt_field_class *fc) | |
1346 | { | |
1347 | struct bt_field_class_option *opt_fc = (void *) fc; | |
1348 | ||
1349 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
467673c1 | 1350 | BT_ASSERT_PRE_FC_IS_OPTION(fc, "Field class"); |
247fa9e3 PP |
1351 | return opt_fc->content_fc; |
1352 | } | |
1353 | ||
87040955 FD |
1354 | struct bt_field_class *bt_field_class_option_borrow_field_class( |
1355 | struct bt_field_class *fc) | |
1356 | { | |
1357 | struct bt_field_class_option *opt_fc = (void *) fc; | |
1358 | ||
1359 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
467673c1 | 1360 | BT_ASSERT_PRE_FC_IS_OPTION(fc, "Field class"); |
87040955 FD |
1361 | return opt_fc->content_fc; |
1362 | } | |
1363 | ||
247fa9e3 | 1364 | const struct bt_field_path * |
8bc207af | 1365 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( |
247fa9e3 PP |
1366 | const struct bt_field_class *fc) |
1367 | { | |
8bc207af | 1368 | const struct bt_field_class_option_with_selector_field *opt_fc = |
467673c1 | 1369 | (const void *) fc; |
247fa9e3 PP |
1370 | |
1371 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
467673c1 | 1372 | BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(fc, "Field class"); |
247fa9e3 PP |
1373 | return opt_fc->selector_field_path; |
1374 | } | |
1375 | ||
8bc207af | 1376 | void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed( |
467673c1 PP |
1377 | struct bt_field_class *fc, bt_bool sel_is_reversed) |
1378 | { | |
8bc207af | 1379 | struct bt_field_class_option_with_selector_field_bool *opt_fc = (void *) fc; |
467673c1 PP |
1380 | |
1381 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1382 | BT_ASSERT_PRE_FC_HAS_ID(fc, | |
8bc207af | 1383 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, "Field class"); |
467673c1 PP |
1384 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); |
1385 | opt_fc->sel_is_reversed = sel_is_reversed; | |
1386 | } | |
1387 | ||
8bc207af | 1388 | bt_bool bt_field_class_option_with_selector_field_bool_selector_is_reversed( |
467673c1 PP |
1389 | const struct bt_field_class *fc) |
1390 | { | |
8bc207af | 1391 | struct bt_field_class_option_with_selector_field_bool *opt_fc = (void *) fc; |
467673c1 PP |
1392 | |
1393 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1394 | BT_ASSERT_PRE_FC_HAS_ID(fc, | |
8bc207af | 1395 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD, "Field class"); |
467673c1 PP |
1396 | return opt_fc->sel_is_reversed; |
1397 | } | |
1398 | ||
1399 | const struct bt_integer_range_set_unsigned * | |
8bc207af | 1400 | bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( |
467673c1 PP |
1401 | const struct bt_field_class *fc) |
1402 | { | |
8bc207af | 1403 | struct bt_field_class_option_with_selector_field_integer *opt_fc = |
467673c1 PP |
1404 | (void *) fc; |
1405 | ||
1406 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1407 | BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc, "Field class"); | |
1408 | return (const void *) opt_fc->range_set; | |
1409 | } | |
1410 | ||
1411 | const struct bt_integer_range_set_signed * | |
8bc207af | 1412 | bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( |
467673c1 PP |
1413 | const struct bt_field_class *fc) |
1414 | { | |
8bc207af | 1415 | struct bt_field_class_option_with_selector_field_integer *opt_fc = |
467673c1 PP |
1416 | (void *) fc; |
1417 | ||
1418 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1419 | BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc, "Field class"); | |
1420 | return (const void *) opt_fc->range_set; | |
1421 | } | |
1422 | ||
02b61fe0 PP |
1423 | static |
1424 | void finalize_variant_field_class(struct bt_field_class_variant *var_fc) | |
e24f271a | 1425 | { |
02b61fe0 PP |
1426 | BT_ASSERT(var_fc); |
1427 | BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc); | |
af90138b | 1428 | finalize_field_class((void *) var_fc); |
02b61fe0 | 1429 | finalize_named_field_classes_container((void *) var_fc); |
e24f271a PP |
1430 | } |
1431 | ||
939190b3 PP |
1432 | static |
1433 | void destroy_variant_field_class(struct bt_object *obj) | |
1434 | { | |
1435 | struct bt_field_class_variant *fc = (void *) obj; | |
1436 | ||
1437 | BT_ASSERT(fc); | |
02b61fe0 PP |
1438 | finalize_variant_field_class(fc); |
1439 | g_free(fc); | |
1440 | } | |
1441 | ||
1442 | static | |
8bc207af | 1443 | void destroy_variant_with_selector_field_field_class(struct bt_object *obj) |
02b61fe0 | 1444 | { |
8bc207af | 1445 | struct bt_field_class_variant_with_selector_field *fc = (void *) obj; |
02b61fe0 PP |
1446 | |
1447 | BT_ASSERT(fc); | |
1448 | finalize_variant_field_class(&fc->common); | |
939190b3 | 1449 | BT_LOGD_STR("Putting selector field path."); |
1248f5ea PP |
1450 | BT_OBJECT_PUT_REF_AND_RESET(fc->selector_field_path); |
1451 | BT_LOGD_STR("Putting selector field class."); | |
1452 | BT_OBJECT_PUT_REF_AND_RESET(fc->selector_fc); | |
939190b3 PP |
1453 | g_free(fc); |
1454 | } | |
1455 | ||
b7396828 | 1456 | struct bt_field_class *bt_field_class_variant_create( |
02b61fe0 | 1457 | bt_trace_class *trace_class, bt_field_class *selector_fc) |
939190b3 PP |
1458 | { |
1459 | int ret; | |
1460 | struct bt_field_class_variant *var_fc = NULL; | |
8bc207af | 1461 | struct bt_field_class_variant_with_selector_field *var_with_sel_fc = NULL; |
02b61fe0 | 1462 | enum bt_field_class_type fc_type; |
939190b3 | 1463 | |
b7396828 | 1464 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
02b61fe0 PP |
1465 | |
1466 | if (selector_fc) { | |
1467 | BT_ASSERT_PRE_FC_IS_INT(selector_fc, "Selector field class"); | |
939190b3 PP |
1468 | } |
1469 | ||
02b61fe0 PP |
1470 | BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F", |
1471 | selector_fc); | |
1472 | ||
1473 | if (selector_fc) { | |
1474 | var_with_sel_fc = g_new0( | |
8bc207af | 1475 | struct bt_field_class_variant_with_selector_field, 1); |
02b61fe0 PP |
1476 | if (!var_with_sel_fc) { |
1477 | BT_LIB_LOGE_APPEND_CAUSE( | |
1478 | "Failed to allocate one variant field class with selector."); | |
1479 | goto error; | |
1480 | } | |
1481 | ||
94847783 PP |
1482 | if (bt_field_class_type_is(selector_fc->type, |
1483 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) { | |
8bc207af | 1484 | fc_type = BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD; |
02b61fe0 | 1485 | } else { |
8bc207af | 1486 | fc_type = BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD; |
02b61fe0 PP |
1487 | } |
1488 | ||
1489 | ret = init_named_field_classes_container( | |
1490 | (void *) var_with_sel_fc, fc_type, | |
8bc207af PP |
1491 | destroy_variant_with_selector_field_field_class, |
1492 | destroy_variant_with_selector_field_option); | |
02b61fe0 PP |
1493 | if (ret) { |
1494 | /* init_named_field_classes_container() logs errors */ | |
1495 | goto error; | |
1496 | } | |
1497 | ||
1498 | var_with_sel_fc->selector_fc = selector_fc; | |
864aa43f | 1499 | bt_object_get_ref_no_null_check(var_with_sel_fc->selector_fc); |
02b61fe0 PP |
1500 | bt_field_class_freeze(selector_fc); |
1501 | var_fc = (void *) var_with_sel_fc; | |
ed47d321 FD |
1502 | BT_LIB_LOGD("Created default variant field class with selector object: " |
1503 | "%![var-fc-]+F, %![sel-fc-]+F", var_fc, selector_fc); | |
02b61fe0 PP |
1504 | } else { |
1505 | var_fc = g_new0(struct bt_field_class_variant, 1); | |
1506 | if (!var_fc) { | |
1507 | BT_LIB_LOGE_APPEND_CAUSE( | |
1508 | "Failed to allocate one variant field class without selector."); | |
1509 | goto error; | |
1510 | } | |
1511 | ||
1512 | ret = init_named_field_classes_container((void *) var_fc, | |
8bc207af | 1513 | BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD, |
02b61fe0 PP |
1514 | destroy_variant_field_class, destroy_named_field_class); |
1515 | if (ret) { | |
1516 | /* init_named_field_classes_container() logs errors */ | |
1517 | goto error; | |
1518 | } | |
ed47d321 FD |
1519 | BT_LIB_LOGD("Created default variant field class without selector object: " |
1520 | "%![var-fc-]+F", var_fc); | |
939190b3 PP |
1521 | } |
1522 | ||
02b61fe0 | 1523 | BT_ASSERT(var_fc); |
939190b3 PP |
1524 | goto end; |
1525 | ||
1526 | error: | |
8138bfe1 | 1527 | BT_OBJECT_PUT_REF_AND_RESET(var_fc); |
98b5e169 | 1528 | BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc); |
939190b3 PP |
1529 | |
1530 | end: | |
1531 | return (void *) var_fc; | |
1532 | } | |
1533 | ||
02b61fe0 PP |
1534 | enum bt_field_class_variant_without_selector_append_option_status |
1535 | bt_field_class_variant_without_selector_append_option(struct bt_field_class *fc, | |
1536 | const char *name, struct bt_field_class *option_fc) | |
1537 | { | |
1538 | enum bt_field_class_variant_without_selector_append_option_status status; | |
1539 | struct bt_named_field_class *named_fc = NULL; | |
1540 | ||
1541 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
1542 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
1543 | BT_ASSERT_PRE_NON_NULL(option_fc, "Option field class"); | |
1544 | BT_ASSERT_PRE_FC_HAS_ID(fc, | |
8bc207af | 1545 | BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD, "Field class"); |
02b61fe0 PP |
1546 | named_fc = create_named_field_class(name, option_fc); |
1547 | if (!named_fc) { | |
1548 | /* create_named_field_class() logs errors */ | |
1549 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1550 | goto end; | |
1551 | } | |
1552 | ||
1553 | status = append_named_field_class_to_container_field_class((void *) fc, | |
1554 | named_fc); | |
1555 | if (status == BT_FUNC_STATUS_OK) { | |
1556 | /* Moved to the container */ | |
1557 | named_fc = NULL; | |
1558 | } | |
1559 | ||
1560 | end: | |
1561 | if (named_fc) { | |
1562 | destroy_named_field_class(named_fc); | |
1563 | } | |
1564 | ||
1565 | return status; | |
939190b3 PP |
1566 | } |
1567 | ||
02b61fe0 PP |
1568 | static |
1569 | int ranges_overlap(GPtrArray *var_fc_opts, const struct bt_integer_range_set *range_set, | |
1570 | bool is_signed, bool *has_overlap) | |
1571 | { | |
1572 | int status = BT_FUNC_STATUS_OK; | |
1573 | struct bt_integer_range_set *full_range_set; | |
1574 | uint64_t i; | |
1575 | ||
1576 | *has_overlap = false; | |
1577 | ||
1578 | /* | |
1579 | * Build a single range set with all the ranges and test for | |
1580 | * overlaps. | |
1581 | */ | |
1582 | if (is_signed) { | |
1583 | full_range_set = (void *) bt_integer_range_set_signed_create(); | |
1584 | } else { | |
1585 | full_range_set = (void *) bt_integer_range_set_unsigned_create(); | |
1586 | } | |
1587 | ||
1588 | if (!full_range_set) { | |
1589 | BT_LOGE_STR("Failed to create a range set."); | |
1590 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1591 | goto end; | |
1592 | } | |
1593 | ||
1594 | /* Add existing option ranges */ | |
1595 | for (i = 0; i < var_fc_opts->len; i++) { | |
8bc207af | 1596 | struct bt_field_class_variant_with_selector_field_option *opt = |
02b61fe0 PP |
1597 | var_fc_opts->pdata[i]; |
1598 | uint64_t j; | |
1599 | ||
1600 | for (j = 0; j < opt->range_set->ranges->len; j++) { | |
1601 | struct bt_integer_range *range = BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
1602 | opt->range_set, j); | |
1603 | ||
1604 | if (is_signed) { | |
1605 | status = bt_integer_range_set_signed_add_range( | |
1606 | (void *) full_range_set, range->lower.i, | |
1607 | range->upper.i); | |
1608 | } else { | |
1609 | status = bt_integer_range_set_unsigned_add_range( | |
1610 | (void *) full_range_set, range->lower.u, | |
1611 | range->upper.u); | |
1612 | } | |
1613 | ||
1614 | if (status) { | |
1615 | goto end; | |
1616 | } | |
1617 | } | |
1618 | } | |
1619 | ||
1620 | /* Add new ranges */ | |
1621 | for (i = 0; i < range_set->ranges->len; i++) { | |
1622 | struct bt_integer_range *range = BT_INTEGER_RANGE_SET_RANGE_AT_INDEX( | |
1623 | range_set, i); | |
1624 | ||
1625 | if (is_signed) { | |
1626 | status = bt_integer_range_set_signed_add_range( | |
1627 | (void *) full_range_set, range->lower.i, | |
1628 | range->upper.i); | |
1629 | } else { | |
1630 | status = bt_integer_range_set_unsigned_add_range( | |
1631 | (void *) full_range_set, range->lower.u, | |
1632 | range->upper.u); | |
1633 | } | |
1634 | ||
1635 | if (status) { | |
1636 | goto end; | |
1637 | } | |
1638 | } | |
1639 | ||
1640 | /* Check overlaps */ | |
1641 | if (is_signed) { | |
1642 | *has_overlap = bt_integer_range_set_signed_has_overlaps(full_range_set); | |
1643 | } else { | |
1644 | *has_overlap = bt_integer_range_set_unsigned_has_overlaps( | |
1645 | full_range_set); | |
1646 | } | |
1647 | ||
1648 | end: | |
1649 | bt_object_put_ref(full_range_set); | |
1650 | return status; | |
1651 | } | |
1652 | ||
1653 | static | |
8bc207af | 1654 | int append_option_to_variant_with_selector_field_field_class( |
02b61fe0 PP |
1655 | struct bt_field_class *fc, const char *name, |
1656 | struct bt_field_class *option_fc, | |
1657 | const struct bt_integer_range_set *range_set, | |
1658 | enum bt_field_class_type expected_type) | |
939190b3 | 1659 | { |
02b61fe0 | 1660 | int status; |
8bc207af PP |
1661 | struct bt_field_class_variant_with_selector_field *var_fc = (void *) fc; |
1662 | struct bt_field_class_variant_with_selector_field_option *opt = NULL; | |
02b61fe0 | 1663 | bool has_overlap; |
9e550e5f | 1664 | |
939190b3 | 1665 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); |
02b61fe0 PP |
1666 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
1667 | BT_ASSERT_PRE_NON_NULL(option_fc, "Option field class"); | |
88efd0a7 | 1668 | BT_ASSERT_PRE_NON_NULL(range_set, "Integer range set"); |
02b61fe0 PP |
1669 | BT_ASSERT_PRE_FC_HAS_ID(fc, expected_type, "Field class"); |
1670 | BT_ASSERT_PRE(range_set->ranges->len > 0, | |
88efd0a7 | 1671 | "Integer range set is empty: %!+R", range_set); |
02b61fe0 | 1672 | status = ranges_overlap(var_fc->common.common.named_fcs, range_set, |
8bc207af | 1673 | expected_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
02b61fe0 PP |
1674 | &has_overlap); |
1675 | if (status) { | |
1676 | /* ranges_overlap() logs errors */ | |
1677 | goto end; | |
1678 | } | |
1679 | ||
1680 | BT_ASSERT_PRE(!has_overlap, | |
88efd0a7 PP |
1681 | "Integer range set's ranges and existing ranges have an overlap: " |
1682 | "%!+R", range_set); | |
8bc207af | 1683 | opt = create_variant_with_selector_field_option(name, option_fc, range_set); |
02b61fe0 | 1684 | if (!opt) { |
8bc207af | 1685 | /* create_variant_with_selector_field_option() logs errors */ |
02b61fe0 PP |
1686 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
1687 | goto end; | |
1688 | } | |
1689 | ||
1690 | status = append_named_field_class_to_container_field_class((void *) fc, | |
1691 | &opt->common); | |
1692 | if (status == BT_FUNC_STATUS_OK) { | |
1693 | /* Moved to the container */ | |
1694 | opt = NULL; | |
1695 | } | |
1696 | ||
1697 | end: | |
1698 | if (opt) { | |
8bc207af | 1699 | destroy_variant_with_selector_field_option(opt); |
02b61fe0 PP |
1700 | } |
1701 | ||
1702 | return status; | |
1703 | } | |
1704 | ||
8bc207af PP |
1705 | enum bt_field_class_variant_with_selector_field_integer_append_option_status |
1706 | bt_field_class_variant_with_selector_field_integer_unsigned_append_option( | |
02b61fe0 PP |
1707 | struct bt_field_class *fc, const char *name, |
1708 | struct bt_field_class *option_fc, | |
1709 | const struct bt_integer_range_set_unsigned *range_set) | |
1710 | { | |
8bc207af | 1711 | return append_option_to_variant_with_selector_field_field_class(fc, |
02b61fe0 | 1712 | name, option_fc, (const void *) range_set, |
8bc207af | 1713 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD); |
02b61fe0 PP |
1714 | } |
1715 | ||
8bc207af PP |
1716 | enum bt_field_class_variant_with_selector_field_integer_append_option_status |
1717 | bt_field_class_variant_with_selector_field_integer_signed_append_option( | |
02b61fe0 PP |
1718 | struct bt_field_class *fc, const char *name, |
1719 | struct bt_field_class *option_fc, | |
1720 | const struct bt_integer_range_set_signed *range_set) | |
1721 | { | |
8bc207af | 1722 | return append_option_to_variant_with_selector_field_field_class(fc, |
02b61fe0 | 1723 | name, option_fc, (const void *) range_set, |
8bc207af | 1724 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD); |
02b61fe0 PP |
1725 | } |
1726 | ||
1727 | uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc) | |
1728 | { | |
1729 | const struct bt_field_class_variant *var_fc = (const void *) fc; | |
1730 | ||
1731 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1732 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); | |
1733 | return (uint64_t) var_fc->common.named_fcs->len; | |
939190b3 PP |
1734 | } |
1735 | ||
e24f271a | 1736 | const struct bt_field_class_variant_option * |
c0db9072 | 1737 | bt_field_class_variant_borrow_option_by_name_const( |
78cf9df6 | 1738 | const struct bt_field_class *fc, const char *name) |
939190b3 | 1739 | { |
fa6cfec3 | 1740 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
02b61fe0 | 1741 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); |
e24f271a PP |
1742 | return (const void *) |
1743 | borrow_named_field_class_from_container_field_class_by_name( | |
1744 | (void *) fc, name); | |
909d0a89 PP |
1745 | } |
1746 | ||
02b61fe0 PP |
1747 | const struct bt_field_class_variant_option * |
1748 | bt_field_class_variant_borrow_option_by_index_const( | |
1749 | const struct bt_field_class *fc, uint64_t index) | |
909d0a89 | 1750 | { |
fa6cfec3 | 1751 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
02b61fe0 PP |
1752 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); |
1753 | return (const void *) | |
1754 | borrow_named_field_class_from_container_field_class_at_index( | |
34dd2c30 PP |
1755 | (void *) fc, index); |
1756 | } | |
1757 | ||
1758 | struct bt_field_class_variant_option * | |
1759 | bt_field_class_variant_borrow_option_by_name( | |
1760 | struct bt_field_class *fc, const char *name) | |
1761 | { | |
1762 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1763 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); | |
1764 | return (void *) | |
1765 | borrow_named_field_class_from_container_field_class_by_name( | |
1766 | (void *) fc, name); | |
1767 | } | |
1768 | ||
1769 | struct bt_field_class_variant_option * | |
1770 | bt_field_class_variant_borrow_option_by_index( | |
1771 | struct bt_field_class *fc, uint64_t index) | |
1772 | { | |
1773 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1774 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc, "Field class"); | |
1775 | return (void *) | |
1776 | borrow_named_field_class_from_container_field_class_at_index( | |
02b61fe0 | 1777 | (void *) fc, index); |
9e550e5f PP |
1778 | } |
1779 | ||
8bc207af PP |
1780 | const struct bt_field_class_variant_with_selector_field_integer_unsigned_option * |
1781 | bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const( | |
02b61fe0 | 1782 | const struct bt_field_class *fc, const char *name) |
939190b3 | 1783 | { |
fa6cfec3 | 1784 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
02b61fe0 | 1785 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
8bc207af | 1786 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
02b61fe0 PP |
1787 | "Field class"); |
1788 | return (const void *) | |
1789 | borrow_named_field_class_from_container_field_class_by_name( | |
1790 | (void *) fc, name); | |
939190b3 PP |
1791 | } |
1792 | ||
8bc207af PP |
1793 | const struct bt_field_class_variant_with_selector_field_integer_unsigned_option * |
1794 | bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( | |
e24f271a | 1795 | const struct bt_field_class *fc, uint64_t index) |
939190b3 | 1796 | { |
fa6cfec3 | 1797 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
02b61fe0 | 1798 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
8bc207af | 1799 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD, |
02b61fe0 | 1800 | "Field class"); |
e24f271a PP |
1801 | return (const void *) |
1802 | borrow_named_field_class_from_container_field_class_at_index( | |
1803 | (void *) fc, index); | |
909d0a89 PP |
1804 | } |
1805 | ||
8bc207af PP |
1806 | const struct bt_field_class_variant_with_selector_field_integer_signed_option * |
1807 | bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const( | |
02b61fe0 | 1808 | const struct bt_field_class *fc, const char *name) |
909d0a89 | 1809 | { |
fa6cfec3 | 1810 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
02b61fe0 | 1811 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
8bc207af | 1812 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
02b61fe0 PP |
1813 | "Field class"); |
1814 | return (const void *) | |
1815 | borrow_named_field_class_from_container_field_class_by_name( | |
1816 | (void *) fc, name); | |
1817 | } | |
1818 | ||
8bc207af PP |
1819 | const struct bt_field_class_variant_with_selector_field_integer_signed_option * |
1820 | bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( | |
02b61fe0 PP |
1821 | const struct bt_field_class *fc, uint64_t index) |
1822 | { | |
1823 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
1824 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, | |
8bc207af | 1825 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD, |
02b61fe0 PP |
1826 | "Field class"); |
1827 | return (const void *) | |
e24f271a PP |
1828 | borrow_named_field_class_from_container_field_class_at_index( |
1829 | (void *) fc, index); | |
1830 | } | |
1831 | ||
1832 | const char *bt_field_class_variant_option_get_name( | |
1833 | const struct bt_field_class_variant_option *option) | |
1834 | { | |
1835 | const struct bt_named_field_class *named_fc = (const void *) option; | |
1836 | ||
fa6cfec3 | 1837 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); |
e24f271a PP |
1838 | return named_fc->name->str; |
1839 | } | |
1840 | ||
1841 | const struct bt_field_class * | |
1842 | bt_field_class_variant_option_borrow_field_class_const( | |
1843 | const struct bt_field_class_variant_option *option) | |
1844 | { | |
1845 | const struct bt_named_field_class *named_fc = (const void *) option; | |
1846 | ||
fa6cfec3 | 1847 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); |
e24f271a PP |
1848 | return named_fc->fc; |
1849 | } | |
1850 | ||
87040955 FD |
1851 | struct bt_field_class * |
1852 | bt_field_class_variant_option_borrow_field_class( | |
1853 | struct bt_field_class_variant_option *option) | |
1854 | { | |
1855 | struct bt_named_field_class *named_fc = (void *) option; | |
1856 | ||
1857 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); | |
1858 | return named_fc->fc; | |
1859 | } | |
1860 | ||
02b61fe0 | 1861 | const struct bt_integer_range_set_unsigned * |
8bc207af PP |
1862 | bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( |
1863 | const struct bt_field_class_variant_with_selector_field_integer_unsigned_option *option) | |
e24f271a | 1864 | { |
8bc207af | 1865 | const struct bt_field_class_variant_with_selector_field_option *opt = |
02b61fe0 | 1866 | (const void *) option; |
e24f271a | 1867 | |
fa6cfec3 | 1868 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); |
02b61fe0 PP |
1869 | return (const void *) opt->range_set; |
1870 | } | |
1871 | ||
1872 | const struct bt_integer_range_set_signed * | |
8bc207af PP |
1873 | bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( |
1874 | const struct bt_field_class_variant_with_selector_field_integer_signed_option *option) | |
02b61fe0 | 1875 | { |
8bc207af | 1876 | const struct bt_field_class_variant_with_selector_field_option *opt = |
02b61fe0 PP |
1877 | (const void *) option; |
1878 | ||
1879 | BT_ASSERT_PRE_DEV_NON_NULL(option, "Variant field class option"); | |
1880 | return (const void *) opt->range_set; | |
939190b3 PP |
1881 | } |
1882 | ||
78cf9df6 | 1883 | const struct bt_field_path * |
8bc207af | 1884 | bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( |
78cf9df6 | 1885 | const struct bt_field_class *fc) |
9e550e5f | 1886 | { |
8bc207af | 1887 | const struct bt_field_class_variant_with_selector_field *var_fc = |
02b61fe0 | 1888 | (const void *) fc; |
939190b3 | 1889 | |
fa6cfec3 | 1890 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
02b61fe0 | 1891 | BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(fc, "Field class"); |
939190b3 PP |
1892 | return var_fc->selector_field_path; |
1893 | } | |
1894 | ||
1895 | static | |
af90138b | 1896 | int init_array_field_class(struct bt_field_class_array *fc, |
af0c18e3 | 1897 | enum bt_field_class_type type, bt_object_release_func release_func, |
939190b3 PP |
1898 | struct bt_field_class *element_fc) |
1899 | { | |
af90138b PP |
1900 | int ret; |
1901 | ||
939190b3 | 1902 | BT_ASSERT(element_fc); |
af90138b PP |
1903 | ret = init_field_class((void *) fc, type, release_func); |
1904 | if (ret) { | |
1905 | goto end; | |
1906 | } | |
1907 | ||
4b70020d | 1908 | fc->element_fc = element_fc; |
864aa43f | 1909 | bt_object_get_ref_no_null_check(fc->element_fc); |
939190b3 | 1910 | bt_field_class_freeze(element_fc); |
af90138b PP |
1911 | |
1912 | end: | |
1913 | return ret; | |
939190b3 PP |
1914 | } |
1915 | ||
1916 | static | |
1917 | void finalize_array_field_class(struct bt_field_class_array *array_fc) | |
1918 | { | |
1919 | BT_ASSERT(array_fc); | |
9e550e5f | 1920 | BT_LOGD_STR("Putting element field class."); |
af90138b | 1921 | finalize_field_class((void *) array_fc); |
1248f5ea | 1922 | BT_OBJECT_PUT_REF_AND_RESET(array_fc->element_fc); |
939190b3 PP |
1923 | } |
1924 | ||
1925 | static | |
1926 | void destroy_static_array_field_class(struct bt_object *obj) | |
1927 | { | |
1928 | BT_ASSERT(obj); | |
9e550e5f | 1929 | BT_LIB_LOGD("Destroying static array field class object: %!+F", obj); |
939190b3 PP |
1930 | finalize_array_field_class((void *) obj); |
1931 | g_free(obj); | |
1932 | } | |
1933 | ||
78cf9df6 | 1934 | struct bt_field_class * |
60bbfc7c | 1935 | bt_field_class_array_static_create(bt_trace_class *trace_class, |
b7396828 | 1936 | struct bt_field_class *element_fc, uint64_t length) |
939190b3 | 1937 | { |
60bbfc7c | 1938 | struct bt_field_class_array_static *array_fc = NULL; |
939190b3 | 1939 | |
b7396828 | 1940 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
9e550e5f PP |
1941 | BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); |
1942 | BT_LOGD_STR("Creating default static array field class object."); | |
60bbfc7c | 1943 | array_fc = g_new0(struct bt_field_class_array_static, 1); |
939190b3 | 1944 | if (!array_fc) { |
a8f90e5d PP |
1945 | BT_LIB_LOGE_APPEND_CAUSE( |
1946 | "Failed to allocate one static array field class."); | |
939190b3 PP |
1947 | goto error; |
1948 | } | |
1949 | ||
af90138b PP |
1950 | if (init_array_field_class((void *) array_fc, |
1951 | BT_FIELD_CLASS_TYPE_STATIC_ARRAY, | |
1952 | destroy_static_array_field_class, element_fc)) { | |
1953 | goto error; | |
1954 | } | |
1955 | ||
939190b3 | 1956 | array_fc->length = length; |
9e550e5f | 1957 | BT_LIB_LOGD("Created static array field class object: %!+F", array_fc); |
939190b3 PP |
1958 | goto end; |
1959 | ||
1960 | error: | |
8138bfe1 | 1961 | BT_OBJECT_PUT_REF_AND_RESET(array_fc); |
939190b3 PP |
1962 | |
1963 | end: | |
1964 | return (void *) array_fc; | |
1965 | } | |
1966 | ||
78cf9df6 PP |
1967 | const struct bt_field_class * |
1968 | bt_field_class_array_borrow_element_field_class_const( | |
1969 | const struct bt_field_class *fc) | |
939190b3 | 1970 | { |
78cf9df6 | 1971 | const struct bt_field_class_array *array_fc = (const void *) fc; |
939190b3 | 1972 | |
fa6cfec3 PP |
1973 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1974 | BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc, "Field class"); | |
939190b3 PP |
1975 | return array_fc->element_fc; |
1976 | } | |
1977 | ||
909d0a89 PP |
1978 | struct bt_field_class * |
1979 | bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc) | |
1980 | { | |
1981 | struct bt_field_class_array *array_fc = (void *) fc; | |
1982 | ||
fa6cfec3 PP |
1983 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1984 | BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc, "Field class"); | |
909d0a89 PP |
1985 | return array_fc->element_fc; |
1986 | } | |
1987 | ||
60bbfc7c | 1988 | uint64_t bt_field_class_array_static_get_length(const struct bt_field_class *fc) |
9e550e5f | 1989 | { |
60bbfc7c | 1990 | const struct bt_field_class_array_static *array_fc = (const void *) fc; |
939190b3 | 1991 | |
fa6cfec3 PP |
1992 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
1993 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STATIC_ARRAY, | |
939190b3 PP |
1994 | "Field class"); |
1995 | return (uint64_t) array_fc->length; | |
1996 | } | |
1997 | ||
1998 | static | |
1999 | void destroy_dynamic_array_field_class(struct bt_object *obj) | |
2000 | { | |
60bbfc7c | 2001 | struct bt_field_class_array_dynamic *fc = (void *) obj; |
939190b3 PP |
2002 | |
2003 | BT_ASSERT(fc); | |
9e550e5f | 2004 | BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc); |
939190b3 PP |
2005 | finalize_array_field_class((void *) fc); |
2006 | BT_LOGD_STR("Putting length field path."); | |
1248f5ea PP |
2007 | BT_OBJECT_PUT_REF_AND_RESET(fc->length_field_path); |
2008 | BT_LOGD_STR("Putting length field class."); | |
2009 | BT_OBJECT_PUT_REF_AND_RESET(fc->length_fc); | |
939190b3 PP |
2010 | g_free(fc); |
2011 | } | |
2012 | ||
60bbfc7c | 2013 | struct bt_field_class *bt_field_class_array_dynamic_create( |
93d7d5d1 PP |
2014 | struct bt_trace_class *trace_class, |
2015 | struct bt_field_class *element_fc, | |
2016 | struct bt_field_class *length_fc) | |
939190b3 | 2017 | { |
60bbfc7c | 2018 | struct bt_field_class_array_dynamic *array_fc = NULL; |
939190b3 | 2019 | |
b7396828 | 2020 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
9e550e5f PP |
2021 | BT_ASSERT_PRE_NON_NULL(element_fc, "Element field class"); |
2022 | BT_LOGD_STR("Creating default dynamic array field class object."); | |
60bbfc7c | 2023 | array_fc = g_new0(struct bt_field_class_array_dynamic, 1); |
939190b3 | 2024 | if (!array_fc) { |
a8f90e5d PP |
2025 | BT_LIB_LOGE_APPEND_CAUSE( |
2026 | "Failed to allocate one dynamic array field class."); | |
939190b3 PP |
2027 | goto error; |
2028 | } | |
2029 | ||
af90138b | 2030 | if (init_array_field_class((void *) array_fc, |
b8ddb4f0 PP |
2031 | length_fc ? |
2032 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD : | |
2033 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD, | |
af90138b PP |
2034 | destroy_dynamic_array_field_class, element_fc)) { |
2035 | goto error; | |
2036 | } | |
93d7d5d1 PP |
2037 | |
2038 | if (length_fc) { | |
2039 | BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc, | |
2040 | "Length field class"); | |
2041 | array_fc->length_fc = length_fc; | |
864aa43f | 2042 | bt_object_get_ref_no_null_check(array_fc->length_fc); |
93d7d5d1 PP |
2043 | bt_field_class_freeze(length_fc); |
2044 | } | |
2045 | ||
9e550e5f | 2046 | BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc); |
939190b3 PP |
2047 | goto end; |
2048 | ||
2049 | error: | |
8138bfe1 | 2050 | BT_OBJECT_PUT_REF_AND_RESET(array_fc); |
939190b3 PP |
2051 | |
2052 | end: | |
2053 | return (void *) array_fc; | |
2054 | } | |
2055 | ||
78cf9df6 | 2056 | const struct bt_field_path * |
b8ddb4f0 | 2057 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( |
78cf9df6 | 2058 | const struct bt_field_class *fc) |
939190b3 | 2059 | { |
60bbfc7c | 2060 | const struct bt_field_class_array_dynamic *seq_fc = (const void *) fc; |
939190b3 | 2061 | |
fa6cfec3 | 2062 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); |
b8ddb4f0 PP |
2063 | BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, |
2064 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD, | |
939190b3 PP |
2065 | "Field class"); |
2066 | return seq_fc->length_field_path; | |
2067 | } | |
2068 | ||
2069 | static | |
2070 | void destroy_string_field_class(struct bt_object *obj) | |
2071 | { | |
2072 | BT_ASSERT(obj); | |
9e550e5f | 2073 | BT_LIB_LOGD("Destroying string field class object: %!+F", obj); |
af90138b | 2074 | finalize_field_class((void *) obj); |
939190b3 PP |
2075 | g_free(obj); |
2076 | } | |
2077 | ||
b7396828 | 2078 | struct bt_field_class *bt_field_class_string_create(bt_trace_class *trace_class) |
939190b3 PP |
2079 | { |
2080 | struct bt_field_class_string *string_fc = NULL; | |
2081 | ||
b7396828 | 2082 | BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class"); |
9e550e5f | 2083 | BT_LOGD_STR("Creating default string field class object."); |
939190b3 PP |
2084 | string_fc = g_new0(struct bt_field_class_string, 1); |
2085 | if (!string_fc) { | |
a8f90e5d PP |
2086 | BT_LIB_LOGE_APPEND_CAUSE( |
2087 | "Failed to allocate one string field class."); | |
939190b3 PP |
2088 | goto error; |
2089 | } | |
2090 | ||
af90138b PP |
2091 | if (init_field_class((void *) string_fc, BT_FIELD_CLASS_TYPE_STRING, |
2092 | destroy_string_field_class)) { | |
2093 | goto error; | |
2094 | } | |
2095 | ||
9e550e5f | 2096 | BT_LIB_LOGD("Created string field class object: %!+F", string_fc); |
939190b3 PP |
2097 | goto end; |
2098 | ||
2099 | error: | |
8138bfe1 | 2100 | BT_OBJECT_PUT_REF_AND_RESET(string_fc); |
939190b3 PP |
2101 | |
2102 | end: | |
2103 | return (void *) string_fc; | |
2104 | } | |
2105 | ||
2106 | BT_HIDDEN | |
e24f271a | 2107 | void _bt_field_class_freeze(const struct bt_field_class *c_fc) |
939190b3 | 2108 | { |
e24f271a PP |
2109 | struct bt_field_class *fc = (void *) c_fc; |
2110 | ||
939190b3 PP |
2111 | /* |
2112 | * Element/member/option field classes are frozen when added to | |
2113 | * their owner. | |
2114 | */ | |
2115 | BT_ASSERT(fc); | |
af90138b | 2116 | bt_value_freeze(fc->user_attributes); |
e24f271a PP |
2117 | fc->frozen = true; |
2118 | ||
94847783 PP |
2119 | if (fc->type == BT_FIELD_CLASS_TYPE_STRUCTURE || |
2120 | bt_field_class_type_is(fc->type, | |
2121 | BT_FIELD_CLASS_TYPE_VARIANT)) { | |
e24f271a PP |
2122 | struct bt_field_class_named_field_class_container *container_fc = |
2123 | (void *) fc; | |
2124 | uint64_t i; | |
2125 | ||
2126 | for (i = 0; i < container_fc->named_fcs->len; i++) { | |
02b61fe0 PP |
2127 | bt_named_field_class_freeze( |
2128 | container_fc->named_fcs->pdata[i]); | |
e24f271a | 2129 | } |
e24f271a PP |
2130 | } |
2131 | } | |
2132 | ||
2133 | BT_HIDDEN | |
2134 | void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc) | |
2135 | { | |
2136 | BT_ASSERT(named_fc); | |
af90138b PP |
2137 | BT_ASSERT(named_fc->fc->frozen); |
2138 | BT_LIB_LOGD("Freezing named field class's user attributes: %!+v", | |
2139 | named_fc->user_attributes); | |
2140 | bt_value_freeze(named_fc->user_attributes); | |
e24f271a | 2141 | ((struct bt_named_field_class *) named_fc)->frozen = true; |
939190b3 PP |
2142 | } |
2143 | ||
2144 | BT_HIDDEN | |
fa6cfec3 | 2145 | void bt_field_class_make_part_of_trace_class(const struct bt_field_class *c_fc) |
939190b3 | 2146 | { |
78cf9df6 PP |
2147 | struct bt_field_class *fc = (void *) c_fc; |
2148 | ||
939190b3 | 2149 | BT_ASSERT(fc); |
10b7a2e4 | 2150 | BT_ASSERT_PRE(!fc->part_of_trace_class, |
939190b3 | 2151 | "Field class is already part of a trace: %!+F", fc); |
10b7a2e4 | 2152 | fc->part_of_trace_class = true; |
939190b3 | 2153 | |
94847783 PP |
2154 | if (fc->type == BT_FIELD_CLASS_TYPE_STRUCTURE || |
2155 | bt_field_class_type_is(fc->type, | |
2156 | BT_FIELD_CLASS_TYPE_VARIANT)) { | |
939190b3 PP |
2157 | struct bt_field_class_named_field_class_container *container_fc = |
2158 | (void *) fc; | |
2159 | uint64_t i; | |
2160 | ||
2161 | for (i = 0; i < container_fc->named_fcs->len; i++) { | |
2162 | struct bt_named_field_class *named_fc = | |
02b61fe0 | 2163 | container_fc->named_fcs->pdata[i]; |
939190b3 | 2164 | |
10b7a2e4 | 2165 | bt_field_class_make_part_of_trace_class(named_fc->fc); |
939190b3 | 2166 | } |
94847783 PP |
2167 | } else if (bt_field_class_type_is(fc->type, |
2168 | BT_FIELD_CLASS_TYPE_ARRAY)) { | |
939190b3 PP |
2169 | struct bt_field_class_array *array_fc = (void *) fc; |
2170 | ||
10b7a2e4 | 2171 | bt_field_class_make_part_of_trace_class(array_fc->element_fc); |
939190b3 PP |
2172 | } |
2173 | } | |
8c6884d9 | 2174 | |
af90138b PP |
2175 | const struct bt_value *bt_field_class_borrow_user_attributes_const( |
2176 | const struct bt_field_class *fc) | |
2177 | { | |
2178 | BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class"); | |
2179 | return fc->user_attributes; | |
2180 | } | |
2181 | ||
2182 | struct bt_value *bt_field_class_borrow_user_attributes( | |
2183 | struct bt_field_class *field_class) | |
2184 | { | |
2185 | return (void *) bt_field_class_borrow_user_attributes_const( | |
2186 | (void *) field_class); | |
2187 | } | |
2188 | ||
2189 | ||
2190 | void bt_field_class_set_user_attributes( | |
2191 | struct bt_field_class *fc, | |
2192 | const struct bt_value *user_attributes) | |
2193 | { | |
2194 | BT_ASSERT_PRE_NON_NULL(fc, "Field class"); | |
2195 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
2196 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
2197 | "User attributes object is not a map value object."); | |
2198 | BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class"); | |
864aa43f | 2199 | bt_object_put_ref_no_null_check(fc->user_attributes); |
af90138b | 2200 | fc->user_attributes = (void *) user_attributes; |
864aa43f | 2201 | bt_object_get_ref_no_null_check(fc->user_attributes); |
af90138b PP |
2202 | } |
2203 | ||
2204 | static | |
2205 | const struct bt_value *bt_named_field_class_borrow_user_attributes_const( | |
2206 | const struct bt_named_field_class *named_fc) | |
2207 | { | |
2208 | return named_fc->user_attributes; | |
2209 | } | |
2210 | ||
2211 | static | |
2212 | void bt_named_field_class_set_user_attributes( | |
2213 | struct bt_named_field_class *named_fc, | |
2214 | const struct bt_value *user_attributes) | |
2215 | { | |
2216 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
2217 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
2218 | "User attributes object is not a map value object."); | |
2219 | BT_ASSERT_PRE_DEV_HOT(named_fc, | |
2220 | "Structure field class member or variant field class option", | |
2221 | "."); | |
864aa43f | 2222 | bt_object_put_ref_no_null_check(named_fc->user_attributes); |
af90138b | 2223 | named_fc->user_attributes = (void *) user_attributes; |
864aa43f | 2224 | bt_object_get_ref_no_null_check(named_fc->user_attributes); |
af90138b PP |
2225 | } |
2226 | ||
2227 | const struct bt_value * | |
2228 | bt_field_class_structure_member_borrow_user_attributes_const( | |
2229 | const struct bt_field_class_structure_member *member) | |
2230 | { | |
2231 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
2232 | return bt_named_field_class_borrow_user_attributes_const( | |
2233 | (const void *) member); | |
2234 | } | |
2235 | ||
2236 | struct bt_value * | |
2237 | bt_field_class_structure_member_borrow_user_attributes( | |
2238 | struct bt_field_class_structure_member *member) | |
2239 | { | |
2240 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
2241 | return (void *) bt_named_field_class_borrow_user_attributes_const( | |
2242 | (void *) member); | |
2243 | } | |
2244 | ||
2245 | void bt_field_class_structure_member_set_user_attributes( | |
2246 | struct bt_field_class_structure_member *member, | |
2247 | const struct bt_value *user_attributes) | |
2248 | { | |
2249 | BT_ASSERT_PRE_NON_NULL(member, "Structure field class member"); | |
2250 | bt_named_field_class_set_user_attributes((void *) member, | |
2251 | user_attributes); | |
2252 | } | |
2253 | ||
2254 | const struct bt_value *bt_field_class_variant_option_borrow_user_attributes_const( | |
2255 | const struct bt_field_class_variant_option *option) | |
2256 | { | |
2257 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
2258 | return bt_named_field_class_borrow_user_attributes_const( | |
2259 | (const void *) option); | |
2260 | } | |
2261 | ||
2262 | struct bt_value *bt_field_class_variant_option_borrow_user_attributes( | |
2263 | struct bt_field_class_variant_option *option) | |
2264 | { | |
2265 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
2266 | return (void *) bt_named_field_class_borrow_user_attributes_const( | |
2267 | (void *) option); | |
2268 | } | |
2269 | ||
2270 | void bt_field_class_variant_option_set_user_attributes( | |
2271 | struct bt_field_class_variant_option *option, | |
2272 | const struct bt_value *user_attributes) | |
2273 | { | |
2274 | BT_ASSERT_PRE_NON_NULL(option, "Variant field class option"); | |
2275 | bt_named_field_class_set_user_attributes((void *) option, | |
2276 | user_attributes); | |
2277 | } | |
2278 | ||
8c6884d9 PP |
2279 | void bt_field_class_get_ref(const struct bt_field_class *field_class) |
2280 | { | |
2281 | bt_object_get_ref(field_class); | |
2282 | } | |
2283 | ||
2284 | void bt_field_class_put_ref(const struct bt_field_class *field_class) | |
2285 | { | |
2286 | bt_object_put_ref(field_class); | |
2287 | } |