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 | ||
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.h> | |
32 | #include <babeltrace/types.h> | |
33 | #include <babeltrace/assert-internal.h> | |
34 | #include <stdbool.h> | |
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 { | |
45 | /* Iterator is not initialized. */ | |
46 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_NON_INITIALIZED, | |
47 | ||
48 | /* Iterator is active, not at the end yet, and not finalized. */ | |
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 | ||
57 | /* | |
d0fea130 | 58 | * Iterator is currently being finalized. |
d6e69534 | 59 | */ |
d0fea130 | 60 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING, |
d6e69534 PP |
61 | |
62 | /* | |
d0fea130 | 63 | * Iterator is finalized. |
d6e69534 | 64 | */ |
d0fea130 | 65 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED, |
d6e69534 PP |
66 | }; |
67 | ||
68 | struct bt_message_iterator { | |
69 | struct bt_object base; | |
70 | enum bt_message_iterator_type type; | |
71 | GPtrArray *msgs; | |
72 | }; | |
73 | ||
74 | struct bt_self_component_port_input_message_iterator { | |
75 | struct bt_message_iterator base; | |
76 | struct bt_component *upstream_component; /* Weak */ | |
77 | struct bt_port *upstream_port; /* Weak */ | |
78 | struct bt_connection *connection; /* Weak */ | |
79 | struct bt_graph *graph; /* Weak */ | |
80 | ||
81 | /* | |
d0fea130 PP |
82 | * This hash table keeps the state of a stream as viewed by this |
83 | * message iterator. This is used, in developer mode, to make | |
84 | * sure that, once the message iterator has seen a "stream end" | |
85 | * message for a given stream, no other messages which refer to | |
86 | * this stream can be delivered by this iterator. It is also | |
87 | * used to check for a valid sequence of messages. | |
d6e69534 | 88 | * |
d0fea130 PP |
89 | * The key (struct bt_stream *) is not owned by this. The value |
90 | * is an allocated state structure. | |
d6e69534 PP |
91 | */ |
92 | GHashTable *stream_states; | |
93 | ||
94 | enum bt_self_component_port_input_message_iterator_state state; | |
95 | void *user_data; | |
96 | }; | |
97 | ||
98 | struct bt_port_output_message_iterator { | |
99 | struct bt_message_iterator base; | |
100 | struct bt_graph *graph; /* Owned by this */ | |
101 | struct bt_component_sink *colander; /* Owned by this */ | |
102 | ||
103 | /* | |
104 | * Only used temporarily as a bridge between a colander sink and | |
105 | * the user. | |
106 | */ | |
107 | uint64_t count; | |
108 | }; | |
109 | ||
110 | BT_HIDDEN | |
d0fea130 | 111 | void bt_self_component_port_input_message_iterator_try_finalize( |
d6e69534 PP |
112 | struct bt_self_component_port_input_message_iterator *iterator); |
113 | ||
114 | BT_HIDDEN | |
115 | void bt_self_component_port_input_message_iterator_set_connection( | |
116 | struct bt_self_component_port_input_message_iterator *iterator, | |
117 | struct bt_connection *connection); | |
118 | ||
119 | static inline | |
120 | const char *bt_message_iterator_status_string( | |
121 | enum bt_message_iterator_status status) | |
122 | { | |
123 | switch (status) { | |
d6e69534 PP |
124 | case BT_MESSAGE_ITERATOR_STATUS_AGAIN: |
125 | return "BT_MESSAGE_ITERATOR_STATUS_AGAIN"; | |
126 | case BT_MESSAGE_ITERATOR_STATUS_END: | |
127 | return "BT_MESSAGE_ITERATOR_STATUS_END"; | |
128 | case BT_MESSAGE_ITERATOR_STATUS_OK: | |
129 | return "BT_MESSAGE_ITERATOR_STATUS_OK"; | |
130 | case BT_MESSAGE_ITERATOR_STATUS_ERROR: | |
131 | return "BT_MESSAGE_ITERATOR_STATUS_ERROR"; | |
132 | case BT_MESSAGE_ITERATOR_STATUS_NOMEM: | |
133 | return "BT_MESSAGE_ITERATOR_STATUS_NOMEM"; | |
134 | default: | |
135 | return "(unknown)"; | |
136 | } | |
137 | }; | |
138 | ||
139 | static inline | |
140 | const char *bt_self_component_port_input_message_iterator_state_string( | |
141 | enum bt_self_component_port_input_message_iterator_state state) | |
142 | { | |
143 | switch (state) { | |
144 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE: | |
145 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ACTIVE"; | |
146 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED: | |
147 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_ENDED"; | |
d0fea130 PP |
148 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING: |
149 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZING"; | |
d6e69534 PP |
150 | case BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED: |
151 | return "BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_STATE_FINALIZED"; | |
d6e69534 PP |
152 | default: |
153 | return "(unknown)"; | |
154 | } | |
155 | }; | |
156 | ||
157 | #endif /* BABELTRACE_GRAPH_MESSAGE_ITERATOR_INTERNAL_H */ |