bt2: split clock value module from clock class module
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.h
index ed1dbbcd9e7e860b5e895f4107648262125b6876..444b945403e6594b38d21873def188201c307f4f 100644 (file)
@@ -32,6 +32,7 @@
 #include <babeltrace/ctf-ir/trace.h>
 #include <babeltrace/ctf-ir/fields.h>
 #include <babeltrace/ctf-ir/event.h>
+#include <babeltrace/graph/clock-class-priority-map.h>
 #include <babeltrace/babeltrace-internal.h>
 
 /**
@@ -53,21 +54,24 @@ enum bt_ctf_notif_iter_medium_status {
         * The medium function called by the notification iterator
         * function reached the end of the file.
         */
-       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF =   -4,
+       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF = 1,
 
        /**
         * There is no data available right now, try again later.
         */
-       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_AGAIN = -3,
+       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_AGAIN = 11,
+
+       /** Unsupported operation. */
+       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_UNSUPPORTED = -3,
 
        /** Invalid argument. */
-       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_INVAL = -2,
+       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_INVAL = -2,
 
        /** General error. */
-       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_ERROR = -1,
+       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_ERROR = -1,
 
        /** Everything okay. */
-       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_OK =            0,
+       BT_CTF_NOTIF_ITER_MEDIUM_STATUS_OK = 0,
 };
 
 /**
@@ -80,7 +84,7 @@ enum bt_ctf_notif_iter_status {
         * The medium function called by the notification iterator
         * function reached the end of the file.
         */
-       BT_CTF_NOTIF_ITER_STATUS_EOF =  -4,
+       BT_CTF_NOTIF_ITER_STATUS_EOF = BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF,
 
        /**
         * There is no data available right now, try again later.
@@ -91,18 +95,32 @@ enum bt_ctf_notif_iter_status {
         * last called notification iterator function once the situation
         * is resolved.
         */
-       BT_CTF_NOTIF_ITER_STATUS_AGAIN =        -3,
+       BT_CTF_NOTIF_ITER_STATUS_AGAIN = BT_CTF_NOTIF_ITER_MEDIUM_STATUS_AGAIN,
 
        /** Invalid argument. */
-       BT_CTF_NOTIF_ITER_STATUS_INVAL =        -2,
+       BT_CTF_NOTIF_ITER_STATUS_INVAL = BT_CTF_NOTIF_ITER_MEDIUM_STATUS_INVAL,
+
+       /** Unsupported operation. */
+       BT_CTF_NOTIF_ITER_STATUS_UNSUPPORTED = BT_CTF_NOTIF_ITER_MEDIUM_STATUS_UNSUPPORTED,
 
        /** General error. */
-       BT_CTF_NOTIF_ITER_STATUS_ERROR =        -1,
+       BT_CTF_NOTIF_ITER_STATUS_ERROR = BT_CTF_NOTIF_ITER_MEDIUM_STATUS_ERROR,
 
        /** Everything okay. */
        BT_CTF_NOTIF_ITER_STATUS_OK =   0,
 };
 
+/**
+ * CTF notification iterator seek operation directives.
+ */
+enum bt_ctf_notif_iter_seek_whence {
+       /**
+        * Set the iterator's position to an absolute offset in the underlying
+        * medium.
+        */
+       BT_CTF_NOTIF_ITER_SEEK_WHENCE_SET,
+};
+
 /**
  * Medium operations.
  *
@@ -180,6 +198,22 @@ struct bt_ctf_notif_iter_medium_ops {
                        size_t request_sz, uint8_t **buffer_addr,
                        size_t *buffer_sz, void *data);
 
+       /**
+        * Repositions the underlying stream's position.
+        *
+        * This *optional* method repositions the underlying stream
+        * to a given absolute or relative position, as indicated by
+        * the whence directive.
+        *
+        * @param whence        One of #bt_ctf_notif_iter_seek_whence values
+        * @param offset        Offset to use for the given directive
+        * @param data          User data
+        * @returns             One of #bt_ctf_notif_iter_medium_status values
+        */
+       enum bt_ctf_notif_iter_medium_status (* seek)(
+                       enum bt_ctf_notif_iter_seek_whence whence,
+                       off_t offset, void *data);
+
        /**
         * Returns a stream instance (weak reference) for the given
         * stream class.
@@ -188,13 +222,16 @@ struct bt_ctf_notif_iter_medium_ops {
         * corresponding stream class is found by the notification
         * iterator.
         *
-        * @param stream_class  Stream class associated to the stream
+        * @param stream_class  Stream class of the stream to get
+        * @param stream_id     Stream (instance) ID of the stream
+        *                      to get (-1ULL if not available)
         * @param data          User data
         * @returns             Stream instance (weak reference) or
         *                      \c NULL on error
         */
        struct bt_ctf_stream * (* get_stream)(
-                       struct bt_ctf_stream_class *stream_class, void *data);
+                       struct bt_ctf_stream_class *stream_class,
+                       uint64_t stream_id, void *data);
 };
 
 /** CTF notification iterator. */
@@ -226,8 +263,6 @@ struct bt_ctf_notif_iter_notif_event {
        struct bt_ctf_event *event;
 };
 
-void bt_ctf_notif_iter_notif_destroy(void *notif);
-
 /**
  * Creates a CTF notification iterator.
  *
@@ -241,13 +276,13 @@ void bt_ctf_notif_iter_notif_destroy(void *notif);
  *                             at a time
  * @param medops               Medium operations
  * @param medops_data          User data (passed to medium operations)
- * @param err_stream           Error stream (can be \c NULL to disable)
  * @returns                    New CTF notification iterator on
  *                             success, or \c NULL on error
  */
+BT_HIDDEN
 struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
        size_t max_request_sz, struct bt_ctf_notif_iter_medium_ops medops,
-       void *medops_data, FILE *err_stream);
+       void *medops_data);
 
 /**
  * Destroys a CTF notification iterator, freeing all internal resources.
@@ -256,21 +291,9 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
  *
  * @param notif_iter           CTF notification iterator
  */
+BT_HIDDEN
 void bt_ctf_notif_iter_destroy(struct bt_ctf_notif_iter *notif_iter);
 
-/**
- * Resets the internal state of a CTF notification iterator.
- *
- * This function can be used when it is desired to seek to the beginning
- * of another packet. It is expected that the next call to
- * bt_ctf_notif_iter_medium_ops::request_bytes() made by this
- * notification iterator will return the \em first bytes of a \em
- * packet.
- *
- * @param notif_iter           CTF notification iterator
- */
-void bt_ctf_notif_iter_reset(struct bt_ctf_notif_iter *notif_iter);
-
 /**
  * Returns the next notification from a CTF notification iterator.
  *
@@ -284,12 +307,95 @@ void bt_ctf_notif_iter_reset(struct bt_ctf_notif_iter *notif_iter);
  * call this function again, until another status is returned.
  *
  * @param notif_iter           CTF notification iterator
+ * @param cc_prio_map          Clock class priority map to use when
+ *                             creating an event notification
  * @param notification         Returned notification if the function's
  *                             return value is #BT_CTF_NOTIF_ITER_STATUS_OK
  * @returns                    One of #bt_ctf_notif_iter_status values
  */
+BT_HIDDEN
 enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification(
-               struct bt_ctf_notif_iter *notif_iter,
-               struct bt_ctf_notif_iter_notif **notification);
+               struct bt_ctf_notif_iter *notit,
+               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);
+
+BT_HIDDEN
+void bt_ctf_notif_iter_set_medops_data(struct bt_ctf_notif_iter *notit,
+               void *medops_data);
+
+BT_HIDDEN
+enum bt_ctf_notif_iter_status bt_ctf_notif_iter_seek(
+               struct bt_ctf_notif_iter *notit, off_t offset);
+
+/*
+ * Get the current packet's offset in bytes relative to the media's initial
+ * position.
+ */
+BT_HIDDEN
+off_t bt_ctf_notif_iter_get_current_packet_offset(
+               struct bt_ctf_notif_iter *notit);
+
+/* Get the current packet's size (in bits). */
+BT_HIDDEN
+off_t bt_ctf_notif_iter_get_current_packet_size(
+               struct bt_ctf_notif_iter *notit);
+
+static inline
+const char *bt_ctf_notif_iter_medium_status_string(
+               enum bt_ctf_notif_iter_medium_status status)
+{
+       switch (status) {
+       case BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF:
+               return "BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF";
+       case BT_CTF_NOTIF_ITER_MEDIUM_STATUS_AGAIN:
+               return "BT_CTF_NOTIF_ITER_MEDIUM_STATUS_AGAIN";
+       case BT_CTF_NOTIF_ITER_MEDIUM_STATUS_INVAL:
+               return "BT_CTF_NOTIF_ITER_MEDIUM_STATUS_INVAL";
+       case BT_CTF_NOTIF_ITER_MEDIUM_STATUS_ERROR:
+               return "BT_CTF_NOTIF_ITER_MEDIUM_STATUS_ERROR";
+       case BT_CTF_NOTIF_ITER_MEDIUM_STATUS_OK:
+               return "BT_CTF_NOTIF_ITER_MEDIUM_STATUS_OK";
+       default:
+               return "(unknown)";
+       }
+}
+
+static inline
+const char *bt_ctf_notif_iter_status_string(
+               enum bt_ctf_notif_iter_status status)
+{
+       switch (status) {
+       case BT_CTF_NOTIF_ITER_STATUS_EOF:
+               return "BT_CTF_NOTIF_ITER_STATUS_EOF";
+       case BT_CTF_NOTIF_ITER_STATUS_AGAIN:
+               return "BT_CTF_NOTIF_ITER_STATUS_AGAIN";
+       case BT_CTF_NOTIF_ITER_STATUS_INVAL:
+               return "BT_CTF_NOTIF_ITER_STATUS_INVAL";
+       case BT_CTF_NOTIF_ITER_STATUS_ERROR:
+               return "BT_CTF_NOTIF_ITER_STATUS_ERROR";
+       case BT_CTF_NOTIF_ITER_STATUS_OK:
+               return "BT_CTF_NOTIF_ITER_STATUS_OK";
+       default:
+               return "(unknown)";
+       }
+}
 
 #endif /* CTF_NOTIF_ITER_H */
This page took 0.026159 seconds and 4 git commands to generate.