lib: make trace IR API const-correct
[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
dbff6338
PP
25#define BT_LOG_TAG "NOTIF-PACKET"
26#include <babeltrace/lib-logging-internal.h>
27
3d9990ac 28#include <babeltrace/compiler-internal.h>
56e18c4c
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>
5c563278 34#include <babeltrace/graph/graph-internal.h>
e5be10ef 35#include <babeltrace/graph/private-notification-packet.h>
b2e0c907 36#include <babeltrace/graph/notification-packet-internal.h>
e5be10ef 37#include <babeltrace/object.h>
f6ccaed9
PP
38#include <babeltrace/assert-internal.h>
39#include <babeltrace/assert-pre-internal.h>
6c677fb5 40#include <babeltrace/object-internal.h>
dbff6338 41#include <inttypes.h>
78586d8a 42
5c563278
PP
43BT_HIDDEN
44struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph)
78586d8a 45{
5c563278 46 struct bt_notification_packet_begin *notification;
78586d8a 47
5c563278
PP
48 notification = g_new0(struct bt_notification_packet_begin, 1);
49 if (!notification) {
50 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
51 goto error;
52 }
78586d8a 53
5c563278
PP
54 bt_notification_init(&notification->parent,
55 BT_NOTIFICATION_TYPE_PACKET_BEGIN,
56 (bt_object_release_func) bt_notification_packet_begin_recycle,
57 graph);
58 goto end;
78586d8a 59
5c563278 60error:
65300d60 61 BT_OBJECT_PUT_REF_AND_RESET(notification);
5c563278
PP
62
63end:
64 return (void *) notification;
78586d8a
JG
65}
66
e5be10ef 67struct bt_private_notification *bt_private_notification_packet_begin_create(
d94d92ac 68 struct bt_self_notification_iterator *self_notif_iter,
40f4ba76 69 struct bt_packet *packet)
78586d8a 70{
d94d92ac
PP
71 struct bt_self_component_port_input_notification_iterator *notif_iter =
72 (void *) self_notif_iter;
ccf82993 73 struct bt_notification_packet_begin *notification = NULL;
50842bdc
PP
74 struct bt_stream *stream;
75 struct bt_stream_class *stream_class;
78586d8a 76
f0010051 77 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
f6ccaed9 78 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
50842bdc 79 stream = bt_packet_borrow_stream(packet);
f6ccaed9 80 BT_ASSERT(stream);
3dca2276 81 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 82 BT_ASSERT(stream_class);
d94d92ac
PP
83 BT_LIB_LOGD("Creating packet beginning notification object: "
84 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
85 packet, stream, stream_class);
5c563278 86 notification = (void *) bt_notification_create_from_pool(
d94d92ac 87 &notif_iter->graph->packet_begin_notif_pool, notif_iter->graph);
dbff6338 88 if (!notification) {
5c563278 89 /* bt_notification_create_from_pool() logs errors */
6c677fb5 90 goto end;
dbff6338
PP
91 }
92
6c677fb5
PP
93 BT_ASSERT(!notification->packet);
94 notification->packet = packet;
95 bt_object_get_no_null_check_no_parent_check(
96 &notification->packet->base);
ccf82993 97 bt_packet_set_is_frozen(packet, true);
d94d92ac
PP
98 BT_LIB_LOGD("Created packet beginning notification object: "
99 "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S",
100 notification, packet, stream, stream_class);
5c563278
PP
101 goto end;
102
5c563278
PP
103end:
104 return (void *) notification;
105}
106
107BT_HIDDEN
108void bt_notification_packet_begin_destroy(struct bt_notification *notif)
109{
110 struct bt_notification_packet_begin *packet_begin_notif = (void *) notif;
111
d94d92ac
PP
112 BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif);
113 BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif->packet);
65300d60 114 BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet);
5c563278
PP
115 g_free(notif);
116}
117
118BT_HIDDEN
119void bt_notification_packet_begin_recycle(struct bt_notification *notif)
120{
121 struct bt_notification_packet_begin *packet_begin_notif = (void *) notif;
122 struct bt_graph *graph;
123
124 BT_ASSERT(packet_begin_notif);
125
6c677fb5 126 if (unlikely(!notif->graph)) {
5c563278
PP
127 bt_notification_packet_begin_destroy(notif);
128 return;
129 }
130
d94d92ac 131 BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif);
5c563278 132 bt_notification_reset(notif);
6c677fb5
PP
133 bt_object_put_no_null_check(&packet_begin_notif->packet->base);
134 packet_begin_notif->packet = NULL;
5c563278
PP
135 graph = notif->graph;
136 notif->graph = NULL;
137 bt_object_pool_recycle_object(&graph->packet_begin_notif_pool, notif);
78586d8a
JG
138}
139
40f4ba76
PP
140struct bt_packet *bt_private_notification_packet_begin_borrow_packet(
141 struct bt_private_notification *notification)
78586d8a 142{
ea0e619e 143 struct bt_notification_packet_begin *packet_begin;
78586d8a 144
f6ccaed9
PP
145 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
146 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
147 BT_NOTIFICATION_TYPE_PACKET_BEGIN);
40f4ba76 148 packet_begin = (void *) notification;
094ff7c0 149 return packet_begin->packet;
78586d8a
JG
150}
151
40f4ba76
PP
152const struct bt_packet *bt_notification_packet_begin_borrow_packet(
153 struct bt_notification *notification)
e5be10ef 154{
40f4ba76 155 return bt_private_notification_packet_begin_borrow_packet(
e5be10ef
PP
156 (void *) notification);
157}
158
5c563278
PP
159BT_HIDDEN
160struct bt_notification *bt_notification_packet_end_new(struct bt_graph *graph)
161{
162 struct bt_notification_packet_end *notification;
163
164 notification = g_new0(struct bt_notification_packet_end, 1);
165 if (!notification) {
166 BT_LOGE_STR("Failed to allocate one packet end notification.");
167 goto error;
168 }
169
170 bt_notification_init(&notification->parent,
171 BT_NOTIFICATION_TYPE_PACKET_END,
172 (bt_object_release_func) bt_notification_packet_end_recycle,
173 graph);
174 goto end;
175
176error:
65300d60 177 BT_OBJECT_PUT_REF_AND_RESET(notification);
5c563278
PP
178
179end:
180 return (void *) notification;
181}
182
e5be10ef 183struct bt_private_notification *bt_private_notification_packet_end_create(
d94d92ac 184 struct bt_self_notification_iterator *self_notif_iter,
40f4ba76 185 struct bt_packet *packet)
78586d8a 186{
d94d92ac
PP
187 struct bt_self_component_port_input_notification_iterator *notif_iter =
188 (void *) self_notif_iter;
ccf82993 189 struct bt_notification_packet_end *notification = NULL;
50842bdc
PP
190 struct bt_stream *stream;
191 struct bt_stream_class *stream_class;
78586d8a 192
f0010051 193 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
f6ccaed9 194 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
50842bdc 195 stream = bt_packet_borrow_stream(packet);
f6ccaed9 196 BT_ASSERT(stream);
3dca2276 197 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 198 BT_ASSERT(stream_class);
d94d92ac
PP
199 BT_LIB_LOGD("Creating packet end notification object: "
200 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
201 packet, stream, stream_class);
5c563278 202 notification = (void *) bt_notification_create_from_pool(
d94d92ac 203 &notif_iter->graph->packet_end_notif_pool, notif_iter->graph);
dbff6338 204 if (!notification) {
5c563278 205 /* bt_notification_create_from_pool() logs errors */
6c677fb5 206 goto end;
dbff6338
PP
207 }
208
6c677fb5
PP
209 BT_ASSERT(!notification->packet);
210 notification->packet = packet;
211 bt_object_get_no_null_check_no_parent_check(
212 &notification->packet->base);
ccf82993 213 bt_packet_set_is_frozen(packet, true);
d94d92ac
PP
214 BT_LIB_LOGD("Created packet end notification object: "
215 "%![notif-]+n, %![packet-]+a, %![stream-]+s, %![sc-]+S",
216 notification, packet, stream, stream_class);
5c563278
PP
217 goto end;
218
5c563278
PP
219end:
220 return (void *) notification;
221}
222
223BT_HIDDEN
224void bt_notification_packet_end_destroy(struct bt_notification *notif)
225{
226 struct bt_notification_packet_end *packet_end_notif = (void *) notif;
227
d94d92ac
PP
228 BT_LIB_LOGD("Destroying packet end notification: %!+n", notif);
229 BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif->packet);
65300d60 230 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet);
5c563278
PP
231 g_free(notif);
232}
233
234BT_HIDDEN
235void bt_notification_packet_end_recycle(struct bt_notification *notif)
236{
237 struct bt_notification_packet_end *packet_end_notif = (void *) notif;
238 struct bt_graph *graph;
239
240 BT_ASSERT(packet_end_notif);
241
242 if (!notif->graph) {
243 bt_notification_packet_end_destroy(notif);
244 return;
245 }
246
d94d92ac 247 BT_LIB_LOGD("Recycling packet end notification: %!+n", notif);
5c563278 248 bt_notification_reset(notif);
65300d60 249 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet);
5c563278
PP
250 graph = notif->graph;
251 notif->graph = NULL;
252 bt_object_pool_recycle_object(&graph->packet_end_notif_pool, notif);
78586d8a
JG
253}
254
40f4ba76
PP
255struct bt_packet *bt_private_notification_packet_end_borrow_packet(
256 struct bt_private_notification *notification)
78586d8a
JG
257{
258 struct bt_notification_packet_end *packet_end;
259
f6ccaed9
PP
260 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
261 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
262 BT_NOTIFICATION_TYPE_PACKET_END);
40f4ba76 263 packet_end = (void *) notification;
094ff7c0 264 return packet_end->packet;
78586d8a 265}
e5be10ef 266
40f4ba76
PP
267const struct bt_packet *bt_notification_packet_end_borrow_packet(
268 struct bt_notification *notification)
e5be10ef 269{
40f4ba76 270 return bt_private_notification_packet_end_borrow_packet(
e5be10ef
PP
271 (void *) notification);
272}
This page took 0.048496 seconds and 4 git commands to generate.