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 "compat/glib.h"
25 #include "clock-class.h"
26 #include "field-class.h"
28 #include "field-path.h"
30 #include "lib/func-status.h"
31 #include "lib/integer-range-set.h"
32 #include "lib/value.h"
35 enum bt_field_class_type
bt_field_class_get_type(
36 const struct bt_field_class
*fc
)
38 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
43 int init_field_class(struct bt_field_class
*fc
, enum bt_field_class_type type
,
44 bt_object_release_func release_func
)
49 BT_ASSERT(release_func
);
50 bt_object_init_shared(&fc
->base
, release_func
);
52 fc
->user_attributes
= bt_value_map_create();
53 if (!fc
->user_attributes
) {
54 BT_LIB_LOGE_APPEND_CAUSE(
55 "Failed to create a map value object.");
65 void finalize_field_class(struct bt_field_class
*fc
)
67 BT_OBJECT_PUT_REF_AND_RESET(fc
->user_attributes
);
71 void destroy_bit_array_field_class(struct bt_object
*obj
)
74 BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj
);
75 finalize_field_class((void *) obj
);
80 struct bt_field_class
*bt_field_class_bit_array_create(
81 struct bt_trace_class
*trace_class
, uint64_t length
)
83 struct bt_field_class_bit_array
*ba_fc
= NULL
;
85 BT_ASSERT_PRE_NO_ERROR();
86 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
87 BT_ASSERT_PRE("valid-length", length
> 0 && length
<= 64,
88 "Unsupported length for bit array field class "
89 "(minimum is 1, maximum is 64): length=%" PRIu64
, length
);
90 BT_LOGD("Creating default bit array field class object.");
91 ba_fc
= g_new0(struct bt_field_class_bit_array
, 1);
93 BT_LIB_LOGE_APPEND_CAUSE(
94 "Failed to allocate one bit array field class.");
98 if (init_field_class((void *) ba_fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
99 destroy_bit_array_field_class
)) {
103 ba_fc
->length
= length
;
104 BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc
);
108 BT_OBJECT_PUT_REF_AND_RESET(ba_fc
);
111 return (void *) ba_fc
;
115 uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class
*fc
)
117 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
119 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
120 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
121 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
122 return ba_fc
->length
;
126 void destroy_bool_field_class(struct bt_object
*obj
)
129 BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj
);
130 finalize_field_class((void *) obj
);
135 struct bt_field_class
*bt_field_class_bool_create(
136 bt_trace_class
*trace_class
)
138 struct bt_field_class_bool
*bool_fc
= NULL
;
140 BT_ASSERT_PRE_NO_ERROR();
141 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
142 BT_LOGD("Creating default boolean field class object.");
143 bool_fc
= g_new0(struct bt_field_class_bool
, 1);
145 BT_LIB_LOGE_APPEND_CAUSE(
146 "Failed to allocate one boolean field class.");
150 if (init_field_class((void *) bool_fc
, BT_FIELD_CLASS_TYPE_BOOL
,
151 destroy_bool_field_class
)) {
155 BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc
);
159 BT_OBJECT_PUT_REF_AND_RESET(bool_fc
);
162 return (void *) bool_fc
;
166 int init_integer_field_class(struct bt_field_class_integer
*fc
,
167 enum bt_field_class_type type
,
168 bt_object_release_func release_func
)
172 ret
= init_field_class((void *) fc
, type
, release_func
);
178 fc
->base
= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
;
185 void destroy_integer_field_class(struct bt_object
*obj
)
188 BT_LIB_LOGD("Destroying integer field class object: %!+F", obj
);
189 finalize_field_class((void *) obj
);
194 struct bt_field_class
*create_integer_field_class(bt_trace_class
*trace_class
,
195 enum bt_field_class_type type
)
197 struct bt_field_class_integer
*int_fc
= NULL
;
199 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
200 BT_LOGD("Creating default integer field class object: type=%s",
201 bt_common_field_class_type_string(type
));
202 int_fc
= g_new0(struct bt_field_class_integer
, 1);
204 BT_LIB_LOGE_APPEND_CAUSE(
205 "Failed to allocate one integer field class.");
209 if (init_integer_field_class(int_fc
, type
,
210 destroy_integer_field_class
)) {
214 BT_LIB_LOGD("Created integer field class object: %!+F", int_fc
);
218 BT_OBJECT_PUT_REF_AND_RESET(int_fc
);
221 return (void *) int_fc
;
225 struct bt_field_class
*bt_field_class_integer_unsigned_create(
226 bt_trace_class
*trace_class
)
228 BT_ASSERT_PRE_NO_ERROR();
230 return create_integer_field_class(trace_class
,
231 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
235 struct bt_field_class
*bt_field_class_integer_signed_create(
236 bt_trace_class
*trace_class
)
238 BT_ASSERT_PRE_NO_ERROR();
240 return create_integer_field_class(trace_class
,
241 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
245 uint64_t bt_field_class_integer_get_field_value_range(
246 const struct bt_field_class
*fc
)
248 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
250 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
251 BT_ASSERT_PRE_DEV_FC_IS_INT("field-class", fc
, "Field class");
252 return int_fc
->range
;
256 bool size_is_valid_for_enumeration_field_class(
257 struct bt_field_class
*fc
__attribute__((unused
)),
258 uint64_t size
__attribute__((unused
)))
265 void bt_field_class_integer_set_field_value_range(
266 struct bt_field_class
*fc
, uint64_t size
)
268 struct bt_field_class_integer
*int_fc
= (void *) fc
;
270 BT_ASSERT_PRE_FC_NON_NULL(fc
);
271 BT_ASSERT_PRE_FC_IS_INT("field-class", fc
, "Field class");
272 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
273 BT_ASSERT_PRE("valid-n",
274 size
>= 1 && size
<= 64,
275 "Unsupported size for integer field class's field value range "
276 "(minimum is 1, maximum is 64): size=%" PRIu64
, size
);
277 BT_ASSERT_PRE("valid-n-for-enumeration-field-class",
278 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
279 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
280 size_is_valid_for_enumeration_field_class(fc
, size
),
281 "Invalid field value range for enumeration field class: "
282 "at least one of the current mapping ranges contains values "
283 "which are outside this range: %!+F, size=%" PRIu64
, fc
, size
);
284 int_fc
->range
= size
;
285 BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc
);
289 enum bt_field_class_integer_preferred_display_base
290 bt_field_class_integer_get_preferred_display_base(const struct bt_field_class
*fc
)
292 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
294 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
295 BT_ASSERT_PRE_DEV_FC_IS_INT("field-class", 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_FC_NON_NULL(fc
);
307 BT_ASSERT_PRE_FC_IS_INT("field-class", fc
, "Field class");
308 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
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_TC_NON_NULL(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
;
401 struct bt_field_class
*bt_field_class_enumeration_unsigned_create(
402 bt_trace_class
*trace_class
)
404 BT_ASSERT_PRE_NO_ERROR();
406 return create_enumeration_field_class(trace_class
,
407 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
411 struct bt_field_class
*bt_field_class_enumeration_signed_create(
412 bt_trace_class
*trace_class
)
414 BT_ASSERT_PRE_NO_ERROR();
416 return create_enumeration_field_class(trace_class
,
417 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
421 uint64_t bt_field_class_enumeration_get_mapping_count(
422 const struct bt_field_class
*fc
)
424 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
426 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
427 BT_ASSERT_PRE_DEV_FC_IS_ENUM("field-class", fc
, "Field class");
428 return (uint64_t) enum_fc
->mappings
->len
;
432 const struct bt_field_class_enumeration_unsigned_mapping
*
433 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
434 const struct bt_field_class
*fc
, uint64_t index
)
436 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
438 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
439 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
440 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
441 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
442 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
446 const struct bt_field_class_enumeration_signed_mapping
*
447 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
448 const struct bt_field_class
*fc
, uint64_t index
)
450 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
452 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
453 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
454 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
455 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
456 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
460 const struct bt_field_class_enumeration_mapping
*
461 borrow_enumeration_field_class_mapping_by_label(
462 const struct bt_field_class_enumeration
*fc
, const char *label
,
463 const char *api_func
)
465 struct bt_field_class_enumeration_mapping
*mapping
= NULL
;
469 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "label", label
,
472 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
473 struct bt_field_class_enumeration_mapping
*this_mapping
=
474 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
);
476 if (strcmp(this_mapping
->label
->str
, label
) == 0) {
477 mapping
= this_mapping
;
487 const struct bt_field_class_enumeration_signed_mapping
*
488 bt_field_class_enumeration_signed_borrow_mapping_by_label_const(
489 const struct bt_field_class
*fc
, const char *label
)
491 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
492 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
493 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
494 return (const void *) borrow_enumeration_field_class_mapping_by_label(
495 (const void *) fc
, label
, __func__
);
499 const struct bt_field_class_enumeration_unsigned_mapping
*
500 bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(
501 const struct bt_field_class
*fc
, const char *label
)
503 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
504 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
505 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
506 return (const void *) borrow_enumeration_field_class_mapping_by_label(
507 (const void *) fc
, label
, __func__
);
511 const char *bt_field_class_enumeration_mapping_get_label(
512 const struct bt_field_class_enumeration_mapping
*mapping
)
514 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
515 mapping
, "Enumeration field class mapping");
516 return mapping
->label
->str
;
520 const struct bt_integer_range_set_unsigned
*
521 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
522 const struct bt_field_class_enumeration_unsigned_mapping
*u_mapping
)
524 const struct bt_field_class_enumeration_mapping
*mapping
=
525 (const void *) u_mapping
;
527 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
528 mapping
, "Enumeration field class mapping");
529 return (const void *) mapping
->range_set
;
533 const struct bt_integer_range_set_signed
*
534 bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
535 const struct bt_field_class_enumeration_signed_mapping
*s_mapping
)
537 const struct bt_field_class_enumeration_mapping
*mapping
=
538 (const void *) s_mapping
;
540 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
541 mapping
, "Enumeration field class mapping");
542 return (const void *) mapping
->range_set
;
546 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
547 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
548 const struct bt_field_class
*fc
, uint64_t value
,
549 bt_field_class_enumeration_mapping_label_array
*label_array
,
552 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
555 BT_ASSERT_PRE_DEV_NO_ERROR();
556 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
557 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
558 "Label array (output)");
559 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
560 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
561 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
562 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
564 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
566 const struct bt_field_class_enumeration_mapping
*mapping
=
567 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
569 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
570 const struct bt_integer_range
*range
= (const void *)
571 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
572 mapping
->range_set
, j
);
574 if (value
>= range
->lower
.u
&&
575 value
<= range
->upper
.u
) {
576 g_ptr_array_add(enum_fc
->label_buf
,
577 mapping
->label
->str
);
583 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
584 *count
= (uint64_t) enum_fc
->label_buf
->len
;
585 return BT_FUNC_STATUS_OK
;
589 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
590 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
591 const struct bt_field_class
*fc
, int64_t value
,
592 bt_field_class_enumeration_mapping_label_array
*label_array
,
595 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
598 BT_ASSERT_PRE_DEV_NO_ERROR();
599 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
600 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
601 "Label array (output)");
602 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
603 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
604 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
605 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
607 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
609 const struct bt_field_class_enumeration_mapping
*mapping
=
610 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
612 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
613 const struct bt_integer_range
*range
= (const void *)
614 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
615 mapping
->range_set
, j
);
617 if (value
>= range
->lower
.i
&&
618 value
<= range
->upper
.i
) {
619 g_ptr_array_add(enum_fc
->label_buf
,
620 mapping
->label
->str
);
626 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
627 *count
= (uint64_t) enum_fc
->label_buf
->len
;
628 return BT_FUNC_STATUS_OK
;
632 bool enumeration_field_class_has_mapping_with_label(
633 const struct bt_field_class_enumeration
*enum_fc
,
642 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
643 struct bt_field_class_enumeration_mapping
*mapping_candidate
=
644 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
646 if (strcmp(mapping_candidate
->label
->str
, label
) == 0) {
657 enum bt_field_class_enumeration_add_mapping_status
658 add_mapping_to_enumeration_field_class(struct bt_field_class
*fc
,
659 const char *label
, const struct bt_integer_range_set
*range_set
,
660 const char *api_func
)
662 enum bt_field_class_enumeration_add_mapping_status status
=
664 struct bt_field_class_enumeration
*enum_fc
= (void *) fc
;
665 struct bt_field_class_enumeration_mapping mapping
= { 0 };
667 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
669 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "label", label
, "Label");
670 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL_FROM_FUNC(api_func
, range_set
);
671 BT_ASSERT_PRE_FROM_FUNC(api_func
,
672 "enumeration-field-class-mapping-label-is-unique",
673 !enumeration_field_class_has_mapping_with_label(
675 "Duplicate mapping name in enumeration field class: "
676 "%![enum-fc-]+F, label=\"%s\"", fc
, label
);
677 mapping
.range_set
= range_set
;
678 bt_object_get_ref(mapping
.range_set
);
679 mapping
.label
= g_string_new(label
);
680 if (!mapping
.label
) {
681 finalize_enumeration_field_class_mapping(&mapping
);
682 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
686 g_array_append_val(enum_fc
->mappings
, mapping
);
687 BT_LIB_LOGD("Added mapping to enumeration field class: "
688 "%![fc-]+F, label=\"%s\"", fc
, label
);
695 enum bt_field_class_enumeration_add_mapping_status
696 bt_field_class_enumeration_unsigned_add_mapping(
697 struct bt_field_class
*fc
, const char *label
,
698 const struct bt_integer_range_set_unsigned
*range_set
)
700 BT_ASSERT_PRE_NO_ERROR();
701 BT_ASSERT_PRE_FC_NON_NULL(fc
);
702 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
703 "unsigned-enumeration-field-class",
704 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
705 return add_mapping_to_enumeration_field_class(fc
, label
,
706 (const void *) range_set
, __func__
);
710 enum bt_field_class_enumeration_add_mapping_status
711 bt_field_class_enumeration_signed_add_mapping(
712 struct bt_field_class
*fc
, const char *label
,
713 const struct bt_integer_range_set_signed
*range_set
)
715 BT_ASSERT_PRE_NO_ERROR();
716 BT_ASSERT_PRE_FC_NON_NULL(fc
);
717 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
718 "signed-enumeration-field-class",
719 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
720 return add_mapping_to_enumeration_field_class(fc
, label
,
721 (const void *) range_set
, __func__
);
725 void destroy_real_field_class(struct bt_object
*obj
)
728 BT_LIB_LOGD("Destroying real field class object: %!+F", obj
);
729 finalize_field_class((void *) obj
);
734 struct bt_field_class
*create_real_field_class(bt_trace_class
*trace_class
,
735 enum bt_field_class_type type
)
737 struct bt_field_class_real
*real_fc
= NULL
;
739 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
740 BT_LOGD("Creating default real field class object: type=%s",
741 bt_common_field_class_type_string(type
));
742 real_fc
= g_new0(struct bt_field_class_real
, 1);
744 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
748 if (init_field_class((void *) real_fc
, type
, destroy_real_field_class
)) {
752 BT_LIB_LOGD("Created real field class object: %!+F", real_fc
);
756 BT_OBJECT_PUT_REF_AND_RESET(real_fc
);
759 return (void *) real_fc
;
763 struct bt_field_class
*bt_field_class_real_single_precision_create(
764 bt_trace_class
*trace_class
)
766 BT_ASSERT_PRE_NO_ERROR();
768 return create_real_field_class(trace_class
,
769 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
);
773 struct bt_field_class
*bt_field_class_real_double_precision_create(
774 bt_trace_class
*trace_class
)
776 BT_ASSERT_PRE_NO_ERROR();
778 return create_real_field_class(trace_class
,
779 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
);
783 int init_named_field_classes_container(
784 struct bt_field_class_named_field_class_container
*fc
,
785 enum bt_field_class_type type
,
786 bt_object_release_func fc_release_func
,
787 GDestroyNotify named_fc_destroy_func
)
791 ret
= init_field_class((void *) fc
, type
, fc_release_func
);
796 fc
->named_fcs
= g_ptr_array_new_with_free_func(named_fc_destroy_func
);
797 if (!fc
->named_fcs
) {
798 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
803 fc
->name_to_index
= g_hash_table_new(g_str_hash
, g_str_equal
);
804 if (!fc
->name_to_index
) {
805 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
815 void finalize_named_field_class(struct bt_named_field_class
*named_fc
)
818 BT_LIB_LOGD("Finalizing named field class: "
819 "addr=%p, name=\"%s\", %![fc-]+F",
820 named_fc
, named_fc
->name
? named_fc
->name
->str
: NULL
,
822 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
824 if (named_fc
->name
) {
825 g_string_free(named_fc
->name
, TRUE
);
826 named_fc
->name
= NULL
;
829 BT_LOGD_STR("Putting named field class's field class.");
830 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->fc
);
834 void destroy_named_field_class(gpointer ptr
)
836 struct bt_named_field_class
*named_fc
= ptr
;
839 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
840 finalize_named_field_class(ptr
);
846 void destroy_variant_with_selector_field_option(gpointer ptr
)
848 struct bt_field_class_variant_with_selector_field_option
*opt
= ptr
;
851 finalize_named_field_class(&opt
->common
);
852 BT_OBJECT_PUT_REF_AND_RESET(opt
->range_set
);
858 void finalize_named_field_classes_container(
859 struct bt_field_class_named_field_class_container
*fc
)
864 g_ptr_array_free(fc
->named_fcs
, TRUE
);
865 fc
->named_fcs
= NULL
;
869 if (fc
->name_to_index
) {
870 g_hash_table_destroy(fc
->name_to_index
);
871 fc
->name_to_index
= NULL
;
876 void destroy_structure_field_class(struct bt_object
*obj
)
879 BT_LIB_LOGD("Destroying structure field class object: %!+F", obj
);
880 finalize_field_class((void *) obj
);
881 finalize_named_field_classes_container((void *) obj
);
886 struct bt_field_class
*bt_field_class_structure_create(
887 bt_trace_class
*trace_class
)
890 struct bt_field_class_structure
*struct_fc
= NULL
;
892 BT_ASSERT_PRE_NO_ERROR();
893 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
894 BT_LOGD_STR("Creating default structure field class object.");
895 struct_fc
= g_new0(struct bt_field_class_structure
, 1);
897 BT_LIB_LOGE_APPEND_CAUSE(
898 "Failed to allocate one structure field class.");
902 ret
= init_named_field_classes_container((void *) struct_fc
,
903 BT_FIELD_CLASS_TYPE_STRUCTURE
, destroy_structure_field_class
,
904 destroy_named_field_class
);
906 /* init_named_field_classes_container() logs errors */
910 BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc
);
914 BT_OBJECT_PUT_REF_AND_RESET(struct_fc
);
917 return (void *) struct_fc
;
921 int init_named_field_class(struct bt_named_field_class
*named_fc
,
922 const char *name
, struct bt_field_class
*fc
)
924 int status
= BT_FUNC_STATUS_OK
;
929 named_fc
->name
= g_string_new(name
);
930 if (!named_fc
->name
) {
931 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
932 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
936 named_fc
->user_attributes
= bt_value_map_create();
937 if (!named_fc
->user_attributes
) {
938 BT_LIB_LOGE_APPEND_CAUSE(
939 "Failed to create a map value object.");
940 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
945 bt_object_get_ref_no_null_check(named_fc
->fc
);
952 struct bt_named_field_class
*create_named_field_class(const char *name
,
953 struct bt_field_class
*fc
)
955 struct bt_named_field_class
*named_fc
= g_new0(
956 struct bt_named_field_class
, 1);
959 BT_LIB_LOGE_APPEND_CAUSE(
960 "Failed to allocate a named field class.");
964 if (init_named_field_class(named_fc
, name
, fc
)) {
965 /* init_named_field_class() logs errors */
972 destroy_named_field_class(named_fc
);
980 struct bt_field_class_variant_with_selector_field_option
*
981 create_variant_with_selector_field_option(
982 const char *name
, struct bt_field_class
*fc
,
983 const struct bt_integer_range_set
*range_set
)
985 struct bt_field_class_variant_with_selector_field_option
*opt
= g_new0(
986 struct bt_field_class_variant_with_selector_field_option
, 1);
988 BT_ASSERT(range_set
);
991 BT_LIB_LOGE_APPEND_CAUSE(
992 "Failed to allocate a named field class.");
996 if (init_named_field_class(&opt
->common
, name
, fc
)) {
1000 opt
->range_set
= range_set
;
1001 bt_object_get_ref_no_null_check(opt
->range_set
);
1002 bt_integer_range_set_freeze(range_set
);
1006 destroy_variant_with_selector_field_option(opt
);
1014 int append_named_field_class_to_container_field_class(
1015 struct bt_field_class_named_field_class_container
*container_fc
,
1016 struct bt_named_field_class
*named_fc
, const char *api_func
,
1017 const char *unique_entry_precond_id
)
1019 BT_ASSERT(container_fc
);
1020 BT_ASSERT(named_fc
);
1021 BT_ASSERT_PRE_DEV_FC_HOT_FROM_FUNC(api_func
, container_fc
);
1022 BT_ASSERT_PRE_FROM_FUNC(api_func
, unique_entry_precond_id
,
1023 !bt_g_hash_table_contains(container_fc
->name_to_index
,
1024 named_fc
->name
->str
),
1025 "Duplicate member/option name in structure/variant field class: "
1026 "%![container-fc-]+F, name=\"%s\"", container_fc
,
1027 named_fc
->name
->str
);
1030 * Freeze the contained field class, but not the named field
1031 * class itself, as it's still possible afterwards to modify
1032 * properties of the member/option object.
1034 bt_field_class_freeze(named_fc
->fc
);
1035 g_ptr_array_add(container_fc
->named_fcs
, named_fc
);
1036 g_hash_table_insert(container_fc
->name_to_index
, named_fc
->name
->str
,
1037 GUINT_TO_POINTER(container_fc
->named_fcs
->len
- 1));
1038 return BT_FUNC_STATUS_OK
;
1042 enum bt_field_class_structure_append_member_status
1043 bt_field_class_structure_append_member(
1044 struct bt_field_class
*fc
, const char *name
,
1045 struct bt_field_class
*member_fc
)
1047 enum bt_field_class_structure_append_member_status status
;
1048 struct bt_named_field_class
*named_fc
= NULL
;
1050 BT_ASSERT_PRE_NO_ERROR();
1051 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1052 BT_ASSERT_PRE_FC_IS_STRUCT("field-class", fc
, "Field class");
1053 named_fc
= create_named_field_class(name
, member_fc
);
1055 /* create_named_field_class() logs errors */
1056 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1060 status
= append_named_field_class_to_container_field_class((void *) fc
,
1062 "structure-field-class-member-name-is-unique");
1063 if (status
== BT_FUNC_STATUS_OK
) {
1064 /* Moved to the container */
1073 uint64_t bt_field_class_structure_get_member_count(
1074 const struct bt_field_class
*fc
)
1076 struct bt_field_class_structure
*struct_fc
= (void *) fc
;
1078 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1079 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1080 return (uint64_t) struct_fc
->common
.named_fcs
->len
;
1084 struct bt_named_field_class
*
1085 borrow_named_field_class_from_container_field_class_at_index(
1086 struct bt_field_class_named_field_class_container
*fc
,
1087 uint64_t index
, const char *api_func
)
1090 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1091 fc
->named_fcs
->len
);
1092 return fc
->named_fcs
->pdata
[index
];
1096 const struct bt_field_class_structure_member
*
1097 bt_field_class_structure_borrow_member_by_index_const(
1098 const struct bt_field_class
*fc
, uint64_t index
)
1100 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1101 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1102 return (const void *)
1103 borrow_named_field_class_from_container_field_class_at_index(
1104 (void *) fc
, index
, __func__
);
1108 struct bt_field_class_structure_member
*
1109 bt_field_class_structure_borrow_member_by_index(
1110 struct bt_field_class
*fc
, uint64_t index
)
1112 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1113 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1115 borrow_named_field_class_from_container_field_class_at_index(
1116 (void *) fc
, index
, __func__
);
1120 struct bt_named_field_class
*
1121 borrow_named_field_class_from_container_field_class_by_name(
1122 struct bt_field_class_named_field_class_container
*fc
,
1123 const char *name
, const char *api_func
)
1125 struct bt_named_field_class
*named_fc
= NULL
;
1130 BT_ASSERT_PRE_DEV_NAME_NON_NULL_FROM_FUNC(api_func
, name
);
1131 if (!g_hash_table_lookup_extended(fc
->name_to_index
, name
, &orig_key
,
1136 named_fc
= fc
->named_fcs
->pdata
[GPOINTER_TO_UINT(value
)];
1143 const struct bt_field_class_structure_member
*
1144 bt_field_class_structure_borrow_member_by_name_const(
1145 const struct bt_field_class
*fc
, const char *name
)
1147 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1148 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1149 return (const void *)
1150 borrow_named_field_class_from_container_field_class_by_name(
1151 (void *) fc
, name
, __func__
);
1155 struct bt_field_class_structure_member
*
1156 bt_field_class_structure_borrow_member_by_name(
1157 struct bt_field_class
*fc
, const char *name
)
1159 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1160 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1162 borrow_named_field_class_from_container_field_class_by_name(
1163 (void *) fc
, name
, __func__
);
1167 const char *bt_field_class_structure_member_get_name(
1168 const struct bt_field_class_structure_member
*member
)
1170 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1172 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1173 return named_fc
->name
->str
;
1177 const struct bt_field_class
*
1178 bt_field_class_structure_member_borrow_field_class_const(
1179 const struct bt_field_class_structure_member
*member
)
1181 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1183 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1184 return named_fc
->fc
;
1188 struct bt_field_class
*
1189 bt_field_class_structure_member_borrow_field_class(
1190 struct bt_field_class_structure_member
*member
)
1192 struct bt_named_field_class
*named_fc
= (void *) member
;
1194 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1195 return named_fc
->fc
;
1199 void destroy_option_field_class(struct bt_object
*obj
)
1201 struct bt_field_class_option
*fc
= (void *) obj
;
1204 BT_LIB_LOGD("Destroying option field class object: %!+F", fc
);
1205 finalize_field_class((void *) obj
);
1206 BT_LOGD_STR("Putting content field class.");
1207 BT_OBJECT_PUT_REF_AND_RESET(fc
->content_fc
);
1209 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1210 struct bt_field_class_option_with_selector_field
*with_sel_fc
=
1213 BT_LOGD_STR("Putting selector field path.");
1214 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field_path
);
1215 BT_LOGD_STR("Putting selector field class.");
1216 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_fc
);
1218 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1219 struct bt_field_class_option_with_selector_field_integer
*with_int_sel_fc
=
1222 BT_LOGD_STR("Putting integer range set.");
1223 BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc
->range_set
);
1231 struct bt_field_class
*create_option_field_class(
1232 struct bt_trace_class
*trace_class
,
1233 enum bt_field_class_type fc_type
,
1234 struct bt_field_class
*content_fc
,
1235 struct bt_field_class
*selector_fc
,
1236 const char *api_func
)
1238 struct bt_field_class_option
*opt_fc
= NULL
;
1240 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
1241 BT_ASSERT_PRE_TC_NON_NULL_FROM_FUNC(api_func
, trace_class
);
1242 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "content-field-class",
1243 content_fc
, "Content field class");
1244 BT_LIB_LOGD("Creating option field class: "
1245 "type=%s, %![content-fc-]+F, %![sel-fc-]+F",
1246 bt_common_field_class_type_string(fc_type
),
1247 content_fc
, selector_fc
);
1249 if (fc_type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1250 struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
= NULL
;
1252 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
,
1253 "selector-field-class", selector_fc
,
1254 "Selector field class");
1256 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1257 BT_ASSERT_PRE_FC_HAS_TYPE_FROM_FUNC(api_func
,
1258 "selector-field-class", selector_fc
,
1259 "boolean-field-class", BT_FIELD_CLASS_TYPE_BOOL
,
1260 "Selector field class");
1261 opt_with_sel_fc
= (void *) g_new0(
1262 struct bt_field_class_option_with_selector_field_bool
, 1);
1264 BT_ASSERT_PRE_FC_IS_INT_FROM_FUNC(api_func
,
1265 "selector-field-class",
1266 selector_fc
, "Selector field class");
1267 opt_with_sel_fc
= (void *) g_new0(
1268 struct bt_field_class_option_with_selector_field_integer
, 1);
1271 if (!opt_with_sel_fc
) {
1272 BT_LIB_LOGE_APPEND_CAUSE(
1273 "Failed to allocate one option with selector field class.");
1277 opt_with_sel_fc
->selector_fc
= selector_fc
;
1278 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_fc
);
1279 opt_fc
= (void *) opt_with_sel_fc
;
1281 opt_fc
= g_new0(struct bt_field_class_option
, 1);
1283 BT_LIB_LOGE_APPEND_CAUSE(
1284 "Failed to allocate one option field class.");
1291 if (init_field_class((void *) opt_fc
, fc_type
,
1292 destroy_option_field_class
)) {
1296 opt_fc
->content_fc
= content_fc
;
1297 bt_object_get_ref_no_null_check(opt_fc
->content_fc
);
1298 bt_field_class_freeze(opt_fc
->content_fc
);
1301 bt_field_class_freeze(selector_fc
);
1304 BT_LIB_LOGD("Created option field class object: "
1305 "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc
, selector_fc
);
1309 BT_OBJECT_PUT_REF_AND_RESET(opt_fc
);
1312 return (void *) opt_fc
;
1316 struct bt_field_class
*bt_field_class_option_without_selector_create(
1317 struct bt_trace_class
*trace_class
,
1318 struct bt_field_class
*content_fc
)
1320 return create_option_field_class(trace_class
,
1321 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1322 content_fc
, NULL
, __func__
);
1326 struct bt_field_class
*bt_field_class_option_with_selector_field_bool_create(
1327 struct bt_trace_class
*trace_class
,
1328 struct bt_field_class
*content_fc
,
1329 struct bt_field_class
*selector_fc
)
1331 BT_ASSERT_PRE_NO_ERROR();
1333 return create_option_field_class(trace_class
,
1334 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1335 content_fc
, selector_fc
, __func__
);
1339 struct bt_field_class
*
1340 bt_field_class_option_with_selector_field_integer_unsigned_create(
1341 struct bt_trace_class
*trace_class
,
1342 struct bt_field_class
*content_fc
,
1343 struct bt_field_class
*selector_fc
,
1344 const struct bt_integer_range_set_unsigned
*u_range_set
)
1346 struct bt_field_class_option_with_selector_field_integer
*fc
;
1347 const struct bt_integer_range_set
*range_set
=
1348 (const void *) u_range_set
;
1350 BT_ASSERT_PRE_NO_ERROR();
1351 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1352 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1353 fc
= (void *) create_option_field_class(trace_class
,
1354 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1355 content_fc
, selector_fc
, __func__
);
1361 fc
->range_set
= range_set
;
1362 bt_object_get_ref_no_null_check(fc
->range_set
);
1363 bt_integer_range_set_freeze(range_set
);
1370 struct bt_field_class
*
1371 bt_field_class_option_with_selector_field_integer_signed_create(
1372 struct bt_trace_class
*trace_class
,
1373 struct bt_field_class
*content_fc
,
1374 struct bt_field_class
*selector_fc
,
1375 const struct bt_integer_range_set_signed
*i_range_set
)
1377 struct bt_field_class_option_with_selector_field_integer
*fc
;
1378 const struct bt_integer_range_set
*range_set
=
1379 (const void *) i_range_set
;
1381 BT_ASSERT_PRE_NO_ERROR();
1382 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1383 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1384 fc
= (void *) create_option_field_class(trace_class
,
1385 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1386 content_fc
, selector_fc
, __func__
);
1392 fc
->range_set
= range_set
;
1393 bt_object_get_ref_no_null_check(fc
->range_set
);
1394 bt_integer_range_set_freeze(range_set
);
1401 const struct bt_field_class
*bt_field_class_option_borrow_field_class_const(
1402 const struct bt_field_class
*fc
)
1404 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1406 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1407 BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc
, "Field class");
1408 return opt_fc
->content_fc
;
1412 struct bt_field_class
*bt_field_class_option_borrow_field_class(
1413 struct bt_field_class
*fc
)
1415 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1417 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1418 BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc
, "Field class");
1419 return opt_fc
->content_fc
;
1423 const struct bt_field_path
*
1424 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1425 const struct bt_field_class
*fc
)
1427 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1430 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1431 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL("field-class", fc
, "Field class");
1432 return opt_fc
->selector_field_path
;
1436 void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
1437 struct bt_field_class
*fc
, bt_bool sel_is_reversed
)
1439 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1441 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1442 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1443 "option-field-class-with-boolean-selector-field",
1444 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1446 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
1447 opt_fc
->sel_is_reversed
= sel_is_reversed
;
1451 bt_bool
bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1452 const struct bt_field_class
*fc
)
1454 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1456 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1457 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1458 "option-field-class-with-boolean-selector-field",
1459 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1461 return opt_fc
->sel_is_reversed
;
1465 const struct bt_integer_range_set_unsigned
*
1466 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1467 const struct bt_field_class
*fc
)
1469 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1472 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1473 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc
,
1475 return (const void *) opt_fc
->range_set
;
1479 const struct bt_integer_range_set_signed
*
1480 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1481 const struct bt_field_class
*fc
)
1483 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1486 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1487 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc
,
1489 return (const void *) opt_fc
->range_set
;
1493 void finalize_variant_field_class(struct bt_field_class_variant
*var_fc
)
1496 BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc
);
1497 finalize_field_class((void *) var_fc
);
1498 finalize_named_field_classes_container((void *) var_fc
);
1502 void destroy_variant_field_class(struct bt_object
*obj
)
1504 struct bt_field_class_variant
*fc
= (void *) obj
;
1507 finalize_variant_field_class(fc
);
1512 void destroy_variant_with_selector_field_field_class(struct bt_object
*obj
)
1514 struct bt_field_class_variant_with_selector_field
*fc
= (void *) obj
;
1517 finalize_variant_field_class(&fc
->common
);
1518 BT_LOGD_STR("Putting selector field path.");
1519 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field_path
);
1520 BT_LOGD_STR("Putting selector field class.");
1521 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_fc
);
1526 struct bt_field_class
*bt_field_class_variant_create(
1527 bt_trace_class
*trace_class
, bt_field_class
*selector_fc
)
1530 struct bt_field_class_variant
*var_fc
= NULL
;
1531 struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
= NULL
;
1532 enum bt_field_class_type fc_type
;
1534 BT_ASSERT_PRE_NO_ERROR();
1535 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1538 BT_ASSERT_PRE_FC_IS_INT("selector-field-class", selector_fc
,
1539 "Selector field class");
1542 BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F",
1546 var_with_sel_fc
= g_new0(
1547 struct bt_field_class_variant_with_selector_field
, 1);
1548 if (!var_with_sel_fc
) {
1549 BT_LIB_LOGE_APPEND_CAUSE(
1550 "Failed to allocate one variant field class with selector.");
1554 if (bt_field_class_type_is(selector_fc
->type
,
1555 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
)) {
1556 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
;
1558 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
;
1561 ret
= init_named_field_classes_container(
1562 (void *) var_with_sel_fc
, fc_type
,
1563 destroy_variant_with_selector_field_field_class
,
1564 destroy_variant_with_selector_field_option
);
1566 /* init_named_field_classes_container() logs errors */
1570 var_with_sel_fc
->selector_fc
= selector_fc
;
1571 bt_object_get_ref_no_null_check(var_with_sel_fc
->selector_fc
);
1572 bt_field_class_freeze(selector_fc
);
1573 var_fc
= (void *) var_with_sel_fc
;
1574 BT_LIB_LOGD("Created default variant field class with selector object: "
1575 "%![var-fc-]+F, %![sel-fc-]+F", var_fc
, selector_fc
);
1577 var_fc
= g_new0(struct bt_field_class_variant
, 1);
1579 BT_LIB_LOGE_APPEND_CAUSE(
1580 "Failed to allocate one variant field class without selector.");
1584 ret
= init_named_field_classes_container((void *) var_fc
,
1585 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1586 destroy_variant_field_class
, destroy_named_field_class
);
1588 /* init_named_field_classes_container() logs errors */
1591 BT_LIB_LOGD("Created default variant field class without selector object: "
1592 "%![var-fc-]+F", var_fc
);
1599 BT_OBJECT_PUT_REF_AND_RESET(var_fc
);
1600 BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc
);
1603 return (void *) var_fc
;
1606 #define VAR_FC_OPT_NAME_IS_UNIQUE_ID \
1607 "variant-field-class-option-name-is-unique"
1610 enum bt_field_class_variant_without_selector_append_option_status
1611 bt_field_class_variant_without_selector_append_option(struct bt_field_class
*fc
,
1612 const char *name
, struct bt_field_class
*option_fc
)
1614 enum bt_field_class_variant_without_selector_append_option_status status
;
1615 struct bt_named_field_class
*named_fc
= NULL
;
1617 BT_ASSERT_PRE_NO_ERROR();
1618 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1619 BT_ASSERT_PRE_NAME_NON_NULL(name
);
1620 BT_ASSERT_PRE_NON_NULL("option-field-class", option_fc
,
1621 "Option field class");
1622 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1623 "variant-field-class-without-selector-field",
1624 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1626 named_fc
= create_named_field_class(name
, option_fc
);
1628 /* create_named_field_class() logs errors */
1629 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1633 status
= append_named_field_class_to_container_field_class((void *) fc
,
1634 named_fc
, __func__
, VAR_FC_OPT_NAME_IS_UNIQUE_ID
);
1635 if (status
== BT_FUNC_STATUS_OK
) {
1636 /* Moved to the container */
1642 destroy_named_field_class(named_fc
);
1649 int ranges_overlap(GPtrArray
*var_fc_opts
, const struct bt_integer_range_set
*range_set
,
1650 bool is_signed
, bool *has_overlap
)
1652 int status
= BT_FUNC_STATUS_OK
;
1653 struct bt_integer_range_set
*full_range_set
;
1656 *has_overlap
= false;
1659 * Build a single range set with all the ranges and test for
1663 full_range_set
= (void *) bt_integer_range_set_signed_create();
1665 full_range_set
= (void *) bt_integer_range_set_unsigned_create();
1668 if (!full_range_set
) {
1669 BT_LOGE_STR("Failed to create a range set.");
1670 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1674 /* Add existing option ranges */
1675 for (i
= 0; i
< var_fc_opts
->len
; i
++) {
1676 struct bt_field_class_variant_with_selector_field_option
*opt
=
1677 var_fc_opts
->pdata
[i
];
1680 for (j
= 0; j
< opt
->range_set
->ranges
->len
; j
++) {
1681 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1685 status
= bt_integer_range_set_signed_add_range(
1686 (void *) full_range_set
, range
->lower
.i
,
1689 status
= bt_integer_range_set_unsigned_add_range(
1690 (void *) full_range_set
, range
->lower
.u
,
1700 /* Add new ranges */
1701 for (i
= 0; i
< range_set
->ranges
->len
; i
++) {
1702 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1706 status
= bt_integer_range_set_signed_add_range(
1707 (void *) full_range_set
, range
->lower
.i
,
1710 status
= bt_integer_range_set_unsigned_add_range(
1711 (void *) full_range_set
, range
->lower
.u
,
1720 /* Check overlaps */
1722 *has_overlap
= bt_integer_range_set_signed_has_overlaps(full_range_set
);
1724 *has_overlap
= bt_integer_range_set_unsigned_has_overlaps(
1729 bt_object_put_ref(full_range_set
);
1734 int append_option_to_variant_with_selector_field_field_class(
1735 struct bt_field_class
*fc
, const char *name
,
1736 struct bt_field_class
*option_fc
,
1737 const struct bt_integer_range_set
*range_set
,
1738 enum bt_field_class_type expected_type
,
1739 const char *api_func
)
1742 struct bt_field_class_variant_with_selector_field
*var_fc
= (void *) fc
;
1743 struct bt_field_class_variant_with_selector_field_option
*opt
= NULL
;
1747 BT_ASSERT_PRE_NAME_NON_NULL_FROM_FUNC(api_func
, name
);
1748 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "option-field-class",
1749 option_fc
, "Option field class");
1750 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL_FROM_FUNC(api_func
, range_set
);
1751 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY_FROM_FUNC(api_func
, range_set
);
1752 status
= ranges_overlap(var_fc
->common
.common
.named_fcs
, range_set
,
1753 expected_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1756 /* ranges_overlap() logs errors */
1760 BT_ASSERT_PRE_FROM_FUNC(api_func
, "ranges-do-not-overlap",
1762 "Integer range set's ranges and existing ranges have an overlap: "
1764 opt
= create_variant_with_selector_field_option(name
, option_fc
, range_set
);
1766 /* create_variant_with_selector_field_option() logs errors */
1767 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1771 status
= append_named_field_class_to_container_field_class((void *) fc
,
1772 &opt
->common
, __func__
, VAR_FC_OPT_NAME_IS_UNIQUE_ID
);
1773 if (status
== BT_FUNC_STATUS_OK
) {
1774 /* Moved to the container */
1780 destroy_variant_with_selector_field_option(opt
);
1787 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1788 bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
1789 struct bt_field_class
*fc
, const char *name
,
1790 struct bt_field_class
*option_fc
,
1791 const struct bt_integer_range_set_unsigned
*range_set
)
1793 BT_ASSERT_PRE_NO_ERROR();
1794 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1795 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1796 "variant-field-class-with-unsigned-integer-selector-field",
1797 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1799 return append_option_to_variant_with_selector_field_field_class(fc
,
1800 name
, option_fc
, (const void *) range_set
,
1801 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1806 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1807 bt_field_class_variant_with_selector_field_integer_signed_append_option(
1808 struct bt_field_class
*fc
, const char *name
,
1809 struct bt_field_class
*option_fc
,
1810 const struct bt_integer_range_set_signed
*range_set
)
1812 BT_ASSERT_PRE_NO_ERROR();
1813 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1814 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1815 "variant-field-class-with-signed-integer-selector-field",
1816 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1818 return append_option_to_variant_with_selector_field_field_class(fc
,
1819 name
, option_fc
, (const void *) range_set
,
1820 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1825 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class
*fc
)
1827 const struct bt_field_class_variant
*var_fc
= (const void *) fc
;
1829 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1830 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1831 return (uint64_t) var_fc
->common
.named_fcs
->len
;
1835 const struct bt_field_class_variant_option
*
1836 bt_field_class_variant_borrow_option_by_name_const(
1837 const struct bt_field_class
*fc
, const char *name
)
1839 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1840 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1841 return (const void *)
1842 borrow_named_field_class_from_container_field_class_by_name(
1843 (void *) fc
, name
, __func__
);
1847 const struct bt_field_class_variant_option
*
1848 bt_field_class_variant_borrow_option_by_index_const(
1849 const struct bt_field_class
*fc
, uint64_t index
)
1851 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1852 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1853 return (const void *)
1854 borrow_named_field_class_from_container_field_class_at_index(
1855 (void *) fc
, index
, __func__
);
1859 struct bt_field_class_variant_option
*
1860 bt_field_class_variant_borrow_option_by_name(
1861 struct bt_field_class
*fc
, const char *name
)
1863 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1864 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1866 borrow_named_field_class_from_container_field_class_by_name(
1867 (void *) fc
, name
, __func__
);
1871 struct bt_field_class_variant_option
*
1872 bt_field_class_variant_borrow_option_by_index(
1873 struct bt_field_class
*fc
, uint64_t index
)
1875 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1876 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
1878 borrow_named_field_class_from_container_field_class_at_index(
1879 (void *) fc
, index
, __func__
);
1883 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1884 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
1885 const struct bt_field_class
*fc
, const char *name
)
1887 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1888 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1889 "variant-field-class-with-unsigned-integer-selector-field",
1890 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1892 return (const void *)
1893 borrow_named_field_class_from_container_field_class_by_name(
1894 (void *) fc
, name
, __func__
);
1898 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1899 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
1900 const struct bt_field_class
*fc
, uint64_t index
)
1902 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1903 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1904 "variant-field-class-with-unsigned-integer-selector-field",
1905 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1907 return (const void *)
1908 borrow_named_field_class_from_container_field_class_at_index(
1909 (void *) fc
, index
, __func__
);
1913 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1914 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
1915 const struct bt_field_class
*fc
, const char *name
)
1917 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1918 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1919 "variant-field-class-with-signed-integer-selector-field",
1920 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1922 return (const void *)
1923 borrow_named_field_class_from_container_field_class_by_name(
1924 (void *) fc
, name
, __func__
);
1928 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1929 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
1930 const struct bt_field_class
*fc
, uint64_t index
)
1932 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1933 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
1934 "variant-field-class-with-signed-integer-selector-field",
1935 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1937 return (const void *)
1938 borrow_named_field_class_from_container_field_class_at_index(
1939 (void *) fc
, index
, __func__
);
1943 const char *bt_field_class_variant_option_get_name(
1944 const struct bt_field_class_variant_option
*option
)
1946 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1948 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1949 return named_fc
->name
->str
;
1953 const struct bt_field_class
*
1954 bt_field_class_variant_option_borrow_field_class_const(
1955 const struct bt_field_class_variant_option
*option
)
1957 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1959 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1960 return named_fc
->fc
;
1964 struct bt_field_class
*
1965 bt_field_class_variant_option_borrow_field_class(
1966 struct bt_field_class_variant_option
*option
)
1968 struct bt_named_field_class
*named_fc
= (void *) option
;
1970 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1971 return named_fc
->fc
;
1975 const struct bt_integer_range_set_unsigned
*
1976 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
1977 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*option
)
1979 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1980 (const void *) option
;
1982 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1983 return (const void *) opt
->range_set
;
1987 const struct bt_integer_range_set_signed
*
1988 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
1989 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*option
)
1991 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1992 (const void *) option
;
1994 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
1995 return (const void *) opt
->range_set
;
1999 const struct bt_field_path
*
2000 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
2001 const struct bt_field_class
*fc
)
2003 const struct bt_field_class_variant_with_selector_field
*var_fc
=
2006 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2007 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL("field-class", fc
,
2009 return var_fc
->selector_field_path
;
2013 int init_array_field_class(struct bt_field_class_array
*fc
,
2014 enum bt_field_class_type type
, bt_object_release_func release_func
,
2015 struct bt_field_class
*element_fc
)
2019 BT_ASSERT(element_fc
);
2020 ret
= init_field_class((void *) fc
, type
, release_func
);
2025 fc
->element_fc
= element_fc
;
2026 bt_object_get_ref_no_null_check(fc
->element_fc
);
2027 bt_field_class_freeze(element_fc
);
2034 void finalize_array_field_class(struct bt_field_class_array
*array_fc
)
2036 BT_ASSERT(array_fc
);
2037 BT_LOGD_STR("Putting element field class.");
2038 finalize_field_class((void *) array_fc
);
2039 BT_OBJECT_PUT_REF_AND_RESET(array_fc
->element_fc
);
2043 void destroy_static_array_field_class(struct bt_object
*obj
)
2046 BT_LIB_LOGD("Destroying static array field class object: %!+F", obj
);
2047 finalize_array_field_class((void *) obj
);
2052 struct bt_field_class
*
2053 bt_field_class_array_static_create(bt_trace_class
*trace_class
,
2054 struct bt_field_class
*element_fc
, uint64_t length
)
2056 struct bt_field_class_array_static
*array_fc
= NULL
;
2058 BT_ASSERT_PRE_NO_ERROR();
2059 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2060 BT_ASSERT_PRE_NON_NULL("element-field-class", element_fc
,
2061 "Element field class");
2062 BT_LOGD_STR("Creating default static array field class object.");
2063 array_fc
= g_new0(struct bt_field_class_array_static
, 1);
2065 BT_LIB_LOGE_APPEND_CAUSE(
2066 "Failed to allocate one static array field class.");
2070 if (init_array_field_class((void *) array_fc
,
2071 BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2072 destroy_static_array_field_class
, element_fc
)) {
2076 array_fc
->length
= length
;
2077 BT_LIB_LOGD("Created static array field class object: %!+F", array_fc
);
2081 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2084 return (void *) array_fc
;
2088 const struct bt_field_class
*
2089 bt_field_class_array_borrow_element_field_class_const(
2090 const struct bt_field_class
*fc
)
2092 const struct bt_field_class_array
*array_fc
= (const void *) fc
;
2094 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2095 BT_ASSERT_PRE_DEV_FC_IS_ARRAY("field-class", fc
, "Field class");
2096 return array_fc
->element_fc
;
2100 struct bt_field_class
*
2101 bt_field_class_array_borrow_element_field_class(struct bt_field_class
*fc
)
2103 struct bt_field_class_array
*array_fc
= (void *) fc
;
2105 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2106 BT_ASSERT_PRE_DEV_FC_IS_ARRAY("field-class", fc
, "Field class");
2107 return array_fc
->element_fc
;
2111 uint64_t bt_field_class_array_static_get_length(const struct bt_field_class
*fc
)
2113 const struct bt_field_class_array_static
*array_fc
= (const void *) fc
;
2115 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2116 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2117 "static-array-field-class", BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2119 return (uint64_t) array_fc
->length
;
2123 void destroy_dynamic_array_field_class(struct bt_object
*obj
)
2125 struct bt_field_class_array_dynamic
*fc
= (void *) obj
;
2128 BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc
);
2129 finalize_array_field_class((void *) fc
);
2130 BT_LOGD_STR("Putting length field path.");
2131 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field_path
);
2132 BT_LOGD_STR("Putting length field class.");
2133 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_fc
);
2138 struct bt_field_class
*bt_field_class_array_dynamic_create(
2139 struct bt_trace_class
*trace_class
,
2140 struct bt_field_class
*element_fc
,
2141 struct bt_field_class
*length_fc
)
2143 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2145 BT_ASSERT_PRE_NO_ERROR();
2146 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2147 BT_ASSERT_PRE_NON_NULL("element-field-class", element_fc
,
2148 "Element field class");
2149 BT_LOGD_STR("Creating default dynamic array field class object.");
2150 array_fc
= g_new0(struct bt_field_class_array_dynamic
, 1);
2152 BT_LIB_LOGE_APPEND_CAUSE(
2153 "Failed to allocate one dynamic array field class.");
2157 if (init_array_field_class((void *) array_fc
,
2159 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
2160 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2161 destroy_dynamic_array_field_class
, element_fc
)) {
2166 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT("length-field-class",
2167 length_fc
, "Length field class");
2168 array_fc
->length_fc
= length_fc
;
2169 bt_object_get_ref_no_null_check(array_fc
->length_fc
);
2170 bt_field_class_freeze(length_fc
);
2173 BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc
);
2177 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2180 return (void *) array_fc
;
2184 const struct bt_field_path
*
2185 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
2186 const struct bt_field_class
*fc
)
2188 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2190 BT_ASSERT_PRE_NO_ERROR();
2191 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2192 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2193 "dynamic-array-field-class-with-length-field",
2194 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2196 return seq_fc
->length_field_path
;
2200 void destroy_string_field_class(struct bt_object
*obj
)
2203 BT_LIB_LOGD("Destroying string field class object: %!+F", obj
);
2204 finalize_field_class((void *) obj
);
2209 struct bt_field_class
*bt_field_class_string_create(bt_trace_class
*trace_class
)
2211 struct bt_field_class_string
*string_fc
= NULL
;
2213 BT_ASSERT_PRE_NO_ERROR();
2214 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2215 BT_LOGD_STR("Creating default string field class object.");
2216 string_fc
= g_new0(struct bt_field_class_string
, 1);
2218 BT_LIB_LOGE_APPEND_CAUSE(
2219 "Failed to allocate one string field class.");
2223 if (init_field_class((void *) string_fc
, BT_FIELD_CLASS_TYPE_STRING
,
2224 destroy_string_field_class
)) {
2228 BT_LIB_LOGD("Created string field class object: %!+F", string_fc
);
2232 BT_OBJECT_PUT_REF_AND_RESET(string_fc
);
2235 return (void *) string_fc
;
2238 void _bt_field_class_freeze(const struct bt_field_class
*c_fc
)
2240 struct bt_field_class
*fc
= (void *) c_fc
;
2243 * Element/member/option field classes are frozen when added to
2247 bt_value_freeze(fc
->user_attributes
);
2250 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2251 bt_field_class_type_is(fc
->type
,
2252 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2253 struct bt_field_class_named_field_class_container
*container_fc
=
2257 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2258 bt_named_field_class_freeze(
2259 container_fc
->named_fcs
->pdata
[i
]);
2264 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
)
2266 BT_ASSERT(named_fc
);
2267 BT_ASSERT(named_fc
->fc
->frozen
);
2268 BT_LIB_LOGD("Freezing named field class's user attributes: %!+v",
2269 named_fc
->user_attributes
);
2270 bt_value_freeze(named_fc
->user_attributes
);
2271 ((struct bt_named_field_class
*) named_fc
)->frozen
= true;
2274 void bt_field_class_make_part_of_trace_class(const struct bt_field_class
*c_fc
)
2276 struct bt_field_class
*fc
= (void *) c_fc
;
2279 BT_ASSERT_PRE("field-class-is-not-part-of-trace-class",
2280 !fc
->part_of_trace_class
,
2281 "Field class is already part of a trace class: %!+F", fc
);
2282 fc
->part_of_trace_class
= true;
2284 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2285 bt_field_class_type_is(fc
->type
,
2286 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2287 struct bt_field_class_named_field_class_container
*container_fc
=
2291 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2292 struct bt_named_field_class
*named_fc
=
2293 container_fc
->named_fcs
->pdata
[i
];
2295 bt_field_class_make_part_of_trace_class(named_fc
->fc
);
2297 } else if (bt_field_class_type_is(fc
->type
,
2298 BT_FIELD_CLASS_TYPE_ARRAY
)) {
2299 struct bt_field_class_array
*array_fc
= (void *) fc
;
2301 bt_field_class_make_part_of_trace_class(array_fc
->element_fc
);
2306 const struct bt_value
*bt_field_class_borrow_user_attributes_const(
2307 const struct bt_field_class
*fc
)
2309 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2310 return fc
->user_attributes
;
2314 struct bt_value
*bt_field_class_borrow_user_attributes(
2315 struct bt_field_class
*field_class
)
2317 return (void *) bt_field_class_borrow_user_attributes_const(
2318 (void *) field_class
);
2323 void bt_field_class_set_user_attributes(
2324 struct bt_field_class
*fc
,
2325 const struct bt_value
*user_attributes
)
2327 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2328 BT_ASSERT_PRE_USER_ATTRS_NON_NULL(user_attributes
);
2329 BT_ASSERT_PRE_USER_ATTRS_IS_MAP(user_attributes
);
2330 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
2331 bt_object_put_ref_no_null_check(fc
->user_attributes
);
2332 fc
->user_attributes
= (void *) user_attributes
;
2333 bt_object_get_ref_no_null_check(fc
->user_attributes
);
2337 const struct bt_value
*bt_named_field_class_borrow_user_attributes_const(
2338 const struct bt_named_field_class
*named_fc
)
2340 return named_fc
->user_attributes
;
2344 void set_named_field_class_user_attributes(
2345 struct bt_named_field_class
*named_fc
,
2346 const struct bt_value
*user_attributes
, const char *api_func
)
2348 BT_ASSERT_PRE_USER_ATTRS_NON_NULL_FROM_FUNC(api_func
, user_attributes
);
2349 BT_ASSERT_PRE_USER_ATTRS_NON_NULL_FROM_FUNC(api_func
, user_attributes
);
2350 bt_object_put_ref_no_null_check(named_fc
->user_attributes
);
2351 named_fc
->user_attributes
= (void *) user_attributes
;
2352 bt_object_get_ref_no_null_check(named_fc
->user_attributes
);
2356 const struct bt_value
*
2357 bt_field_class_structure_member_borrow_user_attributes_const(
2358 const struct bt_field_class_structure_member
*member
)
2360 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
2361 return bt_named_field_class_borrow_user_attributes_const(
2362 (const void *) member
);
2367 bt_field_class_structure_member_borrow_user_attributes(
2368 struct bt_field_class_structure_member
*member
)
2370 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
2371 return (void *) bt_named_field_class_borrow_user_attributes_const(
2376 void bt_field_class_structure_member_set_user_attributes(
2377 struct bt_field_class_structure_member
*member
,
2378 const struct bt_value
*user_attributes
)
2380 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
2381 BT_ASSERT_PRE_DEV_HOT("structure-field-class-member",
2382 (struct bt_named_field_class
*) member
,
2383 "Structure field class member", ".");
2384 set_named_field_class_user_attributes((void *) member
,
2385 user_attributes
, __func__
);
2389 const struct bt_value
*bt_field_class_variant_option_borrow_user_attributes_const(
2390 const struct bt_field_class_variant_option
*option
)
2392 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
2393 return bt_named_field_class_borrow_user_attributes_const(
2394 (const void *) option
);
2398 struct bt_value
*bt_field_class_variant_option_borrow_user_attributes(
2399 struct bt_field_class_variant_option
*option
)
2401 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
2402 return (void *) bt_named_field_class_borrow_user_attributes_const(
2407 void bt_field_class_variant_option_set_user_attributes(
2408 struct bt_field_class_variant_option
*option
,
2409 const struct bt_value
*user_attributes
)
2411 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
2412 BT_ASSERT_PRE_DEV_HOT("variant-field-class-option",
2413 (struct bt_named_field_class
*) option
,
2414 "Variant field class option", ".");
2415 set_named_field_class_user_attributes((void *) option
,
2416 user_attributes
, __func__
);
2420 void bt_field_class_get_ref(const struct bt_field_class
*field_class
)
2422 bt_object_get_ref(field_class
);
2426 void bt_field_class_put_ref(const struct bt_field_class
*field_class
)
2428 bt_object_put_ref(field_class
);