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