4 * Babeltrace CTF IR - Stream
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf-ir/clock-class.h>
30 #include <babeltrace/ctf-writer/clock.h>
31 #include <babeltrace/ctf-writer/clock-internal.h>
32 #include <babeltrace/ctf-writer/event.h>
33 #include <babeltrace/ctf-ir/event-internal.h>
34 #include <babeltrace/ctf-ir/field-types-internal.h>
35 #include <babeltrace/ctf-ir/fields-internal.h>
36 #include <babeltrace/ctf-ir/stream.h>
37 #include <babeltrace/ctf-ir/stream-internal.h>
38 #include <babeltrace/ctf-ir/stream-class-internal.h>
39 #include <babeltrace/ctf-ir/trace-internal.h>
40 #include <babeltrace/ctf-writer/writer-internal.h>
41 #include <babeltrace/ref.h>
42 #include <babeltrace/ctf-writer/functor-internal.h>
43 #include <babeltrace/compiler.h>
44 #include <babeltrace/align.h>
45 #include <babeltrace/ctf/ctf-index.h>
48 void bt_ctf_stream_destroy(struct bt_object
*obj
);
50 int set_structure_field_integer(struct bt_ctf_field
*, char *, uint64_t);
53 int set_integer_field_value(struct bt_ctf_field
* field
, uint64_t value
)
56 struct bt_ctf_field_type
*field_type
= NULL
;
63 field_type
= bt_ctf_field_get_type(field
);
66 if (bt_ctf_field_type_get_type_id(field_type
) !=
67 BT_CTF_TYPE_ID_INTEGER
) {
68 /* Not an integer and the value is unset, error. */
73 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
74 ret
= bt_ctf_field_signed_integer_set_value(field
, (int64_t) value
);
76 /* Value is out of range, error. */
80 ret
= bt_ctf_field_unsigned_integer_set_value(field
, value
);
82 /* Value is out of range, error. */
92 int set_packet_header_magic(struct bt_ctf_stream
*stream
)
95 struct bt_ctf_field_type
*magic_field_type
= NULL
;
96 struct bt_ctf_field
*magic_field
= bt_ctf_field_structure_get_field(
97 stream
->packet_header
, "magic");
100 /* No magic field found. Not an error, skip. */
104 if (bt_ctf_field_is_set(magic_field
)) {
105 /* Value already set. Not an error, skip. */
109 magic_field_type
= bt_ctf_field_get_type(magic_field
);
110 assert(magic_field_type
);
112 if (bt_ctf_field_type_get_type_id(magic_field_type
) !=
113 BT_CTF_TYPE_ID_INTEGER
) {
114 /* Magic field is not an integer. Not an error, skip. */
118 if (bt_ctf_field_type_integer_get_size(magic_field_type
) != 32) {
120 * Magic field is not of the expected size.
121 * Not an error, skip.
126 ret
= bt_ctf_field_type_integer_get_signed(magic_field_type
);
129 ret
= bt_ctf_field_signed_integer_set_value(magic_field
,
130 (int64_t) 0xC1FC1FC1);
132 ret
= bt_ctf_field_unsigned_integer_set_value(magic_field
,
133 (uint64_t) 0xC1FC1FC1);
137 bt_put(magic_field_type
);
142 int set_packet_header_uuid(struct bt_ctf_stream
*stream
)
145 struct bt_ctf_trace
*trace
= NULL
;
146 struct bt_ctf_field_type
*uuid_field_type
= NULL
;
147 struct bt_ctf_field_type
*element_field_type
= NULL
;
148 struct bt_ctf_field
*uuid_field
= bt_ctf_field_structure_get_field(
149 stream
->packet_header
, "uuid");
152 /* No uuid field found. Not an error, skip. */
156 if (bt_ctf_field_is_set(uuid_field
)) {
157 /* Value already set. Not an error, skip. */
161 uuid_field_type
= bt_ctf_field_get_type(uuid_field
);
162 assert(uuid_field_type
);
163 if (bt_ctf_field_type_get_type_id(uuid_field_type
) !=
164 BT_CTF_TYPE_ID_ARRAY
) {
165 /* UUID field is not an array. Not an error, skip. */
169 if (bt_ctf_field_type_array_get_length(uuid_field_type
) != 16) {
171 * UUID field is not of the expected size.
172 * Not an error, skip.
177 element_field_type
= bt_ctf_field_type_array_get_element_type(
179 assert(element_field_type
);
180 if (bt_ctf_field_type_get_type_id(element_field_type
) !=
181 BT_CTF_TYPE_ID_INTEGER
) {
182 /* UUID array elements are not integers. Not an error, skip */
186 trace
= (struct bt_ctf_trace
*) bt_object_get_parent(stream
);
187 for (i
= 0; i
< 16; i
++) {
188 struct bt_ctf_field
*uuid_element
=
189 bt_ctf_field_array_get_field(uuid_field
, i
);
191 ret
= bt_ctf_field_type_integer_get_signed(element_field_type
);
195 ret
= bt_ctf_field_signed_integer_set_value(
196 uuid_element
, (int64_t) trace
->uuid
[i
]);
198 ret
= bt_ctf_field_unsigned_integer_set_value(
200 (uint64_t) trace
->uuid
[i
]);
202 bt_put(uuid_element
);
210 bt_put(uuid_field_type
);
211 bt_put(element_field_type
);
216 int set_packet_header_stream_id(struct bt_ctf_stream
*stream
)
220 struct bt_ctf_field_type
*stream_id_field_type
= NULL
;
221 struct bt_ctf_field
*stream_id_field
= bt_ctf_field_structure_get_field(
222 stream
->packet_header
, "stream_id");
224 if (!stream_id_field
) {
225 /* No stream_id field found. Not an error, skip. */
229 if (bt_ctf_field_is_set(stream_id_field
)) {
230 /* Value already set. Not an error, skip. */
234 stream_id_field_type
= bt_ctf_field_get_type(stream_id_field
);
235 assert(stream_id_field_type
);
236 if (bt_ctf_field_type_get_type_id(stream_id_field_type
) !=
237 BT_CTF_TYPE_ID_INTEGER
) {
238 /* stream_id field is not an integer. Not an error, skip. */
242 stream_id
= stream
->stream_class
->id
;
243 ret
= bt_ctf_field_type_integer_get_signed(stream_id_field_type
);
246 ret
= bt_ctf_field_signed_integer_set_value(stream_id_field
,
247 (int64_t) stream_id
);
249 ret
= bt_ctf_field_unsigned_integer_set_value(stream_id_field
,
250 (uint64_t) stream_id
);
253 bt_put(stream_id_field
);
254 bt_put(stream_id_field_type
);
259 int set_packet_header(struct bt_ctf_stream
*stream
)
263 ret
= set_packet_header_magic(stream
);
268 ret
= set_packet_header_uuid(stream
);
273 ret
= set_packet_header_stream_id(stream
);
282 void release_event(struct bt_ctf_event
*event
)
284 if (bt_object_get_ref_count(event
)) {
286 * The event is being orphaned, but it must guarantee the
287 * existence of its event class for the duration of its
290 bt_get(event
->event_class
);
291 BT_PUT(event
->base
.parent
);
293 bt_object_release(event
);
298 int create_stream_file(struct bt_ctf_writer
*writer
,
299 struct bt_ctf_stream
*stream
)
302 GString
*filename
= g_string_new(stream
->stream_class
->name
->str
);
304 if (stream
->stream_class
->name
->len
== 0) {
307 ret
= bt_ctf_stream_class_get_id(stream
->stream_class
);
313 g_string_printf(filename
, "stream_%" PRId64
, ret
);
316 g_string_append_printf(filename
, "_%" PRIu32
, stream
->id
);
317 fd
= openat(writer
->trace_dir_fd
, filename
->str
,
318 O_RDWR
| O_CREAT
| O_TRUNC
,
319 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
321 g_string_free(filename
, TRUE
);
326 int set_stream_fd(struct bt_ctf_stream
*stream
, int fd
)
330 if (stream
->pos
.fd
!= -1) {
335 ctf_init_pos(&stream
->pos
, NULL
, fd
, O_RDWR
);
341 struct bt_ctf_stream
*bt_ctf_stream_create(
342 struct bt_ctf_stream_class
*stream_class
,
346 struct bt_ctf_stream
*stream
= NULL
;
347 struct bt_ctf_trace
*trace
= NULL
;
348 struct bt_ctf_writer
*writer
= NULL
;
354 trace
= bt_ctf_stream_class_get_trace(stream_class
);
359 stream
= g_new0(struct bt_ctf_stream
, 1);
364 bt_object_init(stream
, bt_ctf_stream_destroy
);
366 * Acquire reference to parent since stream will become publicly
367 * reachable; it needs its parent to remain valid.
369 bt_object_set_parent(stream
, trace
);
370 stream
->id
= stream_class
->next_stream_id
++;
371 stream
->stream_class
= stream_class
;
375 stream
->name
= g_string_new(name
);
381 if (trace
->is_created_by_writer
) {
383 writer
= (struct bt_ctf_writer
*)
384 bt_object_get_parent(trace
);
387 stream
->packet_context
= bt_ctf_field_create(
388 stream_class
->packet_context_type
);
389 if (!stream
->packet_context
) {
393 /* Initialize events_discarded */
394 ret
= set_structure_field_integer(stream
->packet_context
,
395 "events_discarded", 0);
400 stream
->events
= g_ptr_array_new_with_free_func(
401 (GDestroyNotify
) release_event
);
402 if (!stream
->events
) {
406 /* A trace is not allowed to have a NULL packet header */
407 assert(trace
->packet_header_type
);
408 stream
->packet_header
=
409 bt_ctf_field_create(trace
->packet_header_type
);
410 if (!stream
->packet_header
) {
415 * Attempt to populate the default trace packet header fields
416 * (magic, uuid and stream_id). This will _not_ fail shall the
417 * fields not be found or be of an incompatible type; they will
418 * simply not be populated automatically. The user will have to
419 * make sure to set the trace packet header fields himself
422 ret
= set_packet_header(stream
);
427 /* Create file associated with this stream */
428 fd
= create_stream_file(writer
, stream
);
433 ret
= set_stream_fd(stream
, fd
);
438 /* Freeze the writer */
439 bt_ctf_writer_freeze(writer
);
441 /* Non-writer stream indicated by a negative FD */
442 ret
= set_stream_fd(stream
, -1);
448 /* Add this stream to the trace's streams */
449 g_ptr_array_add(trace
->streams
, stream
);
461 struct bt_ctf_stream_class
*bt_ctf_stream_get_class(
462 struct bt_ctf_stream
*stream
)
464 struct bt_ctf_stream_class
*stream_class
= NULL
;
470 stream_class
= stream
->stream_class
;
471 bt_get(stream_class
);
476 int bt_ctf_stream_get_discarded_events_count(
477 struct bt_ctf_stream
*stream
, uint64_t *count
)
481 struct bt_ctf_field
*events_discarded_field
= NULL
;
482 struct bt_ctf_field_type
*events_discarded_field_type
= NULL
;
484 if (!stream
|| !count
|| !stream
->packet_context
||
485 stream
->pos
.fd
< 0) {
490 events_discarded_field
= bt_ctf_field_structure_get_field(
491 stream
->packet_context
, "events_discarded");
492 if (!events_discarded_field
) {
497 events_discarded_field_type
= bt_ctf_field_get_type(
498 events_discarded_field
);
499 if (!events_discarded_field_type
) {
504 field_signed
= bt_ctf_field_type_integer_get_signed(
505 events_discarded_field_type
);
506 if (field_signed
< 0) {
512 int64_t signed_count
;
514 ret
= bt_ctf_field_signed_integer_get_value(
515 events_discarded_field
, &signed_count
);
519 if (signed_count
< 0) {
524 *count
= (uint64_t) signed_count
;
526 ret
= bt_ctf_field_unsigned_integer_get_value(
527 events_discarded_field
, count
);
533 bt_put(events_discarded_field
);
534 bt_put(events_discarded_field_type
);
538 void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream
*stream
,
539 uint64_t event_count
)
543 uint64_t previous_count
;
545 struct bt_ctf_field
*events_discarded_field
= NULL
;
546 struct bt_ctf_field_type
*events_discarded_field_type
= NULL
;
548 if (!stream
|| !stream
->packet_context
|| stream
->pos
.fd
< 0) {
552 ret
= bt_ctf_stream_get_discarded_events_count(stream
,
558 events_discarded_field
= bt_ctf_field_structure_get_field(
559 stream
->packet_context
, "events_discarded");
560 if (!events_discarded_field
) {
564 events_discarded_field_type
= bt_ctf_field_get_type(
565 events_discarded_field
);
566 if (!events_discarded_field_type
) {
570 field_signed
= bt_ctf_field_type_integer_get_signed(
571 events_discarded_field_type
);
572 if (field_signed
< 0) {
576 new_count
= previous_count
+ event_count
;
578 ret
= bt_ctf_field_signed_integer_set_value(
579 events_discarded_field
, (int64_t) new_count
);
584 ret
= bt_ctf_field_unsigned_integer_set_value(
585 events_discarded_field
, new_count
);
592 bt_put(events_discarded_field
);
593 bt_put(events_discarded_field_type
);
596 static int auto_populate_event_header(struct bt_ctf_stream
*stream
,
597 struct bt_ctf_event
*event
)
600 struct bt_ctf_field
*id_field
= NULL
, *timestamp_field
= NULL
;
601 struct bt_ctf_clock_class
*mapped_clock_class
= NULL
;
603 if (!event
|| event
->frozen
) {
609 * The condition to automatically set the ID are:
611 * 1. The event header field "id" exists and is an integer
613 * 2. The event header field "id" is NOT set.
615 id_field
= bt_ctf_field_structure_get_field(event
->event_header
, "id");
616 if (id_field
&& !bt_ctf_field_is_set(id_field
)) {
617 ret
= set_integer_field_value(id_field
,
618 (uint64_t) bt_ctf_event_class_get_id(
619 event
->event_class
));
626 * The conditions to automatically set the timestamp are:
628 * 1. The event header field "timestamp" exists and is an
630 * 2. This stream's class has a registered clock (set with
631 * bt_ctf_stream_class_set_clock()).
632 * 3. The event header field "timestamp" has its type mapped to
633 * a clock class which is also the clock class of this
634 * stream's class's registered clock.
635 * 4. The event header field "timestamp" is NOT set.
637 timestamp_field
= bt_ctf_field_structure_get_field(event
->event_header
,
639 if (timestamp_field
&& !bt_ctf_field_is_set(timestamp_field
) &&
640 stream
->stream_class
->clock
) {
641 struct bt_ctf_clock_class
*stream_class_clock_class
=
642 stream
->stream_class
->clock
->clock_class
;
643 struct bt_ctf_field_type
*timestamp_field_type
=
644 bt_ctf_field_get_type(timestamp_field
);
646 assert(timestamp_field_type
);
648 bt_ctf_field_type_integer_get_mapped_clock_class(
649 timestamp_field_type
);
650 BT_PUT(timestamp_field_type
);
651 if (mapped_clock_class
== stream_class_clock_class
) {
654 ret
= bt_ctf_clock_get_value(
655 stream
->stream_class
->clock
,
661 ret
= set_integer_field_value(timestamp_field
,
671 bt_put(timestamp_field
);
672 bt_put(mapped_clock_class
);
676 int bt_ctf_stream_append_event(struct bt_ctf_stream
*stream
,
677 struct bt_ctf_event
*event
)
681 if (!stream
|| !event
|| stream
->pos
.fd
< 0) {
687 * The event is not supposed to have a parent stream at this
688 * point. The only other way an event can have a parent stream
689 * is if it was assigned when setting a packet to the event,
690 * in which case the packet's stream is not a writer stream,
691 * and thus the user is trying to append an event which belongs
694 if (event
->base
.parent
) {
699 bt_object_set_parent(event
, stream
);
700 ret
= auto_populate_event_header(stream
, event
);
705 /* Make sure the various scopes of the event are set */
706 ret
= bt_ctf_event_validate(event
);
711 /* Save the new event and freeze it */
712 bt_ctf_event_freeze(event
);
713 g_ptr_array_add(stream
->events
, event
);
716 * Event had to hold a reference to its event class as long as it wasn't
717 * part of the same trace hierarchy. From now on, the event and its
718 * class share the same lifetime guarantees and the reference is no
721 bt_put(event
->event_class
);
728 * Orphan the event; we were not successful in associating it to
731 bt_object_set_parent(event
, NULL
);
736 struct bt_ctf_field
*bt_ctf_stream_get_packet_context(
737 struct bt_ctf_stream
*stream
)
739 struct bt_ctf_field
*packet_context
= NULL
;
741 if (!stream
|| stream
->pos
.fd
< 0) {
745 packet_context
= stream
->packet_context
;
746 if (packet_context
) {
747 bt_get(packet_context
);
750 return packet_context
;
753 int bt_ctf_stream_set_packet_context(struct bt_ctf_stream
*stream
,
754 struct bt_ctf_field
*field
)
757 struct bt_ctf_field_type
*field_type
;
759 if (!stream
|| stream
->pos
.fd
< 0) {
764 field_type
= bt_ctf_field_get_type(field
);
765 if (bt_ctf_field_type_compare(field_type
,
766 stream
->stream_class
->packet_context_type
)) {
772 bt_put(stream
->packet_context
);
773 stream
->packet_context
= bt_get(field
);
778 struct bt_ctf_field
*bt_ctf_stream_get_packet_header(
779 struct bt_ctf_stream
*stream
)
781 struct bt_ctf_field
*packet_header
= NULL
;
783 if (!stream
|| stream
->pos
.fd
< 0) {
787 packet_header
= stream
->packet_header
;
789 bt_get(packet_header
);
792 return packet_header
;
795 int bt_ctf_stream_set_packet_header(struct bt_ctf_stream
*stream
,
796 struct bt_ctf_field
*field
)
799 struct bt_ctf_trace
*trace
= NULL
;
800 struct bt_ctf_field_type
*field_type
= NULL
;
802 if (!stream
|| stream
->pos
.fd
< 0) {
807 trace
= (struct bt_ctf_trace
*) bt_object_get_parent(stream
);
808 field_type
= bt_ctf_field_get_type(field
);
809 if (bt_ctf_field_type_compare(field_type
, trace
->packet_header_type
)) {
814 bt_put(stream
->packet_header
);
815 stream
->packet_header
= bt_get(field
);
823 int get_event_header_timestamp(struct bt_ctf_field
*event_header
, uint64_t *timestamp
)
826 struct bt_ctf_field
*timestamp_field
= NULL
;
827 struct bt_ctf_field_type
*timestamp_field_type
= NULL
;
829 timestamp_field
= bt_ctf_field_structure_get_field(event_header
,
831 if (!timestamp_field
) {
836 timestamp_field_type
= bt_ctf_field_get_type(timestamp_field
);
837 assert(timestamp_field_type
);
838 if (bt_ctf_field_type_get_type_id(timestamp_field_type
) !=
839 BT_CTF_TYPE_ID_INTEGER
) {
844 if (bt_ctf_field_type_integer_get_signed(timestamp_field_type
)) {
847 ret
= bt_ctf_field_signed_integer_get_value(timestamp_field
,
852 *timestamp
= (uint64_t) val
;
854 ret
= bt_ctf_field_unsigned_integer_get_value(timestamp_field
,
861 bt_put(timestamp_field
);
862 bt_put(timestamp_field_type
);
866 int bt_ctf_stream_flush(struct bt_ctf_stream
*stream
)
870 uint64_t timestamp_begin
, timestamp_end
, events_discarded
;
871 struct bt_ctf_field
*integer
= NULL
;
872 struct ctf_stream_pos packet_context_pos
;
874 if (!stream
|| stream
->pos
.fd
< 0) {
876 * Stream does not have an associated fd. It is,
877 * therefore, not a stream being used to write events.
883 if (!stream
->events
->len
) {
887 ret
= bt_ctf_field_validate(stream
->packet_header
);
892 /* mmap the next packet */
893 ctf_packet_seek(&stream
->pos
.parent
, 0, SEEK_CUR
);
895 ret
= bt_ctf_field_serialize(stream
->packet_header
, &stream
->pos
);
900 /* Set the default context attributes if present and unset. */
901 if (!get_event_header_timestamp(
902 ((struct bt_ctf_event
*) g_ptr_array_index(
903 stream
->events
, 0))->event_header
, ×tamp_begin
)) {
904 ret
= set_structure_field_integer(stream
->packet_context
,
905 "timestamp_begin", timestamp_begin
);
911 if (!get_event_header_timestamp(
912 ((struct bt_ctf_event
*) g_ptr_array_index(
913 stream
->events
, stream
->events
->len
- 1))->event_header
,
916 ret
= set_structure_field_integer(stream
->packet_context
,
917 "timestamp_end", timestamp_end
);
922 ret
= set_structure_field_integer(stream
->packet_context
,
923 "content_size", UINT64_MAX
);
928 ret
= set_structure_field_integer(stream
->packet_context
,
929 "packet_size", UINT64_MAX
);
934 /* Write packet context */
935 memcpy(&packet_context_pos
, &stream
->pos
,
936 sizeof(struct ctf_stream_pos
));
937 ret
= bt_ctf_field_serialize(stream
->packet_context
,
943 ret
= bt_ctf_stream_get_discarded_events_count(stream
,
949 /* Unset the packet context's fields. */
950 ret
= bt_ctf_field_reset(stream
->packet_context
);
955 /* Set the previous number of discarded events. */
956 ret
= set_structure_field_integer(stream
->packet_context
,
957 "events_discarded", events_discarded
);
962 for (i
= 0; i
< stream
->events
->len
; i
++) {
963 struct bt_ctf_event
*event
= g_ptr_array_index(
966 ret
= bt_ctf_field_reset(event
->event_header
);
971 /* Write event header */
972 ret
= bt_ctf_field_serialize(event
->event_header
,
978 /* Write stream event context */
979 if (event
->stream_event_context
) {
980 ret
= bt_ctf_field_serialize(
981 event
->stream_event_context
, &stream
->pos
);
987 /* Write event content */
988 ret
= bt_ctf_event_serialize(event
, &stream
->pos
);
995 * Update the packet total size and content size and overwrite the
997 * Copy base_mma as the packet may have been remapped (e.g. when a
998 * packet is resized).
1000 packet_context_pos
.base_mma
= stream
->pos
.base_mma
;
1001 ret
= set_structure_field_integer(stream
->packet_context
,
1002 "content_size", stream
->pos
.offset
);
1007 ret
= set_structure_field_integer(stream
->packet_context
,
1008 "packet_size", stream
->pos
.packet_size
);
1013 ret
= bt_ctf_field_serialize(stream
->packet_context
,
1014 &packet_context_pos
);
1019 g_ptr_array_set_size(stream
->events
, 0);
1020 stream
->flushed_packet_count
++;
1026 void bt_ctf_stream_get(struct bt_ctf_stream
*stream
)
1031 void bt_ctf_stream_put(struct bt_ctf_stream
*stream
)
1037 void bt_ctf_stream_destroy(struct bt_object
*obj
)
1039 struct bt_ctf_stream
*stream
;
1041 stream
= container_of(obj
, struct bt_ctf_stream
, base
);
1042 ctf_fini_pos(&stream
->pos
);
1043 if (stream
->pos
.fd
>= 0 && close(stream
->pos
.fd
)) {
1047 if (stream
->events
) {
1048 g_ptr_array_free(stream
->events
, TRUE
);
1052 g_string_free(stream
->name
, TRUE
);
1055 bt_put(stream
->packet_header
);
1056 bt_put(stream
->packet_context
);
1061 int set_structure_field_integer(struct bt_ctf_field
*structure
, char *name
,
1065 struct bt_ctf_field_type
*field_type
= NULL
;
1066 struct bt_ctf_field
*integer
=
1067 bt_ctf_field_structure_get_field(structure
, name
);
1069 if (!structure
|| !name
) {
1075 /* Field not found, not an error. */
1079 /* Make sure the payload has not already been set. */
1080 if (bt_ctf_field_is_set(integer
)) {
1081 /* Payload already set, not an error */
1085 field_type
= bt_ctf_field_get_type(integer
);
1086 /* Something is serioulsly wrong */
1088 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_TYPE_ID_INTEGER
) {
1090 * The user most likely meant for us to populate this field
1091 * automatically. However, we can only do this if the field
1092 * is an integer. Return an error.
1098 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
1099 ret
= bt_ctf_field_signed_integer_set_value(integer
,
1102 ret
= bt_ctf_field_unsigned_integer_set_value(integer
, value
);
1110 const char *bt_ctf_stream_get_name(struct bt_ctf_stream
*stream
)
1112 const char *name
= NULL
;
1118 name
= stream
->name
? stream
->name
->str
: NULL
;
1124 int bt_ctf_stream_is_writer(struct bt_ctf_stream
*stream
)
1132 ret
= (stream
->pos
.fd
>= 0);