ctf plugin: add bt_ctf_notif_iter_get_packet_header_context_fields()
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.c
index be79603e672525b5f251c203f182040aa5840675..acb349380c3fa626328b9805300bb38d2f97a4d0 100644 (file)
@@ -361,7 +361,7 @@ static inline
 enum bt_ctf_notif_iter_status notif_iter_status_from_m_status(
                enum bt_ctf_notif_iter_medium_status m_status)
 {
-       return m_status;
+       return (int) m_status;
 }
 
 static inline
@@ -382,38 +382,12 @@ size_t packet_at(struct bt_ctf_notif_iter *notit)
        return notit->buf.packet_offset + notit->buf.at;
 }
 
-static inline
-size_t remaining_content_bits(struct bt_ctf_notif_iter *notit)
-{
-       if (notit->cur_content_size == -1) {
-               return -1;
-       }
-
-       return notit->cur_content_size - packet_at(notit);
-}
-
-static inline
-size_t remaining_packet_bits(struct bt_ctf_notif_iter *notit)
-{
-       if (notit->cur_packet_size == -1) {
-               return -1;
-       }
-
-       return notit->cur_packet_size - packet_at(notit);
-}
-
 static inline
 void buf_consume_bits(struct bt_ctf_notif_iter *notit, size_t incr)
 {
        notit->buf.at += incr;
 }
 
-static inline
-bool buf_has_enough_bits(struct bt_ctf_notif_iter *notit, size_t sz)
-{
-       return buf_available_bits(notit) >= sz;
-}
-
 static
 enum bt_ctf_notif_iter_status request_medium_bytes(
                struct bt_ctf_notif_iter *notit)
@@ -2211,30 +2185,6 @@ end:
        BT_PUT(event);
 }
 
-//FIXME: not used ?
-static
-void notify_eos(struct bt_ctf_notif_iter *notit,
-               struct bt_notification **notification)
-{
-       struct bt_ctf_stream *stream = NULL;
-       struct bt_notification *ret = NULL;
-
-       /* Ask the user for the stream */
-       stream = notit->medium.medops.get_stream(notit->meta.stream_class,
-                       notit->medium.data);
-       if (!stream) {
-               goto end;
-       }
-
-       ret = bt_notification_stream_end_create(stream);
-       if (!ret) {
-               goto end;
-       }
-       *notification = ret;
-end:
-       BT_PUT(stream);
-}
-
 static
 int init_clock_states(GHashTable *clock_states, struct bt_ctf_trace *trace)
 {
@@ -2436,6 +2386,10 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification(
 
        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");
@@ -2493,3 +2447,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.
+                        */
+                       assert(false);
+               }
+       }
+
+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.02586 seconds and 4 git commands to generate.