Commit | Line | Data |
---|---|---|
b09a5592 PP |
1 | #ifndef BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H |
2 | #define BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H | |
3 | ||
4 | /* | |
5 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> | |
6 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 | * SOFTWARE. | |
25 | */ | |
26 | ||
85e7137b | 27 | #include "common/macros.h" |
57952005 | 28 | #include "lib/object.h" |
71c5da58 MJ |
29 | #include <babeltrace2/graph/connection-const.h> |
30 | #include <babeltrace2/graph/message-const.h> | |
71c5da58 | 31 | #include <babeltrace2/types.h> |
57952005 | 32 | #include "common/assert.h" |
b09a5592 | 33 | #include <stdbool.h> |
d126826c | 34 | #include "common/uuid.h" |
b09a5592 PP |
35 | |
36 | struct bt_port; | |
37 | struct bt_graph; | |
38 | ||
b09a5592 | 39 | enum bt_self_component_port_input_message_iterator_state { |
15a52f66 | 40 | /* Iterator is not initialized */ |
b09a5592 PP |
41 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED, |
42 | ||
15a52f66 | 43 | /* Iterator is active, not at the end yet, and not finalized */ |
b09a5592 PP |
44 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE, |
45 | ||
46 | /* | |
47 | * Iterator is ended, not finalized yet: the "next" method | |
48 | * returns BT_MESSAGE_ITERATOR_STATUS_END. | |
49 | */ | |
50 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED, | |
51 | ||
15a52f66 | 52 | /* Iterator is currently being finalized */ |
904860cb | 53 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING, |
b09a5592 | 54 | |
15a52f66 | 55 | /* Iterator is finalized */ |
904860cb | 56 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED, |
15a52f66 PP |
57 | |
58 | /* Iterator is seeking */ | |
59 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING, | |
60 | ||
61 | /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */ | |
62 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN, | |
63 | ||
64 | /* Iterator did seek, but returned error status */ | |
65 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, | |
b09a5592 PP |
66 | }; |
67 | ||
fb25b9e3 | 68 | typedef enum bt_component_class_message_iterator_next_method_status |
15a52f66 PP |
69 | (*bt_self_component_port_input_message_iterator_next_method)( |
70 | void *, bt_message_array_const, uint64_t, uint64_t *); | |
71 | ||
fb25b9e3 | 72 | typedef enum bt_component_class_message_iterator_seek_ns_from_origin_method_status |
15a52f66 PP |
73 | (*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method)( |
74 | void *, int64_t); | |
75 | ||
fb25b9e3 | 76 | typedef enum bt_component_class_message_iterator_seek_beginning_method_status |
15a52f66 PP |
77 | (*bt_self_component_port_input_message_iterator_seek_beginning_method)( |
78 | void *); | |
79 | ||
9e8e8b43 | 80 | typedef enum bt_component_class_message_iterator_can_seek_ns_from_origin_method_status |
15a52f66 | 81 | (*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method)( |
9e8e8b43 | 82 | void *, int64_t, bt_bool *); |
15a52f66 | 83 | |
9e8e8b43 | 84 | typedef enum bt_component_class_message_iterator_can_seek_beginning_method_status |
15a52f66 | 85 | (*bt_self_component_port_input_message_iterator_can_seek_beginning_method)( |
9e8e8b43 | 86 | void *, bt_bool *); |
15a52f66 | 87 | |
9415de1c SM |
88 | struct bt_self_message_iterator_configuration { |
89 | bool frozen; | |
90 | bool can_seek_forward; | |
91 | }; | |
92 | ||
b09a5592 | 93 | struct bt_self_component_port_input_message_iterator { |
fac7b25a PP |
94 | struct bt_object base; |
95 | GPtrArray *msgs; | |
b09a5592 PP |
96 | struct bt_component *upstream_component; /* Weak */ |
97 | struct bt_port *upstream_port; /* Weak */ | |
98 | struct bt_connection *connection; /* Weak */ | |
99 | struct bt_graph *graph; /* Weak */ | |
9415de1c | 100 | struct bt_self_message_iterator_configuration config; |
b09a5592 | 101 | |
692f1a01 PP |
102 | /* |
103 | * Array of | |
104 | * `struct bt_self_component_port_input_message_iterator *` | |
105 | * (weak). | |
106 | * | |
107 | * This is an array of upstream message iterators on which this | |
108 | * iterator depends. The references are weak: an upstream | |
109 | * message iterator is responsible for removing its entry within | |
110 | * this array on finalization/destruction. | |
111 | */ | |
112 | GPtrArray *upstream_msg_iters; | |
113 | ||
114 | /* | |
115 | * Downstream message iterator which depends on this message | |
116 | * iterator (weak). | |
117 | * | |
118 | * This can be `NULL` if this message iterator's owner is a sink | |
119 | * component. | |
120 | */ | |
121 | struct bt_self_component_port_input_message_iterator *downstream_msg_iter; | |
122 | ||
15a52f66 PP |
123 | struct { |
124 | bt_self_component_port_input_message_iterator_next_method next; | |
125 | bt_self_component_port_input_message_iterator_seek_ns_from_origin_method seek_ns_from_origin; | |
126 | bt_self_component_port_input_message_iterator_seek_beginning_method seek_beginning; | |
127 | bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin; | |
128 | bt_self_component_port_input_message_iterator_can_seek_beginning_method can_seek_beginning; | |
129 | } methods; | |
b09a5592 PP |
130 | |
131 | enum bt_self_component_port_input_message_iterator_state state; | |
1b3630b6 | 132 | |
e253ad8d SM |
133 | /* |
134 | * Timestamp of the last received message (or INT64_MIN in the | |
135 | * beginning, or after a seek to beginning). | |
136 | */ | |
137 | int64_t last_ns_from_origin; | |
138 | ||
139 | struct { | |
140 | enum { | |
141 | /* We haven't recorded clock properties yet. */ | |
142 | CLOCK_EXPECTATION_UNSET, | |
143 | ||
144 | /* Expect to have no clock. */ | |
145 | CLOCK_EXPECTATION_NONE, | |
146 | ||
147 | /* Clock with origin_is_unix_epoch true.*/ | |
148 | CLOCK_EXPECTATION_ORIGIN_UNIX, | |
149 | ||
150 | /* Clock with origin_is_unix_epoch false, with a UUID.*/ | |
151 | CLOCK_EXPECTATION_ORIGIN_OTHER_UUID, | |
152 | ||
153 | /* Clock with origin_is_unix_epoch false, without a UUID.*/ | |
154 | CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID, | |
155 | } type; | |
156 | ||
157 | /* | |
158 | * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID. | |
159 | * | |
160 | * If the clock's origin is the unix epoch, the UUID is | |
161 | * irrelevant (as the clock will be correlatable with other | |
162 | * clocks having the same origin). | |
163 | */ | |
d126826c | 164 | bt_uuid_t uuid; |
e253ad8d SM |
165 | } clock_expectation; |
166 | ||
1b3630b6 SM |
167 | /* |
168 | * Data necessary for auto seek (the seek-to-beginning then fast-forward | |
169 | * seek strategy). | |
170 | */ | |
171 | struct { | |
172 | /* | |
173 | * Queue of `const bt_message *` (owned by this queue). | |
174 | * | |
175 | * When fast-forwarding, we get the messages from upstream in | |
176 | * batches. Once we have found the first message with timestamp | |
177 | * greater or equal to the seek time, we put it and all of the | |
178 | * following message of the batch in this queue. They will be | |
179 | * sent on the next "next" call on this iterator. | |
180 | * | |
181 | * The messages are in chronological order (i.e. the first to | |
182 | * send is the first of the queue). | |
183 | */ | |
184 | GQueue *msgs; | |
1d801aab SM |
185 | |
186 | /* | |
187 | * After auto-seeking, we replace the iterator's `next` callback | |
188 | * with our own, which returns the contents of the `msgs` queue. | |
189 | * This field is where we save the original callback, so we can | |
190 | * restore it. | |
191 | */ | |
192 | void *original_next_callback; | |
1b3630b6 SM |
193 | } auto_seek; |
194 | ||
b09a5592 PP |
195 | void *user_data; |
196 | }; | |
197 | ||
b09a5592 | 198 | BT_HIDDEN |
904860cb | 199 | void bt_self_component_port_input_message_iterator_try_finalize( |
b09a5592 PP |
200 | struct bt_self_component_port_input_message_iterator *iterator); |
201 | ||
202 | BT_HIDDEN | |
203 | void bt_self_component_port_input_message_iterator_set_connection( | |
204 | struct bt_self_component_port_input_message_iterator *iterator, | |
205 | struct bt_connection *connection); | |
206 | ||
b09a5592 PP |
207 | static inline |
208 | const char *bt_self_component_port_input_message_iterator_state_string( | |
209 | enum bt_self_component_port_input_message_iterator_state state) | |
210 | { | |
211 | switch (state) { | |
212 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE: | |
e05f8464 | 213 | return "ACTIVE"; |
b09a5592 | 214 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED: |
e05f8464 | 215 | return "ENDED"; |
904860cb | 216 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING: |
e05f8464 | 217 | return "FINALIZING"; |
b09a5592 | 218 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED: |
e05f8464 | 219 | return "FINALIZED"; |
15a52f66 | 220 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING: |
e05f8464 | 221 | return "SEEKING"; |
15a52f66 | 222 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN: |
e05f8464 | 223 | return "LAST_SEEKING_RETURNED_AGAIN"; |
15a52f66 | 224 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR: |
e05f8464 | 225 | return "LAST_SEEKING_RETURNED_ERROR"; |
b09a5592 PP |
226 | default: |
227 | return "(unknown)"; | |
228 | } | |
229 | }; | |
230 | ||
231 | #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */ |