2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/FIELD-CLASS"
9 #include "lib/logging.h"
11 #include "lib/assert-cond.h"
12 #include <babeltrace2/trace-ir/field-class.h>
13 #include <babeltrace2/trace-ir/field.h>
14 #include <babeltrace2/trace-ir/clock-class.h>
15 #include "lib/object.h"
16 #include "compat/compiler.h"
17 #include "compat/endian.h"
18 #include "common/assert.h"
19 #include "common/common.h"
20 #include "compat/glib.h"
25 #include "field-class.h"
26 #include "field-path.h"
27 #include "lib/func-status.h"
28 #include "lib/integer-range-set.h"
29 #include "lib/value.h"
32 enum bt_field_class_type
bt_field_class_get_type(
33 const struct bt_field_class
*fc
)
35 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
40 int init_field_class(struct bt_field_class
*fc
, enum bt_field_class_type type
,
41 bt_object_release_func release_func
)
46 BT_ASSERT(release_func
);
47 bt_object_init_shared(&fc
->base
, release_func
);
49 fc
->user_attributes
= bt_value_map_create();
50 if (!fc
->user_attributes
) {
51 BT_LIB_LOGE_APPEND_CAUSE(
52 "Failed to create a map value object.");
62 void finalize_field_class(struct bt_field_class
*fc
)
64 BT_OBJECT_PUT_REF_AND_RESET(fc
->user_attributes
);
68 void destroy_bit_array_field_class(struct bt_object
*obj
)
71 BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj
);
72 finalize_field_class((void *) obj
);
77 struct bt_field_class
*bt_field_class_bit_array_create(
78 struct bt_trace_class
*trace_class
, uint64_t length
)
80 struct bt_field_class_bit_array
*ba_fc
= NULL
;
82 BT_ASSERT_PRE_NO_ERROR();
83 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
84 BT_ASSERT_PRE("valid-length", length
> 0 && length
<= 64,
85 "Unsupported length for bit array field class "
86 "(minimum is 1, maximum is 64): length=%" PRIu64
, length
);
87 BT_LOGD("Creating default bit array field class object.");
88 ba_fc
= g_new0(struct bt_field_class_bit_array
, 1);
90 BT_LIB_LOGE_APPEND_CAUSE(
91 "Failed to allocate one bit array field class.");
95 if (init_field_class((void *) ba_fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
96 destroy_bit_array_field_class
)) {
100 ba_fc
->length
= length
;
101 BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc
);
105 BT_OBJECT_PUT_REF_AND_RESET(ba_fc
);
108 return (void *) ba_fc
;
112 uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class
*fc
)
114 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
116 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
117 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
118 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
119 return ba_fc
->length
;
123 void destroy_bool_field_class(struct bt_object
*obj
)
126 BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj
);
127 finalize_field_class((void *) obj
);
132 struct bt_field_class
*bt_field_class_bool_create(
133 bt_trace_class
*trace_class
)
135 struct bt_field_class_bool
*bool_fc
= NULL
;
137 BT_ASSERT_PRE_NO_ERROR();
138 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
139 BT_LOGD("Creating default boolean field class object.");
140 bool_fc
= g_new0(struct bt_field_class_bool
, 1);
142 BT_LIB_LOGE_APPEND_CAUSE(
143 "Failed to allocate one boolean field class.");
147 if (init_field_class((void *) bool_fc
, BT_FIELD_CLASS_TYPE_BOOL
,
148 destroy_bool_field_class
)) {
152 BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc
);
156 BT_OBJECT_PUT_REF_AND_RESET(bool_fc
);
159 return (void *) bool_fc
;
163 int init_integer_field_class(struct bt_field_class_integer
*fc
,
164 enum bt_field_class_type type
,
165 bt_object_release_func release_func
)
169 ret
= init_field_class((void *) fc
, type
, release_func
);
175 fc
->base
= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
;
182 void destroy_integer_field_class(struct bt_object
*obj
)
185 BT_LIB_LOGD("Destroying integer field class object: %!+F", obj
);
186 finalize_field_class((void *) obj
);
191 struct bt_field_class
*create_integer_field_class(bt_trace_class
*trace_class
,
192 enum bt_field_class_type type
)
194 struct bt_field_class_integer
*int_fc
= NULL
;
196 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
197 BT_LOGD("Creating default integer field class object: type=%s",
198 bt_common_field_class_type_string(type
));
199 int_fc
= g_new0(struct bt_field_class_integer
, 1);
201 BT_LIB_LOGE_APPEND_CAUSE(
202 "Failed to allocate one integer field class.");
206 if (init_integer_field_class(int_fc
, type
,
207 destroy_integer_field_class
)) {
211 BT_LIB_LOGD("Created integer field class object: %!+F", int_fc
);
215 BT_OBJECT_PUT_REF_AND_RESET(int_fc
);
218 return (void *) int_fc
;
222 struct bt_field_class
*bt_field_class_integer_unsigned_create(
223 bt_trace_class
*trace_class
)
225 BT_ASSERT_PRE_NO_ERROR();
227 return create_integer_field_class(trace_class
,
228 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
232 struct bt_field_class
*bt_field_class_integer_signed_create(
233 bt_trace_class
*trace_class
)
235 BT_ASSERT_PRE_NO_ERROR();
237 return create_integer_field_class(trace_class
,
238 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
242 uint64_t bt_field_class_integer_get_field_value_range(
243 const struct bt_field_class
*fc
)
245 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
247 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
248 BT_ASSERT_PRE_DEV_FC_IS_INT("field-class", fc
, "Field class");
249 return int_fc
->range
;
253 bool size_is_valid_for_enumeration_field_class(
254 struct bt_field_class
*fc
__attribute__((unused
)),
255 uint64_t size
__attribute__((unused
)))
262 void bt_field_class_integer_set_field_value_range(
263 struct bt_field_class
*fc
, uint64_t size
)
265 struct bt_field_class_integer
*int_fc
= (void *) fc
;
267 BT_ASSERT_PRE_FC_NON_NULL(fc
);
268 BT_ASSERT_PRE_FC_IS_INT("field-class", fc
, "Field class");
269 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
270 BT_ASSERT_PRE("valid-n",
271 size
>= 1 && size
<= 64,
272 "Unsupported size for integer field class's field value range "
273 "(minimum is 1, maximum is 64): size=%" PRIu64
, size
);
274 BT_ASSERT_PRE("valid-n-for-enumeration-field-class",
275 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
276 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
277 size_is_valid_for_enumeration_field_class(fc
, size
),
278 "Invalid field value range for enumeration field class: "
279 "at least one of the current mapping ranges contains values "
280 "which are outside this range: %!+F, size=%" PRIu64
, fc
, size
);
281 int_fc
->range
= size
;
282 BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc
);
286 enum bt_field_class_integer_preferred_display_base
287 bt_field_class_integer_get_preferred_display_base(const struct bt_field_class
*fc
)
289 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
291 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
292 BT_ASSERT_PRE_DEV_FC_IS_INT("field-class", fc
, "Field class");
297 void bt_field_class_integer_set_preferred_display_base(
298 struct bt_field_class
*fc
,
299 enum bt_field_class_integer_preferred_display_base base
)
301 struct bt_field_class_integer
*int_fc
= (void *) fc
;
303 BT_ASSERT_PRE_FC_NON_NULL(fc
);
304 BT_ASSERT_PRE_FC_IS_INT("field-class", fc
, "Field class");
305 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
307 BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc
);
311 void finalize_enumeration_field_class_mapping(
312 struct bt_field_class_enumeration_mapping
*mapping
)
316 if (mapping
->label
) {
317 g_string_free(mapping
->label
, TRUE
);
318 mapping
->label
= NULL
;
321 BT_OBJECT_PUT_REF_AND_RESET(mapping
->range_set
);
325 void destroy_enumeration_field_class(struct bt_object
*obj
)
327 struct bt_field_class_enumeration
*fc
= (void *) obj
;
330 BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc
);
331 finalize_field_class((void *) obj
);
336 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
337 finalize_enumeration_field_class_mapping(
338 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
));
341 g_array_free(fc
->mappings
, TRUE
);
346 g_ptr_array_free(fc
->label_buf
, TRUE
);
347 fc
->label_buf
= NULL
;
354 struct bt_field_class
*create_enumeration_field_class(
355 bt_trace_class
*trace_class
, enum bt_field_class_type type
)
357 struct bt_field_class_enumeration
*enum_fc
= NULL
;
359 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
360 BT_LOGD("Creating default enumeration field class object: type=%s",
361 bt_common_field_class_type_string(type
));
362 enum_fc
= g_new0(struct bt_field_class_enumeration
, 1);
364 BT_LIB_LOGE_APPEND_CAUSE(
365 "Failed to allocate one enumeration field class.");
369 if (init_integer_field_class((void *) enum_fc
, type
,
370 destroy_enumeration_field_class
)) {
374 enum_fc
->mappings
= g_array_new(FALSE
, TRUE
,
375 sizeof(struct bt_field_class_enumeration_mapping
));
376 if (!enum_fc
->mappings
) {
377 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
381 enum_fc
->label_buf
= g_ptr_array_new();
382 if (!enum_fc
->label_buf
) {
383 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
387 BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc
);
391 BT_OBJECT_PUT_REF_AND_RESET(enum_fc
);
394 return (void *) enum_fc
;
398 struct bt_field_class
*bt_field_class_enumeration_unsigned_create(
399 bt_trace_class
*trace_class
)
401 BT_ASSERT_PRE_NO_ERROR();
403 return create_enumeration_field_class(trace_class
,
404 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
408 struct bt_field_class
*bt_field_class_enumeration_signed_create(
409 bt_trace_class
*trace_class
)
411 BT_ASSERT_PRE_NO_ERROR();
413 return create_enumeration_field_class(trace_class
,
414 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
418 uint64_t bt_field_class_enumeration_get_mapping_count(
419 const struct bt_field_class
*fc
)
421 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
423 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
424 BT_ASSERT_PRE_DEV_FC_IS_ENUM("field-class", fc
, "Field class");
425 return (uint64_t) enum_fc
->mappings
->len
;
429 const struct bt_field_class_enumeration_unsigned_mapping
*
430 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
431 const struct bt_field_class
*fc
, uint64_t index
)
433 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
435 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
436 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
437 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
438 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
439 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
443 const struct bt_field_class_enumeration_signed_mapping
*
444 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
445 const struct bt_field_class
*fc
, uint64_t index
)
447 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
449 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
450 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
451 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
452 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
453 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
457 const struct bt_field_class_enumeration_mapping
*
458 borrow_enumeration_field_class_mapping_by_label(
459 const struct bt_field_class_enumeration
*fc
, const char *label
,
460 const char *api_func
)
462 struct bt_field_class_enumeration_mapping
*mapping
= NULL
;
466 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "label", label
,
469 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
470 struct bt_field_class_enumeration_mapping
*this_mapping
=
471 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
);
473 if (strcmp(this_mapping
->label
->str
, label
) == 0) {
474 mapping
= this_mapping
;
484 const struct bt_field_class_enumeration_signed_mapping
*
485 bt_field_class_enumeration_signed_borrow_mapping_by_label_const(
486 const struct bt_field_class
*fc
, const char *label
)
488 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
489 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
490 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
491 return (const void *) borrow_enumeration_field_class_mapping_by_label(
492 (const void *) fc
, label
, __func__
);
496 const struct bt_field_class_enumeration_unsigned_mapping
*
497 bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(
498 const struct bt_field_class
*fc
, const char *label
)
500 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
501 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
502 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
503 return (const void *) borrow_enumeration_field_class_mapping_by_label(
504 (const void *) fc
, label
, __func__
);
508 const char *bt_field_class_enumeration_mapping_get_label(
509 const struct bt_field_class_enumeration_mapping
*mapping
)
511 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
512 mapping
, "Enumeration field class mapping");
513 return mapping
->label
->str
;
517 const struct bt_integer_range_set_unsigned
*
518 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
519 const struct bt_field_class_enumeration_unsigned_mapping
*u_mapping
)
521 const struct bt_field_class_enumeration_mapping
*mapping
=
522 (const void *) u_mapping
;
524 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
525 mapping
, "Enumeration field class mapping");
526 return (const void *) mapping
->range_set
;
530 const struct bt_integer_range_set_signed
*
531 bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
532 const struct bt_field_class_enumeration_signed_mapping
*s_mapping
)
534 const struct bt_field_class_enumeration_mapping
*mapping
=
535 (const void *) s_mapping
;
537 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
538 mapping
, "Enumeration field class mapping");
539 return (const void *) mapping
->range_set
;
543 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
544 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
545 const struct bt_field_class
*fc
, uint64_t value
,
546 bt_field_class_enumeration_mapping_label_array
*label_array
,
549 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
552 BT_ASSERT_PRE_DEV_NO_ERROR();
553 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
554 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
555 "Label array (output)");
556 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
557 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
558 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
559 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
561 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
563 const struct bt_field_class_enumeration_mapping
*mapping
=
564 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
566 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
567 const struct bt_integer_range
*range
= (const void *)
568 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
569 mapping
->range_set
, j
);
571 if (value
>= range
->lower
.u
&&
572 value
<= range
->upper
.u
) {
573 g_ptr_array_add(enum_fc
->label_buf
,
574 mapping
->label
->str
);
580 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
581 *count
= (uint64_t) enum_fc
->label_buf
->len
;
582 return BT_FUNC_STATUS_OK
;
586 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
587 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
588 const struct bt_field_class
*fc
, int64_t value
,
589 bt_field_class_enumeration_mapping_label_array
*label_array
,
592 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
595 BT_ASSERT_PRE_DEV_NO_ERROR();
596 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
597 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
598 "Label array (output)");
599 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
600 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
601 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
602 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
604 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
606 const struct bt_field_class_enumeration_mapping
*mapping
=
607 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
609 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
610 const struct bt_integer_range
*range
= (const void *)
611 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
612 mapping
->range_set
, j
);
614 if (value
>= range
->lower
.i
&&
615 value
<= range
->upper
.i
) {
616 g_ptr_array_add(enum_fc
->label_buf
,
617 mapping
->label
->str
);
623 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
624 *count
= (uint64_t) enum_fc
->label_buf
->len
;
625 return BT_FUNC_STATUS_OK
;
629 bool enumeration_field_class_has_mapping_with_label(
630 const struct bt_field_class_enumeration
*enum_fc
,
639 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
640 struct bt_field_class_enumeration_mapping
*mapping_candidate
=
641 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
643 if (strcmp(mapping_candidate
->label
->str
, label
) == 0) {
654 enum bt_field_class_enumeration_add_mapping_status
655 add_mapping_to_enumeration_field_class(struct bt_field_class
*fc
,
656 const char *label
, const struct bt_integer_range_set
*range_set
,
657 const char *api_func
)
659 enum bt_field_class_enumeration_add_mapping_status status
=
661 struct bt_field_class_enumeration
*enum_fc
= (void *) fc
;
662 struct bt_field_class_enumeration_mapping mapping
= { 0 };
664 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
666 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "label", label
, "Label");
667 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL_FROM_FUNC(api_func
, range_set
);
668 BT_ASSERT_PRE_FROM_FUNC(api_func
,
669 "enumeration-field-class-mapping-label-is-unique",
670 !enumeration_field_class_has_mapping_with_label(
672 "Duplicate mapping name in enumeration field class: "
673 "%![enum-fc-]+F, label=\"%s\"", fc
, label
);
674 mapping
.range_set
= range_set
;
675 bt_object_get_ref(mapping
.range_set
);
676 mapping
.label
= g_string_new(label
);
677 if (!mapping
.label
) {
678 finalize_enumeration_field_class_mapping(&mapping
);
679 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
683 g_array_append_val(enum_fc
->mappings
, mapping
);
684 BT_LIB_LOGD("Added mapping to enumeration field class: "
685 "%![fc-]+F, label=\"%s\"", fc
, label
);
692 enum bt_field_class_enumeration_add_mapping_status
693 bt_field_class_enumeration_unsigned_add_mapping(
694 struct bt_field_class
*fc
, const char *label
,
695 const struct bt_integer_range_set_unsigned
*range_set
)
697 BT_ASSERT_PRE_NO_ERROR();
698 BT_ASSERT_PRE_FC_NON_NULL(fc
);
699 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
700 "unsigned-enumeration-field-class",
701 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
702 return add_mapping_to_enumeration_field_class(fc
, label
,
703 (const void *) range_set
, __func__
);
707 enum bt_field_class_enumeration_add_mapping_status
708 bt_field_class_enumeration_signed_add_mapping(
709 struct bt_field_class
*fc
, const char *label
,
710 const struct bt_integer_range_set_signed
*range_set
)
712 BT_ASSERT_PRE_NO_ERROR();
713 BT_ASSERT_PRE_FC_NON_NULL(fc
);
714 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
715 "signed-enumeration-field-class",
716 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
717 return add_mapping_to_enumeration_field_class(fc
, label
,
718 (const void *) range_set
, __func__
);
722 void destroy_real_field_class(struct bt_object
*obj
)
725 BT_LIB_LOGD("Destroying real field class object: %!+F", obj
);
726 finalize_field_class((void *) obj
);
731 struct bt_field_class
*create_real_field_class(bt_trace_class
*trace_class
,
732 enum bt_field_class_type type
)
734 struct bt_field_class_real
*real_fc
= NULL
;
736 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
737 BT_LOGD("Creating default real field class object: type=%s",
738 bt_common_field_class_type_string(type
));
739 real_fc
= g_new0(struct bt_field_class_real
, 1);
741 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
745 if (init_field_class((void *) real_fc
, type
, destroy_real_field_class
)) {
749 BT_LIB_LOGD("Created real field class object: %!+F", real_fc
);
753 BT_OBJECT_PUT_REF_AND_RESET(real_fc
);
756 return (void *) real_fc
;
760 struct bt_field_class
*bt_field_class_real_single_precision_create(
761 bt_trace_class
*trace_class
)
763 BT_ASSERT_PRE_NO_ERROR();
765 return create_real_field_class(trace_class
,
766 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
);
770 struct bt_field_class
*bt_field_class_real_double_precision_create(
771 bt_trace_class
*trace_class
)
773 BT_ASSERT_PRE_NO_ERROR();
775 return create_real_field_class(trace_class
,
776 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
);
780 int init_named_field_classes_container(
781 struct bt_field_class_named_field_class_container
*fc
,
782 enum bt_field_class_type type
,
783 bt_object_release_func fc_release_func
,
784 GDestroyNotify named_fc_destroy_func
)
788 ret
= init_field_class((void *) fc
, type
, fc_release_func
);
793 fc
->named_fcs
= g_ptr_array_new_with_free_func(named_fc_destroy_func
);
794 if (!fc
->named_fcs
) {
795 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
800 fc
->name_to_index
= g_hash_table_new(g_str_hash
, g_str_equal
);
801 if (!fc
->name_to_index
) {
802 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
812 void finalize_named_field_class(struct bt_named_field_class
*named_fc
)
815 BT_LIB_LOGD("Finalizing named field class: "
816 "addr=%p, name=\"%s\", %![fc-]+F",
817 named_fc
, named_fc
->name
? named_fc
->name
->str
: NULL
,
819 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
821 if (named_fc
->name
) {
822 g_string_free(named_fc
->name
, TRUE
);
823 named_fc
->name
= NULL
;
826 BT_LOGD_STR("Putting named field class's field class.");
827 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->fc
);
831 void destroy_named_field_class(gpointer ptr
)
833 struct bt_named_field_class
*named_fc
= ptr
;
836 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
837 finalize_named_field_class(ptr
);
843 void destroy_variant_with_selector_field_option(gpointer ptr
)
845 struct bt_field_class_variant_with_selector_field_option
*opt
= ptr
;
848 finalize_named_field_class(&opt
->common
);
849 BT_OBJECT_PUT_REF_AND_RESET(opt
->range_set
);
855 void finalize_named_field_classes_container(
856 struct bt_field_class_named_field_class_container
*fc
)
861 g_ptr_array_free(fc
->named_fcs
, TRUE
);
862 fc
->named_fcs
= NULL
;
866 if (fc
->name_to_index
) {
867 g_hash_table_destroy(fc
->name_to_index
);
868 fc
->name_to_index
= NULL
;
873 void destroy_structure_field_class(struct bt_object
*obj
)
876 BT_LIB_LOGD("Destroying structure field class object: %!+F", obj
);
877 finalize_field_class((void *) obj
);
878 finalize_named_field_classes_container((void *) obj
);
883 struct bt_field_class
*bt_field_class_structure_create(
884 bt_trace_class
*trace_class
)
887 struct bt_field_class_structure
*struct_fc
= NULL
;
889 BT_ASSERT_PRE_NO_ERROR();
890 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
891 BT_LOGD_STR("Creating default structure field class object.");
892 struct_fc
= g_new0(struct bt_field_class_structure
, 1);
894 BT_LIB_LOGE_APPEND_CAUSE(
895 "Failed to allocate one structure field class.");
899 ret
= init_named_field_classes_container((void *) struct_fc
,
900 BT_FIELD_CLASS_TYPE_STRUCTURE
, destroy_structure_field_class
,
901 destroy_named_field_class
);
903 /* init_named_field_classes_container() logs errors */
907 BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc
);
911 BT_OBJECT_PUT_REF_AND_RESET(struct_fc
);
914 return (void *) struct_fc
;
918 int init_named_field_class(struct bt_named_field_class
*named_fc
,
919 const char *name
, struct bt_field_class
*fc
)
921 int status
= BT_FUNC_STATUS_OK
;
926 named_fc
->name
= g_string_new(name
);
927 if (!named_fc
->name
) {
928 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
929 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
933 named_fc
->user_attributes
= bt_value_map_create();
934 if (!named_fc
->user_attributes
) {
935 BT_LIB_LOGE_APPEND_CAUSE(
936 "Failed to create a map value object.");
937 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
942 bt_object_get_ref_no_null_check(named_fc
->fc
);
949 struct bt_named_field_class
*create_named_field_class(const char *name
,
950 struct bt_field_class
*fc
)
952 struct bt_named_field_class
*named_fc
= g_new0(
953 struct bt_named_field_class
, 1);
956 BT_LIB_LOGE_APPEND_CAUSE(
957 "Failed to allocate a named field class.");
961 if (init_named_field_class(named_fc
, name
, fc
)) {
962 /* init_named_field_class() logs errors */
969 destroy_named_field_class(named_fc
);
977 struct bt_field_class_variant_with_selector_field_option
*
978 create_variant_with_selector_field_option(
979 const char *name
, struct bt_field_class
*fc
,
980 const struct bt_integer_range_set
*range_set
)
982 struct bt_field_class_variant_with_selector_field_option
*opt
= g_new0(
983 struct bt_field_class_variant_with_selector_field_option
, 1);
985 BT_ASSERT(range_set
);
988 BT_LIB_LOGE_APPEND_CAUSE(
989 "Failed to allocate a named field class.");
993 if (init_named_field_class(&opt
->common
, name
, fc
)) {
997 opt
->range_set
= range_set
;
998 bt_object_get_ref_no_null_check(opt
->range_set
);
999 bt_integer_range_set_freeze(range_set
);
1003 destroy_variant_with_selector_field_option(opt
);
1011 int append_named_field_class_to_container_field_class(
1012 struct bt_field_class_named_field_class_container
*container_fc
,
1013 struct bt_named_field_class
*named_fc
, const char *api_func
,
1014 const char *unique_entry_precond_id
)
1016 BT_ASSERT(container_fc
);
1017 BT_ASSERT(named_fc
);
1018 BT_ASSERT_PRE_DEV_FC_HOT_FROM_FUNC(api_func
, container_fc
);
1019 BT_ASSERT_PRE_FROM_FUNC(api_func
, unique_entry_precond_id
,
1020 !bt_g_hash_table_contains(container_fc
->name_to_index
,
1021 named_fc
->name
->str
),
1022 "Duplicate member/option name in structure/variant field class: "
1023 "%![container-fc-]+F, name=\"%s\"", container_fc
,
1024 named_fc
->name
->str
);
1027 * Freeze the contained field class, but not the named field
1028 * class itself, as it's still possible afterwards to modify
1029 * properties of the member/option object.
1031 bt_field_class_freeze(named_fc
->fc
);
1032 g_ptr_array_add(container_fc
->named_fcs
, named_fc
);
1033 g_hash_table_insert(container_fc
->name_to_index
, named_fc
->name
->str
,
1034 GUINT_TO_POINTER(container_fc
->named_fcs
->len
- 1));
1035 return BT_FUNC_STATUS_OK
;
1039 enum bt_field_class_structure_append_member_status
1040 bt_field_class_structure_append_member(
1041 struct bt_field_class
*fc
, const char *name
,
1042 struct bt_field_class
*member_fc
)
1044 enum bt_field_class_structure_append_member_status status
;
1045 struct bt_named_field_class
*named_fc
= NULL
;
1047 BT_ASSERT_PRE_NO_ERROR();
1048 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1049 BT_ASSERT_PRE_FC_IS_STRUCT("field-class", fc
, "Field class");
1050 named_fc
= create_named_field_class(name
, member_fc
);
1052 /* create_named_field_class() logs errors */
1053 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1057 status
= append_named_field_class_to_container_field_class((void *) fc
,
1059 "structure-field-class-member-name-is-unique");
1060 if (status
== BT_FUNC_STATUS_OK
) {
1061 /* Moved to the container */
1070 uint64_t bt_field_class_structure_get_member_count(
1071 const struct bt_field_class
*fc
)
1073 struct bt_field_class_structure
*struct_fc
= (void *) fc
;
1075 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1076 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1077 return (uint64_t) struct_fc
->common
.named_fcs
->len
;
1081 struct bt_named_field_class
*
1082 borrow_named_field_class_from_container_field_class_at_index(
1083 struct bt_field_class_named_field_class_container
*fc
,
1084 uint64_t index
, const char *api_func
)
1087 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1088 fc
->named_fcs
->len
);
1089 return fc
->named_fcs
->pdata
[index
];
1093 const struct bt_field_class_structure_member
*
1094 bt_field_class_structure_borrow_member_by_index_const(
1095 const struct bt_field_class
*fc
, uint64_t index
)
1097 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1098 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1099 return (const void *)
1100 borrow_named_field_class_from_container_field_class_at_index(
1101 (void *) fc
, index
, __func__
);
1105 struct bt_field_class_structure_member
*
1106 bt_field_class_structure_borrow_member_by_index(
1107 struct bt_field_class
*fc
, uint64_t index
)
1109 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1110 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1112 borrow_named_field_class_from_container_field_class_at_index(
1113 (void *) fc
, index
, __func__
);
1117 struct bt_named_field_class
*
1118 borrow_named_field_class_from_container_field_class_by_name(
1119 struct bt_field_class_named_field_class_container
*fc
,
1120 const char *name
, const char *api_func
)
1122 struct bt_named_field_class
*named_fc
= NULL
;
1127 BT_ASSERT_PRE_DEV_NAME_NON_NULL_FROM_FUNC(api_func
, name
);
1128 if (!g_hash_table_lookup_extended(fc
->name_to_index
, name
, &orig_key
,
1133 named_fc
= fc
->named_fcs
->pdata
[GPOINTER_TO_UINT(value
)];
1140 const struct bt_field_class_structure_member
*
1141 bt_field_class_structure_borrow_member_by_name_const(
1142 const struct bt_field_class
*fc
, const char *name
)
1144 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1145 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1146 return (const void *)
1147 borrow_named_field_class_from_container_field_class_by_name(
1148 (void *) fc
, name
, __func__
);
1152 struct bt_field_class_structure_member
*
1153 bt_field_class_structure_borrow_member_by_name(
1154 struct bt_field_class
*fc
, const char *name
)
1156 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1157 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1159 borrow_named_field_class_from_container_field_class_by_name(
1160 (void *) fc
, name
, __func__
);
1164 const char *bt_field_class_structure_member_get_name(
1165 const struct bt_field_class_structure_member
*member
)
1167 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1169 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1170 return named_fc
->name
->str
;
1174 const struct bt_field_class
*
1175 bt_field_class_structure_member_borrow_field_class_const(
1176 const struct bt_field_class_structure_member
*member
)
1178 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1180 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1181 return named_fc
->fc
;
1185 struct bt_field_class
*
1186 bt_field_class_structure_member_borrow_field_class(
1187 struct bt_field_class_structure_member
*member
)
1189 struct bt_named_field_class
*named_fc
= (void *) member
;
1191 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1192 return named_fc
->fc
;
1196 void destroy_option_field_class(struct bt_object
*obj
)
1198 struct bt_field_class_option
*fc
= (void *) obj
;
1201 BT_LIB_LOGD("Destroying option field class object: %!+F", fc
);
1202 finalize_field_class((void *) obj
);
1203 BT_LOGD_STR("Putting content field class.");
1204 BT_OBJECT_PUT_REF_AND_RESET(fc
->content_fc
);
1206 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1207 struct bt_field_class_option_with_selector_field
*with_sel_fc
=
1210 BT_LOGD_STR("Putting selector field path.");
1211 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field_path
);
1212 BT_LOGD_STR("Putting selector field class.");
1213 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_fc
);
1215 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1216 struct bt_field_class_option_with_selector_field_integer
*with_int_sel_fc
=
1219 BT_LOGD_STR("Putting integer range set.");
1220 BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc
->range_set
);
1228 struct bt_field_class
*create_option_field_class(
1229 struct bt_trace_class
*trace_class
,
1230 enum bt_field_class_type fc_type
,
1231 struct bt_field_class
*content_fc
,
1232 struct bt_field_class
*selector_fc
,
1233 const char *api_func
)
1235 struct bt_field_class_option
*opt_fc
= NULL
;
1237 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
1238 BT_ASSERT_PRE_TC_NON_NULL_FROM_FUNC(api_func
, trace_class
);
1239 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "content-field-class",
1240 content_fc
, "Content field class");
1241 BT_LIB_LOGD("Creating option field class: "
1242 "type=%s, %![content-fc-]+F, %![sel-fc-]+F",
1243 bt_common_field_class_type_string(fc_type
),
1244 content_fc
, selector_fc
);
1246 if (fc_type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1247 struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
= NULL
;
1249 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
,
1250 "selector-field-class", selector_fc
,
1251 "Selector field class");
1253 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1254 BT_ASSERT_PRE_FC_HAS_TYPE_FROM_FUNC(api_func
,
1255 "selector-field-class", selector_fc
,
1256 "boolean-field-class", BT_FIELD_CLASS_TYPE_BOOL
,
1257 "Selector field class");
1258 opt_with_sel_fc
= (void *) g_new0(
1259 struct bt_field_class_option_with_selector_field_bool
, 1);
1261 BT_ASSERT_PRE_FC_IS_INT_FROM_FUNC(api_func
,
1262 "selector-field-class",
1263 selector_fc
, "Selector field class");
1264 opt_with_sel_fc
= (void *) g_new0(
1265 struct bt_field_class_option_with_selector_field_integer
, 1);
1268 if (!opt_with_sel_fc
) {
1269 BT_LIB_LOGE_APPEND_CAUSE(
1270 "Failed to allocate one option with selector field class.");
1274 opt_with_sel_fc
->selector_fc
= selector_fc
;
1275 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_fc
);
1276 opt_fc
= (void *) opt_with_sel_fc
;
1278 opt_fc
= g_new0(struct bt_field_class_option
, 1);
1280 BT_LIB_LOGE_APPEND_CAUSE(
1281 "Failed to allocate one option field class.");
1288 if (init_field_class((void *) opt_fc
, fc_type
,
1289 destroy_option_field_class
)) {
1293 opt_fc
->content_fc
= content_fc
;
1294 bt_object_get_ref_no_null_check(opt_fc
->content_fc
);
1295 bt_field_class_freeze(opt_fc
->content_fc
);
1298 bt_field_class_freeze(selector_fc
);
1301 BT_LIB_LOGD("Created option field class object: "
1302 "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc
, selector_fc
);
1306 BT_OBJECT_PUT_REF_AND_RESET(opt_fc
);
1309 return (void *) opt_fc
;
1313 struct bt_field_class
*bt_field_class_option_without_selector_create(
1314 struct bt_trace_class
*trace_class
,
1315 struct bt_field_class
*content_fc
)
1317 return create_option_field_class(trace_class
,
1318 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1319 content_fc
, NULL
, __func__
);
1323 struct bt_field_class
*bt_field_class_option_with_selector_field_bool_create(
1324 struct bt_trace_class
*trace_class
,
1325 struct bt_field_class
*content_fc
,
1326 struct bt_field_class
*selector_fc
)
1328 BT_ASSERT_PRE_NO_ERROR();
1330 return create_option_field_class(trace_class
,
1331 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1332 content_fc
, selector_fc
, __func__
);
1336 struct bt_field_class
*
1337 bt_field_class_option_with_selector_field_integer_unsigned_create(
1338 struct bt_trace_class
*trace_class
,
1339 struct bt_field_class
*content_fc
,
1340 struct bt_field_class
*selector_fc
,
1341 const struct bt_integer_range_set_unsigned
*u_range_set
)
1343 struct bt_field_class_option_with_selector_field_integer
*fc
;
1344 const struct bt_integer_range_set
*range_set
=
1345 (const void *) u_range_set
;
1347 BT_ASSERT_PRE_NO_ERROR();
1348 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1349 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1350 fc
= (void *) create_option_field_class(trace_class
,
1351 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1352 content_fc
, selector_fc
, __func__
);
1358 fc
->range_set
= range_set
;
1359 bt_object_get_ref_no_null_check(fc
->range_set
);
1360 bt_integer_range_set_freeze(range_set
);
1367 struct bt_field_class
*
1368 bt_field_class_option_with_selector_field_integer_signed_create(
1369 struct bt_trace_class
*trace_class
,
1370 struct bt_field_class
*content_fc
,
1371 struct bt_field_class
*selector_fc
,
1372 const struct bt_integer_range_set_signed
*i_range_set
)
1374 struct bt_field_class_option_with_selector_field_integer
*fc
;
1375 const struct bt_integer_range_set
*range_set
=
1376 (const void *) i_range_set
;
1378 BT_ASSERT_PRE_NO_ERROR();
1379 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1380 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1381 fc
= (void *) create_option_field_class(trace_class
,
1382 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1383 content_fc
, selector_fc
, __func__
);
1389 fc
->range_set
= range_set
;
1390 bt_object_get_ref_no_null_check(fc
->range_set
);
1391 bt_integer_range_set_freeze(range_set
);
1398 const struct bt_field_class
*bt_field_class_option_borrow_field_class_const(
1399 const struct bt_field_class
*fc
)
1401 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1403 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1404 BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc
, "Field class");
1405 return opt_fc
->content_fc
;
1409 struct bt_field_class
*bt_field_class_option_borrow_field_class(
1410 struct bt_field_class
*fc
)
1412 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1414 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1415 BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc
, "Field class");
1416 return opt_fc
->content_fc
;
1420 const struct bt_field_path
*
1421 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1422 const struct bt_field_class
*fc
)
1424 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1427 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1428 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL("field-class", fc
, "Field class");
1429 return opt_fc
->selector_field_path
;
1433 void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
1434 struct bt_field_class
*fc
, bt_bool sel_is_reversed
)
1436 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1438 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1439 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1440 "option-field-class-with-boolean-selector-field",
1441 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1443 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
1444 opt_fc
->sel_is_reversed
= sel_is_reversed
;
1448 bt_bool
bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1449 const struct bt_field_class
*fc
)
1451 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1453 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1454 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1455 "option-field-class-with-boolean-selector-field",
1456 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1458 return opt_fc
->sel_is_reversed
;
1462 const struct bt_integer_range_set_unsigned
*
1463 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1464 const struct bt_field_class
*fc
)
1466 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1469 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1470 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc
,
1472 return (const void *) opt_fc
->range_set
;
1476 const struct bt_integer_range_set_signed
*
1477 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1478 const struct bt_field_class
*fc
)
1480 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1483 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1484 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc
,
1486 return (const void *) opt_fc
->range_set
;
1490 void finalize_variant_field_class(struct bt_field_class_variant
*var_fc
)
1493 BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc
);
1494 finalize_field_class((void *) var_fc
);
1495 finalize_named_field_classes_container((void *) var_fc
);
1499 void destroy_variant_field_class(struct bt_object
*obj
)
1501 struct bt_field_class_variant
*fc
= (void *) obj
;
1504 finalize_variant_field_class(fc
);
1509 void destroy_variant_with_selector_field_field_class(struct bt_object
*obj
)
1511 struct bt_field_class_variant_with_selector_field
*fc
= (void *) obj
;
1514 finalize_variant_field_class(&fc
->common
);
1515 BT_LOGD_STR("Putting selector field path.");
1516 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field_path
);
1517 BT_LOGD_STR("Putting selector field class.");
1518 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_fc
);
1523 struct bt_field_class
*bt_field_class_variant_create(
1524 bt_trace_class
*trace_class
, bt_field_class
*selector_fc
)
1527 struct bt_field_class_variant
*var_fc
= NULL
;
1528 struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
= NULL
;
1529 enum bt_field_class_type fc_type
;
1531 BT_ASSERT_PRE_NO_ERROR();
1532 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1535 BT_ASSERT_PRE_FC_IS_INT("selector-field-class", selector_fc
,
1536 "Selector field class");
1539 BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F",
1543 var_with_sel_fc
= g_new0(
1544 struct bt_field_class_variant_with_selector_field
, 1);
1545 if (!var_with_sel_fc
) {
1546 BT_LIB_LOGE_APPEND_CAUSE(
1547 "Failed to allocate one variant field class with selector.");
1551 if (bt_field_class_type_is(selector_fc
->type
,
1552 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
)) {
1553 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
;
1555 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
;
1558 ret
= init_named_field_classes_container(
1559 (void *) var_with_sel_fc
, fc_type
,
1560 destroy_variant_with_selector_field_field_class
,
1561 destroy_variant_with_selector_field_option
);
1563 /* init_named_field_classes_container() logs errors */
1567 var_with_sel_fc
->selector_fc
= selector_fc
;
1568 bt_object_get_ref_no_null_check(var_with_sel_fc
->selector_fc
);
1569 bt_field_class_freeze(selector_fc
);
1570 var_fc
= (void *) var_with_sel_fc
;
1571 BT_LIB_LOGD("Created default variant field class with selector object: "
1572 "%![var-fc-]+F, %![sel-fc-]+F", var_fc
, selector_fc
);
1574 var_fc
= g_new0(struct bt_field_class_variant
, 1);
1576 BT_LIB_LOGE_APPEND_CAUSE(
1577 "Failed to allocate one variant field class without selector.");
1581 ret
= init_named_field_classes_container((void *) var_fc
,
1582 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1583 destroy_variant_field_class
, destroy_named_field_class
);
1585 /* init_named_field_classes_container() logs errors */
1588 BT_LIB_LOGD("Created default variant field class without selector object: "
1589 "%![var-fc-]+F", var_fc
);
1596 BT_OBJECT_PUT_REF_AND_RESET(var_fc
);
1597 BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc
);
1600 return (void *) var_fc
;
1603 #define VAR_FC_OPT_NAME_IS_UNIQUE_ID \
1604 "variant-field-class-option-name-is-unique"
1607 enum bt_field_class_variant_without_selector_append_option_status
1608 bt_field_class_variant_without_selector_append_option(struct bt_field_class
*fc
,
1609 const char *name
, struct bt_field_class
*option_fc
)
1611 enum bt_field_class_variant_without_selector_append_option_status status
;
1612 struct bt_named_field_class
*named_fc
= NULL
;
1614 BT_ASSERT_PRE_NO_ERROR();
1615 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1616 BT_ASSERT_PRE_NAME_NON_NULL(name
);
1617 BT_ASSERT_PRE_NON_NULL("option-field-class", option_fc
,
1618 "Option field class");
1619 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1620 "variant-field-class-without-selector-field",
1621 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1623 named_fc
= create_named_field_class(name
, option_fc
);
1625 /* create_named_field_class() logs errors */
1626 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1630 status
= append_named_field_class_to_container_field_class((void *) fc
,
1631 named_fc
, __func__
, VAR_FC_OPT_NAME_IS_UNIQUE_ID
);
1632 if (status
== BT_FUNC_STATUS_OK
) {
1633 /* Moved to the container */
1639 destroy_named_field_class(named_fc
);
1646 int ranges_overlap(GPtrArray
*var_fc_opts
, const struct bt_integer_range_set
*range_set
,
1647 bool is_signed
, bool *has_overlap
)
1649 int status
= BT_FUNC_STATUS_OK
;
1650 struct bt_integer_range_set
*full_range_set
;
1653 *has_overlap
= false;
1656 * Build a single range set with all the ranges and test for
1660 full_range_set
= (void *) bt_integer_range_set_signed_create();
1662 full_range_set
= (void *) bt_integer_range_set_unsigned_create();
1665 if (!full_range_set
) {
1666 BT_LOGE_STR("Failed to create a range set.");
1667 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1671 /* Add existing option ranges */
1672 for (i
= 0; i
< var_fc_opts
->len
; i
++) {
1673 struct bt_field_class_variant_with_selector_field_option
*opt
=
1674 var_fc_opts
->pdata
[i
];
1677 for (j
= 0; j
< opt
->range_set
->ranges
->len
; j
++) {
1678 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1682 status
= bt_integer_range_set_signed_add_range(
1683 (void *) full_range_set
, range
->lower
.i
,
1686 status
= bt_integer_range_set_unsigned_add_range(
1687 (void *) full_range_set
, range
->lower
.u
,
1697 /* Add new ranges */
1698 for (i
= 0; i
< range_set
->ranges
->len
; i
++) {
1699 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1703 status
= bt_integer_range_set_signed_add_range(
1704 (void *) full_range_set
, range
->lower
.i
,
1707 status
= bt_integer_range_set_unsigned_add_range(
1708 (void *) full_range_set
, range
->lower
.u
,
1717 /* Check overlaps */
1719 *has_overlap
= bt_integer_range_set_signed_has_overlaps(full_range_set
);
1721 *has_overlap
= bt_integer_range_set_unsigned_has_overlaps(
1726 bt_object_put_ref(full_range_set
);
1731 int append_option_to_variant_with_selector_field_field_class(
1732 struct bt_field_class
*fc
, const char *name
,
1733 struct bt_field_class
*option_fc
,
1734 const struct bt_integer_range_set
*range_set
,
1735 enum bt_field_class_type expected_type
,
1736 const char *api_func
)
1739 struct bt_field_class_variant_with_selector_field
*var_fc
= (void *) fc
;
1740 struct bt_field_class_variant_with_selector_field_option
*opt
= NULL
;
1744 BT_ASSERT_PRE_NAME_NON_NULL_FROM_FUNC(api_func
, name
);
1745 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "option-field-class",
1746 option_fc
, "Option field class");
1747 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL_FROM_FUNC(api_func
, range_set
);
1748 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY_FROM_FUNC(api_func
, range_set
);
1749 status
= ranges_overlap(var_fc
->common
.common
.named_fcs
, range_set
,
1750 expected_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1753 /* ranges_overlap() logs errors */
1757 BT_ASSERT_PRE_FROM_FUNC(api_func
, "ranges-do-not-overlap",
1759 "Integer range set's ranges and existing ranges have an overlap: "
1761 opt
= create_variant_with_selector_field_option(name
, option_fc
, range_set
);
1763 /* create_variant_with_selector_field_option() logs errors */
1764 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1768 status
= append_named_field_class_to_container_field_class((void *) fc
,
1769 &opt
->common
, __func__
, VAR_FC_OPT_NAME_IS_UNIQUE_ID
);
1770 if (status
== BT_FUNC_STATUS_OK
) {
1771 /* Moved to the container */
1777 destroy_variant_with_selector_field_option(opt
);
1784 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1785 bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
1786 struct bt_field_class
*fc
, const char *name
,
1787 struct bt_field_class
*option_fc
,
1788 const struct bt_integer_range_set_unsigned
*range_set
)
1790 BT_ASSERT_PRE_NO_ERROR();
1791 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1792 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1793 "variant-field-class-with-unsigned-integer-selector-field",
1794 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1796 return append_option_to_variant_with_selector_field_field_class(fc
,
1797 name
, option_fc
, (const void *) range_set
,
1798 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1803 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1804 bt_field_class_variant_with_selector_field_integer_signed_append_option(
1805 struct bt_field_class
*fc
, const char *name
,
1806 struct bt_field_class
*option_fc
,
1807 const struct bt_integer_range_set_signed
*range_set
)
1809 BT_ASSERT_PRE_NO_ERROR();
1810 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1811 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1812 "variant-field-class-with-signed-integer-selector-field",
1813 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1815 return append_option_to_variant_with_selector_field_field_class(fc
,
1816 name
, option_fc
, (const void *) range_set
,
1817 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1822 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class
*fc
)
1824 const struct bt_field_class_variant
*var_fc
= (const void *) fc
;
1826 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1827 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1828 return (uint64_t) var_fc
->common
.named_fcs
->len
;
1832 const struct bt_field_class_variant_option
*
1833 bt_field_class_variant_borrow_option_by_name_const(
1834 const struct bt_field_class
*fc
, const char *name
)
1836 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1837 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1838 return (const void *)
1839 borrow_named_field_class_from_container_field_class_by_name(
1840 (void *) fc
, name
, __func__
);
1844 const struct bt_field_class_variant_option
*
1845 bt_field_class_variant_borrow_option_by_index_const(
1846 const struct bt_field_class
*fc
, uint64_t index
)
1848 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1849 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1850 return (const void *)
1851 borrow_named_field_class_from_container_field_class_at_index(
1852 (void *) fc
, index
, __func__
);
1856 struct bt_field_class_variant_option
*
1857 bt_field_class_variant_borrow_option_by_name(
1858 struct bt_field_class
*fc
, const char *name
)
1860 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1861 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1863 borrow_named_field_class_from_container_field_class_by_name(
1864 (void *) fc
, name
, __func__
);
1868 struct bt_field_class_variant_option
*
1869 bt_field_class_variant_borrow_option_by_index(
1870 struct bt_field_class
*fc
, uint64_t index
)
1872 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1873 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1875 borrow_named_field_class_from_container_field_class_at_index(
1876 (void *) fc
, index
, __func__
);
1880 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1881 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
1882 const struct bt_field_class
*fc
, const char *name
)
1884 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1885 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1886 "variant-field-class-with-unsigned-integer-selector-field",
1887 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1889 return (const void *)
1890 borrow_named_field_class_from_container_field_class_by_name(
1891 (void *) fc
, name
, __func__
);
1895 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1896 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
1897 const struct bt_field_class
*fc
, uint64_t index
)
1899 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1900 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1901 "variant-field-class-with-unsigned-integer-selector-field",
1902 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1904 return (const void *)
1905 borrow_named_field_class_from_container_field_class_at_index(
1906 (void *) fc
, index
, __func__
);
1910 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1911 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
1912 const struct bt_field_class
*fc
, const char *name
)
1914 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1915 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1916 "variant-field-class-with-signed-integer-selector-field",
1917 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1919 return (const void *)
1920 borrow_named_field_class_from_container_field_class_by_name(
1921 (void *) fc
, name
, __func__
);
1925 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1926 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
1927 const struct bt_field_class
*fc
, uint64_t index
)
1929 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1930 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1931 "variant-field-class-with-signed-integer-selector-field",
1932 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1934 return (const void *)
1935 borrow_named_field_class_from_container_field_class_at_index(
1936 (void *) fc
, index
, __func__
);
1940 const char *bt_field_class_variant_option_get_name(
1941 const struct bt_field_class_variant_option
*option
)
1943 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1945 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1946 return named_fc
->name
->str
;
1950 const struct bt_field_class
*
1951 bt_field_class_variant_option_borrow_field_class_const(
1952 const struct bt_field_class_variant_option
*option
)
1954 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1956 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1957 return named_fc
->fc
;
1961 struct bt_field_class
*
1962 bt_field_class_variant_option_borrow_field_class(
1963 struct bt_field_class_variant_option
*option
)
1965 struct bt_named_field_class
*named_fc
= (void *) option
;
1967 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1968 return named_fc
->fc
;
1972 const struct bt_integer_range_set_unsigned
*
1973 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
1974 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*option
)
1976 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1977 (const void *) option
;
1979 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1980 return (const void *) opt
->range_set
;
1984 const struct bt_integer_range_set_signed
*
1985 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
1986 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*option
)
1988 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1989 (const void *) option
;
1991 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1992 return (const void *) opt
->range_set
;
1996 const struct bt_field_path
*
1997 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
1998 const struct bt_field_class
*fc
)
2000 const struct bt_field_class_variant_with_selector_field
*var_fc
=
2003 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2004 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL("field-class", fc
,
2006 return var_fc
->selector_field_path
;
2010 int init_array_field_class(struct bt_field_class_array
*fc
,
2011 enum bt_field_class_type type
, bt_object_release_func release_func
,
2012 struct bt_field_class
*element_fc
)
2016 BT_ASSERT(element_fc
);
2017 ret
= init_field_class((void *) fc
, type
, release_func
);
2022 fc
->element_fc
= element_fc
;
2023 bt_object_get_ref_no_null_check(fc
->element_fc
);
2024 bt_field_class_freeze(element_fc
);
2031 void finalize_array_field_class(struct bt_field_class_array
*array_fc
)
2033 BT_ASSERT(array_fc
);
2034 BT_LOGD_STR("Putting element field class.");
2035 finalize_field_class((void *) array_fc
);
2036 BT_OBJECT_PUT_REF_AND_RESET(array_fc
->element_fc
);
2040 void destroy_static_array_field_class(struct bt_object
*obj
)
2043 BT_LIB_LOGD("Destroying static array field class object: %!+F", obj
);
2044 finalize_array_field_class((void *) obj
);
2049 struct bt_field_class
*
2050 bt_field_class_array_static_create(bt_trace_class
*trace_class
,
2051 struct bt_field_class
*element_fc
, uint64_t length
)
2053 struct bt_field_class_array_static
*array_fc
= NULL
;
2055 BT_ASSERT_PRE_NO_ERROR();
2056 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2057 BT_ASSERT_PRE_NON_NULL("element-field-class", element_fc
,
2058 "Element field class");
2059 BT_LOGD_STR("Creating default static array field class object.");
2060 array_fc
= g_new0(struct bt_field_class_array_static
, 1);
2062 BT_LIB_LOGE_APPEND_CAUSE(
2063 "Failed to allocate one static array field class.");
2067 if (init_array_field_class((void *) array_fc
,
2068 BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2069 destroy_static_array_field_class
, element_fc
)) {
2073 array_fc
->length
= length
;
2074 BT_LIB_LOGD("Created static array field class object: %!+F", array_fc
);
2078 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2081 return (void *) array_fc
;
2085 const struct bt_field_class
*
2086 bt_field_class_array_borrow_element_field_class_const(
2087 const struct bt_field_class
*fc
)
2089 const struct bt_field_class_array
*array_fc
= (const void *) fc
;
2091 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2092 BT_ASSERT_PRE_DEV_FC_IS_ARRAY("field-class", fc
, "Field class");
2093 return array_fc
->element_fc
;
2097 struct bt_field_class
*
2098 bt_field_class_array_borrow_element_field_class(struct bt_field_class
*fc
)
2100 struct bt_field_class_array
*array_fc
= (void *) fc
;
2102 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2103 BT_ASSERT_PRE_DEV_FC_IS_ARRAY("field-class", fc
, "Field class");
2104 return array_fc
->element_fc
;
2108 uint64_t bt_field_class_array_static_get_length(const struct bt_field_class
*fc
)
2110 const struct bt_field_class_array_static
*array_fc
= (const void *) fc
;
2112 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2113 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2114 "static-array-field-class", BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2116 return (uint64_t) array_fc
->length
;
2120 void destroy_dynamic_array_field_class(struct bt_object
*obj
)
2122 struct bt_field_class_array_dynamic
*fc
= (void *) obj
;
2125 BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc
);
2126 finalize_array_field_class((void *) fc
);
2127 BT_LOGD_STR("Putting length field path.");
2128 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field_path
);
2129 BT_LOGD_STR("Putting length field class.");
2130 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_fc
);
2135 struct bt_field_class
*bt_field_class_array_dynamic_create(
2136 struct bt_trace_class
*trace_class
,
2137 struct bt_field_class
*element_fc
,
2138 struct bt_field_class
*length_fc
)
2140 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2142 BT_ASSERT_PRE_NO_ERROR();
2143 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2144 BT_ASSERT_PRE_NON_NULL("element-field-class", element_fc
,
2145 "Element field class");
2146 BT_LOGD_STR("Creating default dynamic array field class object.");
2147 array_fc
= g_new0(struct bt_field_class_array_dynamic
, 1);
2149 BT_LIB_LOGE_APPEND_CAUSE(
2150 "Failed to allocate one dynamic array field class.");
2154 if (init_array_field_class((void *) array_fc
,
2156 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
2157 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2158 destroy_dynamic_array_field_class
, element_fc
)) {
2163 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT("length-field-class",
2164 length_fc
, "Length field class");
2165 array_fc
->length_fc
= length_fc
;
2166 bt_object_get_ref_no_null_check(array_fc
->length_fc
);
2167 bt_field_class_freeze(length_fc
);
2170 BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc
);
2174 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2177 return (void *) array_fc
;
2181 const struct bt_field_path
*
2182 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
2183 const struct bt_field_class
*fc
)
2185 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2187 BT_ASSERT_PRE_NO_ERROR();
2188 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2189 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2190 "dynamic-array-field-class-with-length-field",
2191 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2193 return seq_fc
->length_field_path
;
2197 void destroy_string_field_class(struct bt_object
*obj
)
2200 BT_LIB_LOGD("Destroying string field class object: %!+F", obj
);
2201 finalize_field_class((void *) obj
);
2206 struct bt_field_class
*bt_field_class_string_create(bt_trace_class
*trace_class
)
2208 struct bt_field_class_string
*string_fc
= NULL
;
2210 BT_ASSERT_PRE_NO_ERROR();
2211 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2212 BT_LOGD_STR("Creating default string field class object.");
2213 string_fc
= g_new0(struct bt_field_class_string
, 1);
2215 BT_LIB_LOGE_APPEND_CAUSE(
2216 "Failed to allocate one string field class.");
2220 if (init_field_class((void *) string_fc
, BT_FIELD_CLASS_TYPE_STRING
,
2221 destroy_string_field_class
)) {
2225 BT_LIB_LOGD("Created string field class object: %!+F", string_fc
);
2229 BT_OBJECT_PUT_REF_AND_RESET(string_fc
);
2232 return (void *) string_fc
;
2235 void _bt_field_class_freeze(const struct bt_field_class
*c_fc
)
2237 struct bt_field_class
*fc
= (void *) c_fc
;
2240 * Element/member/option field classes are frozen when added to
2244 bt_value_freeze(fc
->user_attributes
);
2247 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2248 bt_field_class_type_is(fc
->type
,
2249 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2250 struct bt_field_class_named_field_class_container
*container_fc
=
2254 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2255 bt_named_field_class_freeze(
2256 container_fc
->named_fcs
->pdata
[i
]);
2261 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
)
2263 BT_ASSERT(named_fc
);
2264 BT_ASSERT(named_fc
->fc
->frozen
);
2265 BT_LIB_LOGD("Freezing named field class's user attributes: %!+v",
2266 named_fc
->user_attributes
);
2267 bt_value_freeze(named_fc
->user_attributes
);
2268 ((struct bt_named_field_class
*) named_fc
)->frozen
= true;
2271 void bt_field_class_make_part_of_trace_class(const struct bt_field_class
*c_fc
)
2273 struct bt_field_class
*fc
= (void *) c_fc
;
2276 BT_ASSERT_PRE("field-class-is-not-part-of-trace-class",
2277 !fc
->part_of_trace_class
,
2278 "Field class is already part of a trace class: %!+F", fc
);
2279 fc
->part_of_trace_class
= true;
2281 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2282 bt_field_class_type_is(fc
->type
,
2283 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2284 struct bt_field_class_named_field_class_container
*container_fc
=
2288 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2289 struct bt_named_field_class
*named_fc
=
2290 container_fc
->named_fcs
->pdata
[i
];
2292 bt_field_class_make_part_of_trace_class(named_fc
->fc
);
2294 } else if (bt_field_class_type_is(fc
->type
,
2295 BT_FIELD_CLASS_TYPE_ARRAY
)) {
2296 struct bt_field_class_array
*array_fc
= (void *) fc
;
2298 bt_field_class_make_part_of_trace_class(array_fc
->element_fc
);
2303 const struct bt_value
*bt_field_class_borrow_user_attributes_const(
2304 const struct bt_field_class
*fc
)
2306 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2307 return fc
->user_attributes
;
2311 struct bt_value
*bt_field_class_borrow_user_attributes(
2312 struct bt_field_class
*field_class
)
2314 return (void *) bt_field_class_borrow_user_attributes_const(
2315 (void *) field_class
);
2320 void bt_field_class_set_user_attributes(
2321 struct bt_field_class
*fc
,
2322 const struct bt_value
*user_attributes
)
2324 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2325 BT_ASSERT_PRE_USER_ATTRS_NON_NULL(user_attributes
);
2326 BT_ASSERT_PRE_USER_ATTRS_IS_MAP(user_attributes
);
2327 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
2328 bt_object_put_ref_no_null_check(fc
->user_attributes
);
2329 fc
->user_attributes
= (void *) user_attributes
;
2330 bt_object_get_ref_no_null_check(fc
->user_attributes
);
2334 const struct bt_value
*bt_named_field_class_borrow_user_attributes_const(
2335 const struct bt_named_field_class
*named_fc
)
2337 return named_fc
->user_attributes
;
2341 void set_named_field_class_user_attributes(
2342 struct bt_named_field_class
*named_fc
,
2343 const struct bt_value
*user_attributes
, const char *api_func
)
2345 BT_ASSERT_PRE_USER_ATTRS_NON_NULL_FROM_FUNC(api_func
, user_attributes
);
2346 BT_ASSERT_PRE_USER_ATTRS_NON_NULL_FROM_FUNC(api_func
, user_attributes
);
2347 bt_object_put_ref_no_null_check(named_fc
->user_attributes
);
2348 named_fc
->user_attributes
= (void *) user_attributes
;
2349 bt_object_get_ref_no_null_check(named_fc
->user_attributes
);
2353 const struct bt_value
*
2354 bt_field_class_structure_member_borrow_user_attributes_const(
2355 const struct bt_field_class_structure_member
*member
)
2357 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
2358 return bt_named_field_class_borrow_user_attributes_const(
2359 (const void *) member
);
2364 bt_field_class_structure_member_borrow_user_attributes(
2365 struct bt_field_class_structure_member
*member
)
2367 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
2368 return (void *) bt_named_field_class_borrow_user_attributes_const(
2373 void bt_field_class_structure_member_set_user_attributes(
2374 struct bt_field_class_structure_member
*member
,
2375 const struct bt_value
*user_attributes
)
2377 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
2378 BT_ASSERT_PRE_DEV_HOT("structure-field-class-member",
2379 (struct bt_named_field_class
*) member
,
2380 "Structure field class member", ".");
2381 set_named_field_class_user_attributes((void *) member
,
2382 user_attributes
, __func__
);
2386 const struct bt_value
*bt_field_class_variant_option_borrow_user_attributes_const(
2387 const struct bt_field_class_variant_option
*option
)
2389 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
2390 return bt_named_field_class_borrow_user_attributes_const(
2391 (const void *) option
);
2395 struct bt_value
*bt_field_class_variant_option_borrow_user_attributes(
2396 struct bt_field_class_variant_option
*option
)
2398 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
2399 return (void *) bt_named_field_class_borrow_user_attributes_const(
2404 void bt_field_class_variant_option_set_user_attributes(
2405 struct bt_field_class_variant_option
*option
,
2406 const struct bt_value
*user_attributes
)
2408 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
2409 BT_ASSERT_PRE_DEV_HOT("variant-field-class-option",
2410 (struct bt_named_field_class
*) option
,
2411 "Variant field class option", ".");
2412 set_named_field_class_user_attributes((void *) option
,
2413 user_attributes
, __func__
);
2417 void bt_field_class_get_ref(const struct bt_field_class
*field_class
)
2419 bt_object_get_ref(field_class
);
2423 void bt_field_class_put_ref(const struct bt_field_class
*field_class
)
2425 bt_object_put_ref(field_class
);