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