Replace all assert(false) and assert(0) with abort()
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.c
index bc20f8814b1de423158fa04961a9134d42f4a599..b2aa08e44333eaf9dc2be5d77d889ed38d310a8c 100644 (file)
@@ -44,6 +44,7 @@
 #include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/ref.h>
 #include <glib.h>
+#include <stdlib.h>
 
 #define PRINT_ERR_STREAM       notit->err_stream
 #define PRINT_PREFIX           "ctf-notif-iter"
@@ -1397,8 +1398,7 @@ struct bt_ctf_field *get_next_field(struct bt_ctf_notif_iter *notit)
                next_field = bt_ctf_field_variant_get_current_field(base_field);
                break;
        default:
-               assert(false);
-               break;
+               abort();
        }
 
 end:
@@ -1541,9 +1541,7 @@ enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value,
                type = bt_ctf_field_get_type(int_field);
                break;
        default:
-               assert(0);
-               type = NULL;
-               break;
+               abort();
        }
 
        if (!int_field) {
@@ -1636,9 +1634,7 @@ enum bt_ctf_btr_status btr_signed_int_cb(int64_t value,
                type = bt_ctf_field_get_type(int_field);
                break;
        default:
-               assert(0);
-               type = NULL;
-               break;
+               abort();
        }
 
        if (!int_field) {
@@ -2447,3 +2443,72 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification(
 end:
        return status;
 }
+
+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) {
+                       PDBG("Medium operation reported \"try again later\"");
+                       goto end;
+               }
+               if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
+                       if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) {
+                               PDBG("Medium operation reported end of stream\n");
+                       } else {
+                               PERR("Failed to handle state:\n");
+                               PERR("\tState: %d\n", 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.
+                        */
+                       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;
+}
This page took 0.024088 seconds and 4 git commands to generate.