Fix: stream.c: autopopulate timestamp fields even when not mapped to CC
[babeltrace.git] / lib / ctf-ir / stream.c
index 8ba0977c13bef601458dc296b13809805b4032c3..88e726ca2992f12c55d3dd4ee7a1f96f047a124f 100644 (file)
 #include <unistd.h>
 
 static
-void bt_ctf_stream_destroy(struct bt_object *obj);
+void bt_stream_destroy(struct bt_object *obj);
 static
-int try_set_structure_field_integer(struct bt_ctf_field *, char *, uint64_t);
+int try_set_structure_field_integer(struct bt_field *, char *, uint64_t);
 
 static
-int set_integer_field_value(struct bt_ctf_field* field, uint64_t value)
+int set_integer_field_value(struct bt_field* field, uint64_t value)
 {
        int ret = 0;
-       struct bt_ctf_field_type *field_type = NULL;
+       struct bt_field_type *field_type = NULL;
 
        if (!field) {
                BT_LOGW_STR("Invalid parameter: field is NULL.");
@@ -67,22 +67,22 @@ int set_integer_field_value(struct bt_ctf_field* field, uint64_t value)
                goto end;
        }
 
-       field_type = bt_ctf_field_get_type(field);
+       field_type = bt_field_get_type(field);
        assert(field_type);
 
-       if (bt_ctf_field_type_get_type_id(field_type) !=
-                       BT_CTF_FIELD_TYPE_ID_INTEGER) {
+       if (bt_field_type_get_type_id(field_type) !=
+                       BT_FIELD_TYPE_ID_INTEGER) {
                /* Not an integer and the value is unset, error. */
                BT_LOGW("Invalid parameter: field's type is not an integer field type: "
                        "field-addr=%p, ft-addr=%p, ft-id=%s",
                        field, field_type,
-                       bt_ctf_field_type_id_string(field_type->id));
+                       bt_field_type_id_string(field_type->id));
                ret = -1;
                goto end;
        }
 
-       if (bt_ctf_field_type_integer_get_signed(field_type)) {
-               ret = bt_ctf_field_signed_integer_set_value(field, (int64_t) value);
+       if (bt_field_type_integer_is_signed(field_type)) {
+               ret = bt_field_signed_integer_set_value(field, (int64_t) value);
                if (ret) {
                        /* Value is out of range, error. */
                        BT_LOGW("Cannot set signed integer field's value: "
@@ -91,7 +91,7 @@ int set_integer_field_value(struct bt_ctf_field* field, uint64_t value)
                        goto end;
                }
        } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(field, value);
+               ret = bt_field_unsigned_integer_set_value(field, value);
                if (ret) {
                        /* Value is out of range, error. */
                        BT_LOGW("Cannot set unsigned integer field's value: "
@@ -106,10 +106,10 @@ end:
 }
 
 static
-int set_packet_header_magic(struct bt_ctf_stream *stream)
+int set_packet_header_magic(struct bt_stream *stream)
 {
        int ret = 0;
-       struct bt_ctf_field *magic_field = bt_ctf_field_structure_get_field(
+       struct bt_field *magic_field = bt_field_structure_get_field_by_name(
                stream->packet_header, "magic");
        const uint32_t magic_value = 0xc1fc1fc1;
 
@@ -119,22 +119,22 @@ int set_packet_header_magic(struct bt_ctf_stream *stream)
                /* No magic field found. Not an error, skip. */
                BT_LOGV("No field named `magic` in packet header: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(magic_field,
+       ret = bt_field_unsigned_integer_set_value(magic_field,
                (uint64_t) magic_value);
 
        if (ret) {
                BT_LOGW("Cannot set packet header field's `magic` integer field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        magic_field, (uint64_t) magic_value);
        } else {
                BT_LOGV("Set packet header field's `magic` field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        magic_field, (uint64_t) magic_value);
        }
 end:
@@ -143,12 +143,12 @@ end:
 }
 
 static
-int set_packet_header_uuid(struct bt_ctf_stream *stream)
+int set_packet_header_uuid(struct bt_stream *stream)
 {
        int ret = 0;
        int64_t i;
-       struct bt_ctf_trace *trace = NULL;
-       struct bt_ctf_field *uuid_field = bt_ctf_field_structure_get_field(
+       struct bt_trace *trace = NULL;
+       struct bt_field *uuid_field = bt_field_structure_get_field_by_name(
                stream->packet_header, "uuid");
 
        assert(stream);
@@ -157,23 +157,23 @@ int set_packet_header_uuid(struct bt_ctf_stream *stream)
                /* No uuid field found. Not an error, skip. */
                BT_LOGV("No field named `uuid` in packet header: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
-       trace = (struct bt_ctf_trace *) bt_object_get_parent(stream);
+       trace = (struct bt_trace *) bt_object_get_parent(stream);
        for (i = 0; i < 16; i++) {
-               struct bt_ctf_field *uuid_element =
-                       bt_ctf_field_array_get_field(uuid_field, i);
+               struct bt_field *uuid_element =
+                       bt_field_array_get_field(uuid_field, i);
 
-               ret = bt_ctf_field_unsigned_integer_set_value(
+               ret = bt_field_unsigned_integer_set_value(
                        uuid_element, (uint64_t) trace->uuid[i]);
                bt_put(uuid_element);
                if (ret) {
                        BT_LOGW("Cannot set integer field's value (for `uuid` packet header field): "
                                "stream-addr=%p, stream-name=\"%s\", field-addr=%p, "
                                "value=%" PRIu64 ", index=%" PRId64,
-                               stream, bt_ctf_stream_get_name(stream),
+                               stream, bt_stream_get_name(stream),
                                uuid_element, (uint64_t) trace->uuid[i], i);
                        goto end;
                }
@@ -181,7 +181,7 @@ int set_packet_header_uuid(struct bt_ctf_stream *stream)
 
        BT_LOGV("Set packet header field's `uuid` field's value: "
                "stream-addr=%p, stream-name=\"%s\", field-addr=%p",
-               stream, bt_ctf_stream_get_name(stream), uuid_field);
+               stream, bt_stream_get_name(stream), uuid_field);
 
 end:
        bt_put(uuid_field);
@@ -189,33 +189,33 @@ end:
        return ret;
 }
 static
-int set_packet_header_stream_id(struct bt_ctf_stream *stream)
+int set_packet_header_stream_id(struct bt_stream *stream)
 {
        int ret = 0;
        uint32_t stream_id;
-       struct bt_ctf_field *stream_id_field = bt_ctf_field_structure_get_field(
+       struct bt_field *stream_id_field = bt_field_structure_get_field_by_name(
                stream->packet_header, "stream_id");
 
        if (!stream_id_field) {
                /* No stream_id field found. Not an error, skip. */
                BT_LOGV("No field named `stream_id` in packet header: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
        stream_id = stream->stream_class->id;
-       ret = bt_ctf_field_unsigned_integer_set_value(stream_id_field,
+       ret = bt_field_unsigned_integer_set_value(stream_id_field,
                (uint64_t) stream_id);
        if (ret) {
                BT_LOGW("Cannot set packet header field's `stream_id` integer field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        stream_id_field, (uint64_t) stream_id);
        } else {
                BT_LOGV("Set packet header field's `stream_id` field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        stream_id_field, (uint64_t) stream_id);
        }
 
@@ -225,7 +225,7 @@ end:
 }
 
 static
-int auto_populate_packet_header(struct bt_ctf_stream *stream)
+int auto_populate_packet_header(struct bt_stream *stream)
 {
        int ret = 0;
 
@@ -237,7 +237,7 @@ int auto_populate_packet_header(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet header's magic number field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -245,7 +245,7 @@ int auto_populate_packet_header(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet header's UUID field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -253,23 +253,23 @@ int auto_populate_packet_header(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet header's stream class ID field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
        BT_LOGV("Automatically populated stream's packet header's known fields: "
                "stream-addr=%p, stream-name=\"%s\"",
-               stream, bt_ctf_stream_get_name(stream));
+               stream, bt_stream_get_name(stream));
 
 end:
        return ret;
 }
 
 static
-int set_packet_context_packet_size(struct bt_ctf_stream *stream)
+int set_packet_context_packet_size(struct bt_stream *stream)
 {
        int ret = 0;
-       struct bt_ctf_field *field = bt_ctf_field_structure_get_field(
+       struct bt_field *field = bt_field_structure_get_field_by_name(
                stream->packet_context, "packet_size");
 
        assert(stream);
@@ -278,21 +278,21 @@ int set_packet_context_packet_size(struct bt_ctf_stream *stream)
                /* No packet size field found. Not an error, skip. */
                BT_LOGV("No field named `packet_size` in packet context: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(field,
+       ret = bt_field_unsigned_integer_set_value(field,
                stream->pos.packet_size);
        if (ret) {
                BT_LOGW("Cannot set packet context field's `packet_size` integer field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, stream->pos.packet_size);
        } else {
                BT_LOGV("Set packet context field's `packet_size` field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, stream->pos.packet_size);
        }
 
@@ -302,10 +302,10 @@ end:
 }
 
 static
-int set_packet_context_content_size(struct bt_ctf_stream *stream)
+int set_packet_context_content_size(struct bt_stream *stream)
 {
        int ret = 0;
-       struct bt_ctf_field *field = bt_ctf_field_structure_get_field(
+       struct bt_field *field = bt_field_structure_get_field_by_name(
                stream->packet_context, "content_size");
 
        assert(stream);
@@ -314,21 +314,21 @@ int set_packet_context_content_size(struct bt_ctf_stream *stream)
                /* No content size field found. Not an error, skip. */
                BT_LOGV("No field named `content_size` in packet context: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(field,
+       ret = bt_field_unsigned_integer_set_value(field,
                stream->pos.offset);
        if (ret) {
                BT_LOGW("Cannot set packet context field's `content_size` integer field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRId64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, stream->pos.offset);
        } else {
                BT_LOGV("Set packet context field's `content_size` field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRId64,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, stream->pos.offset);
        }
 
@@ -338,10 +338,10 @@ end:
 }
 
 static
-int set_packet_context_events_discarded(struct bt_ctf_stream *stream)
+int set_packet_context_events_discarded(struct bt_stream *stream)
 {
        int ret = 0;
-       struct bt_ctf_field *field = bt_ctf_field_structure_get_field(
+       struct bt_field *field = bt_field_structure_get_field_by_name(
                stream->packet_context, "events_discarded");
 
        assert(stream);
@@ -350,7 +350,7 @@ int set_packet_context_events_discarded(struct bt_ctf_stream *stream)
                /* No discarded events count field found. Not an error, skip. */
                BT_LOGV("No field named `events_discarded` in packet context: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -360,15 +360,15 @@ int set_packet_context_events_discarded(struct bt_ctf_stream *stream)
         * discarded events. We do not allow wrapping here. If it's
         * valid, update the stream's current count.
         */
-       if (bt_ctf_field_is_set(field)) {
+       if (bt_field_is_set(field)) {
                uint64_t user_val;
 
-               ret = bt_ctf_field_unsigned_integer_get_value(field,
+               ret = bt_field_unsigned_integer_get_value(field,
                        &user_val);
                if (ret) {
                        BT_LOGW("Cannot get packet context `events_discarded` field's unsigned value: "
                                "stream-addr=%p, stream-name=\"%s\", field-addr=%p",
-                               stream, bt_ctf_stream_get_name(stream), field);
+                               stream, bt_stream_get_name(stream), field);
                        goto end;
                }
 
@@ -378,24 +378,24 @@ int set_packet_context_events_discarded(struct bt_ctf_stream *stream)
                                "stream-addr=%p, stream-name=\"%s\", field-addr=%p, "
                                "value=%" PRIu64 ", "
                                "stream-discarded-events-count=%" PRIu64,
-                               stream, bt_ctf_stream_get_name(stream), field,
+                               stream, bt_stream_get_name(stream), field,
                                user_val, stream->discarded_events);
                        goto end;
                }
 
                stream->discarded_events = user_val;
        } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(field,
+               ret = bt_field_unsigned_integer_set_value(field,
                        stream->discarded_events);
                if (ret) {
                        BT_LOGW("Cannot set packet context field's `events_discarded` integer field's value: "
                                "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                               stream, bt_ctf_stream_get_name(stream),
+                               stream, bt_stream_get_name(stream),
                                field, stream->discarded_events);
                } else {
                        BT_LOGV("Set packet context field's `events_discarded` field's value: "
                                "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                               stream, bt_ctf_stream_get_name(stream),
+                               stream, bt_stream_get_name(stream),
                                field, stream->discarded_events);
                }
        }
@@ -406,12 +406,12 @@ end:
 }
 
 static
-int get_event_header_timestamp(struct bt_ctf_stream *stream,
-               struct bt_ctf_field *event_header, uint64_t *timestamp)
+int get_event_header_timestamp(struct bt_stream *stream,
+               struct bt_field *event_header, uint64_t *timestamp)
 {
        int ret = 0;
-       struct bt_ctf_field *timestamp_field = NULL;
-       struct bt_ctf_clock_class *ts_field_mapped_clock_class = NULL;
+       struct bt_field *timestamp_field = NULL;
+       struct bt_clock_class *ts_field_mapped_clock_class = NULL;
 
        *timestamp = 0;
 
@@ -420,7 +420,7 @@ int get_event_header_timestamp(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       timestamp_field = bt_ctf_field_structure_get_field(event_header,
+       timestamp_field = bt_field_structure_get_field_by_name(event_header,
                "timestamp");
        if (!timestamp_field) {
                BT_LOGV("Cannot get event header's `timestamp` field: "
@@ -428,14 +428,14 @@ int get_event_header_timestamp(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       if (!bt_ctf_field_type_is_integer(timestamp_field->type)) {
+       if (!bt_field_type_is_integer(timestamp_field->type)) {
                BT_LOGV("Event header's `timestamp` field's type is not an integer field type: "
                        "event-header-field-addr=%p", event_header);
                goto end;
        }
 
        ts_field_mapped_clock_class =
-               bt_ctf_field_type_integer_get_mapped_clock_class(
+               bt_field_type_integer_get_mapped_clock_class(
                        timestamp_field->type);
        if (!ts_field_mapped_clock_class) {
                BT_LOGV("Event header's `timestamp` field's type is not mapped to a clock class: "
@@ -450,7 +450,7 @@ int get_event_header_timestamp(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       ret = bt_ctf_field_unsigned_integer_get_value(timestamp_field,
+       ret = bt_field_unsigned_integer_get_value(timestamp_field,
                timestamp);
        if (ret) {
                BT_LOGW("Cannot get unsigned integer field's value: "
@@ -467,13 +467,13 @@ end:
 }
 
 static
-int set_packet_context_timestamp_field(struct bt_ctf_stream *stream,
-               const char *field_name, struct bt_ctf_event *event)
+int set_packet_context_timestamp_field(struct bt_stream *stream,
+               const char *field_name, struct bt_event *event)
 {
        int ret = 0;
-       struct bt_ctf_field *field = bt_ctf_field_structure_get_field(
+       struct bt_field *field = bt_field_structure_get_field_by_name(
                stream->packet_context, field_name);
-       struct bt_ctf_clock_class *field_mapped_clock_class = NULL;
+       struct bt_clock_class *field_mapped_clock_class = NULL;
        uint64_t ts;
 
        assert(stream);
@@ -482,29 +482,20 @@ int set_packet_context_timestamp_field(struct bt_ctf_stream *stream,
                /* No beginning timestamp field found. Not an error, skip. */
                BT_LOGV("No field named `%s` in packet context: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"", field_name,
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
        if (!stream->stream_class->clock) {
                BT_LOGV("Stream has no clock: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
        field_mapped_clock_class =
-               bt_ctf_field_type_integer_get_mapped_clock_class(field->type);
-       if (!field_mapped_clock_class) {
-               BT_LOGV("Packet context's `%s` field's type is not mapped to a clock class: skipping: "
-                       "stream-addr=%p, stream-name=\"%s\", "
-                       "field-addr=%p, ft-addr=%p", field_name,
-                       stream, bt_ctf_stream_get_name(stream),
-                       field, field->type);
-               goto end;
-       }
-
-       if (field_mapped_clock_class !=
+               bt_field_type_integer_get_mapped_clock_class(field->type);
+       if (field_mapped_clock_class && field_mapped_clock_class !=
                        stream->stream_class->clock->clock_class) {
                BT_LOGV("Packet context's `%s` field's type is not mapped to the stream's clock's class: skipping: "
                        "stream-addr=%p, stream-name=\"%s\", "
@@ -514,12 +505,12 @@ int set_packet_context_timestamp_field(struct bt_ctf_stream *stream,
                        "stream-clock-class-addr=%p, "
                        "stream-clock-class-name=\"%s\"",
                        field_name,
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, field->type,
                        field_mapped_clock_class,
-                       bt_ctf_clock_class_get_name(field_mapped_clock_class),
+                       bt_clock_class_get_name(field_mapped_clock_class),
                        stream->stream_class->clock->clock_class,
-                       bt_ctf_clock_class_get_name(
+                       bt_clock_class_get_name(
                                stream->stream_class->clock->clock_class));
                goto end;
        }
@@ -532,16 +523,16 @@ int set_packet_context_timestamp_field(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(field, ts);
+       ret = bt_field_unsigned_integer_set_value(field, ts);
        if (ret) {
                BT_LOGW("Cannot set packet context field's `%s` integer field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       field_name, stream, bt_ctf_stream_get_name(stream),
+                       field_name, stream, bt_stream_get_name(stream),
                        field, stream->discarded_events);
        } else {
                BT_LOGV("Set packet context field's `%s` field's value: "
                        "stream-addr=%p, stream-name=\"%s\", field-addr=%p, value=%" PRIu64,
-                       field_name, stream, bt_ctf_stream_get_name(stream),
+                       field_name, stream, bt_stream_get_name(stream),
                        field, stream->discarded_events);
        }
 
@@ -552,14 +543,14 @@ end:
 }
 
 static
-int set_packet_context_timestamp_begin(struct bt_ctf_stream *stream)
+int set_packet_context_timestamp_begin(struct bt_stream *stream)
 {
        int ret = 0;
 
        if (stream->events->len == 0) {
                BT_LOGV("Current packet contains no events: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -571,14 +562,14 @@ end:
 }
 
 static
-int set_packet_context_timestamp_end(struct bt_ctf_stream *stream)
+int set_packet_context_timestamp_end(struct bt_stream *stream)
 {
        int ret = 0;
 
        if (stream->events->len == 0) {
                BT_LOGV("Current packet contains no events: skipping: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -590,7 +581,7 @@ end:
 }
 
 static
-int auto_populate_packet_context(struct bt_ctf_stream *stream)
+int auto_populate_packet_context(struct bt_stream *stream)
 {
        int ret = 0;
 
@@ -602,7 +593,7 @@ int auto_populate_packet_context(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet context's packet size field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -610,7 +601,7 @@ int auto_populate_packet_context(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet context's content size field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -618,7 +609,7 @@ int auto_populate_packet_context(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet context's beginning timestamp field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -626,7 +617,7 @@ int auto_populate_packet_context(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet context's end timestamp field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
@@ -634,20 +625,20 @@ int auto_populate_packet_context(struct bt_ctf_stream *stream)
        if (ret) {
                BT_LOGW("Cannot set packet context's discarded events count field: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                goto end;
        }
 
        BT_LOGV("Automatically populated stream's packet context's known fields: "
                "stream-addr=%p, stream-name=\"%s\"",
-               stream, bt_ctf_stream_get_name(stream));
+               stream, bt_stream_get_name(stream));
 
 end:
        return ret;
 }
 
 static
-void release_event(struct bt_ctf_event *event)
+void release_event(struct bt_event *event)
 {
        if (bt_object_get_ref_count(event)) {
                /*
@@ -664,55 +655,82 @@ void release_event(struct bt_ctf_event *event)
 
 static
 int create_stream_file(struct bt_ctf_writer *writer,
-               struct bt_ctf_stream *stream)
+               struct bt_stream *stream)
 {
        int fd;
-       GString *filename = g_string_new(stream->stream_class->name->str);
-       char *file_path;
+       GString *filename = g_string_new(NULL);
+       int64_t stream_class_id;
+       char *file_path = NULL;
 
        BT_LOGD("Creating stream file: writer-addr=%p, stream-addr=%p, "
                "stream-name=\"%s\", stream-class-addr=%p, stream-class-name=\"%s\"",
-               writer, stream, bt_ctf_stream_get_name(stream),
+               writer, stream, bt_stream_get_name(stream),
                stream->stream_class, stream->stream_class->name->str);
 
-       if (stream->stream_class->name->len == 0) {
-               int64_t ret;
-
-               ret = bt_ctf_stream_class_get_id(stream->stream_class);
-               if (ret < 0) {
-                       BT_LOGW("Cannot get stream class's ID: "
-                               "stream-class-addr=%p, "
-                               "stream-class-name=\"%s\"",
-                               stream->stream_class,
-                               stream->stream_class->name->str);
-                       fd = -1;
-                       goto end;
+       if (stream->name && stream->name->len > 0) {
+               /* Use stream name's base name as prefix */
+               gchar *basename = g_path_get_basename(stream->name->str);
+
+               assert(basename);
+
+               if (strcmp(basename, G_DIR_SEPARATOR_S) == 0) {
+                       g_string_assign(filename, "stream");
+               } else {
+                       g_string_assign(filename, basename);
                }
 
-               g_string_printf(filename, "stream_%" PRId64, ret);
+               g_free(basename);
+               goto append_ids;
        }
 
-       g_string_append_printf(filename, "_%" PRId64, stream->id);
+       if (stream->stream_class->name &&
+                       stream->stream_class->name->len > 0) {
+               /* Use stream class name's base name as prefix */
+               gchar *basename =
+                       g_path_get_basename(stream->stream_class->name->str);
+
+               assert(basename);
+
+               if (strcmp(basename, G_DIR_SEPARATOR_S) == 0) {
+                       g_string_assign(filename, "stream");
+               } else {
+                       g_string_assign(filename, basename);
+               }
+
+               g_free(basename);
+               goto append_ids;
+       }
+
+       /* Default to using `stream-` as prefix */
+       g_string_assign(filename, "stream");
+
+append_ids:
+       stream_class_id = bt_stream_class_get_id(stream->stream_class);
+       assert(stream_class_id >= 0);
+       assert(stream->id >= 0);
+       g_string_append_printf(filename, "-%" PRId64 "-%" PRId64,
+               stream_class_id, stream->id);
+
        file_path = g_build_filename(writer->path->str, filename->str, NULL);
        if (file_path == NULL) {
                fd = -1;
                goto end;
        }
+
        fd = open(file_path,
                O_RDWR | O_CREAT | O_TRUNC,
                S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
        g_free(file_path);
        if (fd < 0) {
-               BT_LOGW("Failed to open stream file for writing: %s: "
-                       "filename=\"%s\", "
-                       "ret=%d, errno=%d", strerror(errno),
-                       filename->str, fd, errno);
+               BT_LOGW_ERRNO("Failed to open stream file for writing",
+                       ": file_path=\"%s\", filename=\"%s\", ret=%d",
+                       file_path, filename->str, fd);
                goto end;
        }
 
        BT_LOGD("Created stream file for writing: "
                "stream-addr=%p, stream-name=\"%s\", "
-               "filename=\"%s\", fd=%d", stream, bt_ctf_stream_get_name(stream),
+               "filename=\"%s\", fd=%d", stream, bt_stream_get_name(stream),
                filename->str, fd);
 
 end:
@@ -721,16 +739,16 @@ end:
 }
 
 static
-void set_stream_fd(struct bt_ctf_stream *stream, int fd)
+void set_stream_fd(struct bt_stream *stream, int fd)
 {
-       (void) bt_ctf_stream_pos_init(&stream->pos, fd, O_RDWR);
+       (void) bt_stream_pos_init(&stream->pos, fd, O_RDWR);
        stream->pos.fd = fd;
 }
 
 static
 void component_destroy_listener(struct bt_component *component, void *data)
 {
-       struct bt_ctf_stream *stream = data;
+       struct bt_stream *stream = data;
 
        BT_LOGD("Component is being destroyed, stream is notified: "
                "comp-addr=%p, stream-addr=%p", component, stream);
@@ -738,13 +756,13 @@ void component_destroy_listener(struct bt_component *component, void *data)
 }
 
 static
-struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
-               struct bt_ctf_stream_class *stream_class,
+struct bt_stream *bt_stream_create_with_id_no_check(
+               struct bt_stream_class *stream_class,
                const char *name, uint64_t id)
 {
        int ret;
-       struct bt_ctf_stream *stream = NULL;
-       struct bt_ctf_trace *trace = NULL;
+       struct bt_stream *stream = NULL;
+       struct bt_trace *trace = NULL;
        struct bt_ctf_writer *writer = NULL;
 
        if (!stream_class) {
@@ -755,19 +773,19 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
        BT_LOGD("Creating stream object: stream-class-addr=%p, "
                "stream-class-name=\"%s\", stream-name=\"%s\", "
                "stream-id=%" PRIu64,
-               stream_class, bt_ctf_stream_class_get_name(stream_class),
+               stream_class, bt_stream_class_get_name(stream_class),
                name, id);
-       trace = bt_ctf_stream_class_borrow_trace(stream_class);
+       trace = bt_stream_class_borrow_trace(stream_class);
        if (!trace) {
                BT_LOGW("Invalid parameter: cannot create stream from a stream class which is not part of trace: "
                        "stream-class-addr=%p, stream-class-name=\"%s\", "
                        "stream-name=\"%s\"",
-                       stream_class, bt_ctf_stream_class_get_name(stream_class),
+                       stream_class, bt_stream_class_get_name(stream_class),
                        name);
                goto error;
        }
 
-       if (bt_ctf_trace_is_static(trace)) {
+       if (bt_trace_is_static(trace)) {
                /*
                 * A static trace has the property that all its stream
                 * classes, clock classes, and streams are definitive:
@@ -776,7 +794,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
                BT_LOGW("Invalid parameter: cannot create stream from a stream class which is part of a static trace: "
                        "stream-class-addr=%p, stream-class-name=\"%s\", "
                        "stream-name=\"%s\", trace-addr=%p",
-                       stream_class, bt_ctf_stream_class_get_name(stream_class),
+                       stream_class, bt_stream_class_get_name(stream_class),
                        name, trace);
                goto error;
        }
@@ -790,7 +808,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
                size_t i;
 
                for (i = 0; i < trace->streams->len; i++) {
-                       struct bt_ctf_stream *trace_stream =
+                       struct bt_stream *trace_stream =
                                g_ptr_array_index(trace->streams, i);
 
                        if (trace_stream->stream_class != stream_class) {
@@ -804,13 +822,13 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
                }
        }
 
-       stream = g_new0(struct bt_ctf_stream, 1);
+       stream = g_new0(struct bt_stream, 1);
        if (!stream) {
                BT_LOGE_STR("Failed to allocate one stream.");
                goto error;
        }
 
-       bt_object_init(stream, bt_ctf_stream_destroy);
+       bt_object_init(stream, bt_stream_destroy);
        /*
         * Acquire reference to parent since stream will become publicly
         * reachable; it needs its parent to remain valid.
@@ -821,7 +839,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
        stream->id = (int64_t) id;
 
        stream->destroy_listeners = g_array_new(FALSE, TRUE,
-               sizeof(struct bt_ctf_stream_destroy_listener));
+               sizeof(struct bt_stream_destroy_listener));
        if (!stream->destroy_listeners) {
                BT_LOGE_STR("Failed to allocate a GArray.");
                goto error;
@@ -849,7 +867,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
                if (stream_class->packet_context_type) {
                        BT_LOGD("Creating stream's packet context field: "
                                "ft-addr=%p", stream_class->packet_context_type);
-                       stream->packet_context = bt_ctf_field_create(
+                       stream->packet_context = bt_field_create(
                                stream_class->packet_context_type);
                        if (!stream->packet_context) {
                                BT_LOGW_STR("Cannot create stream's packet context field.");
@@ -878,7 +896,7 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id_no_check(
                        BT_LOGD("Creating stream's packet header field: "
                                "ft-addr=%p", trace->packet_header_type);
                        stream->packet_header =
-                               bt_ctf_field_create(trace->packet_header_type);
+                               bt_field_create(trace->packet_header_type);
                        if (!stream->packet_header) {
                                BT_LOGW_STR("Cannot create stream's packet header field.");
                                goto error;
@@ -935,12 +953,12 @@ end:
        return stream;
 }
 
-struct bt_ctf_stream *bt_ctf_stream_create_with_id(
-               struct bt_ctf_stream_class *stream_class,
+struct bt_stream *bt_stream_create_with_id(
+               struct bt_stream_class *stream_class,
                const char *name, uint64_t id_param)
 {
-       struct bt_ctf_trace *trace;
-       struct bt_ctf_stream *stream = NULL;
+       struct bt_trace *trace;
+       struct bt_stream *stream = NULL;
        int64_t id = (int64_t) id_param;
 
        if (!stream_class) {
@@ -955,44 +973,44 @@ struct bt_ctf_stream *bt_ctf_stream_create_with_id(
                goto end;
        }
 
-       trace = bt_ctf_stream_class_borrow_trace(stream_class);
+       trace = bt_stream_class_borrow_trace(stream_class);
        if (!trace) {
                BT_LOGW("Invalid parameter: cannot create stream from a stream class which is not part of trace: "
                        "stream-class-addr=%p, stream-class-name=\"%s\", "
                        "stream-name=\"%s\", stream-id=%" PRIu64,
-                       stream_class, bt_ctf_stream_class_get_name(stream_class),
+                       stream_class, bt_stream_class_get_name(stream_class),
                        name, id_param);
                goto end;
        }
 
        if (trace->is_created_by_writer) {
-               BT_LOGW("Invalid parameter: cannot create a CTF writer stream with this function; use bt_ctf_stream_create(): "
+               BT_LOGW("Invalid parameter: cannot create a CTF writer stream with this function; use bt_stream_create(): "
                        "stream-class-addr=%p, stream-class-name=\"%s\", "
                        "stream-name=\"%s\", stream-id=%" PRIu64,
-                       stream_class, bt_ctf_stream_class_get_name(stream_class),
+                       stream_class, bt_stream_class_get_name(stream_class),
                        name, id_param);
                goto end;
        }
 
-       stream = bt_ctf_stream_create_with_id_no_check(stream_class,
+       stream = bt_stream_create_with_id_no_check(stream_class,
                name, id_param);
 
 end:
        return stream;
 }
 
-struct bt_ctf_stream *bt_ctf_stream_create(
-               struct bt_ctf_stream_class *stream_class,
+struct bt_stream *bt_stream_create(
+               struct bt_stream_class *stream_class,
                const char *name)
 {
-       return bt_ctf_stream_create_with_id_no_check(stream_class,
+       return bt_stream_create_with_id_no_check(stream_class,
                name, -1ULL);
 }
 
-struct bt_ctf_stream_class *bt_ctf_stream_get_class(
-               struct bt_ctf_stream *stream)
+struct bt_stream_class *bt_stream_get_class(
+               struct bt_stream *stream)
 {
-       struct bt_ctf_stream_class *stream_class = NULL;
+       struct bt_stream_class *stream_class = NULL;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
@@ -1005,8 +1023,8 @@ end:
        return stream_class;
 }
 
-int bt_ctf_stream_get_discarded_events_count(
-               struct bt_ctf_stream *stream, uint64_t *count)
+int bt_stream_get_discarded_events_count(
+               struct bt_stream *stream, uint64_t *count)
 {
        int ret = 0;
 
@@ -1025,7 +1043,7 @@ int bt_ctf_stream_get_discarded_events_count(
        if (stream->pos.fd < 0) {
                BT_LOGW("Invalid parameter: stream is not a CTF writer stream: "
                        "stream-addr=%p, stream-name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
                ret = -1;
                goto end;
        }
@@ -1037,23 +1055,23 @@ end:
 }
 
 static
-int set_packet_context_events_discarded_field(struct bt_ctf_stream *stream,
+int set_packet_context_events_discarded_field(struct bt_stream *stream,
        uint64_t count)
 {
        int ret = 0;
-       struct bt_ctf_field *events_discarded_field = NULL;
+       struct bt_field *events_discarded_field = NULL;
 
        if (!stream->packet_context) {
                goto end;
        }
 
-       events_discarded_field = bt_ctf_field_structure_get_field(
+       events_discarded_field = bt_field_structure_get_field_by_name(
                stream->packet_context, "events_discarded");
        if (!events_discarded_field) {
                goto end;
        }
 
-       ret = bt_ctf_field_unsigned_integer_set_value(
+       ret = bt_field_unsigned_integer_set_value(
                events_discarded_field, count);
        if (ret) {
                BT_LOGW("Cannot set packet context's `events_discarded` field: "
@@ -1067,12 +1085,12 @@ end:
        return ret;
 }
 
-void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
+void bt_stream_append_discarded_events(struct bt_stream *stream,
                uint64_t event_count)
 {
        int ret;
        uint64_t new_count;
-       struct bt_ctf_field *events_discarded_field = NULL;
+       struct bt_field *events_discarded_field = NULL;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
@@ -1081,7 +1099,7 @@ void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
 
        BT_LOGV("Appending discarded events to stream: "
                "stream-addr=%p, stream-name=\"%s\", append-count=%" PRIu64,
-               stream, bt_ctf_stream_get_name(stream), event_count);
+               stream, bt_stream_get_name(stream), event_count);
 
        if (!stream->packet_context) {
                BT_LOGW_STR("Invalid parameter: stream has no packet context field.");
@@ -1093,7 +1111,7 @@ void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       events_discarded_field = bt_ctf_field_structure_get_field(
+       events_discarded_field = bt_field_structure_get_field_by_name(
                stream->packet_context, "events_discarded");
        if (!events_discarded_field) {
                BT_LOGW_STR("No field named `events_discarded` in stream's packet context.");
@@ -1117,19 +1135,19 @@ void bt_ctf_stream_append_discarded_events(struct bt_ctf_stream *stream,
        stream->discarded_events = new_count;
        BT_LOGV("Appended discarded events to stream: "
                "stream-addr=%p, stream-name=\"%s\", append-count=%" PRIu64,
-               stream, bt_ctf_stream_get_name(stream), event_count);
+               stream, bt_stream_get_name(stream), event_count);
 
 end:
        bt_put(events_discarded_field);
 }
 
-static int auto_populate_event_header(struct bt_ctf_stream *stream,
-               struct bt_ctf_event *event)
+static int auto_populate_event_header(struct bt_stream *stream,
+               struct bt_event *event)
 {
        int ret = 0;
-       struct bt_ctf_field *id_field = NULL, *timestamp_field = NULL;
-       struct bt_ctf_clock_class *mapped_clock_class = NULL;
-       uint64_t event_class_id;
+       struct bt_field *id_field = NULL, *timestamp_field = NULL;
+       struct bt_clock_class *mapped_clock_class = NULL;
+       int64_t event_class_id;
 
        assert(event);
 
@@ -1145,12 +1163,16 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
 
        BT_LOGV("Automatically populating event's header field: "
                "stream-addr=%p, stream-name=\"%s\", event-addr=%p",
-               stream, bt_ctf_stream_get_name(stream), event);
+               stream, bt_stream_get_name(stream), event);
 
-       id_field = bt_ctf_field_structure_get_field(event->event_header, "id");
-       event_class_id = (uint64_t) bt_ctf_event_class_get_id(event->event_class);
-       assert(event_class_id >= 0);
-       if (id_field && bt_ctf_field_type_is_integer(id_field->type)) {
+       id_field = bt_field_structure_get_field_by_name(event->event_header, "id");
+       event_class_id = bt_event_class_get_id(event->event_class);
+       if (event_class_id < 0) {
+               BT_LOGE("Event class ID cannot be found");
+               ret = -1;
+               goto end;
+       }
+       if (id_field && bt_field_type_is_integer(id_field->type)) {
                ret = set_integer_field_value(id_field, event_class_id);
                if (ret) {
                        BT_LOGW("Cannot set event header's `id` field's value: "
@@ -1166,22 +1188,23 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
         * 1. The event header field "timestamp" exists and is an
         *    integer field.
         * 2. This stream's class has a registered clock (set with
-        *    bt_ctf_stream_class_set_clock()).
+        *    bt_stream_class_set_clock()).
         * 3. The event header field "timestamp" has its type mapped to
         *    a clock class which is also the clock class of this
         *    stream's class's registered clock.
         */
-       timestamp_field = bt_ctf_field_structure_get_field(event->event_header,
+       timestamp_field = bt_field_structure_get_field_by_name(event->event_header,
                        "timestamp");
        if (timestamp_field && stream->stream_class->clock &&
-                       bt_ctf_field_type_is_integer(timestamp_field->type)) {
-               struct bt_ctf_clock_class *stream_class_clock_class =
+                       bt_field_type_is_integer(timestamp_field->type)) {
+               struct bt_clock_class *stream_class_clock_class =
                        stream->stream_class->clock->clock_class;
 
                mapped_clock_class =
-                       bt_ctf_field_type_integer_get_mapped_clock_class(
+                       bt_field_type_integer_get_mapped_clock_class(
                                timestamp_field->type);
-               if (mapped_clock_class == stream_class_clock_class) {
+               if (!mapped_clock_class ||
+                               mapped_clock_class == stream_class_clock_class) {
                        uint64_t timestamp;
 
                        ret = bt_ctf_clock_get_value(
@@ -1201,7 +1224,7 @@ static int auto_populate_event_header(struct bt_ctf_stream *stream,
 
        BT_LOGV("Automatically populated event's header field: "
                "stream-addr=%p, stream-name=\"%s\", event-addr=%p",
-               stream, bt_ctf_stream_get_name(stream), event);
+               stream, bt_stream_get_name(stream), event);
 
 end:
        bt_put(id_field);
@@ -1210,8 +1233,8 @@ end:
        return ret;
 }
 
-int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
-               struct bt_ctf_event *event)
+int bt_stream_append_event(struct bt_stream *stream,
+               struct bt_event *event)
 {
        int ret = 0;
 
@@ -1236,9 +1259,9 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
        BT_LOGV("Appending event to stream: "
                "stream-addr=%p, stream-name=\"%s\", event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64,
-               stream, bt_ctf_stream_get_name(stream), event,
-               bt_ctf_event_class_get_name(bt_ctf_event_borrow_event_class(event)),
-               bt_ctf_event_class_get_id(bt_ctf_event_borrow_event_class(event)));
+               stream, bt_stream_get_name(stream), event,
+               bt_event_class_get_name(bt_event_borrow_event_class(event)),
+               bt_event_class_get_id(bt_event_borrow_event_class(event)));
 
        /*
         * The event is not supposed to have a parent stream at this
@@ -1263,14 +1286,14 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
 
        /* Make sure the various scopes of the event are set */
        BT_LOGV_STR("Validating event to append.");
-       ret = bt_ctf_event_validate(event);
+       ret = bt_event_validate(event);
        if (ret) {
                goto error;
        }
 
        /* Save the new event and freeze it */
        BT_LOGV_STR("Freezing the event to append.");
-       bt_ctf_event_freeze(event);
+       bt_event_freeze(event);
        g_ptr_array_add(stream->events, event);
 
        /*
@@ -1284,9 +1307,9 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
        BT_LOGV("Appended event to stream: "
                "stream-addr=%p, stream-name=\"%s\", event-addr=%p, "
                "event-class-name=\"%s\", event-class-id=%" PRId64,
-               stream, bt_ctf_stream_get_name(stream), event,
-               bt_ctf_event_class_get_name(bt_ctf_event_borrow_event_class(event)),
-               bt_ctf_event_class_get_id(bt_ctf_event_borrow_event_class(event)));
+               stream, bt_stream_get_name(stream), event,
+               bt_event_class_get_name(bt_event_borrow_event_class(event)),
+               bt_event_class_get_id(bt_event_borrow_event_class(event)));
 
 end:
        return ret;
@@ -1301,10 +1324,9 @@ error:
        return ret;
 }
 
-struct bt_ctf_field *bt_ctf_stream_get_packet_context(
-               struct bt_ctf_stream *stream)
+struct bt_field *bt_stream_get_packet_context(struct bt_stream *stream)
 {
-       struct bt_ctf_field *packet_context = NULL;
+       struct bt_field *packet_context = NULL;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
@@ -1314,7 +1336,7 @@ struct bt_ctf_field *bt_ctf_stream_get_packet_context(
        if (stream->pos.fd < 0) {
                BT_LOGW("Invalid parameter: stream is not a CTF writer stream: "
                        "stream-addr=%p, stream-name=\"%s\"", stream,
-                       bt_ctf_stream_get_name(stream));
+                       bt_stream_get_name(stream));
                goto end;
        }
 
@@ -1326,11 +1348,11 @@ end:
        return packet_context;
 }
 
-int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream,
-               struct bt_ctf_field *field)
+int bt_stream_set_packet_context(struct bt_stream *stream,
+               struct bt_field *field)
 {
        int ret = 0;
-       struct bt_ctf_field_type *field_type;
+       struct bt_field_type *field_type;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
@@ -1344,14 +1366,14 @@ int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       field_type = bt_ctf_field_get_type(field);
-       if (bt_ctf_field_type_compare(field_type,
+       field_type = bt_field_get_type(field);
+       if (bt_field_type_compare(field_type,
                        stream->stream_class->packet_context_type)) {
                BT_LOGW("Invalid parameter: packet context's field type is different from the stream's packet context field type: "
                        "stream-addr=%p, stream-name=\"%s\", "
                        "packet-context-field-addr=%p, "
                        "packet-context-ft-addr=%p",
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, field_type);
                ret = -1;
                goto end;
@@ -1363,15 +1385,14 @@ int bt_ctf_stream_set_packet_context(struct bt_ctf_stream *stream,
        BT_LOGV("Set stream's packet context field: "
                "stream-addr=%p, stream-name=\"%s\", "
                "packet-context-field-addr=%p",
-               stream, bt_ctf_stream_get_name(stream), field);
+               stream, bt_stream_get_name(stream), field);
 end:
        return ret;
 }
 
-struct bt_ctf_field *bt_ctf_stream_get_packet_header(
-               struct bt_ctf_stream *stream)
+struct bt_field *bt_stream_get_packet_header(struct bt_stream *stream)
 {
-       struct bt_ctf_field *packet_header = NULL;
+       struct bt_field *packet_header = NULL;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
@@ -1381,7 +1402,7 @@ struct bt_ctf_field *bt_ctf_stream_get_packet_header(
        if (stream->pos.fd < 0) {
                BT_LOGW("Invalid parameter: stream is not a CTF writer stream: "
                        "stream-addr=%p, stream-name=\"%s\"", stream,
-                       bt_ctf_stream_get_name(stream));
+                       bt_stream_get_name(stream));
                goto end;
        }
 
@@ -1393,12 +1414,12 @@ end:
        return packet_header;
 }
 
-int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
-               struct bt_ctf_field *field)
+int bt_stream_set_packet_header(struct bt_stream *stream,
+               struct bt_field *field)
 {
        int ret = 0;
-       struct bt_ctf_trace *trace = NULL;
-       struct bt_ctf_field_type *field_type = NULL;
+       struct bt_trace *trace = NULL;
+       struct bt_field_type *field_type = NULL;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
@@ -1412,7 +1433,7 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
                goto end;
        }
 
-       trace = (struct bt_ctf_trace *) bt_object_get_parent(stream);
+       trace = (struct bt_trace *) bt_object_get_parent(stream);
 
        if (!field) {
                if (trace->packet_header_type) {
@@ -1420,7 +1441,7 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
                                "stream-addr=%p, stream-name=\"%s\", "
                                "packet-header-field-addr=%p, "
                                "expected-ft-addr=%p",
-                               stream, bt_ctf_stream_get_name(stream),
+                               stream, bt_stream_get_name(stream),
                                field, trace->packet_header_type);
                        ret = -1;
                        goto end;
@@ -1429,15 +1450,15 @@ int bt_ctf_stream_set_packet_header(struct bt_ctf_stream *stream,
                goto skip_validation;
        }
 
-       field_type = bt_ctf_field_get_type(field);
+       field_type = bt_field_get_type(field);
        assert(field_type);
 
-       if (bt_ctf_field_type_compare(field_type, trace->packet_header_type)) {
+       if (bt_field_type_compare(field_type, trace->packet_header_type)) {
                BT_LOGW("Invalid parameter: packet header's field type is different from the stream's packet header field type: "
                        "stream-addr=%p, stream-name=\"%s\", "
                        "packet-header-field-addr=%p, "
                        "packet-header-ft-addr=%p",
-                       stream, bt_ctf_stream_get_name(stream),
+                       stream, bt_stream_get_name(stream),
                        field, field_type);
                ret = -1;
                goto end;
@@ -1449,7 +1470,7 @@ skip_validation:
        BT_LOGV("Set stream's packet header field: "
                "stream-addr=%p, stream-name=\"%s\", "
                "packet-header-field-addr=%p",
-               stream, bt_ctf_stream_get_name(stream), field);
+               stream, bt_stream_get_name(stream), field);
 end:
        BT_PUT(trace);
        bt_put(field_type);
@@ -1457,30 +1478,30 @@ end:
 }
 
 static
-void reset_structure_field(struct bt_ctf_field *structure, const char *name)
+void reset_structure_field(struct bt_field *structure, const char *name)
 {
-       struct bt_ctf_field *member;
+       struct bt_field *member;
 
-       member = bt_ctf_field_structure_get_field(structure, name);
+       member = bt_field_structure_get_field_by_name(structure, name);
        if (member) {
-               (void) bt_ctf_field_reset(member);
+               (void) bt_field_reset(member);
                bt_put(member);
        }
 }
 
-int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
+int bt_stream_flush(struct bt_stream *stream)
 {
        int ret = 0;
        size_t i;
-       struct bt_ctf_stream_pos packet_context_pos;
-       struct bt_ctf_trace *trace;
-       enum bt_ctf_byte_order native_byte_order;
+       struct bt_stream_pos packet_context_pos;
+       struct bt_trace *trace;
+       enum bt_byte_order native_byte_order;
        bool has_packet_size = false;
 
        if (!stream) {
                BT_LOGW_STR("Invalid parameter: stream is NULL.");
                ret = -1;
-               goto end;
+               goto end_no_stream;
        }
 
        if (stream->pos.fd < 0) {
@@ -1490,9 +1511,9 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        }
 
        if (stream->packet_context) {
-               struct bt_ctf_field *packet_size_field;
+               struct bt_field *packet_size_field;
 
-               packet_size_field = bt_ctf_field_structure_get_field(
+               packet_size_field = bt_field_structure_get_field_by_name(
                                stream->packet_context, "packet_size");
                has_packet_size = (packet_size_field != NULL);
                bt_put(packet_size_field);
@@ -1514,10 +1535,10 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
 
        BT_LOGV("Flushing stream's current packet: stream-addr=%p, "
                "stream-name=\"%s\", packet-index=%u", stream,
-               bt_ctf_stream_get_name(stream), stream->flushed_packet_count);
-       trace = bt_ctf_stream_class_borrow_trace(stream->stream_class);
+               bt_stream_get_name(stream), stream->flushed_packet_count);
+       trace = bt_stream_class_borrow_trace(stream->stream_class);
        assert(trace);
-       native_byte_order = bt_ctf_trace_get_native_byte_order(trace);
+       native_byte_order = bt_trace_get_native_byte_order(trace);
 
        ret = auto_populate_packet_header(stream);
        if (ret) {
@@ -1536,12 +1557,12 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        /* mmap the next packet */
        BT_LOGV("Seeking to the next packet: pos-offset=%" PRId64,
                stream->pos.offset);
-       bt_ctf_stream_pos_packet_seek(&stream->pos, 0, SEEK_CUR);
+       bt_stream_pos_packet_seek(&stream->pos, 0, SEEK_CUR);
        assert(stream->pos.packet_size % 8 == 0);
 
        if (stream->packet_header) {
                BT_LOGV_STR("Serializing packet header field.");
-               ret = bt_ctf_field_serialize(stream->packet_header, &stream->pos,
+               ret = bt_field_serialize(stream->packet_header, &stream->pos,
                        native_byte_order);
                if (ret) {
                        BT_LOGW("Cannot serialize stream's packet header field: "
@@ -1555,7 +1576,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                memcpy(&packet_context_pos, &stream->pos,
                        sizeof(packet_context_pos));
                BT_LOGV_STR("Serializing packet context field.");
-               ret = bt_ctf_field_serialize(stream->packet_context,
+               ret = bt_field_serialize(stream->packet_context,
                        &stream->pos, native_byte_order);
                if (ret) {
                        BT_LOGW("Cannot serialize stream's packet context field: "
@@ -1567,22 +1588,22 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        BT_LOGV("Serializing events: count=%u", stream->events->len);
 
        for (i = 0; i < stream->events->len; i++) {
-               struct bt_ctf_event *event = g_ptr_array_index(
+               struct bt_event *event = g_ptr_array_index(
                        stream->events, i);
-               struct bt_ctf_event_class *event_class =
-                       bt_ctf_event_borrow_event_class(event);
+               struct bt_event_class *event_class =
+                       bt_event_borrow_event_class(event);
 
                BT_LOGV("Serializing event: index=%zu, event-addr=%p, "
                        "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
                        "pos-offset=%" PRId64 ", packet-size=%" PRIu64,
-                       i, event, bt_ctf_event_class_get_name(event_class),
-                       bt_ctf_event_class_get_id(event_class),
+                       i, event, bt_event_class_get_name(event_class),
+                       bt_event_class_get_id(event_class),
                        stream->pos.offset, stream->pos.packet_size);
 
                /* Write event header */
                if (event->event_header) {
                        BT_LOGV_STR("Serializing event's header field.");
-                       ret = bt_ctf_field_serialize(event->event_header,
+                       ret = bt_field_serialize(event->event_header,
                                        &stream->pos, native_byte_order);
                        if (ret) {
                                BT_LOGW("Cannot serialize event's header field: "
@@ -1594,7 +1615,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                /* Write stream event context */
                if (event->stream_event_context) {
                        BT_LOGV_STR("Serializing event's stream event context field.");
-                       ret = bt_ctf_field_serialize(
+                       ret = bt_field_serialize(
                                event->stream_event_context, &stream->pos,
                                native_byte_order);
                        if (ret) {
@@ -1605,10 +1626,10 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                }
 
                /* Write event content */
-               ret = bt_ctf_event_serialize(event, &stream->pos,
+               ret = bt_event_serialize(event, &stream->pos,
                        native_byte_order);
                if (ret) {
-                       /* bt_ctf_event_serialize() logs errors */
+                       /* bt_event_serialize() logs errors */
                        goto end;
                }
        }
@@ -1637,7 +1658,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                 * if `packet_size` is missing, the current content size is
                 * equal to the current packet size.
                 */
-               struct bt_ctf_field *field = bt_ctf_field_structure_get_field(
+               struct bt_field *field = bt_field_structure_get_field_by_name(
                        stream->packet_context, "content_size");
 
                bt_put(field);
@@ -1671,7 +1692,7 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
                }
 
                BT_LOGV("Rewriting (serializing) packet context field.");
-               ret = bt_ctf_field_serialize(stream->packet_context,
+               ret = bt_field_serialize(stream->packet_context,
                        &packet_context_pos, native_byte_order);
                if (ret) {
                        BT_LOGW("Cannot serialize stream's packet context field: "
@@ -1684,16 +1705,6 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        stream->flushed_packet_count++;
        stream->size += stream->pos.packet_size / CHAR_BIT;
 
-       do {
-               ret = ftruncate(stream->pos.fd, stream->size);
-       } while (ret == -1 && errno == EINTR);
-       if (ret == -1) {
-               BT_LOGE_ERRNO("Cannot ftruncate() stream file to new size",
-                               "size = %" PRIu64 ", name = %s",
-                               stream->size,
-                               stream->name ? stream->name->str : "(null)");
-       }
-
 end:
        /* Reset automatically-set fields. */
        if (stream->packet_context) {
@@ -1717,43 +1728,45 @@ end:
                        "packet-size=%" PRIu64,
                        stream->pos.offset, stream->pos.packet_size);
        }
+
+end_no_stream:
        return ret;
 }
 
 /* Pre-2.0 CTF writer backward compatibility */
-void bt_ctf_stream_get(struct bt_ctf_stream *stream)
+void bt_ctf_stream_get(struct bt_stream *stream)
 {
        bt_get(stream);
 }
 
 /* Pre-2.0 CTF writer backward compatibility */
-void bt_ctf_stream_put(struct bt_ctf_stream *stream)
+void bt_ctf_stream_put(struct bt_stream *stream)
 {
        bt_put(stream);
 }
 
 static
-void bt_ctf_stream_destroy(struct bt_object *obj)
+void bt_stream_destroy(struct bt_object *obj)
 {
-       struct bt_ctf_stream *stream;
+       struct bt_stream *stream;
        int i;
 
-       stream = container_of(obj, struct bt_ctf_stream, base);
+       stream = container_of(obj, struct bt_stream, base);
        BT_LOGD("Destroying stream object: addr=%p, name=\"%s\"",
-               stream, bt_ctf_stream_get_name(stream));
+               stream, bt_stream_get_name(stream));
 
        /* Call destroy listeners in reverse registration order */
        for (i = stream->destroy_listeners->len - 1; i >= 0; i--) {
-               struct bt_ctf_stream_destroy_listener *listener =
+               struct bt_stream_destroy_listener *listener =
                        &g_array_index(stream->destroy_listeners,
-                               struct bt_ctf_stream_destroy_listener, i);
+                               struct bt_stream_destroy_listener, i);
 
                BT_LOGD("Calling destroy listener: func=%p, data=%p, index=%d",
                        listener->func, listener->data, i);
                listener->func(stream, listener->data);
        }
 
-       (void) bt_ctf_stream_pos_fini(&stream->pos);
+       (void) bt_stream_pos_fini(&stream->pos);
        if (stream->pos.fd >= 0) {
                int ret;
 
@@ -1766,16 +1779,14 @@ void bt_ctf_stream_destroy(struct bt_object *obj)
                        ret = ftruncate(stream->pos.fd, stream->size);
                } while (ret == -1 && errno == EINTR);
                if (ret) {
-                       BT_LOGE("Failed to truncate stream file: %s: "
-                               "ret=%d, errno=%d, size=%" PRIu64,
-                               strerror(errno), ret, errno,
-                               (uint64_t) stream->size);
+                       BT_LOGE_ERRNO("Failed to truncate stream file",
+                               ": ret=%d, size=%" PRIu64,
+                               ret, (uint64_t) stream->size);
                }
 
                if (close(stream->pos.fd)) {
-                       BT_LOGE("Failed to close stream file: %s: "
-                               "ret=%d, errno=%d", strerror(errno),
-                               ret, errno);
+                       BT_LOGE_ERRNO("Failed to close stream file",
+                               ": ret=%d", ret);
                }
        }
 
@@ -1822,17 +1833,17 @@ void bt_ctf_stream_destroy(struct bt_object *obj)
 }
 
 static
-int _set_structure_field_integer(struct bt_ctf_field *structure, char *name,
+int _set_structure_field_integer(struct bt_field *structure, char *name,
                uint64_t value, bt_bool force)
 {
        int ret = 0;
-       struct bt_ctf_field_type *field_type = NULL;
-       struct bt_ctf_field *integer;
+       struct bt_field_type *field_type = NULL;
+       struct bt_field *integer;
 
        assert(structure);
        assert(name);
 
-       integer = bt_ctf_field_structure_get_field(structure, name);
+       integer = bt_field_structure_get_field_by_name(structure, name);
        if (!integer) {
                /* Field not found, not an error. */
                BT_LOGV("Field not found: struct-field-addr=%p, "
@@ -1841,16 +1852,16 @@ int _set_structure_field_integer(struct bt_ctf_field *structure, char *name,
        }
 
        /* Make sure the payload has not already been set. */
-       if (!force && bt_ctf_field_is_set(integer)) {
+       if (!force && bt_field_is_set(integer)) {
                /* Payload already set, not an error */
                BT_LOGV("Field's payload is already set: struct-field-addr=%p, "
                        "name=\"%s\", force=%d", structure, name, force);
                goto end;
        }
 
-       field_type = bt_ctf_field_get_type(integer);
+       field_type = bt_field_get_type(integer);
        assert(field_type);
-       if (bt_ctf_field_type_get_type_id(field_type) != BT_CTF_FIELD_TYPE_ID_INTEGER) {
+       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) {
                /*
                 * The user most likely meant for us to populate this field
                 * automatically. However, we can only do this if the field
@@ -1859,16 +1870,16 @@ int _set_structure_field_integer(struct bt_ctf_field *structure, char *name,
                BT_LOGW("Invalid parameter: field's type is not an integer field type: "
                        "field-addr=%p, ft-addr=%p, ft-id=%s",
                        integer, field_type,
-                       bt_ctf_field_type_id_string(field_type->id));
+                       bt_field_type_id_string(field_type->id));
                ret = -1;
                goto end;
        }
 
-       if (bt_ctf_field_type_integer_get_signed(field_type)) {
-               ret = bt_ctf_field_signed_integer_set_value(integer,
+       if (bt_field_type_integer_is_signed(field_type)) {
+               ret = bt_field_signed_integer_set_value(integer,
                        (int64_t) value);
        } else {
-               ret = bt_ctf_field_unsigned_integer_set_value(integer, value);
+               ret = bt_field_unsigned_integer_set_value(integer, value);
        }
        ret = !ret ? 1 : ret;
 end:
@@ -1884,13 +1895,13 @@ end:
  * <0 if an error was encoutered
  */
 static
-int try_set_structure_field_integer(struct bt_ctf_field *structure, char *name,
+int try_set_structure_field_integer(struct bt_field *structure, char *name,
                uint64_t value)
 {
        return _set_structure_field_integer(structure, name, value, BT_FALSE);
 }
 
-const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream)
+const char *bt_stream_get_name(struct bt_stream *stream)
 {
        const char *name = NULL;
 
@@ -1905,7 +1916,7 @@ end:
        return name;
 }
 
-int bt_ctf_stream_is_writer(struct bt_ctf_stream *stream)
+int bt_stream_is_writer(struct bt_stream *stream)
 {
        int ret = -1;
 
@@ -1921,7 +1932,7 @@ end:
 }
 
 BT_HIDDEN
-void bt_ctf_stream_map_component_to_port(struct bt_ctf_stream *stream,
+void bt_stream_map_component_to_port(struct bt_stream *stream,
                struct bt_component *comp,
                struct bt_port *port)
 {
@@ -1940,7 +1951,7 @@ void bt_ctf_stream_map_component_to_port(struct bt_ctf_stream *stream,
        BT_LOGV("Adding component's destroy listener for stream: "
                "stream-addr=%p, stream-name=\"%s\", comp-addr=%p, "
                "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"",
-               stream, bt_ctf_stream_get_name(stream),
+               stream, bt_stream_get_name(stream),
                comp, bt_component_get_name(comp), port,
                bt_port_get_name(port));
        bt_component_add_destroy_listener(comp, component_destroy_listener,
@@ -1950,7 +1961,7 @@ void bt_ctf_stream_map_component_to_port(struct bt_ctf_stream *stream,
 }
 
 BT_HIDDEN
-struct bt_port *bt_ctf_stream_port_for_component(struct bt_ctf_stream *stream,
+struct bt_port *bt_stream_port_for_component(struct bt_stream *stream,
                struct bt_component *comp)
 {
        assert(stream);
@@ -1960,10 +1971,10 @@ struct bt_port *bt_ctf_stream_port_for_component(struct bt_ctf_stream *stream,
 }
 
 BT_HIDDEN
-void bt_ctf_stream_add_destroy_listener(struct bt_ctf_stream *stream,
-               bt_ctf_stream_destroy_listener_func func, void *data)
+void bt_stream_add_destroy_listener(struct bt_stream *stream,
+               bt_stream_destroy_listener_func func, void *data)
 {
-       struct bt_ctf_stream_destroy_listener listener;
+       struct bt_stream_destroy_listener listener;
 
        assert(stream);
        assert(func);
@@ -1972,12 +1983,12 @@ void bt_ctf_stream_add_destroy_listener(struct bt_ctf_stream *stream,
        g_array_append_val(stream->destroy_listeners, listener);
        BT_LOGV("Added stream destroy listener: stream-addr=%p, "
                "stream-name=\"%s\", func=%p, data=%p",
-               stream, bt_ctf_stream_get_name(stream), func, data);
+               stream, bt_stream_get_name(stream), func, data);
 }
 
 BT_HIDDEN
-void bt_ctf_stream_remove_destroy_listener(struct bt_ctf_stream *stream,
-               bt_ctf_stream_destroy_listener_func func, void *data)
+void bt_stream_remove_destroy_listener(struct bt_stream *stream,
+               bt_stream_destroy_listener_func func, void *data)
 {
        size_t i;
 
@@ -1985,22 +1996,22 @@ void bt_ctf_stream_remove_destroy_listener(struct bt_ctf_stream *stream,
        assert(func);
 
        for (i = 0; i < stream->destroy_listeners->len; i++) {
-               struct bt_ctf_stream_destroy_listener *listener =
+               struct bt_stream_destroy_listener *listener =
                        &g_array_index(stream->destroy_listeners,
-                               struct bt_ctf_stream_destroy_listener, i);
+                               struct bt_stream_destroy_listener, i);
 
                if (listener->func == func && listener->data == data) {
                        g_array_remove_index(stream->destroy_listeners, i);
                        i--;
                        BT_LOGV("Removed stream destroy listener: stream-addr=%p, "
                                "stream-name=\"%s\", func=%p, data=%p",
-                               stream, bt_ctf_stream_get_name(stream),
+                               stream, bt_stream_get_name(stream),
                                func, data);
                }
        }
 }
 
-int64_t bt_ctf_stream_get_id(struct bt_ctf_stream *stream)
+int64_t bt_stream_get_id(struct bt_stream *stream)
 {
        int64_t ret;
 
@@ -2013,7 +2024,7 @@ int64_t bt_ctf_stream_get_id(struct bt_ctf_stream *stream)
        ret = stream->id;
        if (ret < 0) {
                BT_LOGV("Stream's ID is not set: addr=%p, name=\"%s\"",
-                       stream, bt_ctf_stream_get_name(stream));
+                       stream, bt_stream_get_name(stream));
        }
 
 end:
This page took 0.083659 seconds and 4 git commands to generate.