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"
30 #include "lib/trace-ir/trace-class.h"
33 enum bt_field_class_type
bt_field_class_get_type(
34 const struct bt_field_class
*fc
)
36 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
41 int init_field_class(struct bt_field_class
*fc
, enum bt_field_class_type type
,
42 bt_object_release_func release_func
,
43 const struct bt_trace_class
*trace_class
)
48 BT_ASSERT(release_func
);
49 bt_object_init_shared(&fc
->base
, release_func
);
51 fc
->user_attributes
= bt_value_map_create();
52 if (!fc
->user_attributes
) {
53 BT_LIB_LOGE_APPEND_CAUSE(
54 "Failed to create a map value object.");
59 fc
->mip_version
= trace_class
->mip_version
;
66 void finalize_field_class(struct bt_field_class
*fc
)
68 BT_OBJECT_PUT_REF_AND_RESET(fc
->user_attributes
);
71 #define _BT_ASSERT_PRE_BIT_ARRAY_FC_FLAG_NAME "Bit array field class flag"
72 #define _BT_ASSERT_PRE_BIT_ARRAY_FC_FLAG_ID "bit-array-field-class-flag"
74 #define BT_ASSERT_PRE_DEV_BIT_ARRAY_FC_FLAG_NON_NULL(_flag) \
75 BT_ASSERT_PRE_DEV_NON_NULL( \
76 _BT_ASSERT_PRE_BIT_ARRAY_FC_FLAG_ID, (_flag), \
77 _BT_ASSERT_PRE_BIT_ARRAY_FC_FLAG_NAME)
80 void destroy_bit_array_field_class(struct bt_object
*obj
)
82 const struct bt_field_class_bit_array
*ba_fc
;
85 BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj
);
87 ba_fc
= (const void *) obj
;
90 g_ptr_array_free(ba_fc
->flags
, TRUE
);
93 finalize_field_class((void *) obj
);
98 void destroy_bit_array_flag(struct bt_field_class_bit_array_flag
*flag
)
105 bt_object_put_ref(flag
->range_set
);
113 void destroy_bit_array_flag_void(gpointer ptr
)
115 destroy_bit_array_flag((struct bt_field_class_bit_array_flag
*) ptr
);
119 struct bt_field_class
*bt_field_class_bit_array_create(
120 struct bt_trace_class
*trace_class
, uint64_t length
)
122 struct bt_field_class_bit_array
*ba_fc
= NULL
;
124 BT_ASSERT_PRE_NO_ERROR();
125 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
126 BT_ASSERT_PRE("valid-length", length
> 0 && length
<= 64,
127 "Unsupported length for bit array field class "
128 "(minimum is 1, maximum is 64): length=%" PRIu64
, length
);
129 BT_LOGD("Creating default bit array field class object.");
130 ba_fc
= g_new0(struct bt_field_class_bit_array
, 1);
132 BT_LIB_LOGE_APPEND_CAUSE(
133 "Failed to allocate one bit array field class.");
137 if (init_field_class((void *) ba_fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
138 destroy_bit_array_field_class
, trace_class
)) {
142 ba_fc
->length
= length
;
143 ba_fc
->flags
= g_ptr_array_new_with_free_func(
144 destroy_bit_array_flag_void
);
146 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
150 BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc
);
154 BT_OBJECT_PUT_REF_AND_RESET(ba_fc
);
157 return (void *) ba_fc
;
161 uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class
*fc
)
163 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
165 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
166 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
167 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
168 return ba_fc
->length
;
172 uint64_t bt_field_class_bit_array_get_flag_count(const bt_field_class
*fc
)
174 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
176 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
177 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
178 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
179 return ba_fc
->flags
->len
;
183 bt_field_class_bit_array_add_flag_status
bt_field_class_bit_array_add_flag(
184 struct bt_field_class
*fc
, const char *label
,
185 const bt_integer_range_set_unsigned
*index_ranges
)
187 struct bt_field_class_bit_array
*ba_fc
= (void *) fc
;
188 struct bt_field_class_bit_array_flag
*flag
= NULL
;
189 bt_field_class_bit_array_add_flag_status status
;
190 struct bt_integer_range_set
*index_ranges_internal
=
191 (bt_integer_range_set
*) index_ranges
;
194 BT_ASSERT_PRE_NO_ERROR();
195 BT_ASSERT_PRE_FC_NON_NULL(fc
);
196 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
, "bit-array",
197 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
198 BT_ASSERT_PRE_NON_NULL("label", label
, "Label");
199 BT_ASSERT_PRE("bit-array-field-class-flag-label-is-unique",
200 !bt_field_class_bit_array_borrow_flag_by_label_const(fc
, label
),
201 "Duplicate flag name in bit array field class: "
202 "%![bit-array-fc-]+F, label=\"%s\"", fc
, label
);
203 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(index_ranges
);
205 for (range_i
= 0; range_i
< index_ranges_internal
->ranges
->len
; ++range_i
) {
206 struct bt_integer_range
*range
207 = BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(index_ranges_internal
,
210 BT_ASSERT_PRE("bit-array-field-class-flag-bit-index-is-less-than-field-class-length",
211 range
->upper
.u
< ba_fc
->length
,
212 "Flag bit index range's upper bound is greater than or "
213 "equal to bit array field length: %![bit-array-fc-]+F, "
214 "range-index=%u, upper-bound=%" PRIu64
,
215 ba_fc
, range_i
, range
->upper
.u
);
218 flag
= g_new0(struct bt_field_class_bit_array_flag
, 1);
220 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a bit_array_flag.");
221 status
= BT_FIELD_CLASS_BIT_ARRAY_ADD_FLAG_STATUS_MEMORY_ERROR
;
225 flag
->label
= g_strdup(label
);
227 BT_LIB_LOGE_APPEND_CAUSE(
228 "Failed to allocate memory for bit array flag label.");
229 status
= BT_FIELD_CLASS_BIT_ARRAY_ADD_FLAG_STATUS_MEMORY_ERROR
;
233 flag
->range_set
= index_ranges
;
234 bt_integer_range_set_unsigned_get_ref(flag
->range_set
);
237 for (range_i
= 0; range_i
< index_ranges_internal
->ranges
->len
; range_i
++) {
238 const struct bt_integer_range
*range
= (const void *)
239 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(index_ranges_internal
,
243 for (bit_index
= range
->lower
.u
; bit_index
<= range
->upper
.u
;
245 flag
->mask
|= UINT64_C(1) << bit_index
;
249 g_ptr_array_add(ba_fc
->flags
, flag
);
252 status
= BT_FIELD_CLASS_BIT_ARRAY_ADD_FLAG_STATUS_OK
;
256 destroy_bit_array_flag(flag
);
261 const bt_field_class_bit_array_flag
*
262 bt_field_class_bit_array_borrow_flag_by_index_const(
263 const struct bt_field_class
*fc
, uint64_t index
)
265 struct bt_field_class_bit_array
*ba_fc
= (void *) fc
;
267 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
268 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
269 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
270 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, ba_fc
->flags
->len
);
271 return ba_fc
->flags
->pdata
[index
];
275 const bt_field_class_bit_array_flag
*
276 bt_field_class_bit_array_borrow_flag_by_label_const(
277 const struct bt_field_class
*fc
, const char *label
)
279 struct bt_field_class_bit_array
*ba_fc
= (void *) fc
;
280 const struct bt_field_class_bit_array_flag
*flag
= NULL
;
283 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
284 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
285 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
286 BT_ASSERT_PRE_DEV_NON_NULL("label", label
, "Label");
288 for (i
= 0; i
< ba_fc
->flags
->len
; i
++) {
289 const struct bt_field_class_bit_array_flag
*candidate
=
290 ba_fc
->flags
->pdata
[i
];
292 if (strcmp(candidate
->label
, label
) == 0) {
302 bt_field_class_bit_array_get_active_flag_labels_for_value_as_integer_status
303 bt_field_class_bit_array_get_active_flag_labels_for_value_as_integer(
304 const struct bt_field_class
*fc
, uint64_t value_as_integer
,
305 bt_field_class_bit_array_flag_label_array
*label_array
,
308 struct bt_field_class_bit_array
*ba_fc
= (void *) fc
;
311 BT_ASSERT_PRE_DEV_NO_ERROR();
312 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
313 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "bit-array",
314 BT_FIELD_CLASS_TYPE_BIT_ARRAY
, "Field class");
315 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
316 "Label array (output)");
317 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
319 g_ptr_array_set_size(ba_fc
->label_buf
, 0);
321 for (i
= 0; i
< ba_fc
->flags
->len
; ++i
) {
322 const struct bt_field_class_bit_array_flag
*flag
=
323 ba_fc
->flags
->pdata
[i
];
325 if (value_as_integer
& flag
->mask
) {
326 g_ptr_array_add(ba_fc
->label_buf
, flag
->label
);
330 *label_array
= (void *) ba_fc
->label_buf
->pdata
;
331 *count
= (uint64_t) ba_fc
->label_buf
->len
;
333 return BT_FIELD_CLASS_BIT_ARRAY_GET_ACTIVE_FLAG_LABELS_FOR_VALUE_AS_INTEGER_STATUS_OK
;
337 const char *bt_field_class_bit_array_flag_get_label(
338 const struct bt_field_class_bit_array_flag
*flag
)
340 BT_ASSERT_PRE_DEV_BIT_ARRAY_FC_FLAG_NON_NULL(flag
);
346 const bt_integer_range_set_unsigned
*
347 bt_field_class_bit_array_flag_borrow_index_ranges_const(
348 const struct bt_field_class_bit_array_flag
*flag
)
350 BT_ASSERT_PRE_DEV_BIT_ARRAY_FC_FLAG_NON_NULL(flag
);
352 return flag
->range_set
;
356 void destroy_bool_field_class(struct bt_object
*obj
)
359 BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj
);
360 finalize_field_class((void *) obj
);
365 struct bt_field_class
*bt_field_class_bool_create(
366 bt_trace_class
*trace_class
)
368 struct bt_field_class_bool
*bool_fc
= NULL
;
370 BT_ASSERT_PRE_NO_ERROR();
371 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
372 BT_LOGD("Creating default boolean field class object.");
373 bool_fc
= g_new0(struct bt_field_class_bool
, 1);
375 BT_LIB_LOGE_APPEND_CAUSE(
376 "Failed to allocate one boolean field class.");
380 if (init_field_class((void *) bool_fc
, BT_FIELD_CLASS_TYPE_BOOL
,
381 destroy_bool_field_class
, trace_class
)) {
385 BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc
);
389 BT_OBJECT_PUT_REF_AND_RESET(bool_fc
);
392 return (void *) bool_fc
;
396 int init_integer_field_class(struct bt_field_class_integer
*fc
,
397 enum bt_field_class_type type
,
398 bt_object_release_func release_func
,
399 const struct bt_trace_class
*trace_class
)
403 ret
= init_field_class((void *) fc
, type
, release_func
,
410 fc
->base
= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
;
417 void destroy_integer_field_class(struct bt_object
*obj
)
420 BT_LIB_LOGD("Destroying integer field class object: %!+F", obj
);
421 finalize_field_class((void *) obj
);
426 struct bt_field_class
*create_integer_field_class(bt_trace_class
*trace_class
,
427 enum bt_field_class_type type
)
429 struct bt_field_class_integer
*int_fc
= NULL
;
431 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
432 BT_LOGD("Creating default integer field class object: type=%s",
433 bt_common_field_class_type_string(type
));
434 int_fc
= g_new0(struct bt_field_class_integer
, 1);
436 BT_LIB_LOGE_APPEND_CAUSE(
437 "Failed to allocate one integer field class.");
441 if (init_integer_field_class(int_fc
, type
,
442 destroy_integer_field_class
, trace_class
)) {
446 BT_LIB_LOGD("Created integer field class object: %!+F", int_fc
);
450 BT_OBJECT_PUT_REF_AND_RESET(int_fc
);
453 return (void *) int_fc
;
457 struct bt_field_class
*bt_field_class_integer_unsigned_create(
458 bt_trace_class
*trace_class
)
460 BT_ASSERT_PRE_NO_ERROR();
462 return create_integer_field_class(trace_class
,
463 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
467 struct bt_field_class
*bt_field_class_integer_signed_create(
468 bt_trace_class
*trace_class
)
470 BT_ASSERT_PRE_NO_ERROR();
472 return create_integer_field_class(trace_class
,
473 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
477 uint64_t bt_field_class_integer_get_field_value_range(
478 const struct bt_field_class
*fc
)
480 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
482 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
483 BT_ASSERT_PRE_DEV_FC_IS_INT("field-class", fc
, "Field class");
484 return int_fc
->range
;
488 bool size_is_valid_for_enumeration_field_class(
489 struct bt_field_class
*fc
__attribute__((unused
)),
490 uint64_t size
__attribute__((unused
)))
497 void bt_field_class_integer_set_field_value_range(
498 struct bt_field_class
*fc
, uint64_t size
)
500 struct bt_field_class_integer
*int_fc
= (void *) fc
;
502 BT_ASSERT_PRE_FC_NON_NULL(fc
);
503 BT_ASSERT_PRE_FC_IS_INT("field-class", fc
, "Field class");
504 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
505 BT_ASSERT_PRE("valid-n",
506 size
>= 1 && size
<= 64,
507 "Unsupported size for integer field class's field value range "
508 "(minimum is 1, maximum is 64): size=%" PRIu64
, size
);
509 BT_ASSERT_PRE("valid-n-for-enumeration-field-class",
510 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
511 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
512 size_is_valid_for_enumeration_field_class(fc
, size
),
513 "Invalid field value range for enumeration field class: "
514 "at least one of the current mapping ranges contains values "
515 "which are outside this range: %!+F, size=%" PRIu64
, fc
, size
);
516 int_fc
->range
= size
;
517 BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc
);
521 enum bt_field_class_integer_preferred_display_base
522 bt_field_class_integer_get_preferred_display_base(const struct bt_field_class
*fc
)
524 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
526 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
527 BT_ASSERT_PRE_DEV_FC_IS_INT("field-class", fc
, "Field class");
532 void bt_field_class_integer_set_preferred_display_base(
533 struct bt_field_class
*fc
,
534 enum bt_field_class_integer_preferred_display_base base
)
536 struct bt_field_class_integer
*int_fc
= (void *) fc
;
538 BT_ASSERT_PRE_FC_NON_NULL(fc
);
539 BT_ASSERT_PRE_FC_IS_INT("field-class", fc
, "Field class");
540 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
542 BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc
);
546 void finalize_enumeration_field_class_mapping(
547 struct bt_field_class_enumeration_mapping
*mapping
)
551 if (mapping
->label
) {
552 g_string_free(mapping
->label
, TRUE
);
553 mapping
->label
= NULL
;
556 BT_OBJECT_PUT_REF_AND_RESET(mapping
->range_set
);
560 void destroy_enumeration_field_class(struct bt_object
*obj
)
562 struct bt_field_class_enumeration
*fc
= (void *) obj
;
565 BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc
);
566 finalize_field_class((void *) obj
);
571 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
572 finalize_enumeration_field_class_mapping(
573 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
));
576 g_array_free(fc
->mappings
, TRUE
);
581 g_ptr_array_free(fc
->label_buf
, TRUE
);
582 fc
->label_buf
= NULL
;
589 struct bt_field_class
*create_enumeration_field_class(
590 bt_trace_class
*trace_class
, enum bt_field_class_type type
)
592 struct bt_field_class_enumeration
*enum_fc
= NULL
;
594 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
595 BT_LOGD("Creating default enumeration field class object: type=%s",
596 bt_common_field_class_type_string(type
));
597 enum_fc
= g_new0(struct bt_field_class_enumeration
, 1);
599 BT_LIB_LOGE_APPEND_CAUSE(
600 "Failed to allocate one enumeration field class.");
604 if (init_integer_field_class((void *) enum_fc
, type
,
605 destroy_enumeration_field_class
, trace_class
)) {
609 enum_fc
->mappings
= g_array_new(FALSE
, TRUE
,
610 sizeof(struct bt_field_class_enumeration_mapping
));
611 if (!enum_fc
->mappings
) {
612 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
616 enum_fc
->label_buf
= g_ptr_array_new();
617 if (!enum_fc
->label_buf
) {
618 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
622 BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc
);
626 BT_OBJECT_PUT_REF_AND_RESET(enum_fc
);
629 return (void *) enum_fc
;
633 struct bt_field_class
*bt_field_class_enumeration_unsigned_create(
634 bt_trace_class
*trace_class
)
636 BT_ASSERT_PRE_NO_ERROR();
638 return create_enumeration_field_class(trace_class
,
639 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
643 struct bt_field_class
*bt_field_class_enumeration_signed_create(
644 bt_trace_class
*trace_class
)
646 BT_ASSERT_PRE_NO_ERROR();
648 return create_enumeration_field_class(trace_class
,
649 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
653 uint64_t bt_field_class_enumeration_get_mapping_count(
654 const struct bt_field_class
*fc
)
656 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
658 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
659 BT_ASSERT_PRE_DEV_FC_IS_ENUM("field-class", fc
, "Field class");
660 return (uint64_t) enum_fc
->mappings
->len
;
664 const struct bt_field_class_enumeration_unsigned_mapping
*
665 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
666 const struct bt_field_class
*fc
, uint64_t index
)
668 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
670 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
671 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
672 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
673 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
674 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
678 const struct bt_field_class_enumeration_signed_mapping
*
679 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
680 const struct bt_field_class
*fc
, uint64_t index
)
682 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
684 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
685 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
686 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
687 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
688 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
692 const struct bt_field_class_enumeration_mapping
*
693 borrow_enumeration_field_class_mapping_by_label(
694 const struct bt_field_class_enumeration
*fc
, const char *label
,
695 const char *api_func
)
697 struct bt_field_class_enumeration_mapping
*mapping
= NULL
;
701 BT_ASSERT_PRE_DEV_NON_NULL_FROM_FUNC(api_func
, "label", label
,
704 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
705 struct bt_field_class_enumeration_mapping
*this_mapping
=
706 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
);
708 if (strcmp(this_mapping
->label
->str
, label
) == 0) {
709 mapping
= this_mapping
;
719 const struct bt_field_class_enumeration_signed_mapping
*
720 bt_field_class_enumeration_signed_borrow_mapping_by_label_const(
721 const struct bt_field_class
*fc
, const char *label
)
723 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
724 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
725 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
726 return (const void *) borrow_enumeration_field_class_mapping_by_label(
727 (const void *) fc
, label
, __func__
);
731 const struct bt_field_class_enumeration_unsigned_mapping
*
732 bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(
733 const struct bt_field_class
*fc
, const char *label
)
735 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
736 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
737 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
738 return (const void *) borrow_enumeration_field_class_mapping_by_label(
739 (const void *) fc
, label
, __func__
);
743 const char *bt_field_class_enumeration_mapping_get_label(
744 const struct bt_field_class_enumeration_mapping
*mapping
)
746 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
747 mapping
, "Enumeration field class mapping");
748 return mapping
->label
->str
;
752 const struct bt_integer_range_set_unsigned
*
753 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
754 const struct bt_field_class_enumeration_unsigned_mapping
*u_mapping
)
756 const struct bt_field_class_enumeration_mapping
*mapping
=
757 (const void *) u_mapping
;
759 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
760 mapping
, "Enumeration field class mapping");
761 return (const void *) mapping
->range_set
;
765 const struct bt_integer_range_set_signed
*
766 bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
767 const struct bt_field_class_enumeration_signed_mapping
*s_mapping
)
769 const struct bt_field_class_enumeration_mapping
*mapping
=
770 (const void *) s_mapping
;
772 BT_ASSERT_PRE_DEV_NON_NULL("enumeration-field-class-mapping",
773 mapping
, "Enumeration field class mapping");
774 return (const void *) mapping
->range_set
;
778 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
779 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
780 const struct bt_field_class
*fc
, uint64_t value
,
781 bt_field_class_enumeration_mapping_label_array
*label_array
,
784 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
787 BT_ASSERT_PRE_DEV_NO_ERROR();
788 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
789 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
790 "Label array (output)");
791 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
792 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "unsigned-enumeration",
793 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
794 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
796 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
798 const struct bt_field_class_enumeration_mapping
*mapping
=
799 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
801 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
802 const struct bt_integer_range
*range
= (const void *)
803 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
804 mapping
->range_set
, j
);
806 if (value
>= range
->lower
.u
&&
807 value
<= range
->upper
.u
) {
808 g_ptr_array_add(enum_fc
->label_buf
,
809 mapping
->label
->str
);
815 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
816 *count
= (uint64_t) enum_fc
->label_buf
->len
;
817 return BT_FUNC_STATUS_OK
;
821 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
822 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
823 const struct bt_field_class
*fc
, int64_t value
,
824 bt_field_class_enumeration_mapping_label_array
*label_array
,
827 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
830 BT_ASSERT_PRE_DEV_NO_ERROR();
831 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
832 BT_ASSERT_PRE_DEV_NON_NULL("label-array-output", label_array
,
833 "Label array (output)");
834 BT_ASSERT_PRE_DEV_NON_NULL("count-output", count
, "Count (output)");
835 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
, "signed-enumeration",
836 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
837 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
839 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
841 const struct bt_field_class_enumeration_mapping
*mapping
=
842 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
844 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
845 const struct bt_integer_range
*range
= (const void *)
846 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
847 mapping
->range_set
, j
);
849 if (value
>= range
->lower
.i
&&
850 value
<= range
->upper
.i
) {
851 g_ptr_array_add(enum_fc
->label_buf
,
852 mapping
->label
->str
);
858 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
859 *count
= (uint64_t) enum_fc
->label_buf
->len
;
860 return BT_FUNC_STATUS_OK
;
864 bool enumeration_field_class_has_mapping_with_label(
865 const struct bt_field_class_enumeration
*enum_fc
,
874 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
875 struct bt_field_class_enumeration_mapping
*mapping_candidate
=
876 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
878 if (strcmp(mapping_candidate
->label
->str
, label
) == 0) {
889 enum bt_field_class_enumeration_add_mapping_status
890 add_mapping_to_enumeration_field_class(struct bt_field_class
*fc
,
891 const char *label
, const struct bt_integer_range_set
*range_set
,
892 const char *api_func
)
894 enum bt_field_class_enumeration_add_mapping_status status
=
896 struct bt_field_class_enumeration
*enum_fc
= (void *) fc
;
897 struct bt_field_class_enumeration_mapping mapping
= { 0 };
899 BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func
);
901 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "label", label
, "Label");
902 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL_FROM_FUNC(api_func
, range_set
);
903 BT_ASSERT_PRE_FROM_FUNC(api_func
,
904 "enumeration-field-class-mapping-label-is-unique",
905 !enumeration_field_class_has_mapping_with_label(
907 "Duplicate mapping name in enumeration field class: "
908 "%![enum-fc-]+F, label=\"%s\"", fc
, label
);
909 mapping
.range_set
= range_set
;
910 bt_object_get_ref(mapping
.range_set
);
911 mapping
.label
= g_string_new(label
);
912 if (!mapping
.label
) {
913 finalize_enumeration_field_class_mapping(&mapping
);
914 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
918 g_array_append_val(enum_fc
->mappings
, mapping
);
919 BT_LIB_LOGD("Added mapping to enumeration field class: "
920 "%![fc-]+F, label=\"%s\"", fc
, label
);
927 enum bt_field_class_enumeration_add_mapping_status
928 bt_field_class_enumeration_unsigned_add_mapping(
929 struct bt_field_class
*fc
, const char *label
,
930 const struct bt_integer_range_set_unsigned
*range_set
)
932 BT_ASSERT_PRE_NO_ERROR();
933 BT_ASSERT_PRE_FC_NON_NULL(fc
);
934 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
935 "unsigned-enumeration-field-class",
936 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
937 return add_mapping_to_enumeration_field_class(fc
, label
,
938 (const void *) range_set
, __func__
);
942 enum bt_field_class_enumeration_add_mapping_status
943 bt_field_class_enumeration_signed_add_mapping(
944 struct bt_field_class
*fc
, const char *label
,
945 const struct bt_integer_range_set_signed
*range_set
)
947 BT_ASSERT_PRE_NO_ERROR();
948 BT_ASSERT_PRE_FC_NON_NULL(fc
);
949 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
950 "signed-enumeration-field-class",
951 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
, "Field class");
952 return add_mapping_to_enumeration_field_class(fc
, label
,
953 (const void *) range_set
, __func__
);
957 void destroy_real_field_class(struct bt_object
*obj
)
960 BT_LIB_LOGD("Destroying real field class object: %!+F", obj
);
961 finalize_field_class((void *) obj
);
966 struct bt_field_class
*create_real_field_class(bt_trace_class
*trace_class
,
967 enum bt_field_class_type type
)
969 struct bt_field_class_real
*real_fc
= NULL
;
971 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
972 BT_LOGD("Creating default real field class object: type=%s",
973 bt_common_field_class_type_string(type
));
974 real_fc
= g_new0(struct bt_field_class_real
, 1);
976 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
980 if (init_field_class((void *) real_fc
, type
, destroy_real_field_class
,
985 BT_LIB_LOGD("Created real field class object: %!+F", real_fc
);
989 BT_OBJECT_PUT_REF_AND_RESET(real_fc
);
992 return (void *) real_fc
;
996 struct bt_field_class
*bt_field_class_real_single_precision_create(
997 bt_trace_class
*trace_class
)
999 BT_ASSERT_PRE_NO_ERROR();
1001 return create_real_field_class(trace_class
,
1002 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
);
1006 struct bt_field_class
*bt_field_class_real_double_precision_create(
1007 bt_trace_class
*trace_class
)
1009 BT_ASSERT_PRE_NO_ERROR();
1011 return create_real_field_class(trace_class
,
1012 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
);
1016 int init_named_field_classes_container(
1017 struct bt_field_class_named_field_class_container
*fc
,
1018 enum bt_field_class_type type
,
1019 bt_object_release_func fc_release_func
,
1020 GDestroyNotify named_fc_destroy_func
,
1021 const struct bt_trace_class
*trace_class
)
1025 ret
= init_field_class((void *) fc
, type
, fc_release_func
,
1031 fc
->named_fcs
= g_ptr_array_new_with_free_func(named_fc_destroy_func
);
1032 if (!fc
->named_fcs
) {
1033 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
1038 fc
->name_to_index
= g_hash_table_new(g_str_hash
, g_str_equal
);
1039 if (!fc
->name_to_index
) {
1040 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
1050 void finalize_named_field_class(struct bt_named_field_class
*named_fc
)
1052 BT_ASSERT(named_fc
);
1053 BT_LIB_LOGD("Finalizing named field class: "
1054 "addr=%p, name=\"%s\", %![fc-]+F",
1055 named_fc
, named_fc
->name
? named_fc
->name
->str
: NULL
,
1057 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
1059 if (named_fc
->name
) {
1060 g_string_free(named_fc
->name
, TRUE
);
1061 named_fc
->name
= NULL
;
1064 BT_LOGD_STR("Putting named field class's field class.");
1065 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->fc
);
1069 void destroy_named_field_class(gpointer ptr
)
1071 struct bt_named_field_class
*named_fc
= ptr
;
1074 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
1075 finalize_named_field_class(ptr
);
1081 void destroy_variant_with_selector_field_option(gpointer ptr
)
1083 struct bt_field_class_variant_with_selector_field_option
*opt
= ptr
;
1086 finalize_named_field_class(&opt
->common
);
1087 BT_OBJECT_PUT_REF_AND_RESET(opt
->range_set
);
1093 void finalize_named_field_classes_container(
1094 struct bt_field_class_named_field_class_container
*fc
)
1098 if (fc
->named_fcs
) {
1099 g_ptr_array_free(fc
->named_fcs
, TRUE
);
1100 fc
->named_fcs
= NULL
;
1104 if (fc
->name_to_index
) {
1105 g_hash_table_destroy(fc
->name_to_index
);
1106 fc
->name_to_index
= NULL
;
1111 void destroy_structure_field_class(struct bt_object
*obj
)
1114 BT_LIB_LOGD("Destroying structure field class object: %!+F", obj
);
1115 finalize_field_class((void *) obj
);
1116 finalize_named_field_classes_container((void *) obj
);
1121 struct bt_field_class
*bt_field_class_structure_create(
1122 bt_trace_class
*trace_class
)
1125 struct bt_field_class_structure
*struct_fc
= NULL
;
1127 BT_ASSERT_PRE_NO_ERROR();
1128 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1129 BT_LOGD_STR("Creating default structure field class object.");
1130 struct_fc
= g_new0(struct bt_field_class_structure
, 1);
1132 BT_LIB_LOGE_APPEND_CAUSE(
1133 "Failed to allocate one structure field class.");
1137 ret
= init_named_field_classes_container((void *) struct_fc
,
1138 BT_FIELD_CLASS_TYPE_STRUCTURE
, destroy_structure_field_class
,
1139 destroy_named_field_class
, trace_class
);
1141 /* init_named_field_classes_container() logs errors */
1145 BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc
);
1149 BT_OBJECT_PUT_REF_AND_RESET(struct_fc
);
1152 return (void *) struct_fc
;
1156 int init_named_field_class(struct bt_named_field_class
*named_fc
,
1157 const char *name
, struct bt_field_class
*fc
)
1159 int status
= BT_FUNC_STATUS_OK
;
1161 BT_ASSERT(named_fc
);
1165 named_fc
->name
= g_string_new(name
);
1166 if (!named_fc
->name
) {
1167 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
1168 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1173 named_fc
->user_attributes
= bt_value_map_create();
1174 if (!named_fc
->user_attributes
) {
1175 BT_LIB_LOGE_APPEND_CAUSE(
1176 "Failed to create a map value object.");
1177 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1182 bt_object_get_ref_no_null_check(named_fc
->fc
);
1189 struct bt_named_field_class
*create_named_field_class(const char *name
,
1190 struct bt_field_class
*fc
)
1192 struct bt_named_field_class
*named_fc
= g_new0(
1193 struct bt_named_field_class
, 1);
1196 BT_LIB_LOGE_APPEND_CAUSE(
1197 "Failed to allocate a named field class.");
1201 if (init_named_field_class(named_fc
, name
, fc
)) {
1202 /* init_named_field_class() logs errors */
1209 destroy_named_field_class(named_fc
);
1217 struct bt_field_class_variant_with_selector_field_option
*
1218 create_variant_with_selector_field_option(
1219 const char *name
, struct bt_field_class
*fc
,
1220 const struct bt_integer_range_set
*range_set
)
1222 struct bt_field_class_variant_with_selector_field_option
*opt
= g_new0(
1223 struct bt_field_class_variant_with_selector_field_option
, 1);
1225 BT_ASSERT(range_set
);
1228 BT_LIB_LOGE_APPEND_CAUSE(
1229 "Failed to allocate a named field class.");
1233 if (init_named_field_class(&opt
->common
, name
, fc
)) {
1237 opt
->range_set
= range_set
;
1238 bt_object_get_ref_no_null_check(opt
->range_set
);
1239 bt_integer_range_set_freeze(range_set
);
1243 destroy_variant_with_selector_field_option(opt
);
1251 int append_named_field_class_to_container_field_class(
1252 struct bt_field_class_named_field_class_container
*container_fc
,
1253 struct bt_named_field_class
*named_fc
, const char *api_func
,
1254 const char *unique_entry_precond_id
)
1256 BT_ASSERT(container_fc
);
1257 BT_ASSERT(named_fc
);
1258 BT_ASSERT_PRE_DEV_FC_HOT_FROM_FUNC(api_func
, container_fc
);
1259 BT_ASSERT_PRE_FROM_FUNC(api_func
, unique_entry_precond_id
,
1261 !bt_g_hash_table_contains(container_fc
->name_to_index
,
1262 named_fc
->name
->str
),
1263 "Duplicate member/option name in structure/variant field class: "
1264 "%![container-fc-]+F, name=\"%s\"", container_fc
,
1265 named_fc
->name
->str
);
1268 * Freeze the contained field class, but not the named field
1269 * class itself, as it's still possible afterwards to modify
1270 * properties of the member/option object.
1272 bt_field_class_freeze(named_fc
->fc
);
1273 g_ptr_array_add(container_fc
->named_fcs
, named_fc
);
1275 if (named_fc
->name
) {
1277 * MIP > 0: a variant field class option may have no
1280 g_hash_table_insert(container_fc
->name_to_index
,
1281 named_fc
->name
->str
,
1282 GUINT_TO_POINTER(container_fc
->named_fcs
->len
- 1));
1285 return BT_FUNC_STATUS_OK
;
1289 enum bt_field_class_structure_append_member_status
1290 bt_field_class_structure_append_member(
1291 struct bt_field_class
*fc
, const char *name
,
1292 struct bt_field_class
*member_fc
)
1294 enum bt_field_class_structure_append_member_status status
;
1295 struct bt_named_field_class
*named_fc
= NULL
;
1297 BT_ASSERT_PRE_NO_ERROR();
1298 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1299 BT_ASSERT_PRE_NAME_NON_NULL(name
);
1300 BT_ASSERT_PRE_FC_IS_STRUCT("field-class", fc
, "Field class");
1301 named_fc
= create_named_field_class(name
, member_fc
);
1303 /* create_named_field_class() logs errors */
1304 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1308 status
= append_named_field_class_to_container_field_class((void *) fc
,
1310 "structure-field-class-member-name-is-unique");
1311 if (status
== BT_FUNC_STATUS_OK
) {
1312 /* Moved to the container */
1321 uint64_t bt_field_class_structure_get_member_count(
1322 const struct bt_field_class
*fc
)
1324 struct bt_field_class_structure
*struct_fc
= (void *) fc
;
1326 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1327 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1328 return (uint64_t) struct_fc
->common
.named_fcs
->len
;
1332 struct bt_named_field_class
*
1333 borrow_named_field_class_from_container_field_class_at_index(
1334 struct bt_field_class_named_field_class_container
*fc
,
1335 uint64_t index
, const char *api_func
)
1338 BT_ASSERT_PRE_DEV_VALID_INDEX_FROM_FUNC(api_func
, index
,
1339 fc
->named_fcs
->len
);
1340 return fc
->named_fcs
->pdata
[index
];
1344 const struct bt_field_class_structure_member
*
1345 bt_field_class_structure_borrow_member_by_index_const(
1346 const struct bt_field_class
*fc
, uint64_t index
)
1348 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1349 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1350 return (const void *)
1351 borrow_named_field_class_from_container_field_class_at_index(
1352 (void *) fc
, index
, __func__
);
1356 struct bt_field_class_structure_member
*
1357 bt_field_class_structure_borrow_member_by_index(
1358 struct bt_field_class
*fc
, uint64_t index
)
1360 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1361 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1363 borrow_named_field_class_from_container_field_class_at_index(
1364 (void *) fc
, index
, __func__
);
1368 struct bt_named_field_class
*
1369 borrow_named_field_class_from_container_field_class_by_name(
1370 struct bt_field_class_named_field_class_container
*fc
,
1371 const char *name
, const char *api_func
)
1373 struct bt_named_field_class
*named_fc
= NULL
;
1378 BT_ASSERT_PRE_DEV_NAME_NON_NULL_FROM_FUNC(api_func
, name
);
1379 if (!g_hash_table_lookup_extended(fc
->name_to_index
, name
, &orig_key
,
1384 named_fc
= fc
->named_fcs
->pdata
[GPOINTER_TO_UINT(value
)];
1391 const struct bt_field_class_structure_member
*
1392 bt_field_class_structure_borrow_member_by_name_const(
1393 const struct bt_field_class
*fc
, const char *name
)
1395 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1396 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1397 return (const void *)
1398 borrow_named_field_class_from_container_field_class_by_name(
1399 (void *) fc
, name
, __func__
);
1403 struct bt_field_class_structure_member
*
1404 bt_field_class_structure_borrow_member_by_name(
1405 struct bt_field_class
*fc
, const char *name
)
1407 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
1408 BT_ASSERT_PRE_DEV_FC_IS_STRUCT("field-class", fc
, "Field class");
1410 borrow_named_field_class_from_container_field_class_by_name(
1411 (void *) fc
, name
, __func__
);
1415 const char *bt_field_class_structure_member_get_name(
1416 const struct bt_field_class_structure_member
*member
)
1418 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1420 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1421 BT_ASSERT_DBG(named_fc
->name
);
1422 return named_fc
->name
->str
;
1426 const struct bt_field_class
*
1427 bt_field_class_structure_member_borrow_field_class_const(
1428 const struct bt_field_class_structure_member
*member
)
1430 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1432 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1433 return named_fc
->fc
;
1437 struct bt_field_class
*
1438 bt_field_class_structure_member_borrow_field_class(
1439 struct bt_field_class_structure_member
*member
)
1441 struct bt_named_field_class
*named_fc
= (void *) member
;
1443 BT_ASSERT_PRE_DEV_STRUCT_FC_MEMBER_NON_NULL(member
);
1444 return named_fc
->fc
;
1448 void destroy_option_field_class(struct bt_object
*obj
)
1450 struct bt_field_class_option
*fc
= (void *) obj
;
1453 BT_LIB_LOGD("Destroying option field class object: %!+F", fc
);
1454 finalize_field_class((void *) obj
);
1455 BT_LOGD_STR("Putting content field class.");
1456 BT_OBJECT_PUT_REF_AND_RESET(fc
->content_fc
);
1458 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1459 struct bt_field_class_option_with_selector_field
*with_sel_fc
=
1462 switch (with_sel_fc
->selector_field_xref_kind
) {
1463 case FIELD_XREF_KIND_PATH
:
1464 BT_LOGD_STR("Putting selector field path.");
1465 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field
.path
.path
);
1466 BT_LOGD_STR("Putting selector field class.");
1467 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field
.path
.class);
1469 case FIELD_XREF_KIND_LOCATION
:
1470 BT_LOGD_STR("Putting selector field location.");
1471 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field
.location
);
1475 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1476 struct bt_field_class_option_with_selector_field_integer
*with_int_sel_fc
=
1479 BT_LOGD_STR("Putting integer range set.");
1480 BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc
->range_set
);
1488 struct bt_field_class
*create_option_field_class(
1489 struct bt_trace_class
*trace_class
,
1490 enum bt_field_class_type fc_type
,
1491 struct bt_field_class
*content_fc
,
1492 struct bt_field_class
*selector_fc
,
1493 const struct bt_field_location
*selector_fl
,
1494 const char *api_func
)
1496 struct bt_field_class_option
*opt_fc
= NULL
;
1498 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "content-field-class",
1499 content_fc
, "Content field class");
1501 BT_ASSERT(!(selector_fc
&& selector_fl
));
1503 BT_LIB_LOGD("Creating option field class: "
1504 "type=%s, %![content-fc-]+F, %![sel-fc-]+F",
1505 bt_common_field_class_type_string(fc_type
),
1506 content_fc
, selector_fc
);
1508 if (fc_type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1509 struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
= NULL
;
1511 BT_ASSERT(selector_fc
|| selector_fl
);
1513 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1514 opt_with_sel_fc
= (void *) g_new0(
1515 struct bt_field_class_option_with_selector_field_bool
, 1);
1517 opt_with_sel_fc
= (void *) g_new0(
1518 struct bt_field_class_option_with_selector_field_integer
, 1);
1521 if (!opt_with_sel_fc
) {
1522 BT_LIB_LOGE_APPEND_CAUSE(
1523 "Failed to allocate one option with selector field class.");
1528 opt_with_sel_fc
->selector_field_xref_kind
= FIELD_XREF_KIND_PATH
;
1529 opt_with_sel_fc
->selector_field
.path
.class = selector_fc
;
1530 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_field
.path
.class);
1532 opt_with_sel_fc
->selector_field_xref_kind
= FIELD_XREF_KIND_LOCATION
;
1533 opt_with_sel_fc
->selector_field
.location
= selector_fl
;
1534 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_field
.location
);
1537 opt_fc
= (void *) opt_with_sel_fc
;
1539 BT_ASSERT(!selector_fc
);
1540 BT_ASSERT(!selector_fl
);
1542 opt_fc
= g_new0(struct bt_field_class_option
, 1);
1544 BT_LIB_LOGE_APPEND_CAUSE(
1545 "Failed to allocate one option field class.");
1552 if (init_field_class((void *) opt_fc
, fc_type
,
1553 destroy_option_field_class
, trace_class
)) {
1557 opt_fc
->content_fc
= content_fc
;
1558 bt_object_get_ref_no_null_check(opt_fc
->content_fc
);
1559 bt_field_class_freeze(opt_fc
->content_fc
);
1562 bt_field_class_freeze(selector_fc
);
1568 BT_OBJECT_PUT_REF_AND_RESET(opt_fc
);
1571 return (void *) opt_fc
;
1575 struct bt_field_class
*bt_field_class_option_without_selector_create(
1576 struct bt_trace_class
*trace_class
,
1577 struct bt_field_class
*content_fc
)
1579 struct bt_field_class
*fc
;
1581 BT_ASSERT_PRE_NO_ERROR();
1582 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1583 BT_ASSERT_PRE_TC_MIP_VERSION_EQ(trace_class
, 0);
1585 fc
= create_option_field_class(trace_class
,
1586 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1587 content_fc
, NULL
, NULL
, __func__
);
1589 BT_LIB_LOGD("Created option field class without selector field class: "
1590 "%![opt-fc-]+F", fc
);
1596 struct bt_field_class
*bt_field_class_option_without_selector_field_location_create(
1597 struct bt_trace_class
*trace_class
,
1598 struct bt_field_class
*content_fc
)
1600 struct bt_field_class
*fc
;
1602 BT_ASSERT_PRE_NO_ERROR();
1603 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1604 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
1606 fc
= create_option_field_class(trace_class
,
1607 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1608 content_fc
, NULL
, NULL
, __func__
);
1610 BT_LIB_LOGD("Created option field class without selector field location: "
1611 "%![opt-fc-]+F", fc
);
1617 struct bt_field_class
*bt_field_class_option_with_selector_field_bool_create(
1618 struct bt_trace_class
*trace_class
,
1619 struct bt_field_class
*content_fc
,
1620 struct bt_field_class
*selector_fc
)
1622 struct bt_field_class
*fc
;
1624 BT_ASSERT_PRE_NO_ERROR();
1625 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1626 BT_ASSERT_PRE_TC_MIP_VERSION_EQ(trace_class
, 0);
1627 BT_ASSERT_PRE_SELECTOR_FC_NON_NULL(selector_fc
);
1628 BT_ASSERT_PRE_FC_HAS_TYPE("selector-field-class", selector_fc
,
1629 "boolean-field-class", BT_FIELD_CLASS_TYPE_BOOL
,
1630 "Selector field class");
1632 fc
= create_option_field_class(trace_class
,
1633 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1634 content_fc
, selector_fc
, NULL
, __func__
);
1636 BT_LIB_LOGD("Created option field class with boolean selector field class: "
1637 "%![opt-fc-]+F, %![sel-fc-]+F", fc
, selector_fc
);
1643 struct bt_field_class
*bt_field_class_option_with_selector_field_location_bool_create(
1644 struct bt_trace_class
*trace_class
,
1645 struct bt_field_class
*content_fc
,
1646 const struct bt_field_location
*selector_fl
)
1648 struct bt_field_class
*fc
;
1650 BT_ASSERT_PRE_NO_ERROR();
1651 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1652 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
1653 BT_ASSERT_PRE_SELECTOR_FL_NON_NULL(selector_fl
);
1655 fc
= create_option_field_class(trace_class
,
1656 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1657 content_fc
, NULL
, selector_fl
, __func__
);
1659 BT_LIB_LOGD("Created option field class with boolean selector field location: "
1660 "%![opt-fc-]+F, %![sel-fl-]+L", fc
, selector_fl
);
1666 struct bt_field_class
*
1667 bt_field_class_option_with_selector_field_integer_unsigned_create(
1668 struct bt_trace_class
*trace_class
,
1669 struct bt_field_class
*content_fc
,
1670 struct bt_field_class
*selector_fc
,
1671 const struct bt_integer_range_set_unsigned
*u_range_set
)
1673 struct bt_field_class_option_with_selector_field_integer
*fc
;
1674 const struct bt_integer_range_set
*range_set
=
1675 (const void *) u_range_set
;
1677 BT_ASSERT_PRE_NO_ERROR();
1678 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1679 BT_ASSERT_PRE_TC_MIP_VERSION_EQ(trace_class
, 0);
1680 BT_ASSERT_PRE_SELECTOR_FC_NON_NULL(selector_fc
);
1681 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT("selector-field-class",
1682 selector_fc
, "Selector field class");
1683 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1684 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1686 fc
= (void *) create_option_field_class(trace_class
,
1687 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1688 content_fc
, selector_fc
, NULL
, __func__
);
1693 fc
->range_set
= range_set
;
1694 bt_object_get_ref_no_null_check(fc
->range_set
);
1695 bt_integer_range_set_freeze(range_set
);
1697 BT_LIB_LOGD("Created option field class with unsigned integer selector field class: "
1698 "%![opt-fc-]+F, %![sel-fc-]+F", fc
, selector_fc
);
1705 struct bt_field_class
*
1706 bt_field_class_option_with_selector_field_location_integer_unsigned_create(
1707 struct bt_trace_class
*trace_class
,
1708 struct bt_field_class
*content_fc
,
1709 const struct bt_field_location
*selector_fl
,
1710 const struct bt_integer_range_set_unsigned
*u_range_set
)
1712 struct bt_field_class_option_with_selector_field_integer
*fc
;
1713 const struct bt_integer_range_set
*range_set
=
1714 (const void *) u_range_set
;
1716 BT_ASSERT_PRE_NO_ERROR();
1717 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1718 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
1719 BT_ASSERT_PRE_SELECTOR_FL_NON_NULL(selector_fl
);
1720 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1721 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1723 fc
= (void *) create_option_field_class(trace_class
,
1724 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1725 content_fc
, NULL
, selector_fl
, __func__
);
1730 fc
->range_set
= range_set
;
1731 bt_object_get_ref_no_null_check(fc
->range_set
);
1732 bt_integer_range_set_freeze(range_set
);
1734 BT_LIB_LOGD("Created option field class with unsigned integer selector field location: "
1735 "%![opt-fc-]+F, %![sel-fl-]+L", fc
, selector_fl
);
1742 struct bt_field_class
*
1743 bt_field_class_option_with_selector_field_integer_signed_create(
1744 struct bt_trace_class
*trace_class
,
1745 struct bt_field_class
*content_fc
,
1746 struct bt_field_class
*selector_fc
,
1747 const struct bt_integer_range_set_signed
*i_range_set
)
1749 struct bt_field_class_option_with_selector_field_integer
*fc
;
1750 const struct bt_integer_range_set
*range_set
=
1751 (const void *) i_range_set
;
1753 BT_ASSERT_PRE_NO_ERROR();
1754 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1755 BT_ASSERT_PRE_TC_MIP_VERSION_EQ(trace_class
, 0);
1756 BT_ASSERT_PRE_SELECTOR_FC_NON_NULL(selector_fc
);
1757 BT_ASSERT_PRE_FC_IS_SIGNED_INT("selector-field-class",
1758 selector_fc
, "Selector field class");
1759 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1760 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1762 fc
= (void *) create_option_field_class(trace_class
,
1763 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1764 content_fc
, selector_fc
, NULL
, __func__
);
1769 fc
->range_set
= range_set
;
1770 bt_object_get_ref_no_null_check(fc
->range_set
);
1771 bt_integer_range_set_freeze(range_set
);
1773 BT_LIB_LOGD("Created option field class with signed integer selector field class: "
1774 "%![opt-fc-]+F, %![sel-fc-]+F", fc
, selector_fc
);
1781 struct bt_field_class
*
1782 bt_field_class_option_with_selector_field_location_integer_signed_create(
1783 struct bt_trace_class
*trace_class
,
1784 struct bt_field_class
*content_fc
,
1785 const struct bt_field_location
*selector_fl
,
1786 const struct bt_integer_range_set_signed
*i_range_set
)
1788 struct bt_field_class_option_with_selector_field_integer
*fc
;
1789 const struct bt_integer_range_set
*range_set
=
1790 (const void *) i_range_set
;
1792 BT_ASSERT_PRE_NO_ERROR();
1793 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
1794 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
1795 BT_ASSERT_PRE_SELECTOR_FL_NON_NULL(selector_fl
);
1796 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL(range_set
);
1797 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY(range_set
);
1799 fc
= (void *) create_option_field_class(trace_class
,
1800 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1801 content_fc
, NULL
, selector_fl
, __func__
);
1806 fc
->range_set
= range_set
;
1807 bt_object_get_ref_no_null_check(fc
->range_set
);
1808 bt_integer_range_set_freeze(range_set
);
1810 BT_LIB_LOGD("Created option field class with signed integer selector field location: "
1811 "%![opt-fc-]+F, %![sel-fl-]+L", fc
, selector_fl
);
1818 const struct bt_field_class
*bt_field_class_option_borrow_field_class_const(
1819 const struct bt_field_class
*fc
)
1821 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1823 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1824 BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc
, "Field class");
1825 return opt_fc
->content_fc
;
1829 struct bt_field_class
*bt_field_class_option_borrow_field_class(
1830 struct bt_field_class
*fc
)
1832 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1834 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1835 BT_ASSERT_PRE_FC_IS_OPTION("field-class", fc
, "Field class");
1836 return opt_fc
->content_fc
;
1840 const struct bt_field_path
*
1841 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1842 const struct bt_field_class
*fc
)
1844 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1847 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1848 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL("field-class", fc
, "Field class");
1849 BT_ASSERT_PRE_FC_MIP_VERSION_EQ(fc
, 0);
1850 BT_ASSERT_DBG(opt_fc
->selector_field_xref_kind
== FIELD_XREF_KIND_PATH
);
1851 return opt_fc
->selector_field
.path
.path
;
1855 const struct bt_field_location
*
1856 bt_field_class_option_with_selector_field_borrow_selector_field_location_const(
1857 const struct bt_field_class
*fc
)
1859 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1862 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1863 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL("field-class", fc
, "Field class");
1864 BT_ASSERT_PRE_FC_MIP_VERSION_GE(fc
, 1);
1865 BT_ASSERT_DBG(opt_fc
->selector_field_xref_kind
== FIELD_XREF_KIND_LOCATION
);
1866 return opt_fc
->selector_field
.location
;
1870 void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
1871 struct bt_field_class
*fc
, bt_bool sel_is_reversed
)
1873 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1875 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1876 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1877 "option-field-class-with-boolean-selector-field",
1878 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1880 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
1881 opt_fc
->sel_is_reversed
= sel_is_reversed
;
1885 bt_bool
bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1886 const struct bt_field_class
*fc
)
1888 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1890 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1891 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
1892 "option-field-class-with-boolean-selector-field",
1893 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1895 return opt_fc
->sel_is_reversed
;
1899 const struct bt_integer_range_set_unsigned
*
1900 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1901 const struct bt_field_class
*fc
)
1903 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1906 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1907 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc
,
1909 return (const void *) opt_fc
->range_set
;
1913 const struct bt_integer_range_set_signed
*
1914 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1915 const struct bt_field_class
*fc
)
1917 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1920 BT_ASSERT_PRE_FC_NON_NULL(fc
);
1921 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL("field-class", fc
,
1923 return (const void *) opt_fc
->range_set
;
1927 void finalize_variant_field_class(struct bt_field_class_variant
*var_fc
)
1930 BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc
);
1931 finalize_field_class((void *) var_fc
);
1932 finalize_named_field_classes_container((void *) var_fc
);
1936 void destroy_variant_field_class(struct bt_object
*obj
)
1938 struct bt_field_class_variant
*fc
= (void *) obj
;
1941 finalize_variant_field_class(fc
);
1946 void destroy_variant_with_selector_field_field_class(struct bt_object
*obj
)
1948 struct bt_field_class_variant_with_selector_field
*fc
= (void *) obj
;
1951 finalize_variant_field_class(&fc
->common
);
1953 if (fc
->selector_field_xref_kind
== FIELD_XREF_KIND_PATH
) {
1954 BT_LOGD_STR("Putting selector field path.");
1955 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field
.path
.path
);
1956 BT_LOGD_STR("Putting selector field class.");
1957 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field
.path
.class);
1959 BT_ASSERT(fc
->selector_field_xref_kind
== FIELD_XREF_KIND_LOCATION
);
1960 BT_LOGD_STR("Putting selector field location.");
1961 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field
.location
);
1968 struct bt_field_class
*create_variant_field_class(
1969 struct bt_trace_class
*trace_class
,
1970 enum bt_field_class_type fc_type
,
1971 struct bt_field_class
*selector_fc
,
1972 const struct bt_field_location
*selector_fl
)
1975 struct bt_field_class_variant
*var_fc
= NULL
;
1976 struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
= NULL
;
1978 if (fc_type
!= BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
) {
1979 BT_ASSERT((selector_fc
&& !selector_fl
) ||
1980 (!selector_fc
&& selector_fl
));
1984 BT_LIB_LOGD("Creating default variant field class with selector field class: %![sel-fc-]+F",
1987 BT_LIB_LOGD("Creating default variant field class with selector field location: %![sel-fl-]+L",
1991 var_with_sel_fc
= g_new0(
1992 struct bt_field_class_variant_with_selector_field
, 1);
1993 if (!var_with_sel_fc
) {
1994 BT_LIB_LOGE_APPEND_CAUSE(
1995 "Failed to allocate one variant field class with selector.");
1999 ret
= init_named_field_classes_container(
2000 (void *) var_with_sel_fc
, fc_type
,
2001 destroy_variant_with_selector_field_field_class
,
2002 destroy_variant_with_selector_field_option
,
2005 /* init_named_field_classes_container() logs errors */
2010 var_with_sel_fc
->selector_field_xref_kind
= FIELD_XREF_KIND_PATH
;
2011 var_with_sel_fc
->selector_field
.path
.class = selector_fc
;
2012 bt_object_get_ref_no_null_check(selector_fc
);
2013 bt_field_class_freeze(selector_fc
);
2015 BT_LIB_LOGD("Created default variant field class with selector field class: "
2016 "%![var-fc-]+F, %![sel-fc-]+F", var_with_sel_fc
, selector_fc
);
2018 var_with_sel_fc
->selector_field_xref_kind
= FIELD_XREF_KIND_LOCATION
;
2019 var_with_sel_fc
->selector_field
.location
= selector_fl
;
2020 bt_object_get_ref_no_null_check(var_with_sel_fc
->selector_field
.location
);
2022 BT_LIB_LOGD("Created default variant field class with selector field location: "
2023 "%![var-fc-]+F, %![sel-fl-]+L", var_fc
, selector_fl
);
2026 var_fc
= (void *) var_with_sel_fc
;
2028 BT_LIB_LOGD("Creating default variant field class without selector.");
2030 var_fc
= g_new0(struct bt_field_class_variant
, 1);
2032 BT_LIB_LOGE_APPEND_CAUSE(
2033 "Failed to allocate one variant field class without selector.");
2037 ret
= init_named_field_classes_container((void *) var_fc
, fc_type
,
2038 destroy_variant_field_class
, destroy_named_field_class
,
2041 /* init_named_field_classes_container() logs errors */
2044 BT_LIB_LOGD("Created default variant field class without selector object: "
2045 "%![var-fc-]+F", var_fc
);
2052 BT_OBJECT_PUT_REF_AND_RESET(var_fc
);
2053 BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc
);
2056 return (void *) var_fc
;
2060 struct bt_field_class
*bt_field_class_variant_create(
2061 struct bt_trace_class
*trace_class
,
2062 struct bt_field_class
*selector_fc
)
2064 enum bt_field_class_type fc_type
;
2066 BT_ASSERT_PRE_NO_ERROR();
2067 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2068 BT_ASSERT_PRE_TC_MIP_VERSION_EQ(trace_class
, 0);
2071 bt_field_class_type selector_fc_type
;
2073 BT_ASSERT_PRE_FC_IS_INT("selector-field-class", selector_fc
,
2074 "Selector field class");
2076 selector_fc_type
= bt_field_class_get_type(selector_fc
);
2078 if (bt_field_class_type_is(selector_fc_type
,
2079 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
)) {
2080 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
;
2082 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
;
2085 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
;
2088 return create_variant_field_class(trace_class
, fc_type
, selector_fc
, NULL
);
2092 struct bt_field_class
*bt_field_class_variant_without_selector_field_location_create(
2093 struct bt_trace_class
*trace_class
)
2095 BT_ASSERT_PRE_NO_ERROR();
2096 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2097 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
2099 return create_variant_field_class(trace_class
,
2100 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
, NULL
, NULL
);
2104 struct bt_field_class
*bt_field_class_variant_with_selector_field_location_integer_unsigned_create(
2105 struct bt_trace_class
*trace_class
,
2106 const struct bt_field_location
*selector_fl
)
2108 BT_ASSERT_PRE_NO_ERROR();
2109 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2110 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
2111 BT_ASSERT_PRE_SELECTOR_FL_NON_NULL(selector_fl
);
2113 return create_variant_field_class(trace_class
,
2114 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
2119 struct bt_field_class
*bt_field_class_variant_with_selector_field_location_integer_signed_create(
2120 struct bt_trace_class
*trace_class
,
2121 const struct bt_field_location
*selector_fl
)
2123 BT_ASSERT_PRE_NO_ERROR();
2124 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2125 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
2126 BT_ASSERT_PRE_SELECTOR_FL_NON_NULL(selector_fl
);
2128 return create_variant_field_class(trace_class
,
2129 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
2133 #define VAR_FC_OPT_NAME_IS_UNIQUE_ID \
2134 "variant-field-class-option-name-is-unique"
2137 enum bt_field_class_variant_without_selector_append_option_status
2138 bt_field_class_variant_without_selector_append_option(struct bt_field_class
*fc
,
2139 const char *name
, struct bt_field_class
*option_fc
)
2141 enum bt_field_class_variant_without_selector_append_option_status status
;
2142 struct bt_named_field_class
*named_fc
= NULL
;
2144 BT_ASSERT_PRE_NO_ERROR();
2145 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2147 /* Name is mandatory in MIP 0, optional later. */
2148 if (fc
->mip_version
== 0) {
2149 BT_ASSERT_PRE_NAME_NON_NULL(name
);
2152 BT_ASSERT_PRE_NON_NULL("option-field-class", option_fc
,
2153 "Option field class");
2154 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2155 "variant-field-class-without-selector-field",
2156 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
2158 named_fc
= create_named_field_class(name
, option_fc
);
2160 /* create_named_field_class() logs errors */
2161 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
2165 status
= append_named_field_class_to_container_field_class((void *) fc
,
2166 named_fc
, __func__
, VAR_FC_OPT_NAME_IS_UNIQUE_ID
);
2167 if (status
== BT_FUNC_STATUS_OK
) {
2168 /* Moved to the container */
2174 destroy_named_field_class(named_fc
);
2181 int ranges_overlap(GPtrArray
*var_fc_opts
, const struct bt_integer_range_set
*range_set
,
2182 bool is_signed
, bool *has_overlap
)
2184 int status
= BT_FUNC_STATUS_OK
;
2185 struct bt_integer_range_set
*full_range_set
;
2188 *has_overlap
= false;
2191 * Build a single range set with all the ranges and test for
2195 full_range_set
= (void *) bt_integer_range_set_signed_create();
2197 full_range_set
= (void *) bt_integer_range_set_unsigned_create();
2200 if (!full_range_set
) {
2201 BT_LOGE_STR("Failed to create a range set.");
2202 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
2206 /* Add existing option ranges */
2207 for (i
= 0; i
< var_fc_opts
->len
; i
++) {
2208 struct bt_field_class_variant_with_selector_field_option
*opt
=
2209 var_fc_opts
->pdata
[i
];
2212 for (j
= 0; j
< opt
->range_set
->ranges
->len
; j
++) {
2213 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
2217 status
= bt_integer_range_set_signed_add_range(
2218 (void *) full_range_set
, range
->lower
.i
,
2221 status
= bt_integer_range_set_unsigned_add_range(
2222 (void *) full_range_set
, range
->lower
.u
,
2232 /* Add new ranges */
2233 for (i
= 0; i
< range_set
->ranges
->len
; i
++) {
2234 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
2238 status
= bt_integer_range_set_signed_add_range(
2239 (void *) full_range_set
, range
->lower
.i
,
2242 status
= bt_integer_range_set_unsigned_add_range(
2243 (void *) full_range_set
, range
->lower
.u
,
2252 /* Check overlaps */
2254 *has_overlap
= bt_integer_range_set_signed_has_overlaps(full_range_set
);
2256 *has_overlap
= bt_integer_range_set_unsigned_has_overlaps(
2261 bt_object_put_ref(full_range_set
);
2266 int append_option_to_variant_with_selector_field_field_class(
2267 struct bt_field_class
*fc
, const char *name
,
2268 struct bt_field_class
*option_fc
,
2269 const struct bt_integer_range_set
*range_set
,
2270 enum bt_field_class_type expected_type
,
2271 const char *api_func
)
2274 struct bt_field_class_variant_with_selector_field
*var_fc
= (void *) fc
;
2275 struct bt_field_class_variant_with_selector_field_option
*opt
= NULL
;
2280 /* Name is mandatory in MIP 0, optional later. */
2281 if (fc
->mip_version
== 0) {
2282 BT_ASSERT_PRE_NAME_NON_NULL_FROM_FUNC(api_func
, name
);
2285 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "option-field-class",
2286 option_fc
, "Option field class");
2287 BT_ASSERT_PRE_INT_RANGE_SET_NON_NULL_FROM_FUNC(api_func
, range_set
);
2288 BT_ASSERT_PRE_INT_RANGE_SET_NOT_EMPTY_FROM_FUNC(api_func
, range_set
);
2289 status
= ranges_overlap(var_fc
->common
.common
.named_fcs
, range_set
,
2290 expected_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
2293 /* ranges_overlap() logs errors */
2297 BT_ASSERT_PRE_FROM_FUNC(api_func
, "ranges-do-not-overlap",
2299 "Integer range set's ranges and existing ranges have an overlap: "
2301 opt
= create_variant_with_selector_field_option(name
, option_fc
, range_set
);
2303 /* create_variant_with_selector_field_option() logs errors */
2304 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
2308 status
= append_named_field_class_to_container_field_class((void *) fc
,
2309 &opt
->common
, __func__
, VAR_FC_OPT_NAME_IS_UNIQUE_ID
);
2310 if (status
== BT_FUNC_STATUS_OK
) {
2311 /* Moved to the container */
2317 destroy_variant_with_selector_field_option(opt
);
2324 enum bt_field_class_variant_with_selector_field_integer_append_option_status
2325 bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
2326 struct bt_field_class
*fc
, const char *name
,
2327 struct bt_field_class
*option_fc
,
2328 const struct bt_integer_range_set_unsigned
*range_set
)
2330 BT_ASSERT_PRE_NO_ERROR();
2331 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2332 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2333 "variant-field-class-with-unsigned-integer-selector-field",
2334 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
2336 return append_option_to_variant_with_selector_field_field_class(fc
,
2337 name
, option_fc
, (const void *) range_set
,
2338 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
2343 enum bt_field_class_variant_with_selector_field_integer_append_option_status
2344 bt_field_class_variant_with_selector_field_integer_signed_append_option(
2345 struct bt_field_class
*fc
, const char *name
,
2346 struct bt_field_class
*option_fc
,
2347 const struct bt_integer_range_set_signed
*range_set
)
2349 BT_ASSERT_PRE_NO_ERROR();
2350 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2351 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2352 "variant-field-class-with-signed-integer-selector-field",
2353 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
2355 return append_option_to_variant_with_selector_field_field_class(fc
,
2356 name
, option_fc
, (const void *) range_set
,
2357 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
2362 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class
*fc
)
2364 const struct bt_field_class_variant
*var_fc
= (const void *) fc
;
2366 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2367 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
2368 return (uint64_t) var_fc
->common
.named_fcs
->len
;
2372 const struct bt_field_class_variant_option
*
2373 bt_field_class_variant_borrow_option_by_name_const(
2374 const struct bt_field_class
*fc
, const char *name
)
2376 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2377 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
2378 return (const void *)
2379 borrow_named_field_class_from_container_field_class_by_name(
2380 (void *) fc
, name
, __func__
);
2384 const struct bt_field_class_variant_option
*
2385 bt_field_class_variant_borrow_option_by_index_const(
2386 const struct bt_field_class
*fc
, uint64_t index
)
2388 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2389 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
2390 return (const void *)
2391 borrow_named_field_class_from_container_field_class_at_index(
2392 (void *) fc
, index
, __func__
);
2396 struct bt_field_class_variant_option
*
2397 bt_field_class_variant_borrow_option_by_name(
2398 struct bt_field_class
*fc
, const char *name
)
2400 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2401 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
2403 borrow_named_field_class_from_container_field_class_by_name(
2404 (void *) fc
, name
, __func__
);
2408 struct bt_field_class_variant_option
*
2409 bt_field_class_variant_borrow_option_by_index(
2410 struct bt_field_class
*fc
, uint64_t index
)
2412 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2413 BT_ASSERT_PRE_DEV_FC_IS_VARIANT("field-class", fc
, "Field class");
2415 borrow_named_field_class_from_container_field_class_at_index(
2416 (void *) fc
, index
, __func__
);
2420 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
2421 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
2422 const struct bt_field_class
*fc
, const char *name
)
2424 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2425 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2426 "variant-field-class-with-unsigned-integer-selector-field",
2427 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
2429 return (const void *)
2430 borrow_named_field_class_from_container_field_class_by_name(
2431 (void *) fc
, name
, __func__
);
2435 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
2436 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
2437 const struct bt_field_class
*fc
, uint64_t index
)
2439 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2440 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2441 "variant-field-class-with-unsigned-integer-selector-field",
2442 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
2444 return (const void *)
2445 borrow_named_field_class_from_container_field_class_at_index(
2446 (void *) fc
, index
, __func__
);
2450 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
2451 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
2452 const struct bt_field_class
*fc
, const char *name
)
2454 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2455 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2456 "variant-field-class-with-signed-integer-selector-field",
2457 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
2459 return (const void *)
2460 borrow_named_field_class_from_container_field_class_by_name(
2461 (void *) fc
, name
, __func__
);
2465 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
2466 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
2467 const struct bt_field_class
*fc
, uint64_t index
)
2469 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2470 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2471 "variant-field-class-with-signed-integer-selector-field",
2472 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
2474 return (const void *)
2475 borrow_named_field_class_from_container_field_class_at_index(
2476 (void *) fc
, index
, __func__
);
2480 const char *bt_field_class_variant_option_get_name(
2481 const struct bt_field_class_variant_option
*option
)
2483 const struct bt_named_field_class
*named_fc
= (const void *) option
;
2485 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
2487 /* MIP > 0: a variant field class option may have no name */
2488 return named_fc
->name
? named_fc
->name
->str
: NULL
;
2492 const struct bt_field_class
*
2493 bt_field_class_variant_option_borrow_field_class_const(
2494 const struct bt_field_class_variant_option
*option
)
2496 const struct bt_named_field_class
*named_fc
= (const void *) option
;
2498 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
2499 return named_fc
->fc
;
2503 struct bt_field_class
*
2504 bt_field_class_variant_option_borrow_field_class(
2505 struct bt_field_class_variant_option
*option
)
2507 struct bt_named_field_class
*named_fc
= (void *) option
;
2509 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
2510 return named_fc
->fc
;
2514 const struct bt_integer_range_set_unsigned
*
2515 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
2516 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*option
)
2518 const struct bt_field_class_variant_with_selector_field_option
*opt
=
2519 (const void *) option
;
2521 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
2522 return (const void *) opt
->range_set
;
2526 const struct bt_integer_range_set_signed
*
2527 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
2528 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*option
)
2530 const struct bt_field_class_variant_with_selector_field_option
*opt
=
2531 (const void *) option
;
2533 BT_ASSERT_PRE_DEV_VAR_FC_OPT_NON_NULL(option
);
2534 return (const void *) opt
->range_set
;
2538 const struct bt_field_path
*
2539 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
2540 const struct bt_field_class
*fc
)
2542 const struct bt_field_class_variant_with_selector_field
*var_fc
=
2545 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2546 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL("field-class", fc
,
2548 BT_ASSERT_PRE_FC_MIP_VERSION_EQ(fc
, 0);
2549 BT_ASSERT_DBG(var_fc
->selector_field_xref_kind
== FIELD_XREF_KIND_PATH
);
2550 return var_fc
->selector_field
.path
.path
;
2554 const struct bt_field_location
*
2555 bt_field_class_variant_with_selector_field_borrow_selector_field_location_const(
2556 const struct bt_field_class
*fc
)
2558 const struct bt_field_class_variant_with_selector_field
*var_fc
=
2561 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2562 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL("field-class", fc
,
2564 BT_ASSERT_PRE_DEV_FC_MIP_VERSION_GE(fc
, 1);
2565 BT_ASSERT_DBG(var_fc
->selector_field_xref_kind
== FIELD_XREF_KIND_LOCATION
);
2566 return var_fc
->selector_field
.location
;
2570 int init_array_field_class(struct bt_field_class_array
*fc
,
2571 enum bt_field_class_type type
, bt_object_release_func release_func
,
2572 struct bt_field_class
*element_fc
,
2573 const struct bt_trace_class
*trace_class
)
2577 BT_ASSERT(element_fc
);
2578 ret
= init_field_class((void *) fc
, type
, release_func
,
2584 fc
->element_fc
= element_fc
;
2585 bt_object_get_ref_no_null_check(fc
->element_fc
);
2586 bt_field_class_freeze(element_fc
);
2593 void finalize_array_field_class(struct bt_field_class_array
*array_fc
)
2595 BT_ASSERT(array_fc
);
2596 BT_LOGD_STR("Putting element field class.");
2597 finalize_field_class((void *) array_fc
);
2598 BT_OBJECT_PUT_REF_AND_RESET(array_fc
->element_fc
);
2602 void destroy_static_array_field_class(struct bt_object
*obj
)
2605 BT_LIB_LOGD("Destroying static array field class object: %!+F", obj
);
2606 finalize_array_field_class((void *) obj
);
2611 struct bt_field_class
*
2612 bt_field_class_array_static_create(bt_trace_class
*trace_class
,
2613 struct bt_field_class
*element_fc
, uint64_t length
)
2615 struct bt_field_class_array_static
*array_fc
= NULL
;
2617 BT_ASSERT_PRE_NO_ERROR();
2618 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2619 BT_ASSERT_PRE_NON_NULL("element-field-class", element_fc
,
2620 "Element field class");
2621 BT_LOGD_STR("Creating default static array field class object.");
2622 array_fc
= g_new0(struct bt_field_class_array_static
, 1);
2624 BT_LIB_LOGE_APPEND_CAUSE(
2625 "Failed to allocate one static array field class.");
2629 if (init_array_field_class((void *) array_fc
,
2630 BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2631 destroy_static_array_field_class
, element_fc
,
2636 array_fc
->length
= length
;
2637 BT_LIB_LOGD("Created static array field class object: %!+F", array_fc
);
2641 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2644 return (void *) array_fc
;
2648 const struct bt_field_class
*
2649 bt_field_class_array_borrow_element_field_class_const(
2650 const struct bt_field_class
*fc
)
2652 const struct bt_field_class_array
*array_fc
= (const void *) fc
;
2654 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2655 BT_ASSERT_PRE_DEV_FC_IS_ARRAY("field-class", fc
, "Field class");
2656 return array_fc
->element_fc
;
2660 struct bt_field_class
*
2661 bt_field_class_array_borrow_element_field_class(struct bt_field_class
*fc
)
2663 struct bt_field_class_array
*array_fc
= (void *) fc
;
2665 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2666 BT_ASSERT_PRE_DEV_FC_IS_ARRAY("field-class", fc
, "Field class");
2667 return array_fc
->element_fc
;
2671 uint64_t bt_field_class_array_static_get_length(const struct bt_field_class
*fc
)
2673 const struct bt_field_class_array_static
*array_fc
= (const void *) fc
;
2675 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
2676 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
2677 "static-array-field-class", BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2679 return (uint64_t) array_fc
->length
;
2683 void destroy_dynamic_array_field_class(struct bt_object
*obj
)
2685 struct bt_field_class_array_dynamic
*fc
= (void *) obj
;
2688 BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc
);
2689 finalize_array_field_class((void *) fc
);
2691 if (fc
->common
.common
.type
== BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
) {
2692 switch (fc
->length_field
.xref_kind
) {
2693 case FIELD_XREF_KIND_PATH
:
2694 BT_LOGD_STR("Putting length field class.");
2695 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field
.path
.class);
2696 fc
->length_field
.path
.class = NULL
;
2698 BT_LOGD_STR("Putting length field path.");
2699 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field
.path
.path
);
2700 fc
->length_field
.path
.path
= NULL
;
2702 case FIELD_XREF_KIND_LOCATION
:
2703 BT_LOGD_STR("Putting length field location.");
2704 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field
.location
);
2705 fc
->length_field
.location
= NULL
;
2714 struct bt_field_class_array_dynamic
*create_dynamic_array_field_class(
2715 struct bt_trace_class
*trace_class
,
2716 struct bt_field_class
*element_fc
,
2717 enum bt_field_class_type fc_type
,
2718 const char *api_func
)
2720 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2722 BT_ASSERT_PRE_NON_NULL_FROM_FUNC(api_func
, "element-field-class", element_fc
,
2723 "Element field class");
2724 BT_LOGD_STR("Creating default dynamic array field class object.");
2725 array_fc
= g_new0(struct bt_field_class_array_dynamic
, 1);
2727 BT_LIB_LOGE_APPEND_CAUSE(
2728 "Failed to allocate one dynamic array field class.");
2732 if (init_array_field_class((void *) array_fc
, fc_type
,
2733 destroy_dynamic_array_field_class
, element_fc
,
2741 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2748 struct bt_field_class
*bt_field_class_array_dynamic_create(
2749 struct bt_trace_class
*trace_class
,
2750 struct bt_field_class
*element_fc
,
2751 struct bt_field_class
*length_fc
)
2753 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2756 BT_ASSERT_PRE_NO_ERROR();
2757 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2758 BT_ASSERT_PRE_TC_MIP_VERSION_EQ(trace_class
, 0);
2760 array_fc
= create_dynamic_array_field_class(trace_class
, element_fc
,
2762 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
2763 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2770 array_fc
->length_field
.xref_kind
= FIELD_XREF_KIND_PATH
;
2772 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT("length-field-class",
2773 length_fc
, "Length field class");
2774 array_fc
->length_field
.path
.class = length_fc
;
2775 bt_object_get_ref_no_null_check(length_fc
);
2776 bt_field_class_freeze(length_fc
);
2779 BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc
);
2784 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2787 return (void *) array_fc
;
2791 struct bt_field_class
*bt_field_class_array_dynamic_without_length_field_location_create(
2792 struct bt_trace_class
*trace_class
,
2793 struct bt_field_class
*element_field_class
)
2795 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2797 BT_ASSERT_PRE_NO_ERROR();
2798 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2799 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
2801 array_fc
= create_dynamic_array_field_class(trace_class
,
2802 element_field_class
, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2808 BT_LIB_LOGD("Created dynamic array field class without field location object: %!+F",
2814 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2817 return (void *) array_fc
;
2821 struct bt_field_class
*bt_field_class_array_dynamic_with_length_field_location_create(
2822 struct bt_trace_class
*trace_class
,
2823 struct bt_field_class
*element_field_class
,
2824 const struct bt_field_location
*length_field_location
)
2826 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2828 BT_ASSERT_PRE_NO_ERROR();
2829 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2830 BT_ASSERT_PRE_FL_NON_NULL(length_field_location
);
2831 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
2833 array_fc
= create_dynamic_array_field_class(trace_class
,
2834 element_field_class
, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2840 array_fc
->length_field
.xref_kind
= FIELD_XREF_KIND_LOCATION
;
2841 array_fc
->length_field
.location
= length_field_location
;
2842 bt_object_get_ref_no_null_check(length_field_location
);
2844 BT_LIB_LOGD("Created dynamic array field class with field location object: %!+F",
2850 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2853 return (void *) array_fc
;
2857 const struct bt_field_path
*
2858 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
2859 const struct bt_field_class
*fc
)
2861 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2863 BT_ASSERT_PRE_NO_ERROR();
2864 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2865 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2866 "dynamic-array-field-class-with-length-field",
2867 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2869 BT_ASSERT_PRE_FC_MIP_VERSION_EQ(fc
, 0);
2870 BT_ASSERT_DBG(seq_fc
->length_field
.xref_kind
== FIELD_XREF_KIND_PATH
);
2871 return seq_fc
->length_field
.path
.path
;
2875 const struct bt_field_location
*
2876 bt_field_class_array_dynamic_with_length_field_borrow_length_field_location_const(
2877 const struct bt_field_class
*fc
)
2879 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2881 BT_ASSERT_PRE_NO_ERROR();
2882 BT_ASSERT_PRE_FC_NON_NULL(fc
);
2883 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
2884 "dynamic-array-field-class-with-length-field",
2885 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2887 BT_ASSERT_PRE_FC_MIP_VERSION_GE(fc
, 1);
2888 BT_ASSERT_DBG(seq_fc
->length_field
.xref_kind
== FIELD_XREF_KIND_LOCATION
);
2889 return seq_fc
->length_field
.location
;
2893 void destroy_string_field_class(struct bt_object
*obj
)
2896 BT_LIB_LOGD("Destroying string field class object: %!+F", obj
);
2897 finalize_field_class((void *) obj
);
2902 struct bt_field_class
*bt_field_class_string_create(bt_trace_class
*trace_class
)
2904 struct bt_field_class_string
*string_fc
= NULL
;
2906 BT_ASSERT_PRE_NO_ERROR();
2907 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
2908 BT_LOGD_STR("Creating default string field class object.");
2909 string_fc
= g_new0(struct bt_field_class_string
, 1);
2911 BT_LIB_LOGE_APPEND_CAUSE(
2912 "Failed to allocate one string field class.");
2916 if (init_field_class((void *) string_fc
, BT_FIELD_CLASS_TYPE_STRING
,
2917 destroy_string_field_class
, trace_class
)) {
2921 BT_LIB_LOGD("Created string field class object: %!+F", string_fc
);
2925 BT_OBJECT_PUT_REF_AND_RESET(string_fc
);
2928 return (void *) string_fc
;
2931 void _bt_field_class_freeze(const struct bt_field_class
*c_fc
)
2933 struct bt_field_class
*fc
= (void *) c_fc
;
2936 * Element/member/option field classes are frozen when added to
2940 bt_value_freeze(fc
->user_attributes
);
2943 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2944 bt_field_class_type_is(fc
->type
,
2945 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2946 struct bt_field_class_named_field_class_container
*container_fc
=
2950 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2951 bt_named_field_class_freeze(
2952 container_fc
->named_fcs
->pdata
[i
]);
2957 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
)
2959 BT_ASSERT(named_fc
);
2960 BT_ASSERT(named_fc
->fc
->frozen
);
2961 BT_LIB_LOGD("Freezing named field class's user attributes: %!+v",
2962 named_fc
->user_attributes
);
2963 bt_value_freeze(named_fc
->user_attributes
);
2964 ((struct bt_named_field_class
*) named_fc
)->frozen
= true;
2967 void bt_field_class_make_part_of_trace_class(const struct bt_field_class
*c_fc
)
2969 struct bt_field_class
*fc
= (void *) c_fc
;
2972 BT_ASSERT_PRE("field-class-is-not-part-of-trace-class",
2973 !fc
->part_of_trace_class
,
2974 "Field class is already part of a trace class: %!+F", fc
);
2975 fc
->part_of_trace_class
= true;
2977 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2978 bt_field_class_type_is(fc
->type
,
2979 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2980 struct bt_field_class_named_field_class_container
*container_fc
=
2984 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2985 struct bt_named_field_class
*named_fc
=
2986 container_fc
->named_fcs
->pdata
[i
];
2988 bt_field_class_make_part_of_trace_class(named_fc
->fc
);
2990 } else if (bt_field_class_type_is(fc
->type
,
2991 BT_FIELD_CLASS_TYPE_ARRAY
)) {
2992 struct bt_field_class_array
*array_fc
= (void *) fc
;
2994 bt_field_class_make_part_of_trace_class(array_fc
->element_fc
);
2999 const struct bt_value
*bt_field_class_borrow_user_attributes_const(
3000 const struct bt_field_class
*fc
)
3002 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
3003 return fc
->user_attributes
;
3007 struct bt_value
*bt_field_class_borrow_user_attributes(
3008 struct bt_field_class
*field_class
)
3010 return (void *) bt_field_class_borrow_user_attributes_const(
3011 (void *) field_class
);
3016 void bt_field_class_set_user_attributes(
3017 struct bt_field_class
*fc
,
3018 const struct bt_value
*user_attributes
)
3020 BT_ASSERT_PRE_FC_NON_NULL(fc
);
3021 BT_ASSERT_PRE_USER_ATTRS_NON_NULL(user_attributes
);
3022 BT_ASSERT_PRE_USER_ATTRS_IS_MAP(user_attributes
);
3023 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
3024 bt_object_put_ref_no_null_check(fc
->user_attributes
);
3025 fc
->user_attributes
= (void *) user_attributes
;
3026 bt_object_get_ref_no_null_check(fc
->user_attributes
);
3030 const struct bt_value
*bt_named_field_class_borrow_user_attributes_const(
3031 const struct bt_named_field_class
*named_fc
)
3033 return named_fc
->user_attributes
;
3037 void set_named_field_class_user_attributes(
3038 struct bt_named_field_class
*named_fc
,
3039 const struct bt_value
*user_attributes
, const char *api_func
)
3041 BT_ASSERT_PRE_USER_ATTRS_NON_NULL_FROM_FUNC(api_func
, user_attributes
);
3042 BT_ASSERT_PRE_USER_ATTRS_NON_NULL_FROM_FUNC(api_func
, user_attributes
);
3043 bt_object_put_ref_no_null_check(named_fc
->user_attributes
);
3044 named_fc
->user_attributes
= (void *) user_attributes
;
3045 bt_object_get_ref_no_null_check(named_fc
->user_attributes
);
3049 const struct bt_value
*
3050 bt_field_class_structure_member_borrow_user_attributes_const(
3051 const struct bt_field_class_structure_member
*member
)
3053 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
3054 return bt_named_field_class_borrow_user_attributes_const(
3055 (const void *) member
);
3060 bt_field_class_structure_member_borrow_user_attributes(
3061 struct bt_field_class_structure_member
*member
)
3063 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
3064 return (void *) bt_named_field_class_borrow_user_attributes_const(
3069 void bt_field_class_structure_member_set_user_attributes(
3070 struct bt_field_class_structure_member
*member
,
3071 const struct bt_value
*user_attributes
)
3073 BT_ASSERT_PRE_STRUCT_FC_MEMBER_NON_NULL(member
);
3074 BT_ASSERT_PRE_DEV_HOT("structure-field-class-member",
3075 (struct bt_named_field_class
*) member
,
3076 "Structure field class member", ".");
3077 set_named_field_class_user_attributes((void *) member
,
3078 user_attributes
, __func__
);
3082 const struct bt_value
*bt_field_class_variant_option_borrow_user_attributes_const(
3083 const struct bt_field_class_variant_option
*option
)
3085 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
3086 return bt_named_field_class_borrow_user_attributes_const(
3087 (const void *) option
);
3091 struct bt_value
*bt_field_class_variant_option_borrow_user_attributes(
3092 struct bt_field_class_variant_option
*option
)
3094 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
3095 return (void *) bt_named_field_class_borrow_user_attributes_const(
3100 void bt_field_class_variant_option_set_user_attributes(
3101 struct bt_field_class_variant_option
*option
,
3102 const struct bt_value
*user_attributes
)
3104 BT_ASSERT_PRE_VAR_FC_OPT_NON_NULL(option
);
3105 BT_ASSERT_PRE_DEV_HOT("variant-field-class-option",
3106 (struct bt_named_field_class
*) option
,
3107 "Variant field class option", ".");
3108 set_named_field_class_user_attributes((void *) option
,
3109 user_attributes
, __func__
);
3113 bt_field_class_blob_set_media_type_status
bt_field_class_blob_set_media_type(
3114 struct bt_field_class
*fc
, const char *media_type
)
3116 struct bt_field_class_blob
*fc_blob
= (void *) fc
;
3118 BT_ASSERT_PRE_FC_NON_NULL(fc
);
3119 BT_ASSERT_PRE_FC_IS_BLOB("field-class", fc
, "Field class");
3120 BT_ASSERT_PRE_DEV_FC_HOT(fc
);
3121 BT_ASSERT_PRE_NON_NULL("media-type", media_type
, "Media type");
3123 g_string_assign(fc_blob
->media_type
, media_type
);
3125 return BT_FIELD_CLASS_BLOB_SET_MEDIA_TYPE_STATUS_OK
;
3129 const char *bt_field_class_blob_get_media_type(
3130 const bt_field_class
*fc
)
3132 struct bt_field_class_blob
*fc_blob
= (void *) fc
;
3134 BT_ASSERT_PRE_FC_NON_NULL(fc
);
3135 BT_ASSERT_PRE_FC_IS_BLOB("field-class", fc
, "Field class");
3137 return fc_blob
->media_type
->str
;
3141 int init_blob_field_class(struct bt_field_class_blob
*fc
,
3142 enum bt_field_class_type type
,
3143 bt_object_release_func release_func
,
3144 bt_trace_class
*trace_class
)
3148 ret
= init_field_class((void *) fc
, type
, release_func
,
3154 fc
->media_type
= g_string_new("application/octet-stream");
3161 void destroy_blob_field_class(struct bt_object
*obj
)
3163 struct bt_field_class_blob
*blob
= (void *) obj
;
3166 g_string_free(blob
->media_type
, TRUE
);
3167 finalize_field_class((void *) obj
);
3172 void destroy_static_blob_field_class(struct bt_object
*obj
)
3174 struct bt_field_class_blob_static
*fc
= (void *) obj
;
3177 BT_LIB_LOGD("Destroying static BLOB field class object: %!+F", fc
);
3179 destroy_blob_field_class(obj
);
3183 struct bt_field_class
*bt_field_class_blob_static_create(
3184 struct bt_trace_class
*trace_class
, uint64_t length
)
3186 struct bt_field_class_blob_static
*blob_fc
= NULL
;
3189 BT_ASSERT_PRE_NO_ERROR();
3190 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
3191 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
3193 BT_LOGD_STR("Creating default static BLOB field class object.");
3194 blob_fc
= g_new0(struct bt_field_class_blob_static
, 1);
3196 BT_LIB_LOGE_APPEND_CAUSE(
3197 "Failed to allocate one static BLOB field class.");
3201 ret
= init_blob_field_class((void *) blob_fc
,
3202 BT_FIELD_CLASS_TYPE_STATIC_BLOB
,
3203 destroy_static_blob_field_class
,
3209 blob_fc
->length
= length
;
3210 BT_LIB_LOGD("Created static BLOB field class object: %!+F", blob_fc
);
3214 BT_OBJECT_PUT_REF_AND_RESET(blob_fc
);
3217 return (void *) blob_fc
;
3221 uint64_t bt_field_class_blob_static_get_length(
3222 const bt_field_class
*fc
)
3224 const struct bt_field_class_blob_static
*blob_fc
= (const void *) fc
;
3226 BT_ASSERT_PRE_DEV_FC_NON_NULL(fc
);
3227 BT_ASSERT_PRE_DEV_FC_HAS_TYPE("field-class", fc
,
3228 "static-blob-field-class", BT_FIELD_CLASS_TYPE_STATIC_BLOB
,
3231 return blob_fc
->length
;
3235 void destroy_dynamic_blob_field_class(struct bt_object
*obj
)
3237 struct bt_field_class_blob_dynamic
*fc
= (void *) obj
;
3240 BT_LIB_LOGD("Destroying dynamic BLOB field class object: %!+F", fc
);
3242 bt_object_put_ref(fc
->length_fl
);
3243 fc
->length_fl
= NULL
;
3245 destroy_blob_field_class(obj
);
3249 struct bt_field_class_blob_dynamic
*create_dynamic_blob_field_class(
3250 struct bt_trace_class
*trace_class
, enum bt_field_class_type type
)
3252 struct bt_field_class_blob_dynamic
*blob_fc
= NULL
;
3255 BT_LOGD_STR("Creating default dynamic BLOB field class object.");
3256 blob_fc
= g_new0(struct bt_field_class_blob_dynamic
, 1);
3258 BT_LIB_LOGE_APPEND_CAUSE(
3259 "Failed to allocate one dynamic BLOB field class.");
3263 ret
= init_blob_field_class((void *) blob_fc
, type
,
3264 destroy_dynamic_blob_field_class
, trace_class
);
3272 BT_OBJECT_PUT_REF_AND_RESET(blob_fc
);
3279 struct bt_field_class
*bt_field_class_blob_dynamic_without_length_field_location_create(
3280 struct bt_trace_class
*trace_class
)
3282 struct bt_field_class_blob_dynamic
*blob_fc
= NULL
;
3284 BT_ASSERT_PRE_NO_ERROR();
3285 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
3286 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
3288 blob_fc
= create_dynamic_blob_field_class(trace_class
,
3289 BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITHOUT_LENGTH_FIELD
);
3294 BT_LIB_LOGD("Created dynamic BLOB field class without field location object: %!+F",
3300 BT_OBJECT_PUT_REF_AND_RESET(blob_fc
);
3303 return (void *) blob_fc
;
3307 struct bt_field_class
*bt_field_class_blob_dynamic_with_length_field_location_create(
3308 bt_trace_class
*trace_class
,
3309 const bt_field_location
*length_field_location
)
3311 struct bt_field_class_blob_dynamic
*blob_fc
= NULL
;
3313 BT_ASSERT_PRE_NO_ERROR();
3314 BT_ASSERT_PRE_TC_NON_NULL(trace_class
);
3315 BT_ASSERT_PRE_FL_NON_NULL(length_field_location
);
3316 BT_ASSERT_PRE_TC_MIP_VERSION_GE(trace_class
, 1);
3318 blob_fc
= create_dynamic_blob_field_class(trace_class
,
3319 BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD
);
3324 blob_fc
->length_fl
= length_field_location
;
3325 bt_object_get_ref_no_null_check(length_field_location
);
3327 BT_LIB_LOGD("Created dynamic BLOB field class with field location object: %!+F",
3333 BT_OBJECT_PUT_REF_AND_RESET(blob_fc
);
3336 return (void *) blob_fc
;
3340 const bt_field_location
*
3341 bt_field_class_blob_dynamic_with_length_field_borrow_length_field_location_const(
3342 const bt_field_class
*fc
)
3344 const struct bt_field_class_blob_dynamic
*blob_fc
= (const void *) fc
;
3346 BT_ASSERT_PRE_NO_ERROR();
3347 BT_ASSERT_PRE_FC_NON_NULL(fc
);
3348 BT_ASSERT_PRE_FC_HAS_TYPE("field-class", fc
,
3349 "dynamic-blob-field-class-with-length-field",
3350 BT_FIELD_CLASS_TYPE_DYNAMIC_BLOB_WITH_LENGTH_FIELD
,
3352 BT_ASSERT_PRE_FC_MIP_VERSION_GE(fc
, 1);
3353 BT_ASSERT(blob_fc
->length_fl
);
3355 return blob_fc
->length_fl
;
3359 void bt_field_class_get_ref(const struct bt_field_class
*field_class
)
3361 bt_object_get_ref(field_class
);
3365 void bt_field_class_put_ref(const struct bt_field_class
*field_class
)
3367 bt_object_put_ref(field_class
);