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
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>
9e550e5f 37#include <babeltrace/object.h>
8b45963b
PP
38#include <babeltrace/assert-internal.h>
39#include <babeltrace/assert-pre-internal.h>
c5a24b0a 40#include <babeltrace/object-internal.h>
93881221 41#include <inttypes.h>
78586d8a 42
f7c3ac09
PP
43BT_HIDDEN
44struct bt_notification *bt_notification_packet_begin_new(struct bt_graph *graph)
78586d8a 45{
f7c3ac09 46 struct bt_notification_packet_begin *notification;
78586d8a 47
f7c3ac09
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
f7c3ac09
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
f7c3ac09 60error:
8138bfe1 61 BT_OBJECT_PUT_REF_AND_RESET(notification);
f7c3ac09
PP
62
63end:
64 return (void *) notification;
78586d8a
JG
65}
66
9e550e5f 67struct bt_private_notification *bt_private_notification_packet_begin_create(
834e9996 68 struct bt_self_notification_iterator *self_notif_iter,
78cf9df6 69 struct bt_packet *packet)
78586d8a 70{
834e9996
PP
71 struct bt_self_component_port_input_notification_iterator *notif_iter =
72 (void *) self_notif_iter;
e5815ba2 73 struct bt_notification_packet_begin *notification = NULL;
839d52a5
PP
74 struct bt_stream *stream;
75 struct bt_stream_class *stream_class;
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);
834e9996
PP
83 BT_LIB_LOGD("Creating packet beginning notification object: "
84 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
85 packet, stream, stream_class);
f7c3ac09 86 notification = (void *) bt_notification_create_from_pool(
834e9996 87 &notif_iter->graph->packet_begin_notif_pool, notif_iter->graph);
93881221 88 if (!notification) {
f7c3ac09 89 /* bt_notification_create_from_pool() logs errors */
c5a24b0a 90 goto end;
93881221
PP
91 }
92
c5a24b0a
PP
93 BT_ASSERT(!notification->packet);
94 notification->packet = packet;
95 bt_object_get_no_null_check_no_parent_check(
96 &notification->packet->base);
e5815ba2 97 bt_packet_set_is_frozen(packet, true);
834e9996
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);
f7c3ac09
PP
101 goto end;
102
f7c3ac09
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
834e9996
PP
112 BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif);
113 BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif->packet);
8138bfe1 114 BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet);
f7c3ac09
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
c5a24b0a 126 if (unlikely(!notif->graph)) {
f7c3ac09
PP
127 bt_notification_packet_begin_destroy(notif);
128 return;
129 }
130
834e9996 131 BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif);
f7c3ac09 132 bt_notification_reset(notif);
c5a24b0a
PP
133 bt_object_put_no_null_check(&packet_begin_notif->packet->base);
134 packet_begin_notif->packet = NULL;
f7c3ac09
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
78cf9df6
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
8b45963b
PP
145 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
146 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
147 BT_NOTIFICATION_TYPE_PACKET_BEGIN);
78cf9df6 148 packet_begin = (void *) notification;
5fe68922 149 return packet_begin->packet;
78586d8a
JG
150}
151
78cf9df6
PP
152const struct bt_packet *bt_notification_packet_begin_borrow_packet(
153 struct bt_notification *notification)
9e550e5f 154{
78cf9df6 155 return bt_private_notification_packet_begin_borrow_packet(
9e550e5f
PP
156 (void *) notification);
157}
158
f7c3ac09
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:
8138bfe1 177 BT_OBJECT_PUT_REF_AND_RESET(notification);
f7c3ac09
PP
178
179end:
180 return (void *) notification;
181}
182
9e550e5f 183struct bt_private_notification *bt_private_notification_packet_end_create(
834e9996 184 struct bt_self_notification_iterator *self_notif_iter,
78cf9df6 185 struct bt_packet *packet)
78586d8a 186{
834e9996
PP
187 struct bt_self_component_port_input_notification_iterator *notif_iter =
188 (void *) self_notif_iter;
e5815ba2 189 struct bt_notification_packet_end *notification = NULL;
839d52a5
PP
190 struct bt_stream *stream;
191 struct bt_stream_class *stream_class;
78586d8a 192
03e18d5d 193 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
8b45963b 194 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
839d52a5 195 stream = bt_packet_borrow_stream(packet);
8b45963b 196 BT_ASSERT(stream);
8deee039 197 stream_class = bt_stream_borrow_class(stream);
8b45963b 198 BT_ASSERT(stream_class);
834e9996
PP
199 BT_LIB_LOGD("Creating packet end notification object: "
200 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
201 packet, stream, stream_class);
f7c3ac09 202 notification = (void *) bt_notification_create_from_pool(
834e9996 203 &notif_iter->graph->packet_end_notif_pool, notif_iter->graph);
93881221 204 if (!notification) {
f7c3ac09 205 /* bt_notification_create_from_pool() logs errors */
c5a24b0a 206 goto end;
93881221
PP
207 }
208
c5a24b0a
PP
209 BT_ASSERT(!notification->packet);
210 notification->packet = packet;
211 bt_object_get_no_null_check_no_parent_check(
212 &notification->packet->base);
e5815ba2 213 bt_packet_set_is_frozen(packet, true);
834e9996
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);
f7c3ac09
PP
217 goto end;
218
f7c3ac09
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
834e9996
PP
228 BT_LIB_LOGD("Destroying packet end notification: %!+n", notif);
229 BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif->packet);
8138bfe1 230 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet);
f7c3ac09
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
834e9996 247 BT_LIB_LOGD("Recycling packet end notification: %!+n", notif);
f7c3ac09 248 bt_notification_reset(notif);
8138bfe1 249 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet);
f7c3ac09
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
78cf9df6
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
8b45963b
PP
260 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
261 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
262 BT_NOTIFICATION_TYPE_PACKET_END);
78cf9df6 263 packet_end = (void *) notification;
5fe68922 264 return packet_end->packet;
78586d8a 265}
9e550e5f 266
78cf9df6
PP
267const struct bt_packet *bt_notification_packet_end_borrow_packet(
268 struct bt_notification *notification)
9e550e5f 269{
78cf9df6 270 return bt_private_notification_packet_end_borrow_packet(
9e550e5f
PP
271 (void *) notification);
272}
This page took 0.047605 seconds and 4 git commands to generate.