2 * Babeltrace Plug-in Packet-related Notifications
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
27 #define BT_LOG_TAG "NOTIF-PACKET"
28 #include <babeltrace/lib-logging-internal.h>
30 #include <babeltrace/compiler-internal.h>
31 #include <babeltrace/ctf-ir/packet.h>
32 #include <babeltrace/ctf-ir/packet-internal.h>
33 #include <babeltrace/ctf-ir/stream-class.h>
34 #include <babeltrace/ctf-ir/stream.h>
35 #include <babeltrace/ctf-ir/stream-internal.h>
36 #include <babeltrace/graph/notification-packet-internal.h>
40 void bt_notification_packet_begin_destroy(struct bt_object
*obj
)
42 struct bt_notification_packet_begin
*notification
=
43 (struct bt_notification_packet_begin
*) obj
;
45 BT_LOGD("Destroying packet beginning notification: addr=%p",
47 BT_LOGD_STR("Putting packet.");
48 BT_PUT(notification
->packet
);
53 void bt_notification_packet_end_destroy(struct bt_object
*obj
)
55 struct bt_notification_packet_end
*notification
=
56 (struct bt_notification_packet_end
*) obj
;
58 BT_LOGD("Destroying packet end notification: addr=%p",
60 BT_LOGD_STR("Putting packet.");
61 BT_PUT(notification
->packet
);
65 struct bt_notification
*bt_notification_packet_begin_create(
66 struct bt_packet
*packet
)
68 struct bt_notification_packet_begin
*notification
;
69 struct bt_stream
*stream
;
70 struct bt_stream_class
*stream_class
;
73 BT_LOGW_STR("Invalid parameter: packet is NULL.");
77 stream
= bt_packet_borrow_stream(packet
);
79 stream_class
= bt_stream_borrow_stream_class(stream
);
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
,
85 packet
, stream
, bt_stream_get_name(stream
),
87 bt_stream_class_get_name(stream_class
),
88 bt_stream_class_get_id(stream_class
));
89 notification
= g_new0(struct bt_notification_packet_begin
, 1);
91 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
95 bt_notification_init(¬ification
->parent
,
96 BT_NOTIFICATION_TYPE_PACKET_BEGIN
,
97 bt_notification_packet_begin_destroy
);
98 notification
->packet
= bt_get(packet
);
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",
103 packet
, stream
, bt_stream_get_name(stream
),
105 bt_stream_class_get_name(stream_class
),
106 bt_stream_class_get_id(stream_class
), notification
);
107 return ¬ification
->parent
;
112 struct bt_packet
*bt_notification_packet_begin_get_packet(
113 struct bt_notification
*notification
)
115 struct bt_packet
*ret
= NULL
;
116 struct bt_notification_packet_begin
*packet_begin
;
119 BT_LOGW_STR("Invalid parameter: notification is NULL.");
123 if (notification
->type
!= BT_NOTIFICATION_TYPE_PACKET_BEGIN
) {
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
)));
131 packet_begin
= container_of(notification
,
132 struct bt_notification_packet_begin
, parent
);
133 ret
= bt_get(packet_begin
->packet
);
138 struct bt_notification
*bt_notification_packet_end_create(
139 struct bt_packet
*packet
)
141 struct bt_notification_packet_end
*notification
;
142 struct bt_stream
*stream
;
143 struct bt_stream_class
*stream_class
;
146 BT_LOGW_STR("Invalid parameter: packet is NULL.");
150 stream
= bt_packet_borrow_stream(packet
);
152 stream_class
= bt_stream_borrow_stream_class(stream
);
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
,
158 packet
, stream
, bt_stream_get_name(stream
),
160 bt_stream_class_get_name(stream_class
),
161 bt_stream_class_get_id(stream_class
));
162 notification
= g_new0(struct bt_notification_packet_end
, 1);
164 BT_LOGE_STR("Failed to allocate one packet end notification.");
168 bt_notification_init(¬ification
->parent
,
169 BT_NOTIFICATION_TYPE_PACKET_END
,
170 bt_notification_packet_end_destroy
);
171 notification
->packet
= bt_get(packet
);
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",
176 packet
, stream
, bt_stream_get_name(stream
),
178 bt_stream_class_get_name(stream_class
),
179 bt_stream_class_get_id(stream_class
), notification
);
180 return ¬ification
->parent
;
185 struct bt_packet
*bt_notification_packet_end_get_packet(
186 struct bt_notification
*notification
)
188 struct bt_packet
*ret
= NULL
;
189 struct bt_notification_packet_end
*packet_end
;
192 BT_LOGW_STR("Invalid parameter: notification is NULL.");
196 if (notification
->type
!= BT_NOTIFICATION_TYPE_PACKET_END
) {
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
)));
204 packet_end
= container_of(notification
,
205 struct bt_notification_packet_end
, parent
);
206 ret
= bt_get(packet_end
->packet
);