lib: make can_seek_beginning and can_seek_ns_from_origin methods return a status
[babeltrace.git] / src / lib / graph / message / iterator.h
index bae41b19249d0f267c9ddbacbe49336a3b60ecf8..8014d1fad536c27d8fbd97772a7c014035f17e43 100644 (file)
  * SOFTWARE.
  */
 
-#include "common/babeltrace.h"
+#include "common/macros.h"
 #include "lib/object.h"
 #include <babeltrace2/graph/connection-const.h>
 #include <babeltrace2/graph/message-const.h>
-#include <babeltrace2/graph/message-iterator-const.h>
 #include <babeltrace2/types.h>
 #include "common/assert.h"
 #include <stdbool.h>
+#include "common/uuid.h"
 
 struct bt_port;
 struct bt_graph;
 
-enum bt_message_iterator_type {
-       BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT,
-       BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT,
-};
-
 enum bt_self_component_port_input_message_iterator_state {
        /* Iterator is not initialized */
        BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED,
@@ -70,39 +65,55 @@ enum bt_self_component_port_input_message_iterator_state {
        BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR,
 };
 
-struct bt_message_iterator {
-       struct bt_object base;
-       enum bt_message_iterator_type type;
-       GPtrArray *msgs;
-};
-
-typedef enum bt_self_message_iterator_status
+typedef enum bt_component_class_message_iterator_next_method_status
 (*bt_self_component_port_input_message_iterator_next_method)(
                void *, bt_message_array_const, uint64_t, uint64_t *);
 
-typedef enum bt_self_message_iterator_status
+typedef enum bt_component_class_message_iterator_seek_ns_from_origin_method_status
 (*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method)(
                void *, int64_t);
 
-typedef enum bt_self_message_iterator_status
+typedef enum bt_component_class_message_iterator_seek_beginning_method_status
 (*bt_self_component_port_input_message_iterator_seek_beginning_method)(
                void *);
 
-typedef bt_bool
+typedef enum bt_component_class_message_iterator_can_seek_ns_from_origin_method_status
 (*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method)(
-               void *, int64_t);
+               void *, int64_t, bt_bool *);
 
-typedef bt_bool
+typedef enum bt_component_class_message_iterator_can_seek_beginning_method_status
 (*bt_self_component_port_input_message_iterator_can_seek_beginning_method)(
-               void *);
+               void *, bt_bool *);
 
 struct bt_self_component_port_input_message_iterator {
-       struct bt_message_iterator base;
+       struct bt_object base;
+       GPtrArray *msgs;
        struct bt_component *upstream_component; /* Weak */
        struct bt_port *upstream_port; /* Weak */
        struct bt_connection *connection; /* Weak */
        struct bt_graph *graph; /* Weak */
 
+       /*
+        * Array of
+        * `struct bt_self_component_port_input_message_iterator *`
+        * (weak).
+        *
+        * This is an array of upstream message iterators on which this
+        * iterator depends. The references are weak: an upstream
+        * message iterator is responsible for removing its entry within
+        * this array on finalization/destruction.
+        */
+       GPtrArray *upstream_msg_iters;
+
+       /*
+        * Downstream message iterator which depends on this message
+        * iterator (weak).
+        *
+        * This can be `NULL` if this message iterator's owner is a sink
+        * component.
+        */
+       struct bt_self_component_port_input_message_iterator *downstream_msg_iter;
+
        struct {
                bt_self_component_port_input_message_iterator_next_method next;
                bt_self_component_port_input_message_iterator_seek_ns_from_origin_method seek_ns_from_origin;
@@ -112,20 +123,70 @@ struct bt_self_component_port_input_message_iterator {
        } methods;
 
        enum bt_self_component_port_input_message_iterator_state state;
-       GQueue *auto_seek_msgs;
-       void *user_data;
-};
 
-struct bt_port_output_message_iterator {
-       struct bt_message_iterator base;
-       struct bt_graph *graph; /* Owned by this */
-       struct bt_component_sink *colander; /* Owned by this */
+       /*
+        * Timestamp of the last received message (or INT64_MIN in the
+        * beginning, or after a seek to beginning).
+        */
+       int64_t last_ns_from_origin;
+
+       struct {
+               enum {
+                       /* We haven't recorded clock properties yet. */
+                       CLOCK_EXPECTATION_UNSET,
+
+                       /* Expect to have no clock. */
+                       CLOCK_EXPECTATION_NONE,
+
+                       /* Clock with origin_is_unix_epoch true.*/
+                       CLOCK_EXPECTATION_ORIGIN_UNIX,
+
+                       /* Clock with origin_is_unix_epoch false, with a UUID.*/
+                       CLOCK_EXPECTATION_ORIGIN_OTHER_UUID,
+
+                       /* Clock with origin_is_unix_epoch false, without a UUID.*/
+                       CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID,
+               } type;
+
+               /*
+                * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID.
+                *
+                * If the clock's origin is the unix epoch, the UUID is
+                * irrelevant (as the clock will be correlatable with other
+                * clocks having the same origin).
+                */
+               bt_uuid_t uuid;
+       } clock_expectation;
 
        /*
-        * Only used temporarily as a bridge between a colander sink and
-        * the user.
+        * Data necessary for auto seek (the seek-to-beginning then fast-forward
+        * seek strategy).
         */
-       uint64_t count;
+       struct {
+               /*
+                * Queue of `const bt_message *` (owned by this queue).
+                *
+                * When fast-forwarding, we get the messages from upstream in
+                * batches. Once we have found the first message with timestamp
+                * greater or equal to the seek time, we put it and all of the
+                * following message of the batch in this queue.  They will be
+                * sent on the next "next" call on this iterator.
+                *
+                * The messages are in chronological order (i.e. the first to
+                * send is the first of the queue).
+                */
+               GQueue *msgs;
+
+               /*
+                * After auto-seeking, we replace the iterator's `next` callback
+                * with our own, which returns the contents of the `msgs` queue.
+                * This field is where we save the original callback, so we can
+                * restore it.
+                */
+               void *original_next_callback;
+       } auto_seek;
+
+       void *user_data;
 };
 
 BT_HIDDEN
@@ -137,45 +198,25 @@ void bt_self_component_port_input_message_iterator_set_connection(
                struct bt_self_component_port_input_message_iterator *iterator,
                struct bt_connection *connection);
 
-static inline
-const char *bt_message_iterator_status_string(
-               enum bt_message_iterator_status status)
-{
-       switch (status) {
-       case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
-               return "BT_MESSAGE_ITERATOR_STATUS_AGAIN";
-       case BT_MESSAGE_ITERATOR_STATUS_END:
-               return "BT_MESSAGE_ITERATOR_STATUS_END";
-       case BT_MESSAGE_ITERATOR_STATUS_OK:
-               return "BT_MESSAGE_ITERATOR_STATUS_OK";
-       case BT_MESSAGE_ITERATOR_STATUS_ERROR:
-               return "BT_MESSAGE_ITERATOR_STATUS_ERROR";
-       case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
-               return "BT_MESSAGE_ITERATOR_STATUS_NOMEM";
-       default:
-               return "(unknown)";
-       }
-};
-
 static inline
 const char *bt_self_component_port_input_message_iterator_state_string(
                enum bt_self_component_port_input_message_iterator_state state)
 {
        switch (state) {
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE";
+               return "ACTIVE";
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED";
+               return "ENDED";
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING";
+               return "FINALIZING";
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED";
+               return "FINALIZED";
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING";
+               return "SEEKING";
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN";
+               return "LAST_SEEKING_RETURNED_AGAIN";
        case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR:
-               return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR";
+               return "LAST_SEEKING_RETURNED_ERROR";
        default:
                return "(unknown)";
        }
This page took 0.026304 seconds and 4 git commands to generate.