lib: add seeking (beginning, ns from origin), with auto-seeking support
[babeltrace.git] / include / babeltrace / graph / message-iterator-internal.h
CommitLineData
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
27#include <babeltrace/babeltrace-internal.h>
28#include <babeltrace/object-internal.h>
29#include <babeltrace/graph/connection-const.h>
30#include <babeltrace/graph/message-const.h>
7474e7d3 31#include <babeltrace/graph/message-iterator-const.h>
d6e69534
PP
32#include <babeltrace/types.h>
33#include <babeltrace/assert-internal.h>
34#include <stdbool.h>
35
36struct bt_port;
37struct bt_graph;
38
39enum bt_message_iterator_type {
40 BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT,
41 BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT,
42};
43
44enum 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
73struct bt_message_iterator {
74 struct bt_object base;
75 enum bt_message_iterator_type type;
76 GPtrArray *msgs;
77};
78
7474e7d3
PP
79typedef enum bt_self_message_iterator_status
80(*bt_self_component_port_input_message_iterator_next_method)(
81 void *, bt_message_array_const, uint64_t, uint64_t *);
82
83typedef enum bt_self_message_iterator_status
84(*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method)(
85 void *, int64_t);
86
87typedef enum bt_self_message_iterator_status
88(*bt_self_component_port_input_message_iterator_seek_beginning_method)(
89 void *);
90
91typedef bt_bool
92(*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method)(
93 void *, int64_t);
94
95typedef bt_bool
96(*bt_self_component_port_input_message_iterator_can_seek_beginning_method)(
97 void *);
98
d6e69534
PP
99struct 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;
7474e7d3
PP
115 uint64_t auto_seek_msg_count;
116 GPtrArray *auto_seek_msgs;
d6e69534
PP
117 void *user_data;
118};
119
120struct bt_port_output_message_iterator {
121 struct bt_message_iterator base;
122 struct bt_graph *graph; /* Owned by this */
123 struct bt_component_sink *colander; /* Owned by this */
124
125 /*
126 * Only used temporarily as a bridge between a colander sink and
127 * the user.
128 */
129 uint64_t count;
130};
131
132BT_HIDDEN
d0fea130 133void bt_self_component_port_input_message_iterator_try_finalize(
d6e69534
PP
134 struct bt_self_component_port_input_message_iterator *iterator);
135
136BT_HIDDEN
137void bt_self_component_port_input_message_iterator_set_connection(
138 struct bt_self_component_port_input_message_iterator *iterator,
139 struct bt_connection *connection);
140
141static inline
142const char *bt_message_iterator_status_string(
143 enum bt_message_iterator_status status)
144{
145 switch (status) {
d6e69534
PP
146 case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
147 return "BT_MESSAGE_ITERATOR_STATUS_AGAIN";
148 case BT_MESSAGE_ITERATOR_STATUS_END:
149 return "BT_MESSAGE_ITERATOR_STATUS_END";
150 case BT_MESSAGE_ITERATOR_STATUS_OK:
151 return "BT_MESSAGE_ITERATOR_STATUS_OK";
152 case BT_MESSAGE_ITERATOR_STATUS_ERROR:
153 return "BT_MESSAGE_ITERATOR_STATUS_ERROR";
154 case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
155 return "BT_MESSAGE_ITERATOR_STATUS_NOMEM";
156 default:
157 return "(unknown)";
158 }
159};
160
161static inline
162const char *bt_self_component_port_input_message_iterator_state_string(
163 enum bt_self_component_port_input_message_iterator_state state)
164{
165 switch (state) {
166 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE:
167 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE";
168 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED:
169 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED";
d0fea130
PP
170 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING:
171 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING";
d6e69534
PP
172 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED:
173 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED";
7474e7d3
PP
174 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING:
175 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING";
176 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN:
177 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN";
178 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR:
179 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR";
d6e69534
PP
180 default:
181 return "(unknown)";
182 }
183};
184
185#endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */
This page took 0.0313 seconds and 4 git commands to generate.