2 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #define BT_LOG_TAG "CTF-WRITER-FIELD-TYPES"
26 #include <babeltrace/lib-logging-internal.h>
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/ctf-ir/field-types-internal.h>
30 #include <babeltrace/ctf-ir/utils-internal.h>
31 #include <babeltrace/ctf-ir/utils.h>
32 #include <babeltrace/ctf-ir/field-path-internal.h>
33 #include <babeltrace/ctf-writer/field-types.h>
34 #include <babeltrace/ctf-writer/field-types-internal.h>
35 #include <babeltrace/ctf-writer/fields.h>
36 #include <babeltrace/ctf-writer/clock-internal.h>
37 #include <babeltrace/object-internal.h>
38 #include <babeltrace/ref.h>
39 #include <babeltrace/compiler-internal.h>
40 #include <babeltrace/endian-internal.h>
41 #include <babeltrace/assert-internal.h>
47 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
48 struct bt_ctf_field_type
*ft
);
51 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
52 struct bt_ctf_field_type
*ft
);
55 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
56 struct bt_ctf_field_type
*ft
);
59 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
60 struct bt_ctf_field_type
*ft
);
63 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
64 struct bt_ctf_field_type
*ft
);
67 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
68 struct bt_ctf_field_type
*ft
);
71 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
72 struct bt_ctf_field_type
*type
);
75 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(
76 struct bt_ctf_field_type
*type
);
78 static struct bt_field_type_common_methods bt_ctf_field_type_integer_methods
= {
79 .freeze
= bt_field_type_common_generic_freeze
,
80 .validate
= bt_field_type_common_integer_validate
,
81 .set_byte_order
= bt_field_type_common_integer_set_byte_order
,
82 .copy
= (bt_field_type_common_method_copy
)
83 bt_ctf_field_type_integer_copy
,
84 .compare
= bt_field_type_common_integer_compare
,
87 static struct bt_field_type_common_methods bt_ctf_field_type_floating_point_methods
= {
88 .freeze
= bt_field_type_common_generic_freeze
,
90 .set_byte_order
= bt_field_type_common_floating_point_set_byte_order
,
91 .copy
= (bt_field_type_common_method_copy
)
92 bt_ctf_field_type_floating_point_copy
,
93 .compare
= bt_field_type_common_floating_point_compare
,
96 static struct bt_field_type_common_methods bt_ctf_field_type_enumeration_methods
= {
97 .freeze
= bt_field_type_common_enumeration_freeze_recursive
,
98 .validate
= bt_field_type_common_enumeration_validate_recursive
,
99 .set_byte_order
= bt_field_type_common_enumeration_set_byte_order_recursive
,
100 .copy
= (bt_field_type_common_method_copy
)
101 bt_ctf_field_type_enumeration_copy_recursive
,
102 .compare
= bt_field_type_common_enumeration_compare_recursive
,
105 static struct bt_field_type_common_methods bt_ctf_field_type_string_methods
= {
106 .freeze
= bt_field_type_common_generic_freeze
,
108 .set_byte_order
= NULL
,
109 .copy
= (bt_field_type_common_method_copy
)
110 bt_ctf_field_type_string_copy
,
111 .compare
= bt_field_type_common_string_compare
,
114 static struct bt_field_type_common_methods bt_ctf_field_type_array_methods
= {
115 .freeze
= bt_field_type_common_array_freeze_recursive
,
116 .validate
= bt_field_type_common_array_validate_recursive
,
117 .set_byte_order
= bt_field_type_common_array_set_byte_order_recursive
,
118 .copy
= (bt_field_type_common_method_copy
)
119 bt_ctf_field_type_array_copy_recursive
,
120 .compare
= bt_field_type_common_array_compare_recursive
,
123 static struct bt_field_type_common_methods bt_ctf_field_type_sequence_methods
= {
124 .freeze
= bt_field_type_common_sequence_freeze_recursive
,
125 .validate
= bt_field_type_common_sequence_validate_recursive
,
126 .set_byte_order
= bt_field_type_common_sequence_set_byte_order_recursive
,
127 .copy
= (bt_field_type_common_method_copy
)
128 bt_ctf_field_type_sequence_copy_recursive
,
129 .compare
= bt_field_type_common_sequence_compare_recursive
,
132 static struct bt_field_type_common_methods bt_ctf_field_type_structure_methods
= {
133 .freeze
= bt_field_type_common_structure_freeze_recursive
,
134 .validate
= bt_field_type_common_structure_validate_recursive
,
135 .set_byte_order
= bt_field_type_common_structure_set_byte_order_recursive
,
136 .copy
= (bt_field_type_common_method_copy
)
137 bt_ctf_field_type_structure_copy_recursive
,
138 .compare
= bt_field_type_common_structure_compare_recursive
,
141 static struct bt_field_type_common_methods bt_ctf_field_type_variant_methods
= {
142 .freeze
= bt_field_type_common_variant_freeze_recursive
,
143 .validate
= bt_field_type_common_variant_validate_recursive
,
144 .set_byte_order
= bt_field_type_common_variant_set_byte_order_recursive
,
145 .copy
= (bt_field_type_common_method_copy
)
146 bt_ctf_field_type_variant_copy_recursive
,
147 .compare
= bt_field_type_common_variant_compare_recursive
,
150 typedef int (*bt_ctf_field_type_serialize_func
)(struct bt_field_type_common
*,
151 struct metadata_context
*);
154 int bt_ctf_field_type_serialize_recursive(struct bt_ctf_field_type
*type
,
155 struct metadata_context
*context
)
158 struct bt_field_type_common
*type_common
= (void *) type
;
159 bt_ctf_field_type_serialize_func serialize_func
;
164 /* Make sure field type is valid before serializing it */
165 ret
= bt_field_type_common_validate((void *) type
);
167 BT_LOGW("Cannot serialize field type's metadata: field type is invalid: "
172 serialize_func
= type_common
->spec
.writer
.serialize_func
;
173 ret
= serialize_func((void *) type
, context
);
180 const char *get_encoding_string(enum bt_string_encoding encoding
)
182 const char *encoding_string
;
185 case BT_STRING_ENCODING_NONE
:
186 encoding_string
= "none";
188 case BT_STRING_ENCODING_ASCII
:
189 encoding_string
= "ASCII";
191 case BT_STRING_ENCODING_UTF8
:
192 encoding_string
= "UTF8";
195 encoding_string
= "unknown";
199 return encoding_string
;
203 const char *get_integer_base_string(enum bt_integer_base base
)
205 const char *base_string
;
208 case BT_INTEGER_BASE_DECIMAL
:
209 case BT_INTEGER_BASE_UNSPECIFIED
:
210 base_string
= "decimal";
212 case BT_INTEGER_BASE_HEXADECIMAL
:
213 base_string
= "hexadecimal";
215 case BT_INTEGER_BASE_OCTAL
:
216 base_string
= "octal";
218 case BT_INTEGER_BASE_BINARY
:
219 base_string
= "binary";
222 base_string
= "unknown";
230 void append_field_name(struct metadata_context
*context
,
233 g_string_append_c(context
->string
, ' ');
235 if (!bt_identifier_is_valid(name
) || *name
== '_') {
236 g_string_append_c(context
->string
, '_');
239 g_string_append(context
->string
, name
);
243 int bt_ctf_field_type_integer_serialize(struct bt_field_type_common
*type
,
244 struct metadata_context
*context
)
246 struct bt_field_type_common_integer
*integer
= BT_FROM_COMMON(type
);
249 BT_LOGD("Serializing CTF writer integer field type's metadata: "
250 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
251 g_string_append_printf(context
->string
,
252 "integer { size = %u; align = %u; signed = %s; encoding = %s; base = %s; byte_order = %s",
253 integer
->size
, type
->alignment
,
254 (integer
->is_signed
? "true" : "false"),
255 get_encoding_string(integer
->encoding
),
256 get_integer_base_string(integer
->base
),
257 get_byte_order_string(integer
->user_byte_order
));
258 if (integer
->mapped_clock_class
) {
259 const char *clock_name
= bt_clock_class_get_name(
260 integer
->mapped_clock_class
);
262 BT_ASSERT(clock_name
);
263 g_string_append_printf(context
->string
,
264 "; map = clock.%s.value", clock_name
);
267 g_string_append(context
->string
, "; }");
272 int bt_ctf_field_type_enumeration_serialize_recursive(
273 struct bt_field_type_common
*type
,
274 struct metadata_context
*context
)
278 struct bt_field_type_common_enumeration
*enumeration
=
279 BT_FROM_COMMON(type
);
280 struct bt_field_type_common
*container_type
;
281 int container_signed
;
283 BT_LOGD("Serializing CTF writer enumeration field type's metadata: "
284 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
286 bt_field_type_common_enumeration_borrow_container_field_type(type
);
287 BT_ASSERT(container_type
);
288 container_signed
= bt_field_type_common_integer_is_signed(
290 BT_ASSERT(container_signed
>= 0);
291 g_string_append(context
->string
, "enum : ");
292 BT_LOGD_STR("Serializing CTF writer enumeration field type's container field type's metadata.");
293 ret
= bt_ctf_field_type_serialize_recursive(
294 (void *) enumeration
->container_ft
, context
);
296 BT_LOGW("Cannot serialize CTF writer enumeration field type's container field type's metadata: "
297 "container-ft-addr=%p", enumeration
->container_ft
);
301 g_string_append(context
->string
, " { ");
302 for (entry
= 0; entry
< enumeration
->entries
->len
; entry
++) {
303 struct enumeration_mapping
*mapping
=
304 enumeration
->entries
->pdata
[entry
];
305 const char *label
= g_quark_to_string(mapping
->string
);
307 g_string_append(context
->string
, "\"");
309 if (!bt_identifier_is_valid(label
) || label
[0] == '_') {
310 g_string_append(context
->string
, "_");
313 g_string_append_printf(context
->string
, "%s\" = ", label
);
315 if (container_signed
) {
316 if (mapping
->range_start
._signed
==
317 mapping
->range_end
._signed
) {
318 g_string_append_printf(context
->string
,
320 mapping
->range_start
._signed
);
322 g_string_append_printf(context
->string
,
323 "%" PRId64
" ... %" PRId64
,
324 mapping
->range_start
._signed
,
325 mapping
->range_end
._signed
);
328 if (mapping
->range_start
._unsigned
==
329 mapping
->range_end
._unsigned
) {
330 g_string_append_printf(context
->string
,
332 mapping
->range_start
._unsigned
);
334 g_string_append_printf(context
->string
,
335 "%" PRIu64
" ... %" PRIu64
,
336 mapping
->range_start
._unsigned
,
337 mapping
->range_end
._unsigned
);
341 g_string_append(context
->string
,
342 ((entry
!= (enumeration
->entries
->len
- 1)) ?
346 if (context
->field_name
->len
) {
347 append_field_name(context
,
348 context
->field_name
->str
);
349 g_string_assign(context
->field_name
, "");
357 int bt_ctf_field_type_floating_point_serialize(struct bt_field_type_common
*type
,
358 struct metadata_context
*context
)
360 struct bt_field_type_common_floating_point
*floating_point
=
361 BT_FROM_COMMON(type
);
363 BT_LOGD("Serializing CTF writer floating point number field type's metadata: "
364 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
365 g_string_append_printf(context
->string
,
366 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
367 floating_point
->exp_dig
,
368 floating_point
->mant_dig
,
369 get_byte_order_string(floating_point
->user_byte_order
),
375 int bt_ctf_field_type_structure_serialize_recursive(
376 struct bt_field_type_common
*type
,
377 struct metadata_context
*context
)
382 struct bt_field_type_common_structure
*structure
= BT_FROM_COMMON(type
);
383 GString
*structure_field_name
= context
->field_name
;
385 BT_LOGD("Serializing CTF writer structure field type's metadata: "
386 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
387 context
->field_name
= g_string_new("");
389 context
->current_indentation_level
++;
390 g_string_append(context
->string
, "struct {\n");
392 for (i
= 0; i
< structure
->fields
->len
; i
++) {
393 struct structure_field_common
*field
= structure
->fields
->pdata
[i
];
395 BT_LOGD("Serializing CTF writer structure field type's field metadata: "
397 "field-ft-addr=%p, field-name=\"%s\"",
398 i
, field
, g_quark_to_string(field
->name
));
400 for (indent
= 0; indent
< context
->current_indentation_level
;
402 g_string_append_c(context
->string
, '\t');
405 g_string_assign(context
->field_name
,
406 g_quark_to_string(field
->name
));
407 ret
= bt_ctf_field_type_serialize_recursive(
408 (void *) field
->type
, context
);
410 BT_LOGW("Cannot serialize CTF writer structure field type's field's metadata: "
412 "field-ft-addr=%p, field-name=\"%s\"",
414 g_quark_to_string(field
->name
));
418 if (context
->field_name
->len
) {
419 append_field_name(context
,
420 context
->field_name
->str
);
422 g_string_append(context
->string
, ";\n");
425 context
->current_indentation_level
--;
426 for (indent
= 0; indent
< context
->current_indentation_level
;
428 g_string_append_c(context
->string
, '\t');
431 g_string_append_printf(context
->string
, "} align(%u)",
435 g_string_free(context
->field_name
, TRUE
);
436 context
->field_name
= structure_field_name
;
441 int bt_ctf_field_type_variant_serialize_recursive(
442 struct bt_field_type_common
*type
,
443 struct metadata_context
*context
)
448 struct bt_field_type_common_variant
*variant
= BT_FROM_COMMON(type
);
449 GString
*variant_field_name
= context
->field_name
;
451 BT_LOGD("Serializing CTF writer variant field type's metadata: "
452 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
453 context
->field_name
= g_string_new("");
454 if (variant
->tag_name
->len
> 0) {
455 g_string_append(context
->string
, "variant <");
456 append_field_name(context
, variant
->tag_name
->str
);
457 g_string_append(context
->string
, "> {\n");
459 g_string_append(context
->string
, "variant {\n");
462 context
->current_indentation_level
++;
463 for (i
= 0; i
< variant
->fields
->len
; i
++) {
464 struct structure_field_common
*field
=
465 variant
->fields
->pdata
[i
];
467 BT_LOGD("Serializing CTF writer variant field type's field metadata: "
469 "field-ft-addr=%p, field-name=\"%s\"",
470 i
, field
, g_quark_to_string(field
->name
));
472 g_string_assign(context
->field_name
,
473 g_quark_to_string(field
->name
));
474 for (indent
= 0; indent
< context
->current_indentation_level
;
476 g_string_append_c(context
->string
, '\t');
479 g_string_assign(context
->field_name
,
480 g_quark_to_string(field
->name
));
481 ret
= bt_ctf_field_type_serialize_recursive(
482 (void *) field
->type
, context
);
484 BT_LOGW("Cannot serialize CTF writer variant field type's field's metadata: "
486 "field-ft-addr=%p, field-name=\"%s\"",
488 g_quark_to_string(field
->name
));
492 if (context
->field_name
->len
) {
493 append_field_name(context
,
494 context
->field_name
->str
);
495 g_string_append_c(context
->string
, ';');
498 g_string_append_c(context
->string
, '\n');
501 context
->current_indentation_level
--;
502 for (indent
= 0; indent
< context
->current_indentation_level
;
504 g_string_append_c(context
->string
, '\t');
507 g_string_append(context
->string
, "}");
510 g_string_free(context
->field_name
, TRUE
);
511 context
->field_name
= variant_field_name
;
516 int bt_ctf_field_type_array_serialize_recursive(
517 struct bt_field_type_common
*type
,
518 struct metadata_context
*context
)
521 struct bt_field_type_common_array
*array
= BT_FROM_COMMON(type
);
523 BT_LOGD("Serializing CTF writer array field type's metadata: "
524 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
525 BT_LOGD_STR("Serializing CTF writer array field type's element field type's metadata.");
526 ret
= bt_ctf_field_type_serialize_recursive(
527 (void *) array
->element_ft
, context
);
529 BT_LOGW("Cannot serialize CTF writer array field type's element field type's metadata: "
530 "element-ft-addr=%p", array
->element_ft
);
534 if (context
->field_name
->len
) {
535 append_field_name(context
,
536 context
->field_name
->str
);
538 g_string_append_printf(context
->string
, "[%u]", array
->length
);
539 g_string_assign(context
->field_name
, "");
541 g_string_append_printf(context
->string
, "[%u]", array
->length
);
549 int bt_ctf_field_type_sequence_serialize_recursive(
550 struct bt_field_type_common
*type
,
551 struct metadata_context
*context
)
554 struct bt_field_type_common_sequence
*sequence
= BT_FROM_COMMON(type
);
556 BT_LOGD("Serializing CTF writer sequence field type's metadata: "
557 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
558 BT_LOGD_STR("Serializing CTF writer sequence field type's element field type's metadata.");
559 ret
= bt_ctf_field_type_serialize_recursive(
560 (void *) sequence
->element_ft
, context
);
562 BT_LOGW("Cannot serialize CTF writer sequence field type's element field type's metadata: "
563 "element-ft-addr=%p", sequence
->element_ft
);
567 if (context
->field_name
->len
) {
568 append_field_name(context
, context
->field_name
->str
);
569 g_string_assign(context
->field_name
, "");
571 g_string_append(context
->string
, "[");
572 append_field_name(context
, sequence
->length_field_name
->str
);
573 g_string_append(context
->string
, "]");
580 int bt_ctf_field_type_string_serialize(struct bt_field_type_common
*type
,
581 struct metadata_context
*context
)
583 struct bt_field_type_common_string
*string
= BT_FROM_COMMON(type
);
585 BT_LOGD("Serializing CTF writer string field type's metadata: "
586 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
587 g_string_append_printf(context
->string
,
588 "string { encoding = %s; }",
589 get_encoding_string(string
->encoding
));
593 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
595 struct bt_field_type_common_integer
*integer
= NULL
;
597 BT_LOGD("Creating CTF writer integer field type object: size=%u", size
);
599 if (size
== 0 || size
> 64) {
600 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
605 integer
= g_new0(struct bt_field_type_common_integer
, 1);
607 BT_LOGE_STR("Failed to allocate one integer field type.");
611 bt_field_type_common_integer_initialize(BT_TO_COMMON(integer
),
612 size
, bt_field_type_common_integer_destroy
,
613 &bt_ctf_field_type_integer_methods
);
614 integer
->common
.spec
.writer
.serialize_func
=
615 bt_ctf_field_type_integer_serialize
;
616 BT_LOGD("Created CTF writer integer field type object: addr=%p, size=%u",
624 return (void *) integer
;
627 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*ft
)
629 return bt_field_type_common_integer_get_size((void *) ft
);
632 bt_bool
bt_ctf_field_type_integer_is_signed(struct bt_ctf_field_type
*ft
)
634 return bt_field_type_common_integer_is_signed((void *) ft
);
637 int bt_ctf_field_type_integer_set_is_signed(struct bt_ctf_field_type
*ft
,
640 return bt_field_type_common_integer_set_is_signed((void *) ft
,
644 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*ft
,
647 return bt_field_type_common_integer_set_size((void *) ft
, size
);
650 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
651 struct bt_ctf_field_type
*ft
)
653 return (int) bt_field_type_common_integer_get_base((void *) ft
);
656 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*ft
,
657 enum bt_ctf_integer_base base
)
659 return bt_field_type_common_integer_set_base((void *) ft
,
663 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
664 struct bt_ctf_field_type
*ft
)
666 return (int) bt_field_type_common_integer_get_encoding((void *) ft
);
669 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*ft
,
670 enum bt_ctf_string_encoding encoding
)
672 return bt_field_type_common_integer_set_encoding((void *) ft
,
676 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
677 struct bt_ctf_field_type
*ft
)
679 return bt_get(bt_field_type_common_integer_borrow_mapped_clock_class(
683 int bt_ctf_field_type_integer_set_mapped_clock_class(
684 struct bt_ctf_field_type
*ft
,
685 struct bt_ctf_clock_class
*clock_class
)
687 return bt_field_type_common_integer_set_mapped_clock_class((void *) ft
,
688 BT_TO_COMMON(clock_class
));
691 int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
692 struct bt_ctf_field_type
*ft
, uint64_t index
,
693 const char **mapping_name
, int64_t *range_begin
,
696 return bt_field_type_common_enumeration_signed_get_mapping_by_index(
697 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
700 int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
701 struct bt_ctf_field_type
*ft
, uint64_t index
,
702 const char **mapping_name
, uint64_t *range_begin
,
705 return bt_field_type_common_enumeration_unsigned_get_mapping_by_index(
706 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
709 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
710 struct bt_ctf_field_type
*container_ft
)
712 struct bt_field_type_common_enumeration
*enumeration
= NULL
;
713 struct bt_field_type_common
*int_ft
= (void *) container_ft
;
715 BT_LOGD("Creating CTF writer enumeration field type object: int-ft-addr=%p",
719 BT_LOGW_STR("Invalid parameter: field type is NULL.");
723 if (int_ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
724 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
725 "container-ft-addr=%p, container-ft-id=%s",
726 container_ft
, bt_common_field_type_id_string(int_ft
->id
));
730 enumeration
= g_new0(struct bt_field_type_common_enumeration
, 1);
732 BT_LOGE_STR("Failed to allocate one enumeration field type.");
736 bt_field_type_common_enumeration_initialize(BT_TO_COMMON(enumeration
),
737 int_ft
, bt_field_type_common_enumeration_destroy_recursive
,
738 &bt_ctf_field_type_enumeration_methods
);
739 enumeration
->common
.spec
.writer
.serialize_func
=
740 bt_ctf_field_type_enumeration_serialize_recursive
;
741 BT_LOGD("Created CTF writer enumeration field type object: addr=%p, "
742 "int-ft-addr=%p, int-ft-size=%u",
743 enumeration
, container_ft
,
744 bt_ctf_field_type_integer_get_size(container_ft
));
751 return (void *) enumeration
;
754 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
755 struct bt_ctf_field_type
*ft
)
758 bt_field_type_common_enumeration_borrow_container_field_type(
762 int bt_ctf_field_type_enumeration_signed_add_mapping(
763 struct bt_ctf_field_type
*ft
, const char *string
,
764 int64_t range_start
, int64_t range_end
)
766 return bt_field_type_common_enumeration_signed_add_mapping(
767 (void *) ft
, string
, range_start
, range_end
);
770 int bt_ctf_field_type_enumeration_unsigned_add_mapping(
771 struct bt_ctf_field_type
*ft
, const char *string
,
772 uint64_t range_start
, uint64_t range_end
)
774 return bt_field_type_common_enumeration_unsigned_add_mapping(
775 (void *) ft
, string
, range_start
, range_end
);
778 int64_t bt_ctf_field_type_enumeration_get_mapping_count(
779 struct bt_ctf_field_type
*ft
)
781 return bt_field_type_common_enumeration_get_mapping_count((void *) ft
);
784 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_create(void)
786 struct bt_field_type_common_floating_point
*floating_point
=
787 g_new0(struct bt_field_type_common_floating_point
, 1);
789 BT_LOGD_STR("Creating CTF writer floating point number field type object.");
791 if (!floating_point
) {
792 BT_LOGE_STR("Failed to allocate one floating point number field type.");
796 bt_field_type_common_floating_point_initialize(
797 BT_TO_COMMON(floating_point
),
798 bt_field_type_common_floating_point_destroy
,
799 &bt_ctf_field_type_floating_point_methods
);
800 floating_point
->common
.spec
.writer
.serialize_func
=
801 bt_ctf_field_type_floating_point_serialize
;
802 BT_LOGD("Created CTF writer floating point number field type object: addr=%p, "
803 "exp-size=%u, mant-size=%u", floating_point
,
804 floating_point
->exp_dig
, floating_point
->mant_dig
);
807 return (void *) floating_point
;
810 int bt_ctf_field_type_floating_point_get_exponent_digits(
811 struct bt_ctf_field_type
*ft
)
813 return bt_field_type_common_floating_point_get_exponent_digits(
817 int bt_ctf_field_type_floating_point_set_exponent_digits(
818 struct bt_ctf_field_type
*ft
, unsigned int exponent_digits
)
820 return bt_field_type_common_floating_point_set_exponent_digits(
821 (void *) ft
, exponent_digits
);
824 int bt_ctf_field_type_floating_point_get_mantissa_digits(
825 struct bt_ctf_field_type
*ft
)
827 return bt_field_type_common_floating_point_get_mantissa_digits(
831 int bt_ctf_field_type_floating_point_set_mantissa_digits(
832 struct bt_ctf_field_type
*ft
, unsigned int mantissa_digits
)
834 return bt_field_type_common_floating_point_set_mantissa_digits(
835 (void *) ft
, mantissa_digits
);
838 struct bt_ctf_field_type
*bt_ctf_field_type_structure_create(void)
840 struct bt_field_type_common_structure
*structure
=
841 g_new0(struct bt_field_type_common_structure
, 1);
843 BT_LOGD_STR("Creating CTF writer structure field type object.");
846 BT_LOGE_STR("Failed to allocate one structure field type.");
850 bt_field_type_common_structure_initialize(BT_TO_COMMON(structure
),
851 bt_field_type_common_structure_destroy_recursive
,
852 &bt_ctf_field_type_structure_methods
);
853 structure
->common
.spec
.writer
.serialize_func
=
854 bt_ctf_field_type_structure_serialize_recursive
;
855 BT_LOGD("Created CTF writer structure field type object: addr=%p",
863 return (void *) structure
;
866 int bt_ctf_field_type_structure_add_field(struct bt_ctf_field_type
*ft
,
867 struct bt_ctf_field_type
*field_type
,
868 const char *field_name
)
870 return bt_field_type_common_structure_add_field((void *) ft
,
871 (void *) field_type
, field_name
);
874 int64_t bt_ctf_field_type_structure_get_field_count(struct bt_ctf_field_type
*ft
)
876 return bt_field_type_common_structure_get_field_count((void *) ft
);
879 int bt_ctf_field_type_structure_get_field_by_index(
880 struct bt_ctf_field_type
*ft
,
881 const char **field_name
,
882 struct bt_ctf_field_type
**field_type
, uint64_t index
)
884 int ret
= bt_field_type_common_structure_borrow_field_by_index(
885 (void *) ft
, field_name
, (void *) field_type
, index
);
887 if (ret
== 0 && field_type
) {
894 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
895 struct bt_ctf_field_type
*ft
, const char *name
)
897 return bt_get(bt_field_type_common_structure_borrow_field_type_by_name(
901 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
902 struct bt_ctf_field_type
*tag_ft
, const char *tag_name
)
904 struct bt_field_type_common_variant
*var_ft
= NULL
;
906 BT_LOGD("Creating CTF writer variant field type object: "
907 "tag-ft-addr=%p, tag-field-name=\"%s\"",
910 if (tag_name
&& !bt_identifier_is_valid(tag_name
)) {
911 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
912 "tag-ft-addr=%p, tag-field-name=\"%s\"",
917 var_ft
= g_new0(struct bt_field_type_common_variant
, 1);
919 BT_LOGE_STR("Failed to allocate one variant field type.");
923 bt_field_type_common_variant_initialize(BT_TO_COMMON(var_ft
),
924 (void *) tag_ft
, tag_name
,
925 bt_field_type_common_variant_destroy_recursive
,
926 &bt_ctf_field_type_variant_methods
);
927 var_ft
->common
.spec
.writer
.serialize_func
=
928 bt_ctf_field_type_variant_serialize_recursive
;
929 BT_LOGD("Created CTF writer variant field type object: addr=%p, "
930 "tag-ft-addr=%p, tag-field-name=\"%s\"",
931 var_ft
, tag_ft
, tag_name
);
938 return (void *) var_ft
;
941 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
942 struct bt_ctf_field_type
*ft
)
944 return bt_get(bt_field_type_common_variant_borrow_tag_field_type(
948 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type
*ft
)
950 return bt_field_type_common_variant_get_tag_name((void *) ft
);
953 int bt_ctf_field_type_variant_set_tag_name(
954 struct bt_ctf_field_type
*ft
, const char *name
)
956 return bt_field_type_common_variant_set_tag_name((void *) ft
, name
);
959 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*ft
,
960 struct bt_ctf_field_type
*field_type
,
961 const char *field_name
)
963 return bt_field_type_common_variant_add_field((void *) ft
,
964 (void *) field_type
, field_name
);
967 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
968 struct bt_ctf_field_type
*ft
,
969 const char *field_name
)
971 return bt_get(bt_field_type_common_variant_borrow_field_type_by_name(
972 (void *) ft
, field_name
));
975 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
976 struct bt_ctf_field_type
*ft
,
977 struct bt_ctf_field
*tag_field
)
979 return bt_get(bt_field_type_common_variant_borrow_field_type_from_tag(
980 (void *) ft
, (void *) tag_field
,
981 (bt_field_common_create_func
) bt_field_create
));
984 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*ft
)
986 return bt_field_type_common_variant_get_field_count((void *) ft
);
989 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*ft
,
990 const char **field_name
, struct bt_ctf_field_type
**field_type
,
993 int ret
= bt_field_type_common_variant_borrow_field_by_index(
994 (void *) ft
, field_name
, (void *) field_type
, index
);
996 if (ret
== 0 && field_type
) {
1003 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
1004 struct bt_ctf_field_type
*element_ft
, unsigned int length
)
1006 struct bt_field_type_common_array
*array
= NULL
;
1008 BT_LOGD("Creating CTF writer array field type object: element-ft-addr=%p, "
1009 "length=%u", element_ft
, length
);
1012 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
1017 BT_LOGW_STR("Invalid parameter: length is zero.");
1021 array
= g_new0(struct bt_field_type_common_array
, 1);
1023 BT_LOGE_STR("Failed to allocate one array field type.");
1027 bt_field_type_common_array_initialize(BT_TO_COMMON(array
),
1028 (void *) element_ft
, length
,
1029 bt_field_type_common_array_destroy_recursive
,
1030 &bt_ctf_field_type_array_methods
);
1031 array
->common
.spec
.writer
.serialize_func
=
1032 bt_ctf_field_type_array_serialize_recursive
;
1033 BT_LOGD("Created CTF writer array field type object: addr=%p, "
1034 "element-ft-addr=%p, length=%u",
1035 array
, element_ft
, length
);
1042 return (void *) array
;
1045 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
1046 struct bt_ctf_field_type
*ft
)
1048 return bt_get(bt_field_type_common_array_borrow_element_field_type(
1052 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*ft
)
1054 return bt_field_type_common_array_get_length((void *) ft
);
1057 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
1058 struct bt_ctf_field_type
*element_ft
,
1059 const char *length_field_name
)
1061 struct bt_field_type_common_sequence
*sequence
= NULL
;
1063 BT_LOGD("Creating CTF writer sequence field type object: element-ft-addr=%p, "
1064 "length-field-name=\"%s\"", element_ft
, length_field_name
);
1067 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
1071 if (!bt_identifier_is_valid(length_field_name
)) {
1072 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
1073 "length-field-name=\"%s\"", length_field_name
);
1077 sequence
= g_new0(struct bt_field_type_common_sequence
, 1);
1079 BT_LOGE_STR("Failed to allocate one sequence field type.");
1083 bt_field_type_common_sequence_initialize(BT_TO_COMMON(sequence
),
1084 (void *) element_ft
, length_field_name
,
1085 bt_field_type_common_sequence_destroy_recursive
,
1086 &bt_ctf_field_type_sequence_methods
);
1087 sequence
->common
.spec
.writer
.serialize_func
=
1088 bt_ctf_field_type_sequence_serialize_recursive
;
1089 BT_LOGD("Created CTF writer sequence field type object: addr=%p, "
1090 "element-ft-addr=%p, length-field-name=\"%s\"",
1091 sequence
, element_ft
, length_field_name
);
1098 return (void *) sequence
;
1101 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
1102 struct bt_ctf_field_type
*ft
)
1104 return bt_get(bt_field_type_common_sequence_borrow_element_field_type(
1108 const char *bt_ctf_field_type_sequence_get_length_field_name(
1109 struct bt_ctf_field_type
*ft
)
1111 return bt_field_type_common_sequence_get_length_field_name((void *) ft
);
1114 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
1116 struct bt_field_type_common_string
*string
=
1117 g_new0(struct bt_field_type_common_string
, 1);
1119 BT_LOGD_STR("Creating CTF writer string field type object.");
1122 BT_LOGE_STR("Failed to allocate one string field type.");
1126 bt_field_type_common_string_initialize(BT_TO_COMMON(string
),
1127 bt_field_type_common_string_destroy
,
1128 &bt_ctf_field_type_string_methods
);
1129 string
->common
.spec
.writer
.serialize_func
=
1130 bt_ctf_field_type_string_serialize
;
1131 BT_LOGD("Created CTF writer string field type object: addr=%p", string
);
1132 return (void *) string
;
1135 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
1136 struct bt_ctf_field_type
*ft
)
1138 return (int) bt_field_type_common_string_get_encoding((void *) ft
);
1141 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*ft
,
1142 enum bt_ctf_string_encoding encoding
)
1144 return bt_field_type_common_string_set_encoding((void *) ft
,
1148 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*ft
)
1150 return bt_field_type_common_get_alignment((void *) ft
);
1153 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*ft
,
1154 unsigned int alignment
)
1156 return bt_field_type_common_set_alignment((void *) ft
, alignment
);
1159 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
1160 struct bt_ctf_field_type
*ft
)
1162 return (int) bt_field_type_common_get_byte_order((void *) ft
);
1165 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*ft
,
1166 enum bt_ctf_byte_order byte_order
)
1168 return bt_field_type_common_set_byte_order((void *) ft
,
1172 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
1173 struct bt_ctf_field_type
*ft
)
1175 return (int) bt_field_type_common_get_type_id((void *) ft
);
1179 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*ft
)
1181 return (void *) bt_field_type_common_copy((void *) ft
);
1185 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
1186 struct bt_ctf_field_type
*ft
)
1188 struct bt_field_type_common_integer
*int_ft
= (void *) ft
;
1189 struct bt_field_type_common_integer
*copy_ft
;
1191 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
1192 copy_ft
= (void *) bt_ctf_field_type_integer_create(int_ft
->size
);
1194 BT_LOGE_STR("Cannot create CTF writer integer field type.");
1198 copy_ft
->mapped_clock_class
= bt_get(int_ft
->mapped_clock_class
);
1199 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
1200 copy_ft
->is_signed
= int_ft
->is_signed
;
1201 copy_ft
->size
= int_ft
->size
;
1202 copy_ft
->base
= int_ft
->base
;
1203 copy_ft
->encoding
= int_ft
->encoding
;
1204 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
1208 return (void *) copy_ft
;
1212 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
1213 struct bt_ctf_field_type
*ft
)
1216 struct bt_field_type_common_enumeration
*enum_ft
= (void *) ft
;
1217 struct bt_field_type_common_enumeration
*copy_ft
= NULL
;
1218 struct bt_field_type_common_enumeration
*container_copy_ft
;
1220 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
1222 /* Copy the source enumeration's container */
1223 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
1224 container_copy_ft
= BT_FROM_COMMON(bt_field_type_common_copy(
1225 BT_TO_COMMON(enum_ft
->container_ft
)));
1226 if (!container_copy_ft
) {
1227 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
1231 copy_ft
= (void *) bt_ctf_field_type_enumeration_create(
1232 (void *) container_copy_ft
);
1234 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
1238 /* Copy all enumaration entries */
1239 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
1240 struct enumeration_mapping
*mapping
= g_ptr_array_index(
1241 enum_ft
->entries
, i
);
1242 struct enumeration_mapping
*copy_mapping
= g_new0(
1243 struct enumeration_mapping
, 1);
1245 if (!copy_mapping
) {
1246 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1250 *copy_mapping
= *mapping
;
1251 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
1254 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
1258 bt_put(container_copy_ft
);
1259 return (void *) copy_ft
;
1262 bt_put(container_copy_ft
);
1264 return (void *) copy_ft
;
1268 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
1269 struct bt_ctf_field_type
*ft
)
1271 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
1272 struct bt_field_type_common_floating_point
*copy_ft
;
1274 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
1275 copy_ft
= (void *) bt_ctf_field_type_floating_point_create();
1277 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
1281 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
1282 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
1283 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
1284 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
1288 return (void *) copy_ft
;
1292 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
1293 struct bt_ctf_field_type
*ft
)
1296 GHashTableIter iter
;
1297 gpointer key
, value
;
1298 struct bt_field_type_common_structure
*struct_ft
= (void *) ft
;
1299 struct bt_field_type_common_structure
*copy_ft
;
1301 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
1302 copy_ft
= (void *) bt_ctf_field_type_structure_create();
1304 BT_LOGE_STR("Cannot create CTF writer structure field type.");
1308 /* Copy field_name_to_index */
1309 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
1310 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
1311 g_hash_table_insert(copy_ft
->field_name_to_index
,
1315 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
1316 struct structure_field_common
*entry
, *copy_entry
;
1317 struct bt_field_type_common
*field_ft_copy
;
1319 entry
= g_ptr_array_index(struct_ft
->fields
, i
);
1320 BT_LOGD("Copying CTF writer structure field type's field: "
1321 "index=%" PRId64
", "
1322 "field-ft-addr=%p, field-name=\"%s\"",
1323 i
, entry
, g_quark_to_string(entry
->name
));
1324 copy_entry
= g_new0(struct structure_field_common
, 1);
1326 BT_LOGE_STR("Failed to allocate one structure field type field.");
1330 field_ft_copy
= (void *) bt_ctf_field_type_copy(
1331 (void *) entry
->type
);
1332 if (!field_ft_copy
) {
1333 BT_LOGE("Cannot copy CTF writer structure field type's field: "
1334 "index=%" PRId64
", "
1335 "field-ft-addr=%p, field-name=\"%s\"",
1336 i
, entry
, g_quark_to_string(entry
->name
));
1341 copy_entry
->name
= entry
->name
;
1342 copy_entry
->type
= field_ft_copy
;
1343 g_ptr_array_add(copy_ft
->fields
, copy_entry
);
1346 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
1350 return (void *) copy_ft
;
1358 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
1359 struct bt_ctf_field_type
*ft
)
1362 GHashTableIter iter
;
1363 gpointer key
, value
;
1364 struct bt_field_type_common
*tag_ft_copy
= NULL
;
1365 struct bt_field_type_common_variant
*var_ft
= (void *) ft
;
1366 struct bt_field_type_common_variant
*copy_ft
= NULL
;
1368 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
1369 if (var_ft
->tag_ft
) {
1370 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
1371 tag_ft_copy
= bt_field_type_common_copy(
1372 BT_TO_COMMON(var_ft
->tag_ft
));
1374 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
1379 copy_ft
= (void *) bt_ctf_field_type_variant_create(
1380 (void *) tag_ft_copy
,
1381 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
1383 BT_LOGE_STR("Cannot create CTF writer variant field type.");
1387 /* Copy field_name_to_index */
1388 g_hash_table_iter_init(&iter
, var_ft
->field_name_to_index
);
1389 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
1390 g_hash_table_insert(copy_ft
->field_name_to_index
,
1394 for (i
= 0; i
< var_ft
->fields
->len
; i
++) {
1395 struct structure_field_common
*entry
, *copy_entry
;
1396 struct bt_field_type_common
*field_ft_copy
;
1398 entry
= g_ptr_array_index(var_ft
->fields
, i
);
1399 BT_LOGD("Copying CTF writer variant field type's field: "
1400 "index=%" PRId64
", "
1401 "field-ft-addr=%p, field-name=\"%s\"",
1402 i
, entry
, g_quark_to_string(entry
->name
));
1403 copy_entry
= g_new0(struct structure_field_common
, 1);
1405 BT_LOGE_STR("Failed to allocate one variant field type field.");
1409 field_ft_copy
= (void *) bt_ctf_field_type_copy(
1410 (void *) entry
->type
);
1411 if (!field_ft_copy
) {
1412 BT_LOGE("Cannot copy CTF writer variant field type's field: "
1413 "index=%" PRId64
", "
1414 "field-ft-addr=%p, field-name=\"%s\"",
1415 i
, entry
, g_quark_to_string(entry
->name
));
1420 copy_entry
->name
= entry
->name
;
1421 copy_entry
->type
= field_ft_copy
;
1422 g_ptr_array_add(copy_ft
->fields
, copy_entry
);
1425 if (var_ft
->tag_field_path
) {
1426 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
1427 copy_ft
->tag_field_path
= bt_field_path_copy(
1428 var_ft
->tag_field_path
);
1429 if (!copy_ft
->tag_field_path
) {
1430 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
1435 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
1439 bt_put(tag_ft_copy
);
1440 return (void *) copy_ft
;
1443 bt_put(tag_ft_copy
);
1449 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
1450 struct bt_ctf_field_type
*ft
)
1452 struct bt_field_type_common
*container_ft_copy
= NULL
;
1453 struct bt_field_type_common_array
*array_ft
= (void *) ft
;
1454 struct bt_field_type_common_array
*copy_ft
= NULL
;
1456 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
1457 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
1458 container_ft_copy
= bt_field_type_common_copy(array_ft
->element_ft
);
1459 if (!container_ft_copy
) {
1460 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
1464 copy_ft
= (void *) bt_ctf_field_type_array_create(
1465 (void *) container_ft_copy
, array_ft
->length
);
1467 BT_LOGE_STR("Cannot create CTF writer array field type.");
1471 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
1475 bt_put(container_ft_copy
);
1476 return (void *) copy_ft
;
1480 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
1481 struct bt_ctf_field_type
*ft
)
1483 struct bt_field_type_common
*container_ft_copy
= NULL
;
1484 struct bt_field_type_common_sequence
*seq_ft
= (void *) ft
;
1485 struct bt_field_type_common_sequence
*copy_ft
= NULL
;
1487 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
1488 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
1489 container_ft_copy
= bt_field_type_common_copy(seq_ft
->element_ft
);
1490 if (!container_ft_copy
) {
1491 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
1495 copy_ft
= (void *) bt_ctf_field_type_sequence_create(
1496 (void *) container_ft_copy
,
1497 seq_ft
->length_field_name
->len
?
1498 seq_ft
->length_field_name
->str
: NULL
);
1500 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
1504 if (seq_ft
->length_field_path
) {
1505 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
1506 copy_ft
->length_field_path
= bt_field_path_copy(
1507 seq_ft
->length_field_path
);
1508 if (!copy_ft
->length_field_path
) {
1509 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
1514 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
1518 bt_put(container_ft_copy
);
1519 return (void *) copy_ft
;
1521 bt_put(container_ft_copy
);
1527 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(struct bt_ctf_field_type
*ft
)
1529 struct bt_field_type_common_string
*string_ft
= (void *) ft
;
1530 struct bt_field_type_common_string
*copy_ft
= NULL
;
1532 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
1533 copy_ft
= (void *) bt_ctf_field_type_string_create();
1535 BT_LOGE_STR("Cannot create CTF writer string field type.");
1539 copy_ft
->encoding
= string_ft
->encoding
;
1540 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
1544 return (void *) copy_ft
;