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 */
564 * Not logging a warning here because the user could
565 * legitimately check if a structure field is set with
566 * this function: if the preconditions are satisfied,
567 * a NULL return value means this.
569 BT_LOGV("Not creating a field because structure field is frozen: "
570 "struct-field-addr=%p, name=\"%s\"", field
, name
);
574 new_field
= bt_ctf_field_create(field_type
);
576 BT_LOGW("Cannot create field: "
577 "struct-field-addr=%p, struct-ft-addr=%p, "
578 "field-ft-addr=%p, name=\"%s\"",
579 field
, field
->type
, field_type
, name
);
583 structure
->fields
->pdata
[index
] = new_field
;
593 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_index(
594 struct bt_ctf_field
*field
, uint64_t index
)
597 const char *field_name
;
598 struct bt_ctf_field_structure
*structure
;
599 struct bt_ctf_field_type
*structure_type
;
600 struct bt_ctf_field_type
*field_type
= NULL
;
601 struct bt_ctf_field
*ret_field
= NULL
;
604 BT_LOGW_STR("Invalid parameter: field is NULL.");
608 if (bt_ctf_field_type_get_type_id(field
->type
) !=
609 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
610 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
611 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
613 bt_ctf_field_type_id_string(field
->type
->id
));
617 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
618 if (index
>= structure
->fields
->len
) {
619 BT_LOGW("Invalid parameter: index is out of bounds: "
620 "addr=%p, index=%" PRIu64
", count=%u",
621 field
, index
, structure
->fields
->len
);
625 ret_field
= structure
->fields
->pdata
[index
];
630 /* We don't want to modify this field if it's frozen */
633 * Not logging a warning here because the user could
634 * legitimately check if a structure field is set with
635 * this function: if the preconditions are satisfied,
636 * a NULL return value means this.
638 BT_LOGV("Not creating a field because structure field is frozen: "
639 "struct-field-addr=%p, index=%" PRIu64
, field
, index
);
643 /* Field has not been instanciated yet, create it */
644 structure_type
= bt_ctf_field_get_type(field
);
645 assert(structure_type
);
646 ret
= bt_ctf_field_type_structure_get_field(structure_type
,
647 &field_name
, &field_type
, index
);
649 bt_put(structure_type
);
650 ret_field
= bt_ctf_field_create(field_type
);
652 BT_LOGW("Cannot create field: "
653 "struct-field-addr=%p, struct-ft-addr=%p, "
654 "field-ft-addr=%p, index=%" PRIu64
,
655 field
, field
->type
, field_type
, index
);
659 structure
->fields
->pdata
[index
] = ret_field
;
667 int bt_ctf_field_structure_set_field(struct bt_ctf_field
*field
,
668 const char *name
, struct bt_ctf_field
*value
)
672 struct bt_ctf_field_structure
*structure
;
673 struct bt_ctf_field_type
*expected_field_type
= NULL
;
677 BT_LOGW_STR("Invalid parameter: structure field is NULL.");
683 BT_LOGW_STR("Invalid parameter: field name is NULL.");
689 BT_LOGW_STR("Invalid parameter: field is NULL.");
694 if (bt_ctf_field_type_get_type_id(field
->type
) !=
695 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
696 BT_LOGW("Invalid parameter: field's type is not a structure field type: "
697 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
699 bt_ctf_field_type_id_string(field
->type
->id
));
704 field_quark
= g_quark_from_string(name
);
705 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
706 expected_field_type
=
707 bt_ctf_field_type_structure_get_field_type_by_name(field
->type
,
710 if (bt_ctf_field_type_compare(expected_field_type
, value
->type
)) {
711 BT_LOGW("Invalid parameter: field type of field to set is different from the expected field type: "
712 "struct-field-addr=%p, field-addr=%p, "
713 "field-ft-addr=%p, expected-ft-addr=%p",
714 field
, value
, value
->type
, expected_field_type
);
719 if (!g_hash_table_lookup_extended(structure
->field_name_to_index
,
720 GUINT_TO_POINTER(field_quark
), NULL
, (gpointer
*) &index
)) {
721 BT_LOGV("Invalid parameter: no such field in structure field's type: "
722 "struct-field-addr=%p, struct-ft-addr=%p, "
723 "field-ft-addr=%p, name=\"%s\"",
724 field
, field
->type
, value
->type
, name
);
729 if (structure
->fields
->pdata
[index
]) {
730 bt_put(structure
->fields
->pdata
[index
]);
733 structure
->fields
->pdata
[index
] = value
;
736 if (expected_field_type
) {
737 bt_put(expected_field_type
);
742 struct bt_ctf_field
*bt_ctf_field_array_get_field(struct bt_ctf_field
*field
,
745 struct bt_ctf_field
*new_field
= NULL
;
746 struct bt_ctf_field_type
*field_type
= NULL
;
747 struct bt_ctf_field_array
*array
;
750 BT_LOGW_STR("Invalid parameter: field is NULL.");
754 if (bt_ctf_field_type_get_type_id(field
->type
) !=
755 BT_CTF_FIELD_TYPE_ID_ARRAY
) {
756 BT_LOGW("Invalid parameter: field's type is not an array field type: "
757 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
759 bt_ctf_field_type_id_string(field
->type
->id
));
763 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
764 if (index
>= array
->elements
->len
) {
765 BT_LOGW("Invalid parameter: index is out of bounds: "
766 "addr=%p, index=%" PRIu64
", count=%u",
767 field
, index
, array
->elements
->len
);
771 field_type
= bt_ctf_field_type_array_get_element_type(field
->type
);
772 if (array
->elements
->pdata
[(size_t)index
]) {
773 new_field
= array
->elements
->pdata
[(size_t)index
];
777 /* We don't want to modify this field if it's frozen */
780 * Not logging a warning here because the user could
781 * legitimately check if a array field is set with
782 * this function: if the preconditions are satisfied,
783 * a NULL return value means this.
785 BT_LOGV("Not creating a field because array field is frozen: "
786 "array-field-addr=%p, index=%" PRIu64
, field
, index
);
790 new_field
= bt_ctf_field_create(field_type
);
791 array
->elements
->pdata
[(size_t)index
] = new_field
;
802 struct bt_ctf_field
*bt_ctf_field_sequence_get_field(struct bt_ctf_field
*field
,
805 struct bt_ctf_field
*new_field
= NULL
;
806 struct bt_ctf_field_type
*field_type
= NULL
;
807 struct bt_ctf_field_sequence
*sequence
;
810 BT_LOGW_STR("Invalid parameter: field is NULL.");
814 if (bt_ctf_field_type_get_type_id(field
->type
) !=
815 BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
816 BT_LOGW("Invalid parameter: field's type is not a sequence field type: "
817 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
819 bt_ctf_field_type_id_string(field
->type
->id
));
823 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
824 if (!sequence
->elements
) {
825 BT_LOGV("Sequence field's elements do not exist: addr=%p",
830 if (index
>= sequence
->elements
->len
) {
831 BT_LOGW("Invalid parameter: index is out of bounds: "
832 "addr=%p, index=%" PRIu64
", count=%u",
833 field
, index
, sequence
->elements
->len
);
837 field_type
= bt_ctf_field_type_sequence_get_element_type(field
->type
);
838 if (sequence
->elements
->pdata
[(size_t) index
]) {
839 new_field
= sequence
->elements
->pdata
[(size_t) index
];
843 /* We don't want to modify this field if it's frozen */
846 * Not logging a warning here because the user could
847 * legitimately check if a sequence field is set with
848 * this function: if the preconditions are satisfied,
849 * a NULL return value means this.
851 BT_LOGV("Not creating a field because sequence field is frozen: "
852 "sequence-field-addr=%p, index=%" PRIu64
, field
, index
);
856 new_field
= bt_ctf_field_create(field_type
);
857 sequence
->elements
->pdata
[(size_t) index
] = new_field
;
868 struct bt_ctf_field
*bt_ctf_field_variant_get_field(struct bt_ctf_field
*field
,
869 struct bt_ctf_field
*tag_field
)
871 struct bt_ctf_field
*new_field
= NULL
;
872 struct bt_ctf_field_variant
*variant
;
873 struct bt_ctf_field_type_variant
*variant_type
;
874 struct bt_ctf_field_type
*field_type
;
875 struct bt_ctf_field
*tag_enum
= NULL
;
876 struct bt_ctf_field_integer
*tag_enum_integer
;
877 int64_t tag_enum_value
;
880 BT_LOGW_STR("Invalid parameter: field is NULL.");
885 BT_LOGW_STR("Invalid parameter: tag field is NULL.");
889 if (bt_ctf_field_type_get_type_id(field
->type
) !=
890 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
891 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
892 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
894 bt_ctf_field_type_id_string(field
->type
->id
));
898 if (bt_ctf_field_type_get_type_id(tag_field
->type
) !=
899 BT_CTF_FIELD_TYPE_ID_ENUM
) {
900 BT_LOGW("Invalid parameter: tag field's type is not an enumeration field type: "
901 "field-addr=%p, ft-addr=%p, ft-id=%s", tag_field
,
903 bt_ctf_field_type_id_string(tag_field
->type
->id
));
907 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
908 variant_type
= container_of(field
->type
,
909 struct bt_ctf_field_type_variant
, parent
);
910 tag_enum
= bt_ctf_field_enumeration_get_container(tag_field
);
915 tag_enum_integer
= container_of(tag_enum
, struct bt_ctf_field_integer
,
918 if (bt_ctf_field_validate(tag_field
) < 0) {
919 BT_LOGW("Invalid parameter: tag field is invalid: "
920 "variant-field-addr=%p, tag-field-addr=%p",
925 tag_enum_value
= tag_enum_integer
->payload
.signd
;
928 * If the variant currently has a tag and a payload, and if the
929 * requested tag value is the same as the current one, return
930 * the current payload instead of creating a fresh one.
932 if (variant
->tag
&& variant
->payload
) {
933 struct bt_ctf_field
*cur_tag_container
= NULL
;
934 struct bt_ctf_field_integer
*cur_tag_enum_integer
;
935 int64_t cur_tag_value
;
938 bt_ctf_field_enumeration_get_container(variant
->tag
);
939 assert(cur_tag_container
);
940 cur_tag_enum_integer
= container_of(cur_tag_container
,
941 struct bt_ctf_field_integer
, parent
);
942 bt_put(cur_tag_container
);
943 cur_tag_value
= cur_tag_enum_integer
->payload
.signd
;
945 if (cur_tag_value
== tag_enum_value
) {
946 new_field
= variant
->payload
;
952 /* We don't want to modify this field if it's frozen */
955 * Not logging a warning here because the user could
956 * legitimately check if a variant field is set with
957 * this function: if the preconditions are satisfied,
958 * a NULL return value means this.
960 BT_LOGV("Not creating a field because variant field is frozen: "
961 "variant-field-addr=%p, tag-field-addr=%p",
966 field_type
= bt_ctf_field_type_variant_get_field_type_signed(
967 variant_type
, tag_enum_value
);
969 BT_LOGW("Cannot get variant field type's field: "
970 "variant-field-addr=%p, variant-ft-addr=%p, "
971 "tag-value-signed=%" PRId64
,
972 field
, variant_type
, tag_enum_value
);
976 new_field
= bt_ctf_field_create(field_type
);
978 BT_LOGW("Cannot create field: "
979 "variant-field-addr=%p, variant-ft-addr=%p, "
980 "field-ft-addr=%p", field
, field
->type
, field_type
);
984 bt_put(variant
->tag
);
985 bt_put(variant
->payload
);
988 variant
->tag
= tag_field
;
989 variant
->payload
= new_field
;
995 struct bt_ctf_field
*bt_ctf_field_variant_get_current_field(
996 struct bt_ctf_field
*variant_field
)
998 struct bt_ctf_field
*current_field
= NULL
;
999 struct bt_ctf_field_variant
*variant
;
1001 if (!variant_field
) {
1002 BT_LOGW_STR("Invalid parameter: field is NULL.");
1006 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
1007 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
1008 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
1009 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
1010 variant_field
->type
,
1011 bt_ctf_field_type_id_string(variant_field
->type
->id
));
1015 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
1018 if (variant
->payload
) {
1019 current_field
= variant
->payload
;
1020 bt_get(current_field
);
1025 return current_field
;
1028 struct bt_ctf_field
*bt_ctf_field_variant_get_tag(
1029 struct bt_ctf_field
*variant_field
)
1031 struct bt_ctf_field
*tag
= NULL
;
1032 struct bt_ctf_field_variant
*variant
;
1034 if (!variant_field
) {
1035 BT_LOGW_STR("Invalid parameter: field is NULL.");
1039 if (bt_ctf_field_type_get_type_id(variant_field
->type
) !=
1040 BT_CTF_FIELD_TYPE_ID_VARIANT
) {
1041 BT_LOGW("Invalid parameter: field's type is not a variant field type: "
1042 "field-addr=%p, ft-addr=%p, ft-id=%s", variant_field
,
1043 variant_field
->type
,
1044 bt_ctf_field_type_id_string(variant_field
->type
->id
));
1048 variant
= container_of(variant_field
, struct bt_ctf_field_variant
,
1051 tag
= bt_get(variant
->tag
);
1057 struct bt_ctf_field
*bt_ctf_field_enumeration_get_container(
1058 struct bt_ctf_field
*field
)
1060 struct bt_ctf_field
*container
= NULL
;
1061 struct bt_ctf_field_enumeration
*enumeration
;
1064 BT_LOGW_STR("Invalid parameter: field is NULL.");
1068 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1069 BT_CTF_FIELD_TYPE_ID_ENUM
) {
1070 BT_LOGW("Invalid parameter: field's type is not an enumeration field type: "
1071 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1073 bt_ctf_field_type_id_string(field
->type
->id
));
1077 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
1079 if (!enumeration
->payload
) {
1080 /* We don't want to modify this field if it's frozen */
1081 if (field
->frozen
) {
1083 * Not logging a warning here because the user
1084 * could legitimately check if an enumeration's
1085 * container field is set with this function: if
1086 * the preconditions are satisfied, a NULL
1087 * return value means this.
1089 BT_LOGV("Not creating a field because enumeration field is frozen: "
1090 "enum-field-addr=%p", field
);
1094 struct bt_ctf_field_type_enumeration
*enumeration_type
=
1095 container_of(field
->type
,
1096 struct bt_ctf_field_type_enumeration
, parent
);
1097 enumeration
->payload
=
1098 bt_ctf_field_create(enumeration_type
->container
);
1101 container
= enumeration
->payload
;
1107 struct bt_ctf_field_type_enumeration_mapping_iterator
*
1108 bt_ctf_field_enumeration_get_mappings(struct bt_ctf_field
*field
)
1111 struct bt_ctf_field
*container
= NULL
;
1112 struct bt_ctf_field_type
*container_type
= NULL
;
1113 struct bt_ctf_field_type_integer
*integer_type
= NULL
;
1114 struct bt_ctf_field_type_enumeration_mapping_iterator
*iter
= NULL
;
1116 container
= bt_ctf_field_enumeration_get_container(field
);
1118 BT_LOGW("Invalid parameter: enumeration field has no container field: "
1123 container_type
= bt_ctf_field_get_type(container
);
1124 assert(container_type
);
1125 integer_type
= container_of(container_type
,
1126 struct bt_ctf_field_type_integer
, parent
);
1128 if (!integer_type
->is_signed
) {
1131 ret
= bt_ctf_field_unsigned_integer_get_value(container
,
1134 BT_LOGW("Cannot get value from signed enumeration field's payload field: "
1135 "enum-field-addr=%p, payload-field-addr=%p",
1137 goto error_put_container_type
;
1139 iter
= bt_ctf_field_type_enumeration_find_mappings_by_unsigned_value(
1140 field
->type
, value
);
1144 ret
= bt_ctf_field_signed_integer_get_value(container
,
1147 BT_LOGW("Cannot get value from unsigned enumeration field's payload field: "
1148 "enum-field-addr=%p, payload-field-addr=%p",
1150 goto error_put_container_type
;
1152 iter
= bt_ctf_field_type_enumeration_find_mappings_by_signed_value(
1153 field
->type
, value
);
1156 error_put_container_type
:
1157 bt_put(container_type
);
1163 int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field
*field
,
1167 struct bt_ctf_field_integer
*integer
;
1168 struct bt_ctf_field_type_integer
*integer_type
;
1171 BT_LOGW_STR("Invalid parameter: field is NULL.");
1177 BT_LOGW_STR("Invalid parameter: value is NULL.");
1182 if (!field
->payload_set
) {
1183 BT_LOGV("Field's payload is not set: addr=%p", field
);
1188 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1189 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1190 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1191 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1193 bt_ctf_field_type_id_string(field
->type
->id
));
1198 integer_type
= container_of(field
->type
,
1199 struct bt_ctf_field_type_integer
, parent
);
1200 if (!integer_type
->is_signed
) {
1201 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1202 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1207 integer
= container_of(field
,
1208 struct bt_ctf_field_integer
, parent
);
1209 *value
= integer
->payload
.signd
;
1214 int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field
*field
,
1218 struct bt_ctf_field_integer
*integer
;
1219 struct bt_ctf_field_type_integer
*integer_type
;
1221 int64_t min_value
, max_value
;
1224 BT_LOGW_STR("Invalid parameter: field is NULL.");
1229 if (field
->frozen
) {
1230 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1236 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1237 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1238 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1239 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1241 bt_ctf_field_type_id_string(field
->type
->id
));
1246 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1247 integer_type
= container_of(field
->type
,
1248 struct bt_ctf_field_type_integer
, parent
);
1249 if (!integer_type
->is_signed
) {
1250 BT_LOGW("Invalid parameter: integer field's type is not signed: "
1251 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1256 size
= integer_type
->size
;
1257 min_value
= -(1ULL << (size
- 1));
1258 max_value
= (1ULL << (size
- 1)) - 1;
1259 if (value
< min_value
|| value
> max_value
) {
1260 BT_LOGW("Invalid parameter: value is out of bounds: "
1261 "addr=%p, value=%" PRId64
", "
1262 "min-value=%" PRId64
", max-value=%" PRId64
,
1263 field
, value
, min_value
, max_value
);
1268 integer
->payload
.signd
= value
;
1269 integer
->parent
.payload_set
= 1;
1274 int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field
*field
,
1278 struct bt_ctf_field_integer
*integer
;
1279 struct bt_ctf_field_type_integer
*integer_type
;
1282 BT_LOGW_STR("Invalid parameter: field is NULL.");
1288 BT_LOGW_STR("Invalid parameter: value is NULL.");
1293 if (!field
->payload_set
) {
1294 BT_LOGV("Field's payload is not set: addr=%p", field
);
1299 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1300 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1301 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1302 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1304 bt_ctf_field_type_id_string(field
->type
->id
));
1309 integer_type
= container_of(field
->type
,
1310 struct bt_ctf_field_type_integer
, parent
);
1311 if (integer_type
->is_signed
) {
1312 BT_LOGW("Invalid parameter: integer field's type is signed: "
1313 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1318 integer
= container_of(field
,
1319 struct bt_ctf_field_integer
, parent
);
1320 *value
= integer
->payload
.unsignd
;
1325 int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field
*field
,
1329 struct bt_ctf_field_integer
*integer
;
1330 struct bt_ctf_field_type_integer
*integer_type
;
1335 BT_LOGW_STR("Invalid parameter: field is NULL.");
1340 if (field
->frozen
) {
1341 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1347 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1348 BT_CTF_FIELD_TYPE_ID_INTEGER
) {
1349 BT_LOGW("Invalid parameter: field's type is not an integer field type: "
1350 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1352 bt_ctf_field_type_id_string(field
->type
->id
));
1357 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1358 integer_type
= container_of(field
->type
,
1359 struct bt_ctf_field_type_integer
, parent
);
1360 if (integer_type
->is_signed
) {
1361 BT_LOGW("Invalid parameter: integer field's type is signed: "
1362 "field-addr=%p, ft-addr=%p", field
, field
->type
);
1367 size
= integer_type
->size
;
1368 max_value
= (size
== 64) ? UINT64_MAX
: ((uint64_t) 1 << size
) - 1;
1369 if (value
> max_value
) {
1370 BT_LOGW("Invalid parameter: value is out of bounds: "
1371 "addr=%p, value=%" PRIu64
", "
1372 "min-value=%" PRIu64
", max-value=%" PRIu64
,
1373 field
, value
, (uint64_t) 0, max_value
);
1378 integer
->payload
.unsignd
= value
;
1379 integer
->parent
.payload_set
= 1;
1384 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field
*field
,
1388 struct bt_ctf_field_floating_point
*floating_point
;
1391 BT_LOGW_STR("Invalid parameter: field is NULL.");
1397 BT_LOGW_STR("Invalid parameter: value is NULL.");
1402 if (!field
->payload_set
) {
1403 BT_LOGV("Field's payload is not set: addr=%p", field
);
1408 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1409 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1410 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1411 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1413 bt_ctf_field_type_id_string(field
->type
->id
));
1418 floating_point
= container_of(field
,
1419 struct bt_ctf_field_floating_point
, parent
);
1420 *value
= floating_point
->payload
;
1425 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field
*field
,
1429 struct bt_ctf_field_floating_point
*floating_point
;
1432 BT_LOGW_STR("Invalid parameter: field is NULL.");
1437 if (field
->frozen
) {
1438 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1444 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1445 BT_CTF_FIELD_TYPE_ID_FLOAT
) {
1446 BT_LOGW("Invalid parameter: field's type is not a floating point number field type: "
1447 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1449 bt_ctf_field_type_id_string(field
->type
->id
));
1454 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
1456 floating_point
->payload
= value
;
1457 floating_point
->parent
.payload_set
= 1;
1462 const char *bt_ctf_field_string_get_value(struct bt_ctf_field
*field
)
1464 const char *ret
= NULL
;
1465 struct bt_ctf_field_string
*string
;
1468 BT_LOGW_STR("Invalid parameter: field is NULL.");
1472 if (!field
->payload_set
) {
1473 BT_LOGV("Field's payload is not set: addr=%p", field
);
1477 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1478 BT_CTF_FIELD_TYPE_ID_STRING
) {
1479 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1480 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1482 bt_ctf_field_type_id_string(field
->type
->id
));
1486 string
= container_of(field
,
1487 struct bt_ctf_field_string
, parent
);
1488 ret
= string
->payload
->str
;
1493 int bt_ctf_field_string_set_value(struct bt_ctf_field
*field
,
1497 struct bt_ctf_field_string
*string
;
1500 BT_LOGW_STR("Invalid parameter: field is NULL.");
1506 BT_LOGW_STR("Invalid parameter: value is NULL.");
1511 if (field
->frozen
) {
1512 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1518 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1519 BT_CTF_FIELD_TYPE_ID_STRING
) {
1520 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1521 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1523 bt_ctf_field_type_id_string(field
->type
->id
));
1528 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
1529 if (string
->payload
) {
1530 g_string_assign(string
->payload
, value
);
1532 string
->payload
= g_string_new(value
);
1535 string
->parent
.payload_set
= 1;
1540 int bt_ctf_field_string_append(struct bt_ctf_field
*field
,
1544 struct bt_ctf_field_string
*string_field
;
1547 BT_LOGW_STR("Invalid parameter: field is NULL.");
1553 BT_LOGW_STR("Invalid parameter: value is NULL.");
1558 if (field
->frozen
) {
1559 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1565 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1566 BT_CTF_FIELD_TYPE_ID_STRING
) {
1567 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1568 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1570 bt_ctf_field_type_id_string(field
->type
->id
));
1575 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1577 if (string_field
->payload
) {
1578 g_string_append(string_field
->payload
, value
);
1580 string_field
->payload
= g_string_new(value
);
1583 string_field
->parent
.payload_set
= 1;
1589 int bt_ctf_field_string_append_len(struct bt_ctf_field
*field
,
1590 const char *value
, unsigned int length
)
1594 unsigned int effective_length
= length
;
1595 struct bt_ctf_field_string
*string_field
;
1598 BT_LOGW_STR("Invalid parameter: field is NULL.");
1604 BT_LOGW_STR("Invalid parameter: value is NULL.");
1609 if (field
->frozen
) {
1610 BT_LOGW("Invalid parameter: field is frozen: addr=%p",
1616 if (bt_ctf_field_type_get_type_id(field
->type
) !=
1617 BT_CTF_FIELD_TYPE_ID_STRING
) {
1618 BT_LOGW("Invalid parameter: field's type is not a string field type: "
1619 "field-addr=%p, ft-addr=%p, ft-id=%s", field
,
1621 bt_ctf_field_type_id_string(field
->type
->id
));
1626 string_field
= container_of(field
, struct bt_ctf_field_string
, parent
);
1628 /* make sure no null bytes are appended */
1629 for (i
= 0; i
< length
; ++i
) {
1630 if (value
[i
] == '\0') {
1631 effective_length
= i
;
1636 if (string_field
->payload
) {
1637 g_string_append_len(string_field
->payload
, value
,
1640 string_field
->payload
= g_string_new_len(value
,
1644 string_field
->parent
.payload_set
= 1;
1651 int bt_ctf_field_validate(struct bt_ctf_field
*field
)
1654 enum bt_ctf_field_type_id type_id
;
1657 BT_LOGD_STR("Invalid parameter: field is NULL.");
1662 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1663 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1664 BT_LOGW("Invalid parameter: unknown field type ID: "
1665 "addr=%p, ft-addr=%p, ft-id=%d",
1666 field
, field
->type
, type_id
);
1671 ret
= field_validate_funcs
[type_id
](field
);
1677 int bt_ctf_field_reset(struct bt_ctf_field
*field
)
1680 enum bt_ctf_field_type_id type_id
;
1683 BT_LOGD_STR("Invalid parameter: field is NULL.");
1688 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1689 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1690 BT_LOGW("Invalid parameter: unknown field type ID: "
1691 "addr=%p, ft-addr=%p, ft-id=%d",
1692 field
, field
->type
, type_id
);
1697 ret
= field_reset_funcs
[type_id
](field
);
1703 int bt_ctf_field_serialize(struct bt_ctf_field
*field
,
1704 struct bt_ctf_stream_pos
*pos
,
1705 enum bt_ctf_byte_order native_byte_order
)
1708 enum bt_ctf_field_type_id type_id
;
1713 BT_LOGD_STR("Invalid parameter: field is NULL.");
1718 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1719 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1720 BT_LOGW("Invalid parameter: unknown field type ID: "
1721 "addr=%p, ft-addr=%p, ft-id=%d",
1722 field
, field
->type
, type_id
);
1727 ret
= field_serialize_funcs
[type_id
](field
, pos
, native_byte_order
);
1734 bt_bool
bt_ctf_field_is_set(struct bt_ctf_field
*field
)
1736 bt_bool is_set
= BT_FALSE
;
1737 enum bt_ctf_field_type_id type_id
;
1743 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1744 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1745 BT_LOGW("Invalid parameter: unknown field type ID: "
1746 "field-addr=%p, ft-addr=%p, ft-id=%d",
1747 field
, field
->type
, type_id
);
1751 is_set
= field_is_set_funcs
[type_id
](field
);
1756 struct bt_ctf_field
*bt_ctf_field_copy(struct bt_ctf_field
*field
)
1759 struct bt_ctf_field
*copy
= NULL
;
1760 enum bt_ctf_field_type_id type_id
;
1763 BT_LOGW_STR("Invalid parameter: field is NULL.");
1767 type_id
= bt_ctf_field_type_get_type_id(field
->type
);
1768 if (type_id
<= BT_CTF_FIELD_TYPE_ID_UNKNOWN
|| type_id
>= BT_CTF_NR_TYPE_IDS
) {
1769 BT_LOGW("Invalid parameter: unknown field type ID: "
1770 "field-addr=%p, ft-addr=%p, ft-id=%d",
1771 field
, field
->type
, type_id
);
1775 copy
= bt_ctf_field_create(field
->type
);
1777 BT_LOGW("Cannot create field: ft-addr=%p", field
->type
);
1781 copy
->payload_set
= field
->payload_set
;
1782 ret
= field_copy_funcs
[type_id
](field
, copy
);
1792 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*type
)
1794 struct bt_ctf_field_integer
*integer
= g_new0(
1795 struct bt_ctf_field_integer
, 1);
1797 BT_LOGD("Creating integer field object: ft-addr=%p", type
);
1800 BT_LOGD("Created integer field object: addr=%p, ft-addr=%p",
1801 &integer
->parent
, type
);
1803 BT_LOGE_STR("Failed to allocate one integer field.");
1806 return integer
? &integer
->parent
: NULL
;
1810 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
1811 struct bt_ctf_field_type
*type
)
1813 struct bt_ctf_field_enumeration
*enumeration
= g_new0(
1814 struct bt_ctf_field_enumeration
, 1);
1816 BT_LOGD("Creating enumeration field object: ft-addr=%p", type
);
1819 BT_LOGD("Created enumeration field object: addr=%p, ft-addr=%p",
1820 &enumeration
->parent
, type
);
1822 BT_LOGE_STR("Failed to allocate one enumeration field.");
1825 return enumeration
? &enumeration
->parent
: NULL
;
1829 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
1830 struct bt_ctf_field_type
*type
)
1832 struct bt_ctf_field_floating_point
*floating_point
;
1834 BT_LOGD("Creating floating point number field object: ft-addr=%p", type
);
1835 floating_point
= g_new0(struct bt_ctf_field_floating_point
, 1);
1837 if (floating_point
) {
1838 BT_LOGD("Created floating point number field object: addr=%p, ft-addr=%p",
1839 &floating_point
->parent
, type
);
1841 BT_LOGE_STR("Failed to allocate one floating point number field.");
1844 return floating_point
? &floating_point
->parent
: NULL
;
1848 struct bt_ctf_field
*bt_ctf_field_structure_create(
1849 struct bt_ctf_field_type
*type
)
1851 struct bt_ctf_field_type_structure
*structure_type
= container_of(type
,
1852 struct bt_ctf_field_type_structure
, parent
);
1853 struct bt_ctf_field_structure
*structure
= g_new0(
1854 struct bt_ctf_field_structure
, 1);
1855 struct bt_ctf_field
*field
= NULL
;
1857 BT_LOGD("Creating structure field object: ft-addr=%p", type
);
1860 BT_LOGE_STR("Failed to allocate one structure field.");
1864 structure
->field_name_to_index
= structure_type
->field_name_to_index
;
1865 structure
->fields
= g_ptr_array_new_with_free_func(
1866 (GDestroyNotify
)bt_ctf_field_put
);
1867 g_ptr_array_set_size(structure
->fields
,
1868 g_hash_table_size(structure
->field_name_to_index
));
1869 field
= &structure
->parent
;
1870 BT_LOGD("Created structure field object: addr=%p, ft-addr=%p",
1877 struct bt_ctf_field
*bt_ctf_field_variant_create(struct bt_ctf_field_type
*type
)
1879 struct bt_ctf_field_variant
*variant
= g_new0(
1880 struct bt_ctf_field_variant
, 1);
1882 BT_LOGD("Creating variant field object: ft-addr=%p", type
);
1885 BT_LOGD("Created variant field object: addr=%p, ft-addr=%p",
1886 &variant
->parent
, type
);
1888 BT_LOGE_STR("Failed to allocate one variant field.");
1891 return variant
? &variant
->parent
: NULL
;
1895 struct bt_ctf_field
*bt_ctf_field_array_create(struct bt_ctf_field_type
*type
)
1897 struct bt_ctf_field_array
*array
= g_new0(struct bt_ctf_field_array
, 1);
1898 struct bt_ctf_field_type_array
*array_type
;
1899 unsigned int array_length
;
1901 BT_LOGD("Creating array field object: ft-addr=%p", type
);
1905 BT_LOGE_STR("Failed to allocate one array field.");
1909 array_type
= container_of(type
, struct bt_ctf_field_type_array
, parent
);
1910 array_length
= array_type
->length
;
1911 array
->elements
= g_ptr_array_sized_new(array_length
);
1912 if (!array
->elements
) {
1916 g_ptr_array_set_free_func(array
->elements
,
1917 (GDestroyNotify
)bt_ctf_field_put
);
1918 g_ptr_array_set_size(array
->elements
, array_length
);
1919 BT_LOGD("Created array field object: addr=%p, ft-addr=%p",
1920 &array
->parent
, type
);
1921 return &array
->parent
;
1928 struct bt_ctf_field
*bt_ctf_field_sequence_create(
1929 struct bt_ctf_field_type
*type
)
1931 struct bt_ctf_field_sequence
*sequence
= g_new0(
1932 struct bt_ctf_field_sequence
, 1);
1934 BT_LOGD("Creating sequence field object: ft-addr=%p", type
);
1937 BT_LOGD("Created sequence field object: addr=%p, ft-addr=%p",
1938 &sequence
->parent
, type
);
1940 BT_LOGE_STR("Failed to allocate one sequence field.");
1943 return sequence
? &sequence
->parent
: NULL
;
1947 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*type
)
1949 struct bt_ctf_field_string
*string
= g_new0(
1950 struct bt_ctf_field_string
, 1);
1952 BT_LOGD("Creating string field object: ft-addr=%p", type
);
1955 BT_LOGD("Created string field object: addr=%p, ft-addr=%p",
1956 &string
->parent
, type
);
1958 BT_LOGE_STR("Failed to allocate one string field.");
1961 return string
? &string
->parent
: NULL
;
1965 void bt_ctf_field_destroy(struct bt_object
*obj
)
1967 struct bt_ctf_field
*field
;
1968 struct bt_ctf_field_type
*type
;
1969 enum bt_ctf_field_type_id type_id
;
1971 field
= container_of(obj
, struct bt_ctf_field
, base
);
1973 type_id
= bt_ctf_field_type_get_type_id(type
);
1974 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
1975 type_id
< BT_CTF_NR_TYPE_IDS
);
1976 field_destroy_funcs
[type_id
](field
);
1977 BT_LOGD_STR("Putting field's type.");
1982 void bt_ctf_field_integer_destroy(struct bt_ctf_field
*field
)
1984 struct bt_ctf_field_integer
*integer
;
1990 BT_LOGD("Destroying integer field object: addr=%p", field
);
1991 integer
= container_of(field
, struct bt_ctf_field_integer
, parent
);
1996 void bt_ctf_field_enumeration_destroy(struct bt_ctf_field
*field
)
1998 struct bt_ctf_field_enumeration
*enumeration
;
2004 BT_LOGD("Destroying enumeration field object: addr=%p", field
);
2005 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2007 BT_LOGD_STR("Putting payload field.");
2008 bt_put(enumeration
->payload
);
2009 g_free(enumeration
);
2013 void bt_ctf_field_floating_point_destroy(struct bt_ctf_field
*field
)
2015 struct bt_ctf_field_floating_point
*floating_point
;
2021 BT_LOGD("Destroying floating point number field object: addr=%p", field
);
2022 floating_point
= container_of(field
, struct bt_ctf_field_floating_point
,
2024 g_free(floating_point
);
2028 void bt_ctf_field_structure_destroy(struct bt_ctf_field
*field
)
2030 struct bt_ctf_field_structure
*structure
;
2036 BT_LOGD("Destroying structure field object: addr=%p", field
);
2037 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2038 g_ptr_array_free(structure
->fields
, TRUE
);
2043 void bt_ctf_field_variant_destroy(struct bt_ctf_field
*field
)
2045 struct bt_ctf_field_variant
*variant
;
2051 BT_LOGD("Destroying variant field object: addr=%p", field
);
2052 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2053 BT_LOGD_STR("Putting tag field.");
2054 bt_put(variant
->tag
);
2055 BT_LOGD_STR("Putting payload field.");
2056 bt_put(variant
->payload
);
2061 void bt_ctf_field_array_destroy(struct bt_ctf_field
*field
)
2063 struct bt_ctf_field_array
*array
;
2069 BT_LOGD("Destroying array field object: addr=%p", field
);
2070 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2071 g_ptr_array_free(array
->elements
, TRUE
);
2076 void bt_ctf_field_sequence_destroy(struct bt_ctf_field
*field
)
2078 struct bt_ctf_field_sequence
*sequence
;
2084 BT_LOGD("Destroying sequence field object: addr=%p", field
);
2085 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2086 if (sequence
->elements
) {
2087 g_ptr_array_free(sequence
->elements
, TRUE
);
2089 BT_LOGD_STR("Putting length field.");
2090 bt_put(sequence
->length
);
2095 void bt_ctf_field_string_destroy(struct bt_ctf_field
*field
)
2097 struct bt_ctf_field_string
*string
;
2103 BT_LOGD("Destroying string field object: addr=%p", field
);
2104 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2105 if (string
->payload
) {
2106 g_string_free(string
->payload
, TRUE
);
2112 int bt_ctf_field_generic_validate(struct bt_ctf_field
*field
)
2114 return (field
&& field
->payload_set
) ? 0 : -1;
2118 int bt_ctf_field_enumeration_validate(struct bt_ctf_field
*field
)
2121 struct bt_ctf_field_enumeration
*enumeration
;
2124 BT_LOGD_STR("Invalid parameter: field is NULL.");
2129 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2131 if (!enumeration
->payload
) {
2132 BT_LOGW("Invalid enumeration field: payload is not set: "
2138 ret
= bt_ctf_field_validate(enumeration
->payload
);
2144 int bt_ctf_field_structure_validate(struct bt_ctf_field
*field
)
2148 struct bt_ctf_field_structure
*structure
;
2151 BT_LOGD_STR("Invalid parameter: field is NULL.");
2156 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2157 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2158 struct bt_ctf_field
*entry_field
= structure
->fields
->pdata
[i
];
2159 ret
= bt_ctf_field_validate(entry_field
);
2164 struct bt_ctf_field_type
*field_type
=
2165 bt_ctf_field_get_type(field
);
2167 this_ret
= bt_ctf_field_type_structure_get_field(
2168 field_type
, &name
, NULL
, i
);
2169 assert(this_ret
== 0);
2170 BT_LOGW("Invalid structure field's field: "
2171 "struct-field-addr=%p, field-addr=%p, "
2172 "field-name=\"%s\", index=%" PRId64
,
2173 field
, entry_field
, name
, i
);
2183 int bt_ctf_field_variant_validate(struct bt_ctf_field
*field
)
2186 struct bt_ctf_field_variant
*variant
;
2189 BT_LOGD_STR("Invalid parameter: field is NULL.");
2194 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2195 ret
= bt_ctf_field_validate(variant
->payload
);
2197 BT_LOGW("Invalid variant field's payload field: "
2198 "variant-field-addr=%p, variant-payload-field-addr=%p",
2199 field
, variant
->payload
);
2206 int bt_ctf_field_array_validate(struct bt_ctf_field
*field
)
2210 struct bt_ctf_field_array
*array
;
2213 BT_LOGD_STR("Invalid parameter: field is NULL.");
2218 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2219 for (i
= 0; i
< array
->elements
->len
; i
++) {
2220 struct bt_ctf_field
*elem_field
= array
->elements
->pdata
[i
];
2222 ret
= bt_ctf_field_validate(elem_field
);
2224 BT_LOGW("Invalid array field's element field: "
2225 "array-field-addr=%p, field-addr=%p, "
2226 "index=%" PRId64
, field
, elem_field
, i
);
2235 int bt_ctf_field_sequence_validate(struct bt_ctf_field
*field
)
2239 struct bt_ctf_field_sequence
*sequence
;
2242 BT_LOGD_STR("Invalid parameter: field is NULL.");
2247 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2248 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2249 struct bt_ctf_field
*elem_field
= sequence
->elements
->pdata
[i
];
2251 ret
= bt_ctf_field_validate(elem_field
);
2253 BT_LOGW("Invalid sequence field's element field: "
2254 "sequence-field-addr=%p, field-addr=%p, "
2255 "index=%" PRId64
, field
, elem_field
, i
);
2264 int bt_ctf_field_generic_reset(struct bt_ctf_field
*field
)
2269 BT_LOGD_STR("Invalid parameter: field is NULL.");
2274 field
->payload_set
= 0;
2280 int bt_ctf_field_enumeration_reset(struct bt_ctf_field
*field
)
2283 struct bt_ctf_field_enumeration
*enumeration
;
2286 BT_LOGD_STR("Invalid parameter: field is NULL.");
2291 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
2293 if (!enumeration
->payload
) {
2297 ret
= bt_ctf_field_reset(enumeration
->payload
);
2303 int bt_ctf_field_structure_reset(struct bt_ctf_field
*field
)
2307 struct bt_ctf_field_structure
*structure
;
2310 BT_LOGD_STR("Invalid parameter: field is NULL.");
2315 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
2316 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2317 struct bt_ctf_field
*member
= structure
->fields
->pdata
[i
];
2321 * Structure members are lazily initialized; skip if
2322 * this member has not been allocated yet.
2327 ret
= bt_ctf_field_reset(member
);
2329 BT_LOGE("Failed to reset structure field's field: "
2330 "struct-field-addr=%p, field-addr=%p, "
2331 "index=%" PRId64
, field
, member
, i
);
2340 int bt_ctf_field_variant_reset(struct bt_ctf_field
*field
)
2343 struct bt_ctf_field_variant
*variant
;
2346 BT_LOGD_STR("Invalid parameter: field is NULL.");
2351 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
2352 if (variant
->payload
) {
2353 ret
= bt_ctf_field_reset(variant
->payload
);
2355 BT_LOGW("Failed to reset variant field's payload field: "
2356 "variant-field-addr=%p, payload-field-addr=%p",
2357 field
, variant
->payload
);
2365 int bt_ctf_field_array_reset(struct bt_ctf_field
*field
)
2369 struct bt_ctf_field_array
*array
;
2372 BT_LOGD_STR("Invalid parameter: field is NULL.");
2377 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
2378 for (i
= 0; i
< array
->elements
->len
; i
++) {
2379 struct bt_ctf_field
*member
= array
->elements
->pdata
[i
];
2383 * Array elements are lazily initialized; skip if
2384 * this member has not been allocated yet.
2389 ret
= bt_ctf_field_reset(member
);
2391 BT_LOGE("Failed to reset array field's field: "
2392 "array-field-addr=%p, field-addr=%p, "
2393 "index=%" PRId64
, field
, member
, i
);
2402 int bt_ctf_field_sequence_reset(struct bt_ctf_field
*field
)
2406 struct bt_ctf_field_sequence
*sequence
;
2409 BT_LOGD_STR("Invalid parameter: field is NULL.");
2414 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
2415 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2416 struct bt_ctf_field
*member
= sequence
->elements
->pdata
[i
];
2420 * Sequence elements are lazily initialized; skip if
2421 * this member has not been allocated yet.
2426 ret
= bt_ctf_field_reset(member
);
2428 BT_LOGE("Failed to reset sequence field's field: "
2429 "sequence-field-addr=%p, field-addr=%p, "
2430 "index=%" PRId64
, field
, member
, i
);
2439 int bt_ctf_field_string_reset(struct bt_ctf_field
*field
)
2442 struct bt_ctf_field_string
*string
;
2445 BT_LOGD_STR("Invalid parameter: field is NULL.");
2450 ret
= bt_ctf_field_generic_reset(field
);
2455 string
= container_of(field
, struct bt_ctf_field_string
, parent
);
2456 if (string
->payload
) {
2457 g_string_truncate(string
->payload
, 0);
2464 int bt_ctf_field_integer_serialize(struct bt_ctf_field
*field
,
2465 struct bt_ctf_stream_pos
*pos
,
2466 enum bt_ctf_byte_order native_byte_order
)
2469 struct bt_ctf_field_integer
*integer
= container_of(field
,
2470 struct bt_ctf_field_integer
, parent
);
2472 BT_LOGV("Serializing integer field: addr=%p, pos-offset=%" PRId64
", "
2473 "native-bo=%s", field
, pos
->offset
,
2474 bt_ctf_byte_order_string(native_byte_order
));
2476 if (!bt_ctf_field_generic_is_set(field
)) {
2477 BT_LOGW_STR("Field's payload is not set.");
2482 ret
= bt_ctf_field_integer_write(integer
, pos
, native_byte_order
);
2483 if (ret
== -EFAULT
) {
2485 * The field is too large to fit in the current packet's
2486 * remaining space. Bump the packet size and retry.
2488 ret
= increase_packet_size(pos
);
2490 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2500 int bt_ctf_field_enumeration_serialize(struct bt_ctf_field
*field
,
2501 struct bt_ctf_stream_pos
*pos
,
2502 enum bt_ctf_byte_order native_byte_order
)
2504 struct bt_ctf_field_enumeration
*enumeration
= container_of(
2505 field
, struct bt_ctf_field_enumeration
, parent
);
2507 BT_LOGV("Serializing enumeration field: addr=%p, pos-offset=%" PRId64
", "
2508 "native-bo=%s", field
, pos
->offset
,
2509 bt_ctf_byte_order_string(native_byte_order
));
2510 BT_LOGV_STR("Serializing enumeration field's payload field.");
2511 return bt_ctf_field_serialize(enumeration
->payload
, pos
,
2516 int bt_ctf_field_floating_point_serialize(struct bt_ctf_field
*field
,
2517 struct bt_ctf_stream_pos
*pos
,
2518 enum bt_ctf_byte_order native_byte_order
)
2521 struct bt_ctf_field_floating_point
*floating_point
= container_of(field
,
2522 struct bt_ctf_field_floating_point
, parent
);
2524 BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64
", "
2525 "native-bo=%s", field
, pos
->offset
,
2526 bt_ctf_byte_order_string(native_byte_order
));
2528 if (!bt_ctf_field_generic_is_set(field
)) {
2529 BT_LOGW_STR("Field's payload is not set.");
2534 ret
= bt_ctf_field_floating_point_write(floating_point
, pos
,
2536 if (ret
== -EFAULT
) {
2538 * The field is too large to fit in the current packet's
2539 * remaining space. Bump the packet size and retry.
2541 ret
= increase_packet_size(pos
);
2543 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2553 int bt_ctf_field_structure_serialize(struct bt_ctf_field
*field
,
2554 struct bt_ctf_stream_pos
*pos
,
2555 enum bt_ctf_byte_order native_byte_order
)
2559 struct bt_ctf_field_structure
*structure
= container_of(
2560 field
, struct bt_ctf_field_structure
, parent
);
2562 BT_LOGV("Serializing structure field: addr=%p, pos-offset=%" PRId64
", "
2563 "native-bo=%s", field
, pos
->offset
,
2564 bt_ctf_byte_order_string(native_byte_order
));
2566 while (!bt_ctf_stream_pos_access_ok(pos
,
2567 offset_align(pos
->offset
, field
->type
->alignment
))) {
2568 ret
= increase_packet_size(pos
);
2570 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
2575 if (!bt_ctf_stream_pos_align(pos
, field
->type
->alignment
)) {
2576 BT_LOGE("Cannot align packet's position: pos-offset=%" PRId64
", "
2577 "align=%u", pos
->offset
, field
->type
->alignment
);
2582 for (i
= 0; i
< structure
->fields
->len
; i
++) {
2583 struct bt_ctf_field
*member
= g_ptr_array_index(
2584 structure
->fields
, i
);
2585 const char *field_name
= NULL
;
2587 if (BT_LOG_ON_WARN
) {
2588 ret
= bt_ctf_field_type_structure_get_field(
2589 field
->type
, &field_name
, NULL
, i
);
2593 BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64
", "
2594 "field-addr=%p, index=%" PRId64
,
2595 pos
->offset
, member
, i
);
2598 BT_LOGW("Cannot serialize structure field's field: field is not set: "
2599 "struct-field-addr=%p, "
2600 "field-name=\"%s\", index=%" PRId64
,
2601 field
, field_name
, i
);
2606 ret
= bt_ctf_field_serialize(member
, pos
, native_byte_order
);
2608 BT_LOGW("Cannot serialize structure field's field: "
2609 "struct-field-addr=%p, field-addr=%p, "
2610 "field-name=\"%s\", index=%" PRId64
,
2611 field
->type
, member
, field_name
, i
);
2620 int bt_ctf_field_variant_serialize(struct bt_ctf_field
*field
,
2621 struct bt_ctf_stream_pos
*pos
,
2622 enum bt_ctf_byte_order native_byte_order
)
2624 struct bt_ctf_field_variant
*variant
= container_of(
2625 field
, struct bt_ctf_field_variant
, parent
);
2627 BT_LOGV("Serializing variant field: addr=%p, pos-offset=%" PRId64
", "
2628 "native-bo=%s", field
, pos
->offset
,
2629 bt_ctf_byte_order_string(native_byte_order
));
2630 BT_LOGV_STR("Serializing variant field's payload field.");
2631 return bt_ctf_field_serialize(variant
->payload
, pos
,
2636 int bt_ctf_field_array_serialize(struct bt_ctf_field
*field
,
2637 struct bt_ctf_stream_pos
*pos
,
2638 enum bt_ctf_byte_order native_byte_order
)
2642 struct bt_ctf_field_array
*array
= container_of(
2643 field
, struct bt_ctf_field_array
, parent
);
2645 BT_LOGV("Serializing array field: addr=%p, pos-offset=%" PRId64
", "
2646 "native-bo=%s", field
, pos
->offset
,
2647 bt_ctf_byte_order_string(native_byte_order
));
2649 for (i
= 0; i
< array
->elements
->len
; i
++) {
2650 struct bt_ctf_field
*elem_field
=
2651 g_ptr_array_index(array
->elements
, i
);
2653 BT_LOGV("Serializing array field's element field: "
2654 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2655 pos
->offset
, elem_field
, i
);
2656 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2659 BT_LOGW("Cannot serialize array field's element field: "
2660 "array-field-addr=%p, field-addr=%p, "
2661 "index=%" PRId64
, field
, elem_field
, i
);
2670 int bt_ctf_field_sequence_serialize(struct bt_ctf_field
*field
,
2671 struct bt_ctf_stream_pos
*pos
,
2672 enum bt_ctf_byte_order native_byte_order
)
2676 struct bt_ctf_field_sequence
*sequence
= container_of(
2677 field
, struct bt_ctf_field_sequence
, parent
);
2679 BT_LOGV("Serializing sequence field: addr=%p, pos-offset=%" PRId64
", "
2680 "native-bo=%s", field
, pos
->offset
,
2681 bt_ctf_byte_order_string(native_byte_order
));
2683 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
2684 struct bt_ctf_field
*elem_field
=
2685 g_ptr_array_index(sequence
->elements
, i
);
2687 BT_LOGV("Serializing sequence field's element field: "
2688 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
2689 pos
->offset
, elem_field
, i
);
2690 ret
= bt_ctf_field_serialize(elem_field
, pos
,
2693 BT_LOGW("Cannot serialize sequence field's element field: "
2694 "sequence-field-addr=%p, field-addr=%p, "
2695 "index=%" PRId64
, field
, elem_field
, i
);
2704 int bt_ctf_field_string_serialize(struct bt_ctf_field
*field
,
2705 struct bt_ctf_stream_pos
*pos
,
2706 enum bt_ctf_byte_order native_byte_order
)
2710 struct bt_ctf_field_string
*string
= container_of(field
,
2711 struct bt_ctf_field_string
, parent
);
2712 struct bt_ctf_field_type
*character_type
=
2713 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
2714 struct bt_ctf_field
*character
;
2716 BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64
", "
2717 "native-bo=%s", field
, pos
->offset
,
2718 bt_ctf_byte_order_string(native_byte_order
));
2720 BT_LOGV_STR("Creating character field from string field's character field type.");
2721 character
= bt_ctf_field_create(character_type
);
2723 for (i
= 0; i
< string
->payload
->len
+ 1; i
++) {
2724 const uint64_t chr
= (uint64_t) string
->payload
->str
[i
];
2726 ret
= bt_ctf_field_unsigned_integer_set_value(character
, chr
);
2728 BT_LOGW("Cannot set character field's value: "
2729 "pos-offset=%" PRId64
", field-addr=%p, "
2730 "index=%" PRId64
", char-int=%" PRIu64
,
2731 pos
->offset
, character
, i
, chr
);
2735 BT_LOGV("Serializing string field's character field: "
2736 "pos-offset=%" PRId64
", field-addr=%p, "
2737 "index=%" PRId64
", char-int=%" PRIu64
,
2738 pos
->offset
, character
, i
, chr
);
2739 ret
= bt_ctf_field_integer_serialize(character
, pos
,
2742 BT_LOGW_STR("Cannot serialize character field.");
2748 bt_put(character_type
);
2753 int bt_ctf_field_integer_copy(struct bt_ctf_field
*src
,
2754 struct bt_ctf_field
*dst
)
2756 struct bt_ctf_field_integer
*integer_src
, *integer_dst
;
2758 BT_LOGD("Copying integer field: src-field-addr=%p, dst-field-addr=%p",
2760 integer_src
= container_of(src
, struct bt_ctf_field_integer
, parent
);
2761 integer_dst
= container_of(dst
, struct bt_ctf_field_integer
, parent
);
2762 integer_dst
->payload
= integer_src
->payload
;
2763 BT_LOGD_STR("Copied integer field.");
2768 int bt_ctf_field_enumeration_copy(struct bt_ctf_field
*src
,
2769 struct bt_ctf_field
*dst
)
2772 struct bt_ctf_field_enumeration
*enum_src
, *enum_dst
;
2774 BT_LOGD("Copying enumeration field: src-field-addr=%p, dst-field-addr=%p",
2776 enum_src
= container_of(src
, struct bt_ctf_field_enumeration
, parent
);
2777 enum_dst
= container_of(dst
, struct bt_ctf_field_enumeration
, parent
);
2779 if (enum_src
->payload
) {
2780 BT_LOGD_STR("Copying enumeration field's payload field.");
2781 enum_dst
->payload
= bt_ctf_field_copy(enum_src
->payload
);
2782 if (!enum_dst
->payload
) {
2783 BT_LOGE_STR("Cannot copy enumeration field's payload field.");
2789 BT_LOGD_STR("Copied enumeration field.");
2795 int bt_ctf_field_floating_point_copy(
2796 struct bt_ctf_field
*src
, struct bt_ctf_field
*dst
)
2798 struct bt_ctf_field_floating_point
*float_src
, *float_dst
;
2800 BT_LOGD("Copying floating point number field: src-field-addr=%p, dst-field-addr=%p",
2802 float_src
= container_of(src
, struct bt_ctf_field_floating_point
,
2804 float_dst
= container_of(dst
, struct bt_ctf_field_floating_point
,
2806 float_dst
->payload
= float_src
->payload
;
2807 BT_LOGD_STR("Copied floating point number field.");
2812 int bt_ctf_field_structure_copy(struct bt_ctf_field
*src
,
2813 struct bt_ctf_field
*dst
)
2817 struct bt_ctf_field_structure
*struct_src
, *struct_dst
;
2819 BT_LOGD("Copying structure field: src-field-addr=%p, dst-field-addr=%p",
2821 struct_src
= container_of(src
, struct bt_ctf_field_structure
, parent
);
2822 struct_dst
= container_of(dst
, struct bt_ctf_field_structure
, parent
);
2824 /* This field_name_to_index HT is owned by the structure field type */
2825 struct_dst
->field_name_to_index
= struct_src
->field_name_to_index
;
2826 g_ptr_array_set_size(struct_dst
->fields
, struct_src
->fields
->len
);
2828 for (i
= 0; i
< struct_src
->fields
->len
; i
++) {
2829 struct bt_ctf_field
*field
=
2830 g_ptr_array_index(struct_src
->fields
, i
);
2831 struct bt_ctf_field
*field_copy
= NULL
;
2834 BT_LOGD("Copying structure field's field: src-field-addr=%p"
2835 "index=%" PRId64
, field
, i
);
2836 field_copy
= bt_ctf_field_copy(field
);
2838 BT_LOGE("Cannot copy structure field's field: "
2839 "src-field-addr=%p, index=%" PRId64
,
2846 g_ptr_array_index(struct_dst
->fields
, i
) = field_copy
;
2849 BT_LOGD_STR("Copied structure field.");
2856 int bt_ctf_field_variant_copy(struct bt_ctf_field
*src
,
2857 struct bt_ctf_field
*dst
)
2860 struct bt_ctf_field_variant
*variant_src
, *variant_dst
;
2862 BT_LOGD("Copying variant field: src-field-addr=%p, dst-field-addr=%p",
2864 variant_src
= container_of(src
, struct bt_ctf_field_variant
, parent
);
2865 variant_dst
= container_of(dst
, struct bt_ctf_field_variant
, parent
);
2867 if (variant_src
->tag
) {
2868 BT_LOGD_STR("Copying variant field's tag field.");
2869 variant_dst
->tag
= bt_ctf_field_copy(variant_src
->tag
);
2870 if (!variant_dst
->tag
) {
2871 BT_LOGE_STR("Cannot copy variant field's tag field.");
2876 if (variant_src
->payload
) {
2877 BT_LOGD_STR("Copying variant field's payload field.");
2878 variant_dst
->payload
= bt_ctf_field_copy(variant_src
->payload
);
2879 if (!variant_dst
->payload
) {
2880 BT_LOGE_STR("Cannot copy variant field's payload field.");
2886 BT_LOGD_STR("Copied variant field.");
2893 int bt_ctf_field_array_copy(struct bt_ctf_field
*src
,
2894 struct bt_ctf_field
*dst
)
2898 struct bt_ctf_field_array
*array_src
, *array_dst
;
2900 BT_LOGD("Copying array field: src-field-addr=%p, dst-field-addr=%p",
2902 array_src
= container_of(src
, struct bt_ctf_field_array
, parent
);
2903 array_dst
= container_of(dst
, struct bt_ctf_field_array
, parent
);
2905 g_ptr_array_set_size(array_dst
->elements
, array_src
->elements
->len
);
2906 for (i
= 0; i
< array_src
->elements
->len
; i
++) {
2907 struct bt_ctf_field
*field
=
2908 g_ptr_array_index(array_src
->elements
, i
);
2909 struct bt_ctf_field
*field_copy
= NULL
;
2912 BT_LOGD("Copying array field's element field: field-addr=%p, "
2913 "index=%" PRId64
, field
, i
);
2914 field_copy
= bt_ctf_field_copy(field
);
2916 BT_LOGE("Cannot copy array field's element field: "
2917 "src-field-addr=%p, index=%" PRId64
,
2924 g_ptr_array_index(array_dst
->elements
, i
) = field_copy
;
2927 BT_LOGD_STR("Copied array field.");
2934 int bt_ctf_field_sequence_copy(struct bt_ctf_field
*src
,
2935 struct bt_ctf_field
*dst
)
2939 struct bt_ctf_field_sequence
*sequence_src
, *sequence_dst
;
2940 struct bt_ctf_field
*src_length
;
2941 struct bt_ctf_field
*dst_length
;
2943 BT_LOGD("Copying sequence field: src-field-addr=%p, dst-field-addr=%p",
2945 sequence_src
= container_of(src
, struct bt_ctf_field_sequence
, parent
);
2946 sequence_dst
= container_of(dst
, struct bt_ctf_field_sequence
, parent
);
2948 src_length
= bt_ctf_field_sequence_get_length(src
);
2950 /* no length set yet: keep destination sequence empty */
2954 /* copy source length */
2955 BT_LOGD_STR("Copying sequence field's length field.");
2956 dst_length
= bt_ctf_field_copy(src_length
);
2959 BT_LOGE_STR("Cannot copy sequence field's length field.");
2964 /* this will initialize the destination sequence's internal array */
2965 ret
= bt_ctf_field_sequence_set_length(dst
, dst_length
);
2968 BT_LOGE("Cannot set sequence field copy's length field: "
2969 "dst-length-field-addr=%p", dst_length
);
2974 assert(sequence_dst
->elements
->len
== sequence_src
->elements
->len
);
2976 for (i
= 0; i
< sequence_src
->elements
->len
; i
++) {
2977 struct bt_ctf_field
*field
=
2978 g_ptr_array_index(sequence_src
->elements
, i
);
2979 struct bt_ctf_field
*field_copy
= NULL
;
2982 BT_LOGD("Copying sequence field's element field: field-addr=%p, "
2983 "index=%" PRId64
, field
, i
);
2984 field_copy
= bt_ctf_field_copy(field
);
2986 BT_LOGE("Cannot copy sequence field's element field: "
2987 "src-field-addr=%p, index=%" PRId64
,
2994 g_ptr_array_index(sequence_dst
->elements
, i
) = field_copy
;
2997 BT_LOGD_STR("Copied sequence field.");
3004 int bt_ctf_field_string_copy(struct bt_ctf_field
*src
,
3005 struct bt_ctf_field
*dst
)
3008 struct bt_ctf_field_string
*string_src
, *string_dst
;
3010 BT_LOGD("Copying string field: src-field-addr=%p, dst-field-addr=%p",
3012 string_src
= container_of(src
, struct bt_ctf_field_string
, parent
);
3013 string_dst
= container_of(dst
, struct bt_ctf_field_string
, parent
);
3015 if (string_src
->payload
) {
3016 string_dst
->payload
= g_string_new(string_src
->payload
->str
);
3017 if (!string_dst
->payload
) {
3018 BT_LOGE_STR("Failed to allocate a GString.");
3024 BT_LOGD_STR("Copied string field.");
3031 int increase_packet_size(struct bt_ctf_stream_pos
*pos
)
3036 BT_LOGV("Increasing packet size: pos-offset=%" PRId64
", "
3037 "cur-packet-size=%" PRIu64
,
3038 pos
->offset
, pos
->packet_size
);
3039 ret
= munmap_align(pos
->base_mma
);
3041 BT_LOGE("Failed to perform an aligned memory unmapping: "
3042 "ret=%d, errno=%d", ret
, errno
);
3046 pos
->packet_size
+= PACKET_LEN_INCREMENT
;
3048 ret
= bt_posix_fallocate(pos
->fd
, pos
->mmap_offset
,
3049 pos
->packet_size
/ CHAR_BIT
);
3050 } while (ret
== EINTR
);
3052 BT_LOGE("Failed to preallocate memory space: ret=%d, errno=%d",
3059 pos
->base_mma
= mmap_align(pos
->packet_size
/ CHAR_BIT
, pos
->prot
,
3060 pos
->flags
, pos
->fd
, pos
->mmap_offset
);
3061 if (pos
->base_mma
== MAP_FAILED
) {
3062 BT_LOGE("Failed to perform an aligned memory mapping: "
3063 "ret=%d, errno=%d", ret
, errno
);
3067 BT_LOGV("Increased packet size: pos-offset=%" PRId64
", "
3068 "new-packet-size=%" PRIu64
,
3069 pos
->offset
, pos
->packet_size
);
3070 assert(pos
->packet_size
% 8 == 0);
3077 void generic_field_freeze(struct bt_ctf_field
*field
)
3083 void bt_ctf_field_enumeration_freeze(struct bt_ctf_field
*field
)
3085 struct bt_ctf_field_enumeration
*enum_field
=
3086 container_of(field
, struct bt_ctf_field_enumeration
, parent
);
3088 BT_LOGD("Freezing enumeration field object: addr=%p", field
);
3089 BT_LOGD("Freezing enumeration field object's contained payload field: payload-field-addr=%p", enum_field
->payload
);
3090 bt_ctf_field_freeze(enum_field
->payload
);
3091 generic_field_freeze(field
);
3095 void bt_ctf_field_structure_freeze(struct bt_ctf_field
*field
)
3098 struct bt_ctf_field_structure
*structure_field
=
3099 container_of(field
, struct bt_ctf_field_structure
, parent
);
3101 BT_LOGD("Freezing structure field object: addr=%p", field
);
3103 for (i
= 0; i
< structure_field
->fields
->len
; i
++) {
3104 struct bt_ctf_field
*field
=
3105 g_ptr_array_index(structure_field
->fields
, i
);
3107 BT_LOGD("Freezing structure field's field: field-addr=%p, index=%" PRId64
,
3109 bt_ctf_field_freeze(field
);
3112 generic_field_freeze(field
);
3116 void bt_ctf_field_variant_freeze(struct bt_ctf_field
*field
)
3118 struct bt_ctf_field_variant
*variant_field
=
3119 container_of(field
, struct bt_ctf_field_variant
, parent
);
3121 BT_LOGD("Freezing variant field object: addr=%p", field
);
3122 BT_LOGD("Freezing variant field object's tag field: tag-field-addr=%p", variant_field
->tag
);
3123 bt_ctf_field_freeze(variant_field
->tag
);
3124 BT_LOGD("Freezing variant field object's payload field: payload-field-addr=%p", variant_field
->payload
);
3125 bt_ctf_field_freeze(variant_field
->payload
);
3126 generic_field_freeze(field
);
3130 void bt_ctf_field_array_freeze(struct bt_ctf_field
*field
)
3133 struct bt_ctf_field_array
*array_field
=
3134 container_of(field
, struct bt_ctf_field_array
, parent
);
3136 BT_LOGD("Freezing array field object: addr=%p", field
);
3138 for (i
= 0; i
< array_field
->elements
->len
; i
++) {
3139 struct bt_ctf_field
*elem_field
=
3140 g_ptr_array_index(array_field
->elements
, i
);
3142 BT_LOGD("Freezing array field object's element field: "
3143 "element-field-addr=%p, index=%" PRId64
,
3145 bt_ctf_field_freeze(elem_field
);
3148 generic_field_freeze(field
);
3152 void bt_ctf_field_sequence_freeze(struct bt_ctf_field
*field
)
3155 struct bt_ctf_field_sequence
*sequence_field
=
3156 container_of(field
, struct bt_ctf_field_sequence
, parent
);
3158 BT_LOGD("Freezing sequence field object: addr=%p", field
);
3159 BT_LOGD("Freezing sequence field object's length field: length-field-addr=%p",
3160 sequence_field
->length
);
3161 bt_ctf_field_freeze(sequence_field
->length
);
3163 for (i
= 0; i
< sequence_field
->elements
->len
; i
++) {
3164 struct bt_ctf_field
*elem_field
=
3165 g_ptr_array_index(sequence_field
->elements
, i
);
3167 BT_LOGD("Freezing sequence field object's element field: "
3168 "element-field-addr=%p, index=%" PRId64
,
3170 bt_ctf_field_freeze(elem_field
);
3173 generic_field_freeze(field
);
3177 void bt_ctf_field_freeze(struct bt_ctf_field
*field
)
3179 enum bt_ctf_field_type_id type_id
;
3185 if (field
->frozen
) {
3189 BT_LOGD("Freezing field object: addr=%p", field
);
3190 type_id
= bt_ctf_field_get_type_id(field
);
3191 assert(type_id
> BT_CTF_FIELD_TYPE_ID_UNKNOWN
&&
3192 type_id
< BT_CTF_NR_TYPE_IDS
);
3193 field_freeze_funcs
[type_id
](field
);
3199 bt_bool
bt_ctf_field_generic_is_set(struct bt_ctf_field
*field
)
3201 return field
&& field
->payload_set
;
3205 bt_bool
bt_ctf_field_enumeration_is_set(struct bt_ctf_field
*field
)
3207 bt_bool is_set
= BT_FALSE
;
3208 struct bt_ctf_field_enumeration
*enumeration
;
3214 enumeration
= container_of(field
, struct bt_ctf_field_enumeration
,
3216 if (!enumeration
->payload
) {
3220 is_set
= bt_ctf_field_is_set(enumeration
->payload
);
3226 bt_bool
bt_ctf_field_structure_is_set(struct bt_ctf_field
*field
)
3228 bt_bool is_set
= BT_FALSE
;
3230 struct bt_ctf_field_structure
*structure
;
3236 structure
= container_of(field
, struct bt_ctf_field_structure
, parent
);
3237 for (i
= 0; i
< structure
->fields
->len
; i
++) {
3238 is_set
= bt_ctf_field_is_set(structure
->fields
->pdata
[i
]);
3248 bt_bool
bt_ctf_field_variant_is_set(struct bt_ctf_field
*field
)
3250 bt_bool is_set
= BT_FALSE
;
3251 struct bt_ctf_field_variant
*variant
;
3257 variant
= container_of(field
, struct bt_ctf_field_variant
, parent
);
3258 is_set
= bt_ctf_field_is_set(variant
->payload
);
3264 bt_bool
bt_ctf_field_array_is_set(struct bt_ctf_field
*field
)
3267 bt_bool is_set
= BT_FALSE
;
3268 struct bt_ctf_field_array
*array
;
3274 array
= container_of(field
, struct bt_ctf_field_array
, parent
);
3275 for (i
= 0; i
< array
->elements
->len
; i
++) {
3276 is_set
= bt_ctf_field_is_set(array
->elements
->pdata
[i
]);
3286 bt_bool
bt_ctf_field_sequence_is_set(struct bt_ctf_field
*field
)
3289 bt_bool is_set
= BT_FALSE
;
3290 struct bt_ctf_field_sequence
*sequence
;
3296 sequence
= container_of(field
, struct bt_ctf_field_sequence
, parent
);
3297 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
3298 is_set
= bt_ctf_field_validate(sequence
->elements
->pdata
[i
]);