Commit | Line | Data |
---|---|---|
78586d8a | 1 | /* |
78586d8a JG |
2 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
3 | * | |
4 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
22 | * SOFTWARE. | |
23 | */ | |
24 | ||
dbff6338 PP |
25 | #define BT_LOG_TAG "NOTIF-PACKET" |
26 | #include <babeltrace/lib-logging-internal.h> | |
27 | ||
3d9990ac | 28 | #include <babeltrace/compiler-internal.h> |
061831e1 PP |
29 | #include <babeltrace/trace-ir/packet.h> |
30 | #include <babeltrace/trace-ir/packet-internal.h> | |
31 | #include <babeltrace/trace-ir/stream-class.h> | |
32 | #include <babeltrace/trace-ir/stream.h> | |
33 | #include <babeltrace/trace-ir/stream-internal.h> | |
ecb2b2fe | 34 | #include <babeltrace/graph/graph-internal.h> |
af5863fc | 35 | #include <babeltrace/graph/private-notification-packet.h> |
b2e0c907 | 36 | #include <babeltrace/graph/notification-packet-internal.h> |
af5863fc | 37 | #include <babeltrace/object.h> |
1d2f35fd PP |
38 | #include <babeltrace/assert-internal.h> |
39 | #include <babeltrace/assert-pre-internal.h> | |
2259462c | 40 | #include <babeltrace/object-internal.h> |
dbff6338 | 41 | #include <inttypes.h> |
78586d8a | 42 | |
ecb2b2fe PP |
43 | BT_HIDDEN |
44 | struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph) | |
78586d8a | 45 | { |
ecb2b2fe | 46 | struct bt_notification_packet_begin *notification; |
78586d8a | 47 | |
ecb2b2fe PP |
48 | notification = g_new0(struct bt_notification_packet_begin, 1); |
49 | if (!notification) { | |
50 | BT_LOGE_STR("Failed to allocate one packet beginning notification."); | |
51 | goto error; | |
52 | } | |
78586d8a | 53 | |
ecb2b2fe PP |
54 | bt_notification_init(¬ification->parent, |
55 | BT_NOTIFICATION_TYPE_PACKET_BEGIN, | |
56 | (bt_object_release_func) bt_notification_packet_begin_recycle, | |
57 | graph); | |
58 | goto end; | |
78586d8a | 59 | |
ecb2b2fe | 60 | error: |
6f998913 | 61 | BT_OBJECT_PUT_REF_AND_RESET(notification); |
ecb2b2fe PP |
62 | |
63 | end: | |
64 | return (void *) notification; | |
78586d8a JG |
65 | } |
66 | ||
af5863fc | 67 | struct bt_private_notification *bt_private_notification_packet_begin_create( |
110ebe2b | 68 | struct bt_self_notification_iterator *self_notif_iter, |
af5863fc | 69 | struct bt_private_packet *priv_packet) |
78586d8a | 70 | { |
110ebe2b PP |
71 | struct bt_self_component_port_input_notification_iterator *notif_iter = |
72 | (void *) self_notif_iter; | |
af5863fc | 73 | struct bt_packet *packet = (void *) priv_packet; |
333b001e | 74 | struct bt_notification_packet_begin *notification = NULL; |
50842bdc PP |
75 | struct bt_stream *stream; |
76 | struct bt_stream_class *stream_class; | |
78586d8a | 77 | |
8eda4bcb | 78 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
1d2f35fd | 79 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 80 | stream = bt_packet_borrow_stream(packet); |
1d2f35fd | 81 | BT_ASSERT(stream); |
d6b8c7f1 | 82 | stream_class = bt_stream_borrow_class(stream); |
1d2f35fd | 83 | BT_ASSERT(stream_class); |
110ebe2b PP |
84 | BT_LIB_LOGD("Creating packet beginning notification object: " |
85 | "%![packet-]+a, %![stream-]+s, %![sc-]+S", | |
86 | packet, stream, stream_class); | |
ecb2b2fe | 87 | notification = (void *) bt_notification_create_from_pool( |
110ebe2b | 88 | ¬if_iter->graph->packet_begin_notif_pool, notif_iter->graph); |
dbff6338 | 89 | if (!notification) { |
ecb2b2fe | 90 | /* bt_notification_create_from_pool() logs errors */ |
2259462c | 91 | goto end; |
dbff6338 PP |
92 | } |
93 | ||
2259462c PP |
94 | BT_ASSERT(!notification->packet); |
95 | notification->packet = packet; | |
96 | bt_object_get_no_null_check_no_parent_check( | |
97 | ¬ification->packet->base); | |
333b001e | 98 | bt_packet_set_is_frozen(packet, true); |
110ebe2b PP |
99 | BT_LIB_LOGD("Created packet beginning notification object: " |
100 | "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S", | |
101 | notification, packet, stream, stream_class); | |
ecb2b2fe PP |
102 | goto end; |
103 | ||
ecb2b2fe PP |
104 | end: |
105 | return (void *) notification; | |
106 | } | |
107 | ||
108 | BT_HIDDEN | |
109 | void bt_notification_packet_begin_destroy(struct bt_notification *notif) | |
110 | { | |
111 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
112 | ||
110ebe2b PP |
113 | BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif); |
114 | BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif->packet); | |
6f998913 | 115 | BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet); |
ecb2b2fe PP |
116 | g_free(notif); |
117 | } | |
118 | ||
119 | BT_HIDDEN | |
120 | void bt_notification_packet_begin_recycle(struct bt_notification *notif) | |
121 | { | |
122 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
123 | struct bt_graph *graph; | |
124 | ||
125 | BT_ASSERT(packet_begin_notif); | |
126 | ||
2259462c | 127 | if (unlikely(!notif->graph)) { |
ecb2b2fe PP |
128 | bt_notification_packet_begin_destroy(notif); |
129 | return; | |
130 | } | |
131 | ||
110ebe2b | 132 | BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif); |
ecb2b2fe | 133 | bt_notification_reset(notif); |
2259462c PP |
134 | bt_object_put_no_null_check(&packet_begin_notif->packet->base); |
135 | packet_begin_notif->packet = NULL; | |
ecb2b2fe PP |
136 | graph = notif->graph; |
137 | notif->graph = NULL; | |
138 | bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif); | |
78586d8a JG |
139 | } |
140 | ||
9a844f3c | 141 | struct bt_packet *bt_notification_packet_begin_borrow_packet( |
78586d8a JG |
142 | struct bt_notification *notification) |
143 | { | |
ea0e619e | 144 | struct bt_notification_packet_begin *packet_begin; |
78586d8a | 145 | |
1d2f35fd PP |
146 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
147 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
148 | BT_NOTIFICATION_TYPE_PACKET_BEGIN); | |
ea0e619e JG |
149 | packet_begin = container_of(notification, |
150 | struct bt_notification_packet_begin, parent); | |
9a844f3c | 151 | return packet_begin->packet; |
78586d8a JG |
152 | } |
153 | ||
af5863fc | 154 | struct bt_private_packet * |
7160adc1 | 155 | bt_private_notification_packet_begin_borrow_packet( |
af5863fc PP |
156 | struct bt_private_notification *notification) |
157 | { | |
158 | return (void *) bt_notification_packet_begin_borrow_packet( | |
159 | (void *) notification); | |
160 | } | |
161 | ||
ecb2b2fe PP |
162 | BT_HIDDEN |
163 | struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) | |
164 | { | |
165 | struct bt_notification_packet_end *notification; | |
166 | ||
167 | notification = g_new0(struct bt_notification_packet_end, 1); | |
168 | if (!notification) { | |
169 | BT_LOGE_STR("Failed to allocate one packet end notification."); | |
170 | goto error; | |
171 | } | |
172 | ||
173 | bt_notification_init(¬ification->parent, | |
174 | BT_NOTIFICATION_TYPE_PACKET_END, | |
175 | (bt_object_release_func) bt_notification_packet_end_recycle, | |
176 | graph); | |
177 | goto end; | |
178 | ||
179 | error: | |
6f998913 | 180 | BT_OBJECT_PUT_REF_AND_RESET(notification); |
ecb2b2fe PP |
181 | |
182 | end: | |
183 | return (void *) notification; | |
184 | } | |
185 | ||
af5863fc | 186 | struct bt_private_notification *bt_private_notification_packet_end_create( |
110ebe2b | 187 | struct bt_self_notification_iterator *self_notif_iter, |
af5863fc | 188 | struct bt_private_packet *priv_packet) |
78586d8a | 189 | { |
110ebe2b PP |
190 | struct bt_self_component_port_input_notification_iterator *notif_iter = |
191 | (void *) self_notif_iter; | |
af5863fc | 192 | struct bt_packet *packet = (void *) priv_packet; |
333b001e | 193 | struct bt_notification_packet_end *notification = NULL; |
50842bdc PP |
194 | struct bt_stream *stream; |
195 | struct bt_stream_class *stream_class; | |
78586d8a | 196 | |
8eda4bcb | 197 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
1d2f35fd | 198 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 199 | stream = bt_packet_borrow_stream(packet); |
1d2f35fd | 200 | BT_ASSERT(stream); |
d6b8c7f1 | 201 | stream_class = bt_stream_borrow_class(stream); |
1d2f35fd | 202 | BT_ASSERT(stream_class); |
110ebe2b PP |
203 | BT_LIB_LOGD("Creating packet end notification object: " |
204 | "%![packet-]+a, %![stream-]+s, %![sc-]+S", | |
205 | packet, stream, stream_class); | |
ecb2b2fe | 206 | notification = (void *) bt_notification_create_from_pool( |
110ebe2b | 207 | ¬if_iter->graph->packet_end_notif_pool, notif_iter->graph); |
dbff6338 | 208 | if (!notification) { |
ecb2b2fe | 209 | /* bt_notification_create_from_pool() logs errors */ |
2259462c | 210 | goto end; |
dbff6338 PP |
211 | } |
212 | ||
2259462c PP |
213 | BT_ASSERT(!notification->packet); |
214 | notification->packet = packet; | |
215 | bt_object_get_no_null_check_no_parent_check( | |
216 | ¬ification->packet->base); | |
333b001e | 217 | bt_packet_set_is_frozen(packet, true); |
110ebe2b PP |
218 | BT_LIB_LOGD("Created packet end notification object: " |
219 | "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S", | |
220 | notification, packet, stream, stream_class); | |
ecb2b2fe PP |
221 | goto end; |
222 | ||
ecb2b2fe PP |
223 | end: |
224 | return (void *) notification; | |
225 | } | |
226 | ||
227 | BT_HIDDEN | |
228 | void bt_notification_packet_end_destroy(struct bt_notification *notif) | |
229 | { | |
230 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
231 | ||
110ebe2b PP |
232 | BT_LIB_LOGD("Destroying packet end notification: %!+n", notif); |
233 | BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif->packet); | |
6f998913 | 234 | BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); |
ecb2b2fe PP |
235 | g_free(notif); |
236 | } | |
237 | ||
238 | BT_HIDDEN | |
239 | void bt_notification_packet_end_recycle(struct bt_notification *notif) | |
240 | { | |
241 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
242 | struct bt_graph *graph; | |
243 | ||
244 | BT_ASSERT(packet_end_notif); | |
245 | ||
246 | if (!notif->graph) { | |
247 | bt_notification_packet_end_destroy(notif); | |
248 | return; | |
249 | } | |
250 | ||
110ebe2b | 251 | BT_LIB_LOGD("Recycling packet end notification: %!+n", notif); |
ecb2b2fe | 252 | bt_notification_reset(notif); |
6f998913 | 253 | BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); |
ecb2b2fe PP |
254 | graph = notif->graph; |
255 | notif->graph = NULL; | |
256 | bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); | |
78586d8a JG |
257 | } |
258 | ||
9a844f3c | 259 | struct bt_packet *bt_notification_packet_end_borrow_packet( |
78586d8a JG |
260 | struct bt_notification *notification) |
261 | { | |
262 | struct bt_notification_packet_end *packet_end; | |
263 | ||
1d2f35fd PP |
264 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
265 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
266 | BT_NOTIFICATION_TYPE_PACKET_END); | |
78586d8a JG |
267 | packet_end = container_of(notification, |
268 | struct bt_notification_packet_end, parent); | |
9a844f3c | 269 | return packet_end->packet; |
78586d8a | 270 | } |
af5863fc PP |
271 | |
272 | struct bt_private_packet *bt_private_notification_packet_end_borrow_packet( | |
273 | struct bt_private_notification *notification) | |
274 | { | |
275 | return (void *) bt_notification_packet_end_borrow_packet( | |
276 | (void *) notification); | |
277 | } |