2 * Babeltrace Plug-in Packet-related Notifications
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
27 #define BT_LOG_TAG "NOTIF-PACKET"
28 #include <babeltrace/lib-logging-internal.h>
30 #include <babeltrace/compiler-internal.h>
31 #include <babeltrace/ctf-ir/packet.h>
32 #include <babeltrace/ctf-ir/packet-internal.h>
33 #include <babeltrace/ctf-ir/stream-class.h>
34 #include <babeltrace/ctf-ir/stream.h>
35 #include <babeltrace/ctf-ir/stream-internal.h>
36 #include <babeltrace/graph/graph-internal.h>
37 #include <babeltrace/graph/notification-packet-internal.h>
38 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
39 #include <babeltrace/assert-internal.h>
40 #include <babeltrace/assert-pre-internal.h>
41 #include <babeltrace/object-internal.h>
45 struct bt_notification
*bt_notification_packet_begin_new(struct bt_graph
*graph
)
47 struct bt_notification_packet_begin
*notification
;
49 notification
= g_new0(struct bt_notification_packet_begin
, 1);
51 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
55 bt_notification_init(¬ification
->parent
,
56 BT_NOTIFICATION_TYPE_PACKET_BEGIN
,
57 (bt_object_release_func
) bt_notification_packet_begin_recycle
,
65 return (void *) notification
;
68 struct bt_notification
*bt_notification_packet_begin_create(
69 struct bt_private_connection_private_notification_iterator
*notif_iter
,
70 struct bt_packet
*packet
)
72 struct bt_notification_packet_begin
*notification
= NULL
;
73 struct bt_stream
*stream
;
74 struct bt_stream_class
*stream_class
;
75 struct bt_graph
*graph
;
78 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
79 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
80 stream
= bt_packet_borrow_stream(packet
);
82 stream_class
= bt_stream_borrow_class(stream
);
83 BT_ASSERT(stream_class
);
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
,
88 packet
, stream
, bt_stream_get_name(stream
),
90 bt_stream_class_get_name(stream_class
),
91 bt_stream_class_get_id(stream_class
));
93 if (likely(!packet
->props_are_set
)) {
94 ret
= bt_packet_set_properties(packet
);
96 BT_LIB_LOGE("Cannot update packet's properties: "
97 "%![prev-packet-]+a", packet
);
102 graph
= bt_private_connection_private_notification_iterator_borrow_graph(
104 notification
= (void *) bt_notification_create_from_pool(
105 &graph
->packet_begin_notif_pool
, graph
);
107 /* bt_notification_create_from_pool() logs errors */
111 BT_ASSERT(!notification
->packet
);
112 notification
->packet
= packet
;
113 bt_object_get_no_null_check_no_parent_check(
114 ¬ification
->packet
->base
);
115 bt_packet_set_is_frozen(packet
, true);
116 bt_packet_validate_properties(packet
);
117 BT_LOGD("Created packet beginning notification object: "
118 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
119 "stream-class-addr=%p, stream-class-name=\"%s\", "
120 "stream-class-id=%" PRId64
", addr=%p",
121 packet
, stream
, bt_stream_get_name(stream
),
123 bt_stream_class_get_name(stream_class
),
124 bt_stream_class_get_id(stream_class
), notification
);
128 return (void *) notification
;
132 void bt_notification_packet_begin_destroy(struct bt_notification
*notif
)
134 struct bt_notification_packet_begin
*packet_begin_notif
= (void *) notif
;
136 BT_LOGD("Destroying packet beginning notification: addr=%p", notif
);
137 BT_LOGD_STR("Putting packet.");
138 BT_PUT(packet_begin_notif
->packet
);
143 void bt_notification_packet_begin_recycle(struct bt_notification
*notif
)
145 struct bt_notification_packet_begin
*packet_begin_notif
= (void *) notif
;
146 struct bt_graph
*graph
;
148 BT_ASSERT(packet_begin_notif
);
150 if (unlikely(!notif
->graph
)) {
151 bt_notification_packet_begin_destroy(notif
);
155 BT_LOGD("Recycling packet beginning notification: addr=%p", notif
);
156 bt_notification_reset(notif
);
157 bt_object_put_no_null_check(&packet_begin_notif
->packet
->base
);
158 packet_begin_notif
->packet
= NULL
;
159 graph
= notif
->graph
;
161 bt_object_pool_recycle_object(&graph
->packet_begin_notif_pool
, notif
);
164 struct bt_packet
*bt_notification_packet_begin_borrow_packet(
165 struct bt_notification
*notification
)
167 struct bt_notification_packet_begin
*packet_begin
;
169 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
170 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
171 BT_NOTIFICATION_TYPE_PACKET_BEGIN
);
172 packet_begin
= container_of(notification
,
173 struct bt_notification_packet_begin
, parent
);
174 return packet_begin
->packet
;
178 struct bt_notification
*bt_notification_packet_end_new(struct bt_graph
*graph
)
180 struct bt_notification_packet_end
*notification
;
182 notification
= g_new0(struct bt_notification_packet_end
, 1);
184 BT_LOGE_STR("Failed to allocate one packet end notification.");
188 bt_notification_init(¬ification
->parent
,
189 BT_NOTIFICATION_TYPE_PACKET_END
,
190 (bt_object_release_func
) bt_notification_packet_end_recycle
,
195 BT_PUT(notification
);
198 return (void *) notification
;
201 struct bt_notification
*bt_notification_packet_end_create(
202 struct bt_private_connection_private_notification_iterator
*notif_iter
,
203 struct bt_packet
*packet
)
205 struct bt_notification_packet_end
*notification
= NULL
;
206 struct bt_stream
*stream
;
207 struct bt_stream_class
*stream_class
;
208 struct bt_graph
*graph
;
211 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
212 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
213 stream
= bt_packet_borrow_stream(packet
);
215 stream_class
= bt_stream_borrow_class(stream
);
216 BT_ASSERT(stream_class
);
217 BT_LOGD("Creating packet end notification object: "
218 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
219 "stream-class-addr=%p, stream-class-name=\"%s\", "
220 "stream-class-id=%" PRId64
,
221 packet
, stream
, bt_stream_get_name(stream
),
223 bt_stream_class_get_name(stream_class
),
224 bt_stream_class_get_id(stream_class
));
226 if (unlikely(!packet
->props_are_set
)) {
227 ret
= bt_packet_set_properties(packet
);
229 BT_LIB_LOGE("Cannot update packet's properties: "
230 "%![prev-packet-]+a", packet
);
235 graph
= bt_private_connection_private_notification_iterator_borrow_graph(
237 notification
= (void *) bt_notification_create_from_pool(
238 &graph
->packet_end_notif_pool
, graph
);
240 /* bt_notification_create_from_pool() logs errors */
244 BT_ASSERT(!notification
->packet
);
245 notification
->packet
= packet
;
246 bt_object_get_no_null_check_no_parent_check(
247 ¬ification
->packet
->base
);
248 bt_packet_set_is_frozen(packet
, true);
249 bt_packet_validate_properties(packet
);
250 BT_LOGD("Created packet end notification object: "
251 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
252 "stream-class-addr=%p, stream-class-name=\"%s\", "
253 "stream-class-id=%" PRId64
", addr=%p",
254 packet
, stream
, bt_stream_get_name(stream
),
256 bt_stream_class_get_name(stream_class
),
257 bt_stream_class_get_id(stream_class
), notification
);
261 return (void *) notification
;
265 void bt_notification_packet_end_destroy(struct bt_notification
*notif
)
267 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
269 BT_LOGD("Destroying packet end notification: addr=%p", notif
);
270 BT_LOGD_STR("Putting packet.");
271 BT_PUT(packet_end_notif
->packet
);
276 void bt_notification_packet_end_recycle(struct bt_notification
*notif
)
278 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
279 struct bt_graph
*graph
;
281 BT_ASSERT(packet_end_notif
);
284 bt_notification_packet_end_destroy(notif
);
288 BT_LOGD("Recycling packet end notification: addr=%p", notif
);
289 bt_notification_reset(notif
);
290 BT_PUT(packet_end_notif
->packet
);
291 graph
= notif
->graph
;
293 bt_object_pool_recycle_object(&graph
->packet_end_notif_pool
, notif
);
296 struct bt_packet
*bt_notification_packet_end_borrow_packet(
297 struct bt_notification
*notification
)
299 struct bt_notification_packet_end
*packet_end
;
301 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
302 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
303 BT_NOTIFICATION_TYPE_PACKET_END
);
304 packet_end
= container_of(notification
,
305 struct bt_notification_packet_end
, parent
);
306 return packet_end
->packet
;