CTF IR -> Trace IR
[babeltrace.git] / lib / graph / notification / packet.c
CommitLineData
78586d8a
JG
1/*
2 * Babeltrace Plug-in Packet-related Notifications
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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
24 * SOFTWARE.
25 */
26
93881221
PP
27#define BT_LOG_TAG "NOTIF-PACKET"
28#include <babeltrace/lib-logging-internal.h>
29
3d9990ac 30#include <babeltrace/compiler-internal.h>
108b91d0
PP
31#include <babeltrace/trace-ir/packet.h>
32#include <babeltrace/trace-ir/packet-internal.h>
33#include <babeltrace/trace-ir/stream-class.h>
34#include <babeltrace/trace-ir/stream.h>
35#include <babeltrace/trace-ir/stream-internal.h>
f7c3ac09 36#include <babeltrace/graph/graph-internal.h>
b2e0c907 37#include <babeltrace/graph/notification-packet-internal.h>
03e18d5d 38#include <babeltrace/graph/private-connection-private-notification-iterator.h>
8b45963b
PP
39#include <babeltrace/assert-internal.h>
40#include <babeltrace/assert-pre-internal.h>
c5a24b0a 41#include <babeltrace/object-internal.h>
93881221 42#include <inttypes.h>
78586d8a 43
f7c3ac09
PP
44BT_HIDDEN
45struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph)
78586d8a 46{
f7c3ac09 47 struct bt_notification_packet_begin *notification;
78586d8a 48
f7c3ac09
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
f7c3ac09
PP
55 bt_notification_init(&notification->parent,
56 BT_NOTIFICATION_TYPE_PACKET_BEGIN,
57 (bt_object_release_func) bt_notification_packet_begin_recycle,
58 graph);
59 goto end;
78586d8a 60
f7c3ac09
PP
61error:
62 BT_PUT(notification);
63
64end:
65 return (void *) notification;
78586d8a
JG
66}
67
ea0e619e 68struct bt_notification *bt_notification_packet_begin_create(
03e18d5d
PP
69 struct bt_private_connection_private_notification_iterator *notif_iter,
70 struct bt_packet *packet)
78586d8a 71{
e5815ba2 72 struct bt_notification_packet_begin *notification = NULL;
839d52a5
PP
73 struct bt_stream *stream;
74 struct bt_stream_class *stream_class;
03e18d5d 75 struct bt_graph *graph;
78586d8a 76
03e18d5d 77 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
8b45963b 78 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
839d52a5 79 stream = bt_packet_borrow_stream(packet);
8b45963b 80 BT_ASSERT(stream);
8deee039 81 stream_class = bt_stream_borrow_class(stream);
8b45963b 82 BT_ASSERT(stream_class);
93881221
PP
83 BT_LOGD("Creating packet beginning notification object: "
84 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
85 "stream-class-addr=%p, stream-class-name=\"%s\", "
86 "stream-class-id=%" PRId64,
839d52a5 87 packet, stream, bt_stream_get_name(stream),
93881221 88 stream_class,
839d52a5
PP
89 bt_stream_class_get_name(stream_class),
90 bt_stream_class_get_id(stream_class));
03e18d5d
PP
91 graph = bt_private_connection_private_notification_iterator_borrow_graph(
92 notif_iter);
f7c3ac09
PP
93 notification = (void *) bt_notification_create_from_pool(
94 &graph->packet_begin_notif_pool, graph);
93881221 95 if (!notification) {
f7c3ac09 96 /* bt_notification_create_from_pool() logs errors */
c5a24b0a 97 goto end;
93881221
PP
98 }
99
c5a24b0a
PP
100 BT_ASSERT(!notification->packet);
101 notification->packet = packet;
102 bt_object_get_no_null_check_no_parent_check(
103 &notification->packet->base);
e5815ba2 104 bt_packet_set_is_frozen(packet, true);
93881221
PP
105 BT_LOGD("Created packet beginning notification object: "
106 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
107 "stream-class-addr=%p, stream-class-name=\"%s\", "
108 "stream-class-id=%" PRId64 ", addr=%p",
839d52a5 109 packet, stream, bt_stream_get_name(stream),
93881221 110 stream_class,
839d52a5
PP
111 bt_stream_class_get_name(stream_class),
112 bt_stream_class_get_id(stream_class), notification);
f7c3ac09
PP
113 goto end;
114
f7c3ac09
PP
115end:
116 return (void *) notification;
117}
118
119BT_HIDDEN
120void bt_notification_packet_begin_destroy(struct bt_notification *notif)
121{
122 struct bt_notification_packet_begin *packet_begin_notif = (void *) notif;
123
124 BT_LOGD("Destroying packet beginning notification: addr=%p", notif);
125 BT_LOGD_STR("Putting packet.");
126 BT_PUT(packet_begin_notif->packet);
127 g_free(notif);
128}
129
130BT_HIDDEN
131void bt_notification_packet_begin_recycle(struct bt_notification *notif)
132{
133 struct bt_notification_packet_begin *packet_begin_notif = (void *) notif;
134 struct bt_graph *graph;
135
136 BT_ASSERT(packet_begin_notif);
137
c5a24b0a 138 if (unlikely(!notif->graph)) {
f7c3ac09
PP
139 bt_notification_packet_begin_destroy(notif);
140 return;
141 }
142
143 BT_LOGD("Recycling packet beginning notification: addr=%p", notif);
144 bt_notification_reset(notif);
c5a24b0a
PP
145 bt_object_put_no_null_check(&packet_begin_notif->packet->base);
146 packet_begin_notif->packet = NULL;
f7c3ac09
PP
147 graph = notif->graph;
148 notif->graph = NULL;
149 bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif);
78586d8a
JG
150}
151
5fe68922 152struct bt_packet *bt_notification_packet_begin_borrow_packet(
78586d8a
JG
153 struct bt_notification *notification)
154{
ea0e619e 155 struct bt_notification_packet_begin *packet_begin;
78586d8a 156
8b45963b
PP
157 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
158 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
159 BT_NOTIFICATION_TYPE_PACKET_BEGIN);
ea0e619e
JG
160 packet_begin = container_of(notification,
161 struct bt_notification_packet_begin, parent);
5fe68922 162 return packet_begin->packet;
78586d8a
JG
163}
164
f7c3ac09
PP
165BT_HIDDEN
166struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph)
167{
168 struct bt_notification_packet_end *notification;
169
170 notification = g_new0(struct bt_notification_packet_end, 1);
171 if (!notification) {
172 BT_LOGE_STR("Failed to allocate one packet end notification.");
173 goto error;
174 }
175
176 bt_notification_init(&notification->parent,
177 BT_NOTIFICATION_TYPE_PACKET_END,
178 (bt_object_release_func) bt_notification_packet_end_recycle,
179 graph);
180 goto end;
181
182error:
183 BT_PUT(notification);
184
185end:
186 return (void *) notification;
187}
188
78586d8a 189struct bt_notification *bt_notification_packet_end_create(
03e18d5d
PP
190 struct bt_private_connection_private_notification_iterator *notif_iter,
191 struct bt_packet *packet)
78586d8a 192{
e5815ba2 193 struct bt_notification_packet_end *notification = NULL;
839d52a5
PP
194 struct bt_stream *stream;
195 struct bt_stream_class *stream_class;
03e18d5d 196 struct bt_graph *graph;
78586d8a 197
03e18d5d 198 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
8b45963b 199 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
839d52a5 200 stream = bt_packet_borrow_stream(packet);
8b45963b 201 BT_ASSERT(stream);
8deee039 202 stream_class = bt_stream_borrow_class(stream);
8b45963b 203 BT_ASSERT(stream_class);
93881221
PP
204 BT_LOGD("Creating packet end notification object: "
205 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
206 "stream-class-addr=%p, stream-class-name=\"%s\", "
207 "stream-class-id=%" PRId64,
839d52a5 208 packet, stream, bt_stream_get_name(stream),
93881221 209 stream_class,
839d52a5
PP
210 bt_stream_class_get_name(stream_class),
211 bt_stream_class_get_id(stream_class));
03e18d5d
PP
212 graph = bt_private_connection_private_notification_iterator_borrow_graph(
213 notif_iter);
f7c3ac09
PP
214 notification = (void *) bt_notification_create_from_pool(
215 &graph->packet_end_notif_pool, graph);
93881221 216 if (!notification) {
f7c3ac09 217 /* bt_notification_create_from_pool() logs errors */
c5a24b0a 218 goto end;
93881221
PP
219 }
220
c5a24b0a
PP
221 BT_ASSERT(!notification->packet);
222 notification->packet = packet;
223 bt_object_get_no_null_check_no_parent_check(
224 &notification->packet->base);
e5815ba2 225 bt_packet_set_is_frozen(packet, true);
93881221
PP
226 BT_LOGD("Created packet end notification object: "
227 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
228 "stream-class-addr=%p, stream-class-name=\"%s\", "
229 "stream-class-id=%" PRId64 ", addr=%p",
839d52a5 230 packet, stream, bt_stream_get_name(stream),
93881221 231 stream_class,
839d52a5
PP
232 bt_stream_class_get_name(stream_class),
233 bt_stream_class_get_id(stream_class), notification);
f7c3ac09
PP
234 goto end;
235
f7c3ac09
PP
236end:
237 return (void *) notification;
238}
239
240BT_HIDDEN
241void bt_notification_packet_end_destroy(struct bt_notification *notif)
242{
243 struct bt_notification_packet_end *packet_end_notif = (void *) notif;
244
245 BT_LOGD("Destroying packet end notification: addr=%p", notif);
246 BT_LOGD_STR("Putting packet.");
247 BT_PUT(packet_end_notif->packet);
248 g_free(notif);
249}
250
251BT_HIDDEN
252void bt_notification_packet_end_recycle(struct bt_notification *notif)
253{
254 struct bt_notification_packet_end *packet_end_notif = (void *) notif;
255 struct bt_graph *graph;
256
257 BT_ASSERT(packet_end_notif);
258
259 if (!notif->graph) {
260 bt_notification_packet_end_destroy(notif);
261 return;
262 }
263
264 BT_LOGD("Recycling packet end notification: addr=%p", notif);
265 bt_notification_reset(notif);
266 BT_PUT(packet_end_notif->packet);
267 graph = notif->graph;
268 notif->graph = NULL;
269 bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif);
78586d8a
JG
270}
271
5fe68922 272struct bt_packet *bt_notification_packet_end_borrow_packet(
78586d8a
JG
273 struct bt_notification *notification)
274{
275 struct bt_notification_packet_end *packet_end;
276
8b45963b
PP
277 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
278 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
279 BT_NOTIFICATION_TYPE_PACKET_END);
78586d8a
JG
280 packet_end = container_of(notification,
281 struct bt_notification_packet_end, parent);
5fe68922 282 return packet_end->packet;
78586d8a 283}
This page took 0.047349 seconds and 4 git commands to generate.