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_value(struct bt_ctf_field
*);
100 int bt_ctf_field_structure_reset_value(struct bt_ctf_field
*);
102 int bt_ctf_field_variant_reset_value(struct bt_ctf_field
*);
104 int bt_ctf_field_enumeration_reset_value(struct bt_ctf_field
*);
106 int bt_ctf_field_array_reset_value(struct bt_ctf_field
*);
108 int bt_ctf_field_sequence_reset_value(struct bt_ctf_field
*);
110 int bt_ctf_field_string_reset_value(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_value_is_set(struct bt_ctf_field
*);
171 bt_bool
bt_ctf_field_structure_value_is_set(struct bt_ctf_field
*);
173 bt_bool
bt_ctf_field_variant_value_is_set(struct bt_ctf_field
*);
175 bt_bool
bt_ctf_field_enumeration_value_is_set(struct bt_ctf_field
*);
177 bt_bool
bt_ctf_field_array_value_is_set(struct bt_ctf_field
*);
179 bt_bool
bt_ctf_field_sequence_value_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_value_funcs
[])(struct bt_ctf_field
*) = {
225 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_reset_value
,
226 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_reset_value
,
227 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_reset_value
,
228 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_reset_value
,
229 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_reset_value
,
230 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_reset_value
,
231 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_reset_value
,
232 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_reset_value
,
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_value_is_set_funcs
[])(struct bt_ctf_field
*) = {
276 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_value_is_set
,
277 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_value_is_set
,
278 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_value_is_set
,
279 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_value_is_set
,
280 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_value_is_set
,
281 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_value_is_set
,
282 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_value_is_set
,
283 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_generic_value_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
*ret
= NULL
;
516 struct bt_ctf_field_structure
*structure
;
518 GHashTable
*field_name_to_index
;
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_name_to_index
=
540 container_of(field
->type
, struct bt_ctf_field_type_structure
,
541 parent
)->field_name_to_index
;
542 field_quark
= g_quark_from_string(name
);
543 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
544 if (!g_hash_table_lookup_extended(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, name=\"%s\"",
549 field
, field
->type
, name
);
553 ret
= bt_get(structure
->fields
->pdata
[index
]);
559 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_index(
560 struct bt_ctf_field
*field
, uint64_t index
)
562 struct bt_ctf_field_structure
*structure
;
563 struct bt_ctf_field
*ret
= NULL
;
566 BT_LOGW_STR("Invalid parameter: field is NULL.");
570 if (bt_ctf_field_type_get_type_id(field
->type
) !=
571 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
572 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
573 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
575 bt_ctf_field_type_id_string(field
->type
->id
));
579 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
580 if (index
>= structure
->fields
->len
) {
581 BT_LOGW("Invalid parameter: index is out of bounds: "
582 "addr=%p, index=%" PRIu64
", count=%u",
583 field
, index
, structure
->fields
->len
);
587 ret
= bt_get(structure
->fields
->pdata
[index
]);
592 int bt_ctf_field_structure_set_field_by_name(struct bt_ctf_field
*field
,
593 const char *name
, struct bt_ctf_field
*value
)
597 struct bt_ctf_field_structure
*structure
;
598 struct bt_ctf_field_type
*expected_field_type
= NULL
;
600 GHashTable
*field_name_to_index
;
603 BT_LOGW_STR("Invalid parameter: structure field is NULL.");
609 BT_LOGW_STR("Invalid parameter: field name is NULL.");
615 BT_LOGW_STR("Invalid parameter: field is NULL.");
620 if (bt_ctf_field_type_get_type_id(field
->type
) !=
621 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
622 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
623 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
625 bt_ctf_field_type_id_string(field
->type
->id
));
630 field_quark
= g_quark_from_string(name
);
631 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
632 expected_field_type
=
633 bt_ctf_field_type_structure_get_field_type_by_name(field
->type
,
636 if (bt_ctf_field_type_compare(expected_field_type
, value
->type
)) {
637 BT_LOGW("Invalid parameter: field type of field to set is different from the expected field type: "
638 "struct-field-addr=%p, field-addr=%p, "
639 "field-ft-addr=%p, expected-ft-addr=%p",
640 field
, value
, value
->type
, expected_field_type
);
645 field_name_to_index
=
646 container_of(field
->type
, struct bt_ctf_field_type_structure
,
647 parent
)->field_name_to_index
;
648 if (!g_hash_table_lookup_extended(field_name_to_index
,
649 GUINT_TO_POINTER(field_quark
), NULL
,
650 (gpointer
*) &index
)) {
651 BT_LOGV("Invalid parameter: no such field in structure field's type: "
652 "struct-field-addr=%p, struct-ft-addr=%p, "
653 "field-ft-addr=%p, name=\"%s\"",
654 field
, field
->type
, value
->type
, name
);
659 BT_MOVE(structure
->fields
->pdata
[index
], value
);
661 if (expected_field_type
) {
662 bt_put(expected_field_type
);
667 struct bt_ctf_field
*bt_ctf_field_array_get_field(struct bt_ctf_field
*field
,
670 struct bt_ctf_field
*new_field
= NULL
;
671 struct bt_ctf_field_type
*field_type
= NULL
;
672 struct bt_ctf_field_array
*array
;
675 BT_LOGW_STR("Invalid parameter: field is NULL.");
679 if (bt_ctf_field_type_get_type_id(field
->type
) !=
680 BT_CTF_FIELD_TYPE_ID_ARRAY
) {
681 BT_LOGW("Invalid parameter: field's type is not an array field type: "
682 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
684 bt_ctf_field_type_id_string(field
->type
->id
));
688 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
689 if (index
>= array
->elements
->len
) {
690 BT_LOGW("Invalid parameter: index is out of bounds: "
691 "addr=%p, index=%" PRIu64
", count=%u",
692 field
, index
, array
->elements
->len
);
696 field_type
= bt_ctf_field_type_array_get_element_type(field
->type
);
697 if (array
->elements
->pdata
[(size_t)index
]) {
698 new_field
= array
->elements
->pdata
[(size_t)index
];
702 /* We don't want to modify this field if it's frozen */
705 * Not logging a warning here because the user could
706 * legitimately check if a array field is set with
707 * this function: if the preconditions are satisfied,
708 * a NULL return value means this.
710 BT_LOGV("Not creating a field because array field is frozen: "
711 "array-field-addr=%p, index=%" PRIu64
, field
, index
);
715 new_field
= bt_ctf_field_create(field_type
);
716 array
->elements
->pdata
[(size_t)index
] = new_field
;
727 struct bt_ctf_field
*bt_ctf_field_sequence_get_field(struct bt_ctf_field
*field
,
730 struct bt_ctf_field
*new_field
= NULL
;
731 struct bt_ctf_field_type
*field_type
= NULL
;
732 struct bt_ctf_field_sequence
*sequence
;
735 BT_LOGW_STR("Invalid parameter: field is NULL.");
739 if (bt_ctf_field_type_get_type_id(field
->type
) !=
740 BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
741 BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
742 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
744 bt_ctf_field_type_id_string(field
->type
->id
));
748 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
749 if (!sequence
->elements
) {
750 BT_LOGV("Sequence field's elements do not exist: addr=%p",
755 if (index
>= sequence
->elements
->len
) {
756 BT_LOGW("Invalid parameter: index is out of bounds: "
757 "addr=%p, index=%" PRIu64
", count=%u",
758 field
, index
, sequence
->elements
->len
);
762 field_type
= bt_ctf_field_type_sequence_get_element_type(field
->type
);
763 if (sequence
->elements
->pdata
[(size_t) index
]) {
764 new_field
= sequence
->elements
->pdata
[(size_t) index
];
768 /* We don't want to modify this field if it's frozen */
771 * Not logging a warning here because the user could
772 * legitimately check if a sequence field is set with
773 * this function: if the preconditions are satisfied,
774 * a NULL return value means this.
776 BT_LOGV("Not creating a field because sequence field is frozen: "
777 "sequence-field-addr=%p, index=%" PRIu64
, field
, index
);
781 new_field
= bt_ctf_field_create(field_type
);
782 sequence
->elements
->pdata
[(size_t) index
] = new_field
;
793 struct bt_ctf_field
*bt_ctf_field_variant_get_field(struct bt_ctf_field
*field
,
794 struct bt_ctf_field
*tag_field
)
796 struct bt_ctf_field
*new_field
= NULL
;
797 struct bt_ctf_field_variant
*variant
;
798 struct bt_ctf_field_type_variant
*variant_type
;
799 struct bt_ctf_field_type
*field_type
;
800 struct bt_ctf_field
*tag_enum
= NULL
;
801 struct bt_ctf_field_integer
*tag_enum_integer
;
802 int64_t tag_enum_value
;
805 BT_LOGW_STR("Invalid parameter: field is NULL.");
810 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
814 if (bt_ctf_field_type_get_type_id(field
->type
) !=
815 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
816 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
817 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
819 bt_ctf_field_type_id_string(field
->type
->id
));
823 if (bt_ctf_field_type_get_type_id(tag_field
->type
) !=
824 BT_CTF_FIELD_TYPE_ID_ENUM
) {
825 BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: "
826 "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field
,
828 bt_ctf_field_type_id_string(tag_field
->type
->id
));
832 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
833 variant_type
= container_of(field
->type
,
834 struct bt_ctf_field_type_variant
, parent
);
835 tag_enum
= bt_ctf_field_enumeration_get_container(tag_field
);
840 tag_enum_integer
= container_of(tag_enum
, struct bt_ctf_field_integer
,
843 if (bt_ctf_field_validate(tag_field
) < 0) {
844 BT_LOGW("Invalid parameter: tag field is invalid: "
845 "variant-field-addr=%p, tag-field-addr=%p",
850 tag_enum_value
= tag_enum_integer
->payload
.signd
;
853 * If the variant currently has a tag and a payload, and if the
854 * requested tag value is the same as the current one, return
855 * the current payload instead of creating a fresh one.
857 if (variant
->tag
&& variant
->payload
) {
858 struct bt_ctf_field
*cur_tag_container
= NULL
;
859 struct bt_ctf_field_integer
*cur_tag_enum_integer
;
860 int64_t cur_tag_value
;
863 bt_ctf_field_enumeration_get_container(variant
->tag
);
864 assert(cur_tag_container
);
865 cur_tag_enum_integer
= container_of(cur_tag_container
,
866 struct bt_ctf_field_integer
, parent
);
867 bt_put(cur_tag_container
);
868 cur_tag_value
= cur_tag_enum_integer
->payload
.signd
;
870 if (cur_tag_value
== tag_enum_value
) {
871 new_field
= variant
->payload
;
877 /* We don't want to modify this field if it's frozen */
880 * Not logging a warning here because the user could
881 * legitimately check if a variant field is set with
882 * this function: if the preconditions are satisfied,
883 * a NULL return value means this.
885 BT_LOGV("Not creating a field because variant field is frozen: "
886 "variant-field-addr=%p, tag-field-addr=%p",
891 field_type
= bt_ctf_field_type_variant_get_field_type_signed(
892 variant_type
, tag_enum_value
);
894 BT_LOGW("Cannot get variant field type's field: "
895 "variant-field-addr=%p, variant-ft-addr=%p, "
896 "tag-value-signed=%" PRId64
,
897 field
, variant_type
, tag_enum_value
);
901 new_field
= bt_ctf_field_create(field_type
);
903 BT_LOGW("Cannot create field: "
904 "variant-field-addr=%p, variant-ft-addr=%p, "
905 "field-ft-addr=%p", field
, field
->type
, field_type
);
909 bt_put(variant
->tag
);
910 bt_put(variant
->payload
);
913 variant
->tag
= tag_field
;
914 variant
->payload
= new_field
;
920 struct bt_ctf_field
*bt_ctf_field_variant_get_current_field(
921 struct bt_ctf_field
*variant_field
)
923 struct bt_ctf_field
*current_field
= NULL
;
924 struct bt_ctf_field_variant
*variant
;
926 if (!variant_field
) {
927 BT_LOGW_STR("Invalid parameter: field is NULL.");
931 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
932 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
933 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
934 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
936 bt_ctf_field_type_id_string(variant_field
->type
->id
));
940 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
943 if (variant
->payload
) {
944 current_field
= variant
->payload
;
945 bt_get(current_field
);
950 return current_field
;
953 struct bt_ctf_field
*bt_ctf_field_variant_get_tag(
954 struct bt_ctf_field
*variant_field
)
956 struct bt_ctf_field
*tag
= NULL
;
957 struct bt_ctf_field_variant
*variant
;
959 if (!variant_field
) {
960 BT_LOGW_STR("Invalid parameter: field is NULL.");
964 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
965 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
966 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
967 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
969 bt_ctf_field_type_id_string(variant_field
->type
->id
));
973 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
976 tag
= bt_get(variant
->tag
);
982 struct bt_ctf_field
*bt_ctf_field_enumeration_get_container(
983 struct bt_ctf_field
*field
)
985 struct bt_ctf_field
*container
= NULL
;
986 struct bt_ctf_field_enumeration
*enumeration
;
989 BT_LOGW_STR("Invalid parameter: field is NULL.");
993 if (bt_ctf_field_type_get_type_id(field
->type
) !=
994 BT_CTF_FIELD_TYPE_ID_ENUM
) {
995 BT_LOGW("Invalid parameter: field's type is not an enumeration field type: "
996 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
998 bt_ctf_field_type_id_string(field
->type
->id
));
1002 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
1004 if (!enumeration
->payload
) {
1005 /* We don't want to modify this field if it's frozen */
1006 if (field
->frozen
) {
1008 * Not logging a warning here because the user
1009 * could legitimately check if an enumeration's
1010 * container field is set with this function: if
1011 * the preconditions are satisfied, a NULL
1012 * return value means this.
1014 BT_LOGV("Not creating a field because enumeration field is frozen: "
1015 "enum-field-addr=%p", field
);
1019 struct bt_ctf_field_type_enumeration
*enumeration_type
=
1020 container_of(field
->type
,
1021 struct bt_ctf_field_type_enumeration
, parent
);
1022 enumeration
->payload
=
1023 bt_ctf_field_create(enumeration_type
->container
);
1026 container
= enumeration
->payload
;
1032 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1033 bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field
*field
)
1036 struct bt_ctf_field
*container
= NULL
;
1037 struct bt_ctf_field_type
*container_type
= NULL
;
1038 struct bt_ctf_field_type_integer
*integer_type
= NULL
;
1039 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1041 container
= bt_ctf_field_enumeration_get_container(field
);
1043 BT_LOGW("Invalid parameter: enumeration field has no container field: "
1048 container_type
= bt_ctf_field_get_type(container
);
1049 assert(container_type
);
1050 integer_type
= container_of(container_type
,
1051 struct bt_ctf_field_type_integer
, parent
);
1053 if (!integer_type
->is_signed
) {
1056 ret
= bt_ctf_field_unsigned_integer_get_value(container
,
1059 BT_LOGW("Cannot get value from signed enumeration field's payload field: "
1060 "enum-field-addr=%p, payload-field-addr=%p",
1062 goto error_put_container_type
;
1064 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1065 field
->type
, value
);
1069 ret
= bt_ctf_field_signed_integer_get_value(container
,
1072 BT_LOGW("Cannot get value from unsigned enumeration field's payload field: "
1073 "enum-field-addr=%p, payload-field-addr=%p",
1075 goto error_put_container_type
;
1077 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1078 field
->type
, value
);
1081 error_put_container_type
:
1082 bt_put(container_type
);
1088 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field
*field
,
1092 struct bt_ctf_field_integer
*integer
;
1093 struct bt_ctf_field_type_integer
*integer_type
;
1096 BT_LOGW_STR("Invalid parameter: field is NULL.");
1102 BT_LOGW_STR("Invalid parameter: value is NULL.");
1107 if (!field
->payload_set
) {
1108 BT_LOGV("Field's payload is not set: addr=%p", field
);
1113 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1114 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1115 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1116 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1118 bt_ctf_field_type_id_string(field
->type
->id
));
1123 integer_type
= container_of(field
->type
,
1124 struct bt_ctf_field_type_integer
, parent
);
1125 if (!integer_type
->is_signed
) {
1126 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1127 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1132 integer
= container_of(field
,
1133 struct bt_ctf_field_integer
, parent
);
1134 *value
= integer
->payload
.signd
;
1139 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field
*field
,
1143 struct bt_ctf_field_integer
*integer
;
1144 struct bt_ctf_field_type_integer
*integer_type
;
1146 int64_t min_value
, max_value
;
1149 BT_LOGW_STR("Invalid parameter: field is NULL.");
1154 if (field
->frozen
) {
1155 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1161 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1162 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1163 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1164 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1166 bt_ctf_field_type_id_string(field
->type
->id
));
1171 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1172 integer_type
= container_of(field
->type
,
1173 struct bt_ctf_field_type_integer
, parent
);
1174 if (!integer_type
->is_signed
) {
1175 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1176 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1181 size
= integer_type
->size
;
1182 min_value
= -(1ULL << (size
- 1));
1183 max_value
= (1ULL << (size
- 1)) - 1;
1184 if (value
< min_value
|| value
> max_value
) {
1185 BT_LOGW("Invalid parameter: value is out of bounds: "
1186 "addr=%p, value=%" PRId64
", "
1187 "min-value=%" PRId64
", max-value=%" PRId64
,
1188 field
, value
, min_value
, max_value
);
1193 integer
->payload
.signd
= value
;
1194 integer
->parent
.payload_set
= true;
1199 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field
*field
,
1203 struct bt_ctf_field_integer
*integer
;
1204 struct bt_ctf_field_type_integer
*integer_type
;
1207 BT_LOGW_STR("Invalid parameter: field is NULL.");
1213 BT_LOGW_STR("Invalid parameter: value is NULL.");
1218 if (!field
->payload_set
) {
1219 BT_LOGV("Field's payload is not set: addr=%p", field
);
1224 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1225 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1226 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1227 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1229 bt_ctf_field_type_id_string(field
->type
->id
));
1234 integer_type
= container_of(field
->type
,
1235 struct bt_ctf_field_type_integer
, parent
);
1236 if (integer_type
->is_signed
) {
1237 BT_LOGW("Invalid parameter: integer field's type is signed: "
1238 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1243 integer
= container_of(field
,
1244 struct bt_ctf_field_integer
, parent
);
1245 *value
= integer
->payload
.unsignd
;
1250 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field
*field
,
1254 struct bt_ctf_field_integer
*integer
;
1255 struct bt_ctf_field_type_integer
*integer_type
;
1260 BT_LOGW_STR("Invalid parameter: field is NULL.");
1265 if (field
->frozen
) {
1266 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1272 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1273 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1274 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1275 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1277 bt_ctf_field_type_id_string(field
->type
->id
));
1282 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1283 integer_type
= container_of(field
->type
,
1284 struct bt_ctf_field_type_integer
, parent
);
1285 if (integer_type
->is_signed
) {
1286 BT_LOGW("Invalid parameter: integer field's type is signed: "
1287 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1292 size
= integer_type
->size
;
1293 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
1294 if (value
> max_value
) {
1295 BT_LOGW("Invalid parameter: value is out of bounds: "
1296 "addr=%p, value=%" PRIu64
", "
1297 "min-value=%" PRIu64
", max-value=%" PRIu64
,
1298 field
, value
, (uint64_t) 0, max_value
);
1303 integer
->payload
.unsignd
= value
;
1304 integer
->parent
.payload_set
= true;
1309 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field
*field
,
1313 struct bt_ctf_field_floating_point
*floating_point
;
1316 BT_LOGW_STR("Invalid parameter: field is NULL.");
1322 BT_LOGW_STR("Invalid parameter: value is NULL.");
1327 if (!field
->payload_set
) {
1328 BT_LOGV("Field's payload is not set: addr=%p", field
);
1333 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1334 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1335 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1336 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1338 bt_ctf_field_type_id_string(field
->type
->id
));
1343 floating_point
= container_of(field
,
1344 struct bt_ctf_field_floating_point
, parent
);
1345 *value
= floating_point
->payload
;
1350 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field
*field
,
1354 struct bt_ctf_field_floating_point
*floating_point
;
1357 BT_LOGW_STR("Invalid parameter: field is NULL.");
1362 if (field
->frozen
) {
1363 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1369 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1370 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1371 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1372 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1374 bt_ctf_field_type_id_string(field
->type
->id
));
1379 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
1381 floating_point
->payload
= value
;
1382 floating_point
->parent
.payload_set
= true;
1387 const char *bt_ctf_field_string_get_value(struct bt_ctf_field
*field
)
1389 const char *ret
= NULL
;
1390 struct bt_ctf_field_string
*string
;
1393 BT_LOGW_STR("Invalid parameter: field is NULL.");
1397 if (!field
->payload_set
) {
1398 BT_LOGV("Field's payload is not set: addr=%p", field
);
1402 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1403 BT_CTF_FIELD_TYPE_ID_STRING
) {
1404 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1405 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1407 bt_ctf_field_type_id_string(field
->type
->id
));
1411 string
= container_of(field
,
1412 struct bt_ctf_field_string
, parent
);
1413 ret
= string
->payload
->str
;
1418 int bt_ctf_field_string_set_value(struct bt_ctf_field
*field
,
1422 struct bt_ctf_field_string
*string
;
1425 BT_LOGW_STR("Invalid parameter: field is NULL.");
1431 BT_LOGW_STR("Invalid parameter: value is NULL.");
1436 if (field
->frozen
) {
1437 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1443 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1444 BT_CTF_FIELD_TYPE_ID_STRING
) {
1445 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1446 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1448 bt_ctf_field_type_id_string(field
->type
->id
));
1453 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
1454 if (string
->payload
) {
1455 g_string_assign(string
->payload
, value
);
1457 string
->payload
= g_string_new(value
);
1460 string
->parent
.payload_set
= true;
1465 int bt_ctf_field_string_append(struct bt_ctf_field
*field
,
1469 struct bt_ctf_field_string
*string_field
;
1472 BT_LOGW_STR("Invalid parameter: field is NULL.");
1478 BT_LOGW_STR("Invalid parameter: value is NULL.");
1483 if (field
->frozen
) {
1484 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1490 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1491 BT_CTF_FIELD_TYPE_ID_STRING
) {
1492 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1493 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1495 bt_ctf_field_type_id_string(field
->type
->id
));
1500 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1502 if (string_field
->payload
) {
1503 g_string_append(string_field
->payload
, value
);
1505 string_field
->payload
= g_string_new(value
);
1508 string_field
->parent
.payload_set
= true;
1514 int bt_ctf_field_string_append_len(struct bt_ctf_field
*field
,
1515 const char *value
, unsigned int length
)
1519 unsigned int effective_length
= length
;
1520 struct bt_ctf_field_string
*string_field
;
1523 BT_LOGW_STR("Invalid parameter: field is NULL.");
1529 BT_LOGW_STR("Invalid parameter: value is NULL.");
1534 if (field
->frozen
) {
1535 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1541 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1542 BT_CTF_FIELD_TYPE_ID_STRING
) {
1543 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1544 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1546 bt_ctf_field_type_id_string(field
->type
->id
));
1551 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1553 /* make sure no null bytes are appended */
1554 for (i
= 0; i
< length
; ++i
) {
1555 if (value
[i
] == '\0') {
1556 effective_length
= i
;
1561 if (string_field
->payload
) {
1562 g_string_append_len(string_field
->payload
, value
,
1565 string_field
->payload
= g_string_new_len(value
,
1569 string_field
->parent
.payload_set
= true;
1576 int bt_ctf_field_validate(struct bt_ctf_field
*field
)
1579 enum bt_ctf_field_type_id type_id
;
1582 BT_LOGD_STR("Invalid parameter: field is NULL.");
1587 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1588 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1589 BT_LOGW("Invalid parameter: unknown field type ID: "
1590 "addr=%p, ft-addr=%p, ft-id=%d",
1591 field
, field
->type
, type_id
);
1596 ret
= field_validate_funcs
[type_id
](field
);
1601 int bt_ctf_field_reset_value(struct bt_ctf_field
*field
)
1604 enum bt_ctf_field_type_id type_id
;
1607 BT_LOGD_STR("Invalid parameter: field is NULL.");
1612 if (field
->frozen
) {
1613 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1619 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1620 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1621 BT_LOGW("Invalid parameter: unknown field type ID: "
1622 "addr=%p, ft-addr=%p, ft-id=%d",
1623 field
, field
->type
, type_id
);
1628 ret
= field_reset_value_funcs
[type_id
](field
);
1634 int bt_ctf_field_serialize(struct bt_ctf_field
*field
,
1635 struct bt_ctf_stream_pos
*pos
,
1636 enum bt_ctf_byte_order native_byte_order
)
1639 enum bt_ctf_field_type_id type_id
;
1644 BT_LOGD_STR("Invalid parameter: field is NULL.");
1649 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1650 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1651 BT_LOGW("Invalid parameter: unknown field type ID: "
1652 "addr=%p, ft-addr=%p, ft-id=%d",
1653 field
, field
->type
, type_id
);
1658 ret
= field_serialize_funcs
[type_id
](field
, pos
, native_byte_order
);
1663 bt_bool
bt_ctf_field_value_is_set(struct bt_ctf_field
*field
)
1665 bt_bool value_is_set
= BT_FALSE
;
1666 enum bt_ctf_field_type_id type_id
;
1672 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1673 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1674 BT_LOGW("Invalid parameter: unknown field type ID: "
1675 "field-addr=%p, ft-addr=%p, ft-id=%d",
1676 field
, field
->type
, type_id
);
1680 value_is_set
= field_value_is_set_funcs
[type_id
](field
);
1682 return value_is_set
;
1685 struct bt_ctf_field
*bt_ctf_field_copy(struct bt_ctf_field
*field
)
1688 struct bt_ctf_field
*copy
= NULL
;
1689 enum bt_ctf_field_type_id type_id
;
1692 BT_LOGW_STR("Invalid parameter: field is NULL.");
1696 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1697 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1698 BT_LOGW("Invalid parameter: unknown field type ID: "
1699 "field-addr=%p, ft-addr=%p, ft-id=%d",
1700 field
, field
->type
, type_id
);
1704 copy
= bt_ctf_field_create(field
->type
);
1706 BT_LOGW("Cannot create field: ft-addr=%p", field
->type
);
1710 copy
->payload_set
= field
->payload_set
;
1711 ret
= field_copy_funcs
[type_id
](field
, copy
);
1721 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*type
)
1723 struct bt_ctf_field_integer
*integer
= g_new0(
1724 struct bt_ctf_field_integer
, 1);
1726 BT_LOGD("Creating integer field object: ft-addr=%p", type
);
1729 BT_LOGD("Created integer field object: addr=%p, ft-addr=%p",
1730 &integer
->parent
, type
);
1732 BT_LOGE_STR("Failed to allocate one integer field.");
1735 return integer
? &integer
->parent
: NULL
;
1739 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
1740 struct bt_ctf_field_type
*type
)
1742 struct bt_ctf_field_enumeration
*enumeration
= g_new0(
1743 struct bt_ctf_field_enumeration
, 1);
1745 BT_LOGD("Creating enumeration field object: ft-addr=%p", type
);
1748 BT_LOGD("Created enumeration field object: addr=%p, ft-addr=%p",
1749 &enumeration
->parent
, type
);
1751 BT_LOGE_STR("Failed to allocate one enumeration field.");
1754 return enumeration
? &enumeration
->parent
: NULL
;
1758 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
1759 struct bt_ctf_field_type
*type
)
1761 struct bt_ctf_field_floating_point
*floating_point
;
1763 BT_LOGD("Creating floating point number field object: ft-addr=%p", type
);
1764 floating_point
= g_new0(struct bt_ctf_field_floating_point
, 1);
1766 if (floating_point
) {
1767 BT_LOGD("Created floating point number field object: addr=%p, ft-addr=%p",
1768 &floating_point
->parent
, type
);
1770 BT_LOGE_STR("Failed to allocate one floating point number field.");
1773 return floating_point
? &floating_point
->parent
: NULL
;
1777 struct bt_ctf_field
*bt_ctf_field_structure_create(
1778 struct bt_ctf_field_type
*type
)
1780 struct bt_ctf_field_type_structure
*structure_type
= container_of(type
,
1781 struct bt_ctf_field_type_structure
, parent
);
1782 struct bt_ctf_field_structure
*structure
= g_new0(
1783 struct bt_ctf_field_structure
, 1);
1784 struct bt_ctf_field
*ret
= NULL
;
1787 BT_LOGD("Creating structure field object: ft-addr=%p", type
);
1790 BT_LOGE_STR("Failed to allocate one structure field.");
1794 structure
->fields
= g_ptr_array_new_with_free_func(
1795 (GDestroyNotify
) bt_ctf_field_put
);
1796 g_ptr_array_set_size(structure
->fields
,
1797 structure_type
->fields
->len
);
1799 /* Create all fields contained by the structure field. */
1800 for (i
= 0; i
< structure_type
->fields
->len
; i
++) {
1801 struct bt_ctf_field
*field
;
1802 struct structure_field
*field_type
=
1803 g_ptr_array_index(structure_type
->fields
, i
);
1805 field
= bt_ctf_field_create(field_type
->type
);
1807 BT_LOGE("Failed to create structure field's member: name=\"%s\", index=%zu",
1808 g_quark_to_string(field_type
->name
), i
);
1809 bt_ctf_field_structure_destroy(&structure
->parent
);
1813 g_ptr_array_index(structure
->fields
, i
) = field
;
1816 ret
= &structure
->parent
;
1817 BT_LOGD("Created structure field object: addr=%p, ft-addr=%p", ret
,
1824 struct bt_ctf_field
*bt_ctf_field_variant_create(struct bt_ctf_field_type
*type
)
1826 struct bt_ctf_field_variant
*variant
= g_new0(
1827 struct bt_ctf_field_variant
, 1);
1829 BT_LOGD("Creating variant field object: ft-addr=%p", type
);
1832 BT_LOGD("Created variant field object: addr=%p, ft-addr=%p",
1833 &variant
->parent
, type
);
1835 BT_LOGE_STR("Failed to allocate one variant field.");
1838 return variant
? &variant
->parent
: NULL
;
1842 struct bt_ctf_field
*bt_ctf_field_array_create(struct bt_ctf_field_type
*type
)
1844 struct bt_ctf_field_array
*array
= g_new0(struct bt_ctf_field_array
, 1);
1845 struct bt_ctf_field_type_array
*array_type
;
1846 unsigned int array_length
;
1848 BT_LOGD("Creating array field object: ft-addr=%p", type
);
1852 BT_LOGE_STR("Failed to allocate one array field.");
1856 array_type
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
1857 array_length
= array_type
->length
;
1858 array
->elements
= g_ptr_array_sized_new(array_length
);
1859 if (!array
->elements
) {
1863 g_ptr_array_set_free_func(array
->elements
,
1864 (GDestroyNotify
)bt_ctf_field_put
);
1865 g_ptr_array_set_size(array
->elements
, array_length
);
1866 BT_LOGD("Created array field object: addr=%p, ft-addr=%p",
1867 &array
->parent
, type
);
1868 return &array
->parent
;
1875 struct bt_ctf_field
*bt_ctf_field_sequence_create(
1876 struct bt_ctf_field_type
*type
)
1878 struct bt_ctf_field_sequence
*sequence
= g_new0(
1879 struct bt_ctf_field_sequence
, 1);
1881 BT_LOGD("Creating sequence field object: ft-addr=%p", type
);
1884 BT_LOGD("Created sequence field object: addr=%p, ft-addr=%p",
1885 &sequence
->parent
, type
);
1887 BT_LOGE_STR("Failed to allocate one sequence field.");
1890 return sequence
? &sequence
->parent
: NULL
;
1894 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*type
)
1896 struct bt_ctf_field_string
*string
= g_new0(
1897 struct bt_ctf_field_string
, 1);
1899 BT_LOGD("Creating string field object: ft-addr=%p", type
);
1902 BT_LOGD("Created string field object: addr=%p, ft-addr=%p",
1903 &string
->parent
, type
);
1905 BT_LOGE_STR("Failed to allocate one string field.");
1908 return string
? &string
->parent
: NULL
;
1912 void bt_ctf_field_destroy(struct bt_object
*obj
)
1914 struct bt_ctf_field
*field
;
1915 struct bt_ctf_field_type
*type
;
1916 enum bt_ctf_field_type_id type_id
;
1918 field
= container_of(obj
, struct bt_ctf_field
, base
);
1920 type_id
= bt_ctf_field_type_get_type_id(type
);
1921 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
1922 type_id
< BT_CTF_NR_TYPE_IDS
);
1923 field_destroy_funcs
[type_id
](field
);
1924 BT_LOGD_STR("Putting field's type.");
1929 void bt_ctf_field_integer_destroy(struct bt_ctf_field
*field
)
1931 struct bt_ctf_field_integer
*integer
;
1937 BT_LOGD("Destroying integer field object: addr=%p", field
);
1938 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1943 void bt_ctf_field_enumeration_destroy(struct bt_ctf_field
*field
)
1945 struct bt_ctf_field_enumeration
*enumeration
;
1951 BT_LOGD("Destroying enumeration field object: addr=%p", field
);
1952 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
1954 BT_LOGD_STR("Putting payload field.");
1955 bt_put(enumeration
->payload
);
1956 g_free(enumeration
);
1960 void bt_ctf_field_floating_point_destroy(struct bt_ctf_field
*field
)
1962 struct bt_ctf_field_floating_point
*floating_point
;
1968 BT_LOGD("Destroying floating point number field object: addr=%p", field
);
1969 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
1971 g_free(floating_point
);
1975 void bt_ctf_field_structure_destroy(struct bt_ctf_field
*field
)
1977 struct bt_ctf_field_structure
*structure
;
1983 BT_LOGD("Destroying structure field object: addr=%p", field
);
1984 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
1985 g_ptr_array_free(structure
->fields
, TRUE
);
1990 void bt_ctf_field_variant_destroy(struct bt_ctf_field
*field
)
1992 struct bt_ctf_field_variant
*variant
;
1998 BT_LOGD("Destroying variant field object: addr=%p", field
);
1999 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2000 BT_LOGD_STR("Putting tag field.");
2001 bt_put(variant
->tag
);
2002 BT_LOGD_STR("Putting payload field.");
2003 bt_put(variant
->payload
);
2008 void bt_ctf_field_array_destroy(struct bt_ctf_field
*field
)
2010 struct bt_ctf_field_array
*array
;
2016 BT_LOGD("Destroying array field object: addr=%p", field
);
2017 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2018 g_ptr_array_free(array
->elements
, TRUE
);
2023 void bt_ctf_field_sequence_destroy(struct bt_ctf_field
*field
)
2025 struct bt_ctf_field_sequence
*sequence
;
2031 BT_LOGD("Destroying sequence field object: addr=%p", field
);
2032 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2033 if (sequence
->elements
) {
2034 g_ptr_array_free(sequence
->elements
, TRUE
);
2036 BT_LOGD_STR("Putting length field.");
2037 bt_put(sequence
->length
);
2042 void bt_ctf_field_string_destroy(struct bt_ctf_field
*field
)
2044 struct bt_ctf_field_string
*string
;
2050 BT_LOGD("Destroying string field object: addr=%p", field
);
2051 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2052 if (string
->payload
) {
2053 g_string_free(string
->payload
, TRUE
);
2059 int bt_ctf_field_generic_validate(struct bt_ctf_field
*field
)
2061 return (field
&& field
->payload_set
) ? 0 : -1;
2065 int bt_ctf_field_enumeration_validate(struct bt_ctf_field
*field
)
2068 struct bt_ctf_field_enumeration
*enumeration
;
2071 BT_LOGD_STR("Invalid parameter: field is NULL.");
2076 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2078 if (!enumeration
->payload
) {
2079 BT_LOGW("Invalid enumeration field: payload is not set: "
2085 ret
= bt_ctf_field_validate(enumeration
->payload
);
2091 int bt_ctf_field_structure_validate(struct bt_ctf_field
*field
)
2095 struct bt_ctf_field_structure
*structure
;
2098 BT_LOGD_STR("Invalid parameter: field is NULL.");
2103 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2104 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2105 struct bt_ctf_field
*entry_field
= structure
->fields
->pdata
[i
];
2106 ret
= bt_ctf_field_validate(entry_field
);
2111 struct bt_ctf_field_type
*field_type
=
2112 bt_ctf_field_get_type(field
);
2114 this_ret
= bt_ctf_field_type_structure_get_field(
2115 field_type
, &name
, NULL
, i
);
2116 assert(this_ret
== 0);
2117 BT_LOGW("Invalid structure field's field: "
2118 "struct-field-addr=%p, field-addr=%p, "
2119 "field-name=\"%s\", index=%" PRId64
,
2120 field
, entry_field
, name
, i
);
2130 int bt_ctf_field_variant_validate(struct bt_ctf_field
*field
)
2133 struct bt_ctf_field_variant
*variant
;
2136 BT_LOGD_STR("Invalid parameter: field is NULL.");
2141 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2142 ret
= bt_ctf_field_validate(variant
->payload
);
2144 BT_LOGW("Invalid variant field's payload field: "
2145 "variant-field-addr=%p, variant-payload-field-addr=%p",
2146 field
, variant
->payload
);
2153 int bt_ctf_field_array_validate(struct bt_ctf_field
*field
)
2157 struct bt_ctf_field_array
*array
;
2160 BT_LOGD_STR("Invalid parameter: field is NULL.");
2165 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2166 for (i
= 0; i
< array
->elements
->len
; i
++) {
2167 struct bt_ctf_field
*elem_field
= array
->elements
->pdata
[i
];
2169 ret
= bt_ctf_field_validate(elem_field
);
2171 BT_LOGW("Invalid array field's element field: "
2172 "array-field-addr=%p, field-addr=%p, "
2173 "index=%" PRId64
, field
, elem_field
, i
);
2182 int bt_ctf_field_sequence_validate(struct bt_ctf_field
*field
)
2186 struct bt_ctf_field_sequence
*sequence
;
2189 BT_LOGD_STR("Invalid parameter: field is NULL.");
2194 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2195 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2196 struct bt_ctf_field
*elem_field
= sequence
->elements
->pdata
[i
];
2198 ret
= bt_ctf_field_validate(elem_field
);
2200 BT_LOGW("Invalid sequence field's element field: "
2201 "sequence-field-addr=%p, field-addr=%p, "
2202 "index=%zu", field
, elem_field
, i
);
2211 int bt_ctf_field_generic_reset_value(struct bt_ctf_field
*field
)
2216 BT_LOGD_STR("Invalid parameter: field is NULL.");
2221 field
->payload_set
= false;
2227 int bt_ctf_field_enumeration_reset_value(struct bt_ctf_field
*field
)
2230 struct bt_ctf_field_enumeration
*enumeration
;
2233 BT_LOGD_STR("Invalid parameter: field is NULL.");
2238 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2240 if (!enumeration
->payload
) {
2244 ret
= bt_ctf_field_reset_value(enumeration
->payload
);
2250 int bt_ctf_field_structure_reset_value(struct bt_ctf_field
*field
)
2254 struct bt_ctf_field_structure
*structure
;
2257 BT_LOGD_STR("Invalid parameter: field is NULL.");
2262 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2263 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2264 struct bt_ctf_field
*member
= structure
->fields
->pdata
[i
];
2268 * Structure members are lazily initialized; skip if
2269 * this member has not been allocated yet.
2274 ret
= bt_ctf_field_reset_value(member
);
2276 BT_LOGE("Failed to reset structure field's field: "
2277 "struct-field-addr=%p, field-addr=%p, "
2278 "index=%" PRId64
, field
, member
, i
);
2287 int bt_ctf_field_variant_reset_value(struct bt_ctf_field
*field
)
2290 struct bt_ctf_field_variant
*variant
;
2293 BT_LOGD_STR("Invalid parameter: field is NULL.");
2298 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2299 BT_PUT(variant
->tag
);
2300 BT_PUT(variant
->payload
);
2306 int bt_ctf_field_array_reset_value(struct bt_ctf_field
*field
)
2310 struct bt_ctf_field_array
*array
;
2313 BT_LOGD_STR("Invalid parameter: field is NULL.");
2318 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2319 for (i
= 0; i
< array
->elements
->len
; i
++) {
2320 struct bt_ctf_field
*member
= array
->elements
->pdata
[i
];
2324 * Array elements are lazily initialized; skip if
2325 * this member has not been allocated yet.
2330 ret
= bt_ctf_field_reset_value(member
);
2332 BT_LOGE("Failed to reset array field's field: "
2333 "array-field-addr=%p, field-addr=%p, "
2334 "index=%zu", field
, member
, i
);
2343 int bt_ctf_field_sequence_reset_value(struct bt_ctf_field
*field
)
2346 struct bt_ctf_field_sequence
*sequence
;
2349 BT_LOGD_STR("Invalid parameter: field is NULL.");
2354 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2355 if (sequence
->elements
) {
2356 g_ptr_array_free(sequence
->elements
, TRUE
);
2357 sequence
->elements
= NULL
;
2359 BT_PUT(sequence
->length
);
2365 int bt_ctf_field_string_reset_value(struct bt_ctf_field
*field
)
2368 struct bt_ctf_field_string
*string
;
2371 BT_LOGD_STR("Invalid parameter: field is NULL.");
2376 ret
= bt_ctf_field_generic_reset_value(field
);
2381 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2382 if (string
->payload
) {
2383 g_string_truncate(string
->payload
, 0);
2390 int bt_ctf_field_integer_serialize(struct bt_ctf_field
*field
,
2391 struct bt_ctf_stream_pos
*pos
,
2392 enum bt_ctf_byte_order native_byte_order
)
2395 struct bt_ctf_field_integer
*integer
= container_of(field
,
2396 struct bt_ctf_field_integer
, parent
);
2398 BT_LOGV("Serializing integer field: addr=%p, pos-offset=%" PRId64
", "
2399 "native-bo=%s", field
, pos
->offset
,
2400 bt_ctf_byte_order_string(native_byte_order
));
2402 if (!bt_ctf_field_generic_value_is_set(field
)) {
2403 BT_LOGW_STR("Field's payload is not set.");
2408 ret
= bt_ctf_field_integer_write(integer
, pos
, native_byte_order
);
2409 if (ret
== -EFAULT
) {
2411 * The field is too large to fit in the current packet's
2412 * remaining space. Bump the packet size and retry.
2414 ret
= increase_packet_size(pos
);
2416 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2426 int bt_ctf_field_enumeration_serialize(struct bt_ctf_field
*field
,
2427 struct bt_ctf_stream_pos
*pos
,
2428 enum bt_ctf_byte_order native_byte_order
)
2430 struct bt_ctf_field_enumeration
*enumeration
= container_of(
2431 field
, struct bt_ctf_field_enumeration
, parent
);
2433 BT_LOGV("Serializing enumeration field: addr=%p, pos-offset=%" PRId64
", "
2434 "native-bo=%s", field
, pos
->offset
,
2435 bt_ctf_byte_order_string(native_byte_order
));
2436 BT_LOGV_STR("Serializing enumeration field's payload field.");
2437 return bt_ctf_field_serialize(enumeration
->payload
, pos
,
2442 int bt_ctf_field_floating_point_serialize(struct bt_ctf_field
*field
,
2443 struct bt_ctf_stream_pos
*pos
,
2444 enum bt_ctf_byte_order native_byte_order
)
2447 struct bt_ctf_field_floating_point
*floating_point
= container_of(field
,
2448 struct bt_ctf_field_floating_point
, parent
);
2450 BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64
", "
2451 "native-bo=%s", field
, pos
->offset
,
2452 bt_ctf_byte_order_string(native_byte_order
));
2454 if (!bt_ctf_field_generic_value_is_set(field
)) {
2455 BT_LOGW_STR("Field's payload is not set.");
2460 ret
= bt_ctf_field_floating_point_write(floating_point
, pos
,
2462 if (ret
== -EFAULT
) {
2464 * The field is too large to fit in the current packet's
2465 * remaining space. Bump the packet size and retry.
2467 ret
= increase_packet_size(pos
);
2469 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2479 int bt_ctf_field_structure_serialize(struct bt_ctf_field
*field
,
2480 struct bt_ctf_stream_pos
*pos
,
2481 enum bt_ctf_byte_order native_byte_order
)
2485 struct bt_ctf_field_structure
*structure
= container_of(
2486 field
, struct bt_ctf_field_structure
, parent
);
2488 BT_LOGV("Serializing structure field: addr=%p, pos-offset=%" PRId64
", "
2489 "native-bo=%s", field
, pos
->offset
,
2490 bt_ctf_byte_order_string(native_byte_order
));
2492 while (!bt_ctf_stream_pos_access_ok(pos
,
2493 offset_align(pos
->offset
, field
->type
->alignment
))) {
2494 ret
= increase_packet_size(pos
);
2496 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2501 if (!bt_ctf_stream_pos_align(pos
, field
->type
->alignment
)) {
2502 BT_LOGE("Cannot align packet's position: pos-offset=%" PRId64
", "
2503 "align=%u", pos
->offset
, field
->type
->alignment
);
2508 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2509 struct bt_ctf_field
*member
= g_ptr_array_index(
2510 structure
->fields
, i
);
2511 const char *field_name
= NULL
;
2513 if (BT_LOG_ON_WARN
) {
2514 ret
= bt_ctf_field_type_structure_get_field(
2515 field
->type
, &field_name
, NULL
, i
);
2519 BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64
", "
2520 "field-addr=%p, index=%" PRId64
,
2521 pos
->offset
, member
, i
);
2524 BT_LOGW("Cannot serialize structure field's field: field is not set: "
2525 "struct-field-addr=%p, "
2526 "field-name=\"%s\", index=%" PRId64
,
2527 field
, field_name
, i
);
2532 ret
= bt_ctf_field_serialize(member
, pos
, native_byte_order
);
2534 BT_LOGW("Cannot serialize structure field's field: "
2535 "struct-field-addr=%p, field-addr=%p, "
2536 "field-name=\"%s\", index=%" PRId64
,
2537 field
->type
, member
, field_name
, i
);
2546 int bt_ctf_field_variant_serialize(struct bt_ctf_field
*field
,
2547 struct bt_ctf_stream_pos
*pos
,
2548 enum bt_ctf_byte_order native_byte_order
)
2550 struct bt_ctf_field_variant
*variant
= container_of(
2551 field
, struct bt_ctf_field_variant
, parent
);
2553 BT_LOGV("Serializing variant field: addr=%p, pos-offset=%" PRId64
", "
2554 "native-bo=%s", field
, pos
->offset
,
2555 bt_ctf_byte_order_string(native_byte_order
));
2556 BT_LOGV_STR("Serializing variant field's payload field.");
2557 return bt_ctf_field_serialize(variant
->payload
, pos
,
2562 int bt_ctf_field_array_serialize(struct bt_ctf_field
*field
,
2563 struct bt_ctf_stream_pos
*pos
,
2564 enum bt_ctf_byte_order native_byte_order
)
2568 struct bt_ctf_field_array
*array
= container_of(
2569 field
, struct bt_ctf_field_array
, parent
);
2571 BT_LOGV("Serializing array field: addr=%p, pos-offset=%" PRId64
", "
2572 "native-bo=%s", field
, pos
->offset
,
2573 bt_ctf_byte_order_string(native_byte_order
));
2575 for (i
= 0; i
< array
->elements
->len
; i
++) {
2576 struct bt_ctf_field
*elem_field
=
2577 g_ptr_array_index(array
->elements
, i
);
2579 BT_LOGV("Serializing array field's element field: "
2580 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2581 pos
->offset
, elem_field
, i
);
2582 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2585 BT_LOGW("Cannot serialize array field's element field: "
2586 "array-field-addr=%p, field-addr=%p, "
2587 "index=%" PRId64
, field
, elem_field
, i
);
2596 int bt_ctf_field_sequence_serialize(struct bt_ctf_field
*field
,
2597 struct bt_ctf_stream_pos
*pos
,
2598 enum bt_ctf_byte_order native_byte_order
)
2602 struct bt_ctf_field_sequence
*sequence
= container_of(
2603 field
, struct bt_ctf_field_sequence
, parent
);
2605 BT_LOGV("Serializing sequence field: addr=%p, pos-offset=%" PRId64
", "
2606 "native-bo=%s", field
, pos
->offset
,
2607 bt_ctf_byte_order_string(native_byte_order
));
2609 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2610 struct bt_ctf_field
*elem_field
=
2611 g_ptr_array_index(sequence
->elements
, i
);
2613 BT_LOGV("Serializing sequence field's element field: "
2614 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2615 pos
->offset
, elem_field
, i
);
2616 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2619 BT_LOGW("Cannot serialize sequence field's element field: "
2620 "sequence-field-addr=%p, field-addr=%p, "
2621 "index=%" PRId64
, field
, elem_field
, i
);
2630 int bt_ctf_field_string_serialize(struct bt_ctf_field
*field
,
2631 struct bt_ctf_stream_pos
*pos
,
2632 enum bt_ctf_byte_order native_byte_order
)
2636 struct bt_ctf_field_string
*string
= container_of(field
,
2637 struct bt_ctf_field_string
, parent
);
2638 struct bt_ctf_field_type
*character_type
=
2639 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
2640 struct bt_ctf_field
*character
;
2642 BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64
", "
2643 "native-bo=%s", field
, pos
->offset
,
2644 bt_ctf_byte_order_string(native_byte_order
));
2646 BT_LOGV_STR("Creating character field from string field's character field type.");
2647 character
= bt_ctf_field_create(character_type
);
2649 for (i
= 0; i
< string
->payload
->len
+ 1; i
++) {
2650 const uint64_t chr
= (uint64_t) string
->payload
->str
[i
];
2652 ret
= bt_ctf_field_unsigned_integer_set_value(character
, chr
);
2654 BT_LOGW("Cannot set character field's value: "
2655 "pos-offset=%" PRId64
", field-addr=%p, "
2656 "index=%" PRId64
", char-int=%" PRIu64
,
2657 pos
->offset
, character
, i
, chr
);
2661 BT_LOGV("Serializing string field's character field: "
2662 "pos-offset=%" PRId64
", field-addr=%p, "
2663 "index=%" PRId64
", char-int=%" PRIu64
,
2664 pos
->offset
, character
, i
, chr
);
2665 ret
= bt_ctf_field_integer_serialize(character
, pos
,
2668 BT_LOGW_STR("Cannot serialize character field.");
2674 bt_put(character_type
);
2679 int bt_ctf_field_integer_copy(struct bt_ctf_field
*src
,
2680 struct bt_ctf_field
*dst
)
2682 struct bt_ctf_field_integer
*integer_src
, *integer_dst
;
2684 BT_LOGD("Copying integer field: src-field-addr=%p, dst-field-addr=%p",
2686 integer_src
= container_of(src
, struct bt_ctf_field_integer
, parent
);
2687 integer_dst
= container_of(dst
, struct bt_ctf_field_integer
, parent
);
2688 integer_dst
->payload
= integer_src
->payload
;
2689 BT_LOGD_STR("Copied integer field.");
2694 int bt_ctf_field_enumeration_copy(struct bt_ctf_field
*src
,
2695 struct bt_ctf_field
*dst
)
2698 struct bt_ctf_field_enumeration
*enum_src
, *enum_dst
;
2700 BT_LOGD("Copying enumeration field: src-field-addr=%p, dst-field-addr=%p",
2702 enum_src
= container_of(src
, struct bt_ctf_field_enumeration
, parent
);
2703 enum_dst
= container_of(dst
, struct bt_ctf_field_enumeration
, parent
);
2705 if (enum_src
->payload
) {
2706 BT_LOGD_STR("Copying enumeration field's payload field.");
2707 enum_dst
->payload
= bt_ctf_field_copy(enum_src
->payload
);
2708 if (!enum_dst
->payload
) {
2709 BT_LOGE_STR("Cannot copy enumeration field's payload field.");
2715 BT_LOGD_STR("Copied enumeration field.");
2721 int bt_ctf_field_floating_point_copy(
2722 struct bt_ctf_field
*src
, struct bt_ctf_field
*dst
)
2724 struct bt_ctf_field_floating_point
*float_src
, *float_dst
;
2726 BT_LOGD("Copying floating point number field: src-field-addr=%p, dst-field-addr=%p",
2728 float_src
= container_of(src
, struct bt_ctf_field_floating_point
,
2730 float_dst
= container_of(dst
, struct bt_ctf_field_floating_point
,
2732 float_dst
->payload
= float_src
->payload
;
2733 BT_LOGD_STR("Copied floating point number field.");
2738 int bt_ctf_field_structure_copy(struct bt_ctf_field
*src
,
2739 struct bt_ctf_field
*dst
)
2743 struct bt_ctf_field_structure
*struct_src
, *struct_dst
;
2745 BT_LOGD("Copying structure field: src-field-addr=%p, dst-field-addr=%p",
2747 struct_src
= container_of(src
, struct bt_ctf_field_structure
, parent
);
2748 struct_dst
= container_of(dst
, struct bt_ctf_field_structure
, parent
);
2750 g_ptr_array_set_size(struct_dst
->fields
, struct_src
->fields
->len
);
2752 for (i
= 0; i
< struct_src
->fields
->len
; i
++) {
2753 struct bt_ctf_field
*field
=
2754 g_ptr_array_index(struct_src
->fields
, i
);
2755 struct bt_ctf_field
*field_copy
= NULL
;
2758 BT_LOGD("Copying structure field's field: src-field-addr=%p"
2759 "index=%" PRId64
, field
, i
);
2760 field_copy
= bt_ctf_field_copy(field
);
2762 BT_LOGE("Cannot copy structure field's field: "
2763 "src-field-addr=%p, index=%" PRId64
,
2770 BT_MOVE(g_ptr_array_index(struct_dst
->fields
, i
), field_copy
);
2773 BT_LOGD_STR("Copied structure field.");
2780 int bt_ctf_field_variant_copy(struct bt_ctf_field
*src
,
2781 struct bt_ctf_field
*dst
)
2784 struct bt_ctf_field_variant
*variant_src
, *variant_dst
;
2786 BT_LOGD("Copying variant field: src-field-addr=%p, dst-field-addr=%p",
2788 variant_src
= container_of(src
, struct bt_ctf_field_variant
, parent
);
2789 variant_dst
= container_of(dst
, struct bt_ctf_field_variant
, parent
);
2791 if (variant_src
->tag
) {
2792 BT_LOGD_STR("Copying variant field's tag field.");
2793 variant_dst
->tag
= bt_ctf_field_copy(variant_src
->tag
);
2794 if (!variant_dst
->tag
) {
2795 BT_LOGE_STR("Cannot copy variant field's tag field.");
2800 if (variant_src
->payload
) {
2801 BT_LOGD_STR("Copying variant field's payload field.");
2802 variant_dst
->payload
= bt_ctf_field_copy(variant_src
->payload
);
2803 if (!variant_dst
->payload
) {
2804 BT_LOGE_STR("Cannot copy variant field's payload field.");
2810 BT_LOGD_STR("Copied variant field.");
2817 int bt_ctf_field_array_copy(struct bt_ctf_field
*src
,
2818 struct bt_ctf_field
*dst
)
2822 struct bt_ctf_field_array
*array_src
, *array_dst
;
2824 BT_LOGD("Copying array field: src-field-addr=%p, dst-field-addr=%p",
2826 array_src
= container_of(src
, struct bt_ctf_field_array
, parent
);
2827 array_dst
= container_of(dst
, struct bt_ctf_field_array
, parent
);
2829 g_ptr_array_set_size(array_dst
->elements
, array_src
->elements
->len
);
2830 for (i
= 0; i
< array_src
->elements
->len
; i
++) {
2831 struct bt_ctf_field
*field
=
2832 g_ptr_array_index(array_src
->elements
, i
);
2833 struct bt_ctf_field
*field_copy
= NULL
;
2836 BT_LOGD("Copying array field's element field: field-addr=%p, "
2837 "index=%" PRId64
, field
, i
);
2838 field_copy
= bt_ctf_field_copy(field
);
2840 BT_LOGE("Cannot copy array field's element field: "
2841 "src-field-addr=%p, index=%" PRId64
,
2848 g_ptr_array_index(array_dst
->elements
, i
) = field_copy
;
2851 BT_LOGD_STR("Copied array field.");
2858 int bt_ctf_field_sequence_copy(struct bt_ctf_field
*src
,
2859 struct bt_ctf_field
*dst
)
2863 struct bt_ctf_field_sequence
*sequence_src
, *sequence_dst
;
2864 struct bt_ctf_field
*src_length
;
2865 struct bt_ctf_field
*dst_length
;
2867 BT_LOGD("Copying sequence field: src-field-addr=%p, dst-field-addr=%p",
2869 sequence_src
= container_of(src
, struct bt_ctf_field_sequence
, parent
);
2870 sequence_dst
= container_of(dst
, struct bt_ctf_field_sequence
, parent
);
2872 src_length
= bt_ctf_field_sequence_get_length(src
);
2874 /* no length set yet: keep destination sequence empty */
2878 /* copy source length */
2879 BT_LOGD_STR("Copying sequence field's length field.");
2880 dst_length
= bt_ctf_field_copy(src_length
);
2883 BT_LOGE_STR("Cannot copy sequence field's length field.");
2888 /* this will initialize the destination sequence's internal array */
2889 ret
= bt_ctf_field_sequence_set_length(dst
, dst_length
);
2892 BT_LOGE("Cannot set sequence field copy's length field: "
2893 "dst-length-field-addr=%p", dst_length
);
2898 assert(sequence_dst
->elements
->len
== sequence_src
->elements
->len
);
2900 for (i
= 0; i
< sequence_src
->elements
->len
; i
++) {
2901 struct bt_ctf_field
*field
=
2902 g_ptr_array_index(sequence_src
->elements
, i
);
2903 struct bt_ctf_field
*field_copy
= NULL
;
2906 BT_LOGD("Copying sequence field's element field: field-addr=%p, "
2907 "index=%" PRId64
, field
, i
);
2908 field_copy
= bt_ctf_field_copy(field
);
2910 BT_LOGE("Cannot copy sequence field's element field: "
2911 "src-field-addr=%p, index=%" PRId64
,
2918 g_ptr_array_index(sequence_dst
->elements
, i
) = field_copy
;
2921 BT_LOGD_STR("Copied sequence field.");
2928 int bt_ctf_field_string_copy(struct bt_ctf_field
*src
,
2929 struct bt_ctf_field
*dst
)
2932 struct bt_ctf_field_string
*string_src
, *string_dst
;
2934 BT_LOGD("Copying string field: src-field-addr=%p, dst-field-addr=%p",
2936 string_src
= container_of(src
, struct bt_ctf_field_string
, parent
);
2937 string_dst
= container_of(dst
, struct bt_ctf_field_string
, parent
);
2939 if (string_src
->payload
) {
2940 string_dst
->payload
= g_string_new(string_src
->payload
->str
);
2941 if (!string_dst
->payload
) {
2942 BT_LOGE_STR("Failed to allocate a GString.");
2948 BT_LOGD_STR("Copied string field.");
2955 int increase_packet_size(struct bt_ctf_stream_pos
*pos
)
2960 BT_LOGV("Increasing packet size: pos-offset=%" PRId64
", "
2961 "cur-packet-size=%" PRIu64
,
2962 pos
->offset
, pos
->packet_size
);
2963 ret
= munmap_align(pos
->base_mma
);
2965 BT_LOGE_ERRNO("Failed to perform an aligned memory unmapping",
2970 pos
->packet_size
+= PACKET_LEN_INCREMENT
;
2972 ret
= bt_posix_fallocate(pos
->fd
, pos
->mmap_offset
,
2973 pos
->packet_size
/ CHAR_BIT
);
2974 } while (ret
== EINTR
);
2976 BT_LOGE_ERRNO("Failed to preallocate memory space",
2983 pos
->base_mma
= mmap_align(pos
->packet_size
/ CHAR_BIT
, pos
->prot
,
2984 pos
->flags
, pos
->fd
, pos
->mmap_offset
);
2985 if (pos
->base_mma
== MAP_FAILED
) {
2986 BT_LOGE_ERRNO("Failed to perform an aligned memory mapping",
2991 BT_LOGV("Increased packet size: pos-offset=%" PRId64
", "
2992 "new-packet-size=%" PRIu64
,
2993 pos
->offset
, pos
->packet_size
);
2994 assert(pos
->packet_size
% 8 == 0);
3001 void generic_field_freeze(struct bt_ctf_field
*field
)
3003 field
->frozen
= true;
3007 void bt_ctf_field_enumeration_freeze(struct bt_ctf_field
*field
)
3009 struct bt_ctf_field_enumeration
*enum_field
=
3010 container_of(field
, struct bt_ctf_field_enumeration
, parent
);
3012 BT_LOGD("Freezing enumeration field object: addr=%p", field
);
3013 BT_LOGD("Freezing enumeration field object's contained payload field: payload-field-addr=%p", enum_field
->payload
);
3014 bt_ctf_field_freeze(enum_field
->payload
);
3015 generic_field_freeze(field
);
3019 void bt_ctf_field_structure_freeze(struct bt_ctf_field
*field
)
3022 struct bt_ctf_field_structure
*structure_field
=
3023 container_of(field
, struct bt_ctf_field_structure
, parent
);
3025 BT_LOGD("Freezing structure field object: addr=%p", field
);
3027 for (i
= 0; i
< structure_field
->fields
->len
; i
++) {
3028 struct bt_ctf_field
*field
=
3029 g_ptr_array_index(structure_field
->fields
, i
);
3031 BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64
,
3033 bt_ctf_field_freeze(field
);
3036 generic_field_freeze(field
);
3040 void bt_ctf_field_variant_freeze(struct bt_ctf_field
*field
)
3042 struct bt_ctf_field_variant
*variant_field
=
3043 container_of(field
, struct bt_ctf_field_variant
, parent
);
3045 BT_LOGD("Freezing variant field object: addr=%p", field
);
3046 BT_LOGD("Freezing variant field object's tag field: tag-field-addr=%p", variant_field
->tag
);
3047 bt_ctf_field_freeze(variant_field
->tag
);
3048 BT_LOGD("Freezing variant field object's payload field: payload-field-addr=%p", variant_field
->payload
);
3049 bt_ctf_field_freeze(variant_field
->payload
);
3050 generic_field_freeze(field
);
3054 void bt_ctf_field_array_freeze(struct bt_ctf_field
*field
)
3057 struct bt_ctf_field_array
*array_field
=
3058 container_of(field
, struct bt_ctf_field_array
, parent
);
3060 BT_LOGD("Freezing array field object: addr=%p", field
);
3062 for (i
= 0; i
< array_field
->elements
->len
; i
++) {
3063 struct bt_ctf_field
*elem_field
=
3064 g_ptr_array_index(array_field
->elements
, i
);
3066 BT_LOGD("Freezing array field object's element field: "
3067 "element-field-addr=%p, index=%" PRId64
,
3069 bt_ctf_field_freeze(elem_field
);
3072 generic_field_freeze(field
);
3076 void bt_ctf_field_sequence_freeze(struct bt_ctf_field
*field
)
3079 struct bt_ctf_field_sequence
*sequence_field
=
3080 container_of(field
, struct bt_ctf_field_sequence
, parent
);
3082 BT_LOGD("Freezing sequence field object: addr=%p", field
);
3083 BT_LOGD("Freezing sequence field object's length field: length-field-addr=%p",
3084 sequence_field
->length
);
3085 bt_ctf_field_freeze(sequence_field
->length
);
3087 for (i
= 0; i
< sequence_field
->elements
->len
; i
++) {
3088 struct bt_ctf_field
*elem_field
=
3089 g_ptr_array_index(sequence_field
->elements
, i
);
3091 BT_LOGD("Freezing sequence field object's element field: "
3092 "element-field-addr=%p, index=%" PRId64
,
3094 bt_ctf_field_freeze(elem_field
);
3097 generic_field_freeze(field
);
3101 void bt_ctf_field_freeze(struct bt_ctf_field
*field
)
3103 enum bt_ctf_field_type_id type_id
;
3109 if (field
->frozen
) {
3113 BT_LOGD("Freezing field object: addr=%p", field
);
3114 type_id
= bt_ctf_field_get_type_id(field
);
3115 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
3116 type_id
< BT_CTF_NR_TYPE_IDS
);
3117 field_freeze_funcs
[type_id
](field
);
3123 bt_bool
bt_ctf_field_generic_value_is_set(struct bt_ctf_field
*field
)
3125 return field
&& field
->payload_set
;
3129 bt_bool
bt_ctf_field_enumeration_value_is_set(struct bt_ctf_field
*field
)
3131 bt_bool value_is_set
= BT_FALSE
;
3132 struct bt_ctf_field_enumeration
*enumeration
;
3138 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
3140 if (!enumeration
->payload
) {
3144 value_is_set
= bt_ctf_field_value_is_set(enumeration
->payload
);
3146 return value_is_set
;
3150 bt_bool
bt_ctf_field_structure_value_is_set(struct bt_ctf_field
*field
)
3152 bt_bool value_is_set
= BT_FALSE
;
3154 struct bt_ctf_field_structure
*structure
;
3160 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
3161 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3162 value_is_set
= bt_ctf_field_value_is_set(structure
->fields
->pdata
[i
]);
3163 if (!value_is_set
) {
3168 return value_is_set
;
3172 bt_bool
bt_ctf_field_variant_value_is_set(struct bt_ctf_field
*field
)
3174 bt_bool value_is_set
= BT_FALSE
;
3175 struct bt_ctf_field_variant
*variant
;
3181 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
3182 value_is_set
= bt_ctf_field_value_is_set(variant
->payload
);
3184 return value_is_set
;
3188 bt_bool
bt_ctf_field_array_value_is_set(struct bt_ctf_field
*field
)
3191 bt_bool value_is_set
= BT_FALSE
;
3192 struct bt_ctf_field_array
*array
;
3198 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
3199 for (i
= 0; i
< array
->elements
->len
; i
++) {
3200 value_is_set
= bt_ctf_field_value_is_set(array
->elements
->pdata
[i
]);
3201 if (!value_is_set
) {
3206 return value_is_set
;
3210 bt_bool
bt_ctf_field_sequence_value_is_set(struct bt_ctf_field
*field
)
3213 bt_bool value_is_set
= BT_FALSE
;
3214 struct bt_ctf_field_sequence
*sequence
;
3220 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
3221 if (!sequence
->elements
) {
3225 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
3226 value_is_set
= bt_ctf_field_value_is_set(sequence
->elements
->pdata
[i
]);
3227 if (!value_is_set
) {
3232 return value_is_set
;