lib: remove CTF concepts of packet and event headers
[babeltrace.git] / plugins / ctf / common / msg-iter / msg-iter.c
index 4843f275e516a5a9db5df8da00da54562c8c5ab7..91d06e9da78355f4c33778ba69790fb741149f75 100644 (file)
@@ -120,21 +120,18 @@ struct bt_msg_iter {
        bool done_filling_string;
 
        /* Trace and classes */
+       /* True to set IR fields */
+       bool set_ir_fields;
+
        struct {
                struct ctf_trace_class *tc;
                struct ctf_stream_class *sc;
                struct ctf_event_class *ec;
        } meta;
 
-       /* Current packet header field wrapper (NULL if not created yet) */
-       bt_packet_header_field *packet_header_field;
-
-       /* Current packet header field wrapper (NULL if not created yet) */
+       /* Current packet context field wrapper (NULL if not created yet) */
        bt_packet_context_field *packet_context_field;
 
-       /* Current event header field (NULL if not created yet) */
-       bt_event_header_field *event_header_field;
-
        /* Current packet (NULL if not created yet) */
        bt_packet *packet;
 
@@ -149,9 +146,7 @@ struct bt_msg_iter {
 
        /* Database of current dynamic scopes */
        struct {
-               bt_field *trace_packet_header;
                bt_field *stream_packet_context;
-               bt_field *event_header;
                bt_field *event_common_context;
                bt_field *event_spec_context;
                bt_field *event_payload;
@@ -213,7 +208,7 @@ struct bt_msg_iter {
        off_t cur_packet_offset;
 
        /* Default clock's current value */
-       uint64_t default_clock_val;
+       uint64_t default_clock_snapshot;
 
        /* End of packet snapshots */
        struct {
@@ -616,13 +611,6 @@ end:
 static
 void release_event_dscopes(struct bt_msg_iter *notit)
 {
-       notit->dscopes.event_header = NULL;
-
-       if (notit->event_header_field) {
-               bt_event_header_field_release(notit->event_header_field);
-               notit->event_header_field = NULL;
-       }
-
        notit->dscopes.event_common_context = NULL;
        notit->dscopes.event_spec_context = NULL;
        notit->dscopes.event_payload = NULL;
@@ -631,13 +619,6 @@ void release_event_dscopes(struct bt_msg_iter *notit)
 static
 void release_all_dscopes(struct bt_msg_iter *notit)
 {
-       notit->dscopes.trace_packet_header = NULL;
-
-       if (notit->packet_header_field) {
-               bt_packet_header_field_release(notit->packet_header_field);
-               notit->packet_header_field = NULL;
-       }
-
        notit->dscopes.stream_packet_context = NULL;
 
        if (notit->packet_context_field) {
@@ -668,34 +649,6 @@ enum bt_msg_iter_status read_packet_header_begin_state(
                goto end;
        }
 
-       BT_ASSERT(!notit->packet_header_field);
-
-       if (packet_header_fc->in_ir) {
-               /*
-                * Create free packet header field from trace class.
-                * This field is going to be moved to the packet once we
-                * create it. We cannot create the packet now because:
-                *
-                * 1. A packet is created from a stream.
-                * 2. A stream is created from a stream class.
-                * 3. We need the packet header field's content to know
-                *    the ID of the stream class to select.
-                */
-               notit->packet_header_field =
-                       bt_packet_header_field_create(
-                               notit->meta.tc->ir_tc);
-               if (!notit->packet_header_field) {
-                       BT_LOGE_STR("Cannot create packet header field wrapper from trace class.");
-                       ret = BT_MSG_ITER_STATUS_ERROR;
-                       goto end;
-               }
-
-               notit->dscopes.trace_packet_header =
-                       bt_packet_header_field_borrow_field(
-                               notit->packet_header_field);
-               BT_ASSERT(notit->dscopes.trace_packet_header);
-       }
-
        notit->cur_stream_class_id = -1;
        notit->cur_event_class_id = -1;
        notit->cur_data_stream_id = -1;
@@ -704,8 +657,7 @@ enum bt_msg_iter_status read_packet_header_begin_state(
                notit, notit->meta.tc, packet_header_fc);
        ret = read_dscope_begin_state(notit, packet_header_fc,
                STATE_AFTER_TRACE_PACKET_HEADER,
-               STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE,
-               notit->dscopes.trace_packet_header);
+               STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE, NULL);
        if (ret < 0) {
                BT_LOGW("Cannot decode packet header field: "
                        "notit-addr=%p, trace-class-addr=%p, "
@@ -907,9 +859,9 @@ enum bt_msg_iter_status read_packet_context_begin_state(
                 * 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 header and context fields
-                * without creating a stream
-                * (bt_msg_iter_borrow_packet_header_context_fields()).
+                * able to return the packet context properties without
+                * creating a stream
+                * (bt_msg_iter_get_packet_properties()).
                 */
                notit->packet_context_field =
                        bt_packet_context_field_create(
@@ -1087,23 +1039,6 @@ enum bt_msg_iter_status read_event_header_begin_state(
                goto end;
        }
 
-       if (event_header_fc->in_ir) {
-               BT_ASSERT(!notit->event_header_field);
-               notit->event_header_field =
-                       bt_event_header_field_create(
-                               notit->meta.sc->ir_sc);
-               if (!notit->event_header_field) {
-                       BT_LOGE_STR("Cannot create event header field wrapper from trace class.");
-                       status = BT_MSG_ITER_STATUS_ERROR;
-                       goto end;
-               }
-
-               notit->dscopes.event_header =
-                       bt_event_header_field_borrow_field(
-                               notit->event_header_field);
-               BT_ASSERT(notit->dscopes.event_header);
-       }
-
        BT_LOGV("Decoding event header field: "
                "notit-addr=%p, stream-class-addr=%p, "
                "stream-class-id=%" PRId64 ", "
@@ -1113,8 +1048,7 @@ enum bt_msg_iter_status read_event_header_begin_state(
                event_header_fc);
        status = read_dscope_begin_state(notit, event_header_fc,
                STATE_AFTER_EVENT_HEADER,
-               STATE_DSCOPE_EVENT_HEADER_CONTINUE,
-               notit->dscopes.event_header);
+               STATE_DSCOPE_EVENT_HEADER_CONTINUE, NULL);
        if (status < 0) {
                BT_LOGW("Cannot decode event header field: "
                        "notit-addr=%p, stream-class-addr=%p, "
@@ -1242,29 +1176,6 @@ enum bt_msg_iter_status after_event_header_state(
        notit->event = bt_message_event_borrow_event(
                notit->event_msg);
        BT_ASSERT(notit->event);
-
-       if (notit->event_header_field) {
-               int ret;
-
-               BT_ASSERT(notit->event);
-               ret = bt_event_move_header_field(notit->event,
-                       notit->event_header_field);
-               if (ret) {
-                       status = BT_MSG_ITER_STATUS_ERROR;
-                       goto end;
-               }
-
-               notit->event_header_field = NULL;
-
-               /*
-                * At this point notit->dscopes.event_header has
-                * the same value as the event header field within
-                * notit->event.
-                */
-               BT_ASSERT(bt_event_borrow_header_field(
-                       notit->event) == notit->dscopes.event_header);
-       }
-
        notit->state = STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN;
 
 end:
@@ -1577,21 +1488,11 @@ void bt_msg_iter_reset(struct bt_msg_iter *notit)
        release_all_dscopes(notit);
        notit->cur_dscope_field = NULL;
 
-       if (notit->packet_header_field) {
-               bt_packet_header_field_release(notit->packet_header_field);
-               notit->packet_header_field = NULL;
-       }
-
        if (notit->packet_context_field) {
                bt_packet_context_field_release(notit->packet_context_field);
                notit->packet_context_field = NULL;
        }
 
-       if (notit->event_header_field) {
-               bt_event_header_field_release(notit->event_header_field);
-               notit->event_header_field = NULL;
-       }
-
        notit->buf.addr = NULL;
        notit->buf.sz = 0;
        notit->buf.at = 0;
@@ -1731,12 +1632,12 @@ void update_default_clock(struct bt_msg_iter *notit, uint64_t new_val,
         * current value directly.
         */
        if (new_val_size == 64) {
-               notit->default_clock_val = new_val;
+               notit->default_clock_snapshot = new_val;
                goto end;
        }
 
        new_val_mask = (1ULL << new_val_size) - 1;
-       cur_value_masked = notit->default_clock_val & new_val_mask;
+       cur_value_masked = notit->default_clock_snapshot & new_val_mask;
 
        if (new_val < cur_value_masked) {
                /*
@@ -1744,18 +1645,18 @@ void update_default_clock(struct bt_msg_iter *notit, uint64_t new_val,
                 * of the requested new value. Assume that the clock
                 * value wrapped only one time.
                 */
-               notit->default_clock_val += new_val_mask + 1;
+               notit->default_clock_snapshot += new_val_mask + 1;
        }
 
        /* Clear the low bits of the current clock value. */
-       notit->default_clock_val &= ~new_val_mask;
+       notit->default_clock_snapshot &= ~new_val_mask;
 
        /* Set the low bits of the current clock value. */
-       notit->default_clock_val |= new_val;
+       notit->default_clock_snapshot |= new_val;
 
 end:
        BT_LOGV("Updated default clock's value from integer field's value: "
-               "value=%" PRIu64, notit->default_clock_val);
+               "value=%" PRIu64, notit->default_clock_snapshot);
 }
 
 static
@@ -1946,7 +1847,11 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value,
                "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
                "fc-type=%d, fc-in-ir=%d, value=%f",
                notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
-       BT_ASSERT(fc->in_ir);
+
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
+
        field = borrow_next_field(notit);
        BT_ASSERT(field);
        BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
@@ -1954,6 +1859,8 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value,
                  BT_FIELD_CLASS_TYPE_REAL);
        bt_field_real_set_value(field, value);
        stack_top(notit->stack)->index++;
+
+end:
        return status;
 }
 
@@ -1970,7 +1877,10 @@ enum bt_bfcr_status bfcr_string_begin_cb(
                "fc-type=%d, fc-in-ir=%d",
                notit, notit->bfcr, fc, fc->type, fc->in_ir);
 
-       BT_ASSERT(fc->in_ir);
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
+
        field = borrow_next_field(notit);
        BT_ASSERT(field);
        BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
@@ -1985,6 +1895,8 @@ enum bt_bfcr_status bfcr_string_begin_cb(
         * subsequent call to bfcr_string_end_cb().
         */
        stack_push(notit->stack, field);
+
+end:
        return BT_BFCR_STATUS_OK;
 }
 
@@ -2002,7 +1914,11 @@ enum bt_bfcr_status bfcr_string_cb(const char *value,
                "fc-type=%d, fc-in-ir=%d, string-length=%zu",
                notit, notit->bfcr, fc, fc->type, fc->in_ir,
                len);
-       BT_ASSERT(fc->in_ir);
+
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
+
        field = stack_top(notit->stack)->base;
        BT_ASSERT(field);
 
@@ -2030,13 +1946,18 @@ enum bt_bfcr_status bfcr_string_end_cb(
                "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
                "fc-type=%d, fc-in-ir=%d",
                notit, notit->bfcr, fc, fc->type, fc->in_ir);
-       BT_ASSERT(fc->in_ir);
+
+       if (unlikely(!fc->in_ir)) {
+               goto end;
+       }
 
        /* Pop string field */
        stack_pop(notit->stack);
 
        /* Go to next field */
        stack_top(notit->stack)->index++;
+
+end:
        return BT_BFCR_STATUS_OK;
 }
 
@@ -2244,7 +2165,7 @@ end:
 }
 
 static
-void set_event_default_clock_value(struct bt_msg_iter *notit)
+void set_event_default_clock_snapshot(struct bt_msg_iter *notit)
 {
        bt_event *event =
                bt_message_event_borrow_event(
@@ -2254,8 +2175,8 @@ void set_event_default_clock_value(struct bt_msg_iter *notit)
        BT_ASSERT(event);
 
        if (bt_stream_class_borrow_default_clock_class(sc)) {
-               bt_event_set_default_clock_value(event,
-                       notit->default_clock_val);
+               bt_event_set_default_clock_snapshot(event,
+                       notit->default_clock_snapshot);
        }
 }
 
@@ -2341,37 +2262,18 @@ void notify_new_packet(struct bt_msg_iter *notit,
                        notit->packet, notit->snapshots.packets);
        }
 
-       if (bt_stream_class_packets_have_default_beginning_clock_value(sc)) {
+       if (bt_stream_class_packets_have_default_beginning_clock_snapshot(sc)) {
                BT_ASSERT(notit->snapshots.beginning_clock != UINT64_C(-1));
-               bt_packet_set_default_beginning_clock_value(
+               bt_packet_set_default_beginning_clock_snapshot(
                        notit->packet, notit->snapshots.beginning_clock);
        }
 
-       if (bt_stream_class_packets_have_default_end_clock_value(sc)) {
+       if (bt_stream_class_packets_have_default_end_clock_snapshot(sc)) {
                BT_ASSERT(notit->snapshots.end_clock != UINT64_C(-1));
-               bt_packet_set_default_end_clock_value(
+               bt_packet_set_default_end_clock_snapshot(
                        notit->packet, notit->snapshots.end_clock);
        }
 
-       if (notit->packet_header_field) {
-               ret = bt_packet_move_header_field(
-                       notit->packet, notit->packet_header_field);
-               if (ret) {
-                       goto end;
-               }
-
-               notit->packet_header_field = NULL;
-
-               /*
-                * At this point notit->dscopes.trace_packet_header has
-                * the same value as the packet header field within
-                * notit->packet.
-                */
-               BT_ASSERT(bt_packet_borrow_header_field(
-                       notit->packet) ==
-                       notit->dscopes.trace_packet_header);
-       }
-
        if (notit->packet_context_field) {
                ret = bt_packet_move_context_field(
                        notit->packet, notit->packet_context_field);
@@ -2382,8 +2284,8 @@ void notify_new_packet(struct bt_msg_iter *notit,
                notit->packet_context_field = NULL;
 
                /*
-                * At this point notit->dscopes.trace_packet_header has
-                * the same value as the packet header field within
+                * At this point notit->dscopes.stream_packet_context
+                * has the same value as the packet context field within
                 * notit->packet.
                 */
                BT_ASSERT(bt_packet_borrow_context_field(
@@ -2419,7 +2321,7 @@ void notify_end_of_packet(struct bt_msg_iter *notit,
 
        /* Update default clock from packet's end time */
        if (notit->snapshots.end_clock != UINT64_C(-1)) {
-               notit->default_clock_val = notit->snapshots.end_clock;
+               notit->default_clock_snapshot = notit->snapshots.end_clock;
        }
 
        BT_ASSERT(notit->msg_iter);
@@ -2610,7 +2512,7 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                        goto end;
                case STATE_EMIT_MSG_EVENT:
                        BT_ASSERT(notit->event_msg);
-                       set_event_default_clock_value(notit);
+                       set_event_default_clock_snapshot(notit);
                        *message = notit->event_msg;
                        notit->event_msg = NULL;
                        goto end;
@@ -2633,11 +2535,9 @@ end:
        return status;
 }
 
-BT_HIDDEN
-enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
-               struct bt_msg_iter *notit,
-               bt_field **packet_header_field,
-               bt_field **packet_context_field)
+static
+enum bt_msg_iter_status read_packet_header_context_fields(
+               struct bt_msg_iter *notit)
 {
        int ret;
        enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
@@ -2646,7 +2546,7 @@ enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
 
        if (notit->state == STATE_EMIT_MSG_NEW_PACKET) {
                /* We're already there */
-               goto set_fields;
+               goto end;
        }
 
        while (true) {
@@ -2672,7 +2572,7 @@ enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
                         * Packet header and context fields are
                         * potentially decoded (or they don't exist).
                         */
-                       goto set_fields;
+                       goto end;
                case STATE_INIT:
                case STATE_EMIT_MSG_NEW_STREAM:
                case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
@@ -2694,22 +2594,13 @@ enum bt_msg_iter_status bt_msg_iter_borrow_packet_header_context_fields(
                }
        }
 
-set_fields:
+end:
        ret = set_current_packet_content_sizes(notit);
        if (ret) {
                status = BT_MSG_ITER_STATUS_ERROR;
                goto end;
        }
 
-       if (packet_header_field) {
-               *packet_header_field = notit->dscopes.trace_packet_header;
-       }
-
-       if (packet_context_field) {
-               *packet_context_field = notit->dscopes.stream_packet_context;
-       }
-
-end:
        return status;
 }
 
@@ -2788,8 +2679,14 @@ enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
                struct bt_msg_iter *notit,
                struct bt_msg_iter_packet_properties *props)
 {
+       enum bt_msg_iter_status status;
+
        BT_ASSERT(notit);
        BT_ASSERT(props);
+       status = read_packet_header_context_fields(notit);
+       if (status != BT_MSG_ITER_STATUS_OK) {
+               goto end;
+       }
 
        props->exp_packet_total_size =
                (uint64_t) notit->cur_exp_packet_total_size;
@@ -2802,5 +2699,7 @@ enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
        props->snapshots.packets = notit->snapshots.packets;
        props->snapshots.beginning_clock = notit->snapshots.beginning_clock;
        props->snapshots.end_clock = notit->snapshots.end_clock;
-       return BT_MSG_ITER_STATUS_OK;
+
+end:
+       return status;
 }
This page took 0.051229 seconds and 4 git commands to generate.