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