2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "LIB/FIELD-CLASS"
25 #include "lib/logging.h"
27 #include "lib/assert-pre.h"
28 #include <babeltrace2/trace-ir/field-class.h>
29 #include <babeltrace2/trace-ir/field-class-const.h>
30 #include <babeltrace2/trace-ir/field-const.h>
31 #include <babeltrace2/trace-ir/field.h>
32 #include <babeltrace2/trace-ir/clock-class.h>
33 #include "lib/object.h"
34 #include "compat/compiler.h"
35 #include "compat/endian.h"
36 #include "common/assert.h"
37 #include "compat/glib.h"
43 #include "clock-class.h"
44 #include "field-class.h"
46 #include "field-path.h"
48 #include "lib/func-status.h"
49 #include "lib/integer-range-set.h"
50 #include "lib/value.h"
52 enum bt_field_class_type
bt_field_class_get_type(
53 const struct bt_field_class
*fc
)
55 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
60 int init_field_class(struct bt_field_class
*fc
, enum bt_field_class_type type
,
61 bt_object_release_func release_func
)
66 BT_ASSERT(release_func
);
67 bt_object_init_shared(&fc
->base
, release_func
);
69 fc
->user_attributes
= bt_value_map_create();
70 if (!fc
->user_attributes
) {
71 BT_LIB_LOGE_APPEND_CAUSE(
72 "Failed to create a map value object.");
82 void finalize_field_class(struct bt_field_class
*fc
)
84 BT_OBJECT_PUT_REF_AND_RESET(fc
->user_attributes
);
88 void destroy_bit_array_field_class(struct bt_object
*obj
)
91 BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj
);
92 finalize_field_class((void *) obj
);
96 struct bt_field_class
*bt_field_class_bit_array_create(
97 struct bt_trace_class
*trace_class
, uint64_t length
)
99 struct bt_field_class_bit_array
*ba_fc
= NULL
;
101 BT_ASSERT_PRE_NO_ERROR();
102 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
103 BT_ASSERT_PRE(length
> 0 && length
<= 64,
104 "Unsupported length for bit array field class "
105 "(minimum is 1, maximum is 64): length=%" PRIu64
, length
);
106 BT_LOGD("Creating default bit array field class object.");
107 ba_fc
= g_new0(struct bt_field_class_bit_array
, 1);
109 BT_LIB_LOGE_APPEND_CAUSE(
110 "Failed to allocate one bit array field class.");
114 if (init_field_class((void *) ba_fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
115 destroy_bit_array_field_class
)) {
119 ba_fc
->length
= length
;
120 BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc
);
124 BT_OBJECT_PUT_REF_AND_RESET(ba_fc
);
127 return (void *) ba_fc
;
130 uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class
*fc
)
132 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
134 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
135 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
137 return ba_fc
->length
;
141 void destroy_bool_field_class(struct bt_object
*obj
)
144 BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj
);
145 finalize_field_class((void *) obj
);
149 struct bt_field_class
*bt_field_class_bool_create(
150 bt_trace_class
*trace_class
)
152 struct bt_field_class_bool
*bool_fc
= NULL
;
154 BT_ASSERT_PRE_NO_ERROR();
155 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
156 BT_LOGD("Creating default boolean field class object.");
157 bool_fc
= g_new0(struct bt_field_class_bool
, 1);
159 BT_LIB_LOGE_APPEND_CAUSE(
160 "Failed to allocate one boolean field class.");
164 if (init_field_class((void *) bool_fc
, BT_FIELD_CLASS_TYPE_BOOL
,
165 destroy_bool_field_class
)) {
169 BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc
);
173 BT_OBJECT_PUT_REF_AND_RESET(bool_fc
);
176 return (void *) bool_fc
;
180 int init_integer_field_class(struct bt_field_class_integer
*fc
,
181 enum bt_field_class_type type
,
182 bt_object_release_func release_func
)
186 ret
= init_field_class((void *) fc
, type
, release_func
);
192 fc
->base
= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
;
199 void destroy_integer_field_class(struct bt_object
*obj
)
202 BT_LIB_LOGD("Destroying integer field class object: %!+F", obj
);
203 finalize_field_class((void *) obj
);
208 struct bt_field_class
*create_integer_field_class(bt_trace_class
*trace_class
,
209 enum bt_field_class_type type
)
211 struct bt_field_class_integer
*int_fc
= NULL
;
213 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
214 BT_LOGD("Creating default integer field class object: type=%s",
215 bt_common_field_class_type_string(type
));
216 int_fc
= g_new0(struct bt_field_class_integer
, 1);
218 BT_LIB_LOGE_APPEND_CAUSE(
219 "Failed to allocate one integer field class.");
223 if (init_integer_field_class(int_fc
, type
,
224 destroy_integer_field_class
)) {
228 BT_LIB_LOGD("Created integer field class object: %!+F", int_fc
);
232 BT_OBJECT_PUT_REF_AND_RESET(int_fc
);
235 return (void *) int_fc
;
238 struct bt_field_class
*bt_field_class_integer_unsigned_create(
239 bt_trace_class
*trace_class
)
241 BT_ASSERT_PRE_NO_ERROR();
243 return create_integer_field_class(trace_class
,
244 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
247 struct bt_field_class
*bt_field_class_integer_signed_create(
248 bt_trace_class
*trace_class
)
250 BT_ASSERT_PRE_NO_ERROR();
252 return create_integer_field_class(trace_class
,
253 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
256 uint64_t bt_field_class_integer_get_field_value_range(
257 const struct bt_field_class
*fc
)
259 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
261 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
262 BT_ASSERT_PRE_DEV_FC_IS_INT(fc
, "Field class");
263 return int_fc
->range
;
267 bool size_is_valid_for_enumeration_field_class(struct bt_field_class
*fc
,
274 void bt_field_class_integer_set_field_value_range(
275 struct bt_field_class
*fc
, uint64_t size
)
277 struct bt_field_class_integer
*int_fc
= (void *) fc
;
279 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
280 BT_ASSERT_PRE_FC_IS_INT(fc
, "Field class");
281 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
282 BT_ASSERT_PRE(size
<= 64,
283 "Unsupported size for integer field class's field value range "
284 "(maximum is 64): size=%" PRIu64
, size
);
286 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
287 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
288 size_is_valid_for_enumeration_field_class(fc
, size
),
289 "Invalid field value range for enumeration field class: "
290 "at least one of the current mapping ranges contains values "
291 "which are outside this range: %!+F, size=%" PRIu64
, fc
, size
);
292 int_fc
->range
= size
;
293 BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc
);
296 enum bt_field_class_integer_preferred_display_base
297 bt_field_class_integer_get_preferred_display_base(const struct bt_field_class
*fc
)
299 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
301 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
302 BT_ASSERT_PRE_DEV_FC_IS_INT(fc
, "Field class");
306 void bt_field_class_integer_set_preferred_display_base(
307 struct bt_field_class
*fc
,
308 enum bt_field_class_integer_preferred_display_base base
)
310 struct bt_field_class_integer
*int_fc
= (void *) fc
;
312 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
313 BT_ASSERT_PRE_FC_IS_INT(fc
, "Field class");
314 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
316 BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc
);
320 void finalize_enumeration_field_class_mapping(
321 struct bt_field_class_enumeration_mapping
*mapping
)
325 if (mapping
->label
) {
326 g_string_free(mapping
->label
, TRUE
);
327 mapping
->label
= NULL
;
330 BT_OBJECT_PUT_REF_AND_RESET(mapping
->range_set
);
334 void destroy_enumeration_field_class(struct bt_object
*obj
)
336 struct bt_field_class_enumeration
*fc
= (void *) obj
;
339 BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc
);
340 finalize_field_class((void *) obj
);
345 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
346 finalize_enumeration_field_class_mapping(
347 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
));
350 g_array_free(fc
->mappings
, TRUE
);
355 g_ptr_array_free(fc
->label_buf
, TRUE
);
356 fc
->label_buf
= NULL
;
363 struct bt_field_class
*create_enumeration_field_class(
364 bt_trace_class
*trace_class
, enum bt_field_class_type type
)
366 struct bt_field_class_enumeration
*enum_fc
= NULL
;
368 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
369 BT_LOGD("Creating default enumeration field class object: type=%s",
370 bt_common_field_class_type_string(type
));
371 enum_fc
= g_new0(struct bt_field_class_enumeration
, 1);
373 BT_LIB_LOGE_APPEND_CAUSE(
374 "Failed to allocate one enumeration field class.");
378 if (init_integer_field_class((void *) enum_fc
, type
,
379 destroy_enumeration_field_class
)) {
383 enum_fc
->mappings
= g_array_new(FALSE
, TRUE
,
384 sizeof(struct bt_field_class_enumeration_mapping
));
385 if (!enum_fc
->mappings
) {
386 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
390 enum_fc
->label_buf
= g_ptr_array_new();
391 if (!enum_fc
->label_buf
) {
392 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
396 BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc
);
400 BT_OBJECT_PUT_REF_AND_RESET(enum_fc
);
403 return (void *) enum_fc
;
406 struct bt_field_class
*bt_field_class_enumeration_unsigned_create(
407 bt_trace_class
*trace_class
)
409 BT_ASSERT_PRE_NO_ERROR();
411 return create_enumeration_field_class(trace_class
,
412 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
415 struct bt_field_class
*bt_field_class_enumeration_signed_create(
416 bt_trace_class
*trace_class
)
418 BT_ASSERT_PRE_NO_ERROR();
420 return create_enumeration_field_class(trace_class
,
421 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
424 uint64_t bt_field_class_enumeration_get_mapping_count(
425 const struct bt_field_class
*fc
)
427 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
429 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
430 BT_ASSERT_PRE_DEV_FC_IS_ENUM(fc
, "Field class");
431 return (uint64_t) enum_fc
->mappings
->len
;
434 const struct bt_field_class_enumeration_unsigned_mapping
*
435 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
436 const struct bt_field_class
*fc
, uint64_t index
)
438 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
440 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
441 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
442 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
444 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
447 const struct bt_field_class_enumeration_signed_mapping
*
448 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
449 const struct bt_field_class
*fc
, uint64_t index
)
451 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
453 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
454 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
455 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
457 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
461 const struct bt_field_class_enumeration_mapping
*
462 borrow_enumeration_field_class_mapping_by_label(
463 const struct bt_field_class_enumeration
*fc
, const char *label
)
465 struct bt_field_class_enumeration_mapping
*mapping
= NULL
;
469 BT_ASSERT_PRE_DEV_NON_NULL(label
, "Label");
471 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
472 struct bt_field_class_enumeration_mapping
*this_mapping
=
473 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
);
475 if (strcmp(this_mapping
->label
->str
, label
) == 0) {
476 mapping
= this_mapping
;
485 const struct bt_field_class_enumeration_signed_mapping
*
486 bt_field_class_enumeration_signed_borrow_mapping_by_label_const(
487 const struct bt_field_class
*fc
, const char *label
)
489 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
490 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
492 return (const void *) borrow_enumeration_field_class_mapping_by_label(
493 (const void *) fc
, label
);
496 const struct bt_field_class_enumeration_unsigned_mapping
*
497 bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(
498 const struct bt_field_class
*fc
, const char *label
)
500 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
501 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
502 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
503 return (const void *) borrow_enumeration_field_class_mapping_by_label(
504 (const void *) fc
, label
);
507 const char *bt_field_class_enumeration_mapping_get_label(
508 const struct bt_field_class_enumeration_mapping
*mapping
)
510 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
511 return mapping
->label
->str
;
514 const struct bt_integer_range_set_unsigned
*
515 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
516 const struct bt_field_class_enumeration_unsigned_mapping
*u_mapping
)
518 const struct bt_field_class_enumeration_mapping
*mapping
=
519 (const void *) u_mapping
;
521 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
522 return (const void *) mapping
->range_set
;
525 const struct bt_integer_range_set_signed
*
526 bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
527 const struct bt_field_class_enumeration_signed_mapping
*s_mapping
)
529 const struct bt_field_class_enumeration_mapping
*mapping
=
530 (const void *) s_mapping
;
532 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
533 return (const void *) mapping
->range_set
;
536 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
537 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
538 const struct bt_field_class
*fc
, uint64_t value
,
539 bt_field_class_enumeration_mapping_label_array
*label_array
,
542 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
545 BT_ASSERT_PRE_DEV_NO_ERROR();
546 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
547 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
548 BT_ASSERT_PRE_DEV_NON_NULL(count
, "Count (output)");
549 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
551 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
553 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
555 const struct bt_field_class_enumeration_mapping
*mapping
=
556 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
558 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
559 const struct bt_integer_range
*range
= (const void *)
560 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
561 mapping
->range_set
, j
);
563 if (value
>= range
->lower
.u
&&
564 value
<= range
->upper
.u
) {
565 g_ptr_array_add(enum_fc
->label_buf
,
566 mapping
->label
->str
);
572 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
573 *count
= (uint64_t) enum_fc
->label_buf
->len
;
574 return BT_FUNC_STATUS_OK
;
577 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
578 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
579 const struct bt_field_class
*fc
, int64_t value
,
580 bt_field_class_enumeration_mapping_label_array
*label_array
,
583 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
586 BT_ASSERT_PRE_DEV_NO_ERROR();
587 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
588 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
589 BT_ASSERT_PRE_DEV_NON_NULL(count
, "Count (output)");
590 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
592 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
594 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
596 const struct bt_field_class_enumeration_mapping
*mapping
=
597 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
599 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
600 const struct bt_integer_range
*range
= (const void *)
601 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
602 mapping
->range_set
, j
);
604 if (value
>= range
->lower
.i
&&
605 value
<= range
->upper
.i
) {
606 g_ptr_array_add(enum_fc
->label_buf
,
607 mapping
->label
->str
);
613 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
614 *count
= (uint64_t) enum_fc
->label_buf
->len
;
615 return BT_FUNC_STATUS_OK
;
619 bool enumeration_field_class_has_mapping_with_label(
620 const struct bt_field_class_enumeration
*enum_fc
,
629 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
630 struct bt_field_class_enumeration_mapping
*mapping_candidate
=
631 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
633 if (strcmp(mapping_candidate
->label
->str
, label
) == 0) {
644 enum bt_field_class_enumeration_add_mapping_status
645 add_mapping_to_enumeration_field_class(struct bt_field_class
*fc
,
646 const char *label
, const struct bt_integer_range_set
*range_set
)
648 enum bt_field_class_enumeration_add_mapping_status status
=
650 struct bt_field_class_enumeration
*enum_fc
= (void *) fc
;
651 struct bt_field_class_enumeration_mapping mapping
= { 0 };
653 BT_ASSERT_PRE_NO_ERROR();
655 BT_ASSERT_PRE_NON_NULL(label
, "Label");
656 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
657 BT_ASSERT_PRE(!enumeration_field_class_has_mapping_with_label(
659 "Duplicate mapping name in enumeration field class: "
660 "%![enum-fc-]+F, label=\"%s\"", fc
, label
);
661 mapping
.range_set
= range_set
;
662 bt_object_get_ref(mapping
.range_set
);
663 mapping
.label
= g_string_new(label
);
664 if (!mapping
.label
) {
665 finalize_enumeration_field_class_mapping(&mapping
);
666 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
670 g_array_append_val(enum_fc
->mappings
, mapping
);
671 BT_LIB_LOGD("Added mapping to enumeration field class: "
672 "%![fc-]+F, label=\"%s\"", fc
, label
);
678 enum bt_field_class_enumeration_add_mapping_status
679 bt_field_class_enumeration_unsigned_add_mapping(
680 struct bt_field_class
*fc
, const char *label
,
681 const struct bt_integer_range_set_unsigned
*range_set
)
683 BT_ASSERT_PRE_NO_ERROR();
684 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
685 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
687 return add_mapping_to_enumeration_field_class(fc
, label
,
688 (const void *) range_set
);
691 enum bt_field_class_enumeration_add_mapping_status
692 bt_field_class_enumeration_signed_add_mapping(
693 struct bt_field_class
*fc
, const char *label
,
694 const struct bt_integer_range_set_signed
*range_set
)
696 BT_ASSERT_PRE_NO_ERROR();
697 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
698 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
700 return add_mapping_to_enumeration_field_class(fc
, label
,
701 (const void *) range_set
);
705 void destroy_real_field_class(struct bt_object
*obj
)
708 BT_LIB_LOGD("Destroying real field class object: %!+F", obj
);
709 finalize_field_class((void *) obj
);
714 struct bt_field_class
*create_real_field_class(bt_trace_class
*trace_class
,
715 enum bt_field_class_type type
)
717 struct bt_field_class_real
*real_fc
= NULL
;
719 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
720 BT_LOGD("Creating default real field class object: type=%s",
721 bt_common_field_class_type_string(type
));
722 real_fc
= g_new0(struct bt_field_class_real
, 1);
724 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
728 if (init_field_class((void *) real_fc
, type
, destroy_real_field_class
)) {
732 BT_LIB_LOGD("Created real field class object: %!+F", real_fc
);
736 BT_OBJECT_PUT_REF_AND_RESET(real_fc
);
739 return (void *) real_fc
;
742 struct bt_field_class
*bt_field_class_real_single_precision_create(
743 bt_trace_class
*trace_class
)
745 BT_ASSERT_PRE_NO_ERROR();
747 return create_real_field_class(trace_class
,
748 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
);
751 struct bt_field_class
*bt_field_class_real_double_precision_create(
752 bt_trace_class
*trace_class
)
754 BT_ASSERT_PRE_NO_ERROR();
756 return create_real_field_class(trace_class
,
757 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
);
761 int init_named_field_classes_container(
762 struct bt_field_class_named_field_class_container
*fc
,
763 enum bt_field_class_type type
,
764 bt_object_release_func fc_release_func
,
765 GDestroyNotify named_fc_destroy_func
)
769 ret
= init_field_class((void *) fc
, type
, fc_release_func
);
774 fc
->named_fcs
= g_ptr_array_new_with_free_func(named_fc_destroy_func
);
775 if (!fc
->named_fcs
) {
776 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
781 fc
->name_to_index
= g_hash_table_new(g_str_hash
, g_str_equal
);
782 if (!fc
->name_to_index
) {
783 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
793 void finalize_named_field_class(struct bt_named_field_class
*named_fc
)
796 BT_LIB_LOGD("Finalizing named field class: "
797 "addr=%p, name=\"%s\", %![fc-]+F",
798 named_fc
, named_fc
->name
? named_fc
->name
->str
: NULL
,
800 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
802 if (named_fc
->name
) {
803 g_string_free(named_fc
->name
, TRUE
);
804 named_fc
->name
= NULL
;
807 BT_LOGD_STR("Putting named field class's field class.");
808 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->fc
);
812 void destroy_named_field_class(gpointer ptr
)
814 struct bt_named_field_class
*named_fc
= ptr
;
817 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
818 finalize_named_field_class(ptr
);
824 void destroy_variant_with_selector_field_option(gpointer ptr
)
826 struct bt_field_class_variant_with_selector_field_option
*opt
= ptr
;
829 finalize_named_field_class(&opt
->common
);
830 BT_OBJECT_PUT_REF_AND_RESET(opt
->range_set
);
836 void finalize_named_field_classes_container(
837 struct bt_field_class_named_field_class_container
*fc
)
842 g_ptr_array_free(fc
->named_fcs
, TRUE
);
843 fc
->named_fcs
= NULL
;
847 if (fc
->name_to_index
) {
848 g_hash_table_destroy(fc
->name_to_index
);
849 fc
->name_to_index
= NULL
;
854 void destroy_structure_field_class(struct bt_object
*obj
)
857 BT_LIB_LOGD("Destroying structure field class object: %!+F", obj
);
858 finalize_field_class((void *) obj
);
859 finalize_named_field_classes_container((void *) obj
);
863 struct bt_field_class
*bt_field_class_structure_create(
864 bt_trace_class
*trace_class
)
867 struct bt_field_class_structure
*struct_fc
= NULL
;
869 BT_ASSERT_PRE_NO_ERROR();
870 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
871 BT_LOGD_STR("Creating default structure field class object.");
872 struct_fc
= g_new0(struct bt_field_class_structure
, 1);
874 BT_LIB_LOGE_APPEND_CAUSE(
875 "Failed to allocate one structure field class.");
879 ret
= init_named_field_classes_container((void *) struct_fc
,
880 BT_FIELD_CLASS_TYPE_STRUCTURE
, destroy_structure_field_class
,
881 destroy_named_field_class
);
883 /* init_named_field_classes_container() logs errors */
887 BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc
);
891 BT_OBJECT_PUT_REF_AND_RESET(struct_fc
);
894 return (void *) struct_fc
;
898 int init_named_field_class(struct bt_named_field_class
*named_fc
,
899 const char *name
, struct bt_field_class
*fc
)
901 int status
= BT_FUNC_STATUS_OK
;
906 named_fc
->name
= g_string_new(name
);
907 if (!named_fc
->name
) {
908 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
909 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
913 named_fc
->user_attributes
= bt_value_map_create();
914 if (!named_fc
->user_attributes
) {
915 BT_LIB_LOGE_APPEND_CAUSE(
916 "Failed to create a map value object.");
917 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
922 bt_object_get_ref_no_null_check(named_fc
->fc
);
929 struct bt_named_field_class
*create_named_field_class(const char *name
,
930 struct bt_field_class
*fc
)
932 struct bt_named_field_class
*named_fc
= g_new0(
933 struct bt_named_field_class
, 1);
936 BT_LIB_LOGE_APPEND_CAUSE(
937 "Failed to allocate a named field class.");
941 if (init_named_field_class(named_fc
, name
, fc
)) {
942 /* init_named_field_class() logs errors */
949 destroy_named_field_class(named_fc
);
957 struct bt_field_class_variant_with_selector_field_option
*
958 create_variant_with_selector_field_option(
959 const char *name
, struct bt_field_class
*fc
,
960 const struct bt_integer_range_set
*range_set
)
962 struct bt_field_class_variant_with_selector_field_option
*opt
= g_new0(
963 struct bt_field_class_variant_with_selector_field_option
, 1);
965 BT_ASSERT(range_set
);
968 BT_LIB_LOGE_APPEND_CAUSE(
969 "Failed to allocate a named field class.");
973 if (init_named_field_class(&opt
->common
, name
, fc
)) {
977 opt
->range_set
= range_set
;
978 bt_object_get_ref_no_null_check(opt
->range_set
);
979 bt_integer_range_set_freeze(range_set
);
983 destroy_variant_with_selector_field_option(opt
);
991 int append_named_field_class_to_container_field_class(
992 struct bt_field_class_named_field_class_container
*container_fc
,
993 struct bt_named_field_class
*named_fc
)
995 BT_ASSERT(container_fc
);
997 BT_ASSERT_PRE_DEV_FC_HOT(container_fc
, "Field class");
998 BT_ASSERT_PRE(!bt_g_hash_table_contains(container_fc
->name_to_index
,
999 named_fc
->name
->str
),
1000 "Duplicate member/option name in structure/variant field class: "
1001 "%![container-fc-]+F, name=\"%s\"", container_fc
,
1002 named_fc
->name
->str
);
1005 * Freeze the contained field class, but not the named field
1006 * class itself, as it's still possible afterwards to modify
1007 * properties of the member/option object.
1009 bt_field_class_freeze(named_fc
->fc
);
1010 g_ptr_array_add(container_fc
->named_fcs
, named_fc
);
1011 g_hash_table_insert(container_fc
->name_to_index
, named_fc
->name
->str
,
1012 GUINT_TO_POINTER(container_fc
->named_fcs
->len
- 1));
1013 return BT_FUNC_STATUS_OK
;
1016 enum bt_field_class_structure_append_member_status
1017 bt_field_class_structure_append_member(
1018 struct bt_field_class
*fc
, const char *name
,
1019 struct bt_field_class
*member_fc
)
1021 enum bt_field_class_structure_append_member_status status
;
1022 struct bt_named_field_class
*named_fc
= NULL
;
1024 BT_ASSERT_PRE_NO_ERROR();
1025 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1026 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1028 named_fc
= create_named_field_class(name
, member_fc
);
1030 /* create_named_field_class() logs errors */
1031 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1035 status
= append_named_field_class_to_container_field_class((void *) fc
,
1037 if (status
== BT_FUNC_STATUS_OK
) {
1038 /* Moved to the container */
1046 uint64_t bt_field_class_structure_get_member_count(
1047 const struct bt_field_class
*fc
)
1049 struct bt_field_class_structure
*struct_fc
= (void *) fc
;
1051 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1052 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1054 return (uint64_t) struct_fc
->common
.named_fcs
->len
;
1058 struct bt_named_field_class
*
1059 borrow_named_field_class_from_container_field_class_at_index(
1060 struct bt_field_class_named_field_class_container
*fc
,
1064 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, fc
->named_fcs
->len
);
1065 return fc
->named_fcs
->pdata
[index
];
1068 const struct bt_field_class_structure_member
*
1069 bt_field_class_structure_borrow_member_by_index_const(
1070 const struct bt_field_class
*fc
, uint64_t index
)
1072 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1073 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1075 return (const void *)
1076 borrow_named_field_class_from_container_field_class_at_index(
1077 (void *) fc
, index
);
1080 struct bt_field_class_structure_member
*
1081 bt_field_class_structure_borrow_member_by_index(
1082 struct bt_field_class
*fc
, uint64_t index
)
1084 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1085 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1088 borrow_named_field_class_from_container_field_class_at_index(
1089 (void *) fc
, index
);
1093 struct bt_named_field_class
*
1094 borrow_named_field_class_from_container_field_class_by_name(
1095 struct bt_field_class_named_field_class_container
*fc
,
1098 struct bt_named_field_class
*named_fc
= NULL
;
1103 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Name");
1104 if (!g_hash_table_lookup_extended(fc
->name_to_index
, name
, &orig_key
,
1109 named_fc
= fc
->named_fcs
->pdata
[GPOINTER_TO_UINT(value
)];
1115 const struct bt_field_class_structure_member
*
1116 bt_field_class_structure_borrow_member_by_name_const(
1117 const struct bt_field_class
*fc
, const char *name
)
1119 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1120 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1122 return (const void *)
1123 borrow_named_field_class_from_container_field_class_by_name(
1127 struct bt_field_class_structure_member
*
1128 bt_field_class_structure_borrow_member_by_name(
1129 struct bt_field_class
*fc
, const char *name
)
1131 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1132 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1135 borrow_named_field_class_from_container_field_class_by_name(
1139 const char *bt_field_class_structure_member_get_name(
1140 const struct bt_field_class_structure_member
*member
)
1142 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1144 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1145 return named_fc
->name
->str
;
1148 const struct bt_field_class
*
1149 bt_field_class_structure_member_borrow_field_class_const(
1150 const struct bt_field_class_structure_member
*member
)
1152 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1154 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1155 return named_fc
->fc
;
1158 struct bt_field_class
*
1159 bt_field_class_structure_member_borrow_field_class(
1160 struct bt_field_class_structure_member
*member
)
1162 struct bt_named_field_class
*named_fc
= (void *) member
;
1164 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1165 return named_fc
->fc
;
1169 void destroy_option_field_class(struct bt_object
*obj
)
1171 struct bt_field_class_option
*fc
= (void *) obj
;
1174 BT_LIB_LOGD("Destroying option field class object: %!+F", fc
);
1175 finalize_field_class((void *) obj
);
1176 BT_LOGD_STR("Putting content field class.");
1177 BT_OBJECT_PUT_REF_AND_RESET(fc
->content_fc
);
1179 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1180 struct bt_field_class_option_with_selector_field
*with_sel_fc
=
1183 BT_LOGD_STR("Putting selector field path.");
1184 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field_path
);
1185 BT_LOGD_STR("Putting selector field class.");
1186 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_fc
);
1188 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1189 struct bt_field_class_option_with_selector_field_integer
*with_int_sel_fc
=
1192 BT_LOGD_STR("Putting integer range set.");
1193 BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc
->range_set
);
1201 struct bt_field_class
*create_option_field_class(
1202 struct bt_trace_class
*trace_class
,
1203 enum bt_field_class_type fc_type
,
1204 struct bt_field_class
*content_fc
,
1205 struct bt_field_class
*selector_fc
)
1207 struct bt_field_class_option
*opt_fc
= NULL
;
1209 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1210 BT_ASSERT_PRE_NON_NULL(content_fc
, "Content field class");
1211 BT_LIB_LOGD("Creating option field class: "
1212 "type=%s, %![content-fc-]+F, %![sel-fc-]+F",
1213 bt_common_field_class_type_string(fc_type
),
1214 content_fc
, selector_fc
);
1216 if (fc_type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1217 struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
= NULL
;
1219 BT_ASSERT_PRE_NON_NULL(selector_fc
, "Selector field class");
1221 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1222 BT_ASSERT_PRE_FC_HAS_ID(selector_fc
,
1223 BT_FIELD_CLASS_TYPE_BOOL
,
1224 "Selector field class");
1225 opt_with_sel_fc
= (void *) g_new0(
1226 struct bt_field_class_option_with_selector_field_bool
, 1);
1228 BT_ASSERT_PRE_FC_IS_INT(selector_fc
,
1229 "Selector field class");
1230 opt_with_sel_fc
= (void *) g_new0(
1231 struct bt_field_class_option_with_selector_field_integer
, 1);
1234 if (!opt_with_sel_fc
) {
1235 BT_LIB_LOGE_APPEND_CAUSE(
1236 "Failed to allocate one option with selector field class.");
1240 opt_with_sel_fc
->selector_fc
= selector_fc
;
1241 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_fc
);
1242 opt_fc
= (void *) opt_with_sel_fc
;
1244 opt_fc
= g_new0(struct bt_field_class_option
, 1);
1246 BT_LIB_LOGE_APPEND_CAUSE(
1247 "Failed to allocate one option field class.");
1254 if (init_field_class((void *) opt_fc
, fc_type
,
1255 destroy_option_field_class
)) {
1259 opt_fc
->content_fc
= content_fc
;
1260 bt_object_get_ref_no_null_check(opt_fc
->content_fc
);
1261 bt_field_class_freeze(opt_fc
->content_fc
);
1264 bt_field_class_freeze(selector_fc
);
1267 BT_LIB_LOGD("Created option field class object: "
1268 "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc
, selector_fc
);
1272 BT_OBJECT_PUT_REF_AND_RESET(opt_fc
);
1275 return (void *) opt_fc
;
1278 struct bt_field_class
*bt_field_class_option_without_selector_create(
1279 struct bt_trace_class
*trace_class
,
1280 struct bt_field_class
*content_fc
)
1282 BT_ASSERT_PRE_NO_ERROR();
1284 return create_option_field_class(trace_class
,
1285 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1289 struct bt_field_class
*bt_field_class_option_with_selector_field_bool_create(
1290 struct bt_trace_class
*trace_class
,
1291 struct bt_field_class
*content_fc
,
1292 struct bt_field_class
*selector_fc
)
1294 BT_ASSERT_PRE_NO_ERROR();
1296 return create_option_field_class(trace_class
,
1297 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1298 content_fc
, selector_fc
);
1301 struct bt_field_class
*
1302 bt_field_class_option_with_selector_field_integer_unsigned_create(
1303 struct bt_trace_class
*trace_class
,
1304 struct bt_field_class
*content_fc
,
1305 struct bt_field_class
*selector_fc
,
1306 const struct bt_integer_range_set_unsigned
*u_range_set
)
1308 struct bt_field_class_option_with_selector_field_integer
*fc
;
1309 const struct bt_integer_range_set
*range_set
=
1310 (const void *) u_range_set
;
1312 BT_ASSERT_PRE_NO_ERROR();
1313 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1314 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1315 "Integer range set is empty: %!+R", range_set
);
1316 fc
= (void *) create_option_field_class(trace_class
,
1317 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1318 content_fc
, selector_fc
);
1324 fc
->range_set
= range_set
;
1325 bt_object_get_ref_no_null_check(fc
->range_set
);
1326 bt_integer_range_set_freeze(range_set
);
1332 struct bt_field_class
*
1333 bt_field_class_option_with_selector_field_integer_signed_create(
1334 struct bt_trace_class
*trace_class
,
1335 struct bt_field_class
*content_fc
,
1336 struct bt_field_class
*selector_fc
,
1337 const struct bt_integer_range_set_signed
*i_range_set
)
1339 struct bt_field_class_option_with_selector_field_integer
*fc
;
1340 const struct bt_integer_range_set
*range_set
=
1341 (const void *) i_range_set
;
1343 BT_ASSERT_PRE_NO_ERROR();
1344 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1345 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1346 "Integer range set is empty: %!+R", range_set
);
1347 fc
= (void *) create_option_field_class(trace_class
,
1348 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1349 content_fc
, selector_fc
);
1355 fc
->range_set
= range_set
;
1356 bt_object_get_ref_no_null_check(fc
->range_set
);
1357 bt_integer_range_set_freeze(range_set
);
1363 const struct bt_field_class
*bt_field_class_option_borrow_field_class_const(
1364 const struct bt_field_class
*fc
)
1366 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1368 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1369 BT_ASSERT_PRE_FC_IS_OPTION(fc
, "Field class");
1370 return opt_fc
->content_fc
;
1373 struct bt_field_class
*bt_field_class_option_borrow_field_class(
1374 struct bt_field_class
*fc
)
1376 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1378 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1379 BT_ASSERT_PRE_FC_IS_OPTION(fc
, "Field class");
1380 return opt_fc
->content_fc
;
1383 const struct bt_field_path
*
1384 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1385 const struct bt_field_class
*fc
)
1387 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1390 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1391 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(fc
, "Field class");
1392 return opt_fc
->selector_field_path
;
1395 void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
1396 struct bt_field_class
*fc
, bt_bool sel_is_reversed
)
1398 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1400 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1401 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1402 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
, "Field class");
1403 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
1404 opt_fc
->sel_is_reversed
= sel_is_reversed
;
1407 bt_bool
bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1408 const struct bt_field_class
*fc
)
1410 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1412 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1413 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1414 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
, "Field class");
1415 return opt_fc
->sel_is_reversed
;
1418 const struct bt_integer_range_set_unsigned
*
1419 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1420 const struct bt_field_class
*fc
)
1422 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1425 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1426 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc
, "Field class");
1427 return (const void *) opt_fc
->range_set
;
1430 const struct bt_integer_range_set_signed
*
1431 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1432 const struct bt_field_class
*fc
)
1434 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1437 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1438 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc
, "Field class");
1439 return (const void *) opt_fc
->range_set
;
1443 void finalize_variant_field_class(struct bt_field_class_variant
*var_fc
)
1446 BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc
);
1447 finalize_field_class((void *) var_fc
);
1448 finalize_named_field_classes_container((void *) var_fc
);
1452 void destroy_variant_field_class(struct bt_object
*obj
)
1454 struct bt_field_class_variant
*fc
= (void *) obj
;
1457 finalize_variant_field_class(fc
);
1462 void destroy_variant_with_selector_field_field_class(struct bt_object
*obj
)
1464 struct bt_field_class_variant_with_selector_field
*fc
= (void *) obj
;
1467 finalize_variant_field_class(&fc
->common
);
1468 BT_LOGD_STR("Putting selector field path.");
1469 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field_path
);
1470 BT_LOGD_STR("Putting selector field class.");
1471 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_fc
);
1475 struct bt_field_class
*bt_field_class_variant_create(
1476 bt_trace_class
*trace_class
, bt_field_class
*selector_fc
)
1479 struct bt_field_class_variant
*var_fc
= NULL
;
1480 struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
= NULL
;
1481 enum bt_field_class_type fc_type
;
1483 BT_ASSERT_PRE_NO_ERROR();
1484 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1487 BT_ASSERT_PRE_FC_IS_INT(selector_fc
, "Selector field class");
1490 BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F",
1494 var_with_sel_fc
= g_new0(
1495 struct bt_field_class_variant_with_selector_field
, 1);
1496 if (!var_with_sel_fc
) {
1497 BT_LIB_LOGE_APPEND_CAUSE(
1498 "Failed to allocate one variant field class with selector.");
1502 if (bt_field_class_type_is(selector_fc
->type
,
1503 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
)) {
1504 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
;
1506 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
;
1509 ret
= init_named_field_classes_container(
1510 (void *) var_with_sel_fc
, fc_type
,
1511 destroy_variant_with_selector_field_field_class
,
1512 destroy_variant_with_selector_field_option
);
1514 /* init_named_field_classes_container() logs errors */
1518 var_with_sel_fc
->selector_fc
= selector_fc
;
1519 bt_object_get_ref_no_null_check(var_with_sel_fc
->selector_fc
);
1520 bt_field_class_freeze(selector_fc
);
1521 var_fc
= (void *) var_with_sel_fc
;
1522 BT_LIB_LOGD("Created default variant field class with selector object: "
1523 "%![var-fc-]+F, %![sel-fc-]+F", var_fc
, selector_fc
);
1525 var_fc
= g_new0(struct bt_field_class_variant
, 1);
1527 BT_LIB_LOGE_APPEND_CAUSE(
1528 "Failed to allocate one variant field class without selector.");
1532 ret
= init_named_field_classes_container((void *) var_fc
,
1533 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1534 destroy_variant_field_class
, destroy_named_field_class
);
1536 /* init_named_field_classes_container() logs errors */
1539 BT_LIB_LOGD("Created default variant field class without selector object: "
1540 "%![var-fc-]+F", var_fc
);
1547 BT_OBJECT_PUT_REF_AND_RESET(var_fc
);
1548 BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc
);
1551 return (void *) var_fc
;
1554 enum bt_field_class_variant_without_selector_append_option_status
1555 bt_field_class_variant_without_selector_append_option(struct bt_field_class
*fc
,
1556 const char *name
, struct bt_field_class
*option_fc
)
1558 enum bt_field_class_variant_without_selector_append_option_status status
;
1559 struct bt_named_field_class
*named_fc
= NULL
;
1561 BT_ASSERT_PRE_NO_ERROR();
1562 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1563 BT_ASSERT_PRE_NON_NULL(name
, "Name");
1564 BT_ASSERT_PRE_NON_NULL(option_fc
, "Option field class");
1565 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1566 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
, "Field class");
1567 named_fc
= create_named_field_class(name
, option_fc
);
1569 /* create_named_field_class() logs errors */
1570 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1574 status
= append_named_field_class_to_container_field_class((void *) fc
,
1576 if (status
== BT_FUNC_STATUS_OK
) {
1577 /* Moved to the container */
1583 destroy_named_field_class(named_fc
);
1590 int ranges_overlap(GPtrArray
*var_fc_opts
, const struct bt_integer_range_set
*range_set
,
1591 bool is_signed
, bool *has_overlap
)
1593 int status
= BT_FUNC_STATUS_OK
;
1594 struct bt_integer_range_set
*full_range_set
;
1597 *has_overlap
= false;
1600 * Build a single range set with all the ranges and test for
1604 full_range_set
= (void *) bt_integer_range_set_signed_create();
1606 full_range_set
= (void *) bt_integer_range_set_unsigned_create();
1609 if (!full_range_set
) {
1610 BT_LOGE_STR("Failed to create a range set.");
1611 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1615 /* Add existing option ranges */
1616 for (i
= 0; i
< var_fc_opts
->len
; i
++) {
1617 struct bt_field_class_variant_with_selector_field_option
*opt
=
1618 var_fc_opts
->pdata
[i
];
1621 for (j
= 0; j
< opt
->range_set
->ranges
->len
; j
++) {
1622 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1626 status
= bt_integer_range_set_signed_add_range(
1627 (void *) full_range_set
, range
->lower
.i
,
1630 status
= bt_integer_range_set_unsigned_add_range(
1631 (void *) full_range_set
, range
->lower
.u
,
1641 /* Add new ranges */
1642 for (i
= 0; i
< range_set
->ranges
->len
; i
++) {
1643 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1647 status
= bt_integer_range_set_signed_add_range(
1648 (void *) full_range_set
, range
->lower
.i
,
1651 status
= bt_integer_range_set_unsigned_add_range(
1652 (void *) full_range_set
, range
->lower
.u
,
1661 /* Check overlaps */
1663 *has_overlap
= bt_integer_range_set_signed_has_overlaps(full_range_set
);
1665 *has_overlap
= bt_integer_range_set_unsigned_has_overlaps(
1670 bt_object_put_ref(full_range_set
);
1675 int append_option_to_variant_with_selector_field_field_class(
1676 struct bt_field_class
*fc
, const char *name
,
1677 struct bt_field_class
*option_fc
,
1678 const struct bt_integer_range_set
*range_set
,
1679 enum bt_field_class_type expected_type
)
1682 struct bt_field_class_variant_with_selector_field
*var_fc
= (void *) fc
;
1683 struct bt_field_class_variant_with_selector_field_option
*opt
= NULL
;
1686 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1687 BT_ASSERT_PRE_NON_NULL(name
, "Name");
1688 BT_ASSERT_PRE_NON_NULL(option_fc
, "Option field class");
1689 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1690 BT_ASSERT_PRE_FC_HAS_ID(fc
, expected_type
, "Field class");
1691 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1692 "Integer range set is empty: %!+R", range_set
);
1693 status
= ranges_overlap(var_fc
->common
.common
.named_fcs
, range_set
,
1694 expected_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1697 /* ranges_overlap() logs errors */
1701 BT_ASSERT_PRE(!has_overlap
,
1702 "Integer range set's ranges and existing ranges have an overlap: "
1704 opt
= create_variant_with_selector_field_option(name
, option_fc
, range_set
);
1706 /* create_variant_with_selector_field_option() logs errors */
1707 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1711 status
= append_named_field_class_to_container_field_class((void *) fc
,
1713 if (status
== BT_FUNC_STATUS_OK
) {
1714 /* Moved to the container */
1720 destroy_variant_with_selector_field_option(opt
);
1726 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1727 bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
1728 struct bt_field_class
*fc
, const char *name
,
1729 struct bt_field_class
*option_fc
,
1730 const struct bt_integer_range_set_unsigned
*range_set
)
1732 BT_ASSERT_PRE_NO_ERROR();
1734 return append_option_to_variant_with_selector_field_field_class(fc
,
1735 name
, option_fc
, (const void *) range_set
,
1736 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
);
1739 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1740 bt_field_class_variant_with_selector_field_integer_signed_append_option(
1741 struct bt_field_class
*fc
, const char *name
,
1742 struct bt_field_class
*option_fc
,
1743 const struct bt_integer_range_set_signed
*range_set
)
1745 BT_ASSERT_PRE_NO_ERROR();
1747 return append_option_to_variant_with_selector_field_field_class(fc
,
1748 name
, option_fc
, (const void *) range_set
,
1749 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
);
1752 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class
*fc
)
1754 const struct bt_field_class_variant
*var_fc
= (const void *) fc
;
1756 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1757 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1758 return (uint64_t) var_fc
->common
.named_fcs
->len
;
1761 const struct bt_field_class_variant_option
*
1762 bt_field_class_variant_borrow_option_by_name_const(
1763 const struct bt_field_class
*fc
, const char *name
)
1765 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1766 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1767 return (const void *)
1768 borrow_named_field_class_from_container_field_class_by_name(
1772 const struct bt_field_class_variant_option
*
1773 bt_field_class_variant_borrow_option_by_index_const(
1774 const struct bt_field_class
*fc
, uint64_t index
)
1776 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1777 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1778 return (const void *)
1779 borrow_named_field_class_from_container_field_class_at_index(
1780 (void *) fc
, index
);
1783 struct bt_field_class_variant_option
*
1784 bt_field_class_variant_borrow_option_by_name(
1785 struct bt_field_class
*fc
, const char *name
)
1787 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1788 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1790 borrow_named_field_class_from_container_field_class_by_name(
1794 struct bt_field_class_variant_option
*
1795 bt_field_class_variant_borrow_option_by_index(
1796 struct bt_field_class
*fc
, uint64_t index
)
1798 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1799 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1801 borrow_named_field_class_from_container_field_class_at_index(
1802 (void *) fc
, index
);
1805 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1806 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
1807 const struct bt_field_class
*fc
, const char *name
)
1809 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1810 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1811 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1813 return (const void *)
1814 borrow_named_field_class_from_container_field_class_by_name(
1818 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1819 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
1820 const struct bt_field_class
*fc
, uint64_t index
)
1822 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1823 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1824 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1826 return (const void *)
1827 borrow_named_field_class_from_container_field_class_at_index(
1828 (void *) fc
, index
);
1831 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1832 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
1833 const struct bt_field_class
*fc
, const char *name
)
1835 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1836 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1837 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1839 return (const void *)
1840 borrow_named_field_class_from_container_field_class_by_name(
1844 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1845 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
1846 const struct bt_field_class
*fc
, uint64_t index
)
1848 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1849 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1850 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1852 return (const void *)
1853 borrow_named_field_class_from_container_field_class_at_index(
1854 (void *) fc
, index
);
1857 const char *bt_field_class_variant_option_get_name(
1858 const struct bt_field_class_variant_option
*option
)
1860 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1862 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1863 return named_fc
->name
->str
;
1866 const struct bt_field_class
*
1867 bt_field_class_variant_option_borrow_field_class_const(
1868 const struct bt_field_class_variant_option
*option
)
1870 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1872 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1873 return named_fc
->fc
;
1876 struct bt_field_class
*
1877 bt_field_class_variant_option_borrow_field_class(
1878 struct bt_field_class_variant_option
*option
)
1880 struct bt_named_field_class
*named_fc
= (void *) option
;
1882 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1883 return named_fc
->fc
;
1886 const struct bt_integer_range_set_unsigned
*
1887 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
1888 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*option
)
1890 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1891 (const void *) option
;
1893 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1894 return (const void *) opt
->range_set
;
1897 const struct bt_integer_range_set_signed
*
1898 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
1899 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*option
)
1901 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1902 (const void *) option
;
1904 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1905 return (const void *) opt
->range_set
;
1908 const struct bt_field_path
*
1909 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
1910 const struct bt_field_class
*fc
)
1912 const struct bt_field_class_variant_with_selector_field
*var_fc
=
1915 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1916 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(fc
, "Field class");
1917 return var_fc
->selector_field_path
;
1921 int init_array_field_class(struct bt_field_class_array
*fc
,
1922 enum bt_field_class_type type
, bt_object_release_func release_func
,
1923 struct bt_field_class
*element_fc
)
1927 BT_ASSERT(element_fc
);
1928 ret
= init_field_class((void *) fc
, type
, release_func
);
1933 fc
->element_fc
= element_fc
;
1934 bt_object_get_ref_no_null_check(fc
->element_fc
);
1935 bt_field_class_freeze(element_fc
);
1942 void finalize_array_field_class(struct bt_field_class_array
*array_fc
)
1944 BT_ASSERT(array_fc
);
1945 BT_LOGD_STR("Putting element field class.");
1946 finalize_field_class((void *) array_fc
);
1947 BT_OBJECT_PUT_REF_AND_RESET(array_fc
->element_fc
);
1951 void destroy_static_array_field_class(struct bt_object
*obj
)
1954 BT_LIB_LOGD("Destroying static array field class object: %!+F", obj
);
1955 finalize_array_field_class((void *) obj
);
1959 struct bt_field_class
*
1960 bt_field_class_array_static_create(bt_trace_class
*trace_class
,
1961 struct bt_field_class
*element_fc
, uint64_t length
)
1963 struct bt_field_class_array_static
*array_fc
= NULL
;
1965 BT_ASSERT_PRE_NO_ERROR();
1966 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1967 BT_ASSERT_PRE_NON_NULL(element_fc
, "Element field class");
1968 BT_LOGD_STR("Creating default static array field class object.");
1969 array_fc
= g_new0(struct bt_field_class_array_static
, 1);
1971 BT_LIB_LOGE_APPEND_CAUSE(
1972 "Failed to allocate one static array field class.");
1976 if (init_array_field_class((void *) array_fc
,
1977 BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
1978 destroy_static_array_field_class
, element_fc
)) {
1982 array_fc
->length
= length
;
1983 BT_LIB_LOGD("Created static array field class object: %!+F", array_fc
);
1987 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
1990 return (void *) array_fc
;
1993 const struct bt_field_class
*
1994 bt_field_class_array_borrow_element_field_class_const(
1995 const struct bt_field_class
*fc
)
1997 const struct bt_field_class_array
*array_fc
= (const void *) fc
;
1999 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2000 BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc
, "Field class");
2001 return array_fc
->element_fc
;
2004 struct bt_field_class
*
2005 bt_field_class_array_borrow_element_field_class(struct bt_field_class
*fc
)
2007 struct bt_field_class_array
*array_fc
= (void *) fc
;
2009 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2010 BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc
, "Field class");
2011 return array_fc
->element_fc
;
2014 uint64_t bt_field_class_array_static_get_length(const struct bt_field_class
*fc
)
2016 const struct bt_field_class_array_static
*array_fc
= (const void *) fc
;
2018 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2019 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2021 return (uint64_t) array_fc
->length
;
2025 void destroy_dynamic_array_field_class(struct bt_object
*obj
)
2027 struct bt_field_class_array_dynamic
*fc
= (void *) obj
;
2030 BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc
);
2031 finalize_array_field_class((void *) fc
);
2032 BT_LOGD_STR("Putting length field path.");
2033 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field_path
);
2034 BT_LOGD_STR("Putting length field class.");
2035 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_fc
);
2039 struct bt_field_class
*bt_field_class_array_dynamic_create(
2040 struct bt_trace_class
*trace_class
,
2041 struct bt_field_class
*element_fc
,
2042 struct bt_field_class
*length_fc
)
2044 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2046 BT_ASSERT_PRE_NO_ERROR();
2047 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
2048 BT_ASSERT_PRE_NON_NULL(element_fc
, "Element field class");
2049 BT_LOGD_STR("Creating default dynamic array field class object.");
2050 array_fc
= g_new0(struct bt_field_class_array_dynamic
, 1);
2052 BT_LIB_LOGE_APPEND_CAUSE(
2053 "Failed to allocate one dynamic array field class.");
2057 if (init_array_field_class((void *) array_fc
,
2059 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
2060 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2061 destroy_dynamic_array_field_class
, element_fc
)) {
2066 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc
,
2067 "Length field class");
2068 array_fc
->length_fc
= length_fc
;
2069 bt_object_get_ref_no_null_check(array_fc
->length_fc
);
2070 bt_field_class_freeze(length_fc
);
2073 BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc
);
2077 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2080 return (void *) array_fc
;
2083 const struct bt_field_path
*
2084 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
2085 const struct bt_field_class
*fc
)
2087 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2089 BT_ASSERT_PRE_NO_ERROR();
2090 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2091 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
2092 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2094 return seq_fc
->length_field_path
;
2098 void destroy_string_field_class(struct bt_object
*obj
)
2101 BT_LIB_LOGD("Destroying string field class object: %!+F", obj
);
2102 finalize_field_class((void *) obj
);
2106 struct bt_field_class
*bt_field_class_string_create(bt_trace_class
*trace_class
)
2108 struct bt_field_class_string
*string_fc
= NULL
;
2110 BT_ASSERT_PRE_NO_ERROR();
2111 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
2112 BT_LOGD_STR("Creating default string field class object.");
2113 string_fc
= g_new0(struct bt_field_class_string
, 1);
2115 BT_LIB_LOGE_APPEND_CAUSE(
2116 "Failed to allocate one string field class.");
2120 if (init_field_class((void *) string_fc
, BT_FIELD_CLASS_TYPE_STRING
,
2121 destroy_string_field_class
)) {
2125 BT_LIB_LOGD("Created string field class object: %!+F", string_fc
);
2129 BT_OBJECT_PUT_REF_AND_RESET(string_fc
);
2132 return (void *) string_fc
;
2136 void _bt_field_class_freeze(const struct bt_field_class
*c_fc
)
2138 struct bt_field_class
*fc
= (void *) c_fc
;
2141 * Element/member/option field classes are frozen when added to
2145 bt_value_freeze(fc
->user_attributes
);
2148 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2149 bt_field_class_type_is(fc
->type
,
2150 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2151 struct bt_field_class_named_field_class_container
*container_fc
=
2155 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2156 bt_named_field_class_freeze(
2157 container_fc
->named_fcs
->pdata
[i
]);
2163 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
)
2165 BT_ASSERT(named_fc
);
2166 BT_ASSERT(named_fc
->fc
->frozen
);
2167 BT_LIB_LOGD("Freezing named field class's user attributes: %!+v",
2168 named_fc
->user_attributes
);
2169 bt_value_freeze(named_fc
->user_attributes
);
2170 ((struct bt_named_field_class
*) named_fc
)->frozen
= true;
2174 void bt_field_class_make_part_of_trace_class(const struct bt_field_class
*c_fc
)
2176 struct bt_field_class
*fc
= (void *) c_fc
;
2179 BT_ASSERT_PRE(!fc
->part_of_trace_class
,
2180 "Field class is already part of a trace: %!+F", fc
);
2181 fc
->part_of_trace_class
= true;
2183 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2184 bt_field_class_type_is(fc
->type
,
2185 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2186 struct bt_field_class_named_field_class_container
*container_fc
=
2190 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2191 struct bt_named_field_class
*named_fc
=
2192 container_fc
->named_fcs
->pdata
[i
];
2194 bt_field_class_make_part_of_trace_class(named_fc
->fc
);
2196 } else if (bt_field_class_type_is(fc
->type
,
2197 BT_FIELD_CLASS_TYPE_ARRAY
)) {
2198 struct bt_field_class_array
*array_fc
= (void *) fc
;
2200 bt_field_class_make_part_of_trace_class(array_fc
->element_fc
);
2204 const struct bt_value
*bt_field_class_borrow_user_attributes_const(
2205 const struct bt_field_class
*fc
)
2207 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2208 return fc
->user_attributes
;
2211 struct bt_value
*bt_field_class_borrow_user_attributes(
2212 struct bt_field_class
*field_class
)
2214 return (void *) bt_field_class_borrow_user_attributes_const(
2215 (void *) field_class
);
2219 void bt_field_class_set_user_attributes(
2220 struct bt_field_class
*fc
,
2221 const struct bt_value
*user_attributes
)
2223 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
2224 BT_ASSERT_PRE_NON_NULL(user_attributes
, "User attributes");
2225 BT_ASSERT_PRE(user_attributes
->type
== BT_VALUE_TYPE_MAP
,
2226 "User attributes object is not a map value object.");
2227 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
2228 bt_object_put_ref_no_null_check(fc
->user_attributes
);
2229 fc
->user_attributes
= (void *) user_attributes
;
2230 bt_object_get_ref_no_null_check(fc
->user_attributes
);
2234 const struct bt_value
*bt_named_field_class_borrow_user_attributes_const(
2235 const struct bt_named_field_class
*named_fc
)
2237 return named_fc
->user_attributes
;
2241 void bt_named_field_class_set_user_attributes(
2242 struct bt_named_field_class
*named_fc
,
2243 const struct bt_value
*user_attributes
)
2245 BT_ASSERT_PRE_NON_NULL(user_attributes
, "User attributes");
2246 BT_ASSERT_PRE(user_attributes
->type
== BT_VALUE_TYPE_MAP
,
2247 "User attributes object is not a map value object.");
2248 BT_ASSERT_PRE_DEV_HOT(named_fc
,
2249 "Structure field class member or variant field class option",
2251 bt_object_put_ref_no_null_check(named_fc
->user_attributes
);
2252 named_fc
->user_attributes
= (void *) user_attributes
;
2253 bt_object_get_ref_no_null_check(named_fc
->user_attributes
);
2256 const struct bt_value
*
2257 bt_field_class_structure_member_borrow_user_attributes_const(
2258 const struct bt_field_class_structure_member
*member
)
2260 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2261 return bt_named_field_class_borrow_user_attributes_const(
2262 (const void *) member
);
2266 bt_field_class_structure_member_borrow_user_attributes(
2267 struct bt_field_class_structure_member
*member
)
2269 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2270 return (void *) bt_named_field_class_borrow_user_attributes_const(
2274 void bt_field_class_structure_member_set_user_attributes(
2275 struct bt_field_class_structure_member
*member
,
2276 const struct bt_value
*user_attributes
)
2278 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2279 bt_named_field_class_set_user_attributes((void *) member
,
2283 const struct bt_value
*bt_field_class_variant_option_borrow_user_attributes_const(
2284 const struct bt_field_class_variant_option
*option
)
2286 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2287 return bt_named_field_class_borrow_user_attributes_const(
2288 (const void *) option
);
2291 struct bt_value
*bt_field_class_variant_option_borrow_user_attributes(
2292 struct bt_field_class_variant_option
*option
)
2294 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2295 return (void *) bt_named_field_class_borrow_user_attributes_const(
2299 void bt_field_class_variant_option_set_user_attributes(
2300 struct bt_field_class_variant_option
*option
,
2301 const struct bt_value
*user_attributes
)
2303 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2304 bt_named_field_class_set_user_attributes((void *) option
,
2308 void bt_field_class_get_ref(const struct bt_field_class
*field_class
)
2310 bt_object_get_ref(field_class
);
2313 void bt_field_class_put_ref(const struct bt_field_class
*field_class
)
2315 bt_object_put_ref(field_class
);