Fix: msg-iter.c: accept no packet total and content sizes
[babeltrace.git] / plugins / ctf / common / msg-iter / msg-iter.c
index 8e45e6edfcde77013118e34426552d26ae5e1837..0d41638e988cfa88a02a6eee3434932214567e78 100644 (file)
@@ -969,14 +969,8 @@ enum bt_msg_iter_status set_current_packet_content_sizes(
 
        if (notit->cur_exp_packet_total_size == -1) {
                if (notit->cur_exp_packet_content_size != -1) {
-                       BT_LOGW("Content size is set, but packet size is not: "
-                               "notit-addr=%p, packet-context-field-addr=%p, "
-                               "packet-size=%" PRId64 ", content-size=%" PRId64,
-                               notit, notit->dscopes.stream_packet_context,
-                               notit->cur_exp_packet_total_size,
-                               notit->cur_exp_packet_content_size);
-                       status = BT_MSG_ITER_STATUS_ERROR;
-                       goto end;
+                       notit->cur_exp_packet_total_size =
+                               notit->cur_exp_packet_content_size;
                }
        } else {
                if (notit->cur_exp_packet_content_size == -1) {
@@ -985,6 +979,11 @@ enum bt_msg_iter_status set_current_packet_content_sizes(
                }
        }
 
+       BT_ASSERT((notit->cur_exp_packet_total_size >= 0 &&
+               notit->cur_exp_packet_content_size >= 0) ||
+               (notit->cur_exp_packet_total_size < 0 &&
+               notit->cur_exp_packet_content_size < 0));
+
        if (notit->cur_exp_packet_content_size >
                        notit->cur_exp_packet_total_size) {
                BT_LOGW("Invalid packet or content size: "
@@ -1183,8 +1182,17 @@ enum bt_msg_iter_status set_current_event_message(
                notit->meta.ec->name->str,
                notit->packet);
        BT_ASSERT(notit->msg_iter);
-       msg = bt_message_event_create(notit->msg_iter,
-               notit->meta.ec->ir_ec, notit->packet);
+       BT_ASSERT(notit->meta.sc);
+
+       if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
+               msg = bt_message_event_create_with_default_clock_snapshot(
+                       notit->msg_iter, notit->meta.ec->ir_ec,
+                       notit->packet, notit->default_clock_snapshot);
+       } else {
+               msg = bt_message_event_create(notit->msg_iter,
+                       notit->meta.ec->ir_ec, notit->packet);
+       }
+
        if (!msg) {
                BT_LOGE("Cannot create event message: "
                        "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", "
@@ -2369,20 +2377,6 @@ end:
        return ret_fc;
 }
 
-static
-void set_event_default_clock_snapshot(struct bt_msg_iter *notit)
-{
-       bt_event *event = bt_message_event_borrow_event(notit->event_msg);
-       bt_stream_class *sc = notit->meta.sc->ir_sc;
-
-       BT_ASSERT(event);
-
-       if (bt_stream_class_borrow_default_clock_class(sc)) {
-               bt_event_set_default_clock_snapshot(event,
-                       notit->default_clock_snapshot);
-       }
-}
-
 static
 void create_msg_stream_beginning(struct bt_msg_iter *notit,
                bt_message **message)
@@ -2491,30 +2485,6 @@ void create_msg_packet_beginning(struct bt_msg_iter *notit,
        sc = notit->meta.sc->ir_sc;
        BT_ASSERT(sc);
 
-       if (bt_stream_class_packets_have_discarded_event_counter_snapshot(sc)) {
-               BT_ASSERT(notit->snapshots.discarded_events != UINT64_C(-1));
-               bt_packet_set_discarded_event_counter_snapshot(
-                       notit->packet, notit->snapshots.discarded_events);
-       }
-
-       if (bt_stream_class_packets_have_packet_counter_snapshot(sc)) {
-               BT_ASSERT(notit->snapshots.packets != UINT64_C(-1));
-               bt_packet_set_packet_counter_snapshot(
-                       notit->packet, notit->snapshots.packets);
-       }
-
-       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_snapshot(
-                       notit->packet, notit->snapshots.beginning_clock);
-       }
-
-       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_snapshot(
-                       notit->packet, notit->snapshots.end_clock);
-       }
-
        if (notit->packet_context_field) {
                ret = bt_packet_move_context_field(
                        notit->packet, notit->packet_context_field);
@@ -2535,8 +2505,26 @@ void create_msg_packet_beginning(struct bt_msg_iter *notit,
        }
 
        BT_ASSERT(notit->msg_iter);
-       msg = bt_message_packet_beginning_create(notit->msg_iter,
-               notit->packet);
+
+       if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
+               uint64_t value = 0;
+
+               if (notit->snapshots.beginning_clock == UINT64_C(-1)) {
+                       if (notit->prev_packet_snapshots.end_clock != UINT64_C(-1)) {
+                               value = notit->prev_packet_snapshots.end_clock;
+                       }
+               } else {
+                       value = notit->snapshots.beginning_clock;
+               }
+
+
+               msg = bt_message_packet_beginning_create_with_default_clock_snapshot(
+                       notit->msg_iter, notit->packet, value);
+       } else {
+               msg = bt_message_packet_beginning_create(notit->msg_iter,
+                       notit->packet);
+       }
+
        if (!msg) {
                BT_LOGE("Cannot create packet beginning message: "
                        "notit-addr=%p, packet-addr=%p",
@@ -2565,8 +2553,22 @@ void create_msg_packet_end(struct bt_msg_iter *notit, bt_message **message)
        }
 
        BT_ASSERT(notit->msg_iter);
-       msg = bt_message_packet_end_create(notit->msg_iter,
-               notit->packet);
+
+       if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
+               if (notit->snapshots.end_clock == UINT64_C(-1)) {
+                       notit->snapshots.end_clock =
+                               notit->default_clock_snapshot;
+               }
+
+               BT_ASSERT(notit->snapshots.end_clock != UINT64_C(-1));
+               msg = bt_message_packet_end_create_with_default_clock_snapshot(
+                       notit->msg_iter, notit->packet,
+                       notit->snapshots.end_clock);
+       } else {
+               msg = bt_message_packet_end_create(notit->msg_iter,
+                       notit->packet);
+       }
+
        if (!msg) {
                BT_LOGE("Cannot create packet end message: "
                        "notit-addr=%p, packet-addr=%p",
@@ -2786,7 +2788,6 @@ enum bt_msg_iter_status bt_msg_iter_get_next_message(
                switch (notit->state) {
                case STATE_EMIT_MSG_EVENT:
                        BT_ASSERT(notit->event_msg);
-                       set_event_default_clock_snapshot(notit);
                        *message = notit->event_msg;
                        notit->event_msg = NULL;
                        goto end;
@@ -2940,7 +2941,6 @@ end:
        ret = set_current_packet_content_sizes(notit);
        if (ret) {
                status = BT_MSG_ITER_STATUS_ERROR;
-               goto end;
        }
 
        return status;
@@ -3008,8 +3008,8 @@ enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
 
        props->exp_packet_total_size = notit->cur_exp_packet_total_size;
        props->exp_packet_content_size = notit->cur_exp_packet_content_size;
-       BT_ASSERT(props->stream_class_id >= 0);
        props->stream_class_id = (uint64_t) notit->cur_stream_class_id;
+       BT_ASSERT(props->stream_class_id >= 0);
        props->data_stream_id = notit->cur_data_stream_id;
        props->snapshots.discarded_events = notit->snapshots.discarded_events;
        props->snapshots.packets = notit->snapshots.packets;
This page took 0.029005 seconds and 4 git commands to generate.