+static
+enum bt_msg_iter_status check_emit_msg_stream_beginning_state(
+ struct bt_msg_iter *notit)
+{
+ enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
+
+ if (notit->set_stream) {
+ status = set_current_stream(notit);
+ if (status != BT_MSG_ITER_STATUS_OK) {
+ goto end;
+ }
+ }
+
+ if (notit->emit_stream_begin_msg) {
+ notit->state = STATE_EMIT_MSG_STREAM_BEGINNING;
+ } else {
+ /* Stream's first packet */
+ notit->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 *notit)
+{
+ notit->state = STATE_EMIT_MSG_DISCARDED_EVENTS;
+
+ if (notit->prev_packet_snapshots.discarded_events == UINT64_C(-1)) {
+ if (notit->snapshots.discarded_events == 0 ||
+ notit->snapshots.discarded_events == UINT64_C(-1)) {
+ /*
+ * Stream's first packet with no discarded
+ * events or no information about discarded
+ * events: do not emit.
+ */
+ notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
+ }
+ } else {
+ /*
+ * If the previous packet has a value for this counter,
+ * then this counter is defined for the whole stream.
+ */
+ BT_ASSERT(notit->snapshots.discarded_events != UINT64_C(-1));
+
+ if (notit->snapshots.discarded_events -
+ notit->prev_packet_snapshots.discarded_events == 0) {
+ /*
+ * No discarded events since previous packet: do
+ * not emit.
+ */
+ notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
+ }
+ }
+
+ return BT_MSG_ITER_STATUS_OK;
+}
+
+static
+enum bt_msg_iter_status check_emit_msg_discarded_packets(
+ struct bt_msg_iter *notit)
+{
+ notit->state = STATE_EMIT_MSG_DISCARDED_PACKETS;
+
+ if (notit->prev_packet_snapshots.packets == UINT64_C(-1)) {
+ /*
+ * Stream's first packet or no information about
+ * discarded packets: do not emit. In other words, if
+ * this is the first packet and its sequence number is
+ * not 0, do not consider that packets were previously
+ * lost: we might be reading a partial stream (LTTng
+ * snapshot for example).
+ */
+ notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
+ } else {
+ /*
+ * If the previous packet has a value for this counter,
+ * then this counter is defined for the whole stream.
+ */
+ BT_ASSERT(notit->snapshots.packets != UINT64_C(-1));
+
+ if (notit->snapshots.packets -
+ notit->prev_packet_snapshots.packets <= 1) {
+ /*
+ * No discarded packets since previous packet:
+ * do not emit.
+ */
+ notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
+ }
+ }
+
+ return BT_MSG_ITER_STATUS_OK;
+}
+
+static
+enum bt_msg_iter_status check_emit_msg_stream_activity_end(
+ struct bt_msg_iter *notit)
+{
+ if (notit->emit_stream_end_msg) {
+ notit->state = STATE_EMIT_MSG_STREAM_ACTIVITY_END;
+ } else {
+ notit->state = STATE_DONE;
+ }
+
+ return BT_MSG_ITER_STATUS_OK;
+}
+