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>
42 #define PACKET_LEN_INCREMENT (getpagesize() * 8 * CHAR_BIT)
45 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*);
47 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
48 struct bt_ctf_field_type
*);
50 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
51 struct bt_ctf_field_type
*);
53 struct bt_ctf_field
*bt_ctf_field_structure_create(
54 struct bt_ctf_field_type
*);
56 struct bt_ctf_field
*bt_ctf_field_variant_create(
57 struct bt_ctf_field_type
*);
59 struct bt_ctf_field
*bt_ctf_field_array_create(
60 struct bt_ctf_field_type
*);
62 struct bt_ctf_field
*bt_ctf_field_sequence_create(
63 struct bt_ctf_field_type
*);
65 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*);
68 void bt_ctf_field_destroy(struct bt_object
*);
70 void bt_ctf_field_integer_destroy(struct bt_ctf_field
*);
72 void bt_ctf_field_enumeration_destroy(struct bt_ctf_field
*);
74 void bt_ctf_field_floating_point_destroy(struct bt_ctf_field
*);
76 void bt_ctf_field_structure_destroy(struct bt_ctf_field
*);
78 void bt_ctf_field_variant_destroy(struct bt_ctf_field
*);
80 void bt_ctf_field_array_destroy(struct bt_ctf_field
*);
82 void bt_ctf_field_sequence_destroy(struct bt_ctf_field
*);
84 void bt_ctf_field_string_destroy(struct bt_ctf_field
*);
87 int bt_ctf_field_generic_validate(struct bt_ctf_field
*);
89 int bt_ctf_field_structure_validate(struct bt_ctf_field
*);
91 int bt_ctf_field_variant_validate(struct bt_ctf_field
*);
93 int bt_ctf_field_enumeration_validate(struct bt_ctf_field
*);
95 int bt_ctf_field_array_validate(struct bt_ctf_field
*);
97 int bt_ctf_field_sequence_validate(struct bt_ctf_field
*);
100 int bt_ctf_field_generic_reset(struct bt_ctf_field
*);
102 int bt_ctf_field_structure_reset(struct bt_ctf_field
*);
104 int bt_ctf_field_variant_reset(struct bt_ctf_field
*);
106 int bt_ctf_field_enumeration_reset(struct bt_ctf_field
*);
108 int bt_ctf_field_array_reset(struct bt_ctf_field
*);
110 int bt_ctf_field_sequence_reset(struct bt_ctf_field
*);
112 int bt_ctf_field_string_reset(struct bt_ctf_field
*);
115 int bt_ctf_field_integer_serialize(struct bt_ctf_field
*,
116 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
118 int bt_ctf_field_enumeration_serialize(struct bt_ctf_field
*,
119 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
121 int bt_ctf_field_floating_point_serialize(struct bt_ctf_field
*,
122 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
124 int bt_ctf_field_structure_serialize(struct bt_ctf_field
*,
125 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
127 int bt_ctf_field_variant_serialize(struct bt_ctf_field
*,
128 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
130 int bt_ctf_field_array_serialize(struct bt_ctf_field
*,
131 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
133 int bt_ctf_field_sequence_serialize(struct bt_ctf_field
*,
134 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
136 int bt_ctf_field_string_serialize(struct bt_ctf_field
*,
137 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
);
140 int bt_ctf_field_integer_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
142 int bt_ctf_field_enumeration_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
144 int bt_ctf_field_floating_point_copy(struct bt_ctf_field
*,
145 struct bt_ctf_field
*);
147 int bt_ctf_field_structure_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
149 int bt_ctf_field_variant_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
151 int bt_ctf_field_array_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
153 int bt_ctf_field_sequence_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
155 int bt_ctf_field_string_copy(struct bt_ctf_field
*, struct bt_ctf_field
*);
158 void generic_field_freeze(struct bt_ctf_field
*);
160 void bt_ctf_field_enumeration_freeze(struct bt_ctf_field
*);
162 void bt_ctf_field_structure_freeze(struct bt_ctf_field
*);
164 void bt_ctf_field_variant_freeze(struct bt_ctf_field
*);
166 void bt_ctf_field_array_freeze(struct bt_ctf_field
*);
168 void bt_ctf_field_sequence_freeze(struct bt_ctf_field
*);
171 bt_bool
bt_ctf_field_generic_is_set(struct bt_ctf_field
*);
173 bt_bool
bt_ctf_field_structure_is_set(struct bt_ctf_field
*);
175 bt_bool
bt_ctf_field_variant_is_set(struct bt_ctf_field
*);
177 bt_bool
bt_ctf_field_enumeration_is_set(struct bt_ctf_field
*);
179 bt_bool
bt_ctf_field_array_is_set(struct bt_ctf_field
*);
181 bt_bool
bt_ctf_field_sequence_is_set(struct bt_ctf_field
*);
184 int increase_packet_size(struct bt_ctf_stream_pos
*pos
);
187 struct bt_ctf_field
*(* const field_create_funcs
[])(
188 struct bt_ctf_field_type
*) = {
189 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_create
,
190 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_create
,
191 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
192 bt_ctf_field_floating_point_create
,
193 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_create
,
194 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_create
,
195 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_create
,
196 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_create
,
197 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_create
,
201 void (* const field_destroy_funcs
[])(struct bt_ctf_field
*) = {
202 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_destroy
,
203 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_destroy
,
204 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
205 bt_ctf_field_floating_point_destroy
,
206 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_destroy
,
207 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_destroy
,
208 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_destroy
,
209 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_destroy
,
210 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_destroy
,
214 int (* const field_validate_funcs
[])(struct bt_ctf_field
*) = {
215 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_validate
,
216 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_validate
,
217 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_validate
,
218 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_validate
,
219 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_validate
,
220 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_validate
,
221 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_validate
,
222 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_generic_validate
,
226 int (* const field_reset_funcs
[])(struct bt_ctf_field
*) = {
227 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_reset
,
228 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_reset
,
229 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_reset
,
230 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_reset
,
231 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_reset
,
232 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_reset
,
233 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_reset
,
234 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_reset
,
238 int (* const field_serialize_funcs
[])(struct bt_ctf_field
*,
239 struct bt_ctf_stream_pos
*, enum bt_ctf_byte_order
) = {
240 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_serialize
,
241 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_serialize
,
242 [BT_CTF_FIELD_TYPE_ID_FLOAT
] =
243 bt_ctf_field_floating_point_serialize
,
244 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_serialize
,
245 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_serialize
,
246 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_serialize
,
247 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_serialize
,
248 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_serialize
,
252 int (* const field_copy_funcs
[])(struct bt_ctf_field
*,
253 struct bt_ctf_field
*) = {
254 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_copy
,
255 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_copy
,
256 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_floating_point_copy
,
257 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_copy
,
258 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_copy
,
259 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_copy
,
260 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_copy
,
261 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_copy
,
265 void (* const field_freeze_funcs
[])(struct bt_ctf_field
*) = {
266 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = generic_field_freeze
,
267 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = generic_field_freeze
,
268 [BT_CTF_FIELD_TYPE_ID_STRING
] = generic_field_freeze
,
269 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_freeze
,
270 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_freeze
,
271 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_freeze
,
272 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_freeze
,
273 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_freeze
,
277 bt_bool (* const field_is_set_funcs
[])(struct bt_ctf_field
*) = {
278 [BT_CTF_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_generic_is_set
,
279 [BT_CTF_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_is_set
,
280 [BT_CTF_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_generic_is_set
,
281 [BT_CTF_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_is_set
,
282 [BT_CTF_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_is_set
,
283 [BT_CTF_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_is_set
,
284 [BT_CTF_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_is_set
,
285 [BT_CTF_FIELD_TYPE_ID_STRING
] = bt_ctf_field_generic_is_set
,
288 struct bt_ctf_field
*bt_ctf_field_create(struct bt_ctf_field_type
*type
)
290 struct bt_ctf_field
*field
= NULL
;
291 enum bt_ctf_field_type_id type_id
;
295 BT_LOGW_STR("Invalid parameter: field type is NULL.");
299 type_id
= bt_ctf_field_type_get_type_id(type
);
300 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
||
301 type_id
>= BT_CTF_NR_TYPE_IDS
) {
302 BT_LOGW("Invalid parameter: unknown field type ID: "
303 "ft-addr=%p, ft-id=%d", type
, type_id
);
307 /* Field class MUST be valid */
308 ret
= bt_ctf_field_type_validate(type
);
311 BT_LOGW("Invalid parameter: field type is invalid: "
316 field
= field_create_funcs
[type_id
](type
);
321 /* The type's declaration can't change after this point */
322 bt_ctf_field_type_freeze(type
);
324 bt_object_init(field
, bt_ctf_field_destroy
);
330 /* Pre-2.0 CTF writer backward compatibility */
331 void bt_ctf_field_get(struct bt_ctf_field
*field
)
336 /* Pre-2.0 CTF writer backward compatibility */
337 void bt_ctf_field_put(struct bt_ctf_field
*field
)
342 struct bt_ctf_field_type
*bt_ctf_field_get_type(struct bt_ctf_field
*field
)
344 struct bt_ctf_field_type
*ret
= NULL
;
347 BT_LOGW_STR("Invalid parameter: field is NULL.");
357 enum bt_ctf_field_type_id
bt_ctf_field_get_type_id(struct bt_ctf_field
*field
)
359 enum bt_ctf_field_type_id ret
= BT_CTF_FIELD_TYPE_ID_UNKNOWN
;
362 BT_LOGW_STR("Invalid parameter: field is NULL.");
366 ret
= bt_ctf_field_type_get_type_id(field
->type
);
371 bt_bool
bt_ctf_field_is_integer(struct bt_ctf_field
*field
)
373 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_INTEGER
;
376 bt_bool
bt_ctf_field_is_floating_point(struct bt_ctf_field
*field
)
378 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_FLOAT
;
381 bt_bool
bt_ctf_field_is_enumeration(struct bt_ctf_field
*field
)
383 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_ENUM
;
386 bt_bool
bt_ctf_field_is_string(struct bt_ctf_field
*field
)
388 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_STRING
;
391 bt_bool
bt_ctf_field_is_structure(struct bt_ctf_field
*field
)
393 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_STRUCT
;
396 bt_bool
bt_ctf_field_is_array(struct bt_ctf_field
*field
)
398 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_ARRAY
;
401 bt_bool
bt_ctf_field_is_sequence(struct bt_ctf_field
*field
)
403 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_SEQUENCE
;
406 bt_bool
bt_ctf_field_is_variant(struct bt_ctf_field
*field
)
408 return bt_ctf_field_get_type_id(field
) == BT_CTF_FIELD_TYPE_ID_VARIANT
;
411 struct bt_ctf_field
*bt_ctf_field_sequence_get_length(
412 struct bt_ctf_field
*field
)
414 struct bt_ctf_field
*ret
= NULL
;
415 struct bt_ctf_field_sequence
*sequence
;
418 BT_LOGW_STR("Invalid parameter: field is NULL.");
422 if (bt_ctf_field_type_get_type_id(field
->type
) !=
423 BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
424 BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
425 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
427 bt_ctf_field_type_id_string(field
->type
->id
));
431 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
432 ret
= sequence
->length
;
438 int bt_ctf_field_sequence_set_length(struct bt_ctf_field
*field
,
439 struct bt_ctf_field
*length_field
)
442 struct bt_ctf_field_type_integer
*length_type
;
443 struct bt_ctf_field_integer
*length
;
444 struct bt_ctf_field_sequence
*sequence
;
445 uint64_t sequence_length
;
448 BT_LOGW_STR("Invalid parameter: field is NULL.");
454 BT_LOGW_STR("Invalid parameter: length field is NULL.");
460 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
466 if (bt_ctf_field_type_get_type_id(length_field
->type
) !=
467 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
468 BT_LOGW("Invalid parameter: length field's type is not an integer field type: "
469 "field-addr=%p, length-field-addr=%p, length-ft-addr=%p, length-ft-id=%s",
470 field
, length_field
, length_field
->type
,
471 bt_ctf_field_type_id_string(length_field
->type
->id
));
476 length_type
= container_of(length_field
->type
,
477 struct bt_ctf_field_type_integer
, parent
);
478 /* The length field must be unsigned */
479 if (length_type
->is_signed
) {
480 BT_LOGW("Invalid parameter: length field's type is signed: "
481 "field-addr=%p, length-field-addr=%p, "
482 "length-field-ft-addr=%p", field
, length_field
,
488 length
= container_of(length_field
, struct bt_ctf_field_integer
,
490 sequence_length
= length
->payload
.unsignd
;
491 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
492 if (sequence
->elements
) {
493 g_ptr_array_free(sequence
->elements
, TRUE
);
494 bt_put(sequence
->length
);
497 sequence
->elements
= g_ptr_array_sized_new((size_t)sequence_length
);
498 if (!sequence
->elements
) {
499 BT_LOGE_STR("Failed to allocate a GPtrArray.");
504 g_ptr_array_set_free_func(sequence
->elements
,
505 (GDestroyNotify
) bt_put
);
506 g_ptr_array_set_size(sequence
->elements
, (size_t) sequence_length
);
507 bt_get(length_field
);
508 sequence
->length
= length_field
;
513 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_name(
514 struct bt_ctf_field
*field
, const char *name
)
516 struct bt_ctf_field
*new_field
= NULL
;
518 struct bt_ctf_field_structure
*structure
;
519 struct bt_ctf_field_type
*field_type
= NULL
;
523 BT_LOGW_STR("Invalid parameter: field is NULL.");
528 BT_LOGW_STR("Invalid parameter: field name is NULL.");
532 if (bt_ctf_field_type_get_type_id(field
->type
) !=
533 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
534 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
535 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
537 bt_ctf_field_type_id_string(field
->type
->id
));
541 field_quark
= g_quark_from_string(name
);
542 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
544 bt_ctf_field_type_structure_get_field_type_by_name(field
->type
,
546 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
547 GUINT_TO_POINTER(field_quark
),
548 NULL
, (gpointer
*)&index
)) {
549 BT_LOGV("Invalid parameter: no such field in structure field's type: "
550 "struct-field-addr=%p, struct-ft-addr=%p, "
551 "field-ft-addr=%p, name=\"%s\"",
552 field
, field
->type
, field_type
, name
);
556 if (structure
->fields
->pdata
[index
]) {
557 new_field
= structure
->fields
->pdata
[index
];
561 /* We don't want to modify this field if it's frozen */
563 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
568 new_field
= bt_ctf_field_create(field_type
);
570 BT_LOGW("Cannot create field: "
571 "struct-field-addr=%p, struct-ft-addr=%p, "
572 "field-ft-addr=%p, name=\"%s\"",
573 field
, field
->type
, field_type
, name
);
577 structure
->fields
->pdata
[index
] = new_field
;
587 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_index(
588 struct bt_ctf_field
*field
, uint64_t index
)
591 const char *field_name
;
592 struct bt_ctf_field_structure
*structure
;
593 struct bt_ctf_field_type
*structure_type
;
594 struct bt_ctf_field_type
*field_type
= NULL
;
595 struct bt_ctf_field
*ret_field
= NULL
;
598 BT_LOGW_STR("Invalid parameter: field is NULL.");
602 if (bt_ctf_field_type_get_type_id(field
->type
) !=
603 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
604 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
605 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
607 bt_ctf_field_type_id_string(field
->type
->id
));
611 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
612 if (index
>= structure
->fields
->len
) {
613 BT_LOGW("Invalid parameter: index is out of bounds: "
614 "addr=%p, index=%" PRIu64
", count=%u",
615 field
, index
, structure
->fields
->len
);
619 ret_field
= structure
->fields
->pdata
[index
];
624 /* We don't want to modify this field if it's frozen */
626 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
631 /* Field has not been instanciated yet, create it */
632 structure_type
= bt_ctf_field_get_type(field
);
633 assert(structure_type
);
634 ret
= bt_ctf_field_type_structure_get_field(structure_type
,
635 &field_name
, &field_type
, index
);
637 bt_put(structure_type
);
638 ret_field
= bt_ctf_field_create(field_type
);
640 BT_LOGW("Cannot create field: "
641 "struct-field-addr=%p, struct-ft-addr=%p, "
642 "field-ft-addr=%p, index=%" PRIu64
,
643 field
, field
->type
, field_type
, index
);
647 structure
->fields
->pdata
[index
] = ret_field
;
655 int bt_ctf_field_structure_set_field(struct bt_ctf_field
*field
,
656 const char *name
, struct bt_ctf_field
*value
)
660 struct bt_ctf_field_structure
*structure
;
661 struct bt_ctf_field_type
*expected_field_type
= NULL
;
665 BT_LOGW_STR("Invalid parameter: structure field is NULL.");
671 BT_LOGW_STR("Invalid parameter: field name is NULL.");
677 BT_LOGW_STR("Invalid parameter: field is NULL.");
682 if (bt_ctf_field_type_get_type_id(field
->type
) !=
683 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
684 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
685 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
687 bt_ctf_field_type_id_string(field
->type
->id
));
692 field_quark
= g_quark_from_string(name
);
693 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
694 expected_field_type
=
695 bt_ctf_field_type_structure_get_field_type_by_name(field
->type
,
698 if (bt_ctf_field_type_compare(expected_field_type
, value
->type
)) {
699 BT_LOGW("Invalid parameter: field type of field to set is different from the expected field type: "
700 "struct-field-addr=%p, field-addr=%p, "
701 "field-ft-addr=%p, expected-ft-addr=%p",
702 field
, value
, value
->type
, expected_field_type
);
707 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
708 GUINT_TO_POINTER(field_quark
), NULL
, (gpointer
*) &index
)) {
709 BT_LOGV("Invalid parameter: no such field in structure field's type: "
710 "struct-field-addr=%p, struct-ft-addr=%p, "
711 "field-ft-addr=%p, name=\"%s\"",
712 field
, field
->type
, value
->type
, name
);
717 if (structure
->fields
->pdata
[index
]) {
718 bt_put(structure
->fields
->pdata
[index
]);
721 structure
->fields
->pdata
[index
] = value
;
724 if (expected_field_type
) {
725 bt_put(expected_field_type
);
730 struct bt_ctf_field
*bt_ctf_field_array_get_field(struct bt_ctf_field
*field
,
733 struct bt_ctf_field
*new_field
= NULL
;
734 struct bt_ctf_field_type
*field_type
= NULL
;
735 struct bt_ctf_field_array
*array
;
738 BT_LOGW_STR("Invalid parameter: field is NULL.");
742 if (bt_ctf_field_type_get_type_id(field
->type
) !=
743 BT_CTF_FIELD_TYPE_ID_ARRAY
) {
744 BT_LOGW("Invalid parameter: field's type is not an array field type: "
745 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
747 bt_ctf_field_type_id_string(field
->type
->id
));
751 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
752 if (index
>= array
->elements
->len
) {
753 BT_LOGW("Invalid parameter: index is out of bounds: "
754 "addr=%p, index=%" PRIu64
", count=%u",
755 field
, index
, array
->elements
->len
);
759 field_type
= bt_ctf_field_type_array_get_element_type(field
->type
);
760 if (array
->elements
->pdata
[(size_t)index
]) {
761 new_field
= array
->elements
->pdata
[(size_t)index
];
765 /* We don't want to modify this field if it's frozen */
767 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
772 new_field
= bt_ctf_field_create(field_type
);
773 array
->elements
->pdata
[(size_t)index
] = new_field
;
784 struct bt_ctf_field
*bt_ctf_field_sequence_get_field(struct bt_ctf_field
*field
,
787 struct bt_ctf_field
*new_field
= NULL
;
788 struct bt_ctf_field_type
*field_type
= NULL
;
789 struct bt_ctf_field_sequence
*sequence
;
792 BT_LOGW_STR("Invalid parameter: field is NULL.");
796 if (bt_ctf_field_type_get_type_id(field
->type
) !=
797 BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
798 BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
799 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
801 bt_ctf_field_type_id_string(field
->type
->id
));
805 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
806 if (!sequence
->elements
) {
807 BT_LOGV("Sequence field's elements do not exist: addr=%p",
812 if (index
>= sequence
->elements
->len
) {
813 BT_LOGW("Invalid parameter: index is out of bounds: "
814 "addr=%p, index=%" PRIu64
", count=%u",
815 field
, index
, sequence
->elements
->len
);
819 field_type
= bt_ctf_field_type_sequence_get_element_type(field
->type
);
820 if (sequence
->elements
->pdata
[(size_t) index
]) {
821 new_field
= sequence
->elements
->pdata
[(size_t) index
];
825 /* We don't want to modify this field if it's frozen */
827 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
832 new_field
= bt_ctf_field_create(field_type
);
833 sequence
->elements
->pdata
[(size_t) index
] = new_field
;
844 struct bt_ctf_field
*bt_ctf_field_variant_get_field(struct bt_ctf_field
*field
,
845 struct bt_ctf_field
*tag_field
)
847 struct bt_ctf_field
*new_field
= NULL
;
848 struct bt_ctf_field_variant
*variant
;
849 struct bt_ctf_field_type_variant
*variant_type
;
850 struct bt_ctf_field_type
*field_type
;
851 struct bt_ctf_field
*tag_enum
= NULL
;
852 struct bt_ctf_field_integer
*tag_enum_integer
;
853 int64_t tag_enum_value
;
856 BT_LOGW_STR("Invalid parameter: field is NULL.");
861 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
865 if (bt_ctf_field_type_get_type_id(field
->type
) !=
866 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
867 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
868 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
870 bt_ctf_field_type_id_string(field
->type
->id
));
874 if (bt_ctf_field_type_get_type_id(tag_field
->type
) !=
875 BT_CTF_FIELD_TYPE_ID_ENUM
) {
876 BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: "
877 "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field
,
879 bt_ctf_field_type_id_string(tag_field
->type
->id
));
883 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
884 variant_type
= container_of(field
->type
,
885 struct bt_ctf_field_type_variant
, parent
);
886 tag_enum
= bt_ctf_field_enumeration_get_container(tag_field
);
891 tag_enum_integer
= container_of(tag_enum
, struct bt_ctf_field_integer
,
894 if (bt_ctf_field_validate(tag_field
) < 0) {
895 BT_LOGW("Invalid parameter: tag field is invalid: "
896 "variant-field-addr=%p, tag-field-addr=%p",
901 tag_enum_value
= tag_enum_integer
->payload
.signd
;
904 * If the variant currently has a tag and a payload, and if the
905 * requested tag value is the same as the current one, return
906 * the current payload instead of creating a fresh one.
908 if (variant
->tag
&& variant
->payload
) {
909 struct bt_ctf_field
*cur_tag_container
= NULL
;
910 struct bt_ctf_field_integer
*cur_tag_enum_integer
;
911 int64_t cur_tag_value
;
914 bt_ctf_field_enumeration_get_container(variant
->tag
);
915 assert(cur_tag_container
);
916 cur_tag_enum_integer
= container_of(cur_tag_container
,
917 struct bt_ctf_field_integer
, parent
);
918 bt_put(cur_tag_container
);
919 cur_tag_value
= cur_tag_enum_integer
->payload
.signd
;
921 if (cur_tag_value
== tag_enum_value
) {
922 new_field
= variant
->payload
;
928 /* We don't want to modify this field if it's frozen */
930 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
935 field_type
= bt_ctf_field_type_variant_get_field_type_signed(
936 variant_type
, tag_enum_value
);
938 BT_LOGW("Cannot get variant field type's field: "
939 "variant-field-addr=%p, variant-ft-addr=%p, "
940 "tag-value-signed=%" PRId64
,
941 field
, variant_type
, tag_enum_value
);
945 new_field
= bt_ctf_field_create(field_type
);
947 BT_LOGW("Cannot create field: "
948 "variant-field-addr=%p, variant-ft-addr=%p, "
949 "field-ft-addr=%p", field
, field
->type
, field_type
);
953 bt_put(variant
->tag
);
954 bt_put(variant
->payload
);
957 variant
->tag
= tag_field
;
958 variant
->payload
= new_field
;
964 struct bt_ctf_field
*bt_ctf_field_variant_get_current_field(
965 struct bt_ctf_field
*variant_field
)
967 struct bt_ctf_field
*current_field
= NULL
;
968 struct bt_ctf_field_variant
*variant
;
970 if (!variant_field
) {
971 BT_LOGW_STR("Invalid parameter: field is NULL.");
975 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
976 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
977 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
978 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
980 bt_ctf_field_type_id_string(variant_field
->type
->id
));
984 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
987 if (variant
->payload
) {
988 current_field
= variant
->payload
;
989 bt_get(current_field
);
994 return current_field
;
997 struct bt_ctf_field
*bt_ctf_field_variant_get_tag(
998 struct bt_ctf_field
*variant_field
)
1000 struct bt_ctf_field
*tag
= NULL
;
1001 struct bt_ctf_field_variant
*variant
;
1003 if (!variant_field
) {
1004 BT_LOGW_STR("Invalid parameter: field is NULL.");
1008 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
1009 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
1010 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
1011 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
1012 variant_field
->type
,
1013 bt_ctf_field_type_id_string(variant_field
->type
->id
));
1017 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
1020 tag
= bt_get(variant
->tag
);
1026 struct bt_ctf_field
*bt_ctf_field_enumeration_get_container(
1027 struct bt_ctf_field
*field
)
1029 struct bt_ctf_field
*container
= NULL
;
1030 struct bt_ctf_field_enumeration
*enumeration
;
1033 BT_LOGW_STR("Invalid parameter: field is NULL.");
1037 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1038 BT_CTF_FIELD_TYPE_ID_ENUM
) {
1039 BT_LOGW("Invalid parameter: field's type is not an enumeration field type: "
1040 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1042 bt_ctf_field_type_id_string(field
->type
->id
));
1046 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
1048 if (!enumeration
->payload
) {
1049 /* We don't want to modify this field if it's frozen */
1050 if (field
->frozen
) {
1051 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1056 struct bt_ctf_field_type_enumeration
*enumeration_type
=
1057 container_of(field
->type
,
1058 struct bt_ctf_field_type_enumeration
, parent
);
1059 enumeration
->payload
=
1060 bt_ctf_field_create(enumeration_type
->container
);
1063 container
= enumeration
->payload
;
1069 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1070 bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field
*field
)
1073 struct bt_ctf_field
*container
= NULL
;
1074 struct bt_ctf_field_type
*container_type
= NULL
;
1075 struct bt_ctf_field_type_integer
*integer_type
= NULL
;
1076 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1078 container
= bt_ctf_field_enumeration_get_container(field
);
1080 BT_LOGW("Invalid parameter: enumeration field has no container field: "
1085 container_type
= bt_ctf_field_get_type(container
);
1086 assert(container_type
);
1087 integer_type
= container_of(container_type
,
1088 struct bt_ctf_field_type_integer
, parent
);
1090 if (!integer_type
->is_signed
) {
1093 ret
= bt_ctf_field_unsigned_integer_get_value(container
,
1096 BT_LOGW("Cannot get value from signed enumeration field's payload field: "
1097 "enum-field-addr=%p, payload-field-addr=%p",
1099 goto error_put_container_type
;
1101 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1102 field
->type
, value
);
1106 ret
= bt_ctf_field_signed_integer_get_value(container
,
1109 BT_LOGW("Cannot get value from unsigned enumeration field's payload field: "
1110 "enum-field-addr=%p, payload-field-addr=%p",
1112 goto error_put_container_type
;
1114 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1115 field
->type
, value
);
1118 error_put_container_type
:
1119 bt_put(container_type
);
1125 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field
*field
,
1129 struct bt_ctf_field_integer
*integer
;
1130 struct bt_ctf_field_type_integer
*integer_type
;
1133 BT_LOGW_STR("Invalid parameter: field is NULL.");
1139 BT_LOGW_STR("Invalid parameter: value is NULL.");
1144 if (!field
->payload_set
) {
1145 BT_LOGV("Field's payload is not set: addr=%p", field
);
1150 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1151 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1152 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1153 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1155 bt_ctf_field_type_id_string(field
->type
->id
));
1160 integer_type
= container_of(field
->type
,
1161 struct bt_ctf_field_type_integer
, parent
);
1162 if (!integer_type
->is_signed
) {
1163 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1164 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1169 integer
= container_of(field
,
1170 struct bt_ctf_field_integer
, parent
);
1171 *value
= integer
->payload
.signd
;
1176 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field
*field
,
1180 struct bt_ctf_field_integer
*integer
;
1181 struct bt_ctf_field_type_integer
*integer_type
;
1183 int64_t min_value
, max_value
;
1186 BT_LOGW_STR("Invalid parameter: field is NULL.");
1191 if (field
->frozen
) {
1192 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1198 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1199 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1200 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1201 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1203 bt_ctf_field_type_id_string(field
->type
->id
));
1208 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1209 integer_type
= container_of(field
->type
,
1210 struct bt_ctf_field_type_integer
, parent
);
1211 if (!integer_type
->is_signed
) {
1212 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1213 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1218 size
= integer_type
->size
;
1219 min_value
= -(1ULL << (size
- 1));
1220 max_value
= (1ULL << (size
- 1)) - 1;
1221 if (value
< min_value
|| value
> max_value
) {
1222 BT_LOGW("Invalid parameter: value is out of bounds: "
1223 "addr=%p, value=%" PRId64
", "
1224 "min-value=%" PRId64
", max-value=%" PRId64
,
1225 field
, value
, min_value
, max_value
);
1230 integer
->payload
.signd
= value
;
1231 integer
->parent
.payload_set
= 1;
1236 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field
*field
,
1240 struct bt_ctf_field_integer
*integer
;
1241 struct bt_ctf_field_type_integer
*integer_type
;
1244 BT_LOGW_STR("Invalid parameter: field is NULL.");
1250 BT_LOGW_STR("Invalid parameter: value is NULL.");
1255 if (!field
->payload_set
) {
1256 BT_LOGV("Field's payload is not set: addr=%p", field
);
1261 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1262 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1263 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1264 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1266 bt_ctf_field_type_id_string(field
->type
->id
));
1271 integer_type
= container_of(field
->type
,
1272 struct bt_ctf_field_type_integer
, parent
);
1273 if (integer_type
->is_signed
) {
1274 BT_LOGW("Invalid parameter: integer field's type is signed: "
1275 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1280 integer
= container_of(field
,
1281 struct bt_ctf_field_integer
, parent
);
1282 *value
= integer
->payload
.unsignd
;
1287 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field
*field
,
1291 struct bt_ctf_field_integer
*integer
;
1292 struct bt_ctf_field_type_integer
*integer_type
;
1297 BT_LOGW_STR("Invalid parameter: field is NULL.");
1302 if (field
->frozen
) {
1303 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1309 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1310 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1311 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1312 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1314 bt_ctf_field_type_id_string(field
->type
->id
));
1319 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1320 integer_type
= container_of(field
->type
,
1321 struct bt_ctf_field_type_integer
, parent
);
1322 if (integer_type
->is_signed
) {
1323 BT_LOGW("Invalid parameter: integer field's type is signed: "
1324 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1329 size
= integer_type
->size
;
1330 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
1331 if (value
> max_value
) {
1332 BT_LOGW("Invalid parameter: value is out of bounds: "
1333 "addr=%p, value=%" PRIu64
", "
1334 "min-value=%" PRIu64
", max-value=%" PRIu64
,
1335 field
, value
, (uint64_t) 0, max_value
);
1340 integer
->payload
.unsignd
= value
;
1341 integer
->parent
.payload_set
= 1;
1346 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field
*field
,
1350 struct bt_ctf_field_floating_point
*floating_point
;
1353 BT_LOGW_STR("Invalid parameter: field is NULL.");
1359 BT_LOGW_STR("Invalid parameter: value is NULL.");
1364 if (!field
->payload_set
) {
1365 BT_LOGV("Field's payload is not set: addr=%p", field
);
1370 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1371 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1372 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1373 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1375 bt_ctf_field_type_id_string(field
->type
->id
));
1380 floating_point
= container_of(field
,
1381 struct bt_ctf_field_floating_point
, parent
);
1382 *value
= floating_point
->payload
;
1387 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field
*field
,
1391 struct bt_ctf_field_floating_point
*floating_point
;
1394 BT_LOGW_STR("Invalid parameter: field is NULL.");
1399 if (field
->frozen
) {
1400 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
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
, struct bt_ctf_field_floating_point
,
1418 floating_point
->payload
= value
;
1419 floating_point
->parent
.payload_set
= 1;
1424 const char *bt_ctf_field_string_get_value(struct bt_ctf_field
*field
)
1426 const char *ret
= NULL
;
1427 struct bt_ctf_field_string
*string
;
1430 BT_LOGW_STR("Invalid parameter: field is NULL.");
1434 if (!field
->payload_set
) {
1435 BT_LOGV("Field's payload is not set: addr=%p", field
);
1439 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1440 BT_CTF_FIELD_TYPE_ID_STRING
) {
1441 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1442 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1444 bt_ctf_field_type_id_string(field
->type
->id
));
1448 string
= container_of(field
,
1449 struct bt_ctf_field_string
, parent
);
1450 ret
= string
->payload
->str
;
1455 int bt_ctf_field_string_set_value(struct bt_ctf_field
*field
,
1459 struct bt_ctf_field_string
*string
;
1462 BT_LOGW_STR("Invalid parameter: field is NULL.");
1468 BT_LOGW_STR("Invalid parameter: value is NULL.");
1473 if (field
->frozen
) {
1474 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1480 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1481 BT_CTF_FIELD_TYPE_ID_STRING
) {
1482 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1483 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1485 bt_ctf_field_type_id_string(field
->type
->id
));
1490 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
1491 if (string
->payload
) {
1492 g_string_assign(string
->payload
, value
);
1494 string
->payload
= g_string_new(value
);
1497 string
->parent
.payload_set
= 1;
1502 int bt_ctf_field_string_append(struct bt_ctf_field
*field
,
1506 struct bt_ctf_field_string
*string_field
;
1509 BT_LOGW_STR("Invalid parameter: field is NULL.");
1515 BT_LOGW_STR("Invalid parameter: value is NULL.");
1520 if (field
->frozen
) {
1521 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1527 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1528 BT_CTF_FIELD_TYPE_ID_STRING
) {
1529 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1530 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1532 bt_ctf_field_type_id_string(field
->type
->id
));
1537 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1539 if (string_field
->payload
) {
1540 g_string_append(string_field
->payload
, value
);
1542 string_field
->payload
= g_string_new(value
);
1545 string_field
->parent
.payload_set
= 1;
1551 int bt_ctf_field_string_append_len(struct bt_ctf_field
*field
,
1552 const char *value
, unsigned int length
)
1556 unsigned int effective_length
= length
;
1557 struct bt_ctf_field_string
*string_field
;
1560 BT_LOGW_STR("Invalid parameter: field is NULL.");
1566 BT_LOGW_STR("Invalid parameter: value is NULL.");
1571 if (field
->frozen
) {
1572 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1578 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1579 BT_CTF_FIELD_TYPE_ID_STRING
) {
1580 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1581 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1583 bt_ctf_field_type_id_string(field
->type
->id
));
1588 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1590 /* make sure no null bytes are appended */
1591 for (i
= 0; i
< length
; ++i
) {
1592 if (value
[i
] == '\0') {
1593 effective_length
= i
;
1598 if (string_field
->payload
) {
1599 g_string_append_len(string_field
->payload
, value
,
1602 string_field
->payload
= g_string_new_len(value
,
1606 string_field
->parent
.payload_set
= 1;
1613 int bt_ctf_field_validate(struct bt_ctf_field
*field
)
1616 enum bt_ctf_field_type_id type_id
;
1619 BT_LOGD_STR("Invalid parameter: field is NULL.");
1624 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1625 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1626 BT_LOGW("Invalid parameter: unknown field type ID: "
1627 "addr=%p, ft-addr=%p, ft-id=%d",
1628 field
, field
->type
, type_id
);
1633 ret
= field_validate_funcs
[type_id
](field
);
1639 int bt_ctf_field_reset(struct bt_ctf_field
*field
)
1642 enum bt_ctf_field_type_id type_id
;
1645 BT_LOGD_STR("Invalid parameter: field is NULL.");
1650 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1651 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1652 BT_LOGW("Invalid parameter: unknown field type ID: "
1653 "addr=%p, ft-addr=%p, ft-id=%d",
1654 field
, field
->type
, type_id
);
1659 ret
= field_reset_funcs
[type_id
](field
);
1665 int bt_ctf_field_serialize(struct bt_ctf_field
*field
,
1666 struct bt_ctf_stream_pos
*pos
,
1667 enum bt_ctf_byte_order native_byte_order
)
1670 enum bt_ctf_field_type_id type_id
;
1675 BT_LOGD_STR("Invalid parameter: field is NULL.");
1680 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1681 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1682 BT_LOGW("Invalid parameter: unknown field type ID: "
1683 "addr=%p, ft-addr=%p, ft-id=%d",
1684 field
, field
->type
, type_id
);
1689 ret
= field_serialize_funcs
[type_id
](field
, pos
, native_byte_order
);
1696 bt_bool
bt_ctf_field_is_set(struct bt_ctf_field
*field
)
1698 bt_bool is_set
= BT_FALSE
;
1699 enum bt_ctf_field_type_id type_id
;
1705 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1706 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1707 BT_LOGW("Invalid parameter: unknown field type ID: "
1708 "field-addr=%p, ft-addr=%p, ft-id=%d",
1709 field
, field
->type
, type_id
);
1713 is_set
= field_is_set_funcs
[type_id
](field
);
1718 struct bt_ctf_field
*bt_ctf_field_copy(struct bt_ctf_field
*field
)
1721 struct bt_ctf_field
*copy
= NULL
;
1722 enum bt_ctf_field_type_id type_id
;
1725 BT_LOGW_STR("Invalid parameter: field is NULL.");
1729 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1730 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1731 BT_LOGW("Invalid parameter: unknown field type ID: "
1732 "field-addr=%p, ft-addr=%p, ft-id=%d",
1733 field
, field
->type
, type_id
);
1737 copy
= bt_ctf_field_create(field
->type
);
1739 BT_LOGW("Cannot create field: ft-addr=%p", field
->type
);
1743 copy
->payload_set
= field
->payload_set
;
1744 ret
= field_copy_funcs
[type_id
](field
, copy
);
1754 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*type
)
1756 struct bt_ctf_field_integer
*integer
= g_new0(
1757 struct bt_ctf_field_integer
, 1);
1759 BT_LOGD("Creating integer field object: ft-addr=%p", type
);
1762 BT_LOGD("Created integer field object: addr=%p, ft-addr=%p",
1763 &integer
->parent
, type
);
1765 BT_LOGE_STR("Failed to allocate one integer field.");
1768 return integer
? &integer
->parent
: NULL
;
1772 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
1773 struct bt_ctf_field_type
*type
)
1775 struct bt_ctf_field_enumeration
*enumeration
= g_new0(
1776 struct bt_ctf_field_enumeration
, 1);
1778 BT_LOGD("Creating enumeration field object: ft-addr=%p", type
);
1781 BT_LOGD("Created enumeration field object: addr=%p, ft-addr=%p",
1782 &enumeration
->parent
, type
);
1784 BT_LOGE_STR("Failed to allocate one enumeration field.");
1787 return enumeration
? &enumeration
->parent
: NULL
;
1791 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
1792 struct bt_ctf_field_type
*type
)
1794 struct bt_ctf_field_floating_point
*floating_point
;
1796 BT_LOGD("Creating floating point number field object: ft-addr=%p", type
);
1797 floating_point
= g_new0(struct bt_ctf_field_floating_point
, 1);
1799 if (floating_point
) {
1800 BT_LOGD("Created floating point number field object: addr=%p, ft-addr=%p",
1801 &floating_point
->parent
, type
);
1803 BT_LOGE_STR("Failed to allocate one floating point number field.");
1806 return floating_point
? &floating_point
->parent
: NULL
;
1810 struct bt_ctf_field
*bt_ctf_field_structure_create(
1811 struct bt_ctf_field_type
*type
)
1813 struct bt_ctf_field_type_structure
*structure_type
= container_of(type
,
1814 struct bt_ctf_field_type_structure
, parent
);
1815 struct bt_ctf_field_structure
*structure
= g_new0(
1816 struct bt_ctf_field_structure
, 1);
1817 struct bt_ctf_field
*field
= NULL
;
1819 BT_LOGD("Creating structure field object: ft-addr=%p", type
);
1822 BT_LOGE_STR("Failed to allocate one structure field.");
1826 structure
->field_name_to_index
= structure_type
->field_name_to_index
;
1827 structure
->fields
= g_ptr_array_new_with_free_func(
1828 (GDestroyNotify
)bt_ctf_field_put
);
1829 g_ptr_array_set_size(structure
->fields
,
1830 g_hash_table_size(structure
->field_name_to_index
));
1831 field
= &structure
->parent
;
1832 BT_LOGD("Created structure field object: addr=%p, ft-addr=%p",
1839 struct bt_ctf_field
*bt_ctf_field_variant_create(struct bt_ctf_field_type
*type
)
1841 struct bt_ctf_field_variant
*variant
= g_new0(
1842 struct bt_ctf_field_variant
, 1);
1844 BT_LOGD("Creating variant field object: ft-addr=%p", type
);
1847 BT_LOGD("Created variant field object: addr=%p, ft-addr=%p",
1848 &variant
->parent
, type
);
1850 BT_LOGE_STR("Failed to allocate one variant field.");
1853 return variant
? &variant
->parent
: NULL
;
1857 struct bt_ctf_field
*bt_ctf_field_array_create(struct bt_ctf_field_type
*type
)
1859 struct bt_ctf_field_array
*array
= g_new0(struct bt_ctf_field_array
, 1);
1860 struct bt_ctf_field_type_array
*array_type
;
1861 unsigned int array_length
;
1863 BT_LOGD("Creating array field object: ft-addr=%p", type
);
1867 BT_LOGE_STR("Failed to allocate one array field.");
1871 array_type
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
1872 array_length
= array_type
->length
;
1873 array
->elements
= g_ptr_array_sized_new(array_length
);
1874 if (!array
->elements
) {
1878 g_ptr_array_set_free_func(array
->elements
,
1879 (GDestroyNotify
)bt_ctf_field_put
);
1880 g_ptr_array_set_size(array
->elements
, array_length
);
1881 BT_LOGD("Created array field object: addr=%p, ft-addr=%p",
1882 &array
->parent
, type
);
1883 return &array
->parent
;
1890 struct bt_ctf_field
*bt_ctf_field_sequence_create(
1891 struct bt_ctf_field_type
*type
)
1893 struct bt_ctf_field_sequence
*sequence
= g_new0(
1894 struct bt_ctf_field_sequence
, 1);
1896 BT_LOGD("Creating sequence field object: ft-addr=%p", type
);
1899 BT_LOGD("Created sequence field object: addr=%p, ft-addr=%p",
1900 &sequence
->parent
, type
);
1902 BT_LOGE_STR("Failed to allocate one sequence field.");
1905 return sequence
? &sequence
->parent
: NULL
;
1909 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*type
)
1911 struct bt_ctf_field_string
*string
= g_new0(
1912 struct bt_ctf_field_string
, 1);
1914 BT_LOGD("Creating string field object: ft-addr=%p", type
);
1917 BT_LOGD("Created string field object: addr=%p, ft-addr=%p",
1918 &string
->parent
, type
);
1920 BT_LOGE_STR("Failed to allocate one string field.");
1923 return string
? &string
->parent
: NULL
;
1927 void bt_ctf_field_destroy(struct bt_object
*obj
)
1929 struct bt_ctf_field
*field
;
1930 struct bt_ctf_field_type
*type
;
1931 enum bt_ctf_field_type_id type_id
;
1933 field
= container_of(obj
, struct bt_ctf_field
, base
);
1935 type_id
= bt_ctf_field_type_get_type_id(type
);
1936 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
1937 type_id
< BT_CTF_NR_TYPE_IDS
);
1938 field_destroy_funcs
[type_id
](field
);
1939 BT_LOGD_STR("Putting field's type.");
1944 void bt_ctf_field_integer_destroy(struct bt_ctf_field
*field
)
1946 struct bt_ctf_field_integer
*integer
;
1952 BT_LOGD("Destroying integer field object: addr=%p", field
);
1953 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1958 void bt_ctf_field_enumeration_destroy(struct bt_ctf_field
*field
)
1960 struct bt_ctf_field_enumeration
*enumeration
;
1966 BT_LOGD("Destroying enumeration field object: addr=%p", field
);
1967 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
1969 BT_LOGD_STR("Putting payload field.");
1970 bt_put(enumeration
->payload
);
1971 g_free(enumeration
);
1975 void bt_ctf_field_floating_point_destroy(struct bt_ctf_field
*field
)
1977 struct bt_ctf_field_floating_point
*floating_point
;
1983 BT_LOGD("Destroying floating point number field object: addr=%p", field
);
1984 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
1986 g_free(floating_point
);
1990 void bt_ctf_field_structure_destroy(struct bt_ctf_field
*field
)
1992 struct bt_ctf_field_structure
*structure
;
1998 BT_LOGD("Destroying structure field object: addr=%p", field
);
1999 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2000 g_ptr_array_free(structure
->fields
, TRUE
);
2005 void bt_ctf_field_variant_destroy(struct bt_ctf_field
*field
)
2007 struct bt_ctf_field_variant
*variant
;
2013 BT_LOGD("Destroying variant field object: addr=%p", field
);
2014 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2015 BT_LOGD_STR("Putting tag field.");
2016 bt_put(variant
->tag
);
2017 BT_LOGD_STR("Putting payload field.");
2018 bt_put(variant
->payload
);
2023 void bt_ctf_field_array_destroy(struct bt_ctf_field
*field
)
2025 struct bt_ctf_field_array
*array
;
2031 BT_LOGD("Destroying array field object: addr=%p", field
);
2032 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2033 g_ptr_array_free(array
->elements
, TRUE
);
2038 void bt_ctf_field_sequence_destroy(struct bt_ctf_field
*field
)
2040 struct bt_ctf_field_sequence
*sequence
;
2046 BT_LOGD("Destroying sequence field object: addr=%p", field
);
2047 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2048 if (sequence
->elements
) {
2049 g_ptr_array_free(sequence
->elements
, TRUE
);
2051 BT_LOGD_STR("Putting length field.");
2052 bt_put(sequence
->length
);
2057 void bt_ctf_field_string_destroy(struct bt_ctf_field
*field
)
2059 struct bt_ctf_field_string
*string
;
2065 BT_LOGD("Destroying string field object: addr=%p", field
);
2066 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2067 if (string
->payload
) {
2068 g_string_free(string
->payload
, TRUE
);
2074 int bt_ctf_field_generic_validate(struct bt_ctf_field
*field
)
2076 return (field
&& field
->payload_set
) ? 0 : -1;
2080 int bt_ctf_field_enumeration_validate(struct bt_ctf_field
*field
)
2083 struct bt_ctf_field_enumeration
*enumeration
;
2086 BT_LOGD_STR("Invalid parameter: field is NULL.");
2091 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2093 if (!enumeration
->payload
) {
2094 BT_LOGW("Invalid enumeration field: payload is not set: "
2100 ret
= bt_ctf_field_validate(enumeration
->payload
);
2106 int bt_ctf_field_structure_validate(struct bt_ctf_field
*field
)
2110 struct bt_ctf_field_structure
*structure
;
2113 BT_LOGD_STR("Invalid parameter: field is NULL.");
2118 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2119 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2120 struct bt_ctf_field
*entry_field
= structure
->fields
->pdata
[i
];
2121 ret
= bt_ctf_field_validate(entry_field
);
2126 struct bt_ctf_field_type
*field_type
=
2127 bt_ctf_field_get_type(field
);
2129 this_ret
= bt_ctf_field_type_structure_get_field(
2130 field_type
, &name
, NULL
, i
);
2131 assert(this_ret
== 0);
2132 BT_LOGW("Invalid structure field's field: "
2133 "struct-field-addr=%p, field-addr=%p, "
2134 "field-name=\"%s\", index=%" PRId64
,
2135 field
, entry_field
, name
, i
);
2145 int bt_ctf_field_variant_validate(struct bt_ctf_field
*field
)
2148 struct bt_ctf_field_variant
*variant
;
2151 BT_LOGD_STR("Invalid parameter: field is NULL.");
2156 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2157 ret
= bt_ctf_field_validate(variant
->payload
);
2159 BT_LOGW("Invalid variant field's payload field: "
2160 "variant-field-addr=%p, variant-payload-field-addr=%p",
2161 field
, variant
->payload
);
2168 int bt_ctf_field_array_validate(struct bt_ctf_field
*field
)
2172 struct bt_ctf_field_array
*array
;
2175 BT_LOGD_STR("Invalid parameter: field is NULL.");
2180 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2181 for (i
= 0; i
< array
->elements
->len
; i
++) {
2182 struct bt_ctf_field
*elem_field
= array
->elements
->pdata
[i
];
2184 ret
= bt_ctf_field_validate(elem_field
);
2186 BT_LOGW("Invalid array field's element field: "
2187 "array-field-addr=%p, field-addr=%p, "
2188 "index=%" PRId64
, field
, elem_field
, i
);
2197 int bt_ctf_field_sequence_validate(struct bt_ctf_field
*field
)
2201 struct bt_ctf_field_sequence
*sequence
;
2204 BT_LOGD_STR("Invalid parameter: field is NULL.");
2209 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2210 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2211 struct bt_ctf_field
*elem_field
= sequence
->elements
->pdata
[i
];
2213 ret
= bt_ctf_field_validate(elem_field
);
2215 BT_LOGW("Invalid sequence field's element field: "
2216 "sequence-field-addr=%p, field-addr=%p, "
2217 "index=%" PRId64
, field
, elem_field
, i
);
2226 int bt_ctf_field_generic_reset(struct bt_ctf_field
*field
)
2231 BT_LOGD_STR("Invalid parameter: field is NULL.");
2236 field
->payload_set
= 0;
2242 int bt_ctf_field_enumeration_reset(struct bt_ctf_field
*field
)
2245 struct bt_ctf_field_enumeration
*enumeration
;
2248 BT_LOGD_STR("Invalid parameter: field is NULL.");
2253 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2255 if (!enumeration
->payload
) {
2259 ret
= bt_ctf_field_reset(enumeration
->payload
);
2265 int bt_ctf_field_structure_reset(struct bt_ctf_field
*field
)
2269 struct bt_ctf_field_structure
*structure
;
2272 BT_LOGD_STR("Invalid parameter: field is NULL.");
2277 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2278 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2279 struct bt_ctf_field
*member
= structure
->fields
->pdata
[i
];
2283 * Structure members are lazily initialized; skip if
2284 * this member has not been allocated yet.
2289 ret
= bt_ctf_field_reset(member
);
2291 BT_LOGE("Failed to reset structure field's field: "
2292 "struct-field-addr=%p, field-addr=%p, "
2293 "index=%" PRId64
, field
, member
, i
);
2302 int bt_ctf_field_variant_reset(struct bt_ctf_field
*field
)
2305 struct bt_ctf_field_variant
*variant
;
2308 BT_LOGD_STR("Invalid parameter: field is NULL.");
2313 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2314 if (variant
->payload
) {
2315 ret
= bt_ctf_field_reset(variant
->payload
);
2317 BT_LOGW("Failed to reset variant field's payload field: "
2318 "variant-field-addr=%p, payload-field-addr=%p",
2319 field
, variant
->payload
);
2327 int bt_ctf_field_array_reset(struct bt_ctf_field
*field
)
2331 struct bt_ctf_field_array
*array
;
2334 BT_LOGD_STR("Invalid parameter: field is NULL.");
2339 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2340 for (i
= 0; i
< array
->elements
->len
; i
++) {
2341 struct bt_ctf_field
*member
= array
->elements
->pdata
[i
];
2345 * Array elements are lazily initialized; skip if
2346 * this member has not been allocated yet.
2351 ret
= bt_ctf_field_reset(member
);
2353 BT_LOGE("Failed to reset array field's field: "
2354 "array-field-addr=%p, field-addr=%p, "
2355 "index=%" PRId64
, field
, member
, i
);
2364 int bt_ctf_field_sequence_reset(struct bt_ctf_field
*field
)
2368 struct bt_ctf_field_sequence
*sequence
;
2371 BT_LOGD_STR("Invalid parameter: field is NULL.");
2376 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2377 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2378 struct bt_ctf_field
*member
= sequence
->elements
->pdata
[i
];
2382 * Sequence elements are lazily initialized; skip if
2383 * this member has not been allocated yet.
2388 ret
= bt_ctf_field_reset(member
);
2390 BT_LOGE("Failed to reset sequence field's field: "
2391 "sequence-field-addr=%p, field-addr=%p, "
2392 "index=%" PRId64
, field
, member
, i
);
2401 int bt_ctf_field_string_reset(struct bt_ctf_field
*field
)
2404 struct bt_ctf_field_string
*string
;
2407 BT_LOGD_STR("Invalid parameter: field is NULL.");
2412 ret
= bt_ctf_field_generic_reset(field
);
2417 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2418 if (string
->payload
) {
2419 g_string_truncate(string
->payload
, 0);
2426 int bt_ctf_field_integer_serialize(struct bt_ctf_field
*field
,
2427 struct bt_ctf_stream_pos
*pos
,
2428 enum bt_ctf_byte_order native_byte_order
)
2431 struct bt_ctf_field_integer
*integer
= container_of(field
,
2432 struct bt_ctf_field_integer
, parent
);
2434 BT_LOGV("Serializing integer field: addr=%p, pos-offset=%" PRId64
", "
2435 "native-bo=%s", field
, pos
->offset
,
2436 bt_ctf_byte_order_string(native_byte_order
));
2438 if (!bt_ctf_field_generic_is_set(field
)) {
2439 BT_LOGW_STR("Field's payload is not set.");
2444 ret
= bt_ctf_field_integer_write(integer
, pos
, native_byte_order
);
2445 if (ret
== -EFAULT
) {
2447 * The field is too large to fit in the current packet's
2448 * remaining space. Bump the packet size and retry.
2450 ret
= increase_packet_size(pos
);
2452 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2462 int bt_ctf_field_enumeration_serialize(struct bt_ctf_field
*field
,
2463 struct bt_ctf_stream_pos
*pos
,
2464 enum bt_ctf_byte_order native_byte_order
)
2466 struct bt_ctf_field_enumeration
*enumeration
= container_of(
2467 field
, struct bt_ctf_field_enumeration
, parent
);
2469 BT_LOGV("Serializing enumeration field: addr=%p, pos-offset=%" PRId64
", "
2470 "native-bo=%s", field
, pos
->offset
,
2471 bt_ctf_byte_order_string(native_byte_order
));
2472 BT_LOGV_STR("Serializing enumeration field's payload field.");
2473 return bt_ctf_field_serialize(enumeration
->payload
, pos
,
2478 int bt_ctf_field_floating_point_serialize(struct bt_ctf_field
*field
,
2479 struct bt_ctf_stream_pos
*pos
,
2480 enum bt_ctf_byte_order native_byte_order
)
2483 struct bt_ctf_field_floating_point
*floating_point
= container_of(field
,
2484 struct bt_ctf_field_floating_point
, parent
);
2486 BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64
", "
2487 "native-bo=%s", field
, pos
->offset
,
2488 bt_ctf_byte_order_string(native_byte_order
));
2490 if (!bt_ctf_field_generic_is_set(field
)) {
2491 BT_LOGW_STR("Field's payload is not set.");
2496 ret
= bt_ctf_field_floating_point_write(floating_point
, pos
,
2498 if (ret
== -EFAULT
) {
2500 * The field is too large to fit in the current packet's
2501 * remaining space. Bump the packet size and retry.
2503 ret
= increase_packet_size(pos
);
2505 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2515 int bt_ctf_field_structure_serialize(struct bt_ctf_field
*field
,
2516 struct bt_ctf_stream_pos
*pos
,
2517 enum bt_ctf_byte_order native_byte_order
)
2521 struct bt_ctf_field_structure
*structure
= container_of(
2522 field
, struct bt_ctf_field_structure
, parent
);
2524 BT_LOGV("Serializing structure field: addr=%p, pos-offset=%" PRId64
", "
2525 "native-bo=%s", field
, pos
->offset
,
2526 bt_ctf_byte_order_string(native_byte_order
));
2528 while (!bt_ctf_stream_pos_access_ok(pos
,
2529 offset_align(pos
->offset
, field
->type
->alignment
))) {
2530 ret
= increase_packet_size(pos
);
2532 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2537 if (!bt_ctf_stream_pos_align(pos
, field
->type
->alignment
)) {
2538 BT_LOGE("Cannot align packet's position: pos-offset=%" PRId64
", "
2539 "align=%u", pos
->offset
, field
->type
->alignment
);
2544 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2545 struct bt_ctf_field
*member
= g_ptr_array_index(
2546 structure
->fields
, i
);
2548 BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64
", "
2549 "field-addr=%p, index=%" PRId64
,
2550 pos
->offset
, member
, i
);
2551 ret
= bt_ctf_field_serialize(member
, pos
, native_byte_order
);
2555 struct bt_ctf_field_type
*structure_type
=
2556 bt_ctf_field_get_type(field
);
2558 this_ret
= bt_ctf_field_type_structure_get_field(
2559 structure_type
, &name
, NULL
, i
);
2560 assert(this_ret
== 0);
2561 BT_LOGW("Cannot serialize structure field's field: "
2562 "struct-field-addr=%p, field-addr=%p, "
2563 "field-name=\"%s\", index=%" PRId64
,
2564 field
, member
, name
, i
);
2565 bt_put(structure_type
);
2574 int bt_ctf_field_variant_serialize(struct bt_ctf_field
*field
,
2575 struct bt_ctf_stream_pos
*pos
,
2576 enum bt_ctf_byte_order native_byte_order
)
2578 struct bt_ctf_field_variant
*variant
= container_of(
2579 field
, struct bt_ctf_field_variant
, parent
);
2581 BT_LOGV("Serializing variant field: addr=%p, pos-offset=%" PRId64
", "
2582 "native-bo=%s", field
, pos
->offset
,
2583 bt_ctf_byte_order_string(native_byte_order
));
2584 BT_LOGV_STR("Serializing variant field's payload field.");
2585 return bt_ctf_field_serialize(variant
->payload
, pos
,
2590 int bt_ctf_field_array_serialize(struct bt_ctf_field
*field
,
2591 struct bt_ctf_stream_pos
*pos
,
2592 enum bt_ctf_byte_order native_byte_order
)
2596 struct bt_ctf_field_array
*array
= container_of(
2597 field
, struct bt_ctf_field_array
, parent
);
2599 BT_LOGV("Serializing array field: addr=%p, pos-offset=%" PRId64
", "
2600 "native-bo=%s", field
, pos
->offset
,
2601 bt_ctf_byte_order_string(native_byte_order
));
2603 for (i
= 0; i
< array
->elements
->len
; i
++) {
2604 struct bt_ctf_field
*elem_field
=
2605 g_ptr_array_index(array
->elements
, i
);
2607 BT_LOGV("Serializing array field's element field: "
2608 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2609 pos
->offset
, elem_field
, i
);
2610 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2613 BT_LOGW("Cannot serialize array field's element field: "
2614 "array-field-addr=%p, field-addr=%p, "
2615 "index=%" PRId64
, field
, elem_field
, i
);
2624 int bt_ctf_field_sequence_serialize(struct bt_ctf_field
*field
,
2625 struct bt_ctf_stream_pos
*pos
,
2626 enum bt_ctf_byte_order native_byte_order
)
2630 struct bt_ctf_field_sequence
*sequence
= container_of(
2631 field
, struct bt_ctf_field_sequence
, parent
);
2633 BT_LOGV("Serializing sequence field: addr=%p, pos-offset=%" PRId64
", "
2634 "native-bo=%s", field
, pos
->offset
,
2635 bt_ctf_byte_order_string(native_byte_order
));
2637 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2638 struct bt_ctf_field
*elem_field
=
2639 g_ptr_array_index(sequence
->elements
, i
);
2641 BT_LOGV("Serializing sequence field's element field: "
2642 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2643 pos
->offset
, elem_field
, i
);
2644 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2647 BT_LOGW("Cannot serialize sequence field's element field: "
2648 "sequence-field-addr=%p, field-addr=%p, "
2649 "index=%" PRId64
, field
, elem_field
, i
);
2658 int bt_ctf_field_string_serialize(struct bt_ctf_field
*field
,
2659 struct bt_ctf_stream_pos
*pos
,
2660 enum bt_ctf_byte_order native_byte_order
)
2664 struct bt_ctf_field_string
*string
= container_of(field
,
2665 struct bt_ctf_field_string
, parent
);
2666 struct bt_ctf_field_type
*character_type
=
2667 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
2668 struct bt_ctf_field
*character
;
2670 BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64
", "
2671 "native-bo=%s", field
, pos
->offset
,
2672 bt_ctf_byte_order_string(native_byte_order
));
2674 BT_LOGV_STR("Creating character field from string field's character field type.");
2675 character
= bt_ctf_field_create(character_type
);
2677 for (i
= 0; i
< string
->payload
->len
+ 1; i
++) {
2678 const uint64_t chr
= (uint64_t) string
->payload
->str
[i
];
2680 ret
= bt_ctf_field_unsigned_integer_set_value(character
, chr
);
2682 BT_LOGE("Cannot set character field's value: "
2683 "pos-offset=%" PRId64
", field-addr=%p, "
2684 "index=%" PRId64
", char-int=%" PRIu64
,
2685 pos
->offset
, character
, i
, chr
);
2689 BT_LOGV("Serializing string field's character field: "
2690 "pos-offset=%" PRId64
", field-addr=%p, "
2691 "index=%" PRId64
", char-int=%" PRIu64
,
2692 pos
->offset
, character
, i
, chr
);
2693 ret
= bt_ctf_field_integer_serialize(character
, pos
,
2696 BT_LOGE_STR("Cannot serialize character field.");
2702 bt_put(character_type
);
2707 int bt_ctf_field_integer_copy(struct bt_ctf_field
*src
,
2708 struct bt_ctf_field
*dst
)
2710 struct bt_ctf_field_integer
*integer_src
, *integer_dst
;
2712 BT_LOGD("Copying integer field: src-field-addr=%p, dst-field-addr=%p",
2714 integer_src
= container_of(src
, struct bt_ctf_field_integer
, parent
);
2715 integer_dst
= container_of(dst
, struct bt_ctf_field_integer
, parent
);
2716 integer_dst
->payload
= integer_src
->payload
;
2717 BT_LOGD_STR("Copied integer field.");
2722 int bt_ctf_field_enumeration_copy(struct bt_ctf_field
*src
,
2723 struct bt_ctf_field
*dst
)
2726 struct bt_ctf_field_enumeration
*enum_src
, *enum_dst
;
2728 BT_LOGD("Copying enumeration field: src-field-addr=%p, dst-field-addr=%p",
2730 enum_src
= container_of(src
, struct bt_ctf_field_enumeration
, parent
);
2731 enum_dst
= container_of(dst
, struct bt_ctf_field_enumeration
, parent
);
2733 if (enum_src
->payload
) {
2734 BT_LOGD_STR("Copying enumeration field's payload field.");
2735 enum_dst
->payload
= bt_ctf_field_copy(enum_src
->payload
);
2736 if (!enum_dst
->payload
) {
2737 BT_LOGE_STR("Cannot copy enumeration field's payload field.");
2743 BT_LOGD_STR("Copied enumeration field.");
2749 int bt_ctf_field_floating_point_copy(
2750 struct bt_ctf_field
*src
, struct bt_ctf_field
*dst
)
2752 struct bt_ctf_field_floating_point
*float_src
, *float_dst
;
2754 BT_LOGD("Copying floating point number field: src-field-addr=%p, dst-field-addr=%p",
2756 float_src
= container_of(src
, struct bt_ctf_field_floating_point
,
2758 float_dst
= container_of(dst
, struct bt_ctf_field_floating_point
,
2760 float_dst
->payload
= float_src
->payload
;
2761 BT_LOGD_STR("Copied floating point number field.");
2766 int bt_ctf_field_structure_copy(struct bt_ctf_field
*src
,
2767 struct bt_ctf_field
*dst
)
2771 struct bt_ctf_field_structure
*struct_src
, *struct_dst
;
2773 BT_LOGD("Copying structure field: src-field-addr=%p, dst-field-addr=%p",
2775 struct_src
= container_of(src
, struct bt_ctf_field_structure
, parent
);
2776 struct_dst
= container_of(dst
, struct bt_ctf_field_structure
, parent
);
2778 /* This field_name_to_index HT is owned by the structure field type */
2779 struct_dst
->field_name_to_index
= struct_src
->field_name_to_index
;
2780 g_ptr_array_set_size(struct_dst
->fields
, struct_src
->fields
->len
);
2782 for (i
= 0; i
< struct_src
->fields
->len
; i
++) {
2783 struct bt_ctf_field
*field
=
2784 g_ptr_array_index(struct_src
->fields
, i
);
2785 struct bt_ctf_field
*field_copy
= NULL
;
2788 BT_LOGD("Copying structure field's field: src-field-addr=%p",
2789 "index=%" PRId64
, field
, i
);
2790 field_copy
= bt_ctf_field_copy(field
);
2792 BT_LOGE("Cannot copy structure field's field: "
2793 "src-field-addr=%p, index=%" PRId64
,
2800 g_ptr_array_index(struct_dst
->fields
, i
) = field_copy
;
2803 BT_LOGD_STR("Copied structure field.");
2810 int bt_ctf_field_variant_copy(struct bt_ctf_field
*src
,
2811 struct bt_ctf_field
*dst
)
2814 struct bt_ctf_field_variant
*variant_src
, *variant_dst
;
2816 BT_LOGD("Copying variant field: src-field-addr=%p, dst-field-addr=%p",
2818 variant_src
= container_of(src
, struct bt_ctf_field_variant
, parent
);
2819 variant_dst
= container_of(dst
, struct bt_ctf_field_variant
, parent
);
2821 if (variant_src
->tag
) {
2822 BT_LOGD_STR("Copying variant field's tag field.");
2823 variant_dst
->tag
= bt_ctf_field_copy(variant_src
->tag
);
2824 if (!variant_dst
->tag
) {
2825 BT_LOGE_STR("Cannot copy variant field's tag field.");
2830 if (variant_src
->payload
) {
2831 BT_LOGD_STR("Copying variant field's payload field.");
2832 variant_dst
->payload
= bt_ctf_field_copy(variant_src
->payload
);
2833 if (!variant_dst
->payload
) {
2834 BT_LOGE_STR("Cannot copy variant field's payload field.");
2840 BT_LOGD_STR("Copied variant field.");
2847 int bt_ctf_field_array_copy(struct bt_ctf_field
*src
,
2848 struct bt_ctf_field
*dst
)
2852 struct bt_ctf_field_array
*array_src
, *array_dst
;
2854 BT_LOGD("Copying array field: src-field-addr=%p, dst-field-addr=%p",
2856 array_src
= container_of(src
, struct bt_ctf_field_array
, parent
);
2857 array_dst
= container_of(dst
, struct bt_ctf_field_array
, parent
);
2859 g_ptr_array_set_size(array_dst
->elements
, array_src
->elements
->len
);
2860 for (i
= 0; i
< array_src
->elements
->len
; i
++) {
2861 struct bt_ctf_field
*field
=
2862 g_ptr_array_index(array_src
->elements
, i
);
2863 struct bt_ctf_field
*field_copy
= NULL
;
2866 BT_LOGD("Copying array field's element field: field-addr=%p, "
2867 "index=%" PRId64
, field
, i
);
2868 field_copy
= bt_ctf_field_copy(field
);
2870 BT_LOGE("Cannot copy array field's element field: "
2871 "src-field-addr=%p, index=%" PRId64
,
2878 g_ptr_array_index(array_dst
->elements
, i
) = field_copy
;
2881 BT_LOGD_STR("Copied array field.");
2888 int bt_ctf_field_sequence_copy(struct bt_ctf_field
*src
,
2889 struct bt_ctf_field
*dst
)
2893 struct bt_ctf_field_sequence
*sequence_src
, *sequence_dst
;
2894 struct bt_ctf_field
*src_length
;
2895 struct bt_ctf_field
*dst_length
;
2897 BT_LOGD("Copying sequence field: src-field-addr=%p, dst-field-addr=%p",
2899 sequence_src
= container_of(src
, struct bt_ctf_field_sequence
, parent
);
2900 sequence_dst
= container_of(dst
, struct bt_ctf_field_sequence
, parent
);
2902 src_length
= bt_ctf_field_sequence_get_length(src
);
2904 /* no length set yet: keep destination sequence empty */
2908 /* copy source length */
2909 BT_LOGD_STR("Copying sequence field's length field.");
2910 dst_length
= bt_ctf_field_copy(src_length
);
2913 BT_LOGE_STR("Cannot copy sequence field's length field.");
2918 /* this will initialize the destination sequence's internal array */
2919 ret
= bt_ctf_field_sequence_set_length(dst
, dst_length
);
2922 BT_LOGE("Cannot set sequence field copy's length field: "
2923 "dst-length-field-addr=%p", dst_length
);
2928 assert(sequence_dst
->elements
->len
== sequence_src
->elements
->len
);
2930 for (i
= 0; i
< sequence_src
->elements
->len
; i
++) {
2931 struct bt_ctf_field
*field
=
2932 g_ptr_array_index(sequence_src
->elements
, i
);
2933 struct bt_ctf_field
*field_copy
= NULL
;
2936 BT_LOGD("Copying sequence field's element field: field-addr=%p, "
2937 "index=%" PRId64
, field
, i
);
2938 field_copy
= bt_ctf_field_copy(field
);
2940 BT_LOGE("Cannot copy sequence field's element field: "
2941 "src-field-addr=%p, index=%" PRId64
,
2948 g_ptr_array_index(sequence_dst
->elements
, i
) = field_copy
;
2951 BT_LOGD_STR("Copied sequence field.");
2958 int bt_ctf_field_string_copy(struct bt_ctf_field
*src
,
2959 struct bt_ctf_field
*dst
)
2962 struct bt_ctf_field_string
*string_src
, *string_dst
;
2964 BT_LOGD("Copying string field: src-field-addr=%p, dst-field-addr=%p",
2966 string_src
= container_of(src
, struct bt_ctf_field_string
, parent
);
2967 string_dst
= container_of(dst
, struct bt_ctf_field_string
, parent
);
2969 if (string_src
->payload
) {
2970 string_dst
->payload
= g_string_new(string_src
->payload
->str
);
2971 if (!string_dst
->payload
) {
2972 BT_LOGE_STR("Failed to allocate a GString.");
2978 BT_LOGD_STR("Copied string field.");
2985 int increase_packet_size(struct bt_ctf_stream_pos
*pos
)
2990 BT_LOGV("Increasing packet size: pos-offset=%" PRId64
", "
2991 "cur-packet-size=%" PRIu64
,
2992 pos
->offset
, pos
->packet_size
);
2993 ret
= munmap_align(pos
->base_mma
);
2995 BT_LOGE("Failed to perform an aligned memory unmapping: "
2996 "ret=%d, errno=%d", ret
, errno
);
3000 pos
->packet_size
+= PACKET_LEN_INCREMENT
;
3002 ret
= bt_posix_fallocate(pos
->fd
, pos
->mmap_offset
,
3003 pos
->packet_size
/ CHAR_BIT
);
3004 } while (ret
== EINTR
);
3006 BT_LOGE("Failed to preallocate memory space: ret=%d, errno=%d",
3013 pos
->base_mma
= mmap_align(pos
->packet_size
/ CHAR_BIT
, pos
->prot
,
3014 pos
->flags
, pos
->fd
, pos
->mmap_offset
);
3015 if (pos
->base_mma
== MAP_FAILED
) {
3016 BT_LOGE("Failed to perform an aligned memory mapping: "
3017 "ret=%d, errno=%d", ret
, errno
);
3021 BT_LOGV("Increased packet size: pos-offset=%" PRId64
", "
3022 "new-packet-size=%" PRIu64
,
3023 pos
->offset
, pos
->packet_size
);
3029 void generic_field_freeze(struct bt_ctf_field
*field
)
3035 void bt_ctf_field_enumeration_freeze(struct bt_ctf_field
*field
)
3037 struct bt_ctf_field_enumeration
*enum_field
=
3038 container_of(field
, struct bt_ctf_field_enumeration
, parent
);
3040 BT_LOGD("Freezing enumeration field object: addr=%p", field
);
3041 BT_LOGD("Freezing enumeration field object's contained payload field: payload-field-addr=%p", enum_field
->payload
);
3042 bt_ctf_field_freeze(enum_field
->payload
);
3043 generic_field_freeze(field
);
3047 void bt_ctf_field_structure_freeze(struct bt_ctf_field
*field
)
3050 struct bt_ctf_field_structure
*structure_field
=
3051 container_of(field
, struct bt_ctf_field_structure
, parent
);
3053 BT_LOGD("Freezing structure field object: addr=%p", field
);
3055 for (i
= 0; i
< structure_field
->fields
->len
; i
++) {
3056 struct bt_ctf_field
*field
=
3057 g_ptr_array_index(structure_field
->fields
, i
);
3059 BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64
,
3061 bt_ctf_field_freeze(field
);
3064 generic_field_freeze(field
);
3068 void bt_ctf_field_variant_freeze(struct bt_ctf_field
*field
)
3070 struct bt_ctf_field_variant
*variant_field
=
3071 container_of(field
, struct bt_ctf_field_variant
, parent
);
3073 BT_LOGD("Freezing variant field object: addr=%p", field
);
3074 BT_LOGD("Freezing variant field object's tag field: tag-field-addr=%p", variant_field
->tag
);
3075 bt_ctf_field_freeze(variant_field
->tag
);
3076 BT_LOGD("Freezing variant field object's payload field: payload-field-addr=%p", variant_field
->payload
);
3077 bt_ctf_field_freeze(variant_field
->payload
);
3078 generic_field_freeze(field
);
3082 void bt_ctf_field_array_freeze(struct bt_ctf_field
*field
)
3085 struct bt_ctf_field_array
*array_field
=
3086 container_of(field
, struct bt_ctf_field_array
, parent
);
3088 BT_LOGD("Freezing array field object: addr=%p", field
);
3090 for (i
= 0; i
< array_field
->elements
->len
; i
++) {
3091 struct bt_ctf_field
*elem_field
=
3092 g_ptr_array_index(array_field
->elements
, i
);
3094 BT_LOGD("Freezing array field object's element field: "
3095 "element-field-addr=%p, index=%" PRId64
,
3097 bt_ctf_field_freeze(elem_field
);
3100 generic_field_freeze(field
);
3104 void bt_ctf_field_sequence_freeze(struct bt_ctf_field
*field
)
3107 struct bt_ctf_field_sequence
*sequence_field
=
3108 container_of(field
, struct bt_ctf_field_sequence
, parent
);
3110 BT_LOGD("Freezing sequence field object: addr=%p", field
);
3111 BT_LOGD("Freezing sequence field object's length field: length-field-addr=%p",
3112 sequence_field
->length
);
3113 bt_ctf_field_freeze(sequence_field
->length
);
3115 for (i
= 0; i
< sequence_field
->elements
->len
; i
++) {
3116 struct bt_ctf_field
*elem_field
=
3117 g_ptr_array_index(sequence_field
->elements
, i
);
3119 BT_LOGD("Freezing sequence field object's element field: "
3120 "element-field-addr=%p, index=%" PRId64
,
3122 bt_ctf_field_freeze(elem_field
);
3125 generic_field_freeze(field
);
3129 void bt_ctf_field_freeze(struct bt_ctf_field
*field
)
3131 enum bt_ctf_field_type_id type_id
;
3137 if (field
->frozen
) {
3141 BT_LOGD("Freezing field object: addr=%p", field
);
3142 type_id
= bt_ctf_field_get_type_id(field
);
3143 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
3144 type_id
< BT_CTF_NR_TYPE_IDS
);
3145 field_freeze_funcs
[type_id
](field
);
3151 bt_bool
bt_ctf_field_generic_is_set(struct bt_ctf_field
*field
)
3153 return field
&& field
->payload_set
;
3157 bt_bool
bt_ctf_field_enumeration_is_set(struct bt_ctf_field
*field
)
3159 bt_bool is_set
= BT_FALSE
;
3160 struct bt_ctf_field_enumeration
*enumeration
;
3166 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
3168 if (!enumeration
->payload
) {
3172 is_set
= bt_ctf_field_is_set(enumeration
->payload
);
3178 bt_bool
bt_ctf_field_structure_is_set(struct bt_ctf_field
*field
)
3180 bt_bool is_set
= BT_FALSE
;
3182 struct bt_ctf_field_structure
*structure
;
3188 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
3189 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3190 is_set
= bt_ctf_field_is_set(structure
->fields
->pdata
[i
]);
3200 bt_bool
bt_ctf_field_variant_is_set(struct bt_ctf_field
*field
)
3202 bt_bool is_set
= BT_FALSE
;
3203 struct bt_ctf_field_variant
*variant
;
3209 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
3210 is_set
= bt_ctf_field_is_set(variant
->payload
);
3216 bt_bool
bt_ctf_field_array_is_set(struct bt_ctf_field
*field
)
3219 bt_bool is_set
= BT_FALSE
;
3220 struct bt_ctf_field_array
*array
;
3226 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
3227 for (i
= 0; i
< array
->elements
->len
; i
++) {
3228 is_set
= bt_ctf_field_is_set(array
->elements
->pdata
[i
]);
3238 bt_bool
bt_ctf_field_sequence_is_set(struct bt_ctf_field
*field
)
3241 bt_bool is_set
= BT_FALSE
;
3242 struct bt_ctf_field_sequence
*sequence
;
3248 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
3249 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
3250 is_set
= bt_ctf_field_validate(sequence
->elements
->pdata
[i
]);