2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
24 #define BT_LOG_TAG "LIB/FIELD-CLASS"
25 #include "lib/logging.h"
27 #include "lib/assert-pre.h"
28 #include <babeltrace2/trace-ir/field-class.h>
29 #include <babeltrace2/trace-ir/field-class-const.h>
30 #include <babeltrace2/trace-ir/field-const.h>
31 #include <babeltrace2/trace-ir/field.h>
32 #include <babeltrace2/trace-ir/clock-class.h>
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"
43 #include "clock-class.h"
44 #include "field-class.h"
46 #include "field-path.h"
48 #include "lib/func-status.h"
49 #include "lib/integer-range-set.h"
50 #include "lib/value.h"
52 enum bt_field_class_type
bt_field_class_get_type(
53 const struct bt_field_class
*fc
)
55 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
60 int init_field_class(struct bt_field_class
*fc
, enum bt_field_class_type type
,
61 bt_object_release_func release_func
)
66 BT_ASSERT(release_func
);
67 bt_object_init_shared(&fc
->base
, release_func
);
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.");
82 void finalize_field_class(struct bt_field_class
*fc
)
84 BT_OBJECT_PUT_REF_AND_RESET(fc
->user_attributes
);
88 void destroy_bit_array_field_class(struct bt_object
*obj
)
91 BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj
);
92 finalize_field_class((void *) obj
);
96 struct bt_field_class
*bt_field_class_bit_array_create(
97 struct bt_trace_class
*trace_class
, uint64_t length
)
99 struct bt_field_class_bit_array
*ba_fc
= NULL
;
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);
108 BT_LIB_LOGE_APPEND_CAUSE(
109 "Failed to allocate one bit array field class.");
113 if (init_field_class((void *) ba_fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
114 destroy_bit_array_field_class
)) {
118 ba_fc
->length
= length
;
119 BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc
);
123 BT_OBJECT_PUT_REF_AND_RESET(ba_fc
);
126 return (void *) ba_fc
;
129 uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class
*fc
)
131 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
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
,
136 return ba_fc
->length
;
140 void destroy_bool_field_class(struct bt_object
*obj
)
143 BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj
);
144 finalize_field_class((void *) obj
);
148 struct bt_field_class
*bt_field_class_bool_create(
149 bt_trace_class
*trace_class
)
151 struct bt_field_class_bool
*bool_fc
= NULL
;
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);
157 BT_LIB_LOGE_APPEND_CAUSE(
158 "Failed to allocate one boolean field class.");
162 if (init_field_class((void *) bool_fc
, BT_FIELD_CLASS_TYPE_BOOL
,
163 destroy_bool_field_class
)) {
167 BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc
);
171 BT_OBJECT_PUT_REF_AND_RESET(bool_fc
);
174 return (void *) bool_fc
;
178 int init_integer_field_class(struct bt_field_class_integer
*fc
,
179 enum bt_field_class_type type
,
180 bt_object_release_func release_func
)
184 ret
= init_field_class((void *) fc
, type
, release_func
);
190 fc
->base
= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
;
197 void destroy_integer_field_class(struct bt_object
*obj
)
200 BT_LIB_LOGD("Destroying integer field class object: %!+F", obj
);
201 finalize_field_class((void *) obj
);
206 struct bt_field_class
*create_integer_field_class(bt_trace_class
*trace_class
,
207 enum bt_field_class_type type
)
209 struct bt_field_class_integer
*int_fc
= NULL
;
211 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
212 BT_LOGD("Creating default integer field class object: type=%s",
213 bt_common_field_class_type_string(type
));
214 int_fc
= g_new0(struct bt_field_class_integer
, 1);
216 BT_LIB_LOGE_APPEND_CAUSE(
217 "Failed to allocate one integer field class.");
221 if (init_integer_field_class(int_fc
, type
,
222 destroy_integer_field_class
)) {
226 BT_LIB_LOGD("Created integer field class object: %!+F", int_fc
);
230 BT_OBJECT_PUT_REF_AND_RESET(int_fc
);
233 return (void *) int_fc
;
236 struct bt_field_class
*bt_field_class_integer_unsigned_create(
237 bt_trace_class
*trace_class
)
239 return create_integer_field_class(trace_class
,
240 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
243 struct bt_field_class
*bt_field_class_integer_signed_create(
244 bt_trace_class
*trace_class
)
246 return create_integer_field_class(trace_class
,
247 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
250 uint64_t bt_field_class_integer_get_field_value_range(
251 const struct bt_field_class
*fc
)
253 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
255 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
256 BT_ASSERT_PRE_DEV_FC_IS_INT(fc
, "Field class");
257 return int_fc
->range
;
261 bool size_is_valid_for_enumeration_field_class(struct bt_field_class
*fc
,
268 void bt_field_class_integer_set_field_value_range(
269 struct bt_field_class
*fc
, uint64_t size
)
271 struct bt_field_class_integer
*int_fc
= (void *) fc
;
273 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
274 BT_ASSERT_PRE_FC_IS_INT(fc
, "Field class");
275 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
276 BT_ASSERT_PRE(size
<= 64,
277 "Unsupported size for integer field class's field value range "
278 "(maximum is 64): size=%" PRIu64
, size
);
280 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
281 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
282 size_is_valid_for_enumeration_field_class(fc
, size
),
283 "Invalid field value range for enumeration field class: "
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
;
287 BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc
);
290 enum bt_field_class_integer_preferred_display_base
291 bt_field_class_integer_get_preferred_display_base(const struct bt_field_class
*fc
)
293 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
295 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
296 BT_ASSERT_PRE_DEV_FC_IS_INT(fc
, "Field class");
300 void bt_field_class_integer_set_preferred_display_base(
301 struct bt_field_class
*fc
,
302 enum bt_field_class_integer_preferred_display_base base
)
304 struct bt_field_class_integer
*int_fc
= (void *) fc
;
306 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
307 BT_ASSERT_PRE_FC_IS_INT(fc
, "Field class");
308 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
310 BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc
);
314 void finalize_enumeration_field_class_mapping(
315 struct bt_field_class_enumeration_mapping
*mapping
)
319 if (mapping
->label
) {
320 g_string_free(mapping
->label
, TRUE
);
321 mapping
->label
= NULL
;
324 BT_OBJECT_PUT_REF_AND_RESET(mapping
->range_set
);
328 void destroy_enumeration_field_class(struct bt_object
*obj
)
330 struct bt_field_class_enumeration
*fc
= (void *) obj
;
333 BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc
);
334 finalize_field_class((void *) obj
);
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
));
344 g_array_free(fc
->mappings
, TRUE
);
349 g_ptr_array_free(fc
->label_buf
, TRUE
);
350 fc
->label_buf
= NULL
;
357 struct bt_field_class
*create_enumeration_field_class(
358 bt_trace_class
*trace_class
, enum bt_field_class_type type
)
360 struct bt_field_class_enumeration
*enum_fc
= NULL
;
362 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
363 BT_LOGD("Creating default enumeration field class object: type=%s",
364 bt_common_field_class_type_string(type
));
365 enum_fc
= g_new0(struct bt_field_class_enumeration
, 1);
367 BT_LIB_LOGE_APPEND_CAUSE(
368 "Failed to allocate one enumeration field class.");
372 if (init_integer_field_class((void *) enum_fc
, type
,
373 destroy_enumeration_field_class
)) {
377 enum_fc
->mappings
= g_array_new(FALSE
, TRUE
,
378 sizeof(struct bt_field_class_enumeration_mapping
));
379 if (!enum_fc
->mappings
) {
380 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
384 enum_fc
->label_buf
= g_ptr_array_new();
385 if (!enum_fc
->label_buf
) {
386 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
390 BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc
);
394 BT_OBJECT_PUT_REF_AND_RESET(enum_fc
);
397 return (void *) enum_fc
;
400 struct bt_field_class
*bt_field_class_enumeration_unsigned_create(
401 bt_trace_class
*trace_class
)
403 return create_enumeration_field_class(trace_class
,
404 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
407 struct bt_field_class
*bt_field_class_enumeration_signed_create(
408 bt_trace_class
*trace_class
)
410 return create_enumeration_field_class(trace_class
,
411 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
414 uint64_t bt_field_class_enumeration_get_mapping_count(
415 const struct bt_field_class
*fc
)
417 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
419 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
420 BT_ASSERT_PRE_DEV_FC_IS_ENUM(fc
, "Field class");
421 return (uint64_t) enum_fc
->mappings
->len
;
424 const struct bt_field_class_enumeration_unsigned_mapping
*
425 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
426 const struct bt_field_class
*fc
, uint64_t index
)
428 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
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
,
434 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
437 const struct bt_field_class_enumeration_signed_mapping
*
438 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
439 const struct bt_field_class
*fc
, uint64_t index
)
441 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
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
,
447 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
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
)
455 struct bt_field_class_enumeration_mapping
*mapping
= NULL
;
459 BT_ASSERT_PRE_DEV_NON_NULL(label
, "Label");
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
);
465 if (strcmp(this_mapping
->label
->str
, label
) == 0) {
466 mapping
= this_mapping
;
475 const struct bt_field_class_enumeration_signed_mapping
*
476 bt_field_class_enumeration_signed_borrow_mapping_by_label_const(
477 const struct bt_field_class
*fc
, const char *label
)
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
,
482 return (const void *) borrow_enumeration_field_class_mapping_by_label(
483 (const void *) fc
, label
);
486 const struct bt_field_class_enumeration_unsigned_mapping
*
487 bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(
488 const struct bt_field_class
*fc
, const char *label
)
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
);
497 const char *bt_field_class_enumeration_mapping_get_label(
498 const struct bt_field_class_enumeration_mapping
*mapping
)
500 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
501 return mapping
->label
->str
;
504 const struct bt_integer_range_set_unsigned
*
505 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
506 const struct bt_field_class_enumeration_unsigned_mapping
*u_mapping
)
508 const struct bt_field_class_enumeration_mapping
*mapping
=
509 (const void *) u_mapping
;
511 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
512 return (const void *) mapping
->range_set
;
515 const struct bt_integer_range_set_signed
*
516 bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
517 const struct bt_field_class_enumeration_signed_mapping
*s_mapping
)
519 const struct bt_field_class_enumeration_mapping
*mapping
=
520 (const void *) s_mapping
;
522 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
523 return (const void *) mapping
->range_set
;
526 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
527 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
528 const struct bt_field_class
*fc
, uint64_t value
,
529 bt_field_class_enumeration_mapping_label_array
*label_array
,
532 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
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
,
540 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
542 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
544 const struct bt_field_class_enumeration_mapping
*mapping
=
545 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
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
);
552 if (value
>= range
->lower
.u
&&
553 value
<= range
->upper
.u
) {
554 g_ptr_array_add(enum_fc
->label_buf
,
555 mapping
->label
->str
);
561 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
562 *count
= (uint64_t) enum_fc
->label_buf
->len
;
563 return BT_FUNC_STATUS_OK
;
566 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
567 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
568 const struct bt_field_class
*fc
, int64_t value
,
569 bt_field_class_enumeration_mapping_label_array
*label_array
,
572 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
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
,
580 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
582 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
584 const struct bt_field_class_enumeration_mapping
*mapping
=
585 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
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
);
592 if (value
>= range
->lower
.i
&&
593 value
<= range
->upper
.i
) {
594 g_ptr_array_add(enum_fc
->label_buf
,
595 mapping
->label
->str
);
601 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
602 *count
= (uint64_t) enum_fc
->label_buf
->len
;
603 return BT_FUNC_STATUS_OK
;
607 bool enumeration_field_class_has_mapping_with_label(
608 const struct bt_field_class_enumeration
*enum_fc
,
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
);
621 if (strcmp(mapping_candidate
->label
->str
, label
) == 0) {
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
)
636 enum bt_field_class_enumeration_add_mapping_status status
=
638 struct bt_field_class_enumeration
*enum_fc
= (void *) fc
;
639 struct bt_field_class_enumeration_mapping mapping
= { 0 };
642 BT_ASSERT_PRE_NON_NULL(label
, "Label");
643 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
644 BT_ASSERT_PRE(!enumeration_field_class_has_mapping_with_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
;
657 g_array_append_val(enum_fc
->mappings
, mapping
);
658 BT_LIB_LOGD("Added mapping to enumeration field class: "
659 "%![fc-]+F, label=\"%s\"", fc
, label
);
665 enum bt_field_class_enumeration_add_mapping_status
666 bt_field_class_enumeration_unsigned_add_mapping(
667 struct bt_field_class
*fc
, const char *label
,
668 const struct bt_integer_range_set_unsigned
*range_set
)
670 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
671 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
673 return add_mapping_to_enumeration_field_class(fc
, label
,
674 (const void *) range_set
);
677 enum bt_field_class_enumeration_add_mapping_status
678 bt_field_class_enumeration_signed_add_mapping(
679 struct bt_field_class
*fc
, const char *label
,
680 const struct bt_integer_range_set_signed
*range_set
)
682 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
683 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
685 return add_mapping_to_enumeration_field_class(fc
, label
,
686 (const void *) range_set
);
690 void destroy_real_field_class(struct bt_object
*obj
)
693 BT_LIB_LOGD("Destroying real field class object: %!+F", obj
);
694 finalize_field_class((void *) obj
);
699 struct bt_field_class
*create_real_field_class(bt_trace_class
*trace_class
,
700 enum bt_field_class_type type
)
702 struct bt_field_class_real
*real_fc
= NULL
;
704 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
705 BT_LOGD("Creating default real field class object: type=%s",
706 bt_common_field_class_type_string(type
));
707 real_fc
= g_new0(struct bt_field_class_real
, 1);
709 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
713 if (init_field_class((void *) real_fc
, type
, destroy_real_field_class
)) {
717 BT_LIB_LOGD("Created real field class object: %!+F", real_fc
);
721 BT_OBJECT_PUT_REF_AND_RESET(real_fc
);
724 return (void *) real_fc
;
727 struct bt_field_class
*bt_field_class_real_single_precision_create(
728 bt_trace_class
*trace_class
)
730 return create_real_field_class(trace_class
,
731 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
);
734 struct bt_field_class
*bt_field_class_real_double_precision_create(
735 bt_trace_class
*trace_class
)
737 return create_real_field_class(trace_class
,
738 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
);
742 int init_named_field_classes_container(
743 struct bt_field_class_named_field_class_container
*fc
,
744 enum bt_field_class_type type
,
745 bt_object_release_func fc_release_func
,
746 GDestroyNotify named_fc_destroy_func
)
750 ret
= init_field_class((void *) fc
, type
, fc_release_func
);
755 fc
->named_fcs
= g_ptr_array_new_with_free_func(named_fc_destroy_func
);
756 if (!fc
->named_fcs
) {
757 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
762 fc
->name_to_index
= g_hash_table_new(g_str_hash
, g_str_equal
);
763 if (!fc
->name_to_index
) {
764 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
774 void finalize_named_field_class(struct bt_named_field_class
*named_fc
)
777 BT_LIB_LOGD("Finalizing named field class: "
778 "addr=%p, name=\"%s\", %![fc-]+F",
779 named_fc
, named_fc
->name
? named_fc
->name
->str
: NULL
,
781 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
783 if (named_fc
->name
) {
784 g_string_free(named_fc
->name
, TRUE
);
785 named_fc
->name
= NULL
;
788 BT_LOGD_STR("Putting named field class's field class.");
789 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->fc
);
793 void destroy_named_field_class(gpointer ptr
)
795 struct bt_named_field_class
*named_fc
= ptr
;
798 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
799 finalize_named_field_class(ptr
);
805 void destroy_variant_with_selector_field_option(gpointer ptr
)
807 struct bt_field_class_variant_with_selector_field_option
*opt
= ptr
;
810 finalize_named_field_class(&opt
->common
);
811 BT_OBJECT_PUT_REF_AND_RESET(opt
->range_set
);
817 void finalize_named_field_classes_container(
818 struct bt_field_class_named_field_class_container
*fc
)
823 g_ptr_array_free(fc
->named_fcs
, TRUE
);
824 fc
->named_fcs
= NULL
;
828 if (fc
->name_to_index
) {
829 g_hash_table_destroy(fc
->name_to_index
);
830 fc
->name_to_index
= NULL
;
835 void destroy_structure_field_class(struct bt_object
*obj
)
838 BT_LIB_LOGD("Destroying structure field class object: %!+F", obj
);
839 finalize_field_class((void *) obj
);
840 finalize_named_field_classes_container((void *) obj
);
844 struct bt_field_class
*bt_field_class_structure_create(
845 bt_trace_class
*trace_class
)
848 struct bt_field_class_structure
*struct_fc
= NULL
;
850 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
851 BT_LOGD_STR("Creating default structure field class object.");
852 struct_fc
= g_new0(struct bt_field_class_structure
, 1);
854 BT_LIB_LOGE_APPEND_CAUSE(
855 "Failed to allocate one structure field class.");
859 ret
= init_named_field_classes_container((void *) struct_fc
,
860 BT_FIELD_CLASS_TYPE_STRUCTURE
, destroy_structure_field_class
,
861 destroy_named_field_class
);
863 /* init_named_field_classes_container() logs errors */
867 BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc
);
871 BT_OBJECT_PUT_REF_AND_RESET(struct_fc
);
874 return (void *) struct_fc
;
878 int init_named_field_class(struct bt_named_field_class
*named_fc
,
879 const char *name
, struct bt_field_class
*fc
)
881 int status
= BT_FUNC_STATUS_OK
;
886 named_fc
->name
= g_string_new(name
);
887 if (!named_fc
->name
) {
888 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
889 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
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
;
902 bt_object_get_ref_no_null_check(named_fc
->fc
);
909 struct bt_named_field_class
*create_named_field_class(const char *name
,
910 struct bt_field_class
*fc
)
912 struct bt_named_field_class
*named_fc
= g_new0(
913 struct bt_named_field_class
, 1);
916 BT_LIB_LOGE_APPEND_CAUSE(
917 "Failed to allocate a named field class.");
921 if (init_named_field_class(named_fc
, name
, fc
)) {
922 /* init_named_field_class() logs errors */
929 destroy_named_field_class(named_fc
);
937 struct bt_field_class_variant_with_selector_field_option
*
938 create_variant_with_selector_field_option(
939 const char *name
, struct bt_field_class
*fc
,
940 const struct bt_integer_range_set
*range_set
)
942 struct bt_field_class_variant_with_selector_field_option
*opt
= g_new0(
943 struct bt_field_class_variant_with_selector_field_option
, 1);
945 BT_ASSERT(range_set
);
948 BT_LIB_LOGE_APPEND_CAUSE(
949 "Failed to allocate a named field class.");
953 if (init_named_field_class(&opt
->common
, name
, fc
)) {
957 opt
->range_set
= range_set
;
958 bt_object_get_ref_no_null_check(opt
->range_set
);
959 bt_integer_range_set_freeze(range_set
);
963 destroy_variant_with_selector_field_option(opt
);
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
)
975 BT_ASSERT(container_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
);
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.
989 bt_field_class_freeze(named_fc
->fc
);
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
;
996 enum bt_field_class_structure_append_member_status
997 bt_field_class_structure_append_member(
998 struct bt_field_class
*fc
, const char *name
,
999 struct bt_field_class
*member_fc
)
1001 enum bt_field_class_structure_append_member_status status
;
1002 struct bt_named_field_class
*named_fc
= NULL
;
1004 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1005 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1007 named_fc
= create_named_field_class(name
, member_fc
);
1009 /* create_named_field_class() logs errors */
1010 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1014 status
= append_named_field_class_to_container_field_class((void *) fc
,
1016 if (status
== BT_FUNC_STATUS_OK
) {
1017 /* Moved to the container */
1025 uint64_t bt_field_class_structure_get_member_count(
1026 const struct bt_field_class
*fc
)
1028 struct bt_field_class_structure
*struct_fc
= (void *) fc
;
1030 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1031 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1033 return (uint64_t) struct_fc
->common
.named_fcs
->len
;
1037 struct bt_named_field_class
*
1038 borrow_named_field_class_from_container_field_class_at_index(
1039 struct bt_field_class_named_field_class_container
*fc
,
1043 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, fc
->named_fcs
->len
);
1044 return fc
->named_fcs
->pdata
[index
];
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
)
1051 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1052 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1054 return (const void *)
1055 borrow_named_field_class_from_container_field_class_at_index(
1056 (void *) fc
, index
);
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
)
1063 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1064 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1067 borrow_named_field_class_from_container_field_class_at_index(
1068 (void *) fc
, index
);
1072 struct bt_named_field_class
*
1073 borrow_named_field_class_from_container_field_class_by_name(
1074 struct bt_field_class_named_field_class_container
*fc
,
1077 struct bt_named_field_class
*named_fc
= NULL
;
1082 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Name");
1083 if (!g_hash_table_lookup_extended(fc
->name_to_index
, name
, &orig_key
,
1088 named_fc
= fc
->named_fcs
->pdata
[GPOINTER_TO_UINT(value
)];
1094 const struct bt_field_class_structure_member
*
1095 bt_field_class_structure_borrow_member_by_name_const(
1096 const struct bt_field_class
*fc
, const char *name
)
1098 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1099 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1101 return (const void *)
1102 borrow_named_field_class_from_container_field_class_by_name(
1106 struct bt_field_class_structure_member
*
1107 bt_field_class_structure_borrow_member_by_name(
1108 struct bt_field_class
*fc
, const char *name
)
1110 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1111 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1114 borrow_named_field_class_from_container_field_class_by_name(
1118 const char *bt_field_class_structure_member_get_name(
1119 const struct bt_field_class_structure_member
*member
)
1121 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1123 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1124 return named_fc
->name
->str
;
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
)
1131 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1133 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1134 return named_fc
->fc
;
1137 struct bt_field_class
*
1138 bt_field_class_structure_member_borrow_field_class(
1139 struct bt_field_class_structure_member
*member
)
1141 struct bt_named_field_class
*named_fc
= (void *) member
;
1143 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1144 return named_fc
->fc
;
1148 void destroy_option_field_class(struct bt_object
*obj
)
1150 struct bt_field_class_option
*fc
= (void *) obj
;
1153 BT_LIB_LOGD("Destroying option field class object: %!+F", fc
);
1154 finalize_field_class((void *) obj
);
1155 BT_LOGD_STR("Putting content field class.");
1156 BT_OBJECT_PUT_REF_AND_RESET(fc
->content_fc
);
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
=
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
);
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
=
1171 BT_LOGD_STR("Putting integer range set.");
1172 BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc
->range_set
);
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
)
1186 struct bt_field_class_option
*opt_fc
= NULL
;
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: "
1191 "type=%s, %![content-fc-]+F, %![sel-fc-]+F",
1192 bt_common_field_class_type_string(fc_type
),
1193 content_fc
, selector_fc
);
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
;
1198 BT_ASSERT_PRE_NON_NULL(selector_fc
, "Selector field class");
1200 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
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(
1205 struct bt_field_class_option_with_selector_field_bool
, 1);
1207 BT_ASSERT_PRE_FC_IS_INT(selector_fc
,
1208 "Selector field class");
1209 opt_with_sel_fc
= (void *) g_new0(
1210 struct bt_field_class_option_with_selector_field_integer
, 1);
1213 if (!opt_with_sel_fc
) {
1214 BT_LIB_LOGE_APPEND_CAUSE(
1215 "Failed to allocate one option with selector field class.");
1219 opt_with_sel_fc
->selector_fc
= selector_fc
;
1220 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_fc
);
1221 opt_fc
= (void *) opt_with_sel_fc
;
1223 opt_fc
= g_new0(struct bt_field_class_option
, 1);
1225 BT_LIB_LOGE_APPEND_CAUSE(
1226 "Failed to allocate one option field class.");
1233 if (init_field_class((void *) opt_fc
, fc_type
,
1234 destroy_option_field_class
)) {
1238 opt_fc
->content_fc
= content_fc
;
1239 bt_object_get_ref_no_null_check(opt_fc
->content_fc
);
1240 bt_field_class_freeze(opt_fc
->content_fc
);
1243 bt_field_class_freeze(selector_fc
);
1246 BT_LIB_LOGD("Created option field class object: "
1247 "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc
, selector_fc
);
1251 BT_OBJECT_PUT_REF_AND_RESET(opt_fc
);
1254 return (void *) opt_fc
;
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
)
1261 return create_option_field_class(trace_class
,
1262 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1266 struct bt_field_class
*bt_field_class_option_with_selector_field_bool_create(
1267 struct bt_trace_class
*trace_class
,
1268 struct bt_field_class
*content_fc
,
1269 struct bt_field_class
*selector_fc
)
1271 struct bt_field_class_option_with_selector_field_bool
*fc
=
1272 (void *) create_option_field_class(trace_class
,
1273 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1274 content_fc
, selector_fc
);
1284 struct bt_field_class
*
1285 bt_field_class_option_with_selector_field_integer_unsigned_create(
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
)
1291 struct bt_field_class_option_with_selector_field_integer
*fc
;
1292 const struct bt_integer_range_set
*range_set
=
1293 (const void *) u_range_set
;
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
,
1299 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1300 content_fc
, selector_fc
);
1306 fc
->range_set
= range_set
;
1307 bt_object_get_ref_no_null_check(fc
->range_set
);
1308 bt_integer_range_set_freeze(range_set
);
1314 struct bt_field_class
*
1315 bt_field_class_option_with_selector_field_integer_signed_create(
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
)
1321 struct bt_field_class_option_with_selector_field_integer
*fc
;
1322 const struct bt_integer_range_set
*range_set
=
1323 (const void *) i_range_set
;
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
,
1329 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1330 content_fc
, selector_fc
);
1336 fc
->range_set
= range_set
;
1337 bt_object_get_ref_no_null_check(fc
->range_set
);
1338 bt_integer_range_set_freeze(range_set
);
1344 const struct bt_field_class
*bt_field_class_option_borrow_field_class_const(
1345 const struct bt_field_class
*fc
)
1347 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1349 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1350 BT_ASSERT_PRE_FC_IS_OPTION(fc
, "Field class");
1351 return opt_fc
->content_fc
;
1354 struct bt_field_class
*bt_field_class_option_borrow_field_class(
1355 struct bt_field_class
*fc
)
1357 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1359 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1360 BT_ASSERT_PRE_FC_IS_OPTION(fc
, "Field class");
1361 return opt_fc
->content_fc
;
1364 const struct bt_field_path
*
1365 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1366 const struct bt_field_class
*fc
)
1368 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1371 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1372 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(fc
, "Field class");
1373 return opt_fc
->selector_field_path
;
1376 void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
1377 struct bt_field_class
*fc
, bt_bool sel_is_reversed
)
1379 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1381 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1382 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1383 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
, "Field class");
1384 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
1385 opt_fc
->sel_is_reversed
= sel_is_reversed
;
1388 bt_bool
bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1389 const struct bt_field_class
*fc
)
1391 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1393 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1394 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1395 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
, "Field class");
1396 return opt_fc
->sel_is_reversed
;
1399 const struct bt_integer_range_set_unsigned
*
1400 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1401 const struct bt_field_class
*fc
)
1403 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
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
;
1411 const struct bt_integer_range_set_signed
*
1412 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1413 const struct bt_field_class
*fc
)
1415 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
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
;
1424 void finalize_variant_field_class(struct bt_field_class_variant
*var_fc
)
1427 BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc
);
1428 finalize_field_class((void *) var_fc
);
1429 finalize_named_field_classes_container((void *) var_fc
);
1433 void destroy_variant_field_class(struct bt_object
*obj
)
1435 struct bt_field_class_variant
*fc
= (void *) obj
;
1438 finalize_variant_field_class(fc
);
1443 void destroy_variant_with_selector_field_field_class(struct bt_object
*obj
)
1445 struct bt_field_class_variant_with_selector_field
*fc
= (void *) obj
;
1448 finalize_variant_field_class(&fc
->common
);
1449 BT_LOGD_STR("Putting selector field path.");
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
);
1456 struct bt_field_class
*bt_field_class_variant_create(
1457 bt_trace_class
*trace_class
, bt_field_class
*selector_fc
)
1460 struct bt_field_class_variant
*var_fc
= NULL
;
1461 struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
= NULL
;
1462 enum bt_field_class_type fc_type
;
1464 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1467 BT_ASSERT_PRE_FC_IS_INT(selector_fc
, "Selector field class");
1470 BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F",
1474 var_with_sel_fc
= g_new0(
1475 struct bt_field_class_variant_with_selector_field
, 1);
1476 if (!var_with_sel_fc
) {
1477 BT_LIB_LOGE_APPEND_CAUSE(
1478 "Failed to allocate one variant field class with selector.");
1482 if (bt_field_class_type_is(selector_fc
->type
,
1483 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
)) {
1484 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
;
1486 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
;
1489 ret
= init_named_field_classes_container(
1490 (void *) var_with_sel_fc
, fc_type
,
1491 destroy_variant_with_selector_field_field_class
,
1492 destroy_variant_with_selector_field_option
);
1494 /* init_named_field_classes_container() logs errors */
1498 var_with_sel_fc
->selector_fc
= selector_fc
;
1499 bt_object_get_ref_no_null_check(var_with_sel_fc
->selector_fc
);
1500 bt_field_class_freeze(selector_fc
);
1501 var_fc
= (void *) var_with_sel_fc
;
1502 BT_LIB_LOGD("Created default variant field class with selector object: "
1503 "%![var-fc-]+F, %![sel-fc-]+F", var_fc
, selector_fc
);
1505 var_fc
= g_new0(struct bt_field_class_variant
, 1);
1507 BT_LIB_LOGE_APPEND_CAUSE(
1508 "Failed to allocate one variant field class without selector.");
1512 ret
= init_named_field_classes_container((void *) var_fc
,
1513 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1514 destroy_variant_field_class
, destroy_named_field_class
);
1516 /* init_named_field_classes_container() logs errors */
1519 BT_LIB_LOGD("Created default variant field class without selector object: "
1520 "%![var-fc-]+F", var_fc
);
1527 BT_OBJECT_PUT_REF_AND_RESET(var_fc
);
1528 BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc
);
1531 return (void *) var_fc
;
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
)
1538 enum bt_field_class_variant_without_selector_append_option_status status
;
1539 struct bt_named_field_class
*named_fc
= NULL
;
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
,
1545 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
, "Field class");
1546 named_fc
= create_named_field_class(name
, option_fc
);
1548 /* create_named_field_class() logs errors */
1549 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1553 status
= append_named_field_class_to_container_field_class((void *) fc
,
1555 if (status
== BT_FUNC_STATUS_OK
) {
1556 /* Moved to the container */
1562 destroy_named_field_class(named_fc
);
1569 int ranges_overlap(GPtrArray
*var_fc_opts
, const struct bt_integer_range_set
*range_set
,
1570 bool is_signed
, bool *has_overlap
)
1572 int status
= BT_FUNC_STATUS_OK
;
1573 struct bt_integer_range_set
*full_range_set
;
1576 *has_overlap
= false;
1579 * Build a single range set with all the ranges and test for
1583 full_range_set
= (void *) bt_integer_range_set_signed_create();
1585 full_range_set
= (void *) bt_integer_range_set_unsigned_create();
1588 if (!full_range_set
) {
1589 BT_LOGE_STR("Failed to create a range set.");
1590 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1594 /* Add existing option ranges */
1595 for (i
= 0; i
< var_fc_opts
->len
; i
++) {
1596 struct bt_field_class_variant_with_selector_field_option
*opt
=
1597 var_fc_opts
->pdata
[i
];
1600 for (j
= 0; j
< opt
->range_set
->ranges
->len
; j
++) {
1601 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1605 status
= bt_integer_range_set_signed_add_range(
1606 (void *) full_range_set
, range
->lower
.i
,
1609 status
= bt_integer_range_set_unsigned_add_range(
1610 (void *) full_range_set
, range
->lower
.u
,
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(
1626 status
= bt_integer_range_set_signed_add_range(
1627 (void *) full_range_set
, range
->lower
.i
,
1630 status
= bt_integer_range_set_unsigned_add_range(
1631 (void *) full_range_set
, range
->lower
.u
,
1640 /* Check overlaps */
1642 *has_overlap
= bt_integer_range_set_signed_has_overlaps(full_range_set
);
1644 *has_overlap
= bt_integer_range_set_unsigned_has_overlaps(
1649 bt_object_put_ref(full_range_set
);
1654 int append_option_to_variant_with_selector_field_field_class(
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
)
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
;
1665 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1666 BT_ASSERT_PRE_NON_NULL(name
, "Name");
1667 BT_ASSERT_PRE_NON_NULL(option_fc
, "Option field class");
1668 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1669 BT_ASSERT_PRE_FC_HAS_ID(fc
, expected_type
, "Field class");
1670 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1671 "Integer range set is empty: %!+R", range_set
);
1672 status
= ranges_overlap(var_fc
->common
.common
.named_fcs
, range_set
,
1673 expected_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1676 /* ranges_overlap() logs errors */
1680 BT_ASSERT_PRE(!has_overlap
,
1681 "Integer range set's ranges and existing ranges have an overlap: "
1683 opt
= create_variant_with_selector_field_option(name
, option_fc
, range_set
);
1685 /* create_variant_with_selector_field_option() logs errors */
1686 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1690 status
= append_named_field_class_to_container_field_class((void *) fc
,
1692 if (status
== BT_FUNC_STATUS_OK
) {
1693 /* Moved to the container */
1699 destroy_variant_with_selector_field_option(opt
);
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(
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
)
1711 return append_option_to_variant_with_selector_field_field_class(fc
,
1712 name
, option_fc
, (const void *) range_set
,
1713 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
);
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(
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
)
1722 return append_option_to_variant_with_selector_field_field_class(fc
,
1723 name
, option_fc
, (const void *) range_set
,
1724 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
);
1727 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class
*fc
)
1729 const struct bt_field_class_variant
*var_fc
= (const void *) fc
;
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
;
1736 const struct bt_field_class_variant_option
*
1737 bt_field_class_variant_borrow_option_by_name_const(
1738 const struct bt_field_class
*fc
, const char *name
)
1740 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1741 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1742 return (const void *)
1743 borrow_named_field_class_from_container_field_class_by_name(
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
)
1751 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
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(
1755 (void *) fc
, index
);
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
)
1762 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1763 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1765 borrow_named_field_class_from_container_field_class_by_name(
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
)
1773 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1774 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1776 borrow_named_field_class_from_container_field_class_at_index(
1777 (void *) fc
, index
);
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(
1782 const struct bt_field_class
*fc
, const char *name
)
1784 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1785 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1786 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1788 return (const void *)
1789 borrow_named_field_class_from_container_field_class_by_name(
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(
1795 const struct bt_field_class
*fc
, uint64_t index
)
1797 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1798 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1799 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1801 return (const void *)
1802 borrow_named_field_class_from_container_field_class_at_index(
1803 (void *) fc
, index
);
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(
1808 const struct bt_field_class
*fc
, const char *name
)
1810 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1811 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1812 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1814 return (const void *)
1815 borrow_named_field_class_from_container_field_class_by_name(
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(
1821 const struct bt_field_class
*fc
, uint64_t index
)
1823 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1824 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1825 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1827 return (const void *)
1828 borrow_named_field_class_from_container_field_class_at_index(
1829 (void *) fc
, index
);
1832 const char *bt_field_class_variant_option_get_name(
1833 const struct bt_field_class_variant_option
*option
)
1835 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1837 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1838 return named_fc
->name
->str
;
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
)
1845 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1847 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1848 return named_fc
->fc
;
1851 struct bt_field_class
*
1852 bt_field_class_variant_option_borrow_field_class(
1853 struct bt_field_class_variant_option
*option
)
1855 struct bt_named_field_class
*named_fc
= (void *) option
;
1857 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1858 return named_fc
->fc
;
1861 const struct bt_integer_range_set_unsigned
*
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
)
1865 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1866 (const void *) option
;
1868 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1869 return (const void *) opt
->range_set
;
1872 const struct bt_integer_range_set_signed
*
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
)
1876 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1877 (const void *) option
;
1879 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1880 return (const void *) opt
->range_set
;
1883 const struct bt_field_path
*
1884 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
1885 const struct bt_field_class
*fc
)
1887 const struct bt_field_class_variant_with_selector_field
*var_fc
=
1890 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1891 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(fc
, "Field class");
1892 return var_fc
->selector_field_path
;
1896 int init_array_field_class(struct bt_field_class_array
*fc
,
1897 enum bt_field_class_type type
, bt_object_release_func release_func
,
1898 struct bt_field_class
*element_fc
)
1902 BT_ASSERT(element_fc
);
1903 ret
= init_field_class((void *) fc
, type
, release_func
);
1908 fc
->element_fc
= element_fc
;
1909 bt_object_get_ref_no_null_check(fc
->element_fc
);
1910 bt_field_class_freeze(element_fc
);
1917 void finalize_array_field_class(struct bt_field_class_array
*array_fc
)
1919 BT_ASSERT(array_fc
);
1920 BT_LOGD_STR("Putting element field class.");
1921 finalize_field_class((void *) array_fc
);
1922 BT_OBJECT_PUT_REF_AND_RESET(array_fc
->element_fc
);
1926 void destroy_static_array_field_class(struct bt_object
*obj
)
1929 BT_LIB_LOGD("Destroying static array field class object: %!+F", obj
);
1930 finalize_array_field_class((void *) obj
);
1934 struct bt_field_class
*
1935 bt_field_class_array_static_create(bt_trace_class
*trace_class
,
1936 struct bt_field_class
*element_fc
, uint64_t length
)
1938 struct bt_field_class_array_static
*array_fc
= NULL
;
1940 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1941 BT_ASSERT_PRE_NON_NULL(element_fc
, "Element field class");
1942 BT_LOGD_STR("Creating default static array field class object.");
1943 array_fc
= g_new0(struct bt_field_class_array_static
, 1);
1945 BT_LIB_LOGE_APPEND_CAUSE(
1946 "Failed to allocate one static array field class.");
1950 if (init_array_field_class((void *) array_fc
,
1951 BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
1952 destroy_static_array_field_class
, element_fc
)) {
1956 array_fc
->length
= length
;
1957 BT_LIB_LOGD("Created static array field class object: %!+F", array_fc
);
1961 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
1964 return (void *) array_fc
;
1967 const struct bt_field_class
*
1968 bt_field_class_array_borrow_element_field_class_const(
1969 const struct bt_field_class
*fc
)
1971 const struct bt_field_class_array
*array_fc
= (const void *) fc
;
1973 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1974 BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc
, "Field class");
1975 return array_fc
->element_fc
;
1978 struct bt_field_class
*
1979 bt_field_class_array_borrow_element_field_class(struct bt_field_class
*fc
)
1981 struct bt_field_class_array
*array_fc
= (void *) fc
;
1983 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1984 BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc
, "Field class");
1985 return array_fc
->element_fc
;
1988 uint64_t bt_field_class_array_static_get_length(const struct bt_field_class
*fc
)
1990 const struct bt_field_class_array_static
*array_fc
= (const void *) fc
;
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
,
1995 return (uint64_t) array_fc
->length
;
1999 void destroy_dynamic_array_field_class(struct bt_object
*obj
)
2001 struct bt_field_class_array_dynamic
*fc
= (void *) obj
;
2004 BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc
);
2005 finalize_array_field_class((void *) fc
);
2006 BT_LOGD_STR("Putting length field path.");
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
);
2013 struct bt_field_class
*bt_field_class_array_dynamic_create(
2014 struct bt_trace_class
*trace_class
,
2015 struct bt_field_class
*element_fc
,
2016 struct bt_field_class
*length_fc
)
2018 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2020 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
2021 BT_ASSERT_PRE_NON_NULL(element_fc
, "Element field class");
2022 BT_LOGD_STR("Creating default dynamic array field class object.");
2023 array_fc
= g_new0(struct bt_field_class_array_dynamic
, 1);
2025 BT_LIB_LOGE_APPEND_CAUSE(
2026 "Failed to allocate one dynamic array field class.");
2030 if (init_array_field_class((void *) array_fc
,
2032 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
2033 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2034 destroy_dynamic_array_field_class
, element_fc
)) {
2039 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc
,
2040 "Length field class");
2041 array_fc
->length_fc
= length_fc
;
2042 bt_object_get_ref_no_null_check(array_fc
->length_fc
);
2043 bt_field_class_freeze(length_fc
);
2046 BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc
);
2050 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2053 return (void *) array_fc
;
2056 const struct bt_field_path
*
2057 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
2058 const struct bt_field_class
*fc
)
2060 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2062 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2063 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
2064 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2066 return seq_fc
->length_field_path
;
2070 void destroy_string_field_class(struct bt_object
*obj
)
2073 BT_LIB_LOGD("Destroying string field class object: %!+F", obj
);
2074 finalize_field_class((void *) obj
);
2078 struct bt_field_class
*bt_field_class_string_create(bt_trace_class
*trace_class
)
2080 struct bt_field_class_string
*string_fc
= NULL
;
2082 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
2083 BT_LOGD_STR("Creating default string field class object.");
2084 string_fc
= g_new0(struct bt_field_class_string
, 1);
2086 BT_LIB_LOGE_APPEND_CAUSE(
2087 "Failed to allocate one string field class.");
2091 if (init_field_class((void *) string_fc
, BT_FIELD_CLASS_TYPE_STRING
,
2092 destroy_string_field_class
)) {
2096 BT_LIB_LOGD("Created string field class object: %!+F", string_fc
);
2100 BT_OBJECT_PUT_REF_AND_RESET(string_fc
);
2103 return (void *) string_fc
;
2107 void _bt_field_class_freeze(const struct bt_field_class
*c_fc
)
2109 struct bt_field_class
*fc
= (void *) c_fc
;
2112 * Element/member/option field classes are frozen when added to
2116 bt_value_freeze(fc
->user_attributes
);
2119 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2120 bt_field_class_type_is(fc
->type
,
2121 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2122 struct bt_field_class_named_field_class_container
*container_fc
=
2126 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2127 bt_named_field_class_freeze(
2128 container_fc
->named_fcs
->pdata
[i
]);
2134 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
)
2136 BT_ASSERT(named_fc
);
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
);
2141 ((struct bt_named_field_class
*) named_fc
)->frozen
= true;
2145 void bt_field_class_make_part_of_trace_class(const struct bt_field_class
*c_fc
)
2147 struct bt_field_class
*fc
= (void *) c_fc
;
2150 BT_ASSERT_PRE(!fc
->part_of_trace_class
,
2151 "Field class is already part of a trace: %!+F", fc
);
2152 fc
->part_of_trace_class
= true;
2154 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2155 bt_field_class_type_is(fc
->type
,
2156 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2157 struct bt_field_class_named_field_class_container
*container_fc
=
2161 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2162 struct bt_named_field_class
*named_fc
=
2163 container_fc
->named_fcs
->pdata
[i
];
2165 bt_field_class_make_part_of_trace_class(named_fc
->fc
);
2167 } else if (bt_field_class_type_is(fc
->type
,
2168 BT_FIELD_CLASS_TYPE_ARRAY
)) {
2169 struct bt_field_class_array
*array_fc
= (void *) fc
;
2171 bt_field_class_make_part_of_trace_class(array_fc
->element_fc
);
2175 const struct bt_value
*bt_field_class_borrow_user_attributes_const(
2176 const struct bt_field_class
*fc
)
2178 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2179 return fc
->user_attributes
;
2182 struct bt_value
*bt_field_class_borrow_user_attributes(
2183 struct bt_field_class
*field_class
)
2185 return (void *) bt_field_class_borrow_user_attributes_const(
2186 (void *) field_class
);
2190 void bt_field_class_set_user_attributes(
2191 struct bt_field_class
*fc
,
2192 const struct bt_value
*user_attributes
)
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");
2199 bt_object_put_ref_no_null_check(fc
->user_attributes
);
2200 fc
->user_attributes
= (void *) user_attributes
;
2201 bt_object_get_ref_no_null_check(fc
->user_attributes
);
2205 const struct bt_value
*bt_named_field_class_borrow_user_attributes_const(
2206 const struct bt_named_field_class
*named_fc
)
2208 return named_fc
->user_attributes
;
2212 void bt_named_field_class_set_user_attributes(
2213 struct bt_named_field_class
*named_fc
,
2214 const struct bt_value
*user_attributes
)
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",
2222 bt_object_put_ref_no_null_check(named_fc
->user_attributes
);
2223 named_fc
->user_attributes
= (void *) user_attributes
;
2224 bt_object_get_ref_no_null_check(named_fc
->user_attributes
);
2227 const struct bt_value
*
2228 bt_field_class_structure_member_borrow_user_attributes_const(
2229 const struct bt_field_class_structure_member
*member
)
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
);
2237 bt_field_class_structure_member_borrow_user_attributes(
2238 struct bt_field_class_structure_member
*member
)
2240 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2241 return (void *) bt_named_field_class_borrow_user_attributes_const(
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
)
2249 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2250 bt_named_field_class_set_user_attributes((void *) member
,
2254 const struct bt_value
*bt_field_class_variant_option_borrow_user_attributes_const(
2255 const struct bt_field_class_variant_option
*option
)
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
);
2262 struct bt_value
*bt_field_class_variant_option_borrow_user_attributes(
2263 struct bt_field_class_variant_option
*option
)
2265 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2266 return (void *) bt_named_field_class_borrow_user_attributes_const(
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
)
2274 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2275 bt_named_field_class_set_user_attributes((void *) option
,
2279 void bt_field_class_get_ref(const struct bt_field_class
*field_class
)
2281 bt_object_get_ref(field_class
);
2284 void bt_field_class_put_ref(const struct bt_field_class
*field_class
)
2286 bt_object_put_ref(field_class
);