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> |
56e18c4c 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> | |
5c563278 | 34 | #include <babeltrace/graph/graph-internal.h> |
e5be10ef | 35 | #include <babeltrace/graph/private-notification-packet.h> |
b2e0c907 | 36 | #include <babeltrace/graph/notification-packet-internal.h> |
f0010051 | 37 | #include <babeltrace/graph/private-connection-private-notification-iterator.h> |
e5be10ef | 38 | #include <babeltrace/object.h> |
f6ccaed9 PP |
39 | #include <babeltrace/assert-internal.h> |
40 | #include <babeltrace/assert-pre-internal.h> | |
6c677fb5 | 41 | #include <babeltrace/object-internal.h> |
dbff6338 | 42 | #include <inttypes.h> |
78586d8a | 43 | |
5c563278 PP |
44 | BT_HIDDEN |
45 | struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph) | |
78586d8a | 46 | { |
5c563278 | 47 | struct bt_notification_packet_begin *notification; |
78586d8a | 48 | |
5c563278 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 | |
5c563278 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 | |
5c563278 | 61 | error: |
65300d60 | 62 | BT_OBJECT_PUT_REF_AND_RESET(notification); |
5c563278 PP |
63 | |
64 | end: | |
65 | return (void *) notification; | |
78586d8a JG |
66 | } |
67 | ||
e5be10ef | 68 | struct bt_private_notification *bt_private_notification_packet_begin_create( |
f0010051 | 69 | struct bt_private_connection_private_notification_iterator *notif_iter, |
e5be10ef | 70 | struct bt_private_packet *priv_packet) |
78586d8a | 71 | { |
e5be10ef | 72 | struct bt_packet *packet = (void *) priv_packet; |
ccf82993 | 73 | struct bt_notification_packet_begin *notification = NULL; |
50842bdc PP |
74 | struct bt_stream *stream; |
75 | struct bt_stream_class *stream_class; | |
f0010051 | 76 | struct bt_graph *graph; |
78586d8a | 77 | |
f0010051 | 78 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
f6ccaed9 | 79 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 80 | stream = bt_packet_borrow_stream(packet); |
f6ccaed9 | 81 | BT_ASSERT(stream); |
3dca2276 | 82 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 83 | BT_ASSERT(stream_class); |
dbff6338 PP |
84 | BT_LOGD("Creating packet beginning notification object: " |
85 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
86 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
87 | "stream-class-id=%" PRId64, | |
50842bdc | 88 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 89 | stream_class, |
50842bdc PP |
90 | bt_stream_class_get_name(stream_class), |
91 | bt_stream_class_get_id(stream_class)); | |
f0010051 PP |
92 | graph = bt_private_connection_private_notification_iterator_borrow_graph( |
93 | notif_iter); | |
5c563278 PP |
94 | notification = (void *) bt_notification_create_from_pool( |
95 | &graph->packet_begin_notif_pool, graph); | |
dbff6338 | 96 | if (!notification) { |
5c563278 | 97 | /* bt_notification_create_from_pool() logs errors */ |
6c677fb5 | 98 | goto end; |
dbff6338 PP |
99 | } |
100 | ||
6c677fb5 PP |
101 | BT_ASSERT(!notification->packet); |
102 | notification->packet = packet; | |
103 | bt_object_get_no_null_check_no_parent_check( | |
104 | ¬ification->packet->base); | |
ccf82993 | 105 | bt_packet_set_is_frozen(packet, true); |
dbff6338 PP |
106 | BT_LOGD("Created packet beginning notification object: " |
107 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
108 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
109 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 110 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 111 | stream_class, |
50842bdc PP |
112 | bt_stream_class_get_name(stream_class), |
113 | bt_stream_class_get_id(stream_class), notification); | |
5c563278 PP |
114 | goto end; |
115 | ||
5c563278 PP |
116 | end: |
117 | return (void *) notification; | |
118 | } | |
119 | ||
120 | BT_HIDDEN | |
121 | void bt_notification_packet_begin_destroy(struct bt_notification *notif) | |
122 | { | |
123 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
124 | ||
125 | BT_LOGD("Destroying packet beginning notification: addr=%p", notif); | |
126 | BT_LOGD_STR("Putting packet."); | |
65300d60 | 127 | BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet); |
5c563278 PP |
128 | g_free(notif); |
129 | } | |
130 | ||
131 | BT_HIDDEN | |
132 | void bt_notification_packet_begin_recycle(struct bt_notification *notif) | |
133 | { | |
134 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
135 | struct bt_graph *graph; | |
136 | ||
137 | BT_ASSERT(packet_begin_notif); | |
138 | ||
6c677fb5 | 139 | if (unlikely(!notif->graph)) { |
5c563278 PP |
140 | bt_notification_packet_begin_destroy(notif); |
141 | return; | |
142 | } | |
143 | ||
144 | BT_LOGD("Recycling packet beginning notification: addr=%p", notif); | |
145 | bt_notification_reset(notif); | |
6c677fb5 PP |
146 | bt_object_put_no_null_check(&packet_begin_notif->packet->base); |
147 | packet_begin_notif->packet = NULL; | |
5c563278 PP |
148 | graph = notif->graph; |
149 | notif->graph = NULL; | |
150 | bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif); | |
78586d8a JG |
151 | } |
152 | ||
094ff7c0 | 153 | struct bt_packet *bt_notification_packet_begin_borrow_packet( |
78586d8a JG |
154 | struct bt_notification *notification) |
155 | { | |
ea0e619e | 156 | struct bt_notification_packet_begin *packet_begin; |
78586d8a | 157 | |
f6ccaed9 PP |
158 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
159 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
160 | BT_NOTIFICATION_TYPE_PACKET_BEGIN); | |
ea0e619e JG |
161 | packet_begin = container_of(notification, |
162 | struct bt_notification_packet_begin, parent); | |
094ff7c0 | 163 | return packet_begin->packet; |
78586d8a JG |
164 | } |
165 | ||
e5be10ef | 166 | struct bt_private_packet * |
28e6ca8b | 167 | bt_private_notification_packet_begin_borrow_packet( |
e5be10ef PP |
168 | struct bt_private_notification *notification) |
169 | { | |
170 | return (void *) bt_notification_packet_begin_borrow_packet( | |
171 | (void *) notification); | |
172 | } | |
173 | ||
5c563278 PP |
174 | BT_HIDDEN |
175 | struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) | |
176 | { | |
177 | struct bt_notification_packet_end *notification; | |
178 | ||
179 | notification = g_new0(struct bt_notification_packet_end, 1); | |
180 | if (!notification) { | |
181 | BT_LOGE_STR("Failed to allocate one packet end notification."); | |
182 | goto error; | |
183 | } | |
184 | ||
185 | bt_notification_init(¬ification->parent, | |
186 | BT_NOTIFICATION_TYPE_PACKET_END, | |
187 | (bt_object_release_func) bt_notification_packet_end_recycle, | |
188 | graph); | |
189 | goto end; | |
190 | ||
191 | error: | |
65300d60 | 192 | BT_OBJECT_PUT_REF_AND_RESET(notification); |
5c563278 PP |
193 | |
194 | end: | |
195 | return (void *) notification; | |
196 | } | |
197 | ||
e5be10ef | 198 | struct bt_private_notification *bt_private_notification_packet_end_create( |
f0010051 | 199 | struct bt_private_connection_private_notification_iterator *notif_iter, |
e5be10ef | 200 | struct bt_private_packet *priv_packet) |
78586d8a | 201 | { |
e5be10ef | 202 | struct bt_packet *packet = (void *) priv_packet; |
ccf82993 | 203 | struct bt_notification_packet_end *notification = NULL; |
50842bdc PP |
204 | struct bt_stream *stream; |
205 | struct bt_stream_class *stream_class; | |
f0010051 | 206 | struct bt_graph *graph; |
78586d8a | 207 | |
f0010051 | 208 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
f6ccaed9 | 209 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 210 | stream = bt_packet_borrow_stream(packet); |
f6ccaed9 | 211 | BT_ASSERT(stream); |
3dca2276 | 212 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 213 | BT_ASSERT(stream_class); |
dbff6338 PP |
214 | BT_LOGD("Creating packet end notification object: " |
215 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
216 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
217 | "stream-class-id=%" PRId64, | |
50842bdc | 218 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 219 | stream_class, |
50842bdc PP |
220 | bt_stream_class_get_name(stream_class), |
221 | bt_stream_class_get_id(stream_class)); | |
f0010051 PP |
222 | graph = bt_private_connection_private_notification_iterator_borrow_graph( |
223 | notif_iter); | |
5c563278 PP |
224 | notification = (void *) bt_notification_create_from_pool( |
225 | &graph->packet_end_notif_pool, graph); | |
dbff6338 | 226 | if (!notification) { |
5c563278 | 227 | /* bt_notification_create_from_pool() logs errors */ |
6c677fb5 | 228 | goto end; |
dbff6338 PP |
229 | } |
230 | ||
6c677fb5 PP |
231 | BT_ASSERT(!notification->packet); |
232 | notification->packet = packet; | |
233 | bt_object_get_no_null_check_no_parent_check( | |
234 | ¬ification->packet->base); | |
ccf82993 | 235 | bt_packet_set_is_frozen(packet, true); |
dbff6338 PP |
236 | BT_LOGD("Created packet end notification object: " |
237 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
238 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
239 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 240 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 241 | stream_class, |
50842bdc PP |
242 | bt_stream_class_get_name(stream_class), |
243 | bt_stream_class_get_id(stream_class), notification); | |
5c563278 PP |
244 | goto end; |
245 | ||
5c563278 PP |
246 | end: |
247 | return (void *) notification; | |
248 | } | |
249 | ||
250 | BT_HIDDEN | |
251 | void bt_notification_packet_end_destroy(struct bt_notification *notif) | |
252 | { | |
253 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
254 | ||
255 | BT_LOGD("Destroying packet end notification: addr=%p", notif); | |
256 | BT_LOGD_STR("Putting packet."); | |
65300d60 | 257 | BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); |
5c563278 PP |
258 | g_free(notif); |
259 | } | |
260 | ||
261 | BT_HIDDEN | |
262 | void bt_notification_packet_end_recycle(struct bt_notification *notif) | |
263 | { | |
264 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
265 | struct bt_graph *graph; | |
266 | ||
267 | BT_ASSERT(packet_end_notif); | |
268 | ||
269 | if (!notif->graph) { | |
270 | bt_notification_packet_end_destroy(notif); | |
271 | return; | |
272 | } | |
273 | ||
274 | BT_LOGD("Recycling packet end notification: addr=%p", notif); | |
275 | bt_notification_reset(notif); | |
65300d60 | 276 | BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); |
5c563278 PP |
277 | graph = notif->graph; |
278 | notif->graph = NULL; | |
279 | bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); | |
78586d8a JG |
280 | } |
281 | ||
094ff7c0 | 282 | struct bt_packet *bt_notification_packet_end_borrow_packet( |
78586d8a JG |
283 | struct bt_notification *notification) |
284 | { | |
285 | struct bt_notification_packet_end *packet_end; | |
286 | ||
f6ccaed9 PP |
287 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
288 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
289 | BT_NOTIFICATION_TYPE_PACKET_END); | |
78586d8a JG |
290 | packet_end = container_of(notification, |
291 | struct bt_notification_packet_end, parent); | |
094ff7c0 | 292 | return packet_end->packet; |
78586d8a | 293 | } |
e5be10ef PP |
294 | |
295 | struct bt_private_packet *bt_private_notification_packet_end_borrow_packet( | |
296 | struct bt_private_notification *notification) | |
297 | { | |
298 | return (void *) bt_notification_packet_end_borrow_packet( | |
299 | (void *) notification); | |
300 | } |