Split CTF IR and CTF writer APIs and implementations
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.c
index 1f3587d75ae67c79a964145379bf5a8a61ca1085..642f9931cb2bf48e22562f4e4d1940a9974b26c7 100644 (file)
@@ -34,8 +34,7 @@
 #include <babeltrace/assert-internal.h>
 #include <string.h>
 #include <babeltrace/babeltrace.h>
-#include <babeltrace/ctf-ir/field-types-internal.h>
-#include <babeltrace/ctf-ir/field-path-internal.h>
+#include <babeltrace/common-internal.h>
 #include <glib.h>
 #include <stdlib.h>
 
@@ -78,6 +77,7 @@ enum state {
        STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN,
        STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
        STATE_AFTER_STREAM_PACKET_CONTEXT,
+       STATE_EMIT_NOTIF_NEW_STREAM,
        STATE_EMIT_NOTIF_NEW_PACKET,
        STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN,
        STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE,
@@ -90,6 +90,7 @@ enum state {
        STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE,
        STATE_EMIT_NOTIF_EVENT,
        STATE_EMIT_NOTIF_END_OF_PACKET,
+       STATE_DONE,
        STATE_SKIP_PACKET_PADDING,
 };
 
@@ -214,6 +215,9 @@ struct bt_notif_iter {
                void *data;
        } medium;
 
+       /* Stream beginning was emitted */
+       bool stream_begin_emitted;
+
        /* Current packet size (bits) (-1 if unknown) */
        int64_t cur_packet_size;
 
@@ -265,6 +269,8 @@ const char *state_string(enum state state)
                return "STATE_AFTER_STREAM_PACKET_CONTEXT";
        case STATE_EMIT_NOTIF_NEW_PACKET:
                return "STATE_EMIT_NOTIF_NEW_PACKET";
+       case STATE_EMIT_NOTIF_NEW_STREAM:
+               return "STATE_EMIT_NOTIF_NEW_STREAM";
        case STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN:
                return "STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN";
        case STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE:
@@ -287,6 +293,8 @@ const char *state_string(enum state state)
                return "STATE_EMIT_NOTIF_EVENT";
        case STATE_EMIT_NOTIF_END_OF_PACKET:
                return "STATE_EMIT_NOTIF_END_OF_PACKET";
+       case STATE_DONE:
+               return "STATE_DONE";
        case STATE_SKIP_PACKET_PADDING:
                return "STATE_SKIP_PACKET_PADDING";
        default:
@@ -682,7 +690,7 @@ enum bt_notif_iter_status read_packet_header_begin_state(
        }
 
        /* Packet header type is common to the whole trace. */
-       packet_header_type = bt_trace_get_packet_header_type(
+       packet_header_type = bt_trace_get_packet_header_field_type(
                        notit->meta.trace);
        if (!packet_header_type) {
                notit->state = STATE_AFTER_TRACE_PACKET_HEADER;
@@ -752,7 +760,7 @@ create_stream_class_field_path_cache_entry(
                goto end;
        }
 
-       event_header = bt_stream_class_get_event_header_type(stream_class);
+       event_header = bt_stream_class_get_event_header_field_type(stream_class);
        if (event_header && bt_field_type_is_structure(event_header)) {
                int i, count;
 
@@ -791,7 +799,7 @@ create_stream_class_field_path_cache_entry(
                }
        }
 
-       packet_context = bt_stream_class_get_packet_context_type(
+       packet_context = bt_stream_class_get_packet_context_field_type(
                        stream_class);
        if (packet_context && bt_field_type_is_structure(packet_context)) {
                int i, count;
@@ -901,7 +909,7 @@ enum bt_notif_iter_status set_current_stream_class(
        notit->cur_sc_field_path_cache = NULL;
 
        /* Is there any "stream_id" field in the packet header? */
-       packet_header_type = bt_trace_get_packet_header_type(
+       packet_header_type = bt_trace_get_packet_header_field_type(
                notit->meta.trace);
        if (!packet_header_type) {
                /*
@@ -928,7 +936,7 @@ enum bt_notif_iter_status set_current_stream_class(
                stream_id_field = bt_field_structure_get_field_by_name(
                                notit->dscopes.trace_packet_header, "stream_id");
                BT_ASSERT(stream_id_field);
-               ret = bt_field_unsigned_integer_get_value(
+               ret = bt_field_integer_unsigned_get_value(
                                stream_id_field, &stream_id);
                BT_ASSERT(!ret);
                BT_PUT(stream_id_field);
@@ -1035,7 +1043,7 @@ enum bt_notif_iter_status read_packet_context_begin_state(
        struct bt_field_type *packet_context_type;
 
        BT_ASSERT(notit->meta.stream_class);
-       packet_context_type = bt_stream_class_get_packet_context_type(
+       packet_context_type = bt_stream_class_get_packet_context_field_type(
                notit->meta.stream_class);
        if (!packet_context_type) {
                BT_LOGV("No packet packet context field type in stream class: continuing: "
@@ -1102,7 +1110,7 @@ enum bt_notif_iter_status set_current_packet_content_sizes(
        content_size_field = bt_field_structure_get_field_by_name(
                notit->dscopes.stream_packet_context, "content_size");
        if (packet_size_field) {
-               int ret = bt_field_unsigned_integer_get_value(
+               int ret = bt_field_integer_unsigned_get_value(
                        packet_size_field, &packet_size);
 
                BT_ASSERT(ret == 0);
@@ -1124,7 +1132,7 @@ enum bt_notif_iter_status set_current_packet_content_sizes(
        }
 
        if (content_size_field) {
-               int ret = bt_field_unsigned_integer_get_value(
+               int ret = bt_field_integer_unsigned_get_value(
                        content_size_field, &content_size);
 
                BT_ASSERT(ret == 0);
@@ -1170,7 +1178,11 @@ enum bt_notif_iter_status after_packet_context_state(
 
        status = set_current_packet_content_sizes(notit);
        if (status == BT_NOTIF_ITER_STATUS_OK) {
-               notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
+               if (notit->stream_begin_emitted) {
+                       notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
+               } else {
+                       notit->state = STATE_EMIT_NOTIF_NEW_STREAM;
+               }
        }
 
        return status;
@@ -1205,7 +1217,7 @@ enum bt_notif_iter_status read_event_header_begin_state(
                }
        }
 
-       event_header_type = bt_stream_class_get_event_header_type(
+       event_header_type = bt_stream_class_get_event_header_field_type(
                notit->meta.stream_class);
        if (!event_header_type) {
                notit->state = STATE_AFTER_STREAM_EVENT_HEADER;
@@ -1265,7 +1277,7 @@ enum bt_notif_iter_status set_current_event_class(struct bt_notif_iter *notit)
        uint64_t event_id = -1ULL;
        int ret;
 
-       event_header_type = bt_stream_class_get_event_header_type(
+       event_header_type = bt_stream_class_get_event_header_field_type(
                notit->meta.stream_class);
        if (!event_header_type) {
                /*
@@ -1314,7 +1326,7 @@ enum bt_notif_iter_status set_current_event_class(struct bt_notif_iter *notit)
                }
 
                if (bt_field_is_integer(v_struct_id_field)) {
-                       ret = bt_field_unsigned_integer_get_value(
+                       ret = bt_field_integer_unsigned_get_value(
                                v_struct_id_field, &event_id);
                        if (ret) {
                                BT_LOGV("Cannot get value of unsigned integer field (`id`): continuing: "
@@ -1343,7 +1355,7 @@ end_v_field_type:
                }
 
                if (bt_field_is_integer(id_field)) {
-                       ret_get_value = bt_field_unsigned_integer_get_value(
+                       ret_get_value = bt_field_integer_unsigned_get_value(
                                id_field, &event_id);
                } else if (bt_field_is_enumeration(id_field)) {
                        struct bt_field *container;
@@ -1351,7 +1363,7 @@ end_v_field_type:
                        container = bt_field_enumeration_get_container(
                                id_field);
                        BT_ASSERT(container);
-                       ret_get_value = bt_field_unsigned_integer_get_value(
+                       ret_get_value = bt_field_integer_unsigned_get_value(
                                container, &event_id);
                        BT_PUT(container);
                }
@@ -1433,8 +1445,9 @@ enum bt_notif_iter_status read_stream_event_context_begin_state(
        enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
        struct bt_field_type *stream_event_context_type;
 
-       stream_event_context_type = bt_stream_class_get_event_context_type(
-               notit->meta.stream_class);
+       stream_event_context_type =
+               bt_stream_class_get_event_context_field_type(
+                       notit->meta.stream_class);
        if (!stream_event_context_type) {
                notit->state = STATE_DSCOPE_EVENT_CONTEXT_BEGIN;
                goto end;
@@ -1484,7 +1497,7 @@ enum bt_notif_iter_status read_event_context_begin_state(
        enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
        struct bt_field_type *event_context_type;
 
-       event_context_type = bt_event_class_get_context_type(
+       event_context_type = bt_event_class_get_context_field_type(
                notit->meta.event_class);
        if (!event_context_type) {
                notit->state = STATE_DSCOPE_EVENT_PAYLOAD_BEGIN;
@@ -1535,7 +1548,7 @@ enum bt_notif_iter_status read_event_payload_begin_state(
        enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
        struct bt_field_type *event_payload_type;
 
-       event_payload_type = bt_event_class_get_payload_type(
+       event_payload_type = bt_event_class_get_payload_field_type(
                notit->meta.event_class);
        if (!event_payload_type) {
                notit->state = STATE_EMIT_NOTIF_EVENT;
@@ -1647,6 +1660,9 @@ enum bt_notif_iter_status handle_state(struct bt_notif_iter *notit)
        case STATE_AFTER_STREAM_PACKET_CONTEXT:
                status = after_packet_context_state(notit);
                break;
+       case STATE_EMIT_NOTIF_NEW_STREAM:
+               notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
+               break;
        case STATE_EMIT_NOTIF_NEW_PACKET:
                notit->state = STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN;
                break;
@@ -1702,7 +1718,7 @@ enum bt_notif_iter_status handle_state(struct bt_notif_iter *notit)
 /**
  * Resets the internal state of a CTF notification iterator.
  */
-static
+BT_HIDDEN
 void bt_notif_iter_reset(struct bt_notif_iter *notit)
 {
        BT_ASSERT(notit);
@@ -1722,6 +1738,7 @@ void bt_notif_iter_reset(struct bt_notif_iter *notit)
        notit->cur_content_size = -1;
        notit->cur_packet_size = -1;
        notit->cur_packet_offset = -1;
+       notit->stream_begin_emitted = false;
 }
 
 static
@@ -1795,9 +1812,14 @@ struct bt_field *get_next_field(struct bt_notif_iter *notit)
 
        switch (bt_field_type_get_type_id(base_type)) {
        case BT_FIELD_TYPE_ID_STRUCT:
+       {
                next_field = bt_field_structure_get_field_by_index(
                        base_field, index);
+               const char *name;
+               bt_field_type_structure_get_field_by_index(base_type,
+                       &name, NULL, index);
                break;
+       }
        case BT_FIELD_TYPE_ID_ARRAY:
                next_field = bt_field_array_get_field(base_field, index);
                break;
@@ -1811,7 +1833,7 @@ struct bt_field *get_next_field(struct bt_notif_iter *notit)
                BT_LOGF("Unknown base field type ID: "
                        "notit-addr=%p, ft-addr=%p, ft-id=%s",
                        notit, base_type,
-                       bt_field_type_id_string(
+                       bt_common_field_type_id_string(
                                bt_field_type_get_type_id(base_type)));
                abort();
        }
@@ -1837,7 +1859,7 @@ void update_clock_state(uint64_t *state,
        requested_new_value_size =
                        bt_field_type_integer_get_size(value_type);
        BT_ASSERT(requested_new_value_size > 0);
-       ret = bt_field_unsigned_integer_get_value(value_field,
+       ret = bt_field_integer_unsigned_get_value(value_field,
                        &requested_new_value);
        BT_ASSERT(!ret);
 
@@ -1934,7 +1956,7 @@ enum bt_btr_status btr_unsigned_int_common(uint64_t value,
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s, value=%" PRIu64,
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)),
                value);
 
@@ -1962,13 +1984,13 @@ enum bt_btr_status btr_unsigned_int_common(uint64_t value,
                BT_LOGF("Unexpected field type ID: "
                        "notit-addr=%p, ft-addr=%p, ft-id=%s",
                        notit, type,
-                       bt_field_type_id_string(
+                       bt_common_field_type_id_string(
                                bt_field_type_get_type_id(type)));
                abort();
        }
 
        BT_ASSERT(int_field);
-       ret = bt_field_unsigned_integer_set_value(int_field, value);
+       ret = bt_field_integer_unsigned_set_value(int_field, value);
        BT_ASSERT(ret == 0);
        stack_top(notit->stack)->index++;
        *out_int_field = int_field;
@@ -1991,7 +2013,7 @@ enum bt_btr_status btr_timestamp_end_cb(void *value,
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)));
        status = btr_unsigned_int_common(*((uint64_t *) value), type, data,
                        &field);
@@ -2014,7 +2036,7 @@ enum bt_btr_status btr_unsigned_int_cb(uint64_t value,
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s, value=%" PRIu64,
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)),
                value);
        override = g_hash_table_lookup(notit->field_overrides, type);
@@ -2050,7 +2072,7 @@ enum bt_btr_status btr_signed_int_cb(int64_t value,
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s, value=%" PRId64,
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)),
                value);
 
@@ -2078,13 +2100,13 @@ enum bt_btr_status btr_signed_int_cb(int64_t value,
                BT_LOGF("Unexpected field type ID: "
                        "notit-addr=%p, ft-addr=%p, ft-id=%s",
                        notit, type,
-                       bt_field_type_id_string(
+                       bt_common_field_type_id_string(
                                bt_field_type_get_type_id(type)));
                abort();
        }
 
        BT_ASSERT(int_field);
-       ret = bt_field_signed_integer_set_value(int_field, value);
+       ret = bt_field_integer_signed_set_value(int_field, value);
        BT_ASSERT(!ret);
        stack_top(notit->stack)->index++;
        status = update_clock(notit, int_field);
@@ -2109,7 +2131,7 @@ enum bt_btr_status btr_floating_point_cb(double value,
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s, value=%f",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)),
                value);
 
@@ -2143,7 +2165,7 @@ enum bt_btr_status btr_string_begin_cb(
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)));
 
        /* Create next field */
@@ -2200,7 +2222,7 @@ enum bt_btr_status btr_string_cb(const char *value,
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s, string-length=%zu",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)),
                len);
 
@@ -2232,7 +2254,7 @@ enum bt_btr_status btr_string_end_cb(
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)));
 
        /* Pop string field */
@@ -2255,7 +2277,7 @@ enum bt_btr_status btr_compound_begin_cb(
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)));
 
        /* Create field */
@@ -2276,7 +2298,7 @@ enum bt_btr_status btr_compound_begin_cb(
                        BT_LOGE("Cannot create compound field: "
                                "notit-addr=%p, ft-addr=%p, ft-id=%s",
                                notit, type,
-                               bt_field_type_id_string(
+                               bt_common_field_type_id_string(
                                        bt_field_type_get_type_id(type)));
                        status = BT_BTR_STATUS_ERROR;
                        goto end;
@@ -2297,7 +2319,7 @@ enum bt_btr_status btr_compound_begin_cb(
                BT_LOGE("Cannot push compound field onto the stack: "
                        "notit-addr=%p, ft-addr=%p, ft-id=%s, ret=%d",
                        notit, type,
-                       bt_field_type_id_string(
+                       bt_common_field_type_id_string(
                                bt_field_type_get_type_id(type)),
                        ret);
                status = BT_BTR_STATUS_ERROR;
@@ -2319,7 +2341,7 @@ enum bt_btr_status btr_compound_end_cb(
                "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
                "ft-id=%s",
                notit, notit->btr, type,
-               bt_field_type_id_string(
+               bt_common_field_type_id_string(
                        bt_field_type_get_type_id(type)));
        BT_ASSERT(!stack_empty(notit->stack));
 
@@ -2374,7 +2396,7 @@ struct bt_field *resolve_field(struct bt_notif_iter *notit,
        default:
                BT_LOGF("Cannot resolve field path: unknown scope: "
                        "notit-addr=%p, root-scope=%s",
-                       notit, bt_scope_string(
+                       notit, bt_common_scope_string(
                                bt_field_path_get_root_scope(path)));
                abort();
        }
@@ -2382,7 +2404,7 @@ struct bt_field *resolve_field(struct bt_notif_iter *notit,
        if (!field) {
                BT_LOGW("Cannot resolve field path: root field not found: "
                        "notit-addr=%p, root-scope=%s",
-                       notit, bt_scope_string(
+                       notit, bt_common_scope_string(
                                bt_field_path_get_root_scope(path)));
                goto end;
        }
@@ -2412,7 +2434,7 @@ struct bt_field *resolve_field(struct bt_notif_iter *notit,
                        BT_LOGW("Cannot find next field: "
                                "notit-addr=%p, ft-addr=%p, ft-id=%s, index=%d",
                                notit, field_type,
-                               bt_field_type_id_string(
+                               bt_common_field_type_id_string(
                                        bt_field_type_get_type_id(field_type)),
                                index);
                        goto end;
@@ -2447,7 +2469,7 @@ int64_t btr_get_sequence_length_cb(struct bt_field_type *type, void *data)
                goto end;
        }
 
-       iret = bt_field_unsigned_integer_get_value(length_field, &length);
+       iret = bt_field_integer_unsigned_get_value(length_field, &length);
        if (iret) {
                BT_LOGE("Cannot get value of sequence length field: "
                        "notit-addr=%p, field-addr=%p",
@@ -2638,7 +2660,7 @@ struct bt_event *create_event(struct bt_notif_iter *notit)
                goto error;
        }
 
-       ret = bt_event_set_event_context(event,
+       ret = bt_event_set_context(event,
                notit->dscopes.event_context);
        if (ret) {
                BT_LOGE("Cannot set event's stream event context field: "
@@ -2652,7 +2674,7 @@ struct bt_event *create_event(struct bt_notif_iter *notit)
                goto error;
        }
 
-       ret = bt_event_set_event_payload(event,
+       ret = bt_event_set_payload(event,
                notit->dscopes.event_payload);
        if (ret) {
                BT_LOGE("Cannot set event's payload field: "
@@ -2719,7 +2741,7 @@ uint64_t get_cur_stream_instance_id(struct bt_notif_iter *notit)
                goto end;
        }
 
-       ret = bt_field_unsigned_integer_get_value(stream_instance_id_field,
+       ret = bt_field_integer_unsigned_get_value(stream_instance_id_field,
                &stream_instance_id);
        if (ret) {
                stream_instance_id = -1ULL;
@@ -2774,13 +2796,6 @@ void create_packet(struct bt_notif_iter *notit)
 
        BT_LOGV("Creating packet for packet notification: "
                "notit-addr=%p", notit);
-
-       /* Ask the user for the stream */
-       ret = set_stream(notit);
-       if (ret) {
-               goto error;
-       }
-
        BT_LOGV("Creating packet from stream: "
                "notit-addr=%p, stream-addr=%p, "
                "stream-class-addr=%p, "
@@ -2791,6 +2806,7 @@ void create_packet(struct bt_notif_iter *notit)
                bt_stream_class_get_id(notit->meta.stream_class));
 
        /* Create packet */
+       BT_ASSERT(notit->stream);
        packet = bt_packet_create(notit->stream);
        if (!packet) {
                BT_LOGE("Cannot create packet from stream: "
@@ -2852,6 +2868,54 @@ end:
        BT_MOVE(notit->packet, packet);
 }
 
+static
+void notify_new_stream(struct bt_notif_iter *notit,
+               struct bt_notification **notification)
+{
+       struct bt_notification *ret = NULL;
+       int iret;
+
+       /* Ask the user for the stream */
+       iret = set_stream(notit);
+       if (iret) {
+               goto end;
+       }
+
+       BT_ASSERT(notit->stream);
+       ret = bt_notification_stream_begin_create(notit->stream);
+       if (!ret) {
+               BT_LOGE("Cannot create stream beginning notification: "
+                       "notit-addr=%p, stream-addr=%p",
+                       notit, notit->stream);
+               return;
+       }
+
+end:
+       *notification = ret;
+}
+
+static
+void notify_end_of_stream(struct bt_notif_iter *notit,
+               struct bt_notification **notification)
+{
+       struct bt_notification *ret;
+
+       if (!notit->stream) {
+               BT_LOGE("Cannot create stream for stream notification: "
+                       "notit-addr=%p", notit);
+               return;
+       }
+
+       ret = bt_notification_stream_end_create(notit->stream);
+       if (!ret) {
+               BT_LOGE("Cannot create stream beginning notification: "
+                       "notit-addr=%p, stream-addr=%p",
+                       notit, notit->stream);
+               return;
+       }
+       *notification = ret;
+}
+
 static
 void notify_new_packet(struct bt_notif_iter *notit,
                struct bt_notification **notification)
@@ -2943,7 +3007,7 @@ void init_trace_field_path_cache(struct bt_trace *trace,
        int i, count;
        struct bt_field_type *packet_header = NULL;
 
-       packet_header = bt_trace_get_packet_header_type(trace);
+       packet_header = bt_trace_get_packet_header_field_type(trace);
        if (!packet_header) {
                goto end;
        }
@@ -3118,6 +3182,11 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification(
        BT_ASSERT(notit);
        BT_ASSERT(notification);
 
+       if (notit->state == STATE_DONE) {
+               status = BT_NOTIF_ITER_STATUS_EOF;
+               goto end;
+       }
+
        BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p",
                notit, cc_prio_map);
 
@@ -3129,7 +3198,25 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification(
                }
                if (status != BT_NOTIF_ITER_STATUS_OK) {
                        if (status == BT_NOTIF_ITER_STATUS_EOF) {
+                               enum state next_state = notit->state;
+
                                BT_LOGV_STR("Medium returned BT_NOTIF_ITER_STATUS_EOF.");
+
+                               if (notit->packet) {
+                                       notify_end_of_packet(notit, notification);
+                               } else {
+                                       notify_end_of_stream(notit, notification);
+                                       next_state = STATE_DONE;
+                               }
+
+                               if (!*notification) {
+                                       status = BT_NOTIF_ITER_STATUS_ERROR;
+                                       goto end;
+                               }
+
+                               status = BT_NOTIF_ITER_STATUS_OK;
+                               notit->state = next_state;
+                               goto end;
                        } else {
                                BT_LOGW("Cannot handle state: "
                                        "notit-addr=%p, state=%s",
@@ -3139,6 +3226,14 @@ enum bt_notif_iter_status bt_notif_iter_get_next_notification(
                }
 
                switch (notit->state) {
+               case STATE_EMIT_NOTIF_NEW_STREAM:
+                       /* notify_new_stream() logs errors */
+                       notify_new_stream(notit, notification);
+                       if (!*notification) {
+                               status = BT_NOTIF_ITER_STATUS_ERROR;
+                       }
+                       notit->stream_begin_emitted = true;
+                       goto end;
                case STATE_EMIT_NOTIF_NEW_PACKET:
                        /* notify_new_packet() logs errors */
                        notify_new_packet(notit, notification);
@@ -3230,6 +3325,7 @@ enum bt_notif_iter_status bt_notif_iter_get_packet_header_context_fields(
                         */
                        goto set_fields;
                case STATE_INIT:
+               case STATE_EMIT_NOTIF_NEW_STREAM:
                case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
                case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
                case STATE_AFTER_TRACE_PACKET_HEADER:
This page took 0.032784 seconds and 4 git commands to generate.