4 * Babeltrace CTF IR - Event Fields
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "FIELDS"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/ctf-ir/fields-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/ctf-writer/serialize-internal.h>
35 #include <babeltrace/object-internal.h>
36 #include <babeltrace/ref.h>
37 #include <babeltrace/compiler-internal.h>
38 #include <babeltrace/compat/fcntl-internal.h>
39 #include <babeltrace/align-internal.h>
43 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*);
45 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
46 struct bt_ctf_field_type
*);
48 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
49 struct bt_ctf_field_type
*);
51 struct bt_ctf_field
*bt_ctf_field_structure_create(
52 struct bt_ctf_field_type
*);
54 struct bt_ctf_field
*bt_ctf_field_variant_create(
55 struct bt_ctf_field_type
*);
57 struct bt_ctf_field
*bt_ctf_field_array_create(
58 struct bt_ctf_field_type
*);
60 struct bt_ctf_field
*bt_ctf_field_sequence_create(
61 struct bt_ctf_field_type
*);
63 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*);
66 void bt_ctf_field_destroy(struct bt_object
*);
68 void bt_ctf_field_integer_destroy(struct bt_ctf_field
*);
70 void bt_ctf_field_enumeration_destroy(struct bt_ctf_field
*);
72 void bt_ctf_field_floating_point_destroy(struct bt_ctf_field
*);
74 void bt_ctf_field_structure_destroy(struct bt_ctf_field
*);
76 void bt_ctf_field_variant_destroy(struct bt_ctf_field
*);
78 void bt_ctf_field_array_destroy(struct bt_ctf_field
*);
80 void bt_ctf_field_sequence_destroy(struct bt_ctf_field
*);
82 void bt_ctf_field_string_destroy(struct bt_ctf_field
*);
85 int bt_ctf_field_generic_validate(struct bt_ctf_field
*);
87 int bt_ctf_field_structure_validate(struct bt_ctf_field
*);
89 int bt_ctf_field_variant_validate(struct bt_ctf_field
*);
91 int bt_ctf_field_enumeration_validate(struct bt_ctf_field
*);
93 int bt_ctf_field_array_validate(struct bt_ctf_field
*);
95 int bt_ctf_field_sequence_validate(struct bt_ctf_field
*);
98 int bt_ctf_field_generic_reset(struct bt_ctf_field
*);
100 int bt_ctf_field_structure_reset(struct bt_ctf_field
*);
102 int bt_ctf_field_variant_reset(struct bt_ctf_field
*);
104 int bt_ctf_field_enumeration_reset(struct bt_ctf_field
*);
106 int bt_ctf_field_array_reset(struct bt_ctf_field
*);
108 int bt_ctf_field_sequence_reset(struct bt_ctf_field
*);
110 int bt_ctf_field_string_reset(struct bt_ctf_field
*);
113 int bt_ctf_field_integer_serialize(struct bt_ctf_field
*,
114 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
116 int bt_ctf_field_enumeration_serialize(struct bt_ctf_field
*,
117 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
119 int bt_ctf_field_floating_point_serialize(struct bt_ctf_field
*,
120 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
122 int bt_ctf_field_structure_serialize(struct bt_ctf_field
*,
123 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
125 int bt_ctf_field_variant_serialize(struct bt_ctf_field
*,
126 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
128 int bt_ctf_field_array_serialize(struct bt_ctf_field
*,
129 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
131 int bt_ctf_field_sequence_serialize(struct bt_ctf_field
*,
132 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
134 int bt_ctf_field_string_serialize(struct bt_ctf_field
*,
135 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
138 int bt_ctf_field_integer_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
140 int bt_ctf_field_enumeration_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
142 int bt_ctf_field_floating_point_copy(struct bt_ctf_field
*,
143 struct bt_ctf_field
*);
145 int bt_ctf_field_structure_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
147 int bt_ctf_field_variant_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
149 int bt_ctf_field_array_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
151 int bt_ctf_field_sequence_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
153 int bt_ctf_field_string_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
156 void generic_field_freeze(struct bt_ctf_field
*);
158 void bt_ctf_field_enumeration_freeze(struct bt_ctf_field
*);
160 void bt_ctf_field_structure_freeze(struct bt_ctf_field
*);
162 void bt_ctf_field_variant_freeze(struct bt_ctf_field
*);
164 void bt_ctf_field_array_freeze(struct bt_ctf_field
*);
166 void bt_ctf_field_sequence_freeze(struct bt_ctf_field
*);
169 bt_bool
bt_ctf_field_generic_is_set(struct bt_ctf_field
*);
171 bt_bool
bt_ctf_field_structure_is_set(struct bt_ctf_field
*);
173 bt_bool
bt_ctf_field_variant_is_set(struct bt_ctf_field
*);
175 bt_bool
bt_ctf_field_enumeration_is_set(struct bt_ctf_field
*);
177 bt_bool
bt_ctf_field_array_is_set(struct bt_ctf_field
*);
179 bt_bool
bt_ctf_field_sequence_is_set(struct bt_ctf_field
*);
182 int increase_packet_size(struct bt_ctf_stream_pos
*pos
);
185 struct bt_ctf_field
*(* const field_create_funcs
[])(
186 struct bt_ctf_field_type
*) = {
187 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_create
,
188 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_create
,
189 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
190 bt_ctf_field_floating_point_create
,
191 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_create
,
192 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_create
,
193 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_create
,
194 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_create
,
195 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_create
,
199 void (* const field_destroy_funcs
[])(struct bt_ctf_field
*) = {
200 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_destroy
,
201 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_destroy
,
202 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
203 bt_ctf_field_floating_point_destroy
,
204 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_destroy
,
205 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_destroy
,
206 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_destroy
,
207 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_destroy
,
208 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_destroy
,
212 int (* const field_validate_funcs
[])(struct bt_ctf_field
*) = {
213 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_validate
,
214 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_validate
,
215 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_validate
,
216 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_validate
,
217 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_validate
,
218 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_validate
,
219 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_validate
,
220 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_generic_validate
,
224 int (* const field_reset_funcs
[])(struct bt_ctf_field
*) = {
225 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_reset
,
226 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_reset
,
227 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_reset
,
228 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_reset
,
229 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_reset
,
230 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_reset
,
231 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_reset
,
232 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_reset
,
236 int (* const field_serialize_funcs
[])(struct bt_ctf_field
*,
237 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
) = {
238 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_serialize
,
239 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_serialize
,
240 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
241 bt_ctf_field_floating_point_serialize
,
242 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_serialize
,
243 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_serialize
,
244 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_serialize
,
245 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_serialize
,
246 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_serialize
,
250 int (* const field_copy_funcs
[])(struct bt_ctf_field
*,
251 struct bt_ctf_field
*) = {
252 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_copy
,
253 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_copy
,
254 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_floating_point_copy
,
255 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_copy
,
256 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_copy
,
257 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_copy
,
258 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_copy
,
259 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_copy
,
263 void (* const field_freeze_funcs
[])(struct bt_ctf_field
*) = {
264 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = generic_field_freeze
,
265 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = generic_field_freeze
,
266 [BT_CTF_FIELD_TYPE_ID_STRING
] = generic_field_freeze
,
267 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_freeze
,
268 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_freeze
,
269 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_freeze
,
270 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_freeze
,
271 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_freeze
,
275 bt_bool (* const field_is_set_funcs
[])(struct bt_ctf_field
*) = {
276 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_is_set
,
277 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_is_set
,
278 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_is_set
,
279 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_is_set
,
280 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_is_set
,
281 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_is_set
,
282 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_is_set
,
283 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_generic_is_set
,
286 struct bt_ctf_field
*bt_ctf_field_create(struct bt_ctf_field_type
*type
)
288 struct bt_ctf_field
*field
= NULL
;
289 enum bt_ctf_field_type_id type_id
;
293 BT_LOGW_STR("Invalid parameter: field type is NULL.");
297 type_id
= bt_ctf_field_type_get_type_id(type
);
298 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
||
299 type_id
>= BT_CTF_NR_TYPE_IDS
) {
300 BT_LOGW("Invalid parameter: unknown field type ID: "
301 "ft-addr=%p, ft-id=%d", type
, type_id
);
305 /* Field class MUST be valid */
306 ret
= bt_ctf_field_type_validate(type
);
309 BT_LOGW("Invalid parameter: field type is invalid: "
314 field
= field_create_funcs
[type_id
](type
);
319 /* The type's declaration can't change after this point */
320 bt_ctf_field_type_freeze(type
);
322 bt_object_init(field
, bt_ctf_field_destroy
);
328 /* Pre-2.0 CTF writer backward compatibility */
329 void bt_ctf_field_get(struct bt_ctf_field
*field
)
334 /* Pre-2.0 CTF writer backward compatibility */
335 void bt_ctf_field_put(struct bt_ctf_field
*field
)
340 struct bt_ctf_field_type
*bt_ctf_field_get_type(struct bt_ctf_field
*field
)
342 struct bt_ctf_field_type
*ret
= NULL
;
345 BT_LOGW_STR("Invalid parameter: field is NULL.");
355 enum bt_ctf_field_type_id
bt_ctf_field_get_type_id(struct bt_ctf_field
*field
)
357 enum bt_ctf_field_type_id ret
= BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
360 BT_LOGW_STR("Invalid parameter: field is NULL.");
364 ret
= bt_ctf_field_type_get_type_id(field
->type
);
369 bt_bool
bt_ctf_field_is_integer(struct bt_ctf_field
*field
)
371 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
374 bt_bool
bt_ctf_field_is_floating_point(struct bt_ctf_field
*field
)
376 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
379 bt_bool
bt_ctf_field_is_enumeration(struct bt_ctf_field
*field
)
381 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
384 bt_bool
bt_ctf_field_is_string(struct bt_ctf_field
*field
)
386 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_STRING
;
389 bt_bool
bt_ctf_field_is_structure(struct bt_ctf_field
*field
)
391 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
394 bt_bool
bt_ctf_field_is_array(struct bt_ctf_field
*field
)
396 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
399 bt_bool
bt_ctf_field_is_sequence(struct bt_ctf_field
*field
)
401 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
404 bt_bool
bt_ctf_field_is_variant(struct bt_ctf_field
*field
)
406 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
409 struct bt_ctf_field
*bt_ctf_field_sequence_get_length(
410 struct bt_ctf_field
*field
)
412 struct bt_ctf_field
*ret
= NULL
;
413 struct bt_ctf_field_sequence
*sequence
;
416 BT_LOGW_STR("Invalid parameter: field is NULL.");
420 if (bt_ctf_field_type_get_type_id(field
->type
) !=
421 BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
422 BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
423 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
425 bt_ctf_field_type_id_string(field
->type
->id
));
429 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
430 ret
= sequence
->length
;
436 int bt_ctf_field_sequence_set_length(struct bt_ctf_field
*field
,
437 struct bt_ctf_field
*length_field
)
440 struct bt_ctf_field_type_integer
*length_type
;
441 struct bt_ctf_field_integer
*length
;
442 struct bt_ctf_field_sequence
*sequence
;
443 uint64_t sequence_length
;
446 BT_LOGW_STR("Invalid parameter: field is NULL.");
452 BT_LOGW_STR("Invalid parameter: length field is NULL.");
458 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
464 if (bt_ctf_field_type_get_type_id(length_field
->type
) !=
465 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
466 BT_LOGW("Invalid parameter: length field's type is not an integer field type: "
467 "field-addr=%p, length-field-addr=%p, length-ft-addr=%p, length-ft-id=%s",
468 field
, length_field
, length_field
->type
,
469 bt_ctf_field_type_id_string(length_field
->type
->id
));
474 length_type
= container_of(length_field
->type
,
475 struct bt_ctf_field_type_integer
, parent
);
476 /* The length field must be unsigned */
477 if (length_type
->is_signed
) {
478 BT_LOGW("Invalid parameter: length field's type is signed: "
479 "field-addr=%p, length-field-addr=%p, "
480 "length-field-ft-addr=%p", field
, length_field
,
486 length
= container_of(length_field
, struct bt_ctf_field_integer
,
488 sequence_length
= length
->payload
.unsignd
;
489 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
490 if (sequence
->elements
) {
491 g_ptr_array_free(sequence
->elements
, TRUE
);
492 bt_put(sequence
->length
);
495 sequence
->elements
= g_ptr_array_sized_new((size_t)sequence_length
);
496 if (!sequence
->elements
) {
497 BT_LOGE_STR("Failed to allocate a GPtrArray.");
502 g_ptr_array_set_free_func(sequence
->elements
,
503 (GDestroyNotify
) bt_put
);
504 g_ptr_array_set_size(sequence
->elements
, (size_t) sequence_length
);
505 bt_get(length_field
);
506 sequence
->length
= length_field
;
511 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_name(
512 struct bt_ctf_field
*field
, const char *name
)
514 struct bt_ctf_field
*new_field
= NULL
;
516 struct bt_ctf_field_structure
*structure
;
517 struct bt_ctf_field_type
*field_type
= NULL
;
521 BT_LOGW_STR("Invalid parameter: field is NULL.");
526 BT_LOGW_STR("Invalid parameter: field name is NULL.");
530 if (bt_ctf_field_type_get_type_id(field
->type
) !=
531 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
532 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
533 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
535 bt_ctf_field_type_id_string(field
->type
->id
));
539 field_quark
= g_quark_from_string(name
);
540 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
542 bt_ctf_field_type_structure_get_field_type_by_name(field
->type
,
544 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
545 GUINT_TO_POINTER(field_quark
),
546 NULL
, (gpointer
*)&index
)) {
547 BT_LOGV("Invalid parameter: no such field in structure field's type: "
548 "struct-field-addr=%p, struct-ft-addr=%p, "
549 "field-ft-addr=%p, name=\"%s\"",
550 field
, field
->type
, field_type
, name
);
554 if (structure
->fields
->pdata
[index
]) {
555 new_field
= structure
->fields
->pdata
[index
];
559 /* We don't want to modify this field if it's frozen */
562 * Not logging a warning here because the user could
563 * legitimately check if a structure field is set with
564 * this function: if the preconditions are satisfied,
565 * a NULL return value means this.
567 BT_LOGV("Not creating a field because structure field is frozen: "
568 "struct-field-addr=%p, name=\"%s\"", field
, name
);
572 new_field
= bt_ctf_field_create(field_type
);
574 BT_LOGW("Cannot create field: "
575 "struct-field-addr=%p, struct-ft-addr=%p, "
576 "field-ft-addr=%p, name=\"%s\"",
577 field
, field
->type
, field_type
, name
);
581 structure
->fields
->pdata
[index
] = new_field
;
591 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_index(
592 struct bt_ctf_field
*field
, uint64_t index
)
595 const char *field_name
;
596 struct bt_ctf_field_structure
*structure
;
597 struct bt_ctf_field_type
*structure_type
;
598 struct bt_ctf_field_type
*field_type
= NULL
;
599 struct bt_ctf_field
*ret_field
= NULL
;
602 BT_LOGW_STR("Invalid parameter: field is NULL.");
606 if (bt_ctf_field_type_get_type_id(field
->type
) !=
607 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
608 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
609 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
611 bt_ctf_field_type_id_string(field
->type
->id
));
615 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
616 if (index
>= structure
->fields
->len
) {
617 BT_LOGW("Invalid parameter: index is out of bounds: "
618 "addr=%p, index=%" PRIu64
", count=%u",
619 field
, index
, structure
->fields
->len
);
623 ret_field
= structure
->fields
->pdata
[index
];
628 /* We don't want to modify this field if it's frozen */
631 * Not logging a warning here because the user could
632 * legitimately check if a structure field is set with
633 * this function: if the preconditions are satisfied,
634 * a NULL return value means this.
636 BT_LOGV("Not creating a field because structure field is frozen: "
637 "struct-field-addr=%p, index=%" PRIu64
, field
, index
);
641 /* Field has not been instanciated yet, create it */
642 structure_type
= bt_ctf_field_get_type(field
);
643 assert(structure_type
);
644 ret
= bt_ctf_field_type_structure_get_field(structure_type
,
645 &field_name
, &field_type
, index
);
647 bt_put(structure_type
);
648 ret_field
= bt_ctf_field_create(field_type
);
650 BT_LOGW("Cannot create field: "
651 "struct-field-addr=%p, struct-ft-addr=%p, "
652 "field-ft-addr=%p, index=%" PRIu64
,
653 field
, field
->type
, field_type
, index
);
657 structure
->fields
->pdata
[index
] = ret_field
;
665 int bt_ctf_field_structure_set_field_by_name(struct bt_ctf_field
*field
,
666 const char *name
, struct bt_ctf_field
*value
)
670 struct bt_ctf_field_structure
*structure
;
671 struct bt_ctf_field_type
*expected_field_type
= NULL
;
675 BT_LOGW_STR("Invalid parameter: structure field is NULL.");
681 BT_LOGW_STR("Invalid parameter: field name is NULL.");
687 BT_LOGW_STR("Invalid parameter: field is NULL.");
692 if (bt_ctf_field_type_get_type_id(field
->type
) !=
693 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
694 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
695 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
697 bt_ctf_field_type_id_string(field
->type
->id
));
702 field_quark
= g_quark_from_string(name
);
703 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
704 expected_field_type
=
705 bt_ctf_field_type_structure_get_field_type_by_name(field
->type
,
708 if (bt_ctf_field_type_compare(expected_field_type
, value
->type
)) {
709 BT_LOGW("Invalid parameter: field type of field to set is different from the expected field type: "
710 "struct-field-addr=%p, field-addr=%p, "
711 "field-ft-addr=%p, expected-ft-addr=%p",
712 field
, value
, value
->type
, expected_field_type
);
717 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
718 GUINT_TO_POINTER(field_quark
), NULL
, (gpointer
*) &index
)) {
719 BT_LOGV("Invalid parameter: no such field in structure field's type: "
720 "struct-field-addr=%p, struct-ft-addr=%p, "
721 "field-ft-addr=%p, name=\"%s\"",
722 field
, field
->type
, value
->type
, name
);
727 if (structure
->fields
->pdata
[index
]) {
728 bt_put(structure
->fields
->pdata
[index
]);
731 structure
->fields
->pdata
[index
] = value
;
734 if (expected_field_type
) {
735 bt_put(expected_field_type
);
740 struct bt_ctf_field
*bt_ctf_field_array_get_field(struct bt_ctf_field
*field
,
743 struct bt_ctf_field
*new_field
= NULL
;
744 struct bt_ctf_field_type
*field_type
= NULL
;
745 struct bt_ctf_field_array
*array
;
748 BT_LOGW_STR("Invalid parameter: field is NULL.");
752 if (bt_ctf_field_type_get_type_id(field
->type
) !=
753 BT_CTF_FIELD_TYPE_ID_ARRAY
) {
754 BT_LOGW("Invalid parameter: field's type is not an array field type: "
755 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
757 bt_ctf_field_type_id_string(field
->type
->id
));
761 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
762 if (index
>= array
->elements
->len
) {
763 BT_LOGW("Invalid parameter: index is out of bounds: "
764 "addr=%p, index=%" PRIu64
", count=%u",
765 field
, index
, array
->elements
->len
);
769 field_type
= bt_ctf_field_type_array_get_element_type(field
->type
);
770 if (array
->elements
->pdata
[(size_t)index
]) {
771 new_field
= array
->elements
->pdata
[(size_t)index
];
775 /* We don't want to modify this field if it's frozen */
778 * Not logging a warning here because the user could
779 * legitimately check if a array field is set with
780 * this function: if the preconditions are satisfied,
781 * a NULL return value means this.
783 BT_LOGV("Not creating a field because array field is frozen: "
784 "array-field-addr=%p, index=%" PRIu64
, field
, index
);
788 new_field
= bt_ctf_field_create(field_type
);
789 array
->elements
->pdata
[(size_t)index
] = new_field
;
800 struct bt_ctf_field
*bt_ctf_field_sequence_get_field(struct bt_ctf_field
*field
,
803 struct bt_ctf_field
*new_field
= NULL
;
804 struct bt_ctf_field_type
*field_type
= NULL
;
805 struct bt_ctf_field_sequence
*sequence
;
808 BT_LOGW_STR("Invalid parameter: field is NULL.");
812 if (bt_ctf_field_type_get_type_id(field
->type
) !=
813 BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
814 BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
815 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
817 bt_ctf_field_type_id_string(field
->type
->id
));
821 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
822 if (!sequence
->elements
) {
823 BT_LOGV("Sequence field's elements do not exist: addr=%p",
828 if (index
>= sequence
->elements
->len
) {
829 BT_LOGW("Invalid parameter: index is out of bounds: "
830 "addr=%p, index=%" PRIu64
", count=%u",
831 field
, index
, sequence
->elements
->len
);
835 field_type
= bt_ctf_field_type_sequence_get_element_type(field
->type
);
836 if (sequence
->elements
->pdata
[(size_t) index
]) {
837 new_field
= sequence
->elements
->pdata
[(size_t) index
];
841 /* We don't want to modify this field if it's frozen */
844 * Not logging a warning here because the user could
845 * legitimately check if a sequence field is set with
846 * this function: if the preconditions are satisfied,
847 * a NULL return value means this.
849 BT_LOGV("Not creating a field because sequence field is frozen: "
850 "sequence-field-addr=%p, index=%" PRIu64
, field
, index
);
854 new_field
= bt_ctf_field_create(field_type
);
855 sequence
->elements
->pdata
[(size_t) index
] = new_field
;
866 struct bt_ctf_field
*bt_ctf_field_variant_get_field(struct bt_ctf_field
*field
,
867 struct bt_ctf_field
*tag_field
)
869 struct bt_ctf_field
*new_field
= NULL
;
870 struct bt_ctf_field_variant
*variant
;
871 struct bt_ctf_field_type_variant
*variant_type
;
872 struct bt_ctf_field_type
*field_type
;
873 struct bt_ctf_field
*tag_enum
= NULL
;
874 struct bt_ctf_field_integer
*tag_enum_integer
;
875 int64_t tag_enum_value
;
878 BT_LOGW_STR("Invalid parameter: field is NULL.");
883 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
887 if (bt_ctf_field_type_get_type_id(field
->type
) !=
888 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
889 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
890 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
892 bt_ctf_field_type_id_string(field
->type
->id
));
896 if (bt_ctf_field_type_get_type_id(tag_field
->type
) !=
897 BT_CTF_FIELD_TYPE_ID_ENUM
) {
898 BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: "
899 "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field
,
901 bt_ctf_field_type_id_string(tag_field
->type
->id
));
905 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
906 variant_type
= container_of(field
->type
,
907 struct bt_ctf_field_type_variant
, parent
);
908 tag_enum
= bt_ctf_field_enumeration_get_container(tag_field
);
913 tag_enum_integer
= container_of(tag_enum
, struct bt_ctf_field_integer
,
916 if (bt_ctf_field_validate(tag_field
) < 0) {
917 BT_LOGW("Invalid parameter: tag field is invalid: "
918 "variant-field-addr=%p, tag-field-addr=%p",
923 tag_enum_value
= tag_enum_integer
->payload
.signd
;
926 * If the variant currently has a tag and a payload, and if the
927 * requested tag value is the same as the current one, return
928 * the current payload instead of creating a fresh one.
930 if (variant
->tag
&& variant
->payload
) {
931 struct bt_ctf_field
*cur_tag_container
= NULL
;
932 struct bt_ctf_field_integer
*cur_tag_enum_integer
;
933 int64_t cur_tag_value
;
936 bt_ctf_field_enumeration_get_container(variant
->tag
);
937 assert(cur_tag_container
);
938 cur_tag_enum_integer
= container_of(cur_tag_container
,
939 struct bt_ctf_field_integer
, parent
);
940 bt_put(cur_tag_container
);
941 cur_tag_value
= cur_tag_enum_integer
->payload
.signd
;
943 if (cur_tag_value
== tag_enum_value
) {
944 new_field
= variant
->payload
;
950 /* We don't want to modify this field if it's frozen */
953 * Not logging a warning here because the user could
954 * legitimately check if a variant field is set with
955 * this function: if the preconditions are satisfied,
956 * a NULL return value means this.
958 BT_LOGV("Not creating a field because variant field is frozen: "
959 "variant-field-addr=%p, tag-field-addr=%p",
964 field_type
= bt_ctf_field_type_variant_get_field_type_signed(
965 variant_type
, tag_enum_value
);
967 BT_LOGW("Cannot get variant field type's field: "
968 "variant-field-addr=%p, variant-ft-addr=%p, "
969 "tag-value-signed=%" PRId64
,
970 field
, variant_type
, tag_enum_value
);
974 new_field
= bt_ctf_field_create(field_type
);
976 BT_LOGW("Cannot create field: "
977 "variant-field-addr=%p, variant-ft-addr=%p, "
978 "field-ft-addr=%p", field
, field
->type
, field_type
);
982 bt_put(variant
->tag
);
983 bt_put(variant
->payload
);
986 variant
->tag
= tag_field
;
987 variant
->payload
= new_field
;
993 struct bt_ctf_field
*bt_ctf_field_variant_get_current_field(
994 struct bt_ctf_field
*variant_field
)
996 struct bt_ctf_field
*current_field
= NULL
;
997 struct bt_ctf_field_variant
*variant
;
999 if (!variant_field
) {
1000 BT_LOGW_STR("Invalid parameter: field is NULL.");
1004 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
1005 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
1006 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
1007 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
1008 variant_field
->type
,
1009 bt_ctf_field_type_id_string(variant_field
->type
->id
));
1013 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
1016 if (variant
->payload
) {
1017 current_field
= variant
->payload
;
1018 bt_get(current_field
);
1023 return current_field
;
1026 struct bt_ctf_field
*bt_ctf_field_variant_get_tag(
1027 struct bt_ctf_field
*variant_field
)
1029 struct bt_ctf_field
*tag
= NULL
;
1030 struct bt_ctf_field_variant
*variant
;
1032 if (!variant_field
) {
1033 BT_LOGW_STR("Invalid parameter: field is NULL.");
1037 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
1038 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
1039 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
1040 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
1041 variant_field
->type
,
1042 bt_ctf_field_type_id_string(variant_field
->type
->id
));
1046 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
1049 tag
= bt_get(variant
->tag
);
1055 struct bt_ctf_field
*bt_ctf_field_enumeration_get_container(
1056 struct bt_ctf_field
*field
)
1058 struct bt_ctf_field
*container
= NULL
;
1059 struct bt_ctf_field_enumeration
*enumeration
;
1062 BT_LOGW_STR("Invalid parameter: field is NULL.");
1066 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1067 BT_CTF_FIELD_TYPE_ID_ENUM
) {
1068 BT_LOGW("Invalid parameter: field's type is not an enumeration field type: "
1069 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1071 bt_ctf_field_type_id_string(field
->type
->id
));
1075 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
1077 if (!enumeration
->payload
) {
1078 /* We don't want to modify this field if it's frozen */
1079 if (field
->frozen
) {
1081 * Not logging a warning here because the user
1082 * could legitimately check if an enumeration's
1083 * container field is set with this function: if
1084 * the preconditions are satisfied, a NULL
1085 * return value means this.
1087 BT_LOGV("Not creating a field because enumeration field is frozen: "
1088 "enum-field-addr=%p", field
);
1092 struct bt_ctf_field_type_enumeration
*enumeration_type
=
1093 container_of(field
->type
,
1094 struct bt_ctf_field_type_enumeration
, parent
);
1095 enumeration
->payload
=
1096 bt_ctf_field_create(enumeration_type
->container
);
1099 container
= enumeration
->payload
;
1105 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1106 bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field
*field
)
1109 struct bt_ctf_field
*container
= NULL
;
1110 struct bt_ctf_field_type
*container_type
= NULL
;
1111 struct bt_ctf_field_type_integer
*integer_type
= NULL
;
1112 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1114 container
= bt_ctf_field_enumeration_get_container(field
);
1116 BT_LOGW("Invalid parameter: enumeration field has no container field: "
1121 container_type
= bt_ctf_field_get_type(container
);
1122 assert(container_type
);
1123 integer_type
= container_of(container_type
,
1124 struct bt_ctf_field_type_integer
, parent
);
1126 if (!integer_type
->is_signed
) {
1129 ret
= bt_ctf_field_unsigned_integer_get_value(container
,
1132 BT_LOGW("Cannot get value from signed enumeration field's payload field: "
1133 "enum-field-addr=%p, payload-field-addr=%p",
1135 goto error_put_container_type
;
1137 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1138 field
->type
, value
);
1142 ret
= bt_ctf_field_signed_integer_get_value(container
,
1145 BT_LOGW("Cannot get value from unsigned enumeration field's payload field: "
1146 "enum-field-addr=%p, payload-field-addr=%p",
1148 goto error_put_container_type
;
1150 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1151 field
->type
, value
);
1154 error_put_container_type
:
1155 bt_put(container_type
);
1161 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field
*field
,
1165 struct bt_ctf_field_integer
*integer
;
1166 struct bt_ctf_field_type_integer
*integer_type
;
1169 BT_LOGW_STR("Invalid parameter: field is NULL.");
1175 BT_LOGW_STR("Invalid parameter: value is NULL.");
1180 if (!field
->payload_set
) {
1181 BT_LOGV("Field's payload is not set: addr=%p", field
);
1186 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1187 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1188 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1189 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1191 bt_ctf_field_type_id_string(field
->type
->id
));
1196 integer_type
= container_of(field
->type
,
1197 struct bt_ctf_field_type_integer
, parent
);
1198 if (!integer_type
->is_signed
) {
1199 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1200 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1205 integer
= container_of(field
,
1206 struct bt_ctf_field_integer
, parent
);
1207 *value
= integer
->payload
.signd
;
1212 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field
*field
,
1216 struct bt_ctf_field_integer
*integer
;
1217 struct bt_ctf_field_type_integer
*integer_type
;
1219 int64_t min_value
, max_value
;
1222 BT_LOGW_STR("Invalid parameter: field is NULL.");
1227 if (field
->frozen
) {
1228 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1234 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1235 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1236 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1237 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1239 bt_ctf_field_type_id_string(field
->type
->id
));
1244 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1245 integer_type
= container_of(field
->type
,
1246 struct bt_ctf_field_type_integer
, parent
);
1247 if (!integer_type
->is_signed
) {
1248 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1249 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1254 size
= integer_type
->size
;
1255 min_value
= -(1ULL << (size
- 1));
1256 max_value
= (1ULL << (size
- 1)) - 1;
1257 if (value
< min_value
|| value
> max_value
) {
1258 BT_LOGW("Invalid parameter: value is out of bounds: "
1259 "addr=%p, value=%" PRId64
", "
1260 "min-value=%" PRId64
", max-value=%" PRId64
,
1261 field
, value
, min_value
, max_value
);
1266 integer
->payload
.signd
= value
;
1267 integer
->parent
.payload_set
= 1;
1272 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field
*field
,
1276 struct bt_ctf_field_integer
*integer
;
1277 struct bt_ctf_field_type_integer
*integer_type
;
1280 BT_LOGW_STR("Invalid parameter: field is NULL.");
1286 BT_LOGW_STR("Invalid parameter: value is NULL.");
1291 if (!field
->payload_set
) {
1292 BT_LOGV("Field's payload is not set: addr=%p", field
);
1297 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1298 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1299 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1300 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1302 bt_ctf_field_type_id_string(field
->type
->id
));
1307 integer_type
= container_of(field
->type
,
1308 struct bt_ctf_field_type_integer
, parent
);
1309 if (integer_type
->is_signed
) {
1310 BT_LOGW("Invalid parameter: integer field's type is signed: "
1311 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1316 integer
= container_of(field
,
1317 struct bt_ctf_field_integer
, parent
);
1318 *value
= integer
->payload
.unsignd
;
1323 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field
*field
,
1327 struct bt_ctf_field_integer
*integer
;
1328 struct bt_ctf_field_type_integer
*integer_type
;
1333 BT_LOGW_STR("Invalid parameter: field is NULL.");
1338 if (field
->frozen
) {
1339 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1345 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1346 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1347 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1348 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1350 bt_ctf_field_type_id_string(field
->type
->id
));
1355 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1356 integer_type
= container_of(field
->type
,
1357 struct bt_ctf_field_type_integer
, parent
);
1358 if (integer_type
->is_signed
) {
1359 BT_LOGW("Invalid parameter: integer field's type is signed: "
1360 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1365 size
= integer_type
->size
;
1366 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
1367 if (value
> max_value
) {
1368 BT_LOGW("Invalid parameter: value is out of bounds: "
1369 "addr=%p, value=%" PRIu64
", "
1370 "min-value=%" PRIu64
", max-value=%" PRIu64
,
1371 field
, value
, (uint64_t) 0, max_value
);
1376 integer
->payload
.unsignd
= value
;
1377 integer
->parent
.payload_set
= 1;
1382 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field
*field
,
1386 struct bt_ctf_field_floating_point
*floating_point
;
1389 BT_LOGW_STR("Invalid parameter: field is NULL.");
1395 BT_LOGW_STR("Invalid parameter: value is NULL.");
1400 if (!field
->payload_set
) {
1401 BT_LOGV("Field's payload is not set: addr=%p", field
);
1406 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1407 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1408 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1409 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1411 bt_ctf_field_type_id_string(field
->type
->id
));
1416 floating_point
= container_of(field
,
1417 struct bt_ctf_field_floating_point
, parent
);
1418 *value
= floating_point
->payload
;
1423 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field
*field
,
1427 struct bt_ctf_field_floating_point
*floating_point
;
1430 BT_LOGW_STR("Invalid parameter: field is NULL.");
1435 if (field
->frozen
) {
1436 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1442 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1443 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1444 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1445 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1447 bt_ctf_field_type_id_string(field
->type
->id
));
1452 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
1454 floating_point
->payload
= value
;
1455 floating_point
->parent
.payload_set
= 1;
1460 const char *bt_ctf_field_string_get_value(struct bt_ctf_field
*field
)
1462 const char *ret
= NULL
;
1463 struct bt_ctf_field_string
*string
;
1466 BT_LOGW_STR("Invalid parameter: field is NULL.");
1470 if (!field
->payload_set
) {
1471 BT_LOGV("Field's payload is not set: addr=%p", field
);
1475 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1476 BT_CTF_FIELD_TYPE_ID_STRING
) {
1477 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1478 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1480 bt_ctf_field_type_id_string(field
->type
->id
));
1484 string
= container_of(field
,
1485 struct bt_ctf_field_string
, parent
);
1486 ret
= string
->payload
->str
;
1491 int bt_ctf_field_string_set_value(struct bt_ctf_field
*field
,
1495 struct bt_ctf_field_string
*string
;
1498 BT_LOGW_STR("Invalid parameter: field is NULL.");
1504 BT_LOGW_STR("Invalid parameter: value is NULL.");
1509 if (field
->frozen
) {
1510 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1516 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1517 BT_CTF_FIELD_TYPE_ID_STRING
) {
1518 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1519 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1521 bt_ctf_field_type_id_string(field
->type
->id
));
1526 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
1527 if (string
->payload
) {
1528 g_string_assign(string
->payload
, value
);
1530 string
->payload
= g_string_new(value
);
1533 string
->parent
.payload_set
= 1;
1538 int bt_ctf_field_string_append(struct bt_ctf_field
*field
,
1542 struct bt_ctf_field_string
*string_field
;
1545 BT_LOGW_STR("Invalid parameter: field is NULL.");
1551 BT_LOGW_STR("Invalid parameter: value is NULL.");
1556 if (field
->frozen
) {
1557 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1563 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1564 BT_CTF_FIELD_TYPE_ID_STRING
) {
1565 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1566 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1568 bt_ctf_field_type_id_string(field
->type
->id
));
1573 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1575 if (string_field
->payload
) {
1576 g_string_append(string_field
->payload
, value
);
1578 string_field
->payload
= g_string_new(value
);
1581 string_field
->parent
.payload_set
= 1;
1587 int bt_ctf_field_string_append_len(struct bt_ctf_field
*field
,
1588 const char *value
, unsigned int length
)
1592 unsigned int effective_length
= length
;
1593 struct bt_ctf_field_string
*string_field
;
1596 BT_LOGW_STR("Invalid parameter: field is NULL.");
1602 BT_LOGW_STR("Invalid parameter: value is NULL.");
1607 if (field
->frozen
) {
1608 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1614 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1615 BT_CTF_FIELD_TYPE_ID_STRING
) {
1616 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1617 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1619 bt_ctf_field_type_id_string(field
->type
->id
));
1624 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1626 /* make sure no null bytes are appended */
1627 for (i
= 0; i
< length
; ++i
) {
1628 if (value
[i
] == '\0') {
1629 effective_length
= i
;
1634 if (string_field
->payload
) {
1635 g_string_append_len(string_field
->payload
, value
,
1638 string_field
->payload
= g_string_new_len(value
,
1642 string_field
->parent
.payload_set
= 1;
1649 int bt_ctf_field_validate(struct bt_ctf_field
*field
)
1652 enum bt_ctf_field_type_id type_id
;
1655 BT_LOGD_STR("Invalid parameter: field is NULL.");
1660 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1661 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1662 BT_LOGW("Invalid parameter: unknown field type ID: "
1663 "addr=%p, ft-addr=%p, ft-id=%d",
1664 field
, field
->type
, type_id
);
1669 ret
= field_validate_funcs
[type_id
](field
);
1675 int bt_ctf_field_reset(struct bt_ctf_field
*field
)
1678 enum bt_ctf_field_type_id type_id
;
1681 BT_LOGD_STR("Invalid parameter: field is NULL.");
1686 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1687 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1688 BT_LOGW("Invalid parameter: unknown field type ID: "
1689 "addr=%p, ft-addr=%p, ft-id=%d",
1690 field
, field
->type
, type_id
);
1695 ret
= field_reset_funcs
[type_id
](field
);
1701 int bt_ctf_field_serialize(struct bt_ctf_field
*field
,
1702 struct bt_ctf_stream_pos
*pos
,
1703 enum bt_ctf_byte_order native_byte_order
)
1706 enum bt_ctf_field_type_id type_id
;
1711 BT_LOGD_STR("Invalid parameter: field is NULL.");
1716 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1717 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1718 BT_LOGW("Invalid parameter: unknown field type ID: "
1719 "addr=%p, ft-addr=%p, ft-id=%d",
1720 field
, field
->type
, type_id
);
1725 ret
= field_serialize_funcs
[type_id
](field
, pos
, native_byte_order
);
1732 bt_bool
bt_ctf_field_is_set(struct bt_ctf_field
*field
)
1734 bt_bool is_set
= BT_FALSE
;
1735 enum bt_ctf_field_type_id type_id
;
1741 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1742 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1743 BT_LOGW("Invalid parameter: unknown field type ID: "
1744 "field-addr=%p, ft-addr=%p, ft-id=%d",
1745 field
, field
->type
, type_id
);
1749 is_set
= field_is_set_funcs
[type_id
](field
);
1754 struct bt_ctf_field
*bt_ctf_field_copy(struct bt_ctf_field
*field
)
1757 struct bt_ctf_field
*copy
= NULL
;
1758 enum bt_ctf_field_type_id type_id
;
1761 BT_LOGW_STR("Invalid parameter: field is NULL.");
1765 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1766 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1767 BT_LOGW("Invalid parameter: unknown field type ID: "
1768 "field-addr=%p, ft-addr=%p, ft-id=%d",
1769 field
, field
->type
, type_id
);
1773 copy
= bt_ctf_field_create(field
->type
);
1775 BT_LOGW("Cannot create field: ft-addr=%p", field
->type
);
1779 copy
->payload_set
= field
->payload_set
;
1780 ret
= field_copy_funcs
[type_id
](field
, copy
);
1790 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*type
)
1792 struct bt_ctf_field_integer
*integer
= g_new0(
1793 struct bt_ctf_field_integer
, 1);
1795 BT_LOGD("Creating integer field object: ft-addr=%p", type
);
1798 BT_LOGD("Created integer field object: addr=%p, ft-addr=%p",
1799 &integer
->parent
, type
);
1801 BT_LOGE_STR("Failed to allocate one integer field.");
1804 return integer
? &integer
->parent
: NULL
;
1808 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
1809 struct bt_ctf_field_type
*type
)
1811 struct bt_ctf_field_enumeration
*enumeration
= g_new0(
1812 struct bt_ctf_field_enumeration
, 1);
1814 BT_LOGD("Creating enumeration field object: ft-addr=%p", type
);
1817 BT_LOGD("Created enumeration field object: addr=%p, ft-addr=%p",
1818 &enumeration
->parent
, type
);
1820 BT_LOGE_STR("Failed to allocate one enumeration field.");
1823 return enumeration
? &enumeration
->parent
: NULL
;
1827 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
1828 struct bt_ctf_field_type
*type
)
1830 struct bt_ctf_field_floating_point
*floating_point
;
1832 BT_LOGD("Creating floating point number field object: ft-addr=%p", type
);
1833 floating_point
= g_new0(struct bt_ctf_field_floating_point
, 1);
1835 if (floating_point
) {
1836 BT_LOGD("Created floating point number field object: addr=%p, ft-addr=%p",
1837 &floating_point
->parent
, type
);
1839 BT_LOGE_STR("Failed to allocate one floating point number field.");
1842 return floating_point
? &floating_point
->parent
: NULL
;
1846 struct bt_ctf_field
*bt_ctf_field_structure_create(
1847 struct bt_ctf_field_type
*type
)
1849 struct bt_ctf_field_type_structure
*structure_type
= container_of(type
,
1850 struct bt_ctf_field_type_structure
, parent
);
1851 struct bt_ctf_field_structure
*structure
= g_new0(
1852 struct bt_ctf_field_structure
, 1);
1853 struct bt_ctf_field
*field
= NULL
;
1855 BT_LOGD("Creating structure field object: ft-addr=%p", type
);
1858 BT_LOGE_STR("Failed to allocate one structure field.");
1862 structure
->field_name_to_index
= structure_type
->field_name_to_index
;
1863 structure
->fields
= g_ptr_array_new_with_free_func(
1864 (GDestroyNotify
)bt_ctf_field_put
);
1865 g_ptr_array_set_size(structure
->fields
,
1866 g_hash_table_size(structure
->field_name_to_index
));
1867 field
= &structure
->parent
;
1868 BT_LOGD("Created structure field object: addr=%p, ft-addr=%p",
1875 struct bt_ctf_field
*bt_ctf_field_variant_create(struct bt_ctf_field_type
*type
)
1877 struct bt_ctf_field_variant
*variant
= g_new0(
1878 struct bt_ctf_field_variant
, 1);
1880 BT_LOGD("Creating variant field object: ft-addr=%p", type
);
1883 BT_LOGD("Created variant field object: addr=%p, ft-addr=%p",
1884 &variant
->parent
, type
);
1886 BT_LOGE_STR("Failed to allocate one variant field.");
1889 return variant
? &variant
->parent
: NULL
;
1893 struct bt_ctf_field
*bt_ctf_field_array_create(struct bt_ctf_field_type
*type
)
1895 struct bt_ctf_field_array
*array
= g_new0(struct bt_ctf_field_array
, 1);
1896 struct bt_ctf_field_type_array
*array_type
;
1897 unsigned int array_length
;
1899 BT_LOGD("Creating array field object: ft-addr=%p", type
);
1903 BT_LOGE_STR("Failed to allocate one array field.");
1907 array_type
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
1908 array_length
= array_type
->length
;
1909 array
->elements
= g_ptr_array_sized_new(array_length
);
1910 if (!array
->elements
) {
1914 g_ptr_array_set_free_func(array
->elements
,
1915 (GDestroyNotify
)bt_ctf_field_put
);
1916 g_ptr_array_set_size(array
->elements
, array_length
);
1917 BT_LOGD("Created array field object: addr=%p, ft-addr=%p",
1918 &array
->parent
, type
);
1919 return &array
->parent
;
1926 struct bt_ctf_field
*bt_ctf_field_sequence_create(
1927 struct bt_ctf_field_type
*type
)
1929 struct bt_ctf_field_sequence
*sequence
= g_new0(
1930 struct bt_ctf_field_sequence
, 1);
1932 BT_LOGD("Creating sequence field object: ft-addr=%p", type
);
1935 BT_LOGD("Created sequence field object: addr=%p, ft-addr=%p",
1936 &sequence
->parent
, type
);
1938 BT_LOGE_STR("Failed to allocate one sequence field.");
1941 return sequence
? &sequence
->parent
: NULL
;
1945 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*type
)
1947 struct bt_ctf_field_string
*string
= g_new0(
1948 struct bt_ctf_field_string
, 1);
1950 BT_LOGD("Creating string field object: ft-addr=%p", type
);
1953 BT_LOGD("Created string field object: addr=%p, ft-addr=%p",
1954 &string
->parent
, type
);
1956 BT_LOGE_STR("Failed to allocate one string field.");
1959 return string
? &string
->parent
: NULL
;
1963 void bt_ctf_field_destroy(struct bt_object
*obj
)
1965 struct bt_ctf_field
*field
;
1966 struct bt_ctf_field_type
*type
;
1967 enum bt_ctf_field_type_id type_id
;
1969 field
= container_of(obj
, struct bt_ctf_field
, base
);
1971 type_id
= bt_ctf_field_type_get_type_id(type
);
1972 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
1973 type_id
< BT_CTF_NR_TYPE_IDS
);
1974 field_destroy_funcs
[type_id
](field
);
1975 BT_LOGD_STR("Putting field's type.");
1980 void bt_ctf_field_integer_destroy(struct bt_ctf_field
*field
)
1982 struct bt_ctf_field_integer
*integer
;
1988 BT_LOGD("Destroying integer field object: addr=%p", field
);
1989 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1994 void bt_ctf_field_enumeration_destroy(struct bt_ctf_field
*field
)
1996 struct bt_ctf_field_enumeration
*enumeration
;
2002 BT_LOGD("Destroying enumeration field object: addr=%p", field
);
2003 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2005 BT_LOGD_STR("Putting payload field.");
2006 bt_put(enumeration
->payload
);
2007 g_free(enumeration
);
2011 void bt_ctf_field_floating_point_destroy(struct bt_ctf_field
*field
)
2013 struct bt_ctf_field_floating_point
*floating_point
;
2019 BT_LOGD("Destroying floating point number field object: addr=%p", field
);
2020 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
2022 g_free(floating_point
);
2026 void bt_ctf_field_structure_destroy(struct bt_ctf_field
*field
)
2028 struct bt_ctf_field_structure
*structure
;
2034 BT_LOGD("Destroying structure field object: addr=%p", field
);
2035 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2036 g_ptr_array_free(structure
->fields
, TRUE
);
2041 void bt_ctf_field_variant_destroy(struct bt_ctf_field
*field
)
2043 struct bt_ctf_field_variant
*variant
;
2049 BT_LOGD("Destroying variant field object: addr=%p", field
);
2050 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2051 BT_LOGD_STR("Putting tag field.");
2052 bt_put(variant
->tag
);
2053 BT_LOGD_STR("Putting payload field.");
2054 bt_put(variant
->payload
);
2059 void bt_ctf_field_array_destroy(struct bt_ctf_field
*field
)
2061 struct bt_ctf_field_array
*array
;
2067 BT_LOGD("Destroying array field object: addr=%p", field
);
2068 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2069 g_ptr_array_free(array
->elements
, TRUE
);
2074 void bt_ctf_field_sequence_destroy(struct bt_ctf_field
*field
)
2076 struct bt_ctf_field_sequence
*sequence
;
2082 BT_LOGD("Destroying sequence field object: addr=%p", field
);
2083 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2084 if (sequence
->elements
) {
2085 g_ptr_array_free(sequence
->elements
, TRUE
);
2087 BT_LOGD_STR("Putting length field.");
2088 bt_put(sequence
->length
);
2093 void bt_ctf_field_string_destroy(struct bt_ctf_field
*field
)
2095 struct bt_ctf_field_string
*string
;
2101 BT_LOGD("Destroying string field object: addr=%p", field
);
2102 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2103 if (string
->payload
) {
2104 g_string_free(string
->payload
, TRUE
);
2110 int bt_ctf_field_generic_validate(struct bt_ctf_field
*field
)
2112 return (field
&& field
->payload_set
) ? 0 : -1;
2116 int bt_ctf_field_enumeration_validate(struct bt_ctf_field
*field
)
2119 struct bt_ctf_field_enumeration
*enumeration
;
2122 BT_LOGD_STR("Invalid parameter: field is NULL.");
2127 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2129 if (!enumeration
->payload
) {
2130 BT_LOGW("Invalid enumeration field: payload is not set: "
2136 ret
= bt_ctf_field_validate(enumeration
->payload
);
2142 int bt_ctf_field_structure_validate(struct bt_ctf_field
*field
)
2146 struct bt_ctf_field_structure
*structure
;
2149 BT_LOGD_STR("Invalid parameter: field is NULL.");
2154 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2155 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2156 struct bt_ctf_field
*entry_field
= structure
->fields
->pdata
[i
];
2157 ret
= bt_ctf_field_validate(entry_field
);
2162 struct bt_ctf_field_type
*field_type
=
2163 bt_ctf_field_get_type(field
);
2165 this_ret
= bt_ctf_field_type_structure_get_field(
2166 field_type
, &name
, NULL
, i
);
2167 assert(this_ret
== 0);
2168 BT_LOGW("Invalid structure field's field: "
2169 "struct-field-addr=%p, field-addr=%p, "
2170 "field-name=\"%s\", index=%" PRId64
,
2171 field
, entry_field
, name
, i
);
2181 int bt_ctf_field_variant_validate(struct bt_ctf_field
*field
)
2184 struct bt_ctf_field_variant
*variant
;
2187 BT_LOGD_STR("Invalid parameter: field is NULL.");
2192 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2193 ret
= bt_ctf_field_validate(variant
->payload
);
2195 BT_LOGW("Invalid variant field's payload field: "
2196 "variant-field-addr=%p, variant-payload-field-addr=%p",
2197 field
, variant
->payload
);
2204 int bt_ctf_field_array_validate(struct bt_ctf_field
*field
)
2208 struct bt_ctf_field_array
*array
;
2211 BT_LOGD_STR("Invalid parameter: field is NULL.");
2216 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2217 for (i
= 0; i
< array
->elements
->len
; i
++) {
2218 struct bt_ctf_field
*elem_field
= array
->elements
->pdata
[i
];
2220 ret
= bt_ctf_field_validate(elem_field
);
2222 BT_LOGW("Invalid array field's element field: "
2223 "array-field-addr=%p, field-addr=%p, "
2224 "index=%" PRId64
, field
, elem_field
, i
);
2233 int bt_ctf_field_sequence_validate(struct bt_ctf_field
*field
)
2237 struct bt_ctf_field_sequence
*sequence
;
2240 BT_LOGD_STR("Invalid parameter: field is NULL.");
2245 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2246 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2247 struct bt_ctf_field
*elem_field
= sequence
->elements
->pdata
[i
];
2249 ret
= bt_ctf_field_validate(elem_field
);
2251 BT_LOGW("Invalid sequence field's element field: "
2252 "sequence-field-addr=%p, field-addr=%p, "
2253 "index=%zu", field
, elem_field
, i
);
2262 int bt_ctf_field_generic_reset(struct bt_ctf_field
*field
)
2267 BT_LOGD_STR("Invalid parameter: field is NULL.");
2272 field
->payload_set
= 0;
2278 int bt_ctf_field_enumeration_reset(struct bt_ctf_field
*field
)
2281 struct bt_ctf_field_enumeration
*enumeration
;
2284 BT_LOGD_STR("Invalid parameter: field is NULL.");
2289 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2291 if (!enumeration
->payload
) {
2295 ret
= bt_ctf_field_reset(enumeration
->payload
);
2301 int bt_ctf_field_structure_reset(struct bt_ctf_field
*field
)
2305 struct bt_ctf_field_structure
*structure
;
2308 BT_LOGD_STR("Invalid parameter: field is NULL.");
2313 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2314 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2315 struct bt_ctf_field
*member
= structure
->fields
->pdata
[i
];
2319 * Structure members are lazily initialized; skip if
2320 * this member has not been allocated yet.
2325 ret
= bt_ctf_field_reset(member
);
2327 BT_LOGE("Failed to reset structure field's field: "
2328 "struct-field-addr=%p, field-addr=%p, "
2329 "index=%" PRId64
, field
, member
, i
);
2338 int bt_ctf_field_variant_reset(struct bt_ctf_field
*field
)
2341 struct bt_ctf_field_variant
*variant
;
2344 BT_LOGD_STR("Invalid parameter: field is NULL.");
2349 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2350 if (variant
->payload
) {
2351 ret
= bt_ctf_field_reset(variant
->payload
);
2353 BT_LOGW("Failed to reset variant field's payload field: "
2354 "variant-field-addr=%p, payload-field-addr=%p",
2355 field
, variant
->payload
);
2363 int bt_ctf_field_array_reset(struct bt_ctf_field
*field
)
2367 struct bt_ctf_field_array
*array
;
2370 BT_LOGD_STR("Invalid parameter: field is NULL.");
2375 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2376 for (i
= 0; i
< array
->elements
->len
; i
++) {
2377 struct bt_ctf_field
*member
= array
->elements
->pdata
[i
];
2381 * Array elements are lazily initialized; skip if
2382 * this member has not been allocated yet.
2387 ret
= bt_ctf_field_reset(member
);
2389 BT_LOGE("Failed to reset array field's field: "
2390 "array-field-addr=%p, field-addr=%p, "
2391 "index=%zu", field
, member
, i
);
2400 int bt_ctf_field_sequence_reset(struct bt_ctf_field
*field
)
2404 struct bt_ctf_field_sequence
*sequence
;
2407 BT_LOGD_STR("Invalid parameter: field is NULL.");
2412 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2413 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2414 struct bt_ctf_field
*member
= sequence
->elements
->pdata
[i
];
2418 * Sequence elements are lazily initialized; skip if
2419 * this member has not been allocated yet.
2424 ret
= bt_ctf_field_reset(member
);
2426 BT_LOGE("Failed to reset sequence field's field: "
2427 "sequence-field-addr=%p, field-addr=%p, "
2428 "index=%zu", field
, member
, i
);
2437 int bt_ctf_field_string_reset(struct bt_ctf_field
*field
)
2440 struct bt_ctf_field_string
*string
;
2443 BT_LOGD_STR("Invalid parameter: field is NULL.");
2448 ret
= bt_ctf_field_generic_reset(field
);
2453 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2454 if (string
->payload
) {
2455 g_string_truncate(string
->payload
, 0);
2462 int bt_ctf_field_integer_serialize(struct bt_ctf_field
*field
,
2463 struct bt_ctf_stream_pos
*pos
,
2464 enum bt_ctf_byte_order native_byte_order
)
2467 struct bt_ctf_field_integer
*integer
= container_of(field
,
2468 struct bt_ctf_field_integer
, parent
);
2470 BT_LOGV("Serializing integer field: addr=%p, pos-offset=%" PRId64
", "
2471 "native-bo=%s", field
, pos
->offset
,
2472 bt_ctf_byte_order_string(native_byte_order
));
2474 if (!bt_ctf_field_generic_is_set(field
)) {
2475 BT_LOGW_STR("Field's payload is not set.");
2480 ret
= bt_ctf_field_integer_write(integer
, pos
, native_byte_order
);
2481 if (ret
== -EFAULT
) {
2483 * The field is too large to fit in the current packet's
2484 * remaining space. Bump the packet size and retry.
2486 ret
= increase_packet_size(pos
);
2488 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2498 int bt_ctf_field_enumeration_serialize(struct bt_ctf_field
*field
,
2499 struct bt_ctf_stream_pos
*pos
,
2500 enum bt_ctf_byte_order native_byte_order
)
2502 struct bt_ctf_field_enumeration
*enumeration
= container_of(
2503 field
, struct bt_ctf_field_enumeration
, parent
);
2505 BT_LOGV("Serializing enumeration field: addr=%p, pos-offset=%" PRId64
", "
2506 "native-bo=%s", field
, pos
->offset
,
2507 bt_ctf_byte_order_string(native_byte_order
));
2508 BT_LOGV_STR("Serializing enumeration field's payload field.");
2509 return bt_ctf_field_serialize(enumeration
->payload
, pos
,
2514 int bt_ctf_field_floating_point_serialize(struct bt_ctf_field
*field
,
2515 struct bt_ctf_stream_pos
*pos
,
2516 enum bt_ctf_byte_order native_byte_order
)
2519 struct bt_ctf_field_floating_point
*floating_point
= container_of(field
,
2520 struct bt_ctf_field_floating_point
, parent
);
2522 BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64
", "
2523 "native-bo=%s", field
, pos
->offset
,
2524 bt_ctf_byte_order_string(native_byte_order
));
2526 if (!bt_ctf_field_generic_is_set(field
)) {
2527 BT_LOGW_STR("Field's payload is not set.");
2532 ret
= bt_ctf_field_floating_point_write(floating_point
, pos
,
2534 if (ret
== -EFAULT
) {
2536 * The field is too large to fit in the current packet's
2537 * remaining space. Bump the packet size and retry.
2539 ret
= increase_packet_size(pos
);
2541 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2551 int bt_ctf_field_structure_serialize(struct bt_ctf_field
*field
,
2552 struct bt_ctf_stream_pos
*pos
,
2553 enum bt_ctf_byte_order native_byte_order
)
2557 struct bt_ctf_field_structure
*structure
= container_of(
2558 field
, struct bt_ctf_field_structure
, parent
);
2560 BT_LOGV("Serializing structure field: addr=%p, pos-offset=%" PRId64
", "
2561 "native-bo=%s", field
, pos
->offset
,
2562 bt_ctf_byte_order_string(native_byte_order
));
2564 while (!bt_ctf_stream_pos_access_ok(pos
,
2565 offset_align(pos
->offset
, field
->type
->alignment
))) {
2566 ret
= increase_packet_size(pos
);
2568 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2573 if (!bt_ctf_stream_pos_align(pos
, field
->type
->alignment
)) {
2574 BT_LOGE("Cannot align packet's position: pos-offset=%" PRId64
", "
2575 "align=%u", pos
->offset
, field
->type
->alignment
);
2580 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2581 struct bt_ctf_field
*member
= g_ptr_array_index(
2582 structure
->fields
, i
);
2583 const char *field_name
= NULL
;
2585 if (BT_LOG_ON_WARN
) {
2586 ret
= bt_ctf_field_type_structure_get_field(
2587 field
->type
, &field_name
, NULL
, i
);
2591 BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64
", "
2592 "field-addr=%p, index=%" PRId64
,
2593 pos
->offset
, member
, i
);
2596 BT_LOGW("Cannot serialize structure field's field: field is not set: "
2597 "struct-field-addr=%p, "
2598 "field-name=\"%s\", index=%" PRId64
,
2599 field
, field_name
, i
);
2604 ret
= bt_ctf_field_serialize(member
, pos
, native_byte_order
);
2606 BT_LOGW("Cannot serialize structure field's field: "
2607 "struct-field-addr=%p, field-addr=%p, "
2608 "field-name=\"%s\", index=%" PRId64
,
2609 field
->type
, member
, field_name
, i
);
2618 int bt_ctf_field_variant_serialize(struct bt_ctf_field
*field
,
2619 struct bt_ctf_stream_pos
*pos
,
2620 enum bt_ctf_byte_order native_byte_order
)
2622 struct bt_ctf_field_variant
*variant
= container_of(
2623 field
, struct bt_ctf_field_variant
, parent
);
2625 BT_LOGV("Serializing variant field: addr=%p, pos-offset=%" PRId64
", "
2626 "native-bo=%s", field
, pos
->offset
,
2627 bt_ctf_byte_order_string(native_byte_order
));
2628 BT_LOGV_STR("Serializing variant field's payload field.");
2629 return bt_ctf_field_serialize(variant
->payload
, pos
,
2634 int bt_ctf_field_array_serialize(struct bt_ctf_field
*field
,
2635 struct bt_ctf_stream_pos
*pos
,
2636 enum bt_ctf_byte_order native_byte_order
)
2640 struct bt_ctf_field_array
*array
= container_of(
2641 field
, struct bt_ctf_field_array
, parent
);
2643 BT_LOGV("Serializing array field: addr=%p, pos-offset=%" PRId64
", "
2644 "native-bo=%s", field
, pos
->offset
,
2645 bt_ctf_byte_order_string(native_byte_order
));
2647 for (i
= 0; i
< array
->elements
->len
; i
++) {
2648 struct bt_ctf_field
*elem_field
=
2649 g_ptr_array_index(array
->elements
, i
);
2651 BT_LOGV("Serializing array field's element field: "
2652 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2653 pos
->offset
, elem_field
, i
);
2654 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2657 BT_LOGW("Cannot serialize array field's element field: "
2658 "array-field-addr=%p, field-addr=%p, "
2659 "index=%" PRId64
, field
, elem_field
, i
);
2668 int bt_ctf_field_sequence_serialize(struct bt_ctf_field
*field
,
2669 struct bt_ctf_stream_pos
*pos
,
2670 enum bt_ctf_byte_order native_byte_order
)
2674 struct bt_ctf_field_sequence
*sequence
= container_of(
2675 field
, struct bt_ctf_field_sequence
, parent
);
2677 BT_LOGV("Serializing sequence field: addr=%p, pos-offset=%" PRId64
", "
2678 "native-bo=%s", field
, pos
->offset
,
2679 bt_ctf_byte_order_string(native_byte_order
));
2681 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2682 struct bt_ctf_field
*elem_field
=
2683 g_ptr_array_index(sequence
->elements
, i
);
2685 BT_LOGV("Serializing sequence field's element field: "
2686 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2687 pos
->offset
, elem_field
, i
);
2688 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2691 BT_LOGW("Cannot serialize sequence field's element field: "
2692 "sequence-field-addr=%p, field-addr=%p, "
2693 "index=%" PRId64
, field
, elem_field
, i
);
2702 int bt_ctf_field_string_serialize(struct bt_ctf_field
*field
,
2703 struct bt_ctf_stream_pos
*pos
,
2704 enum bt_ctf_byte_order native_byte_order
)
2708 struct bt_ctf_field_string
*string
= container_of(field
,
2709 struct bt_ctf_field_string
, parent
);
2710 struct bt_ctf_field_type
*character_type
=
2711 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
2712 struct bt_ctf_field
*character
;
2714 BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64
", "
2715 "native-bo=%s", field
, pos
->offset
,
2716 bt_ctf_byte_order_string(native_byte_order
));
2718 BT_LOGV_STR("Creating character field from string field's character field type.");
2719 character
= bt_ctf_field_create(character_type
);
2721 for (i
= 0; i
< string
->payload
->len
+ 1; i
++) {
2722 const uint64_t chr
= (uint64_t) string
->payload
->str
[i
];
2724 ret
= bt_ctf_field_unsigned_integer_set_value(character
, chr
);
2726 BT_LOGW("Cannot set character field's value: "
2727 "pos-offset=%" PRId64
", field-addr=%p, "
2728 "index=%" PRId64
", char-int=%" PRIu64
,
2729 pos
->offset
, character
, i
, chr
);
2733 BT_LOGV("Serializing string field's character field: "
2734 "pos-offset=%" PRId64
", field-addr=%p, "
2735 "index=%" PRId64
", char-int=%" PRIu64
,
2736 pos
->offset
, character
, i
, chr
);
2737 ret
= bt_ctf_field_integer_serialize(character
, pos
,
2740 BT_LOGW_STR("Cannot serialize character field.");
2746 bt_put(character_type
);
2751 int bt_ctf_field_integer_copy(struct bt_ctf_field
*src
,
2752 struct bt_ctf_field
*dst
)
2754 struct bt_ctf_field_integer
*integer_src
, *integer_dst
;
2756 BT_LOGD("Copying integer field: src-field-addr=%p, dst-field-addr=%p",
2758 integer_src
= container_of(src
, struct bt_ctf_field_integer
, parent
);
2759 integer_dst
= container_of(dst
, struct bt_ctf_field_integer
, parent
);
2760 integer_dst
->payload
= integer_src
->payload
;
2761 BT_LOGD_STR("Copied integer field.");
2766 int bt_ctf_field_enumeration_copy(struct bt_ctf_field
*src
,
2767 struct bt_ctf_field
*dst
)
2770 struct bt_ctf_field_enumeration
*enum_src
, *enum_dst
;
2772 BT_LOGD("Copying enumeration field: src-field-addr=%p, dst-field-addr=%p",
2774 enum_src
= container_of(src
, struct bt_ctf_field_enumeration
, parent
);
2775 enum_dst
= container_of(dst
, struct bt_ctf_field_enumeration
, parent
);
2777 if (enum_src
->payload
) {
2778 BT_LOGD_STR("Copying enumeration field's payload field.");
2779 enum_dst
->payload
= bt_ctf_field_copy(enum_src
->payload
);
2780 if (!enum_dst
->payload
) {
2781 BT_LOGE_STR("Cannot copy enumeration field's payload field.");
2787 BT_LOGD_STR("Copied enumeration field.");
2793 int bt_ctf_field_floating_point_copy(
2794 struct bt_ctf_field
*src
, struct bt_ctf_field
*dst
)
2796 struct bt_ctf_field_floating_point
*float_src
, *float_dst
;
2798 BT_LOGD("Copying floating point number field: src-field-addr=%p, dst-field-addr=%p",
2800 float_src
= container_of(src
, struct bt_ctf_field_floating_point
,
2802 float_dst
= container_of(dst
, struct bt_ctf_field_floating_point
,
2804 float_dst
->payload
= float_src
->payload
;
2805 BT_LOGD_STR("Copied floating point number field.");
2810 int bt_ctf_field_structure_copy(struct bt_ctf_field
*src
,
2811 struct bt_ctf_field
*dst
)
2815 struct bt_ctf_field_structure
*struct_src
, *struct_dst
;
2817 BT_LOGD("Copying structure field: src-field-addr=%p, dst-field-addr=%p",
2819 struct_src
= container_of(src
, struct bt_ctf_field_structure
, parent
);
2820 struct_dst
= container_of(dst
, struct bt_ctf_field_structure
, parent
);
2822 /* This field_name_to_index HT is owned by the structure field type */
2823 struct_dst
->field_name_to_index
= struct_src
->field_name_to_index
;
2824 g_ptr_array_set_size(struct_dst
->fields
, struct_src
->fields
->len
);
2826 for (i
= 0; i
< struct_src
->fields
->len
; i
++) {
2827 struct bt_ctf_field
*field
=
2828 g_ptr_array_index(struct_src
->fields
, i
);
2829 struct bt_ctf_field
*field_copy
= NULL
;
2832 BT_LOGD("Copying structure field's field: src-field-addr=%p"
2833 "index=%" PRId64
, field
, i
);
2834 field_copy
= bt_ctf_field_copy(field
);
2836 BT_LOGE("Cannot copy structure field's field: "
2837 "src-field-addr=%p, index=%" PRId64
,
2844 g_ptr_array_index(struct_dst
->fields
, i
) = field_copy
;
2847 BT_LOGD_STR("Copied structure field.");
2854 int bt_ctf_field_variant_copy(struct bt_ctf_field
*src
,
2855 struct bt_ctf_field
*dst
)
2858 struct bt_ctf_field_variant
*variant_src
, *variant_dst
;
2860 BT_LOGD("Copying variant field: src-field-addr=%p, dst-field-addr=%p",
2862 variant_src
= container_of(src
, struct bt_ctf_field_variant
, parent
);
2863 variant_dst
= container_of(dst
, struct bt_ctf_field_variant
, parent
);
2865 if (variant_src
->tag
) {
2866 BT_LOGD_STR("Copying variant field's tag field.");
2867 variant_dst
->tag
= bt_ctf_field_copy(variant_src
->tag
);
2868 if (!variant_dst
->tag
) {
2869 BT_LOGE_STR("Cannot copy variant field's tag field.");
2874 if (variant_src
->payload
) {
2875 BT_LOGD_STR("Copying variant field's payload field.");
2876 variant_dst
->payload
= bt_ctf_field_copy(variant_src
->payload
);
2877 if (!variant_dst
->payload
) {
2878 BT_LOGE_STR("Cannot copy variant field's payload field.");
2884 BT_LOGD_STR("Copied variant field.");
2891 int bt_ctf_field_array_copy(struct bt_ctf_field
*src
,
2892 struct bt_ctf_field
*dst
)
2896 struct bt_ctf_field_array
*array_src
, *array_dst
;
2898 BT_LOGD("Copying array field: src-field-addr=%p, dst-field-addr=%p",
2900 array_src
= container_of(src
, struct bt_ctf_field_array
, parent
);
2901 array_dst
= container_of(dst
, struct bt_ctf_field_array
, parent
);
2903 g_ptr_array_set_size(array_dst
->elements
, array_src
->elements
->len
);
2904 for (i
= 0; i
< array_src
->elements
->len
; i
++) {
2905 struct bt_ctf_field
*field
=
2906 g_ptr_array_index(array_src
->elements
, i
);
2907 struct bt_ctf_field
*field_copy
= NULL
;
2910 BT_LOGD("Copying array field's element field: field-addr=%p, "
2911 "index=%" PRId64
, field
, i
);
2912 field_copy
= bt_ctf_field_copy(field
);
2914 BT_LOGE("Cannot copy array field's element field: "
2915 "src-field-addr=%p, index=%" PRId64
,
2922 g_ptr_array_index(array_dst
->elements
, i
) = field_copy
;
2925 BT_LOGD_STR("Copied array field.");
2932 int bt_ctf_field_sequence_copy(struct bt_ctf_field
*src
,
2933 struct bt_ctf_field
*dst
)
2937 struct bt_ctf_field_sequence
*sequence_src
, *sequence_dst
;
2938 struct bt_ctf_field
*src_length
;
2939 struct bt_ctf_field
*dst_length
;
2941 BT_LOGD("Copying sequence field: src-field-addr=%p, dst-field-addr=%p",
2943 sequence_src
= container_of(src
, struct bt_ctf_field_sequence
, parent
);
2944 sequence_dst
= container_of(dst
, struct bt_ctf_field_sequence
, parent
);
2946 src_length
= bt_ctf_field_sequence_get_length(src
);
2948 /* no length set yet: keep destination sequence empty */
2952 /* copy source length */
2953 BT_LOGD_STR("Copying sequence field's length field.");
2954 dst_length
= bt_ctf_field_copy(src_length
);
2957 BT_LOGE_STR("Cannot copy sequence field's length field.");
2962 /* this will initialize the destination sequence's internal array */
2963 ret
= bt_ctf_field_sequence_set_length(dst
, dst_length
);
2966 BT_LOGE("Cannot set sequence field copy's length field: "
2967 "dst-length-field-addr=%p", dst_length
);
2972 assert(sequence_dst
->elements
->len
== sequence_src
->elements
->len
);
2974 for (i
= 0; i
< sequence_src
->elements
->len
; i
++) {
2975 struct bt_ctf_field
*field
=
2976 g_ptr_array_index(sequence_src
->elements
, i
);
2977 struct bt_ctf_field
*field_copy
= NULL
;
2980 BT_LOGD("Copying sequence field's element field: field-addr=%p, "
2981 "index=%" PRId64
, field
, i
);
2982 field_copy
= bt_ctf_field_copy(field
);
2984 BT_LOGE("Cannot copy sequence field's element field: "
2985 "src-field-addr=%p, index=%" PRId64
,
2992 g_ptr_array_index(sequence_dst
->elements
, i
) = field_copy
;
2995 BT_LOGD_STR("Copied sequence field.");
3002 int bt_ctf_field_string_copy(struct bt_ctf_field
*src
,
3003 struct bt_ctf_field
*dst
)
3006 struct bt_ctf_field_string
*string_src
, *string_dst
;
3008 BT_LOGD("Copying string field: src-field-addr=%p, dst-field-addr=%p",
3010 string_src
= container_of(src
, struct bt_ctf_field_string
, parent
);
3011 string_dst
= container_of(dst
, struct bt_ctf_field_string
, parent
);
3013 if (string_src
->payload
) {
3014 string_dst
->payload
= g_string_new(string_src
->payload
->str
);
3015 if (!string_dst
->payload
) {
3016 BT_LOGE_STR("Failed to allocate a GString.");
3022 BT_LOGD_STR("Copied string field.");
3029 int increase_packet_size(struct bt_ctf_stream_pos
*pos
)
3034 BT_LOGV("Increasing packet size: pos-offset=%" PRId64
", "
3035 "cur-packet-size=%" PRIu64
,
3036 pos
->offset
, pos
->packet_size
);
3037 ret
= munmap_align(pos
->base_mma
);
3039 BT_LOGE_ERRNO("Failed to perform an aligned memory unmapping",
3044 pos
->packet_size
+= PACKET_LEN_INCREMENT
;
3046 ret
= bt_posix_fallocate(pos
->fd
, pos
->mmap_offset
,
3047 pos
->packet_size
/ CHAR_BIT
);
3048 } while (ret
== EINTR
);
3050 BT_LOGE_ERRNO("Failed to preallocate memory space",
3057 pos
->base_mma
= mmap_align(pos
->packet_size
/ CHAR_BIT
, pos
->prot
,
3058 pos
->flags
, pos
->fd
, pos
->mmap_offset
);
3059 if (pos
->base_mma
== MAP_FAILED
) {
3060 BT_LOGE_ERRNO("Failed to perform an aligned memory mapping",
3065 BT_LOGV("Increased packet size: pos-offset=%" PRId64
", "
3066 "new-packet-size=%" PRIu64
,
3067 pos
->offset
, pos
->packet_size
);
3068 assert(pos
->packet_size
% 8 == 0);
3075 void generic_field_freeze(struct bt_ctf_field
*field
)
3081 void bt_ctf_field_enumeration_freeze(struct bt_ctf_field
*field
)
3083 struct bt_ctf_field_enumeration
*enum_field
=
3084 container_of(field
, struct bt_ctf_field_enumeration
, parent
);
3086 BT_LOGD("Freezing enumeration field object: addr=%p", field
);
3087 BT_LOGD("Freezing enumeration field object's contained payload field: payload-field-addr=%p", enum_field
->payload
);
3088 bt_ctf_field_freeze(enum_field
->payload
);
3089 generic_field_freeze(field
);
3093 void bt_ctf_field_structure_freeze(struct bt_ctf_field
*field
)
3096 struct bt_ctf_field_structure
*structure_field
=
3097 container_of(field
, struct bt_ctf_field_structure
, parent
);
3099 BT_LOGD("Freezing structure field object: addr=%p", field
);
3101 for (i
= 0; i
< structure_field
->fields
->len
; i
++) {
3102 struct bt_ctf_field
*field
=
3103 g_ptr_array_index(structure_field
->fields
, i
);
3105 BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64
,
3107 bt_ctf_field_freeze(field
);
3110 generic_field_freeze(field
);
3114 void bt_ctf_field_variant_freeze(struct bt_ctf_field
*field
)
3116 struct bt_ctf_field_variant
*variant_field
=
3117 container_of(field
, struct bt_ctf_field_variant
, parent
);
3119 BT_LOGD("Freezing variant field object: addr=%p", field
);
3120 BT_LOGD("Freezing variant field object's tag field: tag-field-addr=%p", variant_field
->tag
);
3121 bt_ctf_field_freeze(variant_field
->tag
);
3122 BT_LOGD("Freezing variant field object's payload field: payload-field-addr=%p", variant_field
->payload
);
3123 bt_ctf_field_freeze(variant_field
->payload
);
3124 generic_field_freeze(field
);
3128 void bt_ctf_field_array_freeze(struct bt_ctf_field
*field
)
3131 struct bt_ctf_field_array
*array_field
=
3132 container_of(field
, struct bt_ctf_field_array
, parent
);
3134 BT_LOGD("Freezing array field object: addr=%p", field
);
3136 for (i
= 0; i
< array_field
->elements
->len
; i
++) {
3137 struct bt_ctf_field
*elem_field
=
3138 g_ptr_array_index(array_field
->elements
, i
);
3140 BT_LOGD("Freezing array field object's element field: "
3141 "element-field-addr=%p, index=%" PRId64
,
3143 bt_ctf_field_freeze(elem_field
);
3146 generic_field_freeze(field
);
3150 void bt_ctf_field_sequence_freeze(struct bt_ctf_field
*field
)
3153 struct bt_ctf_field_sequence
*sequence_field
=
3154 container_of(field
, struct bt_ctf_field_sequence
, parent
);
3156 BT_LOGD("Freezing sequence field object: addr=%p", field
);
3157 BT_LOGD("Freezing sequence field object's length field: length-field-addr=%p",
3158 sequence_field
->length
);
3159 bt_ctf_field_freeze(sequence_field
->length
);
3161 for (i
= 0; i
< sequence_field
->elements
->len
; i
++) {
3162 struct bt_ctf_field
*elem_field
=
3163 g_ptr_array_index(sequence_field
->elements
, i
);
3165 BT_LOGD("Freezing sequence field object's element field: "
3166 "element-field-addr=%p, index=%" PRId64
,
3168 bt_ctf_field_freeze(elem_field
);
3171 generic_field_freeze(field
);
3175 void bt_ctf_field_freeze(struct bt_ctf_field
*field
)
3177 enum bt_ctf_field_type_id type_id
;
3183 if (field
->frozen
) {
3187 BT_LOGD("Freezing field object: addr=%p", field
);
3188 type_id
= bt_ctf_field_get_type_id(field
);
3189 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
3190 type_id
< BT_CTF_NR_TYPE_IDS
);
3191 field_freeze_funcs
[type_id
](field
);
3197 bt_bool
bt_ctf_field_generic_is_set(struct bt_ctf_field
*field
)
3199 return field
&& field
->payload_set
;
3203 bt_bool
bt_ctf_field_enumeration_is_set(struct bt_ctf_field
*field
)
3205 bt_bool is_set
= BT_FALSE
;
3206 struct bt_ctf_field_enumeration
*enumeration
;
3212 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
3214 if (!enumeration
->payload
) {
3218 is_set
= bt_ctf_field_is_set(enumeration
->payload
);
3224 bt_bool
bt_ctf_field_structure_is_set(struct bt_ctf_field
*field
)
3226 bt_bool is_set
= BT_FALSE
;
3228 struct bt_ctf_field_structure
*structure
;
3234 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
3235 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3236 is_set
= bt_ctf_field_is_set(structure
->fields
->pdata
[i
]);
3246 bt_bool
bt_ctf_field_variant_is_set(struct bt_ctf_field
*field
)
3248 bt_bool is_set
= BT_FALSE
;
3249 struct bt_ctf_field_variant
*variant
;
3255 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
3256 is_set
= bt_ctf_field_is_set(variant
->payload
);
3262 bt_bool
bt_ctf_field_array_is_set(struct bt_ctf_field
*field
)
3265 bt_bool is_set
= BT_FALSE
;
3266 struct bt_ctf_field_array
*array
;
3272 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
3273 for (i
= 0; i
< array
->elements
->len
; i
++) {
3274 is_set
= bt_ctf_field_is_set(array
->elements
->pdata
[i
]);
3284 bt_bool
bt_ctf_field_sequence_is_set(struct bt_ctf_field
*field
)
3287 bt_bool is_set
= BT_FALSE
;
3288 struct bt_ctf_field_sequence
*sequence
;
3294 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
3295 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
3296 is_set
= bt_ctf_field_validate(sequence
->elements
->pdata
[i
]);