- struct bt_private_notification_iterator *priv_iterator =
- bt_private_notification_iterator_from_notification_iterator(iterator);
- bt_component_class_notification_iterator_next_method next_method = NULL;
- struct bt_notification_iterator_next_return next_return = {
- .status = BT_NOTIFICATION_ITERATOR_STATUS_OK,
- .notification = NULL,
- };
- enum bt_notification_iterator_status status =
- BT_NOTIFICATION_ITERATOR_STATUS_OK;
- int ret;
-
- assert(iterator);
-
- if (iterator->queue->length > 0) {
- /* We already have enough */
- goto end;
- }
-
- if (iterator->is_ended) {
- status = BT_NOTIFICATION_ITERATOR_STATUS_END;
- goto end;
- }
-
- assert(iterator->upstream_component);
- assert(iterator->upstream_component->class);
-
- /* Pick the appropriate "next" method */
- switch (iterator->upstream_component->class->type) {
- case BT_COMPONENT_CLASS_TYPE_SOURCE:
- {
- struct bt_component_class_source *source_class =
- container_of(iterator->upstream_component->class,
- struct bt_component_class_source, parent);
-
- assert(source_class->methods.iterator.next);
- next_method = source_class->methods.iterator.next;
- break;
- }
- case BT_COMPONENT_CLASS_TYPE_FILTER:
- {
- struct bt_component_class_filter *filter_class =
- container_of(iterator->upstream_component->class,
- struct bt_component_class_filter, parent);
-
- assert(filter_class->methods.iterator.next);
- next_method = filter_class->methods.iterator.next;
- break;
- }
- default:
- assert(false);
- break;
- }
-
- /*
- * Call the user's "next" method to get the next notification
- * and status.
- */
- assert(next_method);
-
- while (iterator->queue->length == 0) {
- next_return = next_method(priv_iterator);
- if (next_return.status < 0) {
- status = next_return.status;
+ int status;
+
+ BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator");
+ BT_ASSERT_PRE_ITER_HAS_STATE_TO_SEEK(iterator);
+ BT_ASSERT_PRE(
+ bt_component_borrow_graph(iterator->upstream_component)->config_state !=
+ BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
+ "Graph is not configured: %!+g",
+ bt_component_borrow_graph(iterator->upstream_component));
+ BT_ASSERT_PRE(
+ bt_self_component_port_input_message_iterator_can_seek_ns_from_origin(
+ iterator, ns_from_origin),
+ "Message iterator cannot seek nanoseconds from origin: %!+i, "
+ "ns-from-origin=%" PRId64, iterator, ns_from_origin);
+ set_self_comp_port_input_msg_iterator_state(iterator,
+ BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING);
+
+ if (iterator->methods.seek_ns_from_origin) {
+ BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: "
+ "%![iter-]+i, ns=%" PRId64, iterator, ns_from_origin);
+ status = iterator->methods.seek_ns_from_origin(iterator,
+ ns_from_origin);
+ BT_LOGD("User method returned: status=%s",
+ bt_message_iterator_status_string(status));
+ BT_ASSERT_PRE(status == BT_MESSAGE_ITERATOR_STATUS_OK ||
+ status == BT_MESSAGE_ITERATOR_STATUS_ERROR ||
+ status == BT_MESSAGE_ITERATOR_STATUS_NOMEM ||
+ status == BT_MESSAGE_ITERATOR_STATUS_AGAIN,
+ "Unexpected status: %![iter-]+i, status=%s",
+ iterator,
+ bt_common_self_message_iterator_status_string(status));
+ } else {
+ /* Start automatic seeking: seek beginning first */
+ BT_ASSERT(iterator->methods.can_seek_beginning(iterator));
+ BT_ASSERT(iterator->methods.seek_beginning);
+ BT_LIB_LOGD("Calling user's \"seek beginning\" method: %!+i",
+ iterator);
+ status = iterator->methods.seek_beginning(iterator);
+ BT_LOGD("User method returned: status=%s",
+ bt_message_iterator_status_string(status));
+ BT_ASSERT_PRE(status == BT_MESSAGE_ITERATOR_STATUS_OK ||
+ status == BT_MESSAGE_ITERATOR_STATUS_ERROR ||
+ status == BT_MESSAGE_ITERATOR_STATUS_NOMEM ||
+ status == BT_MESSAGE_ITERATOR_STATUS_AGAIN,
+ "Unexpected status: %![iter-]+i, status=%s",
+ iterator,
+ bt_common_self_message_iterator_status_string(status));
+ switch (status) {
+ case BT_MESSAGE_ITERATOR_STATUS_OK:
+ break;
+ case BT_MESSAGE_ITERATOR_STATUS_ERROR:
+ case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
+ case BT_MESSAGE_ITERATOR_STATUS_AGAIN: