Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / lib / graph / notification / packet.c
CommitLineData
78586d8a
JG
1/*
2 * Babeltrace Plug-in Packet-related Notifications
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
dbff6338
PP
27#define BT_LOG_TAG "NOTIF-PACKET"
28#include <babeltrace/lib-logging-internal.h>
29
3d9990ac 30#include <babeltrace/compiler-internal.h>
dbff6338
PP
31#include <babeltrace/ctf-ir/packet.h>
32#include <babeltrace/ctf-ir/packet-internal.h>
9d408fca 33#include <babeltrace/ctf-ir/stream-class.h>
dbff6338
PP
34#include <babeltrace/ctf-ir/stream.h>
35#include <babeltrace/ctf-ir/stream-internal.h>
b2e0c907 36#include <babeltrace/graph/notification-packet-internal.h>
dbff6338 37#include <inttypes.h>
78586d8a
JG
38
39static
ea0e619e 40void bt_notification_packet_begin_destroy(struct bt_object *obj)
78586d8a 41{
ea0e619e
JG
42 struct bt_notification_packet_begin *notification =
43 (struct bt_notification_packet_begin *) obj;
78586d8a 44
dbff6338
PP
45 BT_LOGD("Destroying packet beginning notification: addr=%p",
46 notification);
47 BT_LOGD_STR("Putting packet.");
78586d8a
JG
48 BT_PUT(notification->packet);
49 g_free(notification);
50}
51
52static
043e2020 53void bt_notification_packet_end_destroy(struct bt_object *obj)
78586d8a
JG
54{
55 struct bt_notification_packet_end *notification =
56 (struct bt_notification_packet_end *) obj;
57
dbff6338
PP
58 BT_LOGD("Destroying packet end notification: addr=%p",
59 notification);
60 BT_LOGD_STR("Putting packet.");
78586d8a
JG
61 BT_PUT(notification->packet);
62 g_free(notification);
63}
64
ea0e619e 65struct bt_notification *bt_notification_packet_begin_create(
50842bdc 66 struct bt_packet *packet)
78586d8a 67{
ea0e619e 68 struct bt_notification_packet_begin *notification;
50842bdc
PP
69 struct bt_stream *stream;
70 struct bt_stream_class *stream_class;
78586d8a
JG
71
72 if (!packet) {
dbff6338 73 BT_LOGW_STR("Invalid parameter: packet is NULL.");
78586d8a
JG
74 goto error;
75 }
76
50842bdc 77 stream = bt_packet_borrow_stream(packet);
dbff6338 78 assert(stream);
50842bdc 79 stream_class = bt_stream_borrow_stream_class(stream);
dbff6338
PP
80 assert(stream_class);
81 BT_LOGD("Creating packet beginning notification object: "
82 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
83 "stream-class-addr=%p, stream-class-name=\"%s\", "
84 "stream-class-id=%" PRId64,
50842bdc 85 packet, stream, bt_stream_get_name(stream),
dbff6338 86 stream_class,
50842bdc
PP
87 bt_stream_class_get_name(stream_class),
88 bt_stream_class_get_id(stream_class));
ea0e619e 89 notification = g_new0(struct bt_notification_packet_begin, 1);
dbff6338
PP
90 if (!notification) {
91 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
92 goto error;
93 }
94
78586d8a 95 bt_notification_init(&notification->parent,
ea0e619e
JG
96 BT_NOTIFICATION_TYPE_PACKET_BEGIN,
97 bt_notification_packet_begin_destroy);
78586d8a 98 notification->packet = bt_get(packet);
dbff6338
PP
99 BT_LOGD("Created packet beginning notification object: "
100 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
101 "stream-class-addr=%p, stream-class-name=\"%s\", "
102 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 103 packet, stream, bt_stream_get_name(stream),
dbff6338 104 stream_class,
50842bdc
PP
105 bt_stream_class_get_name(stream_class),
106 bt_stream_class_get_id(stream_class), notification);
78586d8a
JG
107 return &notification->parent;
108error:
109 return NULL;
110}
111
50842bdc 112struct bt_packet *bt_notification_packet_begin_get_packet(
78586d8a
JG
113 struct bt_notification *notification)
114{
50842bdc 115 struct bt_packet *ret = NULL;
ea0e619e 116 struct bt_notification_packet_begin *packet_begin;
78586d8a 117
dbff6338
PP
118 if (!notification) {
119 BT_LOGW_STR("Invalid parameter: notification is NULL.");
120 goto end;
121 }
122
ea0e619e 123 if (notification->type != BT_NOTIFICATION_TYPE_PACKET_BEGIN) {
dbff6338
PP
124 BT_LOGW("Invalid parameter: notification is not a packet beginning notification: "
125 "addr%p, notif-type=%s",
126 notification, bt_notification_type_string(
127 bt_notification_get_type(notification)));
ea0e619e
JG
128 goto end;
129 }
130
131 packet_begin = container_of(notification,
132 struct bt_notification_packet_begin, parent);
133 ret = bt_get(packet_begin->packet);
134end:
135 return ret;
78586d8a
JG
136}
137
138struct bt_notification *bt_notification_packet_end_create(
50842bdc 139 struct bt_packet *packet)
78586d8a
JG
140{
141 struct bt_notification_packet_end *notification;
50842bdc
PP
142 struct bt_stream *stream;
143 struct bt_stream_class *stream_class;
78586d8a
JG
144
145 if (!packet) {
dbff6338 146 BT_LOGW_STR("Invalid parameter: packet is NULL.");
78586d8a
JG
147 goto error;
148 }
149
50842bdc 150 stream = bt_packet_borrow_stream(packet);
dbff6338 151 assert(stream);
50842bdc 152 stream_class = bt_stream_borrow_stream_class(stream);
dbff6338
PP
153 assert(stream_class);
154 BT_LOGD("Creating packet end notification object: "
155 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
156 "stream-class-addr=%p, stream-class-name=\"%s\", "
157 "stream-class-id=%" PRId64,
50842bdc 158 packet, stream, bt_stream_get_name(stream),
dbff6338 159 stream_class,
50842bdc
PP
160 bt_stream_class_get_name(stream_class),
161 bt_stream_class_get_id(stream_class));
78586d8a 162 notification = g_new0(struct bt_notification_packet_end, 1);
dbff6338
PP
163 if (!notification) {
164 BT_LOGE_STR("Failed to allocate one packet end notification.");
165 goto error;
166 }
167
78586d8a
JG
168 bt_notification_init(&notification->parent,
169 BT_NOTIFICATION_TYPE_PACKET_END,
043e2020 170 bt_notification_packet_end_destroy);
78586d8a 171 notification->packet = bt_get(packet);
dbff6338
PP
172 BT_LOGD("Created packet end notification object: "
173 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
174 "stream-class-addr=%p, stream-class-name=\"%s\", "
175 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 176 packet, stream, bt_stream_get_name(stream),
dbff6338 177 stream_class,
50842bdc
PP
178 bt_stream_class_get_name(stream_class),
179 bt_stream_class_get_id(stream_class), notification);
78586d8a
JG
180 return &notification->parent;
181error:
182 return NULL;
183}
184
50842bdc 185struct bt_packet *bt_notification_packet_end_get_packet(
78586d8a
JG
186 struct bt_notification *notification)
187{
50842bdc 188 struct bt_packet *ret = NULL;
78586d8a
JG
189 struct bt_notification_packet_end *packet_end;
190
dbff6338
PP
191 if (!notification) {
192 BT_LOGW_STR("Invalid parameter: notification is NULL.");
193 goto end;
194 }
195
ea0e619e 196 if (notification->type != BT_NOTIFICATION_TYPE_PACKET_END) {
dbff6338
PP
197 BT_LOGW("Invalid parameter: notification is not a packet end notification: "
198 "addr%p, notif-type=%s",
199 notification, bt_notification_type_string(
200 bt_notification_get_type(notification)));
ea0e619e
JG
201 goto end;
202 }
203
78586d8a
JG
204 packet_end = container_of(notification,
205 struct bt_notification_packet_end, parent);
ea0e619e
JG
206 ret = bt_get(packet_end->packet);
207end:
208 return ret;
78586d8a 209}
This page took 0.046725 seconds and 4 git commands to generate.