lib: update copyrights
[babeltrace.git] / lib / graph / notification / packet.c
CommitLineData
78586d8a 1/*
f2b0325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
78586d8a
JG
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
78586d8a
JG
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
93881221
PP
24#define BT_LOG_TAG "NOTIF-PACKET"
25#include <babeltrace/lib-logging-internal.h>
26
3d9990ac 27#include <babeltrace/compiler-internal.h>
108b91d0
PP
28#include <babeltrace/trace-ir/packet.h>
29#include <babeltrace/trace-ir/packet-internal.h>
30#include <babeltrace/trace-ir/stream-class.h>
31#include <babeltrace/trace-ir/stream.h>
32#include <babeltrace/trace-ir/stream-internal.h>
f7c3ac09 33#include <babeltrace/graph/graph-internal.h>
7b53201c
PP
34#include <babeltrace/graph/notification-packet-const.h>
35#include <babeltrace/graph/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 43BT_HIDDEN
e18f019b 44struct bt_notification *bt_notification_packet_beginning_new(struct bt_graph *graph)
78586d8a 45{
e18f019b 46 struct bt_notification_packet_beginning *notification;
78586d8a 47
e18f019b 48 notification = g_new0(struct bt_notification_packet_beginning, 1);
f7c3ac09
PP
49 if (!notification) {
50 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
51 goto error;
52 }
78586d8a 53
f7c3ac09 54 bt_notification_init(&notification->parent,
e18f019b
PP
55 BT_NOTIFICATION_TYPE_PACKET_BEGINNING,
56 (bt_object_release_func) bt_notification_packet_beginning_recycle,
f7c3ac09
PP
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
e18f019b 67struct bt_notification *bt_notification_packet_beginning_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;
e18f019b 73 struct bt_notification_packet_beginning *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
e18f019b 108void bt_notification_packet_beginning_destroy(struct bt_notification *notif)
f7c3ac09 109{
e18f019b 110 struct bt_notification_packet_beginning *packet_begin_notif = (void *) notif;
f7c3ac09 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
e18f019b 119void bt_notification_packet_beginning_recycle(struct bt_notification *notif)
f7c3ac09 120{
e18f019b 121 struct bt_notification_packet_beginning *packet_begin_notif = (void *) notif;
f7c3ac09
PP
122 struct bt_graph *graph;
123
124 BT_ASSERT(packet_begin_notif);
125
c5a24b0a 126 if (unlikely(!notif->graph)) {
e18f019b 127 bt_notification_packet_beginning_destroy(notif);
f7c3ac09
PP
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
e18f019b 140struct bt_packet *bt_notification_packet_beginning_borrow_packet(
7b53201c 141 struct bt_notification *notification)
78586d8a 142{
e18f019b 143 struct bt_notification_packet_beginning *packet_begin;
78586d8a 144
8b45963b
PP
145 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
146 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
e18f019b 147 BT_NOTIFICATION_TYPE_PACKET_BEGINNING);
78cf9df6 148 packet_begin = (void *) notification;
5fe68922 149 return packet_begin->packet;
78586d8a
JG
150}
151
e18f019b 152const struct bt_packet *bt_notification_packet_beginning_borrow_packet_const(
7b53201c 153 const struct bt_notification *notification)
9e550e5f 154{
e18f019b 155 return bt_notification_packet_beginning_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
7b53201c 183struct bt_notification *bt_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
7b53201c
PP
255struct bt_packet *bt_notification_packet_end_borrow_packet(
256 struct bt_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
7b53201c
PP
267const struct bt_packet *bt_notification_packet_end_borrow_packet_const(
268 const struct bt_notification *notification)
9e550e5f 269{
7b53201c 270 return bt_notification_packet_end_borrow_packet(
9e550e5f
PP
271 (void *) notification);
272}
This page took 0.050128 seconds and 4 git commands to generate.