+ BT_LOGV("Found stream class ID to use: notit-addr=%p, "
+ "stream-class-id=%" PRIu64 ", "
+ "trace-addr=%p, trace-name=\"%s\"",
+ notit, stream_id, notit->meta.trace,
+ bt_trace_get_name(notit->meta.trace));
+
+ new_stream_class = bt_trace_borrow_stream_class_by_id(
+ notit->meta.trace, stream_id);
+ if (!new_stream_class) {
+ BT_LOGW("No stream class with ID of stream class ID to use in trace: "
+ "notit-addr=%p, stream-class-id=%" PRIu64 ", "
+ "trace-addr=%p, trace-name=\"%s\"",
+ notit, stream_id, notit->meta.trace,
+ bt_trace_get_name(notit->meta.trace));
+ status = BT_NOTIF_ITER_STATUS_ERROR;
+ goto end;
+ }
+
+ if (notit->meta.stream_class) {
+ if (new_stream_class != notit->meta.stream_class) {
+ BT_LOGW("Two packets refer to two different stream classes within the same packet sequence: "
+ "notit-addr=%p, prev-stream-class-addr=%p, "
+ "prev-stream-class-name=\"%s\", "
+ "prev-stream-class-id=%" PRId64 ", "
+ "next-stream-class-addr=%p, "
+ "next-stream-class-name=\"%s\", "
+ "next-stream-class-id=%" PRId64 ", "
+ "trace-addr=%p, trace-name=\"%s\"",
+ notit, notit->meta.stream_class,
+ bt_stream_class_get_name(notit->meta.stream_class),
+ bt_stream_class_get_id(notit->meta.stream_class),
+ new_stream_class,
+ bt_stream_class_get_name(new_stream_class),
+ bt_stream_class_get_id(new_stream_class),
+ notit->meta.trace,
+ bt_trace_get_name(notit->meta.trace));
+ status = BT_NOTIF_ITER_STATUS_ERROR;
+ goto end;
+ }
+ } else {
+ notit->meta.stream_class = new_stream_class;
+ }
+
+ BT_LOGV("Set current stream class: "
+ "notit-addr=%p, stream-class-addr=%p, "
+ "stream-class-name=\"%s\", stream-class-id=%" PRId64,
+ notit, notit->meta.stream_class,
+ bt_stream_class_get_name(notit->meta.stream_class),
+ bt_stream_class_get_id(notit->meta.stream_class));
+
+ /*
+ * Retrieve (or lazily create) the current stream class field path
+ * cache.
+ */
+ notit->cur_sc_field_path_cache = get_stream_class_field_path_cache(
+ notit, notit->meta.stream_class);
+ if (!notit->cur_sc_field_path_cache) {
+ BT_LOGW("Cannot retrieve stream class field path from cache: "
+ "notit-addr=%p, stream-class-addr=%p, "
+ "stream-class-name=\"%s\", stream-class-id=%" PRId64,
+ notit, notit->meta.stream_class,
+ bt_stream_class_get_name(notit->meta.stream_class),
+ bt_stream_class_get_id(notit->meta.stream_class));
+ status = BT_NOTIF_ITER_STATUS_ERROR;
+ goto end;
+ }
+
+end:
+ return status;
+}
+
+static inline
+uint64_t get_cur_stream_instance_id(struct bt_notif_iter *notit)
+{
+ struct bt_field *stream_instance_id_field = NULL;
+ uint64_t stream_instance_id = -1ULL;
+ int ret;
+
+ if (!notit->dscopes.trace_packet_header) {
+ goto end;
+ }
+
+ stream_instance_id_field = bt_field_structure_borrow_field_by_name(
+ notit->dscopes.trace_packet_header, "stream_instance_id");
+ if (!stream_instance_id_field) {
+ goto end;
+ }
+
+ ret = bt_field_integer_unsigned_get_value(stream_instance_id_field,
+ &stream_instance_id);
+ if (ret) {
+ stream_instance_id = -1ULL;
+ goto end;
+ }
+
+end:
+ return stream_instance_id;
+}
+
+static inline
+enum bt_notif_iter_status set_current_stream(struct bt_notif_iter *notit)
+{
+ enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
+ struct bt_stream *stream = NULL;
+
+ BT_LOGV("Calling user function (get stream): notit-addr=%p, "
+ "stream-class-addr=%p, stream-class-name=\"%s\", "
+ "stream-class-id=%" PRId64,
+ notit, notit->meta.stream_class,
+ bt_stream_class_get_name(notit->meta.stream_class),
+ bt_stream_class_get_id(notit->meta.stream_class));
+ stream = bt_get(notit->medium.medops.borrow_stream(
+ notit->meta.stream_class, get_cur_stream_instance_id(notit),
+ notit->medium.data));
+ BT_LOGV("User function returned: stream-addr=%p", stream);
+ if (!stream) {
+ BT_LOGW_STR("User function failed to return a stream object for the given stream class.");
+ status = BT_NOTIF_ITER_STATUS_ERROR;
+ goto end;
+ }
+
+ if (notit->stream && stream != notit->stream) {
+ BT_LOGW("User function returned a different stream than the previous one for the same sequence of packets.");
+ status = BT_NOTIF_ITER_STATUS_ERROR;