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.h>
30 #include <babeltrace2/trace-ir/clock-class.h>
31 #include "lib/object.h"
32 #include "compat/compiler.h"
33 #include "compat/endian.h"
34 #include "common/assert.h"
35 #include "compat/glib.h"
41 #include "clock-class.h"
42 #include "field-class.h"
44 #include "field-path.h"
46 #include "lib/func-status.h"
47 #include "lib/integer-range-set.h"
48 #include "lib/value.h"
50 enum bt_field_class_type
bt_field_class_get_type(
51 const struct bt_field_class
*fc
)
53 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
58 int init_field_class(struct bt_field_class
*fc
, enum bt_field_class_type type
,
59 bt_object_release_func release_func
)
64 BT_ASSERT(release_func
);
65 bt_object_init_shared(&fc
->base
, release_func
);
67 fc
->user_attributes
= bt_value_map_create();
68 if (!fc
->user_attributes
) {
69 BT_LIB_LOGE_APPEND_CAUSE(
70 "Failed to create a map value object.");
80 void finalize_field_class(struct bt_field_class
*fc
)
82 BT_OBJECT_PUT_REF_AND_RESET(fc
->user_attributes
);
86 void destroy_bit_array_field_class(struct bt_object
*obj
)
89 BT_LIB_LOGD("Destroying bit array field class object: %!+F", obj
);
90 finalize_field_class((void *) obj
);
94 struct bt_field_class
*bt_field_class_bit_array_create(
95 struct bt_trace_class
*trace_class
, uint64_t length
)
97 struct bt_field_class_bit_array
*ba_fc
= NULL
;
99 BT_ASSERT_PRE_NO_ERROR();
100 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
101 BT_ASSERT_PRE(length
> 0 && length
<= 64,
102 "Unsupported length for bit array field class "
103 "(minimum is 1, maximum is 64): length=%" PRIu64
, length
);
104 BT_LOGD("Creating default bit array field class object.");
105 ba_fc
= g_new0(struct bt_field_class_bit_array
, 1);
107 BT_LIB_LOGE_APPEND_CAUSE(
108 "Failed to allocate one bit array field class.");
112 if (init_field_class((void *) ba_fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
113 destroy_bit_array_field_class
)) {
117 ba_fc
->length
= length
;
118 BT_LIB_LOGD("Created bit array field class object: %!+F", ba_fc
);
122 BT_OBJECT_PUT_REF_AND_RESET(ba_fc
);
125 return (void *) ba_fc
;
128 uint64_t bt_field_class_bit_array_get_length(const struct bt_field_class
*fc
)
130 const struct bt_field_class_bit_array
*ba_fc
= (const void *) fc
;
132 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
133 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_BIT_ARRAY
,
135 return ba_fc
->length
;
139 void destroy_bool_field_class(struct bt_object
*obj
)
142 BT_LIB_LOGD("Destroying boolean field class object: %!+F", obj
);
143 finalize_field_class((void *) obj
);
147 struct bt_field_class
*bt_field_class_bool_create(
148 bt_trace_class
*trace_class
)
150 struct bt_field_class_bool
*bool_fc
= NULL
;
152 BT_ASSERT_PRE_NO_ERROR();
153 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
154 BT_LOGD("Creating default boolean field class object.");
155 bool_fc
= g_new0(struct bt_field_class_bool
, 1);
157 BT_LIB_LOGE_APPEND_CAUSE(
158 "Failed to allocate one boolean field class.");
162 if (init_field_class((void *) bool_fc
, BT_FIELD_CLASS_TYPE_BOOL
,
163 destroy_bool_field_class
)) {
167 BT_LIB_LOGD("Created boolean field class object: %!+F", bool_fc
);
171 BT_OBJECT_PUT_REF_AND_RESET(bool_fc
);
174 return (void *) bool_fc
;
178 int init_integer_field_class(struct bt_field_class_integer
*fc
,
179 enum bt_field_class_type type
,
180 bt_object_release_func release_func
)
184 ret
= init_field_class((void *) fc
, type
, release_func
);
190 fc
->base
= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
;
197 void destroy_integer_field_class(struct bt_object
*obj
)
200 BT_LIB_LOGD("Destroying integer field class object: %!+F", obj
);
201 finalize_field_class((void *) obj
);
206 struct bt_field_class
*create_integer_field_class(bt_trace_class
*trace_class
,
207 enum bt_field_class_type type
)
209 struct bt_field_class_integer
*int_fc
= NULL
;
211 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
212 BT_LOGD("Creating default integer field class object: type=%s",
213 bt_common_field_class_type_string(type
));
214 int_fc
= g_new0(struct bt_field_class_integer
, 1);
216 BT_LIB_LOGE_APPEND_CAUSE(
217 "Failed to allocate one integer field class.");
221 if (init_integer_field_class(int_fc
, type
,
222 destroy_integer_field_class
)) {
226 BT_LIB_LOGD("Created integer field class object: %!+F", int_fc
);
230 BT_OBJECT_PUT_REF_AND_RESET(int_fc
);
233 return (void *) int_fc
;
236 struct bt_field_class
*bt_field_class_integer_unsigned_create(
237 bt_trace_class
*trace_class
)
239 BT_ASSERT_PRE_NO_ERROR();
241 return create_integer_field_class(trace_class
,
242 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
);
245 struct bt_field_class
*bt_field_class_integer_signed_create(
246 bt_trace_class
*trace_class
)
248 BT_ASSERT_PRE_NO_ERROR();
250 return create_integer_field_class(trace_class
,
251 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
254 uint64_t bt_field_class_integer_get_field_value_range(
255 const struct bt_field_class
*fc
)
257 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
259 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
260 BT_ASSERT_PRE_DEV_FC_IS_INT(fc
, "Field class");
261 return int_fc
->range
;
265 bool size_is_valid_for_enumeration_field_class(struct bt_field_class
*fc
,
272 void bt_field_class_integer_set_field_value_range(
273 struct bt_field_class
*fc
, uint64_t size
)
275 struct bt_field_class_integer
*int_fc
= (void *) fc
;
277 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
278 BT_ASSERT_PRE_FC_IS_INT(fc
, "Field class");
279 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
280 BT_ASSERT_PRE(size
<= 64,
281 "Unsupported size for integer field class's field value range "
282 "(maximum is 64): size=%" PRIu64
, size
);
284 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
||
285 int_fc
->common
.type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
||
286 size_is_valid_for_enumeration_field_class(fc
, size
),
287 "Invalid field value range for enumeration field class: "
288 "at least one of the current mapping ranges contains values "
289 "which are outside this range: %!+F, size=%" PRIu64
, fc
, size
);
290 int_fc
->range
= size
;
291 BT_LIB_LOGD("Set integer field class's field value range: %!+F", fc
);
294 enum bt_field_class_integer_preferred_display_base
295 bt_field_class_integer_get_preferred_display_base(const struct bt_field_class
*fc
)
297 const struct bt_field_class_integer
*int_fc
= (const void *) fc
;
299 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
300 BT_ASSERT_PRE_DEV_FC_IS_INT(fc
, "Field class");
304 void bt_field_class_integer_set_preferred_display_base(
305 struct bt_field_class
*fc
,
306 enum bt_field_class_integer_preferred_display_base base
)
308 struct bt_field_class_integer
*int_fc
= (void *) fc
;
310 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
311 BT_ASSERT_PRE_FC_IS_INT(fc
, "Field class");
312 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
314 BT_LIB_LOGD("Set integer field class's preferred display base: %!+F", fc
);
318 void finalize_enumeration_field_class_mapping(
319 struct bt_field_class_enumeration_mapping
*mapping
)
323 if (mapping
->label
) {
324 g_string_free(mapping
->label
, TRUE
);
325 mapping
->label
= NULL
;
328 BT_OBJECT_PUT_REF_AND_RESET(mapping
->range_set
);
332 void destroy_enumeration_field_class(struct bt_object
*obj
)
334 struct bt_field_class_enumeration
*fc
= (void *) obj
;
337 BT_LIB_LOGD("Destroying enumeration field class object: %!+F", fc
);
338 finalize_field_class((void *) obj
);
343 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
344 finalize_enumeration_field_class_mapping(
345 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
));
348 g_array_free(fc
->mappings
, TRUE
);
353 g_ptr_array_free(fc
->label_buf
, TRUE
);
354 fc
->label_buf
= NULL
;
361 struct bt_field_class
*create_enumeration_field_class(
362 bt_trace_class
*trace_class
, enum bt_field_class_type type
)
364 struct bt_field_class_enumeration
*enum_fc
= NULL
;
366 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
367 BT_LOGD("Creating default enumeration field class object: type=%s",
368 bt_common_field_class_type_string(type
));
369 enum_fc
= g_new0(struct bt_field_class_enumeration
, 1);
371 BT_LIB_LOGE_APPEND_CAUSE(
372 "Failed to allocate one enumeration field class.");
376 if (init_integer_field_class((void *) enum_fc
, type
,
377 destroy_enumeration_field_class
)) {
381 enum_fc
->mappings
= g_array_new(FALSE
, TRUE
,
382 sizeof(struct bt_field_class_enumeration_mapping
));
383 if (!enum_fc
->mappings
) {
384 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
388 enum_fc
->label_buf
= g_ptr_array_new();
389 if (!enum_fc
->label_buf
) {
390 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
394 BT_LIB_LOGD("Created enumeration field class object: %!+F", enum_fc
);
398 BT_OBJECT_PUT_REF_AND_RESET(enum_fc
);
401 return (void *) enum_fc
;
404 struct bt_field_class
*bt_field_class_enumeration_unsigned_create(
405 bt_trace_class
*trace_class
)
407 BT_ASSERT_PRE_NO_ERROR();
409 return create_enumeration_field_class(trace_class
,
410 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
);
413 struct bt_field_class
*bt_field_class_enumeration_signed_create(
414 bt_trace_class
*trace_class
)
416 BT_ASSERT_PRE_NO_ERROR();
418 return create_enumeration_field_class(trace_class
,
419 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
);
422 uint64_t bt_field_class_enumeration_get_mapping_count(
423 const struct bt_field_class
*fc
)
425 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
427 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
428 BT_ASSERT_PRE_DEV_FC_IS_ENUM(fc
, "Field class");
429 return (uint64_t) enum_fc
->mappings
->len
;
432 const struct bt_field_class_enumeration_unsigned_mapping
*
433 bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
434 const struct bt_field_class
*fc
, uint64_t index
)
436 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
438 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
439 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
440 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
442 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
445 const struct bt_field_class_enumeration_signed_mapping
*
446 bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
447 const struct bt_field_class
*fc
, uint64_t index
)
449 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
451 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
452 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, enum_fc
->mappings
->len
);
453 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
455 return (const void *) BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, index
);
459 const struct bt_field_class_enumeration_mapping
*
460 borrow_enumeration_field_class_mapping_by_label(
461 const struct bt_field_class_enumeration
*fc
, const char *label
)
463 struct bt_field_class_enumeration_mapping
*mapping
= NULL
;
467 BT_ASSERT_PRE_DEV_NON_NULL(label
, "Label");
469 for (i
= 0; i
< fc
->mappings
->len
; i
++) {
470 struct bt_field_class_enumeration_mapping
*this_mapping
=
471 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(fc
, i
);
473 if (strcmp(this_mapping
->label
->str
, label
) == 0) {
474 mapping
= this_mapping
;
483 const struct bt_field_class_enumeration_signed_mapping
*
484 bt_field_class_enumeration_signed_borrow_mapping_by_label_const(
485 const struct bt_field_class
*fc
, const char *label
)
487 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
488 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
490 return (const void *) borrow_enumeration_field_class_mapping_by_label(
491 (const void *) fc
, label
);
494 const struct bt_field_class_enumeration_unsigned_mapping
*
495 bt_field_class_enumeration_unsigned_borrow_mapping_by_label_const(
496 const struct bt_field_class
*fc
, const char *label
)
498 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
499 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
500 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
, "Field class");
501 return (const void *) borrow_enumeration_field_class_mapping_by_label(
502 (const void *) fc
, label
);
505 const char *bt_field_class_enumeration_mapping_get_label(
506 const struct bt_field_class_enumeration_mapping
*mapping
)
508 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
509 return mapping
->label
->str
;
512 const struct bt_integer_range_set_unsigned
*
513 bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
514 const struct bt_field_class_enumeration_unsigned_mapping
*u_mapping
)
516 const struct bt_field_class_enumeration_mapping
*mapping
=
517 (const void *) u_mapping
;
519 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
520 return (const void *) mapping
->range_set
;
523 const struct bt_integer_range_set_signed
*
524 bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
525 const struct bt_field_class_enumeration_signed_mapping
*s_mapping
)
527 const struct bt_field_class_enumeration_mapping
*mapping
=
528 (const void *) s_mapping
;
530 BT_ASSERT_PRE_DEV_NON_NULL(mapping
, "Enumeration field class mapping");
531 return (const void *) mapping
->range_set
;
534 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
535 bt_field_class_enumeration_unsigned_get_mapping_labels_for_value(
536 const struct bt_field_class
*fc
, uint64_t value
,
537 bt_field_class_enumeration_mapping_label_array
*label_array
,
540 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
543 BT_ASSERT_PRE_DEV_NO_ERROR();
544 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
545 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
546 BT_ASSERT_PRE_DEV_NON_NULL(count
, "Count (output)");
547 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
549 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
551 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
553 const struct bt_field_class_enumeration_mapping
*mapping
=
554 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
556 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
557 const struct bt_integer_range
*range
= (const void *)
558 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
559 mapping
->range_set
, j
);
561 if (value
>= range
->lower
.u
&&
562 value
<= range
->upper
.u
) {
563 g_ptr_array_add(enum_fc
->label_buf
,
564 mapping
->label
->str
);
570 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
571 *count
= (uint64_t) enum_fc
->label_buf
->len
;
572 return BT_FUNC_STATUS_OK
;
575 enum bt_field_class_enumeration_get_mapping_labels_for_value_status
576 bt_field_class_enumeration_signed_get_mapping_labels_for_value(
577 const struct bt_field_class
*fc
, int64_t value
,
578 bt_field_class_enumeration_mapping_label_array
*label_array
,
581 const struct bt_field_class_enumeration
*enum_fc
= (const void *) fc
;
584 BT_ASSERT_PRE_DEV_NO_ERROR();
585 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
586 BT_ASSERT_PRE_DEV_NON_NULL(label_array
, "Label array (output)");
587 BT_ASSERT_PRE_DEV_NON_NULL(count
, "Count (output)");
588 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
590 g_ptr_array_set_size(enum_fc
->label_buf
, 0);
592 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
594 const struct bt_field_class_enumeration_mapping
*mapping
=
595 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
597 for (j
= 0; j
< mapping
->range_set
->ranges
->len
; j
++) {
598 const struct bt_integer_range
*range
= (const void *)
599 BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
600 mapping
->range_set
, j
);
602 if (value
>= range
->lower
.i
&&
603 value
<= range
->upper
.i
) {
604 g_ptr_array_add(enum_fc
->label_buf
,
605 mapping
->label
->str
);
611 *label_array
= (void *) enum_fc
->label_buf
->pdata
;
612 *count
= (uint64_t) enum_fc
->label_buf
->len
;
613 return BT_FUNC_STATUS_OK
;
617 bool enumeration_field_class_has_mapping_with_label(
618 const struct bt_field_class_enumeration
*enum_fc
,
627 for (i
= 0; i
< enum_fc
->mappings
->len
; i
++) {
628 struct bt_field_class_enumeration_mapping
*mapping_candidate
=
629 BT_FIELD_CLASS_ENUM_MAPPING_AT_INDEX(enum_fc
, i
);
631 if (strcmp(mapping_candidate
->label
->str
, label
) == 0) {
642 enum bt_field_class_enumeration_add_mapping_status
643 add_mapping_to_enumeration_field_class(struct bt_field_class
*fc
,
644 const char *label
, const struct bt_integer_range_set
*range_set
)
646 enum bt_field_class_enumeration_add_mapping_status status
=
648 struct bt_field_class_enumeration
*enum_fc
= (void *) fc
;
649 struct bt_field_class_enumeration_mapping mapping
= { 0 };
651 BT_ASSERT_PRE_NO_ERROR();
653 BT_ASSERT_PRE_NON_NULL(label
, "Label");
654 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
655 BT_ASSERT_PRE(!enumeration_field_class_has_mapping_with_label(
657 "Duplicate mapping name in enumeration field class: "
658 "%![enum-fc-]+F, label=\"%s\"", fc
, label
);
659 mapping
.range_set
= range_set
;
660 bt_object_get_ref(mapping
.range_set
);
661 mapping
.label
= g_string_new(label
);
662 if (!mapping
.label
) {
663 finalize_enumeration_field_class_mapping(&mapping
);
664 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
668 g_array_append_val(enum_fc
->mappings
, mapping
);
669 BT_LIB_LOGD("Added mapping to enumeration field class: "
670 "%![fc-]+F, label=\"%s\"", fc
, label
);
676 enum bt_field_class_enumeration_add_mapping_status
677 bt_field_class_enumeration_unsigned_add_mapping(
678 struct bt_field_class
*fc
, const char *label
,
679 const struct bt_integer_range_set_unsigned
*range_set
)
681 BT_ASSERT_PRE_NO_ERROR();
682 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
683 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
,
685 return add_mapping_to_enumeration_field_class(fc
, label
,
686 (const void *) range_set
);
689 enum bt_field_class_enumeration_add_mapping_status
690 bt_field_class_enumeration_signed_add_mapping(
691 struct bt_field_class
*fc
, const char *label
,
692 const struct bt_integer_range_set_signed
*range_set
)
694 BT_ASSERT_PRE_NO_ERROR();
695 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
696 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
,
698 return add_mapping_to_enumeration_field_class(fc
, label
,
699 (const void *) range_set
);
703 void destroy_real_field_class(struct bt_object
*obj
)
706 BT_LIB_LOGD("Destroying real field class object: %!+F", obj
);
707 finalize_field_class((void *) obj
);
712 struct bt_field_class
*create_real_field_class(bt_trace_class
*trace_class
,
713 enum bt_field_class_type type
)
715 struct bt_field_class_real
*real_fc
= NULL
;
717 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
718 BT_LOGD("Creating default real field class object: type=%s",
719 bt_common_field_class_type_string(type
));
720 real_fc
= g_new0(struct bt_field_class_real
, 1);
722 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
726 if (init_field_class((void *) real_fc
, type
, destroy_real_field_class
)) {
730 BT_LIB_LOGD("Created real field class object: %!+F", real_fc
);
734 BT_OBJECT_PUT_REF_AND_RESET(real_fc
);
737 return (void *) real_fc
;
740 struct bt_field_class
*bt_field_class_real_single_precision_create(
741 bt_trace_class
*trace_class
)
743 BT_ASSERT_PRE_NO_ERROR();
745 return create_real_field_class(trace_class
,
746 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
);
749 struct bt_field_class
*bt_field_class_real_double_precision_create(
750 bt_trace_class
*trace_class
)
752 BT_ASSERT_PRE_NO_ERROR();
754 return create_real_field_class(trace_class
,
755 BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
);
759 int init_named_field_classes_container(
760 struct bt_field_class_named_field_class_container
*fc
,
761 enum bt_field_class_type type
,
762 bt_object_release_func fc_release_func
,
763 GDestroyNotify named_fc_destroy_func
)
767 ret
= init_field_class((void *) fc
, type
, fc_release_func
);
772 fc
->named_fcs
= g_ptr_array_new_with_free_func(named_fc_destroy_func
);
773 if (!fc
->named_fcs
) {
774 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
779 fc
->name_to_index
= g_hash_table_new(g_str_hash
, g_str_equal
);
780 if (!fc
->name_to_index
) {
781 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GHashTable.");
791 void finalize_named_field_class(struct bt_named_field_class
*named_fc
)
794 BT_LIB_LOGD("Finalizing named field class: "
795 "addr=%p, name=\"%s\", %![fc-]+F",
796 named_fc
, named_fc
->name
? named_fc
->name
->str
: NULL
,
798 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
800 if (named_fc
->name
) {
801 g_string_free(named_fc
->name
, TRUE
);
802 named_fc
->name
= NULL
;
805 BT_LOGD_STR("Putting named field class's field class.");
806 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->fc
);
810 void destroy_named_field_class(gpointer ptr
)
812 struct bt_named_field_class
*named_fc
= ptr
;
815 BT_OBJECT_PUT_REF_AND_RESET(named_fc
->user_attributes
);
816 finalize_named_field_class(ptr
);
822 void destroy_variant_with_selector_field_option(gpointer ptr
)
824 struct bt_field_class_variant_with_selector_field_option
*opt
= ptr
;
827 finalize_named_field_class(&opt
->common
);
828 BT_OBJECT_PUT_REF_AND_RESET(opt
->range_set
);
834 void finalize_named_field_classes_container(
835 struct bt_field_class_named_field_class_container
*fc
)
840 g_ptr_array_free(fc
->named_fcs
, TRUE
);
841 fc
->named_fcs
= NULL
;
845 if (fc
->name_to_index
) {
846 g_hash_table_destroy(fc
->name_to_index
);
847 fc
->name_to_index
= NULL
;
852 void destroy_structure_field_class(struct bt_object
*obj
)
855 BT_LIB_LOGD("Destroying structure field class object: %!+F", obj
);
856 finalize_field_class((void *) obj
);
857 finalize_named_field_classes_container((void *) obj
);
861 struct bt_field_class
*bt_field_class_structure_create(
862 bt_trace_class
*trace_class
)
865 struct bt_field_class_structure
*struct_fc
= NULL
;
867 BT_ASSERT_PRE_NO_ERROR();
868 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
869 BT_LOGD_STR("Creating default structure field class object.");
870 struct_fc
= g_new0(struct bt_field_class_structure
, 1);
872 BT_LIB_LOGE_APPEND_CAUSE(
873 "Failed to allocate one structure field class.");
877 ret
= init_named_field_classes_container((void *) struct_fc
,
878 BT_FIELD_CLASS_TYPE_STRUCTURE
, destroy_structure_field_class
,
879 destroy_named_field_class
);
881 /* init_named_field_classes_container() logs errors */
885 BT_LIB_LOGD("Created structure field class object: %!+F", struct_fc
);
889 BT_OBJECT_PUT_REF_AND_RESET(struct_fc
);
892 return (void *) struct_fc
;
896 int init_named_field_class(struct bt_named_field_class
*named_fc
,
897 const char *name
, struct bt_field_class
*fc
)
899 int status
= BT_FUNC_STATUS_OK
;
904 named_fc
->name
= g_string_new(name
);
905 if (!named_fc
->name
) {
906 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
907 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
911 named_fc
->user_attributes
= bt_value_map_create();
912 if (!named_fc
->user_attributes
) {
913 BT_LIB_LOGE_APPEND_CAUSE(
914 "Failed to create a map value object.");
915 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
920 bt_object_get_ref_no_null_check(named_fc
->fc
);
927 struct bt_named_field_class
*create_named_field_class(const char *name
,
928 struct bt_field_class
*fc
)
930 struct bt_named_field_class
*named_fc
= g_new0(
931 struct bt_named_field_class
, 1);
934 BT_LIB_LOGE_APPEND_CAUSE(
935 "Failed to allocate a named field class.");
939 if (init_named_field_class(named_fc
, name
, fc
)) {
940 /* init_named_field_class() logs errors */
947 destroy_named_field_class(named_fc
);
955 struct bt_field_class_variant_with_selector_field_option
*
956 create_variant_with_selector_field_option(
957 const char *name
, struct bt_field_class
*fc
,
958 const struct bt_integer_range_set
*range_set
)
960 struct bt_field_class_variant_with_selector_field_option
*opt
= g_new0(
961 struct bt_field_class_variant_with_selector_field_option
, 1);
963 BT_ASSERT(range_set
);
966 BT_LIB_LOGE_APPEND_CAUSE(
967 "Failed to allocate a named field class.");
971 if (init_named_field_class(&opt
->common
, name
, fc
)) {
975 opt
->range_set
= range_set
;
976 bt_object_get_ref_no_null_check(opt
->range_set
);
977 bt_integer_range_set_freeze(range_set
);
981 destroy_variant_with_selector_field_option(opt
);
989 int append_named_field_class_to_container_field_class(
990 struct bt_field_class_named_field_class_container
*container_fc
,
991 struct bt_named_field_class
*named_fc
)
993 BT_ASSERT(container_fc
);
995 BT_ASSERT_PRE_DEV_FC_HOT(container_fc
, "Field class");
996 BT_ASSERT_PRE(!bt_g_hash_table_contains(container_fc
->name_to_index
,
997 named_fc
->name
->str
),
998 "Duplicate member/option name in structure/variant field class: "
999 "%![container-fc-]+F, name=\"%s\"", container_fc
,
1000 named_fc
->name
->str
);
1003 * Freeze the contained field class, but not the named field
1004 * class itself, as it's still possible afterwards to modify
1005 * properties of the member/option object.
1007 bt_field_class_freeze(named_fc
->fc
);
1008 g_ptr_array_add(container_fc
->named_fcs
, named_fc
);
1009 g_hash_table_insert(container_fc
->name_to_index
, named_fc
->name
->str
,
1010 GUINT_TO_POINTER(container_fc
->named_fcs
->len
- 1));
1011 return BT_FUNC_STATUS_OK
;
1014 enum bt_field_class_structure_append_member_status
1015 bt_field_class_structure_append_member(
1016 struct bt_field_class
*fc
, const char *name
,
1017 struct bt_field_class
*member_fc
)
1019 enum bt_field_class_structure_append_member_status status
;
1020 struct bt_named_field_class
*named_fc
= NULL
;
1022 BT_ASSERT_PRE_NO_ERROR();
1023 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1024 BT_ASSERT_PRE_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1026 named_fc
= create_named_field_class(name
, member_fc
);
1028 /* create_named_field_class() logs errors */
1029 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1033 status
= append_named_field_class_to_container_field_class((void *) fc
,
1035 if (status
== BT_FUNC_STATUS_OK
) {
1036 /* Moved to the container */
1044 uint64_t bt_field_class_structure_get_member_count(
1045 const struct bt_field_class
*fc
)
1047 struct bt_field_class_structure
*struct_fc
= (void *) fc
;
1049 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1050 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1052 return (uint64_t) struct_fc
->common
.named_fcs
->len
;
1056 struct bt_named_field_class
*
1057 borrow_named_field_class_from_container_field_class_at_index(
1058 struct bt_field_class_named_field_class_container
*fc
,
1062 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, fc
->named_fcs
->len
);
1063 return fc
->named_fcs
->pdata
[index
];
1066 const struct bt_field_class_structure_member
*
1067 bt_field_class_structure_borrow_member_by_index_const(
1068 const struct bt_field_class
*fc
, uint64_t index
)
1070 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1071 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1073 return (const void *)
1074 borrow_named_field_class_from_container_field_class_at_index(
1075 (void *) fc
, index
);
1078 struct bt_field_class_structure_member
*
1079 bt_field_class_structure_borrow_member_by_index(
1080 struct bt_field_class
*fc
, uint64_t index
)
1082 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1083 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1086 borrow_named_field_class_from_container_field_class_at_index(
1087 (void *) fc
, index
);
1091 struct bt_named_field_class
*
1092 borrow_named_field_class_from_container_field_class_by_name(
1093 struct bt_field_class_named_field_class_container
*fc
,
1096 struct bt_named_field_class
*named_fc
= NULL
;
1101 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Name");
1102 if (!g_hash_table_lookup_extended(fc
->name_to_index
, name
, &orig_key
,
1107 named_fc
= fc
->named_fcs
->pdata
[GPOINTER_TO_UINT(value
)];
1113 const struct bt_field_class_structure_member
*
1114 bt_field_class_structure_borrow_member_by_name_const(
1115 const struct bt_field_class
*fc
, const char *name
)
1117 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1118 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1120 return (const void *)
1121 borrow_named_field_class_from_container_field_class_by_name(
1125 struct bt_field_class_structure_member
*
1126 bt_field_class_structure_borrow_member_by_name(
1127 struct bt_field_class
*fc
, const char *name
)
1129 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1130 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STRUCTURE
,
1133 borrow_named_field_class_from_container_field_class_by_name(
1137 const char *bt_field_class_structure_member_get_name(
1138 const struct bt_field_class_structure_member
*member
)
1140 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1142 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1143 return named_fc
->name
->str
;
1146 const struct bt_field_class
*
1147 bt_field_class_structure_member_borrow_field_class_const(
1148 const struct bt_field_class_structure_member
*member
)
1150 const struct bt_named_field_class
*named_fc
= (const void *) member
;
1152 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1153 return named_fc
->fc
;
1156 struct bt_field_class
*
1157 bt_field_class_structure_member_borrow_field_class(
1158 struct bt_field_class_structure_member
*member
)
1160 struct bt_named_field_class
*named_fc
= (void *) member
;
1162 BT_ASSERT_PRE_DEV_NON_NULL(member
, "Structure field class member");
1163 return named_fc
->fc
;
1167 void destroy_option_field_class(struct bt_object
*obj
)
1169 struct bt_field_class_option
*fc
= (void *) obj
;
1172 BT_LIB_LOGD("Destroying option field class object: %!+F", fc
);
1173 finalize_field_class((void *) obj
);
1174 BT_LOGD_STR("Putting content field class.");
1175 BT_OBJECT_PUT_REF_AND_RESET(fc
->content_fc
);
1177 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1178 struct bt_field_class_option_with_selector_field
*with_sel_fc
=
1181 BT_LOGD_STR("Putting selector field path.");
1182 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_field_path
);
1183 BT_LOGD_STR("Putting selector field class.");
1184 BT_OBJECT_PUT_REF_AND_RESET(with_sel_fc
->selector_fc
);
1186 if (fc
->common
.type
!= BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1187 struct bt_field_class_option_with_selector_field_integer
*with_int_sel_fc
=
1190 BT_LOGD_STR("Putting integer range set.");
1191 BT_OBJECT_PUT_REF_AND_RESET(with_int_sel_fc
->range_set
);
1199 struct bt_field_class
*create_option_field_class(
1200 struct bt_trace_class
*trace_class
,
1201 enum bt_field_class_type fc_type
,
1202 struct bt_field_class
*content_fc
,
1203 struct bt_field_class
*selector_fc
)
1205 struct bt_field_class_option
*opt_fc
= NULL
;
1207 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1208 BT_ASSERT_PRE_NON_NULL(content_fc
, "Content field class");
1209 BT_LIB_LOGD("Creating option field class: "
1210 "type=%s, %![content-fc-]+F, %![sel-fc-]+F",
1211 bt_common_field_class_type_string(fc_type
),
1212 content_fc
, selector_fc
);
1214 if (fc_type
!= BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
1215 struct bt_field_class_option_with_selector_field
*opt_with_sel_fc
= NULL
;
1217 BT_ASSERT_PRE_NON_NULL(selector_fc
, "Selector field class");
1219 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
1220 BT_ASSERT_PRE_FC_HAS_ID(selector_fc
,
1221 BT_FIELD_CLASS_TYPE_BOOL
,
1222 "Selector field class");
1223 opt_with_sel_fc
= (void *) g_new0(
1224 struct bt_field_class_option_with_selector_field_bool
, 1);
1226 BT_ASSERT_PRE_FC_IS_INT(selector_fc
,
1227 "Selector field class");
1228 opt_with_sel_fc
= (void *) g_new0(
1229 struct bt_field_class_option_with_selector_field_integer
, 1);
1232 if (!opt_with_sel_fc
) {
1233 BT_LIB_LOGE_APPEND_CAUSE(
1234 "Failed to allocate one option with selector field class.");
1238 opt_with_sel_fc
->selector_fc
= selector_fc
;
1239 bt_object_get_ref_no_null_check(opt_with_sel_fc
->selector_fc
);
1240 opt_fc
= (void *) opt_with_sel_fc
;
1242 opt_fc
= g_new0(struct bt_field_class_option
, 1);
1244 BT_LIB_LOGE_APPEND_CAUSE(
1245 "Failed to allocate one option field class.");
1252 if (init_field_class((void *) opt_fc
, fc_type
,
1253 destroy_option_field_class
)) {
1257 opt_fc
->content_fc
= content_fc
;
1258 bt_object_get_ref_no_null_check(opt_fc
->content_fc
);
1259 bt_field_class_freeze(opt_fc
->content_fc
);
1262 bt_field_class_freeze(selector_fc
);
1265 BT_LIB_LOGD("Created option field class object: "
1266 "%![opt-fc-]+F, %![sel-fc-]+F", opt_fc
, selector_fc
);
1270 BT_OBJECT_PUT_REF_AND_RESET(opt_fc
);
1273 return (void *) opt_fc
;
1276 struct bt_field_class
*bt_field_class_option_without_selector_create(
1277 struct bt_trace_class
*trace_class
,
1278 struct bt_field_class
*content_fc
)
1280 BT_ASSERT_PRE_NO_ERROR();
1282 return create_option_field_class(trace_class
,
1283 BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
,
1287 struct bt_field_class
*bt_field_class_option_with_selector_field_bool_create(
1288 struct bt_trace_class
*trace_class
,
1289 struct bt_field_class
*content_fc
,
1290 struct bt_field_class
*selector_fc
)
1292 BT_ASSERT_PRE_NO_ERROR();
1294 return create_option_field_class(trace_class
,
1295 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
,
1296 content_fc
, selector_fc
);
1299 struct bt_field_class
*
1300 bt_field_class_option_with_selector_field_integer_unsigned_create(
1301 struct bt_trace_class
*trace_class
,
1302 struct bt_field_class
*content_fc
,
1303 struct bt_field_class
*selector_fc
,
1304 const struct bt_integer_range_set_unsigned
*u_range_set
)
1306 struct bt_field_class_option_with_selector_field_integer
*fc
;
1307 const struct bt_integer_range_set
*range_set
=
1308 (const void *) u_range_set
;
1310 BT_ASSERT_PRE_NO_ERROR();
1311 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1312 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1313 "Integer range set is empty: %!+R", range_set
);
1314 fc
= (void *) create_option_field_class(trace_class
,
1315 BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1316 content_fc
, selector_fc
);
1322 fc
->range_set
= range_set
;
1323 bt_object_get_ref_no_null_check(fc
->range_set
);
1324 bt_integer_range_set_freeze(range_set
);
1330 struct bt_field_class
*
1331 bt_field_class_option_with_selector_field_integer_signed_create(
1332 struct bt_trace_class
*trace_class
,
1333 struct bt_field_class
*content_fc
,
1334 struct bt_field_class
*selector_fc
,
1335 const struct bt_integer_range_set_signed
*i_range_set
)
1337 struct bt_field_class_option_with_selector_field_integer
*fc
;
1338 const struct bt_integer_range_set
*range_set
=
1339 (const void *) i_range_set
;
1341 BT_ASSERT_PRE_NO_ERROR();
1342 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1343 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1344 "Integer range set is empty: %!+R", range_set
);
1345 fc
= (void *) create_option_field_class(trace_class
,
1346 BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1347 content_fc
, selector_fc
);
1353 fc
->range_set
= range_set
;
1354 bt_object_get_ref_no_null_check(fc
->range_set
);
1355 bt_integer_range_set_freeze(range_set
);
1361 const struct bt_field_class
*bt_field_class_option_borrow_field_class_const(
1362 const struct bt_field_class
*fc
)
1364 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1366 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1367 BT_ASSERT_PRE_FC_IS_OPTION(fc
, "Field class");
1368 return opt_fc
->content_fc
;
1371 struct bt_field_class
*bt_field_class_option_borrow_field_class(
1372 struct bt_field_class
*fc
)
1374 struct bt_field_class_option
*opt_fc
= (void *) fc
;
1376 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1377 BT_ASSERT_PRE_FC_IS_OPTION(fc
, "Field class");
1378 return opt_fc
->content_fc
;
1381 const struct bt_field_path
*
1382 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
1383 const struct bt_field_class
*fc
)
1385 const struct bt_field_class_option_with_selector_field
*opt_fc
=
1388 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1389 BT_ASSERT_PRE_FC_IS_OPTION_WITH_SEL(fc
, "Field class");
1390 return opt_fc
->selector_field_path
;
1393 void bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
1394 struct bt_field_class
*fc
, bt_bool sel_is_reversed
)
1396 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1398 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1399 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1400 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
, "Field class");
1401 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
1402 opt_fc
->sel_is_reversed
= sel_is_reversed
;
1405 bt_bool
bt_field_class_option_with_selector_field_bool_selector_is_reversed(
1406 const struct bt_field_class
*fc
)
1408 struct bt_field_class_option_with_selector_field_bool
*opt_fc
= (void *) fc
;
1410 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1411 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1412 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
, "Field class");
1413 return opt_fc
->sel_is_reversed
;
1416 const struct bt_integer_range_set_unsigned
*
1417 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
1418 const struct bt_field_class
*fc
)
1420 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1423 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1424 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc
, "Field class");
1425 return (const void *) opt_fc
->range_set
;
1428 const struct bt_integer_range_set_signed
*
1429 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
1430 const struct bt_field_class
*fc
)
1432 struct bt_field_class_option_with_selector_field_integer
*opt_fc
=
1435 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1436 BT_ASSERT_PRE_FC_IS_OPTION_WITH_INT_SEL(fc
, "Field class");
1437 return (const void *) opt_fc
->range_set
;
1441 void finalize_variant_field_class(struct bt_field_class_variant
*var_fc
)
1444 BT_LIB_LOGD("Finalizing variant field class object: %!+F", var_fc
);
1445 finalize_field_class((void *) var_fc
);
1446 finalize_named_field_classes_container((void *) var_fc
);
1450 void destroy_variant_field_class(struct bt_object
*obj
)
1452 struct bt_field_class_variant
*fc
= (void *) obj
;
1455 finalize_variant_field_class(fc
);
1460 void destroy_variant_with_selector_field_field_class(struct bt_object
*obj
)
1462 struct bt_field_class_variant_with_selector_field
*fc
= (void *) obj
;
1465 finalize_variant_field_class(&fc
->common
);
1466 BT_LOGD_STR("Putting selector field path.");
1467 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_field_path
);
1468 BT_LOGD_STR("Putting selector field class.");
1469 BT_OBJECT_PUT_REF_AND_RESET(fc
->selector_fc
);
1473 struct bt_field_class
*bt_field_class_variant_create(
1474 bt_trace_class
*trace_class
, bt_field_class
*selector_fc
)
1477 struct bt_field_class_variant
*var_fc
= NULL
;
1478 struct bt_field_class_variant_with_selector_field
*var_with_sel_fc
= NULL
;
1479 enum bt_field_class_type fc_type
;
1481 BT_ASSERT_PRE_NO_ERROR();
1482 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1485 BT_ASSERT_PRE_FC_IS_INT(selector_fc
, "Selector field class");
1488 BT_LIB_LOGD("Creating default variant field class: %![sel-fc-]+F",
1492 var_with_sel_fc
= g_new0(
1493 struct bt_field_class_variant_with_selector_field
, 1);
1494 if (!var_with_sel_fc
) {
1495 BT_LIB_LOGE_APPEND_CAUSE(
1496 "Failed to allocate one variant field class with selector.");
1500 if (bt_field_class_type_is(selector_fc
->type
,
1501 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
)) {
1502 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
;
1504 fc_type
= BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
;
1507 ret
= init_named_field_classes_container(
1508 (void *) var_with_sel_fc
, fc_type
,
1509 destroy_variant_with_selector_field_field_class
,
1510 destroy_variant_with_selector_field_option
);
1512 /* init_named_field_classes_container() logs errors */
1516 var_with_sel_fc
->selector_fc
= selector_fc
;
1517 bt_object_get_ref_no_null_check(var_with_sel_fc
->selector_fc
);
1518 bt_field_class_freeze(selector_fc
);
1519 var_fc
= (void *) var_with_sel_fc
;
1520 BT_LIB_LOGD("Created default variant field class with selector object: "
1521 "%![var-fc-]+F, %![sel-fc-]+F", var_fc
, selector_fc
);
1523 var_fc
= g_new0(struct bt_field_class_variant
, 1);
1525 BT_LIB_LOGE_APPEND_CAUSE(
1526 "Failed to allocate one variant field class without selector.");
1530 ret
= init_named_field_classes_container((void *) var_fc
,
1531 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
,
1532 destroy_variant_field_class
, destroy_named_field_class
);
1534 /* init_named_field_classes_container() logs errors */
1537 BT_LIB_LOGD("Created default variant field class without selector object: "
1538 "%![var-fc-]+F", var_fc
);
1545 BT_OBJECT_PUT_REF_AND_RESET(var_fc
);
1546 BT_OBJECT_PUT_REF_AND_RESET(var_with_sel_fc
);
1549 return (void *) var_fc
;
1552 enum bt_field_class_variant_without_selector_append_option_status
1553 bt_field_class_variant_without_selector_append_option(struct bt_field_class
*fc
,
1554 const char *name
, struct bt_field_class
*option_fc
)
1556 enum bt_field_class_variant_without_selector_append_option_status status
;
1557 struct bt_named_field_class
*named_fc
= NULL
;
1559 BT_ASSERT_PRE_NO_ERROR();
1560 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1561 BT_ASSERT_PRE_NON_NULL(name
, "Name");
1562 BT_ASSERT_PRE_NON_NULL(option_fc
, "Option field class");
1563 BT_ASSERT_PRE_FC_HAS_ID(fc
,
1564 BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
, "Field class");
1565 named_fc
= create_named_field_class(name
, option_fc
);
1567 /* create_named_field_class() logs errors */
1568 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1572 status
= append_named_field_class_to_container_field_class((void *) fc
,
1574 if (status
== BT_FUNC_STATUS_OK
) {
1575 /* Moved to the container */
1581 destroy_named_field_class(named_fc
);
1588 int ranges_overlap(GPtrArray
*var_fc_opts
, const struct bt_integer_range_set
*range_set
,
1589 bool is_signed
, bool *has_overlap
)
1591 int status
= BT_FUNC_STATUS_OK
;
1592 struct bt_integer_range_set
*full_range_set
;
1595 *has_overlap
= false;
1598 * Build a single range set with all the ranges and test for
1602 full_range_set
= (void *) bt_integer_range_set_signed_create();
1604 full_range_set
= (void *) bt_integer_range_set_unsigned_create();
1607 if (!full_range_set
) {
1608 BT_LOGE_STR("Failed to create a range set.");
1609 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1613 /* Add existing option ranges */
1614 for (i
= 0; i
< var_fc_opts
->len
; i
++) {
1615 struct bt_field_class_variant_with_selector_field_option
*opt
=
1616 var_fc_opts
->pdata
[i
];
1619 for (j
= 0; j
< opt
->range_set
->ranges
->len
; j
++) {
1620 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1624 status
= bt_integer_range_set_signed_add_range(
1625 (void *) full_range_set
, range
->lower
.i
,
1628 status
= bt_integer_range_set_unsigned_add_range(
1629 (void *) full_range_set
, range
->lower
.u
,
1639 /* Add new ranges */
1640 for (i
= 0; i
< range_set
->ranges
->len
; i
++) {
1641 struct bt_integer_range
*range
= BT_INTEGER_RANGE_SET_RANGE_AT_INDEX(
1645 status
= bt_integer_range_set_signed_add_range(
1646 (void *) full_range_set
, range
->lower
.i
,
1649 status
= bt_integer_range_set_unsigned_add_range(
1650 (void *) full_range_set
, range
->lower
.u
,
1659 /* Check overlaps */
1661 *has_overlap
= bt_integer_range_set_signed_has_overlaps(full_range_set
);
1663 *has_overlap
= bt_integer_range_set_unsigned_has_overlaps(
1668 bt_object_put_ref(full_range_set
);
1673 int append_option_to_variant_with_selector_field_field_class(
1674 struct bt_field_class
*fc
, const char *name
,
1675 struct bt_field_class
*option_fc
,
1676 const struct bt_integer_range_set
*range_set
,
1677 enum bt_field_class_type expected_type
)
1680 struct bt_field_class_variant_with_selector_field
*var_fc
= (void *) fc
;
1681 struct bt_field_class_variant_with_selector_field_option
*opt
= NULL
;
1684 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
1685 BT_ASSERT_PRE_NON_NULL(name
, "Name");
1686 BT_ASSERT_PRE_NON_NULL(option_fc
, "Option field class");
1687 BT_ASSERT_PRE_NON_NULL(range_set
, "Integer range set");
1688 BT_ASSERT_PRE_FC_HAS_ID(fc
, expected_type
, "Field class");
1689 BT_ASSERT_PRE(range_set
->ranges
->len
> 0,
1690 "Integer range set is empty: %!+R", range_set
);
1691 status
= ranges_overlap(var_fc
->common
.common
.named_fcs
, range_set
,
1692 expected_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1695 /* ranges_overlap() logs errors */
1699 BT_ASSERT_PRE(!has_overlap
,
1700 "Integer range set's ranges and existing ranges have an overlap: "
1702 opt
= create_variant_with_selector_field_option(name
, option_fc
, range_set
);
1704 /* create_variant_with_selector_field_option() logs errors */
1705 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
1709 status
= append_named_field_class_to_container_field_class((void *) fc
,
1711 if (status
== BT_FUNC_STATUS_OK
) {
1712 /* Moved to the container */
1718 destroy_variant_with_selector_field_option(opt
);
1724 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1725 bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
1726 struct bt_field_class
*fc
, const char *name
,
1727 struct bt_field_class
*option_fc
,
1728 const struct bt_integer_range_set_unsigned
*range_set
)
1730 BT_ASSERT_PRE_NO_ERROR();
1732 return append_option_to_variant_with_selector_field_field_class(fc
,
1733 name
, option_fc
, (const void *) range_set
,
1734 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
);
1737 enum bt_field_class_variant_with_selector_field_integer_append_option_status
1738 bt_field_class_variant_with_selector_field_integer_signed_append_option(
1739 struct bt_field_class
*fc
, const char *name
,
1740 struct bt_field_class
*option_fc
,
1741 const struct bt_integer_range_set_signed
*range_set
)
1743 BT_ASSERT_PRE_NO_ERROR();
1745 return append_option_to_variant_with_selector_field_field_class(fc
,
1746 name
, option_fc
, (const void *) range_set
,
1747 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
);
1750 uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class
*fc
)
1752 const struct bt_field_class_variant
*var_fc
= (const void *) fc
;
1754 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1755 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1756 return (uint64_t) var_fc
->common
.named_fcs
->len
;
1759 const struct bt_field_class_variant_option
*
1760 bt_field_class_variant_borrow_option_by_name_const(
1761 const struct bt_field_class
*fc
, const char *name
)
1763 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1764 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1765 return (const void *)
1766 borrow_named_field_class_from_container_field_class_by_name(
1770 const struct bt_field_class_variant_option
*
1771 bt_field_class_variant_borrow_option_by_index_const(
1772 const struct bt_field_class
*fc
, uint64_t index
)
1774 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1775 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1776 return (const void *)
1777 borrow_named_field_class_from_container_field_class_at_index(
1778 (void *) fc
, index
);
1781 struct bt_field_class_variant_option
*
1782 bt_field_class_variant_borrow_option_by_name(
1783 struct bt_field_class
*fc
, const char *name
)
1785 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1786 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1788 borrow_named_field_class_from_container_field_class_by_name(
1792 struct bt_field_class_variant_option
*
1793 bt_field_class_variant_borrow_option_by_index(
1794 struct bt_field_class
*fc
, uint64_t index
)
1796 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1797 BT_ASSERT_PRE_DEV_FC_IS_VARIANT(fc
, "Field class");
1799 borrow_named_field_class_from_container_field_class_at_index(
1800 (void *) fc
, index
);
1803 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1804 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_name_const(
1805 const struct bt_field_class
*fc
, const char *name
)
1807 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1808 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1809 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1811 return (const void *)
1812 borrow_named_field_class_from_container_field_class_by_name(
1816 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*
1817 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
1818 const struct bt_field_class
*fc
, uint64_t index
)
1820 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1821 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1822 BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
,
1824 return (const void *)
1825 borrow_named_field_class_from_container_field_class_at_index(
1826 (void *) fc
, index
);
1829 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1830 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_name_const(
1831 const struct bt_field_class
*fc
, const char *name
)
1833 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1834 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1835 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1837 return (const void *)
1838 borrow_named_field_class_from_container_field_class_by_name(
1842 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*
1843 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
1844 const struct bt_field_class
*fc
, uint64_t index
)
1846 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1847 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
1848 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
,
1850 return (const void *)
1851 borrow_named_field_class_from_container_field_class_at_index(
1852 (void *) fc
, index
);
1855 const char *bt_field_class_variant_option_get_name(
1856 const struct bt_field_class_variant_option
*option
)
1858 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1860 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1861 return named_fc
->name
->str
;
1864 const struct bt_field_class
*
1865 bt_field_class_variant_option_borrow_field_class_const(
1866 const struct bt_field_class_variant_option
*option
)
1868 const struct bt_named_field_class
*named_fc
= (const void *) option
;
1870 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1871 return named_fc
->fc
;
1874 struct bt_field_class
*
1875 bt_field_class_variant_option_borrow_field_class(
1876 struct bt_field_class_variant_option
*option
)
1878 struct bt_named_field_class
*named_fc
= (void *) option
;
1880 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1881 return named_fc
->fc
;
1884 const struct bt_integer_range_set_unsigned
*
1885 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
1886 const struct bt_field_class_variant_with_selector_field_integer_unsigned_option
*option
)
1888 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1889 (const void *) option
;
1891 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1892 return (const void *) opt
->range_set
;
1895 const struct bt_integer_range_set_signed
*
1896 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
1897 const struct bt_field_class_variant_with_selector_field_integer_signed_option
*option
)
1899 const struct bt_field_class_variant_with_selector_field_option
*opt
=
1900 (const void *) option
;
1902 BT_ASSERT_PRE_DEV_NON_NULL(option
, "Variant field class option");
1903 return (const void *) opt
->range_set
;
1906 const struct bt_field_path
*
1907 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
1908 const struct bt_field_class
*fc
)
1910 const struct bt_field_class_variant_with_selector_field
*var_fc
=
1913 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1914 BT_ASSERT_PRE_DEV_FC_IS_VARIANT_WITH_SEL(fc
, "Field class");
1915 return var_fc
->selector_field_path
;
1919 int init_array_field_class(struct bt_field_class_array
*fc
,
1920 enum bt_field_class_type type
, bt_object_release_func release_func
,
1921 struct bt_field_class
*element_fc
)
1925 BT_ASSERT(element_fc
);
1926 ret
= init_field_class((void *) fc
, type
, release_func
);
1931 fc
->element_fc
= element_fc
;
1932 bt_object_get_ref_no_null_check(fc
->element_fc
);
1933 bt_field_class_freeze(element_fc
);
1940 void finalize_array_field_class(struct bt_field_class_array
*array_fc
)
1942 BT_ASSERT(array_fc
);
1943 BT_LOGD_STR("Putting element field class.");
1944 finalize_field_class((void *) array_fc
);
1945 BT_OBJECT_PUT_REF_AND_RESET(array_fc
->element_fc
);
1949 void destroy_static_array_field_class(struct bt_object
*obj
)
1952 BT_LIB_LOGD("Destroying static array field class object: %!+F", obj
);
1953 finalize_array_field_class((void *) obj
);
1957 struct bt_field_class
*
1958 bt_field_class_array_static_create(bt_trace_class
*trace_class
,
1959 struct bt_field_class
*element_fc
, uint64_t length
)
1961 struct bt_field_class_array_static
*array_fc
= NULL
;
1963 BT_ASSERT_PRE_NO_ERROR();
1964 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
1965 BT_ASSERT_PRE_NON_NULL(element_fc
, "Element field class");
1966 BT_LOGD_STR("Creating default static array field class object.");
1967 array_fc
= g_new0(struct bt_field_class_array_static
, 1);
1969 BT_LIB_LOGE_APPEND_CAUSE(
1970 "Failed to allocate one static array field class.");
1974 if (init_array_field_class((void *) array_fc
,
1975 BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
1976 destroy_static_array_field_class
, element_fc
)) {
1980 array_fc
->length
= length
;
1981 BT_LIB_LOGD("Created static array field class object: %!+F", array_fc
);
1985 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
1988 return (void *) array_fc
;
1991 const struct bt_field_class
*
1992 bt_field_class_array_borrow_element_field_class_const(
1993 const struct bt_field_class
*fc
)
1995 const struct bt_field_class_array
*array_fc
= (const void *) fc
;
1997 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
1998 BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc
, "Field class");
1999 return array_fc
->element_fc
;
2002 struct bt_field_class
*
2003 bt_field_class_array_borrow_element_field_class(struct bt_field_class
*fc
)
2005 struct bt_field_class_array
*array_fc
= (void *) fc
;
2007 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2008 BT_ASSERT_PRE_DEV_FC_IS_ARRAY(fc
, "Field class");
2009 return array_fc
->element_fc
;
2012 uint64_t bt_field_class_array_static_get_length(const struct bt_field_class
*fc
)
2014 const struct bt_field_class_array_static
*array_fc
= (const void *) fc
;
2016 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2017 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
, BT_FIELD_CLASS_TYPE_STATIC_ARRAY
,
2019 return (uint64_t) array_fc
->length
;
2023 void destroy_dynamic_array_field_class(struct bt_object
*obj
)
2025 struct bt_field_class_array_dynamic
*fc
= (void *) obj
;
2028 BT_LIB_LOGD("Destroying dynamic array field class object: %!+F", fc
);
2029 finalize_array_field_class((void *) fc
);
2030 BT_LOGD_STR("Putting length field path.");
2031 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_field_path
);
2032 BT_LOGD_STR("Putting length field class.");
2033 BT_OBJECT_PUT_REF_AND_RESET(fc
->length_fc
);
2037 struct bt_field_class
*bt_field_class_array_dynamic_create(
2038 struct bt_trace_class
*trace_class
,
2039 struct bt_field_class
*element_fc
,
2040 struct bt_field_class
*length_fc
)
2042 struct bt_field_class_array_dynamic
*array_fc
= NULL
;
2044 BT_ASSERT_PRE_NO_ERROR();
2045 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
2046 BT_ASSERT_PRE_NON_NULL(element_fc
, "Element field class");
2047 BT_LOGD_STR("Creating default dynamic array field class object.");
2048 array_fc
= g_new0(struct bt_field_class_array_dynamic
, 1);
2050 BT_LIB_LOGE_APPEND_CAUSE(
2051 "Failed to allocate one dynamic array field class.");
2055 if (init_array_field_class((void *) array_fc
,
2057 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
2058 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
,
2059 destroy_dynamic_array_field_class
, element_fc
)) {
2064 BT_ASSERT_PRE_FC_IS_UNSIGNED_INT(length_fc
,
2065 "Length field class");
2066 array_fc
->length_fc
= length_fc
;
2067 bt_object_get_ref_no_null_check(array_fc
->length_fc
);
2068 bt_field_class_freeze(length_fc
);
2071 BT_LIB_LOGD("Created dynamic array field class object: %!+F", array_fc
);
2075 BT_OBJECT_PUT_REF_AND_RESET(array_fc
);
2078 return (void *) array_fc
;
2081 const struct bt_field_path
*
2082 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
2083 const struct bt_field_class
*fc
)
2085 const struct bt_field_class_array_dynamic
*seq_fc
= (const void *) fc
;
2087 BT_ASSERT_PRE_NO_ERROR();
2088 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2089 BT_ASSERT_PRE_DEV_FC_HAS_ID(fc
,
2090 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
,
2092 return seq_fc
->length_field_path
;
2096 void destroy_string_field_class(struct bt_object
*obj
)
2099 BT_LIB_LOGD("Destroying string field class object: %!+F", obj
);
2100 finalize_field_class((void *) obj
);
2104 struct bt_field_class
*bt_field_class_string_create(bt_trace_class
*trace_class
)
2106 struct bt_field_class_string
*string_fc
= NULL
;
2108 BT_ASSERT_PRE_NO_ERROR();
2109 BT_ASSERT_PRE_NON_NULL(trace_class
, "Trace class");
2110 BT_LOGD_STR("Creating default string field class object.");
2111 string_fc
= g_new0(struct bt_field_class_string
, 1);
2113 BT_LIB_LOGE_APPEND_CAUSE(
2114 "Failed to allocate one string field class.");
2118 if (init_field_class((void *) string_fc
, BT_FIELD_CLASS_TYPE_STRING
,
2119 destroy_string_field_class
)) {
2123 BT_LIB_LOGD("Created string field class object: %!+F", string_fc
);
2127 BT_OBJECT_PUT_REF_AND_RESET(string_fc
);
2130 return (void *) string_fc
;
2134 void _bt_field_class_freeze(const struct bt_field_class
*c_fc
)
2136 struct bt_field_class
*fc
= (void *) c_fc
;
2139 * Element/member/option field classes are frozen when added to
2143 bt_value_freeze(fc
->user_attributes
);
2146 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2147 bt_field_class_type_is(fc
->type
,
2148 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2149 struct bt_field_class_named_field_class_container
*container_fc
=
2153 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2154 bt_named_field_class_freeze(
2155 container_fc
->named_fcs
->pdata
[i
]);
2161 void _bt_named_field_class_freeze(const struct bt_named_field_class
*named_fc
)
2163 BT_ASSERT(named_fc
);
2164 BT_ASSERT(named_fc
->fc
->frozen
);
2165 BT_LIB_LOGD("Freezing named field class's user attributes: %!+v",
2166 named_fc
->user_attributes
);
2167 bt_value_freeze(named_fc
->user_attributes
);
2168 ((struct bt_named_field_class
*) named_fc
)->frozen
= true;
2172 void bt_field_class_make_part_of_trace_class(const struct bt_field_class
*c_fc
)
2174 struct bt_field_class
*fc
= (void *) c_fc
;
2177 BT_ASSERT_PRE(!fc
->part_of_trace_class
,
2178 "Field class is already part of a trace: %!+F", fc
);
2179 fc
->part_of_trace_class
= true;
2181 if (fc
->type
== BT_FIELD_CLASS_TYPE_STRUCTURE
||
2182 bt_field_class_type_is(fc
->type
,
2183 BT_FIELD_CLASS_TYPE_VARIANT
)) {
2184 struct bt_field_class_named_field_class_container
*container_fc
=
2188 for (i
= 0; i
< container_fc
->named_fcs
->len
; i
++) {
2189 struct bt_named_field_class
*named_fc
=
2190 container_fc
->named_fcs
->pdata
[i
];
2192 bt_field_class_make_part_of_trace_class(named_fc
->fc
);
2194 } else if (bt_field_class_type_is(fc
->type
,
2195 BT_FIELD_CLASS_TYPE_ARRAY
)) {
2196 struct bt_field_class_array
*array_fc
= (void *) fc
;
2198 bt_field_class_make_part_of_trace_class(array_fc
->element_fc
);
2202 const struct bt_value
*bt_field_class_borrow_user_attributes_const(
2203 const struct bt_field_class
*fc
)
2205 BT_ASSERT_PRE_DEV_NON_NULL(fc
, "Field class");
2206 return fc
->user_attributes
;
2209 struct bt_value
*bt_field_class_borrow_user_attributes(
2210 struct bt_field_class
*field_class
)
2212 return (void *) bt_field_class_borrow_user_attributes_const(
2213 (void *) field_class
);
2217 void bt_field_class_set_user_attributes(
2218 struct bt_field_class
*fc
,
2219 const struct bt_value
*user_attributes
)
2221 BT_ASSERT_PRE_NON_NULL(fc
, "Field class");
2222 BT_ASSERT_PRE_NON_NULL(user_attributes
, "User attributes");
2223 BT_ASSERT_PRE(user_attributes
->type
== BT_VALUE_TYPE_MAP
,
2224 "User attributes object is not a map value object.");
2225 BT_ASSERT_PRE_DEV_FC_HOT(fc
, "Field class");
2226 bt_object_put_ref_no_null_check(fc
->user_attributes
);
2227 fc
->user_attributes
= (void *) user_attributes
;
2228 bt_object_get_ref_no_null_check(fc
->user_attributes
);
2232 const struct bt_value
*bt_named_field_class_borrow_user_attributes_const(
2233 const struct bt_named_field_class
*named_fc
)
2235 return named_fc
->user_attributes
;
2239 void bt_named_field_class_set_user_attributes(
2240 struct bt_named_field_class
*named_fc
,
2241 const struct bt_value
*user_attributes
)
2243 BT_ASSERT_PRE_NON_NULL(user_attributes
, "User attributes");
2244 BT_ASSERT_PRE(user_attributes
->type
== BT_VALUE_TYPE_MAP
,
2245 "User attributes object is not a map value object.");
2246 BT_ASSERT_PRE_DEV_HOT(named_fc
,
2247 "Structure field class member or variant field class option",
2249 bt_object_put_ref_no_null_check(named_fc
->user_attributes
);
2250 named_fc
->user_attributes
= (void *) user_attributes
;
2251 bt_object_get_ref_no_null_check(named_fc
->user_attributes
);
2254 const struct bt_value
*
2255 bt_field_class_structure_member_borrow_user_attributes_const(
2256 const struct bt_field_class_structure_member
*member
)
2258 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2259 return bt_named_field_class_borrow_user_attributes_const(
2260 (const void *) member
);
2264 bt_field_class_structure_member_borrow_user_attributes(
2265 struct bt_field_class_structure_member
*member
)
2267 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2268 return (void *) bt_named_field_class_borrow_user_attributes_const(
2272 void bt_field_class_structure_member_set_user_attributes(
2273 struct bt_field_class_structure_member
*member
,
2274 const struct bt_value
*user_attributes
)
2276 BT_ASSERT_PRE_NON_NULL(member
, "Structure field class member");
2277 bt_named_field_class_set_user_attributes((void *) member
,
2281 const struct bt_value
*bt_field_class_variant_option_borrow_user_attributes_const(
2282 const struct bt_field_class_variant_option
*option
)
2284 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2285 return bt_named_field_class_borrow_user_attributes_const(
2286 (const void *) option
);
2289 struct bt_value
*bt_field_class_variant_option_borrow_user_attributes(
2290 struct bt_field_class_variant_option
*option
)
2292 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2293 return (void *) bt_named_field_class_borrow_user_attributes_const(
2297 void bt_field_class_variant_option_set_user_attributes(
2298 struct bt_field_class_variant_option
*option
,
2299 const struct bt_value
*user_attributes
)
2301 BT_ASSERT_PRE_NON_NULL(option
, "Variant field class option");
2302 bt_named_field_class_set_user_attributes((void *) option
,
2306 void bt_field_class_get_ref(const struct bt_field_class
*field_class
)
2308 bt_object_get_ref(field_class
);
2311 void bt_field_class_put_ref(const struct bt_field_class
*field_class
)
2313 bt_object_put_ref(field_class
);