1 #ifndef BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
2 #define BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
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>
31 #include <babeltrace/graph/message-iterator-const.h>
32 #include <babeltrace/types.h>
33 #include <babeltrace/assert-internal.h>
39 enum bt_message_iterator_type
{
40 BT_MESSAGE_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT
,
41 BT_MESSAGE_ITERATOR_TYPE_PORT_OUTPUT
,
44 enum bt_self_component_port_input_message_iterator_state
{
45 /* Iterator is not initialized */
46 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED
,
48 /* Iterator is active, not at the end yet, and not finalized */
49 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
,
52 * Iterator is ended, not finalized yet: the "next" method
53 * returns BT_MESSAGE_ITERATOR_STATUS_END.
55 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
,
57 /* Iterator is currently being finalized */
58 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
,
60 /* Iterator is finalized */
61 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
,
63 /* Iterator is seeking */
64 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
,
66 /* Iterator did seek, but returned `BT_MESSAGE_ITERATOR_STATUS_AGAIN` */
67 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
,
69 /* Iterator did seek, but returned error status */
70 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
,
73 struct bt_message_iterator
{
74 struct bt_object base
;
75 enum bt_message_iterator_type type
;
79 typedef 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 *);
83 typedef enum bt_self_message_iterator_status
84 (*bt_self_component_port_input_message_iterator_seek_ns_from_origin_method
)(
87 typedef enum bt_self_message_iterator_status
88 (*bt_self_component_port_input_message_iterator_seek_beginning_method
)(
92 (*bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method
)(
96 (*bt_self_component_port_input_message_iterator_can_seek_beginning_method
)(
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 */
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
;
114 enum bt_self_component_port_input_message_iterator_state state
;
115 GQueue
*auto_seek_msgs
;
119 struct bt_port_output_message_iterator
{
120 struct bt_message_iterator base
;
121 struct bt_graph
*graph
; /* Owned by this */
122 struct bt_component_sink
*colander
; /* Owned by this */
125 * Only used temporarily as a bridge between a colander sink and
132 void bt_self_component_port_input_message_iterator_try_finalize(
133 struct bt_self_component_port_input_message_iterator
*iterator
);
136 void bt_self_component_port_input_message_iterator_set_connection(
137 struct bt_self_component_port_input_message_iterator
*iterator
,
138 struct bt_connection
*connection
);
141 const char *bt_message_iterator_status_string(
142 enum bt_message_iterator_status status
)
145 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
146 return "BT_MESSAGE_ITERATOR_STATUS_AGAIN";
147 case BT_MESSAGE_ITERATOR_STATUS_END
:
148 return "BT_MESSAGE_ITERATOR_STATUS_END";
149 case BT_MESSAGE_ITERATOR_STATUS_OK
:
150 return "BT_MESSAGE_ITERATOR_STATUS_OK";
151 case BT_MESSAGE_ITERATOR_STATUS_ERROR
:
152 return "BT_MESSAGE_ITERATOR_STATUS_ERROR";
153 case BT_MESSAGE_ITERATOR_STATUS_NOMEM
:
154 return "BT_MESSAGE_ITERATOR_STATUS_NOMEM";
161 const char *bt_self_component_port_input_message_iterator_state_string(
162 enum bt_self_component_port_input_message_iterator_state state
)
165 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE
:
166 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE";
167 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED
:
168 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED";
169 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING
:
170 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING";
171 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED
:
172 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED";
173 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING
:
174 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_SEEKING";
175 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN
:
176 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_AGAIN";
177 case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR
:
178 return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR";
184 #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */