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/graph/private-connection-private-notification-iterator.h>
38 #include <babeltrace/object.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
,
62 BT_OBJECT_PUT_REF_AND_RESET(notification
);
65 return (void *) notification
;
68 struct bt_private_notification
*bt_private_notification_packet_begin_create(
69 struct bt_private_connection_private_notification_iterator
*notif_iter
,
70 struct bt_private_packet
*priv_packet
)
72 struct bt_packet
*packet
= (void *) priv_packet
;
73 struct bt_notification_packet_begin
*notification
= NULL
;
74 struct bt_stream
*stream
;
75 struct bt_stream_class
*stream_class
;
76 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
));
92 graph
= bt_private_connection_private_notification_iterator_borrow_graph(
94 notification
= (void *) bt_notification_create_from_pool(
95 &graph
->packet_begin_notif_pool
, graph
);
97 /* bt_notification_create_from_pool() logs errors */
101 BT_ASSERT(!notification
->packet
);
102 notification
->packet
= packet
;
103 bt_object_get_no_null_check_no_parent_check(
104 ¬ification
->packet
->base
);
105 bt_packet_set_is_frozen(packet
, true);
106 BT_LOGD("Created packet beginning notification object: "
107 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
108 "stream-class-addr=%p, stream-class-name=\"%s\", "
109 "stream-class-id=%" PRId64
", addr=%p",
110 packet
, stream
, bt_stream_get_name(stream
),
112 bt_stream_class_get_name(stream_class
),
113 bt_stream_class_get_id(stream_class
), notification
);
117 return (void *) notification
;
121 void bt_notification_packet_begin_destroy(struct bt_notification
*notif
)
123 struct bt_notification_packet_begin
*packet_begin_notif
= (void *) notif
;
125 BT_LOGD("Destroying packet beginning notification: addr=%p", notif
);
126 BT_LOGD_STR("Putting packet.");
127 BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif
->packet
);
132 void bt_notification_packet_begin_recycle(struct bt_notification
*notif
)
134 struct bt_notification_packet_begin
*packet_begin_notif
= (void *) notif
;
135 struct bt_graph
*graph
;
137 BT_ASSERT(packet_begin_notif
);
139 if (unlikely(!notif
->graph
)) {
140 bt_notification_packet_begin_destroy(notif
);
144 BT_LOGD("Recycling packet beginning notification: addr=%p", notif
);
145 bt_notification_reset(notif
);
146 bt_object_put_no_null_check(&packet_begin_notif
->packet
->base
);
147 packet_begin_notif
->packet
= NULL
;
148 graph
= notif
->graph
;
150 bt_object_pool_recycle_object(&graph
->packet_begin_notif_pool
, notif
);
153 struct bt_packet
*bt_notification_packet_begin_borrow_packet(
154 struct bt_notification
*notification
)
156 struct bt_notification_packet_begin
*packet_begin
;
158 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
159 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
160 BT_NOTIFICATION_TYPE_PACKET_BEGIN
);
161 packet_begin
= container_of(notification
,
162 struct bt_notification_packet_begin
, parent
);
163 return packet_begin
->packet
;
166 struct bt_private_packet
*
167 bt_private_notification_packet_begin_borrow_packet(
168 struct bt_private_notification
*notification
)
170 return (void *) bt_notification_packet_begin_borrow_packet(
171 (void *) notification
);
175 struct bt_notification
*bt_notification_packet_end_new(struct bt_graph
*graph
)
177 struct bt_notification_packet_end
*notification
;
179 notification
= g_new0(struct bt_notification_packet_end
, 1);
181 BT_LOGE_STR("Failed to allocate one packet end notification.");
185 bt_notification_init(¬ification
->parent
,
186 BT_NOTIFICATION_TYPE_PACKET_END
,
187 (bt_object_release_func
) bt_notification_packet_end_recycle
,
192 BT_OBJECT_PUT_REF_AND_RESET(notification
);
195 return (void *) notification
;
198 struct bt_private_notification
*bt_private_notification_packet_end_create(
199 struct bt_private_connection_private_notification_iterator
*notif_iter
,
200 struct bt_private_packet
*priv_packet
)
202 struct bt_packet
*packet
= (void *) priv_packet
;
203 struct bt_notification_packet_end
*notification
= NULL
;
204 struct bt_stream
*stream
;
205 struct bt_stream_class
*stream_class
;
206 struct bt_graph
*graph
;
208 BT_ASSERT_PRE_NON_NULL(notif_iter
, "Notification iterator");
209 BT_ASSERT_PRE_NON_NULL(packet
, "Packet");
210 stream
= bt_packet_borrow_stream(packet
);
212 stream_class
= bt_stream_borrow_class(stream
);
213 BT_ASSERT(stream_class
);
214 BT_LOGD("Creating packet end notification object: "
215 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
216 "stream-class-addr=%p, stream-class-name=\"%s\", "
217 "stream-class-id=%" PRId64
,
218 packet
, stream
, bt_stream_get_name(stream
),
220 bt_stream_class_get_name(stream_class
),
221 bt_stream_class_get_id(stream_class
));
222 graph
= bt_private_connection_private_notification_iterator_borrow_graph(
224 notification
= (void *) bt_notification_create_from_pool(
225 &graph
->packet_end_notif_pool
, graph
);
227 /* bt_notification_create_from_pool() logs errors */
231 BT_ASSERT(!notification
->packet
);
232 notification
->packet
= packet
;
233 bt_object_get_no_null_check_no_parent_check(
234 ¬ification
->packet
->base
);
235 bt_packet_set_is_frozen(packet
, true);
236 BT_LOGD("Created packet end notification object: "
237 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
238 "stream-class-addr=%p, stream-class-name=\"%s\", "
239 "stream-class-id=%" PRId64
", addr=%p",
240 packet
, stream
, bt_stream_get_name(stream
),
242 bt_stream_class_get_name(stream_class
),
243 bt_stream_class_get_id(stream_class
), notification
);
247 return (void *) notification
;
251 void bt_notification_packet_end_destroy(struct bt_notification
*notif
)
253 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
255 BT_LOGD("Destroying packet end notification: addr=%p", notif
);
256 BT_LOGD_STR("Putting packet.");
257 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif
->packet
);
262 void bt_notification_packet_end_recycle(struct bt_notification
*notif
)
264 struct bt_notification_packet_end
*packet_end_notif
= (void *) notif
;
265 struct bt_graph
*graph
;
267 BT_ASSERT(packet_end_notif
);
270 bt_notification_packet_end_destroy(notif
);
274 BT_LOGD("Recycling packet end notification: addr=%p", notif
);
275 bt_notification_reset(notif
);
276 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif
->packet
);
277 graph
= notif
->graph
;
279 bt_object_pool_recycle_object(&graph
->packet_end_notif_pool
, notif
);
282 struct bt_packet
*bt_notification_packet_end_borrow_packet(
283 struct bt_notification
*notification
)
285 struct bt_notification_packet_end
*packet_end
;
287 BT_ASSERT_PRE_NON_NULL(notification
, "Notification");
288 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification
,
289 BT_NOTIFICATION_TYPE_PACKET_END
);
290 packet_end
= container_of(notification
,
291 struct bt_notification_packet_end
, parent
);
292 return packet_end
->packet
;
295 struct bt_private_packet
*bt_private_notification_packet_end_borrow_packet(
296 struct bt_private_notification
*notification
)
298 return (void *) bt_notification_packet_end_borrow_packet(
299 (void *) notification
);