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> | |
5c563278 | 36 | #include <babeltrace/graph/graph-internal.h> |
b2e0c907 | 37 | #include <babeltrace/graph/notification-packet-internal.h> |
f6ccaed9 PP |
38 | #include <babeltrace/assert-internal.h> |
39 | #include <babeltrace/assert-pre-internal.h> | |
6c677fb5 | 40 | #include <babeltrace/object-internal.h> |
dbff6338 | 41 | #include <inttypes.h> |
78586d8a | 42 | |
5c563278 PP |
43 | BT_HIDDEN |
44 | struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph) | |
78586d8a | 45 | { |
5c563278 | 46 | struct bt_notification_packet_begin *notification; |
78586d8a | 47 | |
5c563278 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 | |
5c563278 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 | |
5c563278 PP |
60 | error: |
61 | BT_PUT(notification); | |
62 | ||
63 | end: | |
64 | return (void *) notification; | |
78586d8a JG |
65 | } |
66 | ||
ea0e619e | 67 | struct bt_notification *bt_notification_packet_begin_create( |
5c563278 | 68 | struct bt_graph *graph, struct bt_packet *packet) |
78586d8a | 69 | { |
ea0e619e | 70 | struct bt_notification_packet_begin *notification; |
50842bdc PP |
71 | struct bt_stream *stream; |
72 | struct bt_stream_class *stream_class; | |
78586d8a | 73 | |
f6ccaed9 | 74 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 75 | stream = bt_packet_borrow_stream(packet); |
f6ccaed9 | 76 | BT_ASSERT(stream); |
3dca2276 | 77 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 78 | BT_ASSERT(stream_class); |
dbff6338 PP |
79 | BT_LOGD("Creating packet beginning notification object: " |
80 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
81 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
82 | "stream-class-id=%" PRId64, | |
50842bdc | 83 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 84 | stream_class, |
50842bdc PP |
85 | bt_stream_class_get_name(stream_class), |
86 | bt_stream_class_get_id(stream_class)); | |
5c563278 PP |
87 | notification = (void *) bt_notification_create_from_pool( |
88 | &graph->packet_begin_notif_pool, graph); | |
dbff6338 | 89 | if (!notification) { |
5c563278 | 90 | /* bt_notification_create_from_pool() logs errors */ |
6c677fb5 | 91 | goto end; |
dbff6338 PP |
92 | } |
93 | ||
6c677fb5 PP |
94 | BT_ASSERT(!notification->packet); |
95 | notification->packet = packet; | |
96 | bt_object_get_no_null_check_no_parent_check( | |
97 | ¬ification->packet->base); | |
dbff6338 PP |
98 | BT_LOGD("Created packet beginning notification object: " |
99 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
100 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
101 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 102 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 103 | stream_class, |
50842bdc PP |
104 | bt_stream_class_get_name(stream_class), |
105 | bt_stream_class_get_id(stream_class), notification); | |
5c563278 PP |
106 | goto end; |
107 | ||
5c563278 PP |
108 | end: |
109 | return (void *) notification; | |
110 | } | |
111 | ||
112 | BT_HIDDEN | |
113 | void bt_notification_packet_begin_destroy(struct bt_notification *notif) | |
114 | { | |
115 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
116 | ||
117 | BT_LOGD("Destroying packet beginning notification: addr=%p", notif); | |
118 | BT_LOGD_STR("Putting packet."); | |
119 | BT_PUT(packet_begin_notif->packet); | |
120 | g_free(notif); | |
121 | } | |
122 | ||
123 | BT_HIDDEN | |
124 | void bt_notification_packet_begin_recycle(struct bt_notification *notif) | |
125 | { | |
126 | struct bt_notification_packet_begin *packet_begin_notif = (void *) notif; | |
127 | struct bt_graph *graph; | |
128 | ||
129 | BT_ASSERT(packet_begin_notif); | |
130 | ||
6c677fb5 | 131 | if (unlikely(!notif->graph)) { |
5c563278 PP |
132 | bt_notification_packet_begin_destroy(notif); |
133 | return; | |
134 | } | |
135 | ||
136 | BT_LOGD("Recycling packet beginning notification: addr=%p", notif); | |
137 | bt_notification_reset(notif); | |
6c677fb5 PP |
138 | bt_object_put_no_null_check(&packet_begin_notif->packet->base); |
139 | packet_begin_notif->packet = NULL; | |
5c563278 PP |
140 | graph = notif->graph; |
141 | notif->graph = NULL; | |
142 | bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif); | |
78586d8a JG |
143 | } |
144 | ||
094ff7c0 | 145 | struct bt_packet *bt_notification_packet_begin_borrow_packet( |
78586d8a JG |
146 | struct bt_notification *notification) |
147 | { | |
ea0e619e | 148 | struct bt_notification_packet_begin *packet_begin; |
78586d8a | 149 | |
f6ccaed9 PP |
150 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
151 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
152 | BT_NOTIFICATION_TYPE_PACKET_BEGIN); | |
ea0e619e JG |
153 | packet_begin = container_of(notification, |
154 | struct bt_notification_packet_begin, parent); | |
094ff7c0 | 155 | return packet_begin->packet; |
78586d8a JG |
156 | } |
157 | ||
5c563278 PP |
158 | BT_HIDDEN |
159 | struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) | |
160 | { | |
161 | struct bt_notification_packet_end *notification; | |
162 | ||
163 | notification = g_new0(struct bt_notification_packet_end, 1); | |
164 | if (!notification) { | |
165 | BT_LOGE_STR("Failed to allocate one packet end notification."); | |
166 | goto error; | |
167 | } | |
168 | ||
169 | bt_notification_init(¬ification->parent, | |
170 | BT_NOTIFICATION_TYPE_PACKET_END, | |
171 | (bt_object_release_func) bt_notification_packet_end_recycle, | |
172 | graph); | |
173 | goto end; | |
174 | ||
175 | error: | |
176 | BT_PUT(notification); | |
177 | ||
178 | end: | |
179 | return (void *) notification; | |
180 | } | |
181 | ||
78586d8a | 182 | struct bt_notification *bt_notification_packet_end_create( |
5c563278 | 183 | struct bt_graph *graph, struct bt_packet *packet) |
78586d8a JG |
184 | { |
185 | struct bt_notification_packet_end *notification; | |
50842bdc PP |
186 | struct bt_stream *stream; |
187 | struct bt_stream_class *stream_class; | |
78586d8a | 188 | |
f6ccaed9 | 189 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 190 | stream = bt_packet_borrow_stream(packet); |
f6ccaed9 | 191 | BT_ASSERT(stream); |
3dca2276 | 192 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 193 | BT_ASSERT(stream_class); |
dbff6338 PP |
194 | BT_LOGD("Creating packet end notification object: " |
195 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
196 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
197 | "stream-class-id=%" PRId64, | |
50842bdc | 198 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 199 | stream_class, |
50842bdc PP |
200 | bt_stream_class_get_name(stream_class), |
201 | bt_stream_class_get_id(stream_class)); | |
5c563278 PP |
202 | notification = (void *) bt_notification_create_from_pool( |
203 | &graph->packet_end_notif_pool, graph); | |
dbff6338 | 204 | if (!notification) { |
5c563278 | 205 | /* bt_notification_create_from_pool() logs errors */ |
6c677fb5 | 206 | goto end; |
dbff6338 PP |
207 | } |
208 | ||
6c677fb5 PP |
209 | BT_ASSERT(!notification->packet); |
210 | notification->packet = packet; | |
211 | bt_object_get_no_null_check_no_parent_check( | |
212 | ¬ification->packet->base); | |
dbff6338 PP |
213 | BT_LOGD("Created packet end notification object: " |
214 | "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", " | |
215 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
216 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 217 | packet, stream, bt_stream_get_name(stream), |
dbff6338 | 218 | stream_class, |
50842bdc PP |
219 | bt_stream_class_get_name(stream_class), |
220 | bt_stream_class_get_id(stream_class), notification); | |
5c563278 PP |
221 | goto end; |
222 | ||
5c563278 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 | ||
232 | BT_LOGD("Destroying packet end notification: addr=%p", notif); | |
233 | BT_LOGD_STR("Putting packet."); | |
234 | BT_PUT(packet_end_notif->packet); | |
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 | ||
251 | BT_LOGD("Recycling packet end notification: addr=%p", notif); | |
252 | bt_notification_reset(notif); | |
253 | BT_PUT(packet_end_notif->packet); | |
254 | graph = notif->graph; | |
255 | notif->graph = NULL; | |
256 | bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); | |
78586d8a JG |
257 | } |
258 | ||
094ff7c0 | 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 | ||
f6ccaed9 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); | |
094ff7c0 | 269 | return packet_end->packet; |
78586d8a | 270 | } |