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_get_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
, "");
353 bt_put(container_type
);
358 int bt_ctf_field_type_floating_point_serialize(struct bt_field_type_common
*type
,
359 struct metadata_context
*context
)
361 struct bt_field_type_common_floating_point
*floating_point
=
362 BT_FROM_COMMON(type
);
364 BT_LOGD("Serializing CTF writer floating point number field type's metadata: "
365 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
366 g_string_append_printf(context
->string
,
367 "floating_point { exp_dig = %u; mant_dig = %u; byte_order = %s; align = %u; }",
368 floating_point
->exp_dig
,
369 floating_point
->mant_dig
,
370 get_byte_order_string(floating_point
->user_byte_order
),
376 int bt_ctf_field_type_structure_serialize_recursive(
377 struct bt_field_type_common
*type
,
378 struct metadata_context
*context
)
383 struct bt_field_type_common_structure
*structure
= BT_FROM_COMMON(type
);
384 GString
*structure_field_name
= context
->field_name
;
386 BT_LOGD("Serializing CTF writer structure field type's metadata: "
387 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
388 context
->field_name
= g_string_new("");
390 context
->current_indentation_level
++;
391 g_string_append(context
->string
, "struct {\n");
393 for (i
= 0; i
< structure
->fields
->len
; i
++) {
394 struct structure_field_common
*field
= structure
->fields
->pdata
[i
];
396 BT_LOGD("Serializing CTF writer structure field type's field metadata: "
398 "field-ft-addr=%p, field-name=\"%s\"",
399 i
, field
, g_quark_to_string(field
->name
));
401 for (indent
= 0; indent
< context
->current_indentation_level
;
403 g_string_append_c(context
->string
, '\t');
406 g_string_assign(context
->field_name
,
407 g_quark_to_string(field
->name
));
408 ret
= bt_ctf_field_type_serialize_recursive(
409 (void *) field
->type
, context
);
411 BT_LOGW("Cannot serialize CTF writer structure field type's field's metadata: "
413 "field-ft-addr=%p, field-name=\"%s\"",
415 g_quark_to_string(field
->name
));
419 if (context
->field_name
->len
) {
420 append_field_name(context
,
421 context
->field_name
->str
);
423 g_string_append(context
->string
, ";\n");
426 context
->current_indentation_level
--;
427 for (indent
= 0; indent
< context
->current_indentation_level
;
429 g_string_append_c(context
->string
, '\t');
432 g_string_append_printf(context
->string
, "} align(%u)",
436 g_string_free(context
->field_name
, TRUE
);
437 context
->field_name
= structure_field_name
;
442 int bt_ctf_field_type_variant_serialize_recursive(
443 struct bt_field_type_common
*type
,
444 struct metadata_context
*context
)
449 struct bt_field_type_common_variant
*variant
= BT_FROM_COMMON(type
);
450 GString
*variant_field_name
= context
->field_name
;
452 BT_LOGD("Serializing CTF writer variant field type's metadata: "
453 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
454 context
->field_name
= g_string_new("");
455 if (variant
->tag_name
->len
> 0) {
456 g_string_append(context
->string
, "variant <");
457 append_field_name(context
, variant
->tag_name
->str
);
458 g_string_append(context
->string
, "> {\n");
460 g_string_append(context
->string
, "variant {\n");
463 context
->current_indentation_level
++;
464 for (i
= 0; i
< variant
->fields
->len
; i
++) {
465 struct structure_field_common
*field
=
466 variant
->fields
->pdata
[i
];
468 BT_LOGD("Serializing CTF writer variant field type's field metadata: "
470 "field-ft-addr=%p, field-name=\"%s\"",
471 i
, field
, g_quark_to_string(field
->name
));
473 g_string_assign(context
->field_name
,
474 g_quark_to_string(field
->name
));
475 for (indent
= 0; indent
< context
->current_indentation_level
;
477 g_string_append_c(context
->string
, '\t');
480 g_string_assign(context
->field_name
,
481 g_quark_to_string(field
->name
));
482 ret
= bt_ctf_field_type_serialize_recursive(
483 (void *) field
->type
, context
);
485 BT_LOGW("Cannot serialize CTF writer variant field type's field's metadata: "
487 "field-ft-addr=%p, field-name=\"%s\"",
489 g_quark_to_string(field
->name
));
493 if (context
->field_name
->len
) {
494 append_field_name(context
,
495 context
->field_name
->str
);
496 g_string_append_c(context
->string
, ';');
499 g_string_append_c(context
->string
, '\n');
502 context
->current_indentation_level
--;
503 for (indent
= 0; indent
< context
->current_indentation_level
;
505 g_string_append_c(context
->string
, '\t');
508 g_string_append(context
->string
, "}");
511 g_string_free(context
->field_name
, TRUE
);
512 context
->field_name
= variant_field_name
;
517 int bt_ctf_field_type_array_serialize_recursive(
518 struct bt_field_type_common
*type
,
519 struct metadata_context
*context
)
522 struct bt_field_type_common_array
*array
= BT_FROM_COMMON(type
);
524 BT_LOGD("Serializing CTF writer array field type's metadata: "
525 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
526 BT_LOGD_STR("Serializing CTF writer array field type's element field type's metadata.");
527 ret
= bt_ctf_field_type_serialize_recursive(
528 (void *) array
->element_ft
, context
);
530 BT_LOGW("Cannot serialize CTF writer array field type's element field type's metadata: "
531 "element-ft-addr=%p", array
->element_ft
);
535 if (context
->field_name
->len
) {
536 append_field_name(context
,
537 context
->field_name
->str
);
539 g_string_append_printf(context
->string
, "[%u]", array
->length
);
540 g_string_assign(context
->field_name
, "");
542 g_string_append_printf(context
->string
, "[%u]", array
->length
);
550 int bt_ctf_field_type_sequence_serialize_recursive(
551 struct bt_field_type_common
*type
,
552 struct metadata_context
*context
)
555 struct bt_field_type_common_sequence
*sequence
= BT_FROM_COMMON(type
);
557 BT_LOGD("Serializing CTF writer sequence field type's metadata: "
558 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
559 BT_LOGD_STR("Serializing CTF writer sequence field type's element field type's metadata.");
560 ret
= bt_ctf_field_type_serialize_recursive(
561 (void *) sequence
->element_ft
, context
);
563 BT_LOGW("Cannot serialize CTF writer sequence field type's element field type's metadata: "
564 "element-ft-addr=%p", sequence
->element_ft
);
568 if (context
->field_name
->len
) {
569 append_field_name(context
, context
->field_name
->str
);
570 g_string_assign(context
->field_name
, "");
572 g_string_append(context
->string
, "[");
573 append_field_name(context
, sequence
->length_field_name
->str
);
574 g_string_append(context
->string
, "]");
581 int bt_ctf_field_type_string_serialize(struct bt_field_type_common
*type
,
582 struct metadata_context
*context
)
584 struct bt_field_type_common_string
*string
= BT_FROM_COMMON(type
);
586 BT_LOGD("Serializing CTF writer string field type's metadata: "
587 "ft-addr=%p, metadata-context-addr=%p", type
, context
);
588 g_string_append_printf(context
->string
,
589 "string { encoding = %s; }",
590 get_encoding_string(string
->encoding
));
594 struct bt_ctf_field_type
*bt_ctf_field_type_integer_create(unsigned int size
)
596 struct bt_field_type_common_integer
*integer
= NULL
;
598 BT_LOGD("Creating CTF writer integer field type object: size=%u", size
);
600 if (size
== 0 || size
> 64) {
601 BT_LOGW("Invalid parameter: size must be between 1 and 64: "
606 integer
= g_new0(struct bt_field_type_common_integer
, 1);
608 BT_LOGE_STR("Failed to allocate one integer field type.");
612 bt_field_type_common_integer_initialize(BT_TO_COMMON(integer
),
613 size
, bt_field_type_common_integer_destroy
,
614 &bt_ctf_field_type_integer_methods
);
615 integer
->common
.spec
.writer
.serialize_func
=
616 bt_ctf_field_type_integer_serialize
;
617 BT_LOGD("Created CTF writer integer field type object: addr=%p, size=%u",
625 return (void *) integer
;
628 int bt_ctf_field_type_integer_get_size(struct bt_ctf_field_type
*ft
)
630 return bt_field_type_common_integer_get_size((void *) ft
);
633 bt_bool
bt_ctf_field_type_integer_is_signed(struct bt_ctf_field_type
*ft
)
635 return bt_field_type_common_integer_is_signed((void *) ft
);
638 int bt_ctf_field_type_integer_set_is_signed(struct bt_ctf_field_type
*ft
,
641 return bt_field_type_common_integer_set_is_signed((void *) ft
,
645 int bt_ctf_field_type_integer_set_size(struct bt_ctf_field_type
*ft
,
648 return bt_field_type_common_integer_set_size((void *) ft
, size
);
651 enum bt_ctf_integer_base
bt_ctf_field_type_integer_get_base(
652 struct bt_ctf_field_type
*ft
)
654 return (int) bt_field_type_common_integer_get_base((void *) ft
);
657 int bt_ctf_field_type_integer_set_base(struct bt_ctf_field_type
*ft
,
658 enum bt_ctf_integer_base base
)
660 return bt_field_type_common_integer_set_base((void *) ft
,
664 enum bt_ctf_string_encoding
bt_ctf_field_type_integer_get_encoding(
665 struct bt_ctf_field_type
*ft
)
667 return (int) bt_field_type_common_integer_get_encoding((void *) ft
);
670 int bt_ctf_field_type_integer_set_encoding(struct bt_ctf_field_type
*ft
,
671 enum bt_ctf_string_encoding encoding
)
673 return bt_field_type_common_integer_set_encoding((void *) ft
,
677 struct bt_ctf_clock_class
*bt_ctf_field_type_integer_get_mapped_clock_class(
678 struct bt_ctf_field_type
*ft
)
680 return BT_FROM_COMMON(
681 bt_field_type_common_integer_get_mapped_clock_class((void *) ft
));
684 int bt_ctf_field_type_integer_set_mapped_clock_class(
685 struct bt_ctf_field_type
*ft
,
686 struct bt_ctf_clock_class
*clock_class
)
688 return bt_field_type_common_integer_set_mapped_clock_class((void *) ft
,
689 BT_TO_COMMON(clock_class
));
692 int bt_ctf_field_type_enumeration_signed_get_mapping_by_index(
693 struct bt_ctf_field_type
*ft
, uint64_t index
,
694 const char **mapping_name
, int64_t *range_begin
,
697 return bt_field_type_common_enumeration_signed_get_mapping_by_index(
698 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
701 int bt_ctf_field_type_enumeration_unsigned_get_mapping_by_index(
702 struct bt_ctf_field_type
*ft
, uint64_t index
,
703 const char **mapping_name
, uint64_t *range_begin
,
706 return bt_field_type_common_enumeration_unsigned_get_mapping_by_index(
707 (void *) ft
, index
, mapping_name
, range_begin
, range_end
);
710 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_create(
711 struct bt_ctf_field_type
*container_ft
)
713 struct bt_field_type_common_enumeration
*enumeration
= NULL
;
714 struct bt_field_type_common
*int_ft
= (void *) container_ft
;
716 BT_LOGD("Creating CTF writer enumeration field type object: int-ft-addr=%p",
720 BT_LOGW_STR("Invalid parameter: field type is NULL.");
724 if (int_ft
->id
!= BT_FIELD_TYPE_ID_INTEGER
) {
725 BT_LOGW("Invalid parameter: container field type is not an integer field type: "
726 "container-ft-addr=%p, container-ft-id=%s",
727 container_ft
, bt_common_field_type_id_string(int_ft
->id
));
731 enumeration
= g_new0(struct bt_field_type_common_enumeration
, 1);
733 BT_LOGE_STR("Failed to allocate one enumeration field type.");
737 bt_field_type_common_enumeration_initialize(BT_TO_COMMON(enumeration
),
738 int_ft
, bt_field_type_common_enumeration_destroy_recursive
,
739 &bt_ctf_field_type_enumeration_methods
);
740 enumeration
->common
.spec
.writer
.serialize_func
=
741 bt_ctf_field_type_enumeration_serialize_recursive
;
742 BT_LOGD("Created CTF writer enumeration field type object: addr=%p, "
743 "int-ft-addr=%p, int-ft-size=%u",
744 enumeration
, container_ft
,
745 bt_ctf_field_type_integer_get_size(container_ft
));
752 return (void *) enumeration
;
755 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_get_container_field_type(
756 struct bt_ctf_field_type
*ft
)
758 return (void *) bt_field_type_common_enumeration_get_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 return bt_field_type_common_structure_get_field_by_index(
885 (void *) ft
, field_name
, (void *) field_type
, index
);
888 struct bt_ctf_field_type
*bt_ctf_field_type_structure_get_field_type_by_name(
889 struct bt_ctf_field_type
*ft
, const char *name
)
891 return (void *) bt_field_type_common_structure_get_field_type_by_name(
895 struct bt_ctf_field_type
*bt_ctf_field_type_variant_create(
896 struct bt_ctf_field_type
*tag_ft
, const char *tag_name
)
898 struct bt_field_type_common_variant
*var_ft
= NULL
;
900 BT_LOGD("Creating CTF writer variant field type object: "
901 "tag-ft-addr=%p, tag-field-name=\"%s\"",
904 if (tag_name
&& !bt_identifier_is_valid(tag_name
)) {
905 BT_LOGW("Invalid parameter: tag field name is not a valid CTF identifier: "
906 "tag-ft-addr=%p, tag-field-name=\"%s\"",
911 var_ft
= g_new0(struct bt_field_type_common_variant
, 1);
913 BT_LOGE_STR("Failed to allocate one variant field type.");
917 bt_field_type_common_variant_initialize(BT_TO_COMMON(var_ft
),
918 (void *) tag_ft
, tag_name
,
919 bt_field_type_common_variant_destroy_recursive
,
920 &bt_ctf_field_type_variant_methods
);
921 var_ft
->common
.spec
.writer
.serialize_func
=
922 bt_ctf_field_type_variant_serialize_recursive
;
923 BT_LOGD("Created CTF writer variant field type object: addr=%p, "
924 "tag-ft-addr=%p, tag-field-name=\"%s\"",
925 var_ft
, tag_ft
, tag_name
);
932 return (void *) var_ft
;
935 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_tag_field_type(
936 struct bt_ctf_field_type
*ft
)
938 return (void *) bt_field_type_common_variant_get_tag_field_type(
942 const char *bt_ctf_field_type_variant_get_tag_name(struct bt_ctf_field_type
*ft
)
944 return bt_field_type_common_variant_get_tag_name((void *) ft
);
947 int bt_ctf_field_type_variant_set_tag_name(
948 struct bt_ctf_field_type
*ft
, const char *name
)
950 return bt_field_type_common_variant_set_tag_name((void *) ft
, name
);
953 int bt_ctf_field_type_variant_add_field(struct bt_ctf_field_type
*ft
,
954 struct bt_ctf_field_type
*field_type
,
955 const char *field_name
)
957 return bt_field_type_common_variant_add_field((void *) ft
,
958 (void *) field_type
, field_name
);
961 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_by_name(
962 struct bt_ctf_field_type
*ft
,
963 const char *field_name
)
965 return (void *) bt_field_type_common_variant_get_field_type_by_name(
966 (void *) ft
, field_name
);
969 struct bt_ctf_field_type
*bt_ctf_field_type_variant_get_field_type_from_tag(
970 struct bt_ctf_field_type
*ft
,
971 struct bt_ctf_field
*tag_field
)
973 return (void *) bt_field_type_common_variant_get_field_type_from_tag(
974 (void *) ft
, (void *) tag_field
,
975 (bt_field_common_create_func
) bt_field_create
);
978 int64_t bt_ctf_field_type_variant_get_field_count(struct bt_ctf_field_type
*ft
)
980 return bt_field_type_common_variant_get_field_count((void *) ft
);
983 int bt_ctf_field_type_variant_get_field_by_index(struct bt_ctf_field_type
*ft
,
984 const char **field_name
, struct bt_ctf_field_type
**field_type
,
987 return bt_field_type_common_variant_get_field_by_index((void *) ft
,
988 field_name
, (void *) field_type
, index
);
991 struct bt_ctf_field_type
*bt_ctf_field_type_array_create(
992 struct bt_ctf_field_type
*element_ft
, unsigned int length
)
994 struct bt_field_type_common_array
*array
= NULL
;
996 BT_LOGD("Creating CTF writer array field type object: element-ft-addr=%p, "
997 "length=%u", element_ft
, length
);
1000 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
1005 BT_LOGW_STR("Invalid parameter: length is zero.");
1009 array
= g_new0(struct bt_field_type_common_array
, 1);
1011 BT_LOGE_STR("Failed to allocate one array field type.");
1015 bt_field_type_common_array_initialize(BT_TO_COMMON(array
),
1016 (void *) element_ft
, length
,
1017 bt_field_type_common_array_destroy_recursive
,
1018 &bt_ctf_field_type_array_methods
);
1019 array
->common
.spec
.writer
.serialize_func
=
1020 bt_ctf_field_type_array_serialize_recursive
;
1021 BT_LOGD("Created CTF writer array field type object: addr=%p, "
1022 "element-ft-addr=%p, length=%u",
1023 array
, element_ft
, length
);
1030 return (void *) array
;
1033 struct bt_ctf_field_type
*bt_ctf_field_type_array_get_element_field_type(
1034 struct bt_ctf_field_type
*ft
)
1036 return (void *) bt_field_type_common_array_get_element_field_type(
1040 int64_t bt_ctf_field_type_array_get_length(struct bt_ctf_field_type
*ft
)
1042 return bt_field_type_common_array_get_length((void *) ft
);
1045 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_create(
1046 struct bt_ctf_field_type
*element_ft
,
1047 const char *length_field_name
)
1049 struct bt_field_type_common_sequence
*sequence
= NULL
;
1051 BT_LOGD("Creating CTF writer sequence field type object: element-ft-addr=%p, "
1052 "length-field-name=\"%s\"", element_ft
, length_field_name
);
1055 BT_LOGW_STR("Invalid parameter: element field type is NULL.");
1059 if (!bt_identifier_is_valid(length_field_name
)) {
1060 BT_LOGW("Invalid parameter: length field name is not a valid CTF identifier: "
1061 "length-field-name=\"%s\"", length_field_name
);
1065 sequence
= g_new0(struct bt_field_type_common_sequence
, 1);
1067 BT_LOGE_STR("Failed to allocate one sequence field type.");
1071 bt_field_type_common_sequence_initialize(BT_TO_COMMON(sequence
),
1072 (void *) element_ft
, length_field_name
,
1073 bt_field_type_common_sequence_destroy_recursive
,
1074 &bt_ctf_field_type_sequence_methods
);
1075 sequence
->common
.spec
.writer
.serialize_func
=
1076 bt_ctf_field_type_sequence_serialize_recursive
;
1077 BT_LOGD("Created CTF writer sequence field type object: addr=%p, "
1078 "element-ft-addr=%p, length-field-name=\"%s\"",
1079 sequence
, element_ft
, length_field_name
);
1086 return (void *) sequence
;
1089 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_get_element_field_type(
1090 struct bt_ctf_field_type
*ft
)
1092 return (void *) bt_field_type_common_sequence_get_element_field_type(
1096 const char *bt_ctf_field_type_sequence_get_length_field_name(
1097 struct bt_ctf_field_type
*ft
)
1099 return bt_field_type_common_sequence_get_length_field_name((void *) ft
);
1102 struct bt_ctf_field_type
*bt_ctf_field_type_string_create(void)
1104 struct bt_field_type_common_string
*string
=
1105 g_new0(struct bt_field_type_common_string
, 1);
1107 BT_LOGD_STR("Creating CTF writer string field type object.");
1110 BT_LOGE_STR("Failed to allocate one string field type.");
1114 bt_field_type_common_string_initialize(BT_TO_COMMON(string
),
1115 bt_field_type_common_string_destroy
,
1116 &bt_ctf_field_type_string_methods
);
1117 string
->common
.spec
.writer
.serialize_func
=
1118 bt_ctf_field_type_string_serialize
;
1119 BT_LOGD("Created CTF writer string field type object: addr=%p", string
);
1120 return (void *) string
;
1123 enum bt_ctf_string_encoding
bt_ctf_field_type_string_get_encoding(
1124 struct bt_ctf_field_type
*ft
)
1126 return (int) bt_field_type_common_string_get_encoding((void *) ft
);
1129 int bt_ctf_field_type_string_set_encoding(struct bt_ctf_field_type
*ft
,
1130 enum bt_ctf_string_encoding encoding
)
1132 return bt_field_type_common_string_set_encoding((void *) ft
,
1136 int bt_ctf_field_type_get_alignment(struct bt_ctf_field_type
*ft
)
1138 return bt_field_type_common_get_alignment((void *) ft
);
1141 int bt_ctf_field_type_set_alignment(struct bt_ctf_field_type
*ft
,
1142 unsigned int alignment
)
1144 return bt_field_type_common_set_alignment((void *) ft
, alignment
);
1147 enum bt_ctf_byte_order
bt_ctf_field_type_get_byte_order(
1148 struct bt_ctf_field_type
*ft
)
1150 return (int) bt_field_type_common_get_byte_order((void *) ft
);
1153 int bt_ctf_field_type_set_byte_order(struct bt_ctf_field_type
*ft
,
1154 enum bt_ctf_byte_order byte_order
)
1156 return bt_field_type_common_set_byte_order((void *) ft
,
1160 enum bt_ctf_field_type_id
bt_ctf_field_type_get_type_id(
1161 struct bt_ctf_field_type
*ft
)
1163 return (int) bt_field_type_common_get_type_id((void *) ft
);
1167 struct bt_ctf_field_type
*bt_ctf_field_type_copy(struct bt_ctf_field_type
*ft
)
1169 return (void *) bt_field_type_common_copy((void *) ft
);
1173 struct bt_ctf_field_type
*bt_ctf_field_type_integer_copy(
1174 struct bt_ctf_field_type
*ft
)
1176 struct bt_field_type_common_integer
*int_ft
= (void *) ft
;
1177 struct bt_field_type_common_integer
*copy_ft
;
1179 BT_LOGD("Copying CTF writer integer field type's: addr=%p", ft
);
1180 copy_ft
= (void *) bt_ctf_field_type_integer_create(int_ft
->size
);
1182 BT_LOGE_STR("Cannot create CTF writer integer field type.");
1186 copy_ft
->mapped_clock_class
= bt_get(int_ft
->mapped_clock_class
);
1187 copy_ft
->user_byte_order
= int_ft
->user_byte_order
;
1188 copy_ft
->is_signed
= int_ft
->is_signed
;
1189 copy_ft
->size
= int_ft
->size
;
1190 copy_ft
->base
= int_ft
->base
;
1191 copy_ft
->encoding
= int_ft
->encoding
;
1192 BT_LOGD("Copied CTF writer integer field type: original-ft-addr=%p, copy-ft-addr=%p",
1196 return (void *) copy_ft
;
1200 struct bt_ctf_field_type
*bt_ctf_field_type_enumeration_copy_recursive(
1201 struct bt_ctf_field_type
*ft
)
1204 struct bt_field_type_common_enumeration
*enum_ft
= (void *) ft
;
1205 struct bt_field_type_common_enumeration
*copy_ft
= NULL
;
1206 struct bt_field_type_common_enumeration
*container_copy_ft
;
1208 BT_LOGD("Copying CTF writer enumeration field type's: addr=%p", ft
);
1210 /* Copy the source enumeration's container */
1211 BT_LOGD_STR("Copying CTF writer enumeration field type's container field type.");
1212 container_copy_ft
= BT_FROM_COMMON(bt_field_type_common_copy(
1213 BT_TO_COMMON(enum_ft
->container_ft
)));
1214 if (!container_copy_ft
) {
1215 BT_LOGE_STR("Cannot copy CTF writer enumeration field type's container field type.");
1219 copy_ft
= (void *) bt_ctf_field_type_enumeration_create(
1220 (void *) container_copy_ft
);
1222 BT_LOGE_STR("Cannot create CTF writer enumeration field type.");
1226 /* Copy all enumaration entries */
1227 for (i
= 0; i
< enum_ft
->entries
->len
; i
++) {
1228 struct enumeration_mapping
*mapping
= g_ptr_array_index(
1229 enum_ft
->entries
, i
);
1230 struct enumeration_mapping
*copy_mapping
= g_new0(
1231 struct enumeration_mapping
, 1);
1233 if (!copy_mapping
) {
1234 BT_LOGE_STR("Failed to allocate one enumeration mapping.");
1238 *copy_mapping
= *mapping
;
1239 g_ptr_array_add(copy_ft
->entries
, copy_mapping
);
1242 BT_LOGD("Copied CTF writer enumeration field type: original-ft-addr=%p, copy-ft-addr=%p",
1246 bt_put(container_copy_ft
);
1247 return (void *) copy_ft
;
1250 bt_put(container_copy_ft
);
1252 return (void *) copy_ft
;
1256 struct bt_ctf_field_type
*bt_ctf_field_type_floating_point_copy(
1257 struct bt_ctf_field_type
*ft
)
1259 struct bt_field_type_common_floating_point
*flt_ft
= BT_FROM_COMMON(ft
);
1260 struct bt_field_type_common_floating_point
*copy_ft
;
1262 BT_LOGD("Copying CTF writer floating point number field type's: addr=%p", ft
);
1263 copy_ft
= (void *) bt_ctf_field_type_floating_point_create();
1265 BT_LOGE_STR("Cannot create CTF writer floating point number field type.");
1269 copy_ft
->user_byte_order
= flt_ft
->user_byte_order
;
1270 copy_ft
->exp_dig
= flt_ft
->exp_dig
;
1271 copy_ft
->mant_dig
= flt_ft
->mant_dig
;
1272 BT_LOGD("Copied CTF writer floating point number field type: original-ft-addr=%p, copy-ft-addr=%p",
1276 return (void *) copy_ft
;
1280 struct bt_ctf_field_type
*bt_ctf_field_type_structure_copy_recursive(
1281 struct bt_ctf_field_type
*ft
)
1284 GHashTableIter iter
;
1285 gpointer key
, value
;
1286 struct bt_field_type_common_structure
*struct_ft
= (void *) ft
;
1287 struct bt_field_type_common_structure
*copy_ft
;
1289 BT_LOGD("Copying CTF writer structure field type's: addr=%p", ft
);
1290 copy_ft
= (void *) bt_ctf_field_type_structure_create();
1292 BT_LOGE_STR("Cannot create CTF writer structure field type.");
1296 /* Copy field_name_to_index */
1297 g_hash_table_iter_init(&iter
, struct_ft
->field_name_to_index
);
1298 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
1299 g_hash_table_insert(copy_ft
->field_name_to_index
,
1303 for (i
= 0; i
< struct_ft
->fields
->len
; i
++) {
1304 struct structure_field_common
*entry
, *copy_entry
;
1305 struct bt_field_type_common
*field_ft_copy
;
1307 entry
= g_ptr_array_index(struct_ft
->fields
, i
);
1308 BT_LOGD("Copying CTF writer structure field type's field: "
1309 "index=%" PRId64
", "
1310 "field-ft-addr=%p, field-name=\"%s\"",
1311 i
, entry
, g_quark_to_string(entry
->name
));
1312 copy_entry
= g_new0(struct structure_field_common
, 1);
1314 BT_LOGE_STR("Failed to allocate one structure field type field.");
1318 field_ft_copy
= (void *) bt_ctf_field_type_copy(
1319 (void *) entry
->type
);
1320 if (!field_ft_copy
) {
1321 BT_LOGE("Cannot copy CTF writer structure field type's field: "
1322 "index=%" PRId64
", "
1323 "field-ft-addr=%p, field-name=\"%s\"",
1324 i
, entry
, g_quark_to_string(entry
->name
));
1329 copy_entry
->name
= entry
->name
;
1330 copy_entry
->type
= field_ft_copy
;
1331 g_ptr_array_add(copy_ft
->fields
, copy_entry
);
1334 BT_LOGD("Copied CTF writer structure field type: original-ft-addr=%p, copy-ft-addr=%p",
1338 return (void *) copy_ft
;
1346 struct bt_ctf_field_type
*bt_ctf_field_type_variant_copy_recursive(
1347 struct bt_ctf_field_type
*ft
)
1350 GHashTableIter iter
;
1351 gpointer key
, value
;
1352 struct bt_field_type_common
*tag_ft_copy
= NULL
;
1353 struct bt_field_type_common_variant
*var_ft
= (void *) ft
;
1354 struct bt_field_type_common_variant
*copy_ft
= NULL
;
1356 BT_LOGD("Copying CTF writer variant field type's: addr=%p", ft
);
1357 if (var_ft
->tag_ft
) {
1358 BT_LOGD_STR("Copying CTF writer variant field type's tag field type.");
1359 tag_ft_copy
= bt_field_type_common_copy(
1360 BT_TO_COMMON(var_ft
->tag_ft
));
1362 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field type.");
1367 copy_ft
= (void *) bt_ctf_field_type_variant_create(
1368 (void *) tag_ft_copy
,
1369 var_ft
->tag_name
->len
? var_ft
->tag_name
->str
: NULL
);
1371 BT_LOGE_STR("Cannot create CTF writer variant field type.");
1375 /* Copy field_name_to_index */
1376 g_hash_table_iter_init(&iter
, var_ft
->field_name_to_index
);
1377 while (g_hash_table_iter_next(&iter
, &key
, &value
)) {
1378 g_hash_table_insert(copy_ft
->field_name_to_index
,
1382 for (i
= 0; i
< var_ft
->fields
->len
; i
++) {
1383 struct structure_field_common
*entry
, *copy_entry
;
1384 struct bt_field_type_common
*field_ft_copy
;
1386 entry
= g_ptr_array_index(var_ft
->fields
, i
);
1387 BT_LOGD("Copying CTF writer variant field type's field: "
1388 "index=%" PRId64
", "
1389 "field-ft-addr=%p, field-name=\"%s\"",
1390 i
, entry
, g_quark_to_string(entry
->name
));
1391 copy_entry
= g_new0(struct structure_field_common
, 1);
1393 BT_LOGE_STR("Failed to allocate one variant field type field.");
1397 field_ft_copy
= (void *) bt_ctf_field_type_copy(
1398 (void *) entry
->type
);
1399 if (!field_ft_copy
) {
1400 BT_LOGE("Cannot copy CTF writer variant field type's field: "
1401 "index=%" PRId64
", "
1402 "field-ft-addr=%p, field-name=\"%s\"",
1403 i
, entry
, g_quark_to_string(entry
->name
));
1408 copy_entry
->name
= entry
->name
;
1409 copy_entry
->type
= field_ft_copy
;
1410 g_ptr_array_add(copy_ft
->fields
, copy_entry
);
1413 if (var_ft
->tag_field_path
) {
1414 BT_LOGD_STR("Copying CTF writer variant field type's tag field path.");
1415 copy_ft
->tag_field_path
= bt_field_path_copy(
1416 var_ft
->tag_field_path
);
1417 if (!copy_ft
->tag_field_path
) {
1418 BT_LOGE_STR("Cannot copy CTF writer variant field type's tag field path.");
1423 BT_LOGD("Copied variant field type: original-ft-addr=%p, copy-ft-addr=%p",
1427 bt_put(tag_ft_copy
);
1428 return (void *) copy_ft
;
1431 bt_put(tag_ft_copy
);
1437 struct bt_ctf_field_type
*bt_ctf_field_type_array_copy_recursive(
1438 struct bt_ctf_field_type
*ft
)
1440 struct bt_field_type_common
*container_ft_copy
= NULL
;
1441 struct bt_field_type_common_array
*array_ft
= (void *) ft
;
1442 struct bt_field_type_common_array
*copy_ft
= NULL
;
1444 BT_LOGD("Copying CTF writer array field type's: addr=%p", ft
);
1445 BT_LOGD_STR("Copying CTF writer array field type's element field type.");
1446 container_ft_copy
= bt_field_type_common_copy(array_ft
->element_ft
);
1447 if (!container_ft_copy
) {
1448 BT_LOGE_STR("Cannot copy CTF writer array field type's element field type.");
1452 copy_ft
= (void *) bt_ctf_field_type_array_create(
1453 (void *) container_ft_copy
, array_ft
->length
);
1455 BT_LOGE_STR("Cannot create CTF writer array field type.");
1459 BT_LOGD("Copied CTF writer array field type: original-ft-addr=%p, copy-ft-addr=%p",
1463 bt_put(container_ft_copy
);
1464 return (void *) copy_ft
;
1468 struct bt_ctf_field_type
*bt_ctf_field_type_sequence_copy_recursive(
1469 struct bt_ctf_field_type
*ft
)
1471 struct bt_field_type_common
*container_ft_copy
= NULL
;
1472 struct bt_field_type_common_sequence
*seq_ft
= (void *) ft
;
1473 struct bt_field_type_common_sequence
*copy_ft
= NULL
;
1475 BT_LOGD("Copying CTF writer sequence field type's: addr=%p", ft
);
1476 BT_LOGD_STR("Copying CTF writer sequence field type's element field type.");
1477 container_ft_copy
= bt_field_type_common_copy(seq_ft
->element_ft
);
1478 if (!container_ft_copy
) {
1479 BT_LOGE_STR("Cannot copy CTF writer sequence field type's element field type.");
1483 copy_ft
= (void *) bt_ctf_field_type_sequence_create(
1484 (void *) container_ft_copy
,
1485 seq_ft
->length_field_name
->len
?
1486 seq_ft
->length_field_name
->str
: NULL
);
1488 BT_LOGE_STR("Cannot create CTF writer sequence field type.");
1492 if (seq_ft
->length_field_path
) {
1493 BT_LOGD_STR("Copying CTF writer sequence field type's length field path.");
1494 copy_ft
->length_field_path
= bt_field_path_copy(
1495 seq_ft
->length_field_path
);
1496 if (!copy_ft
->length_field_path
) {
1497 BT_LOGE_STR("Cannot copy CTF writer sequence field type's length field path.");
1502 BT_LOGD("Copied CTF writer sequence field type: original-ft-addr=%p, copy-ft-addr=%p",
1506 bt_put(container_ft_copy
);
1507 return (void *) copy_ft
;
1509 bt_put(container_ft_copy
);
1515 struct bt_ctf_field_type
*bt_ctf_field_type_string_copy(struct bt_ctf_field_type
*ft
)
1517 struct bt_field_type_common_string
*string_ft
= (void *) ft
;
1518 struct bt_field_type_common_string
*copy_ft
= NULL
;
1520 BT_LOGD("Copying CTF writer string field type's: addr=%p", ft
);
1521 copy_ft
= (void *) bt_ctf_field_type_string_create();
1523 BT_LOGE_STR("Cannot create CTF writer string field type.");
1527 copy_ft
->encoding
= string_ft
->encoding
;
1528 BT_LOGD("Copied CTF writer string field type: original-ft-addr=%p, copy-ft-addr=%p",
1532 return (void *) copy_ft
;