Commit | Line | Data |
---|---|---|
d6e69534 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 | ||
91d81473 | 27 | #include "common/macros.h" |
578e048b | 28 | #include "lib/object.h" |
3fadfbc0 MJ |
29 | #include <babeltrace2/graph/connection-const.h> |
30 | #include <babeltrace2/graph/message-const.h> | |
3fadfbc0 | 31 | #include <babeltrace2/types.h> |
578e048b | 32 | #include "common/assert.h" |
d6e69534 | 33 | #include <stdbool.h> |
6162e6b7 | 34 | #include "common/uuid.h" |
d6e69534 PP |
35 | |
36 | struct bt_port; | |
37 | struct bt_graph; | |
38 | ||
39 | enum bt_message_iterator_type { | |
40 | BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT, | |
41 | BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT, | |
42 | }; | |
43 | ||
44 | enum bt_self_component_port_input_message_iterator_state { | |
7474e7d3 | 45 | /* Iterator is not initialized */ |
d6e69534 PP |
46 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED, |
47 | ||
7474e7d3 | 48 | /* Iterator is active, not at the end yet, and not finalized */ |
d6e69534 PP |
49 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE, |
50 | ||
51 | /* | |
52 | * Iterator is ended, not finalized yet: the "next" method | |
53 | * returns BT_MESSAGE_ITERATOR_STATUS_END. | |
54 | */ | |
55 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED, | |
56 | ||
7474e7d3 | 57 | /* Iterator is currently being finalized */ |
d0fea130 | 58 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING, |
d6e69534 | 59 | |
7474e7d3 | 60 | /* Iterator is finalized */ |
d0fea130 | 61 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED, |
7474e7d3 PP |
62 | |
63 | /* Iterator is seeking */ | |
64 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING, | |
65 | ||
66 | /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */ | |
67 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN, | |
68 | ||
69 | /* Iterator did seek, but returned error status */ | |
70 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, | |
d6e69534 PP |
71 | }; |
72 | ||
73 | struct bt_message_iterator { | |
74 | struct bt_object base; | |
75 | enum bt_message_iterator_type type; | |
76 | GPtrArray *msgs; | |
77 | }; | |
78 | ||
d24d5663 | 79 | typedef enum bt_component_class_message_iterator_next_method_status |
7474e7d3 PP |
80 | (*bt_self_component_port_input_message_iterator_next_method)( |
81 | void *, bt_message_array_const, uint64_t, uint64_t *); | |
82 | ||
d24d5663 | 83 | typedef enum bt_component_class_message_iterator_seek_ns_from_origin_method_status |
7474e7d3 PP |
84 | (*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method)( |
85 | void *, int64_t); | |
86 | ||
d24d5663 | 87 | typedef enum bt_component_class_message_iterator_seek_beginning_method_status |
7474e7d3 PP |
88 | (*bt_self_component_port_input_message_iterator_seek_beginning_method)( |
89 | void *); | |
90 | ||
91 | typedef bt_bool | |
92 | (*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method)( | |
93 | void *, int64_t); | |
94 | ||
95 | typedef bt_bool | |
96 | (*bt_self_component_port_input_message_iterator_can_seek_beginning_method)( | |
97 | void *); | |
98 | ||
d6e69534 PP |
99 | struct bt_self_component_port_input_message_iterator { |
100 | struct bt_message_iterator base; | |
101 | struct bt_component *upstream_component; /* Weak */ | |
102 | struct bt_port *upstream_port; /* Weak */ | |
103 | struct bt_connection *connection; /* Weak */ | |
104 | struct bt_graph *graph; /* Weak */ | |
105 | ||
7474e7d3 PP |
106 | struct { |
107 | bt_self_component_port_input_message_iterator_next_method next; | |
108 | bt_self_component_port_input_message_iterator_seek_ns_from_origin_method seek_ns_from_origin; | |
109 | bt_self_component_port_input_message_iterator_seek_beginning_method seek_beginning; | |
110 | bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin; | |
111 | bt_self_component_port_input_message_iterator_can_seek_beginning_method can_seek_beginning; | |
112 | } methods; | |
d6e69534 PP |
113 | |
114 | enum bt_self_component_port_input_message_iterator_state state; | |
da9c4c52 | 115 | |
54b135a0 SM |
116 | /* |
117 | * Timestamp of the last received message (or INT64_MIN in the | |
118 | * beginning, or after a seek to beginning). | |
119 | */ | |
120 | int64_t last_ns_from_origin; | |
121 | ||
122 | struct { | |
123 | enum { | |
124 | /* We haven't recorded clock properties yet. */ | |
125 | CLOCK_EXPECTATION_UNSET, | |
126 | ||
127 | /* Expect to have no clock. */ | |
128 | CLOCK_EXPECTATION_NONE, | |
129 | ||
130 | /* Clock with origin_is_unix_epoch true.*/ | |
131 | CLOCK_EXPECTATION_ORIGIN_UNIX, | |
132 | ||
133 | /* Clock with origin_is_unix_epoch false, with a UUID.*/ | |
134 | CLOCK_EXPECTATION_ORIGIN_OTHER_UUID, | |
135 | ||
136 | /* Clock with origin_is_unix_epoch false, without a UUID.*/ | |
137 | CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID, | |
138 | } type; | |
139 | ||
140 | /* | |
141 | * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID. | |
142 | * | |
143 | * If the clock's origin is the unix epoch, the UUID is | |
144 | * irrelevant (as the clock will be correlatable with other | |
145 | * clocks having the same origin). | |
146 | */ | |
6162e6b7 | 147 | bt_uuid_t uuid; |
54b135a0 SM |
148 | } clock_expectation; |
149 | ||
da9c4c52 SM |
150 | /* |
151 | * Data necessary for auto seek (the seek-to-beginning then fast-forward | |
152 | * seek strategy). | |
153 | */ | |
154 | struct { | |
155 | /* | |
156 | * Queue of `const bt_message *` (owned by this queue). | |
157 | * | |
158 | * When fast-forwarding, we get the messages from upstream in | |
159 | * batches. Once we have found the first message with timestamp | |
160 | * greater or equal to the seek time, we put it and all of the | |
161 | * following message of the batch in this queue. They will be | |
162 | * sent on the next "next" call on this iterator. | |
163 | * | |
164 | * The messages are in chronological order (i.e. the first to | |
165 | * send is the first of the queue). | |
166 | */ | |
167 | GQueue *msgs; | |
572075a8 SM |
168 | |
169 | /* | |
170 | * After auto-seeking, we replace the iterator's `next` callback | |
171 | * with our own, which returns the contents of the `msgs` queue. | |
172 | * This field is where we save the original callback, so we can | |
173 | * restore it. | |
174 | */ | |
175 | void *original_next_callback; | |
da9c4c52 SM |
176 | } auto_seek; |
177 | ||
d6e69534 PP |
178 | void *user_data; |
179 | }; | |
180 | ||
181 | struct bt_port_output_message_iterator { | |
182 | struct bt_message_iterator base; | |
183 | struct bt_graph *graph; /* Owned by this */ | |
184 | struct bt_component_sink *colander; /* Owned by this */ | |
185 | ||
186 | /* | |
187 | * Only used temporarily as a bridge between a colander sink and | |
188 | * the user. | |
189 | */ | |
190 | uint64_t count; | |
191 | }; | |
192 | ||
193 | BT_HIDDEN | |
d0fea130 | 194 | void bt_self_component_port_input_message_iterator_try_finalize( |
d6e69534 PP |
195 | struct bt_self_component_port_input_message_iterator *iterator); |
196 | ||
197 | BT_HIDDEN | |
198 | void bt_self_component_port_input_message_iterator_set_connection( | |
199 | struct bt_self_component_port_input_message_iterator *iterator, | |
200 | struct bt_connection *connection); | |
201 | ||
d6e69534 PP |
202 | static inline |
203 | const char *bt_self_component_port_input_message_iterator_state_string( | |
204 | enum bt_self_component_port_input_message_iterator_state state) | |
205 | { | |
206 | switch (state) { | |
207 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE: | |
208 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE"; | |
209 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED: | |
210 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED"; | |
d0fea130 PP |
211 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING: |
212 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING"; | |
d6e69534 PP |
213 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED: |
214 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED"; | |
7474e7d3 PP |
215 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING: |
216 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING"; | |
217 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN: | |
218 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN"; | |
219 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR: | |
220 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR"; | |
d6e69534 PP |
221 | default: |
222 | return "(unknown)"; | |
223 | } | |
224 | }; | |
225 | ||
226 | #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */ |