Commit | Line | Data |
---|---|---|
69985925 PP |
1 | #ifndef BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H |
2 | #define BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H | |
47e5a032 JG |
3 | |
4 | /* | |
47e5a032 | 5 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
3230ee6b | 6 | * Copyright 2017 Philippe Proulx <pproulx@efficios.com> |
47e5a032 JG |
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> | |
890882ef | 28 | #include <babeltrace/object-internal.h> |
bd14d768 | 29 | #include <babeltrace/graph/connection.h> |
b2e0c907 PP |
30 | #include <babeltrace/graph/notification.h> |
31 | #include <babeltrace/graph/notification-iterator.h> | |
c55a9f58 | 32 | #include <babeltrace/types.h> |
1d2f35fd | 33 | #include <babeltrace/assert-internal.h> |
088d4023 | 34 | #include <stdbool.h> |
47e5a032 | 35 | |
3230ee6b | 36 | struct bt_port; |
8ed535b5 | 37 | struct bt_graph; |
3230ee6b | 38 | |
90157d89 | 39 | enum bt_notification_iterator_type { |
110ebe2b PP |
40 | BT_NOTIFICATION_ITERATOR_TYPE_SELF_COMPONENT_PORT_INPUT, |
41 | BT_NOTIFICATION_ITERATOR_TYPE_PORT_OUTPUT, | |
90157d89 PP |
42 | }; |
43 | ||
110ebe2b | 44 | enum bt_self_component_port_input_notification_iterator_state { |
088d4023 | 45 | /* Iterator is not initialized. */ |
110ebe2b | 46 | BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED, |
088d4023 | 47 | |
bd14d768 | 48 | /* Iterator is active, not at the end yet, and not finalized. */ |
110ebe2b | 49 | BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE, |
bd14d768 PP |
50 | |
51 | /* | |
52 | * Iterator is ended, not finalized yet: the "next" method | |
53 | * returns BT_NOTIFICATION_ITERATOR_STATUS_END. | |
54 | */ | |
110ebe2b | 55 | BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED, |
bd14d768 PP |
56 | |
57 | /* | |
58 | * Iterator is finalized, but not at the end yet. This means | |
59 | * that the "next" method can still return queued notifications | |
60 | * before returning the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED | |
61 | * status. | |
62 | */ | |
110ebe2b | 63 | BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED, |
bd14d768 PP |
64 | |
65 | /* | |
66 | * Iterator is finalized and ended: the "next" method always | |
67 | * returns BT_NOTIFICATION_ITERATOR_STATUS_CANCELED. | |
68 | */ | |
110ebe2b | 69 | BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED, |
bd14d768 PP |
70 | }; |
71 | ||
47e5a032 | 72 | struct bt_notification_iterator { |
b8a06801 | 73 | struct bt_object base; |
90157d89 | 74 | enum bt_notification_iterator_type type; |
0d6f8bf6 | 75 | GPtrArray *notifs; |
90157d89 PP |
76 | }; |
77 | ||
110ebe2b | 78 | struct bt_self_component_port_input_notification_iterator { |
90157d89 | 79 | struct bt_notification_iterator base; |
bd14d768 PP |
80 | struct bt_component *upstream_component; /* Weak */ |
81 | struct bt_port *upstream_port; /* Weak */ | |
82 | struct bt_connection *connection; /* Weak */ | |
ecb2b2fe | 83 | struct bt_graph *graph; /* Weak */ |
3230ee6b PP |
84 | |
85 | /* | |
86 | * This hash table keeps the state of a stream as viewed by | |
9412b331 PP |
87 | * this notification iterator. This is used to, in developer |
88 | * mode: | |
3230ee6b PP |
89 | * |
90 | * * Automatically enqueue "stream begin", "packet begin", | |
91 | * "packet end", and "stream end" notifications depending | |
92 | * on the stream's state and on the next notification returned | |
93 | * by the upstream component. | |
94 | * | |
9412b331 PP |
95 | * * Make sure that, once the notification iterator has seen a |
96 | * "stream end" notification for a given stream, no other | |
97 | * notifications which refer to this stream can be delivered | |
98 | * by this iterator. | |
3230ee6b | 99 | * |
50842bdc | 100 | * The key (struct bt_stream *) is not owned by this. The |
3230ee6b PP |
101 | * value is an allocated state structure. |
102 | */ | |
103 | GHashTable *stream_states; | |
104 | ||
110ebe2b | 105 | enum bt_self_component_port_input_notification_iterator_state state; |
47e5a032 JG |
106 | void *user_data; |
107 | }; | |
108 | ||
110ebe2b | 109 | struct bt_port_output_notification_iterator { |
8ed535b5 PP |
110 | struct bt_notification_iterator base; |
111 | struct bt_graph *graph; /* Owned by this */ | |
110ebe2b | 112 | struct bt_component_sink *colander; /* Owned by this */ |
8ed535b5 | 113 | |
0d6f8bf6 PP |
114 | /* |
115 | * Only used temporarily as a bridge between a colander sink and | |
116 | * the user. | |
117 | */ | |
118 | uint64_t count; | |
fd75631d | 119 | }; |
8ed535b5 | 120 | |
bd14d768 | 121 | BT_HIDDEN |
110ebe2b PP |
122 | void bt_self_component_port_input_notification_iterator_finalize( |
123 | struct bt_self_component_port_input_notification_iterator *iterator); | |
bd14d768 PP |
124 | |
125 | BT_HIDDEN | |
110ebe2b PP |
126 | void bt_self_component_port_input_notification_iterator_set_connection( |
127 | struct bt_self_component_port_input_notification_iterator *iterator, | |
bd14d768 PP |
128 | struct bt_connection *connection); |
129 | ||
a36bfb16 PP |
130 | static inline |
131 | const char *bt_notification_iterator_status_string( | |
132 | enum bt_notification_iterator_status status) | |
133 | { | |
134 | switch (status) { | |
135 | case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED: | |
136 | return "BT_NOTIFICATION_ITERATOR_STATUS_CANCELED"; | |
137 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: | |
138 | return "BT_NOTIFICATION_ITERATOR_STATUS_AGAIN"; | |
139 | case BT_NOTIFICATION_ITERATOR_STATUS_END: | |
140 | return "BT_NOTIFICATION_ITERATOR_STATUS_END"; | |
141 | case BT_NOTIFICATION_ITERATOR_STATUS_OK: | |
142 | return "BT_NOTIFICATION_ITERATOR_STATUS_OK"; | |
a36bfb16 PP |
143 | case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: |
144 | return "BT_NOTIFICATION_ITERATOR_STATUS_ERROR"; | |
145 | case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: | |
146 | return "BT_NOTIFICATION_ITERATOR_STATUS_NOMEM"; | |
a36bfb16 PP |
147 | default: |
148 | return "(unknown)"; | |
149 | } | |
150 | }; | |
151 | ||
8f9d7550 | 152 | static inline |
110ebe2b PP |
153 | const char *bt_self_component_port_input_notification_iterator_state_string( |
154 | enum bt_self_component_port_input_notification_iterator_state state) | |
8f9d7550 PP |
155 | { |
156 | switch (state) { | |
110ebe2b PP |
157 | case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE: |
158 | return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ACTIVE"; | |
159 | case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED: | |
160 | return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_ENDED"; | |
161 | case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED: | |
162 | return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED"; | |
163 | case BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED: | |
164 | return "BT_SELF_COMPONENT_PORT_INPUT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED"; | |
8f9d7550 PP |
165 | default: |
166 | return "(unknown)"; | |
167 | } | |
168 | }; | |
169 | ||
69985925 | 170 | #endif /* BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H */ |