ctf plugin: add bt_ctf_notif_iter_get_packet_header_context_fields()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 24 May 2017 00:45:08 +0000 (20:45 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:44 +0000 (12:57 -0400)
The new bt_ctf_notif_iter_get_packet_header_context_fields() function
returns the packet header and context fields using the usual medium
operation mechanism without ever creating packet of event objects,
therefore not requiring a stream object to exist.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
plugins/ctf/common/notif-iter/notif-iter.c
plugins/ctf/common/notif-iter/notif-iter.h

index bc20f8814b1de423158fa04961a9134d42f4a599..acb349380c3fa626328b9805300bb38d2f97a4d0 100644 (file)
@@ -2447,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;
+}
index 476e7d7a90138639c127adaa8f5184551267eb5f..23277754a759b0d863bef1726a34757adb9572a0 100644 (file)
@@ -284,4 +284,22 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification(
                struct bt_clock_class_priority_map *cc_prio_map,
                struct bt_notification **notification);
 
+/**
+ * Returns the first packet header and context fields. This function
+ * never needs to call the `get_stream()` medium operation because
+ * it does not create packet or event objects.
+ *
+ * @param notif_iter           CTF notification iterator
+ * @param packet_header_field  Packet header field (\c NULL if there's
+ *                             no packet header field)
+ * @param packet_context_field Packet context field (\c NULL if there's
+ *                             no packet context field)
+ * @returns                    One of #bt_ctf_notif_iter_status values
+ */
+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);
+
 #endif /* CTF_NOTIF_ITER_H */
This page took 0.027602 seconds and 4 git commands to generate.