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-FIELDS"
26 #include <babeltrace/lib-logging-internal.h>
28 #include <babeltrace/compat/fcntl-internal.h>
29 #include <babeltrace/ctf-writer/fields-internal.h>
30 #include <babeltrace/ctf-writer/field-types-internal.h>
31 #include <babeltrace/ctf-writer/serialize-internal.h>
32 #include <babeltrace/ctf-ir/fields-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/assert-pre-internal.h>
35 #include <babeltrace/object-internal.h>
36 #include <babeltrace/ref.h>
37 #include <babeltrace/compiler-internal.h>
38 #include <babeltrace/endian-internal.h>
39 #include <babeltrace/assert-internal.h>
44 static struct bt_field_common_methods bt_ctf_field_integer_methods
= {
45 .freeze
= bt_field_common_generic_freeze
,
46 .validate
= bt_field_common_generic_validate
,
48 .is_set
= bt_field_common_generic_is_set
,
49 .reset
= bt_field_common_generic_reset
,
52 static struct bt_field_common_methods bt_ctf_field_floating_point_methods
= {
53 .freeze
= bt_field_common_generic_freeze
,
54 .validate
= bt_field_common_generic_validate
,
56 .is_set
= bt_field_common_generic_is_set
,
57 .reset
= bt_field_common_generic_reset
,
60 static struct bt_field_common_methods bt_ctf_field_enumeration_methods
= {
61 .freeze
= bt_field_common_enumeration_freeze_recursive
,
62 .validate
= bt_field_common_enumeration_validate_recursive
,
64 .is_set
= bt_field_common_enumeration_is_set_recursive
,
65 .reset
= bt_field_common_enumeration_reset_recursive
,
68 static struct bt_field_common_methods bt_ctf_field_string_methods
= {
69 .freeze
= bt_field_common_generic_freeze
,
70 .validate
= bt_field_common_generic_validate
,
72 .is_set
= bt_field_common_generic_is_set
,
73 .reset
= bt_field_common_generic_reset
,
76 static struct bt_field_common_methods bt_ctf_field_structure_methods
= {
77 .freeze
= bt_field_common_structure_freeze_recursive
,
78 .validate
= bt_field_common_structure_validate_recursive
,
80 .is_set
= bt_field_common_structure_is_set_recursive
,
81 .reset
= bt_field_common_structure_reset_recursive
,
84 static struct bt_field_common_methods bt_ctf_field_sequence_methods
= {
85 .freeze
= bt_field_common_sequence_freeze_recursive
,
86 .validate
= bt_field_common_sequence_validate_recursive
,
88 .is_set
= bt_field_common_sequence_is_set_recursive
,
89 .reset
= bt_field_common_sequence_reset_recursive
,
92 static struct bt_field_common_methods bt_ctf_field_array_methods
= {
93 .freeze
= bt_field_common_array_freeze_recursive
,
94 .validate
= bt_field_common_array_validate_recursive
,
96 .is_set
= bt_field_common_array_is_set_recursive
,
97 .reset
= bt_field_common_array_reset_recursive
,
100 static struct bt_field_common_methods bt_ctf_field_variant_methods
= {
101 .freeze
= bt_field_common_variant_freeze_recursive
,
102 .validate
= bt_field_common_variant_validate_recursive
,
104 .is_set
= bt_field_common_variant_is_set_recursive
,
105 .reset
= bt_field_common_variant_reset_recursive
,
109 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*);
112 struct bt_ctf_field
*bt_ctf_field_enumeration_create(struct bt_ctf_field_type
*);
115 struct bt_ctf_field
*bt_ctf_field_floating_point_create(struct bt_ctf_field_type
*);
118 struct bt_ctf_field
*bt_ctf_field_structure_create(struct bt_ctf_field_type
*);
121 struct bt_ctf_field
*bt_ctf_field_variant_create(struct bt_ctf_field_type
*);
124 struct bt_ctf_field
*bt_ctf_field_array_create(struct bt_ctf_field_type
*);
127 struct bt_ctf_field
*bt_ctf_field_sequence_create(struct bt_ctf_field_type
*);
130 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*);
133 struct bt_ctf_field
*(* const field_create_funcs
[])(struct bt_ctf_field_type
*) = {
134 [BT_FIELD_TYPE_ID_INTEGER
] = bt_ctf_field_integer_create
,
135 [BT_FIELD_TYPE_ID_ENUM
] = bt_ctf_field_enumeration_create
,
136 [BT_FIELD_TYPE_ID_FLOAT
] = bt_ctf_field_floating_point_create
,
137 [BT_FIELD_TYPE_ID_STRUCT
] = bt_ctf_field_structure_create
,
138 [BT_FIELD_TYPE_ID_VARIANT
] = bt_ctf_field_variant_create
,
139 [BT_FIELD_TYPE_ID_ARRAY
] = bt_ctf_field_array_create
,
140 [BT_FIELD_TYPE_ID_SEQUENCE
] = bt_ctf_field_sequence_create
,
141 [BT_FIELD_TYPE_ID_STRING
] = bt_ctf_field_string_create
,
144 typedef int (*bt_ctf_field_serialize_recursive_func
)(
145 struct bt_field_common
*, struct bt_ctf_stream_pos
*,
146 enum bt_ctf_byte_order
);
149 int bt_ctf_field_serialize_recursive(struct bt_ctf_field
*field
,
150 struct bt_ctf_stream_pos
*pos
,
151 enum bt_ctf_byte_order native_byte_order
)
153 struct bt_field_common
*field_common
= (void *) field
;
154 bt_ctf_field_serialize_recursive_func serialize_func
;
157 BT_ASSERT_PRE_NON_NULL(field
, "Field");
158 BT_ASSERT(field_common
->spec
.writer
.serialize_func
);
159 serialize_func
= field_common
->spec
.writer
.serialize_func
;
160 return serialize_func(field_common
, pos
,
165 int increase_packet_size(struct bt_ctf_stream_pos
*pos
)
170 BT_LOGV("Increasing packet size: pos-offset=%" PRId64
", "
171 "cur-packet-size=%" PRIu64
,
172 pos
->offset
, pos
->packet_size
);
173 ret
= munmap_align(pos
->base_mma
);
175 BT_LOGE_ERRNO("Failed to perform an aligned memory unmapping",
180 pos
->packet_size
+= PACKET_LEN_INCREMENT
;
182 ret
= bt_posix_fallocate(pos
->fd
, pos
->mmap_offset
,
183 pos
->packet_size
/ CHAR_BIT
);
184 } while (ret
== EINTR
);
186 BT_LOGE_ERRNO("Failed to preallocate memory space",
193 pos
->base_mma
= mmap_align(pos
->packet_size
/ CHAR_BIT
, pos
->prot
,
194 pos
->flags
, pos
->fd
, pos
->mmap_offset
);
195 if (pos
->base_mma
== MAP_FAILED
) {
196 BT_LOGE_ERRNO("Failed to perform an aligned memory mapping",
201 BT_LOGV("Increased packet size: pos-offset=%" PRId64
", "
202 "new-packet-size=%" PRIu64
,
203 pos
->offset
, pos
->packet_size
);
204 BT_ASSERT(pos
->packet_size
% 8 == 0);
211 int bt_ctf_field_integer_serialize(struct bt_field_common
*field
,
212 struct bt_ctf_stream_pos
*pos
,
213 enum bt_ctf_byte_order native_byte_order
)
217 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "Integer field");
218 BT_LOGV("Serializing CTF writer integer field: addr=%p, pos-offset=%" PRId64
", "
219 "native-bo=%s", field
, pos
->offset
,
220 bt_common_byte_order_string((int) native_byte_order
));
223 ret
= bt_ctf_field_integer_write(field
, pos
, native_byte_order
);
224 if (ret
== -EFAULT
) {
226 * The field is too large to fit in the current packet's
227 * remaining space. Bump the packet size and retry.
229 ret
= increase_packet_size(pos
);
231 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
242 int bt_ctf_field_enumeration_serialize_recursive(struct bt_field_common
*field
,
243 struct bt_ctf_stream_pos
*pos
,
244 enum bt_ctf_byte_order native_byte_order
)
246 struct bt_field_common_enumeration
*enumeration
= BT_FROM_COMMON(field
);
248 BT_LOGV("Serializing enumeration field: addr=%p, pos-offset=%" PRId64
", "
249 "native-bo=%s", field
, pos
->offset
,
250 bt_common_byte_order_string((int) native_byte_order
));
251 BT_LOGV_STR("Serializing enumeration field's payload field.");
252 return bt_ctf_field_serialize_recursive((void *) enumeration
->payload
,
253 pos
, native_byte_order
);
257 int bt_ctf_field_floating_point_serialize(struct bt_field_common
*field
,
258 struct bt_ctf_stream_pos
*pos
,
259 enum bt_ctf_byte_order native_byte_order
)
263 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "Floating point number field");
264 BT_LOGV("Serializing floating point number field: addr=%p, pos-offset=%" PRId64
", "
265 "native-bo=%s", field
, pos
->offset
,
266 bt_common_byte_order_string((int) native_byte_order
));
269 ret
= bt_ctf_field_floating_point_write(field
, pos
,
271 if (ret
== -EFAULT
) {
273 * The field is too large to fit in the current packet's
274 * remaining space. Bump the packet size and retry.
276 ret
= increase_packet_size(pos
);
278 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
289 int bt_ctf_field_structure_serialize_recursive(struct bt_field_common
*field
,
290 struct bt_ctf_stream_pos
*pos
,
291 enum bt_ctf_byte_order native_byte_order
)
295 struct bt_field_common_structure
*structure
= BT_FROM_COMMON(field
);
297 BT_LOGV("Serializing structure field: addr=%p, pos-offset=%" PRId64
", "
298 "native-bo=%s", field
, pos
->offset
,
299 bt_common_byte_order_string((int) native_byte_order
));
301 while (!bt_ctf_stream_pos_access_ok(pos
,
302 offset_align(pos
->offset
, field
->type
->alignment
))) {
303 ret
= increase_packet_size(pos
);
305 BT_LOGE("Cannot increase packet size: ret=%d", ret
);
310 if (!bt_ctf_stream_pos_align(pos
, field
->type
->alignment
)) {
311 BT_LOGE("Cannot align packet's position: pos-offset=%" PRId64
", "
312 "align=%u", pos
->offset
, field
->type
->alignment
);
317 for (i
= 0; i
< structure
->fields
->len
; i
++) {
318 struct bt_field_common
*member
= g_ptr_array_index(
319 structure
->fields
, i
);
320 const char *field_name
= NULL
;
322 BT_LOGV("Serializing structure field's field: pos-offset=%" PRId64
", "
323 "field-addr=%p, index=%" PRId64
,
324 pos
->offset
, member
, i
);
327 ret
= bt_field_type_common_structure_get_field_by_index(
328 field
->type
, &field_name
, NULL
, i
);
330 BT_LOGW("Cannot serialize structure field's field: field is not set: "
331 "struct-field-addr=%p, "
332 "field-name=\"%s\", index=%" PRId64
,
333 field
, field_name
, i
);
338 ret
= bt_ctf_field_serialize_recursive((void *) member
, pos
,
341 ret
= bt_field_type_common_structure_get_field_by_index(
342 field
->type
, &field_name
, NULL
, i
);
344 BT_LOGW("Cannot serialize structure field's field: "
345 "struct-field-addr=%p, field-addr=%p, "
346 "field-name=\"%s\", index=%" PRId64
,
347 field
->type
, member
, field_name
, i
);
357 int bt_ctf_field_variant_serialize_recursive(struct bt_field_common
*field
,
358 struct bt_ctf_stream_pos
*pos
,
359 enum bt_ctf_byte_order native_byte_order
)
361 struct bt_field_common_variant
*variant
= BT_FROM_COMMON(field
);
363 BT_LOGV("Serializing variant field: addr=%p, pos-offset=%" PRId64
", "
364 "native-bo=%s", field
, pos
->offset
,
365 bt_common_byte_order_string((int) native_byte_order
));
366 BT_LOGV_STR("Serializing variant field's payload field.");
367 return bt_ctf_field_serialize_recursive(
368 (void *) variant
->payload
, pos
, native_byte_order
);
372 int bt_ctf_field_array_serialize_recursive(struct bt_field_common
*field
,
373 struct bt_ctf_stream_pos
*pos
,
374 enum bt_ctf_byte_order native_byte_order
)
378 struct bt_field_common_array
*array
= BT_FROM_COMMON(field
);
380 BT_LOGV("Serializing array field: addr=%p, pos-offset=%" PRId64
", "
381 "native-bo=%s", field
, pos
->offset
,
382 bt_common_byte_order_string((int) native_byte_order
));
384 for (i
= 0; i
< array
->elements
->len
; i
++) {
385 struct bt_field_common
*elem_field
=
386 g_ptr_array_index(array
->elements
, i
);
388 BT_LOGV("Serializing array field's element field: "
389 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
390 pos
->offset
, elem_field
, i
);
391 ret
= bt_ctf_field_serialize_recursive(
392 (void *) elem_field
, pos
, native_byte_order
);
394 BT_LOGW("Cannot serialize array field's element field: "
395 "array-field-addr=%p, field-addr=%p, "
396 "index=%" PRId64
, field
, elem_field
, i
);
406 int bt_ctf_field_sequence_serialize_recursive(struct bt_field_common
*field
,
407 struct bt_ctf_stream_pos
*pos
,
408 enum bt_ctf_byte_order native_byte_order
)
412 struct bt_field_common_sequence
*sequence
= BT_FROM_COMMON(field
);
414 BT_LOGV("Serializing sequence field: addr=%p, pos-offset=%" PRId64
", "
415 "native-bo=%s", field
, pos
->offset
,
416 bt_common_byte_order_string((int) native_byte_order
));
418 for (i
= 0; i
< sequence
->elements
->len
; i
++) {
419 struct bt_field_common
*elem_field
=
420 g_ptr_array_index(sequence
->elements
, i
);
422 BT_LOGV("Serializing sequence field's element field: "
423 "pos-offset=%" PRId64
", field-addr=%p, index=%" PRId64
,
424 pos
->offset
, elem_field
, i
);
425 ret
= bt_ctf_field_serialize_recursive(
426 (void *) elem_field
, pos
, native_byte_order
);
428 BT_LOGW("Cannot serialize sequence field's element field: "
429 "sequence-field-addr=%p, field-addr=%p, "
430 "index=%" PRId64
, field
, elem_field
, i
);
440 int bt_ctf_field_string_serialize(struct bt_field_common
*field
,
441 struct bt_ctf_stream_pos
*pos
,
442 enum bt_ctf_byte_order native_byte_order
)
446 struct bt_field_common_string
*string
= BT_FROM_COMMON(field
);
447 struct bt_ctf_field_type
*character_type
=
448 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
449 struct bt_ctf_field
*character
;
451 BT_ASSERT_PRE_FIELD_COMMON_IS_SET(field
, "String field");
452 BT_LOGV("Serializing string field: addr=%p, pos-offset=%" PRId64
", "
453 "native-bo=%s", field
, pos
->offset
,
454 bt_common_byte_order_string((int) native_byte_order
));
456 BT_LOGV_STR("Creating character field from string field's character field type.");
457 character
= bt_ctf_field_create(character_type
);
459 for (i
= 0; i
< string
->payload
->len
+ 1; i
++) {
460 const uint64_t chr
= (uint64_t) string
->payload
->str
[i
];
462 ret
= bt_ctf_field_integer_unsigned_set_value(character
, chr
);
464 BT_LOGV("Serializing string field's character field: "
465 "pos-offset=%" PRId64
", field-addr=%p, "
466 "index=%" PRId64
", char-int=%" PRIu64
,
467 pos
->offset
, character
, i
, chr
);
468 ret
= bt_ctf_field_integer_serialize(
469 (void *) character
, pos
, native_byte_order
);
471 BT_LOGW_STR("Cannot serialize character field.");
478 bt_put(character_type
);
482 struct bt_ctf_field
*bt_ctf_field_create(struct bt_ctf_field_type
*type
)
484 struct bt_ctf_field
*field
= NULL
;
485 enum bt_ctf_field_type_id type_id
;
487 BT_ASSERT_PRE_NON_NULL(type
, "Field type");
488 BT_ASSERT(field_type_common_has_known_id((void *) type
));
489 BT_ASSERT_PRE(bt_field_type_common_validate((void *) type
) == 0,
490 "Field type is invalid: %!+wF", type
);
491 type_id
= bt_ctf_field_type_get_type_id(type
);
492 field
= field_create_funcs
[type_id
](type
);
497 bt_field_type_common_freeze((void *) type
);
503 struct bt_ctf_field_type
*bt_ctf_field_get_type(struct bt_ctf_field
*field
)
505 return (void *) bt_field_common_get_type((void *) field
);
508 enum bt_ctf_field_type_id
bt_ctf_field_get_type_id(struct bt_ctf_field
*field
)
510 struct bt_field_common
*field_common
= (void *) field
;
512 BT_ASSERT_PRE_NON_NULL(field
, "Field");
513 return (int) field_common
->type
->id
;
516 struct bt_ctf_field
*bt_ctf_field_sequence_get_length(
517 struct bt_ctf_field
*field
)
519 return (void *) bt_field_common_sequence_get_length((void *) field
);
522 int bt_ctf_field_sequence_set_length(struct bt_ctf_field
*field
,
523 struct bt_ctf_field
*length_field
)
525 return bt_field_common_sequence_set_length((void *) field
,
526 (void *) length_field
);
529 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_index(
530 struct bt_ctf_field
*field
, uint64_t index
)
532 return (void *) bt_field_common_structure_get_field_by_index(
533 (void *) field
, index
);
536 struct bt_ctf_field
*bt_ctf_field_structure_get_field_by_name(
537 struct bt_ctf_field
*field
, const char *name
)
539 return (void *) bt_field_common_structure_get_field_by_name(
540 (void *) field
, name
);
543 int bt_ctf_field_structure_set_field_by_name(struct bt_ctf_field
*field
,
544 const char *name
, struct bt_ctf_field
*value
)
546 return bt_field_common_structure_set_field_by_name((void *) field
,
547 name
, (void *) value
);
550 struct bt_ctf_field
*bt_ctf_field_array_get_field(
551 struct bt_ctf_field
*field
, uint64_t index
)
553 return (void *) bt_field_common_array_get_field((void *) field
, index
,
554 (bt_field_common_create_func
) bt_ctf_field_create
);
557 struct bt_ctf_field
*bt_ctf_field_sequence_get_field(
558 struct bt_ctf_field
*field
, uint64_t index
)
560 return (void *) bt_field_common_sequence_get_field((void *) field
,
561 index
, (bt_field_common_create_func
) bt_ctf_field_create
);
564 struct bt_ctf_field
*bt_ctf_field_variant_get_field(struct bt_ctf_field
*field
,
565 struct bt_ctf_field
*tag_field
)
567 return (void *) bt_field_common_variant_get_field((void *) field
,
569 (bt_field_common_create_func
) bt_ctf_field_create
);
572 struct bt_ctf_field
*bt_ctf_field_variant_get_current_field(
573 struct bt_ctf_field
*variant_field
)
575 return (void *) bt_field_common_variant_get_current_field(
576 (void *) variant_field
);
579 struct bt_ctf_field
*bt_ctf_field_variant_get_tag(
580 struct bt_ctf_field
*variant_field
)
582 return (void *) bt_field_common_variant_get_tag((void *) variant_field
);
585 struct bt_ctf_field
*bt_ctf_field_enumeration_get_container(struct bt_ctf_field
*field
)
587 return (void *) bt_field_common_enumeration_get_container(
588 (void *) field
, (bt_field_common_create_func
) bt_ctf_field_create
);
591 int bt_ctf_field_integer_signed_get_value(struct bt_ctf_field
*field
, int64_t *value
)
593 return bt_field_common_integer_signed_get_value((void *) field
, value
);
596 int bt_ctf_field_integer_signed_set_value(struct bt_ctf_field
*field
,
599 return bt_field_common_integer_signed_set_value((void *) field
, value
);
602 int bt_ctf_field_integer_unsigned_get_value(struct bt_ctf_field
*field
,
605 return bt_field_common_integer_unsigned_get_value((void *) field
,
609 int bt_ctf_field_integer_unsigned_set_value(struct bt_ctf_field
*field
, uint64_t value
)
611 return bt_field_common_integer_unsigned_set_value((void *) field
, value
);
614 int bt_ctf_field_floating_point_get_value(struct bt_ctf_field
*field
,
617 return bt_field_common_floating_point_get_value((void *) field
, value
);
620 int bt_ctf_field_floating_point_set_value(struct bt_ctf_field
*field
,
623 return bt_field_common_floating_point_set_value((void *) field
, value
);
626 const char *bt_ctf_field_string_get_value(struct bt_ctf_field
*field
)
628 return bt_field_common_string_get_value((void *) field
);
631 int bt_ctf_field_string_set_value(struct bt_ctf_field
*field
, const char *value
)
633 return bt_field_common_string_set_value((void *) field
, value
);
636 int bt_ctf_field_string_append(struct bt_ctf_field
*field
, const char *value
)
638 return bt_field_common_string_append((void *) field
, value
);
641 int bt_ctf_field_string_append_len(struct bt_ctf_field
*field
,
642 const char *value
, unsigned int length
)
644 return bt_field_common_string_append_len((void *) field
, value
, length
);
647 struct bt_ctf_field
*bt_ctf_field_copy(struct bt_ctf_field
*field
)
649 return (void *) bt_field_common_copy((void *) field
);
653 struct bt_ctf_field
*bt_ctf_field_integer_create(struct bt_ctf_field_type
*type
)
655 struct bt_field_common_integer
*integer
=
656 g_new0(struct bt_field_common_integer
, 1);
658 BT_LOGD("Creating CTF writer integer field object: ft-addr=%p", type
);
661 bt_field_common_initialize(BT_TO_COMMON(integer
), (void *) type
,
662 bt_field_common_integer_destroy
,
663 &bt_ctf_field_integer_methods
);
664 integer
->common
.spec
.writer
.serialize_func
=
665 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_integer_serialize
;
666 BT_LOGD("Created CTF writer integer field object: addr=%p, ft-addr=%p",
669 BT_LOGE_STR("Failed to allocate one integer field.");
672 return (void *) integer
;
676 struct bt_ctf_field
*bt_ctf_field_enumeration_create(
677 struct bt_ctf_field_type
*type
)
679 struct bt_field_common_enumeration
*enumeration
= g_new0(
680 struct bt_field_common_enumeration
, 1);
682 BT_LOGD("Creating CTF writer enumeration field object: ft-addr=%p", type
);
685 bt_field_common_initialize(BT_TO_COMMON(enumeration
),
687 bt_field_common_enumeration_destroy_recursive
,
688 &bt_ctf_field_enumeration_methods
);
689 enumeration
->common
.spec
.writer
.serialize_func
=
690 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_enumeration_serialize_recursive
;
691 BT_LOGD("Created CTF writer enumeration field object: addr=%p, ft-addr=%p",
694 BT_LOGE_STR("Failed to allocate one enumeration field.");
697 return (void *) enumeration
;
701 struct bt_ctf_field
*bt_ctf_field_floating_point_create(
702 struct bt_ctf_field_type
*type
)
704 struct bt_field_common_floating_point
*floating_point
;
706 BT_LOGD("Creating CTF writer floating point number field object: ft-addr=%p", type
);
707 floating_point
= g_new0(struct bt_field_common_floating_point
, 1);
709 if (floating_point
) {
710 bt_field_common_initialize(BT_TO_COMMON(floating_point
),
712 bt_field_common_floating_point_destroy
,
713 &bt_ctf_field_floating_point_methods
);
714 floating_point
->common
.spec
.writer
.serialize_func
=
715 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_floating_point_serialize
;
716 BT_LOGD("Created CTF writer floating point number field object: addr=%p, ft-addr=%p",
717 floating_point
, type
);
719 BT_LOGE_STR("Failed to allocate one floating point number field.");
722 return (void *) floating_point
;
726 struct bt_ctf_field
*bt_ctf_field_structure_create(
727 struct bt_ctf_field_type
*type
)
729 struct bt_field_common_structure
*structure
= g_new0(
730 struct bt_field_common_structure
, 1);
733 BT_LOGD("Creating CTF writer structure field object: ft-addr=%p", type
);
736 BT_LOGE_STR("Failed to allocate one structure field.");
740 iret
= bt_field_common_structure_initialize(BT_TO_COMMON(structure
),
741 (void *) type
, bt_field_common_structure_destroy_recursive
,
742 &bt_ctf_field_structure_methods
,
743 (bt_field_common_create_func
) bt_ctf_field_create
);
744 structure
->common
.spec
.writer
.serialize_func
=
745 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_structure_serialize_recursive
;
751 BT_LOGD("Created CTF writer structure field object: addr=%p, ft-addr=%p",
755 return (void *) structure
;
759 struct bt_ctf_field
*bt_ctf_field_variant_create(struct bt_ctf_field_type
*type
)
761 struct bt_field_common_variant
*variant
= g_new0(
762 struct bt_field_common_variant
, 1);
764 BT_LOGD("Creating CTF writer variant field object: ft-addr=%p", type
);
767 bt_field_common_initialize(BT_TO_COMMON(variant
),
769 bt_field_common_variant_destroy_recursive
,
770 &bt_ctf_field_variant_methods
);
771 variant
->common
.spec
.writer
.serialize_func
=
772 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_variant_serialize_recursive
;
773 BT_LOGD("Created CTF writer variant field object: addr=%p, ft-addr=%p",
776 BT_LOGE_STR("Failed to allocate one variant field.");
779 return (void *) variant
;
783 struct bt_ctf_field
*bt_ctf_field_array_create(struct bt_ctf_field_type
*type
)
785 struct bt_field_common_array
*array
=
786 g_new0(struct bt_field_common_array
, 1);
789 BT_LOGD("Creating CTF writer array field object: ft-addr=%p", type
);
793 BT_LOGE_STR("Failed to allocate one array field.");
797 ret
= bt_field_common_array_initialize(BT_TO_COMMON(array
),
799 bt_field_common_array_destroy_recursive
,
800 &bt_ctf_field_array_methods
);
801 array
->common
.spec
.writer
.serialize_func
=
802 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_array_serialize_recursive
;
808 BT_LOGD("Created CTF writer array field object: addr=%p, ft-addr=%p",
812 return (void *) array
;
816 struct bt_ctf_field
*bt_ctf_field_sequence_create(struct bt_ctf_field_type
*type
)
818 struct bt_field_common_sequence
*sequence
= g_new0(
819 struct bt_field_common_sequence
, 1);
821 BT_LOGD("Creating CTF writer sequence field object: ft-addr=%p", type
);
824 bt_field_common_initialize(BT_TO_COMMON(sequence
),
826 bt_field_common_sequence_destroy_recursive
,
827 &bt_ctf_field_sequence_methods
);
828 sequence
->common
.spec
.writer
.serialize_func
=
829 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_sequence_serialize_recursive
;
830 BT_LOGD("Created CTF writer sequence field object: addr=%p, ft-addr=%p",
833 BT_LOGE_STR("Failed to allocate one sequence field.");
836 return (void *) sequence
;
840 struct bt_ctf_field
*bt_ctf_field_string_create(struct bt_ctf_field_type
*type
)
842 struct bt_field_common_string
*string
= g_new0(
843 struct bt_field_common_string
, 1);
845 BT_LOGD("Creating CTF writer string field object: ft-addr=%p", type
);
848 bt_field_common_initialize(BT_TO_COMMON(string
),
850 bt_field_common_string_destroy
,
851 &bt_ctf_field_string_methods
);
852 string
->common
.spec
.writer
.serialize_func
=
853 (bt_ctf_field_serialize_recursive_func
) bt_ctf_field_string_serialize
;
854 BT_LOGD("Created CTF writer string field object: addr=%p, ft-addr=%p",
857 BT_LOGE_STR("Failed to allocate one string field.");
860 return (void *) string
;