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.h>
34 #include <babeltrace/ctf-ir/stream-internal.h>
35 #include <babeltrace/graph/notification-packet-internal.h>
39 void bt_notification_packet_begin_destroy(struct bt_object
*obj
)
41 struct bt_notification_packet_begin
*notification
=
42 (struct bt_notification_packet_begin
*) obj
;
44 BT_LOGD("Destroying packet beginning notification: addr=%p",
46 BT_LOGD_STR("Putting packet.");
47 BT_PUT(notification
->packet
);
52 void bt_notification_packet_end_destroy(struct bt_object
*obj
)
54 struct bt_notification_packet_end
*notification
=
55 (struct bt_notification_packet_end
*) obj
;
57 BT_LOGD("Destroying packet end notification: addr=%p",
59 BT_LOGD_STR("Putting packet.");
60 BT_PUT(notification
->packet
);
64 struct bt_notification
*bt_notification_packet_begin_create(
65 struct bt_ctf_packet
*packet
)
67 struct bt_notification_packet_begin
*notification
;
68 struct bt_ctf_stream
*stream
;
69 struct bt_ctf_stream_class
*stream_class
;
72 BT_LOGW_STR("Invalid parameter: packet is NULL.");
76 stream
= bt_ctf_packet_borrow_stream(packet
);
78 stream_class
= bt_ctf_stream_borrow_stream_class(stream
);
80 BT_LOGD("Creating packet beginning notification object: "
81 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
82 "stream-class-addr=%p, stream-class-name=\"%s\", "
83 "stream-class-id=%" PRId64
,
84 packet
, stream
, bt_ctf_stream_get_name(stream
),
86 bt_ctf_stream_class_get_name(stream_class
),
87 bt_ctf_stream_class_get_id(stream_class
));
88 notification
= g_new0(struct bt_notification_packet_begin
, 1);
90 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
94 bt_notification_init(¬ification
->parent
,
95 BT_NOTIFICATION_TYPE_PACKET_BEGIN
,
96 bt_notification_packet_begin_destroy
);
97 notification
->packet
= bt_get(packet
);
98 BT_LOGD("Created packet beginning notification object: "
99 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
100 "stream-class-addr=%p, stream-class-name=\"%s\", "
101 "stream-class-id=%" PRId64
", addr=%p",
102 packet
, stream
, bt_ctf_stream_get_name(stream
),
104 bt_ctf_stream_class_get_name(stream_class
),
105 bt_ctf_stream_class_get_id(stream_class
), notification
);
106 return ¬ification
->parent
;
111 struct bt_ctf_packet
*bt_notification_packet_begin_get_packet(
112 struct bt_notification
*notification
)
114 struct bt_ctf_packet
*ret
= NULL
;
115 struct bt_notification_packet_begin
*packet_begin
;
118 BT_LOGW_STR("Invalid parameter: notification is NULL.");
122 if (notification
->type
!= BT_NOTIFICATION_TYPE_PACKET_BEGIN
) {
123 BT_LOGW("Invalid parameter: notification is not a packet beginning notification: "
124 "addr%p, notif-type=%s",
125 notification
, bt_notification_type_string(
126 bt_notification_get_type(notification
)));
130 packet_begin
= container_of(notification
,
131 struct bt_notification_packet_begin
, parent
);
132 ret
= bt_get(packet_begin
->packet
);
137 struct bt_notification
*bt_notification_packet_end_create(
138 struct bt_ctf_packet
*packet
)
140 struct bt_notification_packet_end
*notification
;
141 struct bt_ctf_stream
*stream
;
142 struct bt_ctf_stream_class
*stream_class
;
145 BT_LOGW_STR("Invalid parameter: packet is NULL.");
149 stream
= bt_ctf_packet_borrow_stream(packet
);
151 stream_class
= bt_ctf_stream_borrow_stream_class(stream
);
152 assert(stream_class
);
153 BT_LOGD("Creating packet end notification object: "
154 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
155 "stream-class-addr=%p, stream-class-name=\"%s\", "
156 "stream-class-id=%" PRId64
,
157 packet
, stream
, bt_ctf_stream_get_name(stream
),
159 bt_ctf_stream_class_get_name(stream_class
),
160 bt_ctf_stream_class_get_id(stream_class
));
161 notification
= g_new0(struct bt_notification_packet_end
, 1);
163 BT_LOGE_STR("Failed to allocate one packet end notification.");
167 bt_notification_init(¬ification
->parent
,
168 BT_NOTIFICATION_TYPE_PACKET_END
,
169 bt_notification_packet_end_destroy
);
170 notification
->packet
= bt_get(packet
);
171 BT_LOGD("Created packet end notification object: "
172 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
173 "stream-class-addr=%p, stream-class-name=\"%s\", "
174 "stream-class-id=%" PRId64
", addr=%p",
175 packet
, stream
, bt_ctf_stream_get_name(stream
),
177 bt_ctf_stream_class_get_name(stream_class
),
178 bt_ctf_stream_class_get_id(stream_class
), notification
);
179 return ¬ification
->parent
;
184 struct bt_ctf_packet
*bt_notification_packet_end_get_packet(
185 struct bt_notification
*notification
)
187 struct bt_ctf_packet
*ret
= NULL
;
188 struct bt_notification_packet_end
*packet_end
;
191 BT_LOGW_STR("Invalid parameter: notification is NULL.");
195 if (notification
->type
!= BT_NOTIFICATION_TYPE_PACKET_END
) {
196 BT_LOGW("Invalid parameter: notification is not a packet end notification: "
197 "addr%p, notif-type=%s",
198 notification
, bt_notification_type_string(
199 bt_notification_get_type(notification
)));
203 packet_end
= container_of(notification
,
204 struct bt_notification_packet_end
, parent
);
205 ret
= bt_get(packet_end
->packet
);