+
+BT_HIDDEN
+enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_packet_header_context_fields(
+ struct bt_ctf_notif_iter *notit,
+ struct bt_ctf_field **packet_header_field,
+ struct bt_ctf_field **packet_context_field)
+{
+ enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
+
+ assert(notit);
+
+ if (notit->state == STATE_EMIT_NOTIF_NEW_PACKET) {
+ /* We're already there */
+ goto set_fields;
+ }
+
+ while (true) {
+ status = handle_state(notit);
+ if (status == BT_CTF_NOTIF_ITER_STATUS_AGAIN) {
+ BT_LOGV_STR("Medium returned BT_CTF_NOTIF_ITER_STATUS_AGAIN.");
+ goto end;
+ }
+ if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
+ if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) {
+ BT_LOGV_STR("Medium returned BT_CTF_NOTIF_ITER_STATUS_EOF.");
+ } else {
+ BT_LOGW("Cannot handle state: "
+ "notit-addr=%p, state=%s",
+ notit, state_string(notit->state));
+ }
+ goto end;
+ }
+
+ switch (notit->state) {
+ case STATE_EMIT_NOTIF_NEW_PACKET:
+ /*
+ * Packet header and context fields are
+ * potentially decoded (or they don't exist).
+ */
+ goto set_fields;
+ case STATE_INIT:
+ case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
+ case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
+ case STATE_AFTER_TRACE_PACKET_HEADER:
+ case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
+ case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
+ case STATE_AFTER_STREAM_PACKET_CONTEXT:
+ /* Non-emitting state: continue */
+ break;
+ default:
+ /*
+ * We should never get past the
+ * STATE_EMIT_NOTIF_NEW_PACKET state.
+ */
+ BT_LOGF("Unexpected state: notit-addr=%p, state=%s",
+ notit, state_string(notit->state));
+ abort();
+ }
+ }
+
+set_fields:
+ if (packet_header_field) {
+ *packet_header_field = bt_get(notit->dscopes.trace_packet_header);
+ }
+
+ if (packet_context_field) {
+ *packet_context_field = bt_get(notit->dscopes.stream_packet_context);
+ }
+
+end:
+ return status;
+}
+
+BT_HIDDEN
+void bt_ctf_notif_iter_set_medops_data(struct bt_ctf_notif_iter *notit,
+ void *medops_data)
+{
+ assert(notit);
+ notit->medium.data = medops_data;
+}