Commit | Line | Data |
---|---|---|
d6e69534 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
d6e69534 PP |
4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
5 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
d6e69534 PP |
6 | */ |
7 | ||
0235b0db MJ |
8 | #ifndef BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H |
9 | #define BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H | |
10 | ||
91d81473 | 11 | #include "common/macros.h" |
578e048b | 12 | #include "lib/object.h" |
43c59509 PP |
13 | #include <babeltrace2/graph/connection.h> |
14 | #include <babeltrace2/graph/message.h> | |
3fadfbc0 | 15 | #include <babeltrace2/types.h> |
d6e69534 | 16 | #include <stdbool.h> |
6162e6b7 | 17 | #include "common/uuid.h" |
d6e69534 PP |
18 | |
19 | struct bt_port; | |
20 | struct bt_graph; | |
21 | ||
9a2c8b8e | 22 | enum bt_message_iterator_state { |
7474e7d3 | 23 | /* Iterator is not initialized */ |
9a2c8b8e | 24 | BT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED, |
d6e69534 | 25 | |
7474e7d3 | 26 | /* Iterator is active, not at the end yet, and not finalized */ |
9a2c8b8e | 27 | BT_MESSAGE_ITERATOR_STATE_ACTIVE, |
d6e69534 PP |
28 | |
29 | /* | |
30 | * Iterator is ended, not finalized yet: the "next" method | |
31 | * returns BT_MESSAGE_ITERATOR_STATUS_END. | |
32 | */ | |
9a2c8b8e | 33 | BT_MESSAGE_ITERATOR_STATE_ENDED, |
d6e69534 | 34 | |
7474e7d3 | 35 | /* Iterator is currently being finalized */ |
9a2c8b8e | 36 | BT_MESSAGE_ITERATOR_STATE_FINALIZING, |
d6e69534 | 37 | |
7474e7d3 | 38 | /* Iterator is finalized */ |
9a2c8b8e | 39 | BT_MESSAGE_ITERATOR_STATE_FINALIZED, |
7474e7d3 PP |
40 | |
41 | /* Iterator is seeking */ | |
9a2c8b8e | 42 | BT_MESSAGE_ITERATOR_STATE_SEEKING, |
7474e7d3 PP |
43 | |
44 | /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */ | |
9a2c8b8e | 45 | BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN, |
7474e7d3 PP |
46 | |
47 | /* Iterator did seek, but returned error status */ | |
9a2c8b8e | 48 | BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, |
d6e69534 PP |
49 | }; |
50 | ||
a3f0c7db | 51 | typedef enum bt_message_iterator_class_next_method_status |
9a2c8b8e | 52 | (*bt_message_iterator_next_method)( |
7474e7d3 PP |
53 | void *, bt_message_array_const, uint64_t, uint64_t *); |
54 | ||
a3f0c7db | 55 | typedef enum bt_message_iterator_class_seek_ns_from_origin_method_status |
9a2c8b8e | 56 | (*bt_message_iterator_seek_ns_from_origin_method)( |
7474e7d3 PP |
57 | void *, int64_t); |
58 | ||
a3f0c7db | 59 | typedef enum bt_message_iterator_class_seek_beginning_method_status |
9a2c8b8e | 60 | (*bt_message_iterator_seek_beginning_method)( |
7474e7d3 PP |
61 | void *); |
62 | ||
a3f0c7db | 63 | typedef enum bt_message_iterator_class_can_seek_ns_from_origin_method_status |
9a2c8b8e | 64 | (*bt_message_iterator_can_seek_ns_from_origin_method)( |
f2fb1b32 | 65 | void *, int64_t, bt_bool *); |
7474e7d3 | 66 | |
a3f0c7db | 67 | typedef enum bt_message_iterator_class_can_seek_beginning_method_status |
9a2c8b8e | 68 | (*bt_message_iterator_can_seek_beginning_method)( |
f2fb1b32 | 69 | void *, bt_bool *); |
7474e7d3 | 70 | |
8d8b141d SM |
71 | struct bt_self_message_iterator_configuration { |
72 | bool frozen; | |
73 | bool can_seek_forward; | |
74 | }; | |
75 | ||
9a2c8b8e | 76 | struct bt_message_iterator { |
6c373cc9 PP |
77 | struct bt_object base; |
78 | GPtrArray *msgs; | |
d6e69534 PP |
79 | struct bt_component *upstream_component; /* Weak */ |
80 | struct bt_port *upstream_port; /* Weak */ | |
81 | struct bt_connection *connection; /* Weak */ | |
82 | struct bt_graph *graph; /* Weak */ | |
8d8b141d | 83 | struct bt_self_message_iterator_configuration config; |
d6e69534 | 84 | |
ca02df0a PP |
85 | /* |
86 | * Array of | |
9a2c8b8e | 87 | * `struct bt_message_iterator *` |
ca02df0a PP |
88 | * (weak). |
89 | * | |
90 | * This is an array of upstream message iterators on which this | |
91 | * iterator depends. The references are weak: an upstream | |
92 | * message iterator is responsible for removing its entry within | |
93 | * this array on finalization/destruction. | |
94 | */ | |
95 | GPtrArray *upstream_msg_iters; | |
96 | ||
97 | /* | |
98 | * Downstream message iterator which depends on this message | |
99 | * iterator (weak). | |
100 | * | |
101 | * This can be `NULL` if this message iterator's owner is a sink | |
102 | * component. | |
103 | */ | |
9a2c8b8e | 104 | struct bt_message_iterator *downstream_msg_iter; |
ca02df0a | 105 | |
7474e7d3 | 106 | struct { |
9a2c8b8e | 107 | bt_message_iterator_next_method next; |
2e1b5615 SM |
108 | |
109 | /* These two are always both set or both unset. */ | |
9a2c8b8e PP |
110 | bt_message_iterator_seek_ns_from_origin_method seek_ns_from_origin; |
111 | bt_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin; | |
2e1b5615 SM |
112 | |
113 | /* These two are always both set or both unset. */ | |
9a2c8b8e PP |
114 | bt_message_iterator_seek_beginning_method seek_beginning; |
115 | bt_message_iterator_can_seek_beginning_method can_seek_beginning; | |
7474e7d3 | 116 | } methods; |
d6e69534 | 117 | |
9a2c8b8e | 118 | enum bt_message_iterator_state state; |
da9c4c52 | 119 | |
54b135a0 SM |
120 | /* |
121 | * Timestamp of the last received message (or INT64_MIN in the | |
122 | * beginning, or after a seek to beginning). | |
123 | */ | |
124 | int64_t last_ns_from_origin; | |
125 | ||
78d07b86 SM |
126 | BT_IF_DEV_MODE( |
127 | struct bt_clock_correlation_validator *correlation_validator); | |
9340eff9 SM |
128 | BT_IF_DEV_MODE(GHashTable *per_stream_state); |
129 | ||
da9c4c52 SM |
130 | /* |
131 | * Data necessary for auto seek (the seek-to-beginning then fast-forward | |
132 | * seek strategy). | |
133 | */ | |
134 | struct { | |
135 | /* | |
136 | * Queue of `const bt_message *` (owned by this queue). | |
137 | * | |
138 | * When fast-forwarding, we get the messages from upstream in | |
139 | * batches. Once we have found the first message with timestamp | |
140 | * greater or equal to the seek time, we put it and all of the | |
141 | * following message of the batch in this queue. They will be | |
142 | * sent on the next "next" call on this iterator. | |
143 | * | |
144 | * The messages are in chronological order (i.e. the first to | |
145 | * send is the first of the queue). | |
146 | */ | |
147 | GQueue *msgs; | |
572075a8 SM |
148 | |
149 | /* | |
150 | * After auto-seeking, we replace the iterator's `next` callback | |
151 | * with our own, which returns the contents of the `msgs` queue. | |
152 | * This field is where we save the original callback, so we can | |
153 | * restore it. | |
154 | */ | |
155 | void *original_next_callback; | |
da9c4c52 SM |
156 | } auto_seek; |
157 | ||
d6e69534 PP |
158 | void *user_data; |
159 | }; | |
160 | ||
9a2c8b8e PP |
161 | void bt_message_iterator_try_finalize( |
162 | struct bt_message_iterator *iterator); | |
d6e69534 | 163 | |
9a2c8b8e PP |
164 | void bt_message_iterator_set_connection( |
165 | struct bt_message_iterator *iterator, | |
d6e69534 PP |
166 | struct bt_connection *connection); |
167 | ||
d6e69534 | 168 | static inline |
9a2c8b8e PP |
169 | const char *bt_message_iterator_state_string( |
170 | enum bt_message_iterator_state state) | |
d6e69534 PP |
171 | { |
172 | switch (state) { | |
9a2c8b8e | 173 | case BT_MESSAGE_ITERATOR_STATE_ACTIVE: |
8a432889 | 174 | return "ACTIVE"; |
9a2c8b8e | 175 | case BT_MESSAGE_ITERATOR_STATE_ENDED: |
8a432889 | 176 | return "ENDED"; |
9a2c8b8e | 177 | case BT_MESSAGE_ITERATOR_STATE_FINALIZING: |
8a432889 | 178 | return "FINALIZING"; |
9a2c8b8e | 179 | case BT_MESSAGE_ITERATOR_STATE_FINALIZED: |
8a432889 | 180 | return "FINALIZED"; |
9a2c8b8e | 181 | case BT_MESSAGE_ITERATOR_STATE_SEEKING: |
8a432889 | 182 | return "SEEKING"; |
9a2c8b8e | 183 | case BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN: |
8a432889 | 184 | return "LAST_SEEKING_RETURNED_AGAIN"; |
9a2c8b8e | 185 | case BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR: |
8a432889 | 186 | return "LAST_SEEKING_RETURNED_ERROR"; |
d6e69534 PP |
187 | default: |
188 | return "(unknown)"; | |
189 | } | |
190 | }; | |
191 | ||
192 | #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */ |