Commit | Line | Data |
---|---|---|
6ac74c0c PP |
1 | #ifndef BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H |
2 | #define BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H | |
47e5a032 JG |
3 | |
4 | /* | |
5 | * BabelTrace - Notification Iterator Internal | |
6 | * | |
7 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
3230ee6b | 8 | * Copyright 2017 Philippe Proulx <pproulx@efficios.com> |
47e5a032 JG |
9 | * |
10 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
11 | * of this software and associated documentation files (the "Software"), to deal | |
12 | * in the Software without restriction, including without limitation the rights | |
13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
14 | * copies of the Software, and to permit persons to whom the Software is | |
15 | * furnished to do so, subject to the following conditions: | |
16 | * | |
17 | * The above copyright notice and this permission notice shall be included in | |
18 | * all copies or substantial portions of the Software. | |
19 | * | |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
26 | * SOFTWARE. | |
27 | */ | |
28 | ||
29 | #include <babeltrace/babeltrace-internal.h> | |
890882ef | 30 | #include <babeltrace/object-internal.h> |
bd14d768 | 31 | #include <babeltrace/graph/connection.h> |
b2e0c907 PP |
32 | #include <babeltrace/graph/notification.h> |
33 | #include <babeltrace/graph/notification-iterator.h> | |
90157d89 | 34 | #include <babeltrace/graph/private-connection-private-notification-iterator.h> |
c55a9f58 | 35 | #include <babeltrace/types.h> |
f6ccaed9 | 36 | #include <babeltrace/assert-internal.h> |
088d4023 | 37 | #include <stdbool.h> |
47e5a032 | 38 | |
3230ee6b | 39 | struct bt_port; |
8ed535b5 | 40 | struct bt_graph; |
3230ee6b | 41 | |
90157d89 PP |
42 | enum bt_notification_iterator_type { |
43 | BT_NOTIFICATION_ITERATOR_TYPE_PRIVATE_CONNECTION, | |
8ed535b5 | 44 | BT_NOTIFICATION_ITERATOR_TYPE_OUTPUT_PORT, |
fa054faf PP |
45 | }; |
46 | ||
90157d89 PP |
47 | enum bt_private_connection_notification_iterator_notif_type { |
48 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_EVENT = (1U << 0), | |
49 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_INACTIVITY = (1U << 1), | |
50 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_BEGIN = (1U << 2), | |
51 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_STREAM_END = (1U << 3), | |
52 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_BEGIN = (1U << 4), | |
53 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_PACKET_END = (1U << 5), | |
54 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_DISCARDED_EVENTS = (1U << 6), | |
55 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_NOTIF_TYPE_DISCARDED_PACKETS = (1U << 7), | |
56 | }; | |
57 | ||
58 | enum bt_private_connection_notification_iterator_state { | |
088d4023 | 59 | /* Iterator is not initialized. */ |
90157d89 | 60 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_NON_INITIALIZED, |
088d4023 | 61 | |
bd14d768 | 62 | /* Iterator is active, not at the end yet, and not finalized. */ |
90157d89 | 63 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE, |
bd14d768 PP |
64 | |
65 | /* | |
66 | * Iterator is ended, not finalized yet: the "next" method | |
67 | * returns BT_NOTIFICATION_ITERATOR_STATUS_END. | |
68 | */ | |
90157d89 | 69 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED, |
bd14d768 PP |
70 | |
71 | /* | |
72 | * Iterator is finalized, but not at the end yet. This means | |
73 | * that the "next" method can still return queued notifications | |
74 | * before returning the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED | |
75 | * status. | |
76 | */ | |
90157d89 | 77 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED, |
bd14d768 PP |
78 | |
79 | /* | |
80 | * Iterator is finalized and ended: the "next" method always | |
81 | * returns BT_NOTIFICATION_ITERATOR_STATUS_CANCELED. | |
82 | */ | |
90157d89 | 83 | BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED, |
bd14d768 PP |
84 | }; |
85 | ||
47e5a032 | 86 | struct bt_notification_iterator { |
b8a06801 | 87 | struct bt_object base; |
90157d89 PP |
88 | enum bt_notification_iterator_type type; |
89 | }; | |
90 | ||
91 | struct bt_notification_iterator_private_connection { | |
92 | struct bt_notification_iterator base; | |
bd14d768 PP |
93 | struct bt_component *upstream_component; /* Weak */ |
94 | struct bt_port *upstream_port; /* Weak */ | |
95 | struct bt_connection *connection; /* Weak */ | |
5c563278 | 96 | struct bt_graph *graph; /* Weak */ |
3230ee6b PP |
97 | |
98 | /* | |
99 | * This hash table keeps the state of a stream as viewed by | |
f42867e2 PP |
100 | * this notification iterator. This is used to, in developer |
101 | * mode: | |
3230ee6b PP |
102 | * |
103 | * * Automatically enqueue "stream begin", "packet begin", | |
104 | * "packet end", and "stream end" notifications depending | |
105 | * on the stream's state and on the next notification returned | |
106 | * by the upstream component. | |
107 | * | |
f42867e2 PP |
108 | * * Make sure that, once the notification iterator has seen a |
109 | * "stream end" notification for a given stream, no other | |
110 | * notifications which refer to this stream can be delivered | |
111 | * by this iterator. | |
3230ee6b | 112 | * |
50842bdc | 113 | * The key (struct bt_stream *) is not owned by this. The |
3230ee6b PP |
114 | * value is an allocated state structure. |
115 | */ | |
116 | GHashTable *stream_states; | |
117 | ||
90157d89 | 118 | enum bt_private_connection_notification_iterator_state state; |
47e5a032 JG |
119 | void *user_data; |
120 | }; | |
121 | ||
8ed535b5 PP |
122 | struct bt_notification_iterator_output_port { |
123 | struct bt_notification_iterator base; | |
124 | struct bt_graph *graph; /* Owned by this */ | |
125 | struct bt_component *colander; /* Owned by this */ | |
8ed535b5 | 126 | |
07245ac2 PP |
127 | /* Only used temporarily: should always be NULL */ |
128 | struct bt_notification *notif; | |
129 | }; | |
8ed535b5 | 130 | |
890882ef | 131 | static inline |
90157d89 PP |
132 | struct bt_private_connection_private_notification_iterator * |
133 | bt_private_connection_private_notification_iterator_from_notification_iterator( | |
134 | struct bt_notification_iterator_private_connection *iterator) | |
890882ef | 135 | { |
90157d89 | 136 | return (void *) iterator; |
890882ef PP |
137 | } |
138 | ||
47e5a032 | 139 | BT_HIDDEN |
90157d89 | 140 | enum bt_connection_status bt_private_connection_notification_iterator_create( |
73d5c1ad | 141 | struct bt_component *upstream_comp, |
fa054faf | 142 | struct bt_port *upstream_port, |
73d5c1ad | 143 | struct bt_connection *connection, |
90157d89 | 144 | struct bt_notification_iterator_private_connection **iterator); |
47e5a032 | 145 | |
bd14d768 | 146 | BT_HIDDEN |
90157d89 PP |
147 | void bt_private_connection_notification_iterator_finalize( |
148 | struct bt_notification_iterator_private_connection *iterator); | |
bd14d768 PP |
149 | |
150 | BT_HIDDEN | |
90157d89 PP |
151 | void bt_private_connection_notification_iterator_set_connection( |
152 | struct bt_notification_iterator_private_connection *iterator, | |
bd14d768 PP |
153 | struct bt_connection *connection); |
154 | ||
a36bfb16 PP |
155 | static inline |
156 | const char *bt_notification_iterator_status_string( | |
157 | enum bt_notification_iterator_status status) | |
158 | { | |
159 | switch (status) { | |
160 | case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED: | |
161 | return "BT_NOTIFICATION_ITERATOR_STATUS_CANCELED"; | |
162 | case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN: | |
163 | return "BT_NOTIFICATION_ITERATOR_STATUS_AGAIN"; | |
164 | case BT_NOTIFICATION_ITERATOR_STATUS_END: | |
165 | return "BT_NOTIFICATION_ITERATOR_STATUS_END"; | |
166 | case BT_NOTIFICATION_ITERATOR_STATUS_OK: | |
167 | return "BT_NOTIFICATION_ITERATOR_STATUS_OK"; | |
168 | case BT_NOTIFICATION_ITERATOR_STATUS_INVALID: | |
169 | return "BT_NOTIFICATION_ITERATOR_STATUS_INVALID"; | |
170 | case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: | |
171 | return "BT_NOTIFICATION_ITERATOR_STATUS_ERROR"; | |
172 | case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM: | |
173 | return "BT_NOTIFICATION_ITERATOR_STATUS_NOMEM"; | |
174 | case BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED: | |
175 | return "BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED"; | |
176 | default: | |
177 | return "(unknown)"; | |
178 | } | |
179 | }; | |
180 | ||
8f9d7550 | 181 | static inline |
90157d89 PP |
182 | const char *bt_private_connection_notification_iterator_state_string( |
183 | enum bt_private_connection_notification_iterator_state state) | |
8f9d7550 PP |
184 | { |
185 | switch (state) { | |
90157d89 PP |
186 | case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE: |
187 | return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE"; | |
188 | case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED: | |
189 | return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ENDED"; | |
190 | case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED: | |
191 | return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED"; | |
192 | case BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED: | |
193 | return "BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED"; | |
8f9d7550 PP |
194 | default: |
195 | return "(unknown)"; | |
196 | } | |
197 | }; | |
198 | ||
6ac74c0c | 199 | #endif /* BABELTRACE_GRAPH_NOTIFICATION_ITERATOR_INTERNAL_H */ |