lib: rename bt_plugin_create_all_*() -> bt_plugin_find_all_*()
[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>
8b45963b
PP
37#include <babeltrace/assert-internal.h>
38#include <babeltrace/assert-pre-internal.h>
c5a24b0a 39#include <babeltrace/object-internal.h>
93881221 40#include <inttypes.h>
78586d8a 41
f7c3ac09 42BT_HIDDEN
e18f019b 43struct bt_notification *bt_notification_packet_beginning_new(struct bt_graph *graph)
78586d8a 44{
e18f019b 45 struct bt_notification_packet_beginning *notification;
78586d8a 46
e18f019b 47 notification = g_new0(struct bt_notification_packet_beginning, 1);
f7c3ac09
PP
48 if (!notification) {
49 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
50 goto error;
51 }
78586d8a 52
f7c3ac09 53 bt_notification_init(&notification->parent,
e18f019b
PP
54 BT_NOTIFICATION_TYPE_PACKET_BEGINNING,
55 (bt_object_release_func) bt_notification_packet_beginning_recycle,
f7c3ac09
PP
56 graph);
57 goto end;
78586d8a 58
f7c3ac09 59error:
8138bfe1 60 BT_OBJECT_PUT_REF_AND_RESET(notification);
f7c3ac09
PP
61
62end:
63 return (void *) notification;
78586d8a
JG
64}
65
e18f019b 66struct bt_notification *bt_notification_packet_beginning_create(
834e9996 67 struct bt_self_notification_iterator *self_notif_iter,
78cf9df6 68 struct bt_packet *packet)
78586d8a 69{
834e9996
PP
70 struct bt_self_component_port_input_notification_iterator *notif_iter =
71 (void *) self_notif_iter;
e18f019b 72 struct bt_notification_packet_beginning *notification = NULL;
839d52a5
PP
73 struct bt_stream *stream;
74 struct bt_stream_class *stream_class;
78586d8a 75
03e18d5d 76 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
8b45963b 77 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
839d52a5 78 stream = bt_packet_borrow_stream(packet);
8b45963b 79 BT_ASSERT(stream);
8deee039 80 stream_class = bt_stream_borrow_class(stream);
8b45963b 81 BT_ASSERT(stream_class);
834e9996
PP
82 BT_LIB_LOGD("Creating packet beginning notification object: "
83 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
84 packet, stream, stream_class);
f7c3ac09 85 notification = (void *) bt_notification_create_from_pool(
834e9996 86 &notif_iter->graph->packet_begin_notif_pool, notif_iter->graph);
93881221 87 if (!notification) {
f7c3ac09 88 /* bt_notification_create_from_pool() logs errors */
c5a24b0a 89 goto end;
93881221
PP
90 }
91
c5a24b0a
PP
92 BT_ASSERT(!notification->packet);
93 notification->packet = packet;
94 bt_object_get_no_null_check_no_parent_check(
95 &notification->packet->base);
e5815ba2 96 bt_packet_set_is_frozen(packet, true);
834e9996
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);
f7c3ac09
PP
100 goto end;
101
f7c3ac09
PP
102end:
103 return (void *) notification;
104}
105
106BT_HIDDEN
e18f019b 107void bt_notification_packet_beginning_destroy(struct bt_notification *notif)
f7c3ac09 108{
e18f019b 109 struct bt_notification_packet_beginning *packet_begin_notif = (void *) notif;
f7c3ac09 110
834e9996
PP
111 BT_LIB_LOGD("Destroying packet beginning notification: %!+n", notif);
112 BT_LIB_LOGD("Putting packet: %!+a", packet_begin_notif->packet);
8138bfe1 113 BT_OBJECT_PUT_REF_AND_RESET(packet_begin_notif->packet);
f7c3ac09
PP
114 g_free(notif);
115}
116
117BT_HIDDEN
e18f019b 118void bt_notification_packet_beginning_recycle(struct bt_notification *notif)
f7c3ac09 119{
e18f019b 120 struct bt_notification_packet_beginning *packet_begin_notif = (void *) notif;
f7c3ac09
PP
121 struct bt_graph *graph;
122
123 BT_ASSERT(packet_begin_notif);
124
c5a24b0a 125 if (unlikely(!notif->graph)) {
e18f019b 126 bt_notification_packet_beginning_destroy(notif);
f7c3ac09
PP
127 return;
128 }
129
834e9996 130 BT_LIB_LOGD("Recycling packet beginning notification: %!+n", notif);
f7c3ac09 131 bt_notification_reset(notif);
c5a24b0a
PP
132 bt_object_put_no_null_check(&packet_begin_notif->packet->base);
133 packet_begin_notif->packet = NULL;
f7c3ac09
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
e18f019b 139struct bt_packet *bt_notification_packet_beginning_borrow_packet(
7b53201c 140 struct bt_notification *notification)
78586d8a 141{
e18f019b 142 struct bt_notification_packet_beginning *packet_begin;
78586d8a 143
8b45963b
PP
144 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
145 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
e18f019b 146 BT_NOTIFICATION_TYPE_PACKET_BEGINNING);
78cf9df6 147 packet_begin = (void *) notification;
5fe68922 148 return packet_begin->packet;
78586d8a
JG
149}
150
e18f019b 151const struct bt_packet *bt_notification_packet_beginning_borrow_packet_const(
7b53201c 152 const struct bt_notification *notification)
9e550e5f 153{
e18f019b 154 return bt_notification_packet_beginning_borrow_packet(
9e550e5f
PP
155 (void *) notification);
156}
157
f7c3ac09
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:
8138bfe1 176 BT_OBJECT_PUT_REF_AND_RESET(notification);
f7c3ac09
PP
177
178end:
179 return (void *) notification;
180}
181
7b53201c 182struct bt_notification *bt_notification_packet_end_create(
834e9996 183 struct bt_self_notification_iterator *self_notif_iter,
78cf9df6 184 struct bt_packet *packet)
78586d8a 185{
834e9996
PP
186 struct bt_self_component_port_input_notification_iterator *notif_iter =
187 (void *) self_notif_iter;
e5815ba2 188 struct bt_notification_packet_end *notification = NULL;
839d52a5
PP
189 struct bt_stream *stream;
190 struct bt_stream_class *stream_class;
78586d8a 191
03e18d5d 192 BT_ASSERT_PRE_NON_NULL(notif_iter, "Notification iterator");
8b45963b 193 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
839d52a5 194 stream = bt_packet_borrow_stream(packet);
8b45963b 195 BT_ASSERT(stream);
8deee039 196 stream_class = bt_stream_borrow_class(stream);
8b45963b 197 BT_ASSERT(stream_class);
834e9996
PP
198 BT_LIB_LOGD("Creating packet end notification object: "
199 "%![packet-]+a, %![stream-]+s, %![sc-]+S",
200 packet, stream, stream_class);
f7c3ac09 201 notification = (void *) bt_notification_create_from_pool(
834e9996 202 &notif_iter->graph->packet_end_notif_pool, notif_iter->graph);
93881221 203 if (!notification) {
f7c3ac09 204 /* bt_notification_create_from_pool() logs errors */
c5a24b0a 205 goto end;
93881221
PP
206 }
207
c5a24b0a
PP
208 BT_ASSERT(!notification->packet);
209 notification->packet = packet;
210 bt_object_get_no_null_check_no_parent_check(
211 &notification->packet->base);
e5815ba2 212 bt_packet_set_is_frozen(packet, true);
834e9996
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);
f7c3ac09
PP
216 goto end;
217
f7c3ac09
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
834e9996
PP
227 BT_LIB_LOGD("Destroying packet end notification: %!+n", notif);
228 BT_LIB_LOGD("Putting packet: %!+a", packet_end_notif->packet);
8138bfe1 229 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet);
f7c3ac09
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
834e9996 246 BT_LIB_LOGD("Recycling packet end notification: %!+n", notif);
f7c3ac09 247 bt_notification_reset(notif);
8138bfe1 248 BT_OBJECT_PUT_REF_AND_RESET(packet_end_notif->packet);
f7c3ac09
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
7b53201c
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
8b45963b
PP
259 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
260 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
261 BT_NOTIFICATION_TYPE_PACKET_END);
78cf9df6 262 packet_end = (void *) notification;
5fe68922 263 return packet_end->packet;
78586d8a 264}
9e550e5f 265
7b53201c
PP
266const struct bt_packet *bt_notification_packet_end_borrow_packet_const(
267 const struct bt_notification *notification)
9e550e5f 268{
7b53201c 269 return bt_notification_packet_end_borrow_packet(
9e550e5f
PP
270 (void *) notification);
271}
This page took 0.050269 seconds and 4 git commands to generate.