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> |
0d72b8c3 PP |
35 | #include <babeltrace/graph/notification-packet-const.h> |
36 | #include <babeltrace/graph/notification-packet.h> | |
b2e0c907 | 37 | #include <babeltrace/graph/notification-packet-internal.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 | ||
0d72b8c3 | 68 | struct bt_notification *bt_notification_packet_begin_create( |
d94d92ac | 69 | struct bt_self_notification_iterator *self_notif_iter, |
40f4ba76 | 70 | struct bt_packet *packet) |
78586d8a | 71 | { |
d94d92ac PP |
72 | struct bt_self_component_port_input_notification_iterator *notif_iter = |
73 | (void *) self_notif_iter; | |
ccf82993 | 74 | struct bt_notification_packet_begin *notification = NULL; |
50842bdc PP |
75 | struct bt_stream *stream; |
76 | struct bt_stream_class *stream_class; | |
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); |
d94d92ac PP |
84 | BT_LIB_LOGD("Creating packet beginning notification object: " |
85 | "%![packet-]+a, %![stream-]+s, %![sc-]+S", | |
86 | packet, stream, stream_class); | |
5c563278 | 87 | notification = (void *) bt_notification_create_from_pool( |
d94d92ac | 88 | ¬if_iter->graph->packet_begin_notif_pool, notif_iter->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); | |
ccf82993 | 98 | bt_packet_set_is_frozen(packet, true); |
d94d92ac 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); | |
5c563278 PP |
102 | goto end; |
103 | ||
5c563278 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 | ||
d94d92ac PP |
113 | BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif); |
114 | BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif->packet); | |
65300d60 | 115 | BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet); |
5c563278 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 | ||
6c677fb5 | 127 | if (unlikely(!notif->graph)) { |
5c563278 PP |
128 | bt_notification_packet_begin_destroy(notif); |
129 | return; | |
130 | } | |
131 | ||
d94d92ac | 132 | BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif); |
5c563278 | 133 | bt_notification_reset(notif); |
6c677fb5 PP |
134 | bt_object_put_no_null_check(&packet_begin_notif->packet->base); |
135 | packet_begin_notif->packet = NULL; | |
5c563278 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 | ||
0d72b8c3 PP |
141 | struct bt_packet *bt_notification_packet_begin_borrow_packet( |
142 | struct bt_notification *notification) | |
78586d8a | 143 | { |
ea0e619e | 144 | struct bt_notification_packet_begin *packet_begin; |
78586d8a | 145 | |
f6ccaed9 PP |
146 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
147 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
148 | BT_NOTIFICATION_TYPE_PACKET_BEGIN); | |
40f4ba76 | 149 | packet_begin = (void *) notification; |
094ff7c0 | 150 | return packet_begin->packet; |
78586d8a JG |
151 | } |
152 | ||
0d72b8c3 PP |
153 | const struct bt_packet *bt_notification_packet_begin_borrow_packet_const( |
154 | const struct bt_notification *notification) | |
e5be10ef | 155 | { |
0d72b8c3 | 156 | return bt_notification_packet_begin_borrow_packet( |
e5be10ef PP |
157 | (void *) notification); |
158 | } | |
159 | ||
5c563278 PP |
160 | BT_HIDDEN |
161 | struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph) | |
162 | { | |
163 | struct bt_notification_packet_end *notification; | |
164 | ||
165 | notification = g_new0(struct bt_notification_packet_end, 1); | |
166 | if (!notification) { | |
167 | BT_LOGE_STR("Failed to allocate one packet end notification."); | |
168 | goto error; | |
169 | } | |
170 | ||
171 | bt_notification_init(¬ification->parent, | |
172 | BT_NOTIFICATION_TYPE_PACKET_END, | |
173 | (bt_object_release_func) bt_notification_packet_end_recycle, | |
174 | graph); | |
175 | goto end; | |
176 | ||
177 | error: | |
65300d60 | 178 | BT_OBJECT_PUT_REF_AND_RESET(notification); |
5c563278 PP |
179 | |
180 | end: | |
181 | return (void *) notification; | |
182 | } | |
183 | ||
0d72b8c3 | 184 | struct bt_notification *bt_notification_packet_end_create( |
d94d92ac | 185 | struct bt_self_notification_iterator *self_notif_iter, |
40f4ba76 | 186 | struct bt_packet *packet) |
78586d8a | 187 | { |
d94d92ac PP |
188 | struct bt_self_component_port_input_notification_iterator *notif_iter = |
189 | (void *) self_notif_iter; | |
ccf82993 | 190 | struct bt_notification_packet_end *notification = NULL; |
50842bdc PP |
191 | struct bt_stream *stream; |
192 | struct bt_stream_class *stream_class; | |
78586d8a | 193 | |
f0010051 | 194 | BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator"); |
f6ccaed9 | 195 | BT_ASSERT_PRE_NON_NULL(packet, "Packet"); |
50842bdc | 196 | stream = bt_packet_borrow_stream(packet); |
f6ccaed9 | 197 | BT_ASSERT(stream); |
3dca2276 | 198 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 199 | BT_ASSERT(stream_class); |
d94d92ac PP |
200 | BT_LIB_LOGD("Creating packet end notification object: " |
201 | "%![packet-]+a, %![stream-]+s, %![sc-]+S", | |
202 | packet, stream, stream_class); | |
5c563278 | 203 | notification = (void *) bt_notification_create_from_pool( |
d94d92ac | 204 | ¬if_iter->graph->packet_end_notif_pool, notif_iter->graph); |
dbff6338 | 205 | if (!notification) { |
5c563278 | 206 | /* bt_notification_create_from_pool() logs errors */ |
6c677fb5 | 207 | goto end; |
dbff6338 PP |
208 | } |
209 | ||
6c677fb5 PP |
210 | BT_ASSERT(!notification->packet); |
211 | notification->packet = packet; | |
212 | bt_object_get_no_null_check_no_parent_check( | |
213 | ¬ification->packet->base); | |
ccf82993 | 214 | bt_packet_set_is_frozen(packet, true); |
d94d92ac PP |
215 | BT_LIB_LOGD("Created packet end notification object: " |
216 | "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S", | |
217 | notification, packet, stream, stream_class); | |
5c563278 PP |
218 | goto end; |
219 | ||
5c563278 PP |
220 | end: |
221 | return (void *) notification; | |
222 | } | |
223 | ||
224 | BT_HIDDEN | |
225 | void bt_notification_packet_end_destroy(struct bt_notification *notif) | |
226 | { | |
227 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
228 | ||
d94d92ac PP |
229 | BT_LIB_LOGD("Destroying packet end notification: %!+n", notif); |
230 | BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif->packet); | |
65300d60 | 231 | BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); |
5c563278 PP |
232 | g_free(notif); |
233 | } | |
234 | ||
235 | BT_HIDDEN | |
236 | void bt_notification_packet_end_recycle(struct bt_notification *notif) | |
237 | { | |
238 | struct bt_notification_packet_end *packet_end_notif = (void *) notif; | |
239 | struct bt_graph *graph; | |
240 | ||
241 | BT_ASSERT(packet_end_notif); | |
242 | ||
243 | if (!notif->graph) { | |
244 | bt_notification_packet_end_destroy(notif); | |
245 | return; | |
246 | } | |
247 | ||
d94d92ac | 248 | BT_LIB_LOGD("Recycling packet end notification: %!+n", notif); |
5c563278 | 249 | bt_notification_reset(notif); |
65300d60 | 250 | BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet); |
5c563278 PP |
251 | graph = notif->graph; |
252 | notif->graph = NULL; | |
253 | bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif); | |
78586d8a JG |
254 | } |
255 | ||
0d72b8c3 PP |
256 | struct bt_packet *bt_notification_packet_end_borrow_packet( |
257 | struct bt_notification *notification) | |
78586d8a JG |
258 | { |
259 | struct bt_notification_packet_end *packet_end; | |
260 | ||
f6ccaed9 PP |
261 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
262 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
263 | BT_NOTIFICATION_TYPE_PACKET_END); | |
40f4ba76 | 264 | packet_end = (void *) notification; |
094ff7c0 | 265 | return packet_end->packet; |
78586d8a | 266 | } |
e5be10ef | 267 | |
0d72b8c3 PP |
268 | const struct bt_packet *bt_notification_packet_end_borrow_packet_const( |
269 | const struct bt_notification *notification) | |
e5be10ef | 270 | { |
0d72b8c3 | 271 | return bt_notification_packet_end_borrow_packet( |
e5be10ef PP |
272 | (void *) notification); |
273 | } |