2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
25 #define BT_LOG_TAG "NOTIF-PACKET"
26 #include <babeltrace/lib-logging-internal.h>
28 #include <babeltrace/compiler-internal.h>
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>
34 #include <babeltrace/graph/graph-internal.h>
35 #include <babeltrace/graph/private-notification-packet.h>
36 #include <babeltrace/graph/notification-packet-internal.h>
37 #include <babeltrace/object.h>
38 #include <babeltrace/assert-internal.h>
39 #include <babeltrace/assert-pre-internal.h>
40 #include <babeltrace/object-internal.h>
44 struct bt_notification
*bt_notification_packet_begin_new(struct bt_graph
*graph
)
46 struct bt_notification_packet_begin
*notification
;
48 notification
= g_new0(struct bt_notification_packet_begin
, 1);
50 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
54 bt_notification_init(¬ification
->parent
,
55 BT_NOTIFICATION_TYPE_PACKET_BEGIN
,
56 (bt_object_release_func
) bt_notification_packet_begin_recycle
,
61 BT_OBJECT_PUT_REF_AND_RESET(notification
);
64 return (void *) notification
;
67 struct bt_private_notification
*bt_private_notification_packet_begin_create(
68 struct bt_self_notification_iterator
*self_notif_iter
,
69 struct bt_packet
*packet
)
71 struct bt_self_component_port_input_notification_iterator
*notif_iter
=
72 (void *) self_notif_iter
;
73 struct bt_notification_packet_begin
*notification
= NULL
;
74 struct bt_stream
*stream
;
75 struct bt_stream_class
*stream_class
;
77 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
78 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
79 stream
= bt_packet_borrow_stream(packet
);
81 stream_class
= bt_stream_borrow_class(stream
);
82 BT_ASSERT(stream_class
);
83 BT_LIB_LOGD("Creating packet beginning notification object: "
84 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
85 packet
, stream
, stream_class
);
86 notification
= (void *) bt_notification_create_from_pool(
87 ¬if_iter
->graph
->packet_begin_notif_pool
, notif_iter
->graph
);
89 /* bt_notification_create_from_pool() logs errors */
93 BT_ASSERT(!notification
->packet
);
94 notification
->packet
= packet
;
95 bt_object_get_no_null_check_no_parent_check(
96 ¬ification
->packet
->base
);
97 bt_packet_set_is_frozen(packet
, true);
98 BT_LIB_LOGD("Created packet beginning notification object: "
99 "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S",
100 notification
, packet
, stream
, stream_class
);
104 return (void *) notification
;
108 void bt_notification_packet_begin_destroy(struct bt_notification
*notif
)
110 struct bt_notification_packet_begin
*packet_begin_notif
= (void *) notif
;
112 BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif
);
113 BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif
->packet
);
114 BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif
->packet
);
119 void bt_notification_packet_begin_recycle(struct bt_notification
*notif
)
121 struct bt_notification_packet_begin
*packet_begin_notif
= (void *) notif
;
122 struct bt_graph
*graph
;
124 BT_ASSERT(packet_begin_notif
);
126 if (unlikely(!notif
->graph
)) {
127 bt_notification_packet_begin_destroy(notif
);
131 BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif
);
132 bt_notification_reset(notif
);
133 bt_object_put_no_null_check(&packet_begin_notif
->packet
->base
);
134 packet_begin_notif
->packet
= NULL
;
135 graph
= notif
->graph
;
137 bt_object_pool_recycle_object(&graph
->packet_begin_notif_pool
, notif
);
140 struct bt_packet
*bt_private_notification_packet_begin_borrow_packet(
141 struct bt_private_notification
*notification
)
143 struct bt_notification_packet_begin
*packet_begin
;
145 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
146 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
147 BT_NOTIFICATION_TYPE_PACKET_BEGIN
);
148 packet_begin
= (void *) notification
;
149 return packet_begin
->packet
;
152 const struct bt_packet
*bt_notification_packet_begin_borrow_packet(
153 struct bt_notification
*notification
)
155 return bt_private_notification_packet_begin_borrow_packet(
156 (void *) notification
);
160 struct bt_notification
*bt_notification_packet_end_new(struct bt_graph
*graph
)
162 struct bt_notification_packet_end
*notification
;
164 notification
= g_new0(struct bt_notification_packet_end
, 1);
166 BT_LOGE_STR("Failed to allocate one packet end notification.");
170 bt_notification_init(¬ification
->parent
,
171 BT_NOTIFICATION_TYPE_PACKET_END
,
172 (bt_object_release_func
) bt_notification_packet_end_recycle
,
177 BT_OBJECT_PUT_REF_AND_RESET(notification
);
180 return (void *) notification
;
183 struct bt_private_notification
*bt_private_notification_packet_end_create(
184 struct bt_self_notification_iterator
*self_notif_iter
,
185 struct bt_packet
*packet
)
187 struct bt_self_component_port_input_notification_iterator
*notif_iter
=
188 (void *) self_notif_iter
;
189 struct bt_notification_packet_end
*notification
= NULL
;
190 struct bt_stream
*stream
;
191 struct bt_stream_class
*stream_class
;
193 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
194 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
195 stream
= bt_packet_borrow_stream(packet
);
197 stream_class
= bt_stream_borrow_class(stream
);
198 BT_ASSERT(stream_class
);
199 BT_LIB_LOGD("Creating packet end notification object: "
200 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
201 packet
, stream
, stream_class
);
202 notification
= (void *) bt_notification_create_from_pool(
203 ¬if_iter
->graph
->packet_end_notif_pool
, notif_iter
->graph
);
205 /* bt_notification_create_from_pool() logs errors */
209 BT_ASSERT(!notification
->packet
);
210 notification
->packet
= packet
;
211 bt_object_get_no_null_check_no_parent_check(
212 ¬ification
->packet
->base
);
213 bt_packet_set_is_frozen(packet
, true);
214 BT_LIB_LOGD("Created packet end notification object: "
215 "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S",
216 notification
, packet
, stream
, stream_class
);
220 return (void *) notification
;
224 void bt_notification_packet_end_destroy(struct bt_notification
*notif
)
226 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
228 BT_LIB_LOGD("Destroying packet end notification: %!+n", notif
);
229 BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif
->packet
);
230 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif
->packet
);
235 void bt_notification_packet_end_recycle(struct bt_notification
*notif
)
237 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
238 struct bt_graph
*graph
;
240 BT_ASSERT(packet_end_notif
);
243 bt_notification_packet_end_destroy(notif
);
247 BT_LIB_LOGD("Recycling packet end notification: %!+n", notif
);
248 bt_notification_reset(notif
);
249 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif
->packet
);
250 graph
= notif
->graph
;
252 bt_object_pool_recycle_object(&graph
->packet_end_notif_pool
, notif
);
255 struct bt_packet
*bt_private_notification_packet_end_borrow_packet(
256 struct bt_private_notification
*notification
)
258 struct bt_notification_packet_end
*packet_end
;
260 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
261 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
262 BT_NOTIFICATION_TYPE_PACKET_END
);
263 packet_end
= (void *) notification
;
264 return packet_end
->packet
;
267 const struct bt_packet
*bt_notification_packet_end_borrow_packet(
268 struct bt_notification
*notification
)
270 return bt_private_notification_packet_end_borrow_packet(
271 (void *) notification
);