Commit | Line | Data |
---|---|---|
78586d8a JG |
1 | /* |
2 | * Babeltrace Plug-in Packet-related Notifications | |
3 | * | |
4 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
5 | * | |
6 | * Author: 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 | ||
dbff6338 PP |
27 | #define BT_LOG_TAG "NOTIF-PACKET" |
28 | #include <babeltrace/lib-logging-internal.h> | |
29 | ||
3d9990ac | 30 | #include <babeltrace/compiler-internal.h> |
dbff6338 PP |
31 | #include <babeltrace/ctf-ir/packet.h> |
32 | #include <babeltrace/ctf-ir/packet-internal.h> | |
9d408fca | 33 | #include <babeltrace/ctf-ir/stream-class.h> |
dbff6338 PP |
34 | #include <babeltrace/ctf-ir/stream.h> |
35 | #include <babeltrace/ctf-ir/stream-internal.h> | |
ecb2b2fe | 36 | #include <babeltrace/graph/graph-internal.h> |
b2e0c907 | 37 | #include <babeltrace/graph/notification-packet-internal.h> |
8eda4bcb | 38 | #include <babeltrace/graph/private-connection-private-notification-iterator.h> |
1d2f35fd PP |
39 | #include <babeltrace/assert-internal.h> |
40 | #include <babeltrace/assert-pre-internal.h> | |
2259462c | 41 | #include <babeltrace/object-internal.h> |
dbff6338 | 42 | #include <inttypes.h> |
78586d8a | 43 | |
ecb2b2fe PP |
44 | BT_HIDDEN |
45 | struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph) | |
78586d8a | 46 | { |
ecb2b2fe | 47 | struct bt_notification_packet_begin *notification; |
78586d8a | 48 | |
ecb2b2fe PP |
49 | notification = g_new0(struct bt_notification_packet_begin, 1); |
50 | if (!notification) { | |
51 | BT_LOGE_STR("Failed to allocate one packet beginning notification."); | |
52 | goto error; | |
53 | } | |
78586d8a | 54 | |
ecb2b2fe PP |
55 | bt_notification_init(¬ification->parent, |
56 | BT_NOTIFICATION_TYPE_PACKET_BEGIN, | |
57 | (bt_object_release_func) bt_notification_packet_begin_recycle, | |
58 | graph); | |
59 | goto end; | |
78586d8a | 60 | |
ecb2b2fe PP |
61 | error: |
62 | BT_PUT(notification); | |
63 | ||
64 | end: | |
65 | return (void *) notification; | |
78586d8a JG |
66 | } |
67 | ||
ea0e619e | 68 | struct bt_notification *bt_notification_packet_begin_create( |
8eda4bcb PP |
69 | struct bt_private_connection_private_notification_iterator *notif_iter, |
70 | struct bt_packet *packet) | |
78586d8a | 71 | { |
ea0e619e | 72 | struct bt_notification_packet_begin *notification; |
50842bdc PP |
73 | struct bt_stream *stream; |
74 | struct bt_stream_class *stream_class; | |
8eda4bcb | 75 | struct bt_graph *graph; |
78586d8a | 76 | |
8eda4bcb | 77 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
1d2f35fd | 78 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 79 | stream = bt_packet_borrow_stream(packet); |
1d2f35fd | 80 | BT_ASSERT(stream); |
d6b8c7f1 | 81 | stream_class = bt_stream_borrow_class(stream); |
1d2f35fd | 82 | BT_ASSERT(stream_class); |
dbff6338 PP |
83 | BT_LOGD("Creating packet beginning notification object: " |
84 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
85 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
86 | "stream-class-id=%" PRId64, | |
50842bdc | 87 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 88 | stream_class, |
50842bdc PP |
89 | bt_stream_class_get_name(stream_class), |
90 | bt_stream_class_get_id(stream_class)); | |
8eda4bcb PP |
91 | graph = bt_private_connection_private_notification_iterator_borrow_graph( |
92 | notif_iter); | |
ecb2b2fe PP |
93 | notification = (void *) bt_notification_create_from_pool( |
94 | &graph->packet_begin_notif_pool, graph); | |
dbff6338 | 95 | if (!notification) { |
ecb2b2fe | 96 | /* bt_notification_create_from_pool() logs errors */ |
2259462c | 97 | goto end; |
dbff6338 PP |
98 | } |
99 | ||
2259462c PP |
100 | BT_ASSERT(!notification->packet); |
101 | notification->packet = packet; | |
102 | bt_object_get_no_null_check_no_parent_check( | |
103 | ¬ification->packet->base); | |
dbff6338 PP |
104 | BT_LOGD("Created packet beginning notification object: " |
105 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
106 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
107 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 108 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 109 | stream_class, |
50842bdc PP |
110 | bt_stream_class_get_name(stream_class), |
111 | bt_stream_class_get_id(stream_class), notification); | |
ecb2b2fe PP |
112 | goto end; |
113 | ||
ecb2b2fe PP |
114 | end: |
115 | return (void *) notification; | |
116 | } | |
117 | ||
118 | BT_HIDDEN | |
119 | void bt_notification_packet_begin_destroy(struct bt_notification *notif) | |
120 | { | |
121 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
122 | ||
123 | BT_LOGD("Destroying packet beginning notification: addr=%p", notif); | |
124 | BT_LOGD_STR("Putting packet."); | |
125 | BT_PUT(packet_begin_notif->packet); | |
126 | g_free(notif); | |
127 | } | |
128 | ||
129 | BT_HIDDEN | |
130 | void bt_notification_packet_begin_recycle(struct bt_notification *notif) | |
131 | { | |
132 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
133 | struct bt_graph *graph; | |
134 | ||
135 | BT_ASSERT(packet_begin_notif); | |
136 | ||
2259462c | 137 | if (unlikely(!notif->graph)) { |
ecb2b2fe PP |
138 | bt_notification_packet_begin_destroy(notif); |
139 | return; | |
140 | } | |
141 | ||
142 | BT_LOGD("Recycling packet beginning notification: addr=%p", notif); | |
143 | bt_notification_reset(notif); | |
2259462c PP |
144 | bt_object_put_no_null_check(&packet_begin_notif->packet->base); |
145 | packet_begin_notif->packet = NULL; | |
ecb2b2fe PP |
146 | graph = notif->graph; |
147 | notif->graph = NULL; | |
148 | bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif); | |
78586d8a JG |
149 | } |
150 | ||
9a844f3c | 151 | struct bt_packet *bt_notification_packet_begin_borrow_packet( |
78586d8a JG |
152 | struct bt_notification *notification) |
153 | { | |
ea0e619e | 154 | struct bt_notification_packet_begin *packet_begin; |
78586d8a | 155 | |
1d2f35fd PP |
156 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
157 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
158 | BT_NOTIFICATION_TYPE_PACKET_BEGIN); | |
ea0e619e JG |
159 | packet_begin = container_of(notification, |
160 | struct bt_notification_packet_begin, parent); | |
9a844f3c | 161 | return packet_begin->packet; |
78586d8a JG |
162 | } |
163 | ||
ecb2b2fe PP |
164 | BT_HIDDEN |
165 | struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) | |
166 | { | |
167 | struct bt_notification_packet_end *notification; | |
168 | ||
169 | notification = g_new0(struct bt_notification_packet_end, 1); | |
170 | if (!notification) { | |
171 | BT_LOGE_STR("Failed to allocate one packet end notification."); | |
172 | goto error; | |
173 | } | |
174 | ||
175 | bt_notification_init(¬ification->parent, | |
176 | BT_NOTIFICATION_TYPE_PACKET_END, | |
177 | (bt_object_release_func) bt_notification_packet_end_recycle, | |
178 | graph); | |
179 | goto end; | |
180 | ||
181 | error: | |
182 | BT_PUT(notification); | |
183 | ||
184 | end: | |
185 | return (void *) notification; | |
186 | } | |
187 | ||
78586d8a | 188 | struct bt_notification *bt_notification_packet_end_create( |
8eda4bcb PP |
189 | struct bt_private_connection_private_notification_iterator *notif_iter, |
190 | struct bt_packet *packet) | |
78586d8a JG |
191 | { |
192 | struct bt_notification_packet_end *notification; | |
50842bdc PP |
193 | struct bt_stream *stream; |
194 | struct bt_stream_class *stream_class; | |
8eda4bcb | 195 | struct bt_graph *graph; |
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); |
dbff6338 PP |
203 | BT_LOGD("Creating packet end notification object: " |
204 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
205 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
206 | "stream-class-id=%" PRId64, | |
50842bdc | 207 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 208 | stream_class, |
50842bdc PP |
209 | bt_stream_class_get_name(stream_class), |
210 | bt_stream_class_get_id(stream_class)); | |
8eda4bcb PP |
211 | graph = bt_private_connection_private_notification_iterator_borrow_graph( |
212 | notif_iter); | |
ecb2b2fe PP |
213 | notification = (void *) bt_notification_create_from_pool( |
214 | &graph->packet_end_notif_pool, graph); | |
dbff6338 | 215 | if (!notification) { |
ecb2b2fe | 216 | /* bt_notification_create_from_pool() logs errors */ |
2259462c | 217 | goto end; |
dbff6338 PP |
218 | } |
219 | ||
2259462c PP |
220 | BT_ASSERT(!notification->packet); |
221 | notification->packet = packet; | |
222 | bt_object_get_no_null_check_no_parent_check( | |
223 | ¬ification->packet->base); | |
dbff6338 PP |
224 | BT_LOGD("Created packet end notification object: " |
225 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
226 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
227 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 228 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 229 | stream_class, |
50842bdc PP |
230 | bt_stream_class_get_name(stream_class), |
231 | bt_stream_class_get_id(stream_class), notification); | |
ecb2b2fe PP |
232 | goto end; |
233 | ||
ecb2b2fe PP |
234 | end: |
235 | return (void *) notification; | |
236 | } | |
237 | ||
238 | BT_HIDDEN | |
239 | void bt_notification_packet_end_destroy(struct bt_notification *notif) | |
240 | { | |
241 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
242 | ||
243 | BT_LOGD("Destroying packet end notification: addr=%p", notif); | |
244 | BT_LOGD_STR("Putting packet."); | |
245 | BT_PUT(packet_end_notif->packet); | |
246 | g_free(notif); | |
247 | } | |
248 | ||
249 | BT_HIDDEN | |
250 | void bt_notification_packet_end_recycle(struct bt_notification *notif) | |
251 | { | |
252 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
253 | struct bt_graph *graph; | |
254 | ||
255 | BT_ASSERT(packet_end_notif); | |
256 | ||
257 | if (!notif->graph) { | |
258 | bt_notification_packet_end_destroy(notif); | |
259 | return; | |
260 | } | |
261 | ||
262 | BT_LOGD("Recycling packet end notification: addr=%p", notif); | |
263 | bt_notification_reset(notif); | |
264 | BT_PUT(packet_end_notif->packet); | |
265 | graph = notif->graph; | |
266 | notif->graph = NULL; | |
267 | bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); | |
78586d8a JG |
268 | } |
269 | ||
9a844f3c | 270 | struct bt_packet *bt_notification_packet_end_borrow_packet( |
78586d8a JG |
271 | struct bt_notification *notification) |
272 | { | |
273 | struct bt_notification_packet_end *packet_end; | |
274 | ||
1d2f35fd PP |
275 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
276 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
277 | BT_NOTIFICATION_TYPE_PACKET_END); | |
78586d8a JG |
278 | packet_end = container_of(notification, |
279 | struct bt_notification_packet_end, parent); | |
9a844f3c | 280 | return packet_end->packet; |
78586d8a | 281 | } |