+
+BT_HIDDEN
+struct bt_notification_iterator_next_return ctf_fs_stream_next(
+ struct ctf_fs_stream *stream)
+{
+ enum bt_ctf_notif_iter_status notif_iter_status;
+ struct bt_notification_iterator_next_return ret = {
+ .status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR,
+ .notification = NULL,
+ };
+
+ if (stream->end_reached) {
+ notif_iter_status = BT_CTF_NOTIF_ITER_STATUS_EOF;
+ goto translate_status;
+ }
+
+ notif_iter_status = bt_ctf_notif_iter_get_next_notification(stream->notif_iter,
+ &ret.notification);
+ if (notif_iter_status != BT_CTF_NOTIF_ITER_STATUS_OK &&
+ notif_iter_status != BT_CTF_NOTIF_ITER_STATUS_EOF) {
+ goto translate_status;
+ }
+
+ /* Should be handled in bt_ctf_notif_iter_get_next_notification. */
+ if (notif_iter_status == BT_CTF_NOTIF_ITER_STATUS_EOF) {
+ ret.notification = bt_notification_stream_end_create(
+ stream->stream);
+ if (!ret.notification) {
+ notif_iter_status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
+ goto translate_status;
+ }
+
+ notif_iter_status = BT_CTF_NOTIF_ITER_STATUS_OK;
+ stream->end_reached = true;
+ }
+
+translate_status:
+ switch (notif_iter_status) {
+ case BT_CTF_NOTIF_ITER_STATUS_EOF:
+ ret.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
+ break;
+ case BT_CTF_NOTIF_ITER_STATUS_OK:
+ ret.status = BT_NOTIFICATION_ITERATOR_STATUS_OK;
+ break;
+ case BT_CTF_NOTIF_ITER_STATUS_AGAIN:
+ /*
+ * Should not make it this far as this is
+ * medium-specific; there is nothing for the user to do
+ * and it should have been handled upstream.
+ */
+ assert(false);
+ case BT_CTF_NOTIF_ITER_STATUS_INVAL:
+ case BT_CTF_NOTIF_ITER_STATUS_ERROR:
+ default:
+ ret.status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR;
+ break;
+ }
+
+ return ret;
+}