+#ifdef BT_DEV_MODE
+static
+void assert_post_dev_expected_packet(struct bt_message_iterator *iterator,
+ const struct bt_message *msg)
+{
+ const bt_stream *stream = get_stream_from_msg(msg);
+ struct per_stream_state *state;
+ const bt_packet *actual_packet = NULL;
+ const bt_packet *expected_packet = NULL;
+
+ if (!stream) {
+ goto end;
+ }
+
+ state = get_per_stream_state(iterator, stream);
+
+ switch (msg->type) {
+ case BT_MESSAGE_TYPE_EVENT:
+ {
+ const struct bt_message_event *msg_event =
+ (const struct bt_message_event *) msg;
+
+ actual_packet = msg_event->event->packet;
+ expected_packet = state->cur_packet;
+ break;
+ }
+ case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+ {
+ const struct bt_message_packet *msg_packet =
+ (const struct bt_message_packet *) msg;
+
+ BT_ASSERT(!state->cur_packet);
+ state->cur_packet = msg_packet->packet;
+ break;
+ }
+ case BT_MESSAGE_TYPE_PACKET_END:
+ {
+ const struct bt_message_packet *msg_packet =
+ (const struct bt_message_packet *) msg;
+
+ actual_packet = msg_packet->packet;
+ expected_packet = state->cur_packet;
+ BT_ASSERT(state->cur_packet);
+ state->cur_packet = NULL;
+ break;
+ }
+ default:
+ break;
+ }
+
+ BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+ "message-packet-is-expected",
+ actual_packet == expected_packet,
+ "Message's packet is not expected: %![stream-]s, %![iterator-]i, "
+ "%![message-]n, %![received-packet-]a, %![expected-packet-]a",
+ stream, iterator, msg, actual_packet, expected_packet);
+
+end:
+ return;
+}
+
+static
+void assert_post_dev_next(
+ struct bt_message_iterator *iterator,
+ bt_message_iterator_class_next_method_status status,
+ bt_message_array_const msgs, uint64_t msg_count)
+{
+ if (status == BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK) {
+ uint64_t i;
+
+ for (i = 0; i < msg_count; i++) {
+ assert_post_dev_expected_packet(iterator, msgs[i]);
+ }
+ }
+}
+#endif
+
+/*
+ * Call the `next` method of the iterator. Do some validation on the returned
+ * messages.
+ */
+
+static
+enum bt_message_iterator_class_next_method_status
+call_iterator_next_method(
+ struct bt_message_iterator *iterator,
+ bt_message_array_const msgs, uint64_t capacity, uint64_t *user_count)
+{
+ enum bt_message_iterator_class_next_method_status status;
+
+ BT_ASSERT_DBG(iterator->methods.next);
+ BT_LOGD_STR("Calling user's \"next\" method.");
+ status = iterator->methods.next(iterator, msgs, capacity, user_count);
+ BT_LOGD("User method returned: status=%s, msg-count=%" PRIu64,
+ bt_common_func_status_string(status), *user_count);
+
+ if (status == BT_FUNC_STATUS_OK) {
+ BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+ "message-clock-classes-are-compatible",
+ clock_classes_are_compatible(iterator, msgs,
+ *user_count),
+ "Clocks are not compatible");
+ BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
+ "message-clock-snapshots-are-monotonic",
+ clock_snapshots_are_monotonic(iterator, msgs,
+ *user_count),
+ "Clock snapshots are not monotonic");
+ }
+
+#ifdef BT_DEV_MODE
+ assert_post_dev_next(iterator, status, msgs, *user_count);
+#endif
+
+ BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(NEXT_METHOD_NAME,
+ status);
+
+ return status;
+}
+
+BT_EXPORT
+enum bt_message_iterator_next_status
+bt_message_iterator_next(
+ struct bt_message_iterator *iterator,
+ bt_message_array_const *msgs, uint64_t *user_count)
+{
+ enum bt_message_iterator_next_status status = BT_FUNC_STATUS_OK;
+
+ BT_ASSERT_PRE_DEV_NO_ERROR();
+ BT_ASSERT_PRE_DEV_MSG_ITER_NON_NULL(iterator);
+ BT_ASSERT_PRE_DEV_NON_NULL("message-array-output", msgs,
+ "Message array (output)");
+ BT_ASSERT_PRE_DEV_NON_NULL("user-count-output", user_count,
+ "Message count (output)");
+ BT_ASSERT_PRE_DEV("message-iterator-is-active",
+ iterator->state == BT_MESSAGE_ITERATOR_STATE_ACTIVE,