Split the CTF-Writer API into IR and Writer-specific parts
[babeltrace.git] / formats / ctf / writer / stream.c
index f03f170d6a5ff7c09744149b4f4f2f9181eaa1f6..71a8212eddb2f30839f7ba730de306d4571e9fed 100644 (file)
  */
 
 #include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/clock-internal.h>
+#include <babeltrace/ctf-ir/clock-internal.h>
 #include <babeltrace/ctf-writer/event.h>
-#include <babeltrace/ctf-writer/event-internal.h>
-#include <babeltrace/ctf-writer/event-types-internal.h>
-#include <babeltrace/ctf-writer/event-fields-internal.h>
+#include <babeltrace/ctf-ir/event-internal.h>
+#include <babeltrace/ctf-ir/event-types-internal.h>
+#include <babeltrace/ctf-ir/event-fields-internal.h>
 #include <babeltrace/ctf-writer/stream.h>
 #include <babeltrace/ctf-writer/stream-internal.h>
+#include <babeltrace/ctf-ir/stream-class-internal.h>
 #include <babeltrace/ctf-writer/functor-internal.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/align.h>
@@ -368,7 +369,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        int ret = 0;
        size_t i;
        uint64_t timestamp_begin, timestamp_end;
-       struct bt_ctf_stream_class *stream_class = stream->stream_class;
+       struct bt_ctf_stream_class *stream_class;
        struct bt_ctf_field *integer = NULL;
        struct ctf_stream_pos packet_context_pos;
 
@@ -385,6 +386,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                stream->flush.func(stream, stream->flush.data);
        }
 
+       stream_class = stream->stream_class;
        timestamp_begin = ((struct bt_ctf_event *) g_ptr_array_index(
                stream->events, 0))->timestamp;
        timestamp_end = ((struct bt_ctf_event *) g_ptr_array_index(
@@ -463,7 +465,10 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        /*
         * Update the packet total size and content size and overwrite the
         * packet context.
+        * Copy base_mma as the packet may have been remapped (e.g. when a
+        * packet is resized).
         */
+       packet_context_pos.base_mma = stream->pos.base_mma;
        ret = set_structure_field_integer(stream_class->packet_context,
                "content_size", stream->pos.offset);
        if (ret) {
@@ -518,7 +523,9 @@ void bt_ctf_stream_destroy(struct bt_ctf_ref *ref)
 
        stream = container_of(ref, struct bt_ctf_stream, ref_count);
        ctf_fini_pos(&stream->pos);
-       close(stream->pos.fd);
+       if (close(stream->pos.fd)) {
+               perror("close");
+       }
        bt_ctf_stream_class_put(stream->stream_class);
        g_ptr_array_free(stream->events, TRUE);
        g_free(stream);
This page took 0.024171 seconds and 4 git commands to generate.