2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "NOTIF-PACKET"
25 #include <babeltrace/lib-logging-internal.h>
27 #include <babeltrace/compiler-internal.h>
28 #include <babeltrace/trace-ir/packet.h>
29 #include <babeltrace/trace-ir/packet-internal.h>
30 #include <babeltrace/trace-ir/stream-class.h>
31 #include <babeltrace/trace-ir/stream.h>
32 #include <babeltrace/trace-ir/stream-internal.h>
33 #include <babeltrace/graph/graph-internal.h>
34 #include <babeltrace/graph/notification-packet-const.h>
35 #include <babeltrace/graph/notification-packet.h>
36 #include <babeltrace/graph/notification-packet-internal.h>
37 #include <babeltrace/assert-internal.h>
38 #include <babeltrace/assert-pre-internal.h>
39 #include <babeltrace/object-internal.h>
43 struct bt_notification
*bt_notification_packet_beginning_new(struct bt_graph
*graph
)
45 struct bt_notification_packet_beginning
*notification
;
47 notification
= g_new0(struct bt_notification_packet_beginning
, 1);
49 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
53 bt_notification_init(¬ification
->parent
,
54 BT_NOTIFICATION_TYPE_PACKET_BEGINNING
,
55 (bt_object_release_func
) bt_notification_packet_beginning_recycle
,
60 BT_OBJECT_PUT_REF_AND_RESET(notification
);
63 return (void *) notification
;
66 struct bt_notification
*bt_notification_packet_beginning_create(
67 struct bt_self_notification_iterator
*self_notif_iter
,
68 struct bt_packet
*packet
)
70 struct bt_self_component_port_input_notification_iterator
*notif_iter
=
71 (void *) self_notif_iter
;
72 struct bt_notification_packet_beginning
*notification
= NULL
;
73 struct bt_stream
*stream
;
74 struct bt_stream_class
*stream_class
;
76 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
77 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
78 stream
= bt_packet_borrow_stream(packet
);
80 stream_class
= bt_stream_borrow_class(stream
);
81 BT_ASSERT(stream_class
);
82 BT_LIB_LOGD("Creating packet beginning notification object: "
83 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
84 packet
, stream
, stream_class
);
85 notification
= (void *) bt_notification_create_from_pool(
86 ¬if_iter
->graph
->packet_begin_notif_pool
, notif_iter
->graph
);
88 /* bt_notification_create_from_pool() logs errors */
92 BT_ASSERT(!notification
->packet
);
93 notification
->packet
= packet
;
94 bt_object_get_no_null_check_no_parent_check(
95 ¬ification
->packet
->base
);
96 bt_packet_set_is_frozen(packet
, true);
97 BT_LIB_LOGD("Created packet beginning notification object: "
98 "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S",
99 notification
, packet
, stream
, stream_class
);
103 return (void *) notification
;
107 void bt_notification_packet_beginning_destroy(struct bt_notification
*notif
)
109 struct bt_notification_packet_beginning
*packet_begin_notif
= (void *) notif
;
111 BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif
);
112 BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif
->packet
);
113 BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif
->packet
);
118 void bt_notification_packet_beginning_recycle(struct bt_notification
*notif
)
120 struct bt_notification_packet_beginning
*packet_begin_notif
= (void *) notif
;
121 struct bt_graph
*graph
;
123 BT_ASSERT(packet_begin_notif
);
125 if (unlikely(!notif
->graph
)) {
126 bt_notification_packet_beginning_destroy(notif
);
130 BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif
);
131 bt_notification_reset(notif
);
132 bt_object_put_no_null_check(&packet_begin_notif
->packet
->base
);
133 packet_begin_notif
->packet
= NULL
;
134 graph
= notif
->graph
;
136 bt_object_pool_recycle_object(&graph
->packet_begin_notif_pool
, notif
);
139 struct bt_packet
*bt_notification_packet_beginning_borrow_packet(
140 struct bt_notification
*notification
)
142 struct bt_notification_packet_beginning
*packet_begin
;
144 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
145 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
146 BT_NOTIFICATION_TYPE_PACKET_BEGINNING
);
147 packet_begin
= (void *) notification
;
148 return packet_begin
->packet
;
151 const struct bt_packet
*bt_notification_packet_beginning_borrow_packet_const(
152 const struct bt_notification
*notification
)
154 return bt_notification_packet_beginning_borrow_packet(
155 (void *) notification
);
159 struct bt_notification
*bt_notification_packet_end_new(struct bt_graph
*graph
)
161 struct bt_notification_packet_end
*notification
;
163 notification
= g_new0(struct bt_notification_packet_end
, 1);
165 BT_LOGE_STR("Failed to allocate one packet end notification.");
169 bt_notification_init(¬ification
->parent
,
170 BT_NOTIFICATION_TYPE_PACKET_END
,
171 (bt_object_release_func
) bt_notification_packet_end_recycle
,
176 BT_OBJECT_PUT_REF_AND_RESET(notification
);
179 return (void *) notification
;
182 struct bt_notification
*bt_notification_packet_end_create(
183 struct bt_self_notification_iterator
*self_notif_iter
,
184 struct bt_packet
*packet
)
186 struct bt_self_component_port_input_notification_iterator
*notif_iter
=
187 (void *) self_notif_iter
;
188 struct bt_notification_packet_end
*notification
= NULL
;
189 struct bt_stream
*stream
;
190 struct bt_stream_class
*stream_class
;
192 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
193 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
194 stream
= bt_packet_borrow_stream(packet
);
196 stream_class
= bt_stream_borrow_class(stream
);
197 BT_ASSERT(stream_class
);
198 BT_LIB_LOGD("Creating packet end notification object: "
199 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
200 packet
, stream
, stream_class
);
201 notification
= (void *) bt_notification_create_from_pool(
202 ¬if_iter
->graph
->packet_end_notif_pool
, notif_iter
->graph
);
204 /* bt_notification_create_from_pool() logs errors */
208 BT_ASSERT(!notification
->packet
);
209 notification
->packet
= packet
;
210 bt_object_get_no_null_check_no_parent_check(
211 ¬ification
->packet
->base
);
212 bt_packet_set_is_frozen(packet
, true);
213 BT_LIB_LOGD("Created packet end notification object: "
214 "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S",
215 notification
, packet
, stream
, stream_class
);
219 return (void *) notification
;
223 void bt_notification_packet_end_destroy(struct bt_notification
*notif
)
225 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
227 BT_LIB_LOGD("Destroying packet end notification: %!+n", notif
);
228 BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif
->packet
);
229 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif
->packet
);
234 void bt_notification_packet_end_recycle(struct bt_notification
*notif
)
236 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
237 struct bt_graph
*graph
;
239 BT_ASSERT(packet_end_notif
);
242 bt_notification_packet_end_destroy(notif
);
246 BT_LIB_LOGD("Recycling packet end notification: %!+n", notif
);
247 bt_notification_reset(notif
);
248 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif
->packet
);
249 graph
= notif
->graph
;
251 bt_object_pool_recycle_object(&graph
->packet_end_notif_pool
, notif
);
254 struct bt_packet
*bt_notification_packet_end_borrow_packet(
255 struct bt_notification
*notification
)
257 struct bt_notification_packet_end
*packet_end
;
259 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
260 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
261 BT_NOTIFICATION_TYPE_PACKET_END
);
262 packet_end
= (void *) notification
;
263 return packet_end
->packet
;
266 const struct bt_packet
*bt_notification_packet_end_borrow_packet_const(
267 const struct bt_notification
*notification
)
269 return bt_notification_packet_end_borrow_packet(
270 (void *) notification
);