lib: remove output port message iterator
[babeltrace.git] / src / lib / graph / message / iterator.h
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
27 #include "common/macros.h"
28 #include "lib/object.h"
29 #include <babeltrace2/graph/connection-const.h>
30 #include <babeltrace2/graph/message-const.h>
31 #include <babeltrace2/types.h>
32 #include "common/assert.h"
33 #include <stdbool.h>
34 #include "common/uuid.h"
35
36 struct bt_port;
37 struct bt_graph;
38
39 enum bt_self_component_port_input_message_iterator_state {
40 /* Iterator is not initialized */
41 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED,
42
43 /* Iterator is active, not at the end yet, and not finalized */
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
52 /* Iterator is currently being finalized */
53 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING,
54
55 /* Iterator is finalized */
56 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED,
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,
66 };
67
68 typedef enum bt_component_class_message_iterator_next_method_status
69 (*bt_self_component_port_input_message_iterator_next_method)(
70 void *, bt_message_array_const, uint64_t, uint64_t *);
71
72 typedef enum bt_component_class_message_iterator_seek_ns_from_origin_method_status
73 (*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method)(
74 void *, int64_t);
75
76 typedef enum bt_component_class_message_iterator_seek_beginning_method_status
77 (*bt_self_component_port_input_message_iterator_seek_beginning_method)(
78 void *);
79
80 typedef bt_bool
81 (*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method)(
82 void *, int64_t);
83
84 typedef bt_bool
85 (*bt_self_component_port_input_message_iterator_can_seek_beginning_method)(
86 void *);
87
88 struct bt_self_component_port_input_message_iterator {
89 struct bt_object base;
90 GPtrArray *msgs;
91 struct bt_component *upstream_component; /* Weak */
92 struct bt_port *upstream_port; /* Weak */
93 struct bt_connection *connection; /* Weak */
94 struct bt_graph *graph; /* Weak */
95
96 /*
97 * Array of
98 * `struct bt_self_component_port_input_message_iterator *`
99 * (weak).
100 *
101 * This is an array of upstream message iterators on which this
102 * iterator depends. The references are weak: an upstream
103 * message iterator is responsible for removing its entry within
104 * this array on finalization/destruction.
105 */
106 GPtrArray *upstream_msg_iters;
107
108 /*
109 * Downstream message iterator which depends on this message
110 * iterator (weak).
111 *
112 * This can be `NULL` if this message iterator's owner is a sink
113 * component.
114 */
115 struct bt_self_component_port_input_message_iterator *downstream_msg_iter;
116
117 struct {
118 bt_self_component_port_input_message_iterator_next_method next;
119 bt_self_component_port_input_message_iterator_seek_ns_from_origin_method seek_ns_from_origin;
120 bt_self_component_port_input_message_iterator_seek_beginning_method seek_beginning;
121 bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin;
122 bt_self_component_port_input_message_iterator_can_seek_beginning_method can_seek_beginning;
123 } methods;
124
125 enum bt_self_component_port_input_message_iterator_state state;
126
127 /*
128 * Timestamp of the last received message (or INT64_MIN in the
129 * beginning, or after a seek to beginning).
130 */
131 int64_t last_ns_from_origin;
132
133 struct {
134 enum {
135 /* We haven't recorded clock properties yet. */
136 CLOCK_EXPECTATION_UNSET,
137
138 /* Expect to have no clock. */
139 CLOCK_EXPECTATION_NONE,
140
141 /* Clock with origin_is_unix_epoch true.*/
142 CLOCK_EXPECTATION_ORIGIN_UNIX,
143
144 /* Clock with origin_is_unix_epoch false, with a UUID.*/
145 CLOCK_EXPECTATION_ORIGIN_OTHER_UUID,
146
147 /* Clock with origin_is_unix_epoch false, without a UUID.*/
148 CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID,
149 } type;
150
151 /*
152 * Expected UUID of the clock, if `type`is CLOCK_EXPECTATION_ORIGIN_OTHER_UUID.
153 *
154 * If the clock's origin is the unix epoch, the UUID is
155 * irrelevant (as the clock will be correlatable with other
156 * clocks having the same origin).
157 */
158 bt_uuid_t uuid;
159 } clock_expectation;
160
161 /*
162 * Data necessary for auto seek (the seek-to-beginning then fast-forward
163 * seek strategy).
164 */
165 struct {
166 /*
167 * Queue of `const bt_message *` (owned by this queue).
168 *
169 * When fast-forwarding, we get the messages from upstream in
170 * batches. Once we have found the first message with timestamp
171 * greater or equal to the seek time, we put it and all of the
172 * following message of the batch in this queue. They will be
173 * sent on the next "next" call on this iterator.
174 *
175 * The messages are in chronological order (i.e. the first to
176 * send is the first of the queue).
177 */
178 GQueue *msgs;
179
180 /*
181 * After auto-seeking, we replace the iterator's `next` callback
182 * with our own, which returns the contents of the `msgs` queue.
183 * This field is where we save the original callback, so we can
184 * restore it.
185 */
186 void *original_next_callback;
187 } auto_seek;
188
189 void *user_data;
190 };
191
192 BT_HIDDEN
193 void bt_self_component_port_input_message_iterator_try_finalize(
194 struct bt_self_component_port_input_message_iterator *iterator);
195
196 BT_HIDDEN
197 void bt_self_component_port_input_message_iterator_set_connection(
198 struct bt_self_component_port_input_message_iterator *iterator,
199 struct bt_connection *connection);
200
201 static inline
202 const char *bt_self_component_port_input_message_iterator_state_string(
203 enum bt_self_component_port_input_message_iterator_state state)
204 {
205 switch (state) {
206 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE:
207 return "ACTIVE";
208 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED:
209 return "ENDED";
210 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING:
211 return "FINALIZING";
212 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED:
213 return "FINALIZED";
214 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING:
215 return "SEEKING";
216 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN:
217 return "LAST_SEEKING_RETURNED_AGAIN";
218 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR:
219 return "LAST_SEEKING_RETURNED_ERROR";
220 default:
221 return "(unknown)";
222 }
223 };
224
225 #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */
This page took 0.03405 seconds and 5 git commands to generate.