ctf: logging: missing comma and space between fields
[babeltrace.git] / src / plugins / ctf / common / msg-iter / msg-iter.c
index cbca3cf1914b085d786f1a39a3d5bee44ed99bdf..b56cf0c1de8c680a5392e9527a0f2c028661977c 100644 (file)
@@ -1,26 +1,10 @@
 /*
- * Babeltrace - CTF message iterator
+ * SPDX-License-Identifier: MIT
  *
  * Copyright (c) 2015-2018 EfficiOS Inc. and Linux Foundation
  * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Babeltrace - CTF message iterator
  */
 
 #define BT_COMP_LOG_SELF_COMP (msg_it->self_comp)
@@ -43,7 +27,7 @@
 #include "msg-iter.h"
 #include "../bfcr/bfcr.h"
 
-struct bt_msg_iter;
+struct ctf_msg_iter;
 
 /* A visit stack entry */
 struct stack_entry {
@@ -64,11 +48,11 @@ struct stack_entry {
        size_t index;
 };
 
-struct bt_msg_iter;
+struct ctf_msg_iter;
 
 /* Visit stack */
 struct stack {
-       struct bt_msg_iter *msg_it;
+       struct ctf_msg_iter *msg_it;
 
        /* Entries (struct stack_entry) */
        GArray *entries;
@@ -87,7 +71,6 @@ enum state {
        STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN,
        STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
        STATE_AFTER_STREAM_PACKET_CONTEXT,
-       STATE_CHECK_EMIT_MSG_STREAM_BEGINNING,
        STATE_EMIT_MSG_STREAM_BEGINNING,
        STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS,
        STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS,
@@ -108,8 +91,8 @@ enum state {
        STATE_SKIP_PACKET_PADDING,
        STATE_EMIT_MSG_PACKET_END_MULTI,
        STATE_EMIT_MSG_PACKET_END_SINGLE,
-       STATE_CHECK_EMIT_MSG_STREAM_END,
        STATE_EMIT_QUEUED_MSG_PACKET_END,
+       STATE_CHECK_EMIT_MSG_STREAM_END,
        STATE_EMIT_MSG_STREAM_END,
        STATE_DONE,
 };
@@ -122,18 +105,12 @@ struct end_of_packet_snapshots {
 };
 
 /* CTF message iterator */
-struct bt_msg_iter {
+struct ctf_msg_iter {
        /* Visit stack */
        struct stack *stack;
 
        /* Current message iterator to create messages (weak) */
-       bt_self_message_iterator *msg_iter;
-
-       /* True to emit a stream beginning message. */
-       bool emit_stream_begin_msg;
-
-       /* True to emit a stream end message. */
-       bool emit_stream_end_msg;
+       bt_self_message_iterator *self_msg_iter;
 
        /*
         * True if library objects are unavailable during the decoding and
@@ -141,9 +118,6 @@ struct bt_msg_iter {
         */
        bool dry_run;
 
-       /* True to set the stream */
-       bool set_stream;
-
        /*
         * Current dynamic scope field pointer.
         *
@@ -168,9 +142,6 @@ struct bt_msg_iter {
                struct ctf_event_class *ec;
        } meta;
 
-       /* Current packet context field wrapper (NULL if not created yet) */
-       bt_packet_context_field *packet_context_field;
-
        /* Current packet (NULL if not created yet) */
        bt_packet *packet;
 
@@ -189,6 +160,20 @@ struct bt_msg_iter {
         */
        bool emit_delayed_packet_beginning_msg;
 
+       /*
+        * True if this is the first packet we are reading, and therefore if we
+        * should emit a stream beginning message.
+        */
+       bool emit_stream_beginning_message;
+
+       /*
+        * True if we need to emit a stream end message at the end of the
+        * current stream. A live stream may never receive any data and thus
+        * never send a stream beginning message which removes the need to emit
+        * a stream end message.
+        */
+       bool emit_stream_end_message;
+
        /* Database of current dynamic scopes */
        struct {
                bt_field *stream_packet_context;
@@ -223,7 +208,7 @@ struct bt_msg_iter {
 
        /* Current medium data */
        struct {
-               struct bt_msg_iter_medium_ops medops;
+               struct ctf_msg_iter_medium_ops medops;
                size_t max_request_sz;
                void *data;
        } medium;
@@ -290,6 +275,10 @@ const char *state_string(enum state state)
                return "AFTER_STREAM_PACKET_CONTEXT";
        case STATE_EMIT_MSG_STREAM_BEGINNING:
                return "EMIT_MSG_STREAM_BEGINNING";
+       case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS:
+               return "CHECK_EMIT_MSG_DISCARDED_EVENTS";
+       case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS:
+               return "CHECK_EMIT_MSG_DISCARDED_PACKETS";
        case STATE_EMIT_MSG_PACKET_BEGINNING:
                return "EMIT_MSG_PACKET_BEGINNING";
        case STATE_EMIT_MSG_DISCARDED_EVENTS:
@@ -326,17 +315,19 @@ const char *state_string(enum state state)
                return "EMIT_MSG_PACKET_END_SINGLE";
        case STATE_EMIT_QUEUED_MSG_PACKET_END:
                return "EMIT_QUEUED_MSG_PACKET_END";
+       case STATE_CHECK_EMIT_MSG_STREAM_END:
+               return "CHECK_EMIT_MSG_STREAM_END";
        case STATE_EMIT_MSG_STREAM_END:
                return "EMIT_MSG_STREAM_END";
        case STATE_DONE:
                return "DONE";
-       default:
-               return "(unknown)";
        }
+
+       bt_common_abort();
 }
 
 static
-struct stack *stack_new(struct bt_msg_iter *msg_it)
+struct stack *stack_new(struct ctf_msg_iter *msg_it)
 {
        bt_self_component *self_comp = msg_it->self_comp;
        struct stack *stack = NULL;
@@ -370,7 +361,7 @@ end:
 static
 void stack_destroy(struct stack *stack)
 {
-       struct bt_msg_iter *msg_it;
+       struct ctf_msg_iter *msg_it;
 
        BT_ASSERT_DBG(stack);
        msg_it = stack->msg_it;
@@ -387,7 +378,7 @@ static
 void stack_push(struct stack *stack, bt_field *base)
 {
        struct stack_entry *entry;
-       struct bt_msg_iter *msg_it;
+       struct ctf_msg_iter *msg_it;
 
        BT_ASSERT_DBG(stack);
        msg_it = stack->msg_it;
@@ -416,7 +407,7 @@ unsigned int stack_size(struct stack *stack)
 static
 void stack_pop(struct stack *stack)
 {
-       struct bt_msg_iter *msg_it;
+       struct ctf_msg_iter *msg_it;
 
        BT_ASSERT_DBG(stack);
        BT_ASSERT_DBG(stack_size(stack));
@@ -450,33 +441,33 @@ void stack_clear(struct stack *stack)
 }
 
 static inline
-enum bt_msg_iter_status msg_iter_status_from_m_status(
-               enum bt_msg_iter_medium_status m_status)
+enum ctf_msg_iter_status msg_iter_status_from_m_status(
+               enum ctf_msg_iter_medium_status m_status)
 {
        /* They are the same */
        return (int) m_status;
 }
 
 static inline
-size_t buf_size_bits(struct bt_msg_iter *msg_it)
+size_t buf_size_bits(struct ctf_msg_iter *msg_it)
 {
        return msg_it->buf.sz * 8;
 }
 
 static inline
-size_t buf_available_bits(struct bt_msg_iter *msg_it)
+size_t buf_available_bits(struct ctf_msg_iter *msg_it)
 {
        return buf_size_bits(msg_it) - msg_it->buf.at;
 }
 
 static inline
-size_t packet_at(struct bt_msg_iter *msg_it)
+size_t packet_at(struct ctf_msg_iter *msg_it)
 {
        return msg_it->buf.packet_offset + msg_it->buf.at;
 }
 
 static inline
-void buf_consume_bits(struct bt_msg_iter *msg_it, size_t incr)
+void buf_consume_bits(struct ctf_msg_iter *msg_it, size_t incr)
 {
        BT_COMP_LOGT("Advancing cursor: msg-it-addr=%p, cur-before=%zu, cur-after=%zu",
                msg_it, msg_it->buf.at, msg_it->buf.at + incr);
@@ -484,13 +475,13 @@ void buf_consume_bits(struct bt_msg_iter *msg_it, size_t incr)
 }
 
 static
-enum bt_msg_iter_status request_medium_bytes(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status request_medium_bytes(
+               struct ctf_msg_iter *msg_it)
 {
        bt_self_component *self_comp = msg_it->self_comp;
        uint8_t *buffer_addr = NULL;
        size_t buffer_sz = 0;
-       enum bt_msg_iter_medium_status m_status;
+       enum ctf_msg_iter_medium_status m_status;
 
        BT_COMP_LOGD("Calling user function (request bytes): msg-it-addr=%p, "
                "request-size=%zu", msg_it, msg_it->medium.max_request_sz);
@@ -498,9 +489,9 @@ enum bt_msg_iter_status request_medium_bytes(
                msg_it->medium.max_request_sz, &buffer_addr,
                &buffer_sz, msg_it->medium.data);
        BT_COMP_LOGD("User function returned: status=%s, buf-addr=%p, buf-size=%zu",
-               bt_msg_iter_medium_status_string(m_status),
+               ctf_msg_iter_medium_status_string(m_status),
                buffer_addr, buffer_sz);
-       if (m_status == BT_MSG_ITER_MEDIUM_STATUS_OK) {
+       if (m_status == CTF_MSG_ITER_MEDIUM_STATUS_OK) {
                BT_ASSERT(buffer_sz != 0);
 
                /* New packet offset is old one + old size (in bits) */
@@ -520,9 +511,9 @@ enum bt_msg_iter_status request_medium_bytes(
                        "packet-offset=%zu, cur=%zu, size=%zu, addr=%p",
                        msg_it->buf.packet_offset, msg_it->buf.at,
                        msg_it->buf.sz, msg_it->buf.addr);
-               BT_COMP_LOGD_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:",
+               BT_COMP_LOGT_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:",
                        buffer_addr);
-       } else if (m_status == BT_MSG_ITER_MEDIUM_STATUS_EOF) {
+       } else if (m_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) {
                /*
                 * User returned end of stream: validate that we're not
                 * in the middle of a packet header, packet context, or
@@ -549,15 +540,15 @@ enum bt_msg_iter_status request_medium_bytes(
                        "User function returned %s, but message iterator is in an unexpected state: "
                        "state=%s, cur-packet-size=%" PRId64 ", cur=%zu, "
                        "packet-cur=%zu, last-eh-at=%zu",
-                       bt_msg_iter_medium_status_string(m_status),
+                       ctf_msg_iter_medium_status_string(m_status),
                        state_string(msg_it->state),
                        msg_it->cur_exp_packet_total_size,
                        msg_it->buf.at, packet_at(msg_it),
                        msg_it->buf.last_eh_at);
-               m_status = BT_MSG_ITER_MEDIUM_STATUS_ERROR;
+               m_status = CTF_MSG_ITER_MEDIUM_STATUS_ERROR;
        } else if (m_status < 0) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp, "User function failed: "
-                       "status=%s", bt_msg_iter_medium_status_string(m_status));
+                       "status=%s", ctf_msg_iter_medium_status_string(m_status));
        }
 
 end:
@@ -565,14 +556,14 @@ end:
 }
 
 static inline
-enum bt_msg_iter_status buf_ensure_available_bits(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status buf_ensure_available_bits(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
 
        if (G_UNLIKELY(buf_available_bits(msg_it) == 0)) {
                /*
-                * This _cannot_ return BT_MSG_ITER_STATUS_OK
+                * This _cannot_ return CTF_MSG_ITER_STATUS_OK
                 * _and_ no bits.
                 */
                status = request_medium_bytes(msg_it);
@@ -582,13 +573,13 @@ enum bt_msg_iter_status buf_ensure_available_bits(
 }
 
 static
-enum bt_msg_iter_status read_dscope_begin_state(
-               struct bt_msg_iter *msg_it,
+enum ctf_msg_iter_status read_dscope_begin_state(
+               struct ctf_msg_iter *msg_it,
                struct ctf_field_class *dscope_fc,
                enum state done_state, enum state continue_state,
                bt_field *dscope_field)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        enum bt_bfcr_status bfcr_status;
        size_t consumed_bits;
@@ -616,7 +607,7 @@ enum bt_msg_iter_status read_dscope_begin_state(
                        "BFCR failed to start: msg-it-addr=%p, bfcr-addr=%p, "
                        "status=%s", msg_it, msg_it->bfcr,
                        bt_bfcr_status_string(bfcr_status));
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -628,10 +619,10 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_dscope_continue_state(
-               struct bt_msg_iter *msg_it, enum state done_state)
+enum ctf_msg_iter_status read_dscope_continue_state(
+               struct ctf_msg_iter *msg_it, enum state done_state)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        enum bt_bfcr_status bfcr_status;
        size_t consumed_bits;
@@ -640,16 +631,16 @@ enum bt_msg_iter_status read_dscope_continue_state(
                msg_it, msg_it->bfcr);
 
        status = buf_ensure_available_bits(msg_it);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                if (status < 0) {
                        BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                                "Cannot ensure that buffer has at least one byte: "
                                "msg-addr=%p, status=%s",
-                               msg_it, bt_msg_iter_status_string(status));
+                               msg_it, ctf_msg_iter_status_string(status));
                } else {
                        BT_COMP_LOGT("Cannot ensure that buffer has at least one byte: "
                                "msg-addr=%p, status=%s",
-                               msg_it, bt_msg_iter_status_string(status));
+                               msg_it, ctf_msg_iter_status_string(status));
                }
 
                goto end;
@@ -674,7 +665,7 @@ enum bt_msg_iter_status read_dscope_continue_state(
                        "BFCR failed to continue: msg-it-addr=%p, bfcr-addr=%p, "
                        "status=%s", msg_it, msg_it->bfcr,
                        bt_bfcr_status_string(bfcr_status));
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -685,7 +676,7 @@ end:
 }
 
 static
-void release_event_dscopes(struct bt_msg_iter *msg_it)
+void release_event_dscopes(struct ctf_msg_iter *msg_it)
 {
        msg_it->dscopes.event_common_context = NULL;
        msg_it->dscopes.event_spec_context = NULL;
@@ -693,22 +684,17 @@ void release_event_dscopes(struct bt_msg_iter *msg_it)
 }
 
 static
-void release_all_dscopes(struct bt_msg_iter *msg_it)
+void release_all_dscopes(struct ctf_msg_iter *msg_it)
 {
        msg_it->dscopes.stream_packet_context = NULL;
 
-       if (msg_it->packet_context_field) {
-               bt_packet_context_field_release(msg_it->packet_context_field);
-               msg_it->packet_context_field = NULL;
-       }
-
        release_event_dscopes(msg_it);
 }
 
 static
-enum bt_msg_iter_status switch_packet_state(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status switch_packet_state(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status;
        bt_self_component *self_comp = msg_it->self_comp;
 
        /*
@@ -732,6 +718,30 @@ enum bt_msg_iter_status switch_packet_state(struct bt_msg_iter *msg_it)
        release_all_dscopes(msg_it);
        msg_it->cur_dscope_field = NULL;
 
+       if (msg_it->medium.medops.switch_packet) {
+               enum ctf_msg_iter_medium_status medium_status;
+
+               medium_status = msg_it->medium.medops.switch_packet(msg_it->medium.data);
+               if (medium_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) {
+                       /* No more packets. */
+                       msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_END;
+                       status = CTF_MSG_ITER_STATUS_OK;
+                       goto end;
+               } else if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) {
+                       status = (int) medium_status;
+                       goto end;
+               }
+
+               /*
+                * After the packet switch, the medium might want to give us a
+                * different buffer for the new packet.
+                */
+               status = request_medium_bytes(msg_it);
+               if (status != CTF_MSG_ITER_STATUS_OK) {
+                       goto end;
+               }
+       }
+
        /*
         * Adjust current buffer so that addr points to the beginning of the new
         * packet.
@@ -744,7 +754,7 @@ enum bt_msg_iter_status switch_packet_state(struct bt_msg_iter *msg_it)
                        BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                                "Cannot switch packet: current position is not a multiple of 8: "
                                "msg-it-addr=%p, cur=%zu", msg_it, msg_it->buf.at);
-                       status = BT_MSG_ITER_STATUS_ERROR;
+                       status = CTF_MSG_ITER_STATUS_ERROR;
                        goto end;
                }
 
@@ -768,17 +778,18 @@ enum bt_msg_iter_status switch_packet_state(struct bt_msg_iter *msg_it)
        msg_it->snapshots.end_clock = UINT64_C(-1);
        msg_it->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
 
+       status = CTF_MSG_ITER_STATUS_OK;
 end:
        return status;
 }
 
 static
-enum bt_msg_iter_status read_packet_header_begin_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_packet_header_begin_state(
+               struct ctf_msg_iter *msg_it)
 {
        struct ctf_field_class *packet_header_fc = NULL;
        bt_self_component *self_comp = msg_it->self_comp;
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
 
        /*
         * Make sure at least one bit is available for this packet. An
@@ -787,10 +798,10 @@ enum bt_msg_iter_status read_packet_header_begin_state(
         */
        status = buf_ensure_available_bits(msg_it);
        switch (status) {
-       case BT_MSG_ITER_STATUS_OK:
+       case CTF_MSG_ITER_STATUS_OK:
                break;
-       case BT_MSG_ITER_STATUS_EOF:
-               status = BT_MSG_ITER_STATUS_OK;
+       case CTF_MSG_ITER_STATUS_EOF:
+               status = CTF_MSG_ITER_STATUS_OK;
                msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_END;
                goto end;
        default:
@@ -807,7 +818,7 @@ enum bt_msg_iter_status read_packet_header_begin_state(
        msg_it->cur_stream_class_id = -1;
        msg_it->cur_event_class_id = -1;
        msg_it->cur_data_stream_id = -1;
-       BT_COMP_LOGD("Decoding packet header field:"
+       BT_COMP_LOGD("Decoding packet header field: "
                "msg-it-addr=%p, trace-class-addr=%p, fc-addr=%p",
                msg_it, msg_it->meta.tc, packet_header_fc);
        status = read_dscope_begin_state(msg_it, packet_header_fc,
@@ -826,17 +837,17 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_packet_header_continue_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_packet_header_continue_state(
+               struct ctf_msg_iter *msg_it)
 {
        return read_dscope_continue_state(msg_it,
                STATE_AFTER_TRACE_PACKET_HEADER);
 }
 
 static inline
-enum bt_msg_iter_status set_current_stream_class(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status set_current_stream_class(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_stream_class *new_stream_class = NULL;
 
@@ -850,7 +861,7 @@ enum bt_msg_iter_status set_current_stream_class(struct bt_msg_iter *msg_it)
                                "Need exactly one stream class since there's "
                                "no stream class ID field: "
                                "msg-it-addr=%p", msg_it);
-                       status = BT_MSG_ITER_STATUS_ERROR;
+                       status = CTF_MSG_ITER_STATUS_ERROR;
                        goto end;
                }
 
@@ -866,7 +877,7 @@ enum bt_msg_iter_status set_current_stream_class(struct bt_msg_iter *msg_it)
                        "msg-it-addr=%p, stream-class-id=%" PRIu64 ", "
                        "trace-class-addr=%p",
                        msg_it, msg_it->cur_stream_class_id, msg_it->meta.tc);
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -884,7 +895,7 @@ enum bt_msg_iter_status set_current_stream_class(struct bt_msg_iter *msg_it)
                                new_stream_class,
                                new_stream_class->id,
                                msg_it->meta.tc);
-                       status = BT_MSG_ITER_STATUS_ERROR;
+                       status = CTF_MSG_ITER_STATUS_ERROR;
                        goto end;
                }
        } else {
@@ -901,9 +912,9 @@ end:
 }
 
 static inline
-enum bt_msg_iter_status set_current_stream(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status set_current_stream(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        bt_stream *stream = NULL;
 
@@ -919,14 +930,14 @@ enum bt_msg_iter_status set_current_stream(struct bt_msg_iter *msg_it)
        if (!stream) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                        "User function failed to return a stream object for the given stream class.");
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
        if (msg_it->stream && stream != msg_it->stream) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                        "User function returned a different stream than the previous one for the same sequence of packets.");
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -938,9 +949,9 @@ end:
 }
 
 static inline
-enum bt_msg_iter_status set_current_packet(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status set_current_packet(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        bt_packet *packet = NULL;
 
@@ -969,7 +980,7 @@ enum bt_msg_iter_status set_current_packet(struct bt_msg_iter *msg_it)
 
 error:
        BT_PACKET_PUT_REF_AND_RESET(packet);
-       status = BT_MSG_ITER_STATUS_ERROR;
+       status = CTF_MSG_ITER_STATUS_ERROR;
 
 end:
        BT_PACKET_MOVE_REF(msg_it->packet, packet);
@@ -977,27 +988,41 @@ end:
 }
 
 static
-enum bt_msg_iter_status after_packet_header_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status after_packet_header_state(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status;
+       enum ctf_msg_iter_status status;
 
        status = set_current_stream_class(msg_it);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
+       if (!msg_it->dry_run) {
+               status = set_current_stream(msg_it);
+               if (status != CTF_MSG_ITER_STATUS_OK) {
+                       goto end;
+               }
+
+               status = set_current_packet(msg_it);
+               if (status != CTF_MSG_ITER_STATUS_OK) {
+                       goto end;
+               }
+       }
+
        msg_it->state = STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN;
 
+       status = CTF_MSG_ITER_STATUS_OK;
+
 end:
        return status;
 }
 
 static
-enum bt_msg_iter_status read_packet_context_begin_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_packet_context_begin_state(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_field_class *packet_context_fc;
 
@@ -1013,31 +1038,11 @@ enum bt_msg_iter_status read_packet_context_begin_state(
                goto end;
        }
 
-       BT_ASSERT(!msg_it->packet_context_field);
-
        if (packet_context_fc->in_ir && !msg_it->dry_run) {
-               /*
-                * Create free packet context field from stream class.
-                * This field is going to be moved to the packet once we
-                * create it. We cannot create the packet now because a
-                * packet is created from a stream, and this API must be
-                * able to return the packet context properties without
-                * creating a stream
-                * (bt_msg_iter_get_packet_properties()).
-                */
-               msg_it->packet_context_field =
-                       bt_packet_context_field_create(
-                               msg_it->meta.sc->ir_sc);
-               if (!msg_it->packet_context_field) {
-                       BT_COMP_LOGE_APPEND_CAUSE(self_comp,
-                               "Cannot create packet context field wrapper from stream class.");
-                       status = BT_MSG_ITER_STATUS_ERROR;
-                       goto end;
-               }
-
+               BT_ASSERT(!msg_it->dscopes.stream_packet_context);
+               BT_ASSERT(msg_it->packet);
                msg_it->dscopes.stream_packet_context =
-                       bt_packet_context_field_borrow_field(
-                               msg_it->packet_context_field);
+                       bt_packet_borrow_context_field(msg_it->packet);
                BT_ASSERT(msg_it->dscopes.stream_packet_context);
        }
 
@@ -1065,18 +1070,18 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_packet_context_continue_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_packet_context_continue_state(
+               struct ctf_msg_iter *msg_it)
 {
        return read_dscope_continue_state(msg_it,
                        STATE_AFTER_STREAM_PACKET_CONTEXT);
 }
 
 static
-enum bt_msg_iter_status set_current_packet_content_sizes(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status set_current_packet_content_sizes(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
 
        if (msg_it->cur_exp_packet_total_size == -1) {
@@ -1106,7 +1111,7 @@ enum bt_msg_iter_status set_current_packet_content_sizes(
                        msg_it, msg_it->dscopes.stream_packet_context,
                        msg_it->cur_exp_packet_total_size,
                        msg_it->cur_exp_packet_content_size);
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -1120,24 +1125,19 @@ end:
 }
 
 static
-enum bt_msg_iter_status after_packet_context_state(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status after_packet_context_state(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status;
+       enum ctf_msg_iter_status status;
 
        status = set_current_packet_content_sizes(msg_it);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
-       if (msg_it->stream) {
-               /*
-                * Stream exists, which means we already emitted at
-                * least one packet beginning message, so the initial
-                * stream beginning message was also emitted.
-                */
-               msg_it->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
+       if (msg_it->emit_stream_beginning_message) {
+               msg_it->state = STATE_EMIT_MSG_STREAM_BEGINNING;
        } else {
-               msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_BEGINNING;
+               msg_it->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
        }
 
 end:
@@ -1145,9 +1145,9 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_event_header_begin_state(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_header_begin_state(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_field_class *event_header_fc = NULL;
 
@@ -1172,7 +1172,7 @@ enum bt_msg_iter_status read_event_header_begin_state(struct bt_msg_iter *msg_it
                                "cur=%zu", msg_it,
                                msg_it->cur_exp_packet_content_size,
                                packet_at(msg_it));
-                       status = BT_MSG_ITER_STATUS_ERROR;
+                       status = CTF_MSG_ITER_STATUS_ERROR;
                        goto end;
                }
        } else {
@@ -1182,10 +1182,10 @@ enum bt_msg_iter_status read_event_header_begin_state(struct bt_msg_iter *msg_it
                 */
                status = buf_ensure_available_bits(msg_it);
                switch (status) {
-               case BT_MSG_ITER_STATUS_OK:
+               case CTF_MSG_ITER_STATUS_OK:
                        break;
-               case BT_MSG_ITER_STATUS_EOF:
-                       status = BT_MSG_ITER_STATUS_OK;
+               case CTF_MSG_ITER_STATUS_EOF:
+                       status = CTF_MSG_ITER_STATUS_OK;
                        msg_it->state = STATE_EMIT_MSG_PACKET_END_SINGLE;
                        goto end;
                default:
@@ -1226,17 +1226,17 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_event_header_continue_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_header_continue_state(
+               struct ctf_msg_iter *msg_it)
 {
        return read_dscope_continue_state(msg_it,
                STATE_AFTER_EVENT_HEADER);
 }
 
 static inline
-enum bt_msg_iter_status set_current_event_class(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status set_current_event_class(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
 
        struct ctf_event_class *new_event_class = NULL;
@@ -1250,7 +1250,7 @@ enum bt_msg_iter_status set_current_event_class(struct bt_msg_iter *msg_it)
                        BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                                "Need exactly one event class since there's no event class ID field: "
                                "msg-it-addr=%p", msg_it);
-                       status = BT_MSG_ITER_STATUS_ERROR;
+                       status = CTF_MSG_ITER_STATUS_ERROR;
                        goto end;
                }
 
@@ -1268,7 +1268,7 @@ enum bt_msg_iter_status set_current_event_class(struct bt_msg_iter *msg_it)
                        "trace-class-addr=%p",
                        msg_it, msg_it->meta.sc->id, msg_it->cur_event_class_id,
                        msg_it->meta.tc);
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -1285,10 +1285,10 @@ end:
 }
 
 static inline
-enum bt_msg_iter_status set_current_event_message(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status set_current_event_message(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        bt_message *msg = NULL;
 
@@ -1299,15 +1299,15 @@ enum bt_msg_iter_status set_current_event_message(
                msg_it, msg_it->meta.ec,
                msg_it->meta.ec->name->str,
                msg_it->packet);
-       BT_ASSERT_DBG(msg_it->msg_iter);
+       BT_ASSERT_DBG(msg_it->self_msg_iter);
        BT_ASSERT_DBG(msg_it->meta.sc);
 
        if (bt_stream_class_borrow_default_clock_class(msg_it->meta.sc->ir_sc)) {
                msg = bt_message_event_create_with_packet_and_default_clock_snapshot(
-                       msg_it->msg_iter, msg_it->meta.ec->ir_ec,
+                       msg_it->self_msg_iter, msg_it->meta.ec->ir_ec,
                        msg_it->packet, msg_it->default_clock_snapshot);
        } else {
-               msg = bt_message_event_create_with_packet(msg_it->msg_iter,
+               msg = bt_message_event_create_with_packet(msg_it->self_msg_iter,
                        msg_it->meta.ec->ir_ec, msg_it->packet);
        }
 
@@ -1326,7 +1326,7 @@ enum bt_msg_iter_status set_current_event_message(
 
 error:
        BT_MESSAGE_PUT_REF_AND_RESET(msg);
-       status = BT_MSG_ITER_STATUS_ERROR;
+       status = CTF_MSG_ITER_STATUS_ERROR;
 
 end:
        BT_MESSAGE_MOVE_REF(msg_it->event_msg, msg);
@@ -1334,13 +1334,13 @@ end:
 }
 
 static
-enum bt_msg_iter_status after_event_header_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status after_event_header_state(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status;
+       enum ctf_msg_iter_status status;
 
        status = set_current_event_class(msg_it);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
@@ -1349,7 +1349,7 @@ enum bt_msg_iter_status after_event_header_state(
        }
 
        status = set_current_event_message(msg_it);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
@@ -1365,10 +1365,10 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_event_common_context_begin_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_common_context_begin_state(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_field_class *event_common_context_fc;
 
@@ -1412,18 +1412,18 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_event_common_context_continue_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_common_context_continue_state(
+               struct ctf_msg_iter *msg_it)
 {
        return read_dscope_continue_state(msg_it,
                STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN);
 }
 
 static
-enum bt_msg_iter_status read_event_spec_context_begin_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_spec_context_begin_state(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_field_class *event_spec_context_fc;
 
@@ -1470,18 +1470,18 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_event_spec_context_continue_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_spec_context_continue_state(
+               struct ctf_msg_iter *msg_it)
 {
        return read_dscope_continue_state(msg_it,
                STATE_DSCOPE_EVENT_PAYLOAD_BEGIN);
 }
 
 static
-enum bt_msg_iter_status read_event_payload_begin_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_payload_begin_state(
+               struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_field_class *event_payload_fc;
 
@@ -1528,16 +1528,16 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_event_payload_continue_state(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_event_payload_continue_state(
+               struct ctf_msg_iter *msg_it)
 {
        return read_dscope_continue_state(msg_it, STATE_EMIT_MSG_EVENT);
 }
 
 static
-enum bt_msg_iter_status skip_packet_padding_state(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status skip_packet_padding_state(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        size_t bits_to_skip;
        const enum state next_state = STATE_SWITCH_PACKET;
 
@@ -1552,7 +1552,7 @@ enum bt_msg_iter_status skip_packet_padding_state(struct bt_msg_iter *msg_it)
                BT_COMP_LOGD("Trying to skip %zu bits of padding: msg-it-addr=%p, size=%zu",
                        bits_to_skip, msg_it, bits_to_skip);
                status = buf_ensure_available_bits(msg_it);
-               if (status != BT_MSG_ITER_STATUS_OK) {
+               if (status != CTF_MSG_ITER_STATUS_OK) {
                        goto end;
                }
 
@@ -1573,32 +1573,8 @@ end:
 }
 
 static
-enum bt_msg_iter_status check_emit_msg_stream_beginning_state(
-               struct bt_msg_iter *msg_it)
-{
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
-
-       if (msg_it->set_stream) {
-               status = set_current_stream(msg_it);
-               if (status != BT_MSG_ITER_STATUS_OK) {
-                       goto end;
-               }
-       }
-
-       if (msg_it->emit_stream_begin_msg) {
-               msg_it->state = STATE_EMIT_MSG_STREAM_BEGINNING;
-       } else {
-               /* Stream's first packet */
-               msg_it->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
-       }
-
-end:
-       return status;
-}
-
-static
-enum bt_msg_iter_status check_emit_msg_discarded_events(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status check_emit_msg_discarded_events(
+               struct ctf_msg_iter *msg_it)
 {
        msg_it->state = STATE_EMIT_MSG_DISCARDED_EVENTS;
 
@@ -1635,12 +1611,12 @@ enum bt_msg_iter_status check_emit_msg_discarded_events(
        }
 
 end:
-       return BT_MSG_ITER_STATUS_OK;
+       return CTF_MSG_ITER_STATUS_OK;
 }
 
 static
-enum bt_msg_iter_status check_emit_msg_discarded_packets(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status check_emit_msg_discarded_packets(
+               struct ctf_msg_iter *msg_it)
 {
        msg_it->state = STATE_EMIT_MSG_DISCARDED_PACKETS;
 
@@ -1677,26 +1653,27 @@ enum bt_msg_iter_status check_emit_msg_discarded_packets(
        }
 
 end:
-       return BT_MSG_ITER_STATUS_OK;
+       return CTF_MSG_ITER_STATUS_OK;
 }
 
-static
-enum bt_msg_iter_status check_emit_msg_stream_end(
-               struct bt_msg_iter *msg_it)
+static inline
+enum state check_emit_msg_stream_end(struct ctf_msg_iter *msg_it)
 {
-       if (msg_it->emit_stream_end_msg) {
-               msg_it->state = STATE_EMIT_MSG_STREAM_END;
+       enum state next_state;
+
+       if (msg_it->emit_stream_end_message) {
+               next_state = STATE_EMIT_MSG_STREAM_END;
        } else {
-               msg_it->state = STATE_DONE;
+               next_state = STATE_DONE;
        }
 
-       return BT_MSG_ITER_STATUS_OK;
+       return next_state;
 }
 
 static inline
-enum bt_msg_iter_status handle_state(struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status handle_state(struct ctf_msg_iter *msg_it)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        const enum state state = msg_it->state;
 
        BT_COMP_LOGT("Handling state: msg-it-addr=%p, state=%s",
@@ -1728,9 +1705,6 @@ enum bt_msg_iter_status handle_state(struct bt_msg_iter *msg_it)
        case STATE_AFTER_STREAM_PACKET_CONTEXT:
                status = after_packet_context_state(msg_it);
                break;
-       case STATE_CHECK_EMIT_MSG_STREAM_BEGINNING:
-               status = check_emit_msg_stream_beginning_state(msg_it);
-               break;
        case STATE_EMIT_MSG_STREAM_BEGINNING:
                msg_it->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
                break;
@@ -1789,14 +1763,14 @@ enum bt_msg_iter_status handle_state(struct bt_msg_iter *msg_it)
                msg_it->state = STATE_SKIP_PACKET_PADDING;
                break;
        case STATE_EMIT_MSG_PACKET_END_SINGLE:
-               msg_it->state = STATE_CHECK_EMIT_MSG_STREAM_END;
-               break;
-       case STATE_CHECK_EMIT_MSG_STREAM_END:
-               status = check_emit_msg_stream_end(msg_it);
+               msg_it->state = STATE_EMIT_MSG_STREAM_END;
                break;
        case STATE_EMIT_QUEUED_MSG_PACKET_END:
                msg_it->state = STATE_EMIT_MSG_PACKET_END_SINGLE;
                break;
+       case STATE_CHECK_EMIT_MSG_STREAM_END:
+               msg_it->state = check_emit_msg_stream_end(msg_it);
+               break;
        case STATE_EMIT_MSG_STREAM_END:
                msg_it->state = STATE_DONE;
                break;
@@ -1805,18 +1779,18 @@ enum bt_msg_iter_status handle_state(struct bt_msg_iter *msg_it)
        default:
                BT_COMP_LOGF("Unknown CTF plugin message iterator state: "
                        "msg-it-addr=%p, state=%d", msg_it, msg_it->state);
-               abort();
+               bt_common_abort();
        }
 
        BT_COMP_LOGT("Handled state: msg-it-addr=%p, status=%s, "
                "prev-state=%s, cur-state=%s",
-               msg_it, bt_msg_iter_status_string(status),
+               msg_it, ctf_msg_iter_status_string(status),
                state_string(state), state_string(msg_it->state));
        return status;
 }
 
 BT_HIDDEN
-void bt_msg_iter_reset_for_next_stream_file(struct bt_msg_iter *msg_it)
+void ctf_msg_iter_reset_for_next_stream_file(struct ctf_msg_iter *msg_it)
 {
        BT_ASSERT(msg_it);
        BT_COMP_LOGD("Resetting message iterator: addr=%p", msg_it);
@@ -1829,11 +1803,6 @@ void bt_msg_iter_reset_for_next_stream_file(struct bt_msg_iter *msg_it)
        release_all_dscopes(msg_it);
        msg_it->cur_dscope_field = NULL;
 
-       if (msg_it->packet_context_field) {
-               bt_packet_context_field_release(msg_it->packet_context_field);
-               msg_it->packet_context_field = NULL;
-       }
-
        msg_it->buf.addr = NULL;
        msg_it->buf.sz = 0;
        msg_it->buf.at = 0;
@@ -1852,9 +1821,9 @@ void bt_msg_iter_reset_for_next_stream_file(struct bt_msg_iter *msg_it)
  * Resets the internal state of a CTF message iterator.
  */
 BT_HIDDEN
-void bt_msg_iter_reset(struct bt_msg_iter *msg_it)
+void ctf_msg_iter_reset(struct ctf_msg_iter *msg_it)
 {
-       bt_msg_iter_reset_for_next_stream_file(msg_it);
+       ctf_msg_iter_reset_for_next_stream_file(msg_it);
        msg_it->cur_stream_class_id = -1;
        msg_it->cur_data_stream_id = -1;
        msg_it->snapshots.discarded_events = UINT64_C(-1);
@@ -1863,10 +1832,12 @@ void bt_msg_iter_reset(struct bt_msg_iter *msg_it)
        msg_it->prev_packet_snapshots.packets = UINT64_C(-1);
        msg_it->prev_packet_snapshots.beginning_clock = UINT64_C(-1);
        msg_it->prev_packet_snapshots.end_clock = UINT64_C(-1);
+       msg_it->emit_stream_beginning_message = true;
+       msg_it->emit_stream_end_message = false;
 }
 
 static
-bt_field *borrow_next_field(struct bt_msg_iter *msg_it)
+bt_field *borrow_next_field(struct ctf_msg_iter *msg_it)
 {
        bt_field *next_field = NULL;
        bt_field *base_field;
@@ -1901,7 +1872,7 @@ bt_field *borrow_next_field(struct bt_msg_iter *msg_it)
                next_field = bt_field_variant_borrow_selected_option_field(
                        base_field);
        } else {
-               abort();
+               bt_common_abort();
        }
 
        BT_ASSERT_DBG(next_field);
@@ -1909,7 +1880,7 @@ bt_field *borrow_next_field(struct bt_msg_iter *msg_it)
 }
 
 static
-void update_default_clock(struct bt_msg_iter *msg_it, uint64_t new_val,
+void update_default_clock(struct ctf_msg_iter *msg_it, uint64_t new_val,
                uint64_t new_val_size)
 {
        uint64_t new_val_mask;
@@ -1954,7 +1925,7 @@ static
 enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value,
                struct ctf_field_class *fc, void *data)
 {
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        bt_self_component *self_comp = msg_it->self_comp;
        enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
 
@@ -2009,7 +1980,7 @@ enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value,
                msg_it->cur_exp_packet_content_size = value;
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
 update_def_clock:
@@ -2043,7 +2014,7 @@ enum bt_bfcr_status bfcr_unsigned_int_char_cb(uint64_t value,
                struct ctf_field_class *fc, void *data)
 {
        int ret;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        bt_self_component *self_comp = msg_it->self_comp;
        enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
        bt_field *string_field = NULL;
@@ -2097,7 +2068,7 @@ enum bt_bfcr_status bfcr_signed_int_cb(int64_t value,
 {
        enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
        bt_field *field = NULL;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        struct ctf_field_class_int *int_fc = (void *) fc;
 
        BT_COMP_LOGT("Signed integer function called from BFCR: "
@@ -2133,7 +2104,7 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value,
 {
        enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
        bt_field *field = NULL;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        bt_field_class_type type;
 
        BT_COMP_LOGT("Floating point number function called from BFCR: "
@@ -2167,7 +2138,7 @@ enum bt_bfcr_status bfcr_string_begin_cb(
                struct ctf_field_class *fc, void *data)
 {
        bt_field *field = NULL;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
 
        BT_COMP_LOGT("String (beginning) function called from BFCR: "
                "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, "
@@ -2202,7 +2173,7 @@ enum bt_bfcr_status bfcr_string_cb(const char *value,
 {
        enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
        bt_field *field = NULL;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        bt_self_component *self_comp = msg_it->self_comp;
        int ret;
 
@@ -2238,7 +2209,7 @@ static
 enum bt_bfcr_status bfcr_string_end_cb(
                struct ctf_field_class *fc, void *data)
 {
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
 
        BT_COMP_LOGT("String (end) function called from BFCR: "
                "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, "
@@ -2263,7 +2234,7 @@ static
 enum bt_bfcr_status bfcr_compound_begin_cb(
                struct ctf_field_class *fc, void *data)
 {
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        bt_field *field;
 
        BT_COMP_LOGT("Compound (beginning) function called from BFCR: "
@@ -2315,7 +2286,7 @@ static
 enum bt_bfcr_status bfcr_compound_end_cb(
                struct ctf_field_class *fc, void *data)
 {
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
 
        BT_COMP_LOGT("Compound (end) function called from BFCR: "
                "msg-it-addr=%p, bfcr-addr=%p, fc-addr=%p, "
@@ -2363,7 +2334,7 @@ static
 int64_t bfcr_get_sequence_length_cb(struct ctf_field_class *fc, void *data)
 {
        bt_field *seq_field;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        bt_self_component *self_comp = msg_it->self_comp;
        struct ctf_field_class_sequence *seq_fc = (void *) fc;
        int64_t length;
@@ -2411,7 +2382,7 @@ struct ctf_field_class *bfcr_borrow_variant_selected_field_class_cb(
        int ret;
        uint64_t i;
        int64_t option_index = -1;
-       struct bt_msg_iter *msg_it = data;
+       struct ctf_msg_iter *msg_it = data;
        struct ctf_field_class_variant *var_fc = (void *) fc;
        struct ctf_named_field_class *selected_option = NULL;
        bt_self_component *self_comp = msg_it->self_comp;
@@ -2469,7 +2440,7 @@ struct ctf_field_class *bfcr_borrow_variant_selected_field_class_cb(
        if (selected_option->fc->in_ir && !msg_it->dry_run) {
                bt_field *var_field = stack_top(msg_it->stack)->base;
 
-               ret = bt_field_variant_select_option_field_by_index(
+               ret = bt_field_variant_select_option_by_index(
                        var_field, option_index);
                if (ret) {
                        BT_COMP_LOGE_APPEND_CAUSE(self_comp,
@@ -2489,14 +2460,14 @@ end:
 }
 
 static
-bt_message *create_msg_stream_beginning(struct bt_msg_iter *msg_it)
+bt_message *create_msg_stream_beginning(struct ctf_msg_iter *msg_it)
 {
        bt_self_component *self_comp = msg_it->self_comp;
        bt_message *msg;
 
        BT_ASSERT(msg_it->stream);
-       BT_ASSERT(msg_it->msg_iter);
-       msg = bt_message_stream_beginning_create(msg_it->msg_iter,
+       BT_ASSERT(msg_it->self_msg_iter);
+       msg = bt_message_stream_beginning_create(msg_it->self_msg_iter,
                msg_it->stream);
        if (!msg) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
@@ -2509,7 +2480,7 @@ bt_message *create_msg_stream_beginning(struct bt_msg_iter *msg_it)
 }
 
 static
-bt_message *create_msg_stream_end(struct bt_msg_iter *msg_it)
+bt_message *create_msg_stream_end(struct ctf_msg_iter *msg_it)
 {
        bt_self_component *self_comp = msg_it->self_comp;
        bt_message *msg;
@@ -2522,8 +2493,8 @@ bt_message *create_msg_stream_end(struct bt_msg_iter *msg_it)
                goto end;
        }
 
-       BT_ASSERT(msg_it->msg_iter);
-       msg = bt_message_stream_end_create(msg_it->msg_iter,
+       BT_ASSERT(msg_it->self_msg_iter);
+       msg = bt_message_stream_end_create(msg_it->self_msg_iter,
                msg_it->stream);
        if (!msg) {
                BT_COMP_LOGE_APPEND_CAUSE(self_comp,
@@ -2537,38 +2508,16 @@ end:
 }
 
 static
-bt_message *create_msg_packet_beginning(struct bt_msg_iter *msg_it,
+bt_message *create_msg_packet_beginning(struct ctf_msg_iter *msg_it,
                bool use_default_cs)
 {
        bt_self_component *self_comp = msg_it->self_comp;
-       int ret;
        bt_message *msg;
        const bt_stream_class *sc = msg_it->meta.sc->ir_sc;
 
        BT_ASSERT(msg_it->packet);
        BT_ASSERT(sc);
-
-       if (msg_it->packet_context_field) {
-               ret = bt_packet_move_context_field(
-                       msg_it->packet, msg_it->packet_context_field);
-               if (ret) {
-                       msg = NULL;
-                       goto end;
-               }
-
-               msg_it->packet_context_field = NULL;
-
-               /*
-                * At this point msg_it->dscopes.stream_packet_context
-                * has the same value as the packet context field within
-                * msg_it->packet.
-                */
-               BT_ASSERT(bt_packet_borrow_context_field(
-                       msg_it->packet) ==
-                       msg_it->dscopes.stream_packet_context);
-       }
-
-       BT_ASSERT(msg_it->msg_iter);
+       BT_ASSERT(msg_it->self_msg_iter);
 
        if (msg_it->meta.sc->packets_have_ts_begin) {
                BT_ASSERT(msg_it->snapshots.beginning_clock != UINT64_C(-1));
@@ -2585,10 +2534,10 @@ bt_message *create_msg_packet_beginning(struct bt_msg_iter *msg_it,
                }
 
                msg = bt_message_packet_beginning_create_with_default_clock_snapshot(
-                       msg_it->msg_iter, msg_it->packet,
+                       msg_it->self_msg_iter, msg_it->packet,
                        raw_cs_value);
        } else {
-               msg = bt_message_packet_beginning_create(msg_it->msg_iter,
+               msg = bt_message_packet_beginning_create(msg_it->self_msg_iter,
                        msg_it->packet);
        }
 
@@ -2605,7 +2554,7 @@ end:
 }
 
 static
-bt_message *emit_delayed_packet_beg_msg(struct bt_msg_iter *msg_it)
+bt_message *emit_delayed_packet_beg_msg(struct ctf_msg_iter *msg_it)
 {
        bool packet_beg_ts_need_fix_up;
 
@@ -2626,7 +2575,7 @@ bt_message *emit_delayed_packet_beg_msg(struct bt_msg_iter *msg_it)
 
 
 static
-bt_message *create_msg_packet_end(struct bt_msg_iter *msg_it)
+bt_message *create_msg_packet_end(struct ctf_msg_iter *msg_it)
 {
        bt_message *msg;
        bool update_default_cs = true;
@@ -2686,15 +2635,15 @@ bt_message *create_msg_packet_end(struct bt_msg_iter *msg_it)
                msg_it->default_clock_snapshot = msg_it->snapshots.end_clock;
        }
 
-       BT_ASSERT(msg_it->msg_iter);
+       BT_ASSERT(msg_it->self_msg_iter);
 
        if (msg_it->meta.sc->packets_have_ts_end) {
                BT_ASSERT(msg_it->snapshots.end_clock != UINT64_C(-1));
                msg = bt_message_packet_end_create_with_default_clock_snapshot(
-                       msg_it->msg_iter, msg_it->packet,
+                       msg_it->self_msg_iter, msg_it->packet,
                        msg_it->default_clock_snapshot);
        } else {
-               msg = bt_message_packet_end_create(msg_it->msg_iter,
+               msg = bt_message_packet_end_create(msg_it->self_msg_iter,
                        msg_it->packet);
        }
 
@@ -2714,14 +2663,14 @@ end:
 }
 
 static
-bt_message *create_msg_discarded_events(struct bt_msg_iter *msg_it)
+bt_message *create_msg_discarded_events(struct ctf_msg_iter *msg_it)
 {
        bt_message *msg;
        bt_self_component *self_comp = msg_it->self_comp;
        uint64_t beginning_raw_value = UINT64_C(-1);
        uint64_t end_raw_value = UINT64_C(-1);
 
-       BT_ASSERT(msg_it->msg_iter);
+       BT_ASSERT(msg_it->self_msg_iter);
        BT_ASSERT(msg_it->stream);
        BT_ASSERT(msg_it->meta.sc->has_discarded_events);
 
@@ -2742,10 +2691,10 @@ bt_message *create_msg_discarded_events(struct bt_msg_iter *msg_it)
                BT_ASSERT(beginning_raw_value != UINT64_C(-1));
                BT_ASSERT(end_raw_value != UINT64_C(-1));
                msg = bt_message_discarded_events_create_with_default_clock_snapshots(
-                       msg_it->msg_iter, msg_it->stream, beginning_raw_value,
+                       msg_it->self_msg_iter, msg_it->stream, beginning_raw_value,
                        end_raw_value);
        } else {
-               msg = bt_message_discarded_events_create(msg_it->msg_iter,
+               msg = bt_message_discarded_events_create(msg_it->self_msg_iter,
                        msg_it->stream);
        }
 
@@ -2768,12 +2717,12 @@ end:
 }
 
 static
-bt_message *create_msg_discarded_packets(struct bt_msg_iter *msg_it)
+bt_message *create_msg_discarded_packets(struct ctf_msg_iter *msg_it)
 {
        bt_message *msg;
        bt_self_component *self_comp = msg_it->self_comp;
 
-       BT_ASSERT(msg_it->msg_iter);
+       BT_ASSERT(msg_it->self_msg_iter);
        BT_ASSERT(msg_it->stream);
        BT_ASSERT(msg_it->meta.sc->has_discarded_packets);
        BT_ASSERT(msg_it->prev_packet_snapshots.packets !=
@@ -2783,11 +2732,11 @@ bt_message *create_msg_discarded_packets(struct bt_msg_iter *msg_it)
                BT_ASSERT(msg_it->prev_packet_snapshots.end_clock != UINT64_C(-1));
                BT_ASSERT(msg_it->snapshots.beginning_clock != UINT64_C(-1));
                msg = bt_message_discarded_packets_create_with_default_clock_snapshots(
-                       msg_it->msg_iter, msg_it->stream,
+                       msg_it->self_msg_iter, msg_it->stream,
                        msg_it->prev_packet_snapshots.end_clock,
                        msg_it->snapshots.beginning_clock);
        } else {
-               msg = bt_message_discarded_packets_create(msg_it->msg_iter,
+               msg = bt_message_discarded_packets_create(msg_it->self_msg_iter,
                        msg_it->stream);
        }
 
@@ -2808,12 +2757,15 @@ end:
 }
 
 BT_HIDDEN
-struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc,
+struct ctf_msg_iter *ctf_msg_iter_create(
+               struct ctf_trace_class *tc,
                size_t max_request_sz,
-               struct bt_msg_iter_medium_ops medops, void *data,
-               bt_logging_level log_level, bt_self_component *self_comp)
+               struct ctf_msg_iter_medium_ops medops, void *data,
+               bt_logging_level log_level,
+               bt_self_component *self_comp,
+               bt_self_message_iterator *self_msg_iter)
 {
-       struct bt_msg_iter *msg_it = NULL;
+       struct ctf_msg_iter *msg_it = NULL;
        struct bt_bfcr_cbs cbs = {
                .classes = {
                        .signed_int = bfcr_signed_int_cb,
@@ -2834,18 +2786,21 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc,
        BT_ASSERT(tc);
        BT_ASSERT(medops.request_bytes);
        BT_ASSERT(medops.borrow_stream);
+       BT_ASSERT(max_request_sz > 0);
+
        BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, log_level, self_comp,
                "Creating CTF plugin message iterator: "
                "trace-addr=%p, max-request-size=%zu, "
                "data=%p, log-level=%s", tc, max_request_sz, data,
                bt_common_logging_level_string(log_level));
-       msg_it = g_new0(struct bt_msg_iter, 1);
+       msg_it = g_new0(struct ctf_msg_iter, 1);
        if (!msg_it) {
                BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
                        "Failed to allocate one CTF plugin message iterator.");
                goto end;
        }
        msg_it->self_comp = self_comp;
+       msg_it->self_msg_iter = self_msg_iter;
        msg_it->log_level = log_level;
        msg_it->meta.tc = tc;
        msg_it->medium.medops = medops;
@@ -2868,7 +2823,7 @@ struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc,
                goto error;
        }
 
-       bt_msg_iter_reset(msg_it);
+       ctf_msg_iter_reset(msg_it);
        BT_COMP_LOGD("Created CTF plugin message iterator: "
                "trace-addr=%p, max-request-size=%zu, "
                "data=%p, msg-it-addr=%p, log-level=%s",
@@ -2880,12 +2835,12 @@ end:
        return msg_it;
 
 error:
-       bt_msg_iter_destroy(msg_it);
+       ctf_msg_iter_destroy(msg_it);
        msg_it = NULL;
        goto end;
 }
 
-void bt_msg_iter_destroy(struct bt_msg_iter *msg_it)
+void ctf_msg_iter_destroy(struct ctf_msg_iter *msg_it)
 {
        BT_PACKET_PUT_REF_AND_RESET(msg_it->packet);
        BT_STREAM_PUT_REF_AND_RESET(msg_it->stream);
@@ -2910,25 +2865,23 @@ void bt_msg_iter_destroy(struct bt_msg_iter *msg_it)
        g_free(msg_it);
 }
 
-enum bt_msg_iter_status bt_msg_iter_get_next_message(
-               struct bt_msg_iter *msg_it,
-               bt_self_message_iterator *msg_iter, bt_message **message)
+enum ctf_msg_iter_status ctf_msg_iter_get_next_message(
+               struct ctf_msg_iter *msg_it,
+               const bt_message **message)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
 
        BT_ASSERT_DBG(msg_it);
        BT_ASSERT_DBG(message);
-       msg_it->msg_iter = msg_iter;
-       msg_it->set_stream = true;
        BT_COMP_LOGD("Getting next message: msg-it-addr=%p", msg_it);
 
        while (true) {
                status = handle_state(msg_it);
-               if (G_UNLIKELY(status == BT_MSG_ITER_STATUS_AGAIN)) {
-                       BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
+               if (G_UNLIKELY(status == CTF_MSG_ITER_STATUS_AGAIN)) {
+                       BT_COMP_LOGD_STR("Medium returned CTF_MSG_ITER_STATUS_AGAIN.");
                        goto end;
-               } else if (G_UNLIKELY(status != BT_MSG_ITER_STATUS_OK)) {
+               } else if (G_UNLIKELY(status != CTF_MSG_ITER_STATUS_OK)) {
                        BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                                "Cannot handle state: msg-it-addr=%p, state=%s",
                                msg_it, state_string(msg_it->state));
@@ -2946,7 +2899,7 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                        if (G_UNLIKELY(msg_it->emit_delayed_packet_beginning_msg)) {
                                *message = emit_delayed_packet_beg_msg(msg_it);
                                if (!*message) {
-                                       status = BT_MSG_ITER_STATUS_ERROR;
+                                       status = CTF_MSG_ITER_STATUS_ERROR;
                                }
 
                                /*
@@ -2965,7 +2918,7 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                        *message = create_msg_discarded_events(msg_it);
 
                        if (!*message) {
-                               status = BT_MSG_ITER_STATUS_ERROR;
+                               status = CTF_MSG_ITER_STATUS_ERROR;
                        }
 
                        goto end;
@@ -2974,16 +2927,11 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                        *message = create_msg_discarded_packets(msg_it);
 
                        if (!*message) {
-                               status = BT_MSG_ITER_STATUS_ERROR;
+                               status = CTF_MSG_ITER_STATUS_ERROR;
                        }
 
                        goto end;
                case STATE_EMIT_MSG_PACKET_BEGINNING:
-                       status = set_current_packet(msg_it);
-                       if (status != BT_MSG_ITER_STATUS_OK) {
-                               goto end;
-                       }
-
                        if (G_UNLIKELY(msg_it->meta.tc->quirks.barectf_event_before_packet)) {
                                msg_it->emit_delayed_packet_beginning_msg = true;
                                /*
@@ -2997,7 +2945,7 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                                /* create_msg_packet_beginning() logs errors */
                                *message = create_msg_packet_beginning(msg_it, false);
                                if (!*message) {
-                                       status = BT_MSG_ITER_STATUS_ERROR;
+                                       status = CTF_MSG_ITER_STATUS_ERROR;
                                }
                        }
 
@@ -3008,30 +2956,33 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                        *message = create_msg_packet_end(msg_it);
 
                        if (!*message) {
-                               status = BT_MSG_ITER_STATUS_ERROR;
+                               status = CTF_MSG_ITER_STATUS_ERROR;
                        }
 
                        goto end;
                case STATE_EMIT_MSG_STREAM_BEGINNING:
                        /* create_msg_stream_beginning() logs errors */
                        *message = create_msg_stream_beginning(msg_it);
+                       msg_it->emit_stream_beginning_message = false;
+                       msg_it->emit_stream_end_message = true;
 
                        if (!*message) {
-                               status = BT_MSG_ITER_STATUS_ERROR;
+                               status = CTF_MSG_ITER_STATUS_ERROR;
                        }
 
                        goto end;
                case STATE_EMIT_MSG_STREAM_END:
                        /* create_msg_stream_end() logs errors */
                        *message = create_msg_stream_end(msg_it);
+                       msg_it->emit_stream_end_message = false;
 
                        if (!*message) {
-                               status = BT_MSG_ITER_STATUS_ERROR;
+                               status = CTF_MSG_ITER_STATUS_ERROR;
                        }
 
                        goto end;
                case STATE_DONE:
-                       status = BT_MSG_ITER_STATUS_EOF;
+                       status = CTF_MSG_ITER_STATUS_EOF;
                        goto end;
                default:
                        /* Non-emitting state: continue */
@@ -3044,14 +2995,13 @@ end:
 }
 
 static
-enum bt_msg_iter_status decode_until_state( struct bt_msg_iter *msg_it,
+enum ctf_msg_iter_status decode_until_state( struct ctf_msg_iter *msg_it,
                enum state target_state_1, enum state target_state_2)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
        bt_self_component *self_comp = msg_it->self_comp;
 
        BT_ASSERT_DBG(msg_it);
-       msg_it->set_stream = false;
 
        do {
                /*
@@ -3064,10 +3014,10 @@ enum bt_msg_iter_status decode_until_state( struct bt_msg_iter *msg_it,
                }
 
                status = handle_state(msg_it);
-               if (G_UNLIKELY(status == BT_MSG_ITER_STATUS_AGAIN)) {
-                       BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
+               if (G_UNLIKELY(status == CTF_MSG_ITER_STATUS_AGAIN)) {
+                       BT_COMP_LOGD_STR("Medium returned CTF_MSG_ITER_STATUS_AGAIN.");
                        goto end;
-               } else if (G_UNLIKELY(status != BT_MSG_ITER_STATUS_OK)) {
+               } else if (G_UNLIKELY(status != CTF_MSG_ITER_STATUS_OK)) {
                        BT_COMP_LOGE_APPEND_CAUSE(self_comp,
                                "Cannot handle state: msg-it-addr=%p, state=%s",
                                msg_it, state_string(msg_it->state));
@@ -3083,7 +3033,6 @@ enum bt_msg_iter_status decode_until_state( struct bt_msg_iter *msg_it,
                case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
                case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
                case STATE_AFTER_STREAM_PACKET_CONTEXT:
-               case STATE_CHECK_EMIT_MSG_STREAM_BEGINNING:
                case STATE_EMIT_MSG_STREAM_BEGINNING:
                case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS:
                case STATE_EMIT_MSG_DISCARDED_EVENTS:
@@ -3105,7 +3054,6 @@ enum bt_msg_iter_status decode_until_state( struct bt_msg_iter *msg_it,
                case STATE_EMIT_MSG_PACKET_END_MULTI:
                case STATE_EMIT_MSG_PACKET_END_SINGLE:
                case STATE_EMIT_QUEUED_MSG_PACKET_END:
-               case STATE_CHECK_EMIT_MSG_STREAM_END:
                case STATE_EMIT_MSG_STREAM_END:
                        break;
                case STATE_DONE:
@@ -3114,7 +3062,7 @@ enum bt_msg_iter_status decode_until_state( struct bt_msg_iter *msg_it,
                        /* We should never get to the STATE_DONE state. */
                        BT_COMP_LOGF("Unexpected state: msg-it-addr=%p, state=%s",
                                msg_it, state_string(msg_it->state));
-                       abort();
+                       bt_common_abort();
                }
        } while (true);
 
@@ -3123,20 +3071,20 @@ end:
 }
 
 static
-enum bt_msg_iter_status read_packet_header_context_fields(
-               struct bt_msg_iter *msg_it)
+enum ctf_msg_iter_status read_packet_header_context_fields(
+               struct ctf_msg_iter *msg_it)
 {
        int ret;
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
 
        status = decode_until_state(msg_it, STATE_EMIT_MSG_PACKET_BEGINNING, -1);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
        ret = set_current_packet_content_sizes(msg_it);
        if (ret) {
-               status = BT_MSG_ITER_STATUS_ERROR;
+               status = CTF_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
@@ -3145,48 +3093,27 @@ end:
 }
 
 BT_HIDDEN
-void bt_msg_iter_set_medops_data(struct bt_msg_iter *msg_it,
-               void *medops_data)
-{
-       BT_ASSERT(msg_it);
-       msg_it->medium.data = medops_data;
-}
-
-BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_seek(struct bt_msg_iter *msg_it,
+enum ctf_msg_iter_status ctf_msg_iter_seek(struct ctf_msg_iter *msg_it,
                off_t offset)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
-       bt_self_component *self_comp = msg_it->self_comp;
-       enum bt_msg_iter_medium_status medium_status;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_medium_status medium_status;
 
        BT_ASSERT(msg_it);
-       if (offset < 0) {
-               BT_COMP_LOGE_APPEND_CAUSE(self_comp,
-                       "Cannot seek to negative offset: offset=%jd",
-                       (intmax_t) offset);
-               status = BT_MSG_ITER_STATUS_INVAL;
-               goto end;
-       }
-
-       if (!msg_it->medium.medops.seek) {
-               status = BT_MSG_ITER_STATUS_UNSUPPORTED;
-               BT_COMP_LOGD("Aborting seek as the iterator's underlying media does not implement seek support.");
-               goto end;
-       }
+       BT_ASSERT(offset >= 0);
+       BT_ASSERT(msg_it->medium.medops.seek);
 
-       medium_status = msg_it->medium.medops.seek(
-               BT_MSG_ITER_SEEK_WHENCE_SET, offset, msg_it->medium.data);
-       if (medium_status != BT_MSG_ITER_MEDIUM_STATUS_OK) {
-               if (medium_status == BT_MSG_ITER_MEDIUM_STATUS_EOF) {
-                       status = BT_MSG_ITER_STATUS_EOF;
+       medium_status = msg_it->medium.medops.seek(offset, msg_it->medium.data);
+       if (medium_status != CTF_MSG_ITER_MEDIUM_STATUS_OK) {
+               if (medium_status == CTF_MSG_ITER_MEDIUM_STATUS_EOF) {
+                       status = CTF_MSG_ITER_STATUS_EOF;
                } else {
-                       status = BT_MSG_ITER_STATUS_ERROR;
+                       status = CTF_MSG_ITER_STATUS_ERROR;
                        goto end;
                }
        }
 
-       bt_msg_iter_reset(msg_it);
+       ctf_msg_iter_reset(msg_it);
        msg_it->cur_packet_offset = offset;
 
 end:
@@ -3194,16 +3121,16 @@ end:
 }
 
 static
-enum bt_msg_iter_status clock_snapshot_at_msg_iter_state(
-               struct bt_msg_iter *msg_it, enum state target_state_1,
+enum ctf_msg_iter_status clock_snapshot_at_msg_iter_state(
+               struct ctf_msg_iter *msg_it, enum state target_state_1,
                enum state target_state_2, uint64_t *clock_snapshot)
 {
-       enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+       enum ctf_msg_iter_status status = CTF_MSG_ITER_STATUS_OK;
 
        BT_ASSERT_DBG(msg_it);
        BT_ASSERT_DBG(clock_snapshot);
        status = decode_until_state(msg_it, target_state_1, target_state_2);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
@@ -3213,16 +3140,16 @@ end:
 }
 
 BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_curr_packet_first_event_clock_snapshot(
-               struct bt_msg_iter *msg_it, uint64_t *first_clock_snapshot)
+enum ctf_msg_iter_status ctf_msg_iter_curr_packet_first_event_clock_snapshot(
+               struct ctf_msg_iter *msg_it, uint64_t *first_clock_snapshot)
 {
        return clock_snapshot_at_msg_iter_state(msg_it,
                STATE_AFTER_EVENT_HEADER, -1, first_clock_snapshot);
 }
 
 BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_curr_packet_last_event_clock_snapshot(
-               struct bt_msg_iter *msg_it, uint64_t *last_clock_snapshot)
+enum ctf_msg_iter_status ctf_msg_iter_curr_packet_last_event_clock_snapshot(
+               struct ctf_msg_iter *msg_it, uint64_t *last_clock_snapshot)
 {
        return clock_snapshot_at_msg_iter_state(msg_it,
                STATE_EMIT_MSG_PACKET_END_SINGLE,
@@ -3230,16 +3157,16 @@ enum bt_msg_iter_status bt_msg_iter_curr_packet_last_event_clock_snapshot(
 }
 
 BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
-               struct bt_msg_iter *msg_it,
-               struct bt_msg_iter_packet_properties *props)
+enum ctf_msg_iter_status ctf_msg_iter_get_packet_properties(
+               struct ctf_msg_iter *msg_it,
+               struct ctf_msg_iter_packet_properties *props)
 {
-       enum bt_msg_iter_status status;
+       enum ctf_msg_iter_status status;
 
        BT_ASSERT_DBG(msg_it);
        BT_ASSERT_DBG(props);
        status = read_packet_header_context_fields(msg_it);
-       if (status != BT_MSG_ITER_STATUS_OK) {
+       if (status != CTF_MSG_ITER_STATUS_OK) {
                goto end;
        }
 
@@ -3257,21 +3184,7 @@ end:
 }
 
 BT_HIDDEN
-void bt_msg_iter_set_emit_stream_beginning_message(struct bt_msg_iter *msg_it,
-               bool val)
-{
-       msg_it->emit_stream_begin_msg = val;
-}
-
-BT_HIDDEN
-void bt_msg_iter_set_emit_stream_end_message(struct bt_msg_iter *msg_it,
-               bool val)
-{
-       msg_it->emit_stream_end_msg = val;
-}
-
-BT_HIDDEN
-void bt_msg_iter_set_dry_run(struct bt_msg_iter *msg_it,
+void ctf_msg_iter_set_dry_run(struct ctf_msg_iter *msg_it,
                bool val)
 {
        msg_it->dry_run = val;
This page took 0.052768 seconds and 4 git commands to generate.