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