Commit | Line | Data |
---|---|---|
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> | |
33 | #include <babeltrace/ctf-ir/stream.h> | |
34 | #include <babeltrace/ctf-ir/stream-internal.h> | |
b2e0c907 | 35 | #include <babeltrace/graph/notification-packet-internal.h> |
dbff6338 | 36 | #include <inttypes.h> |
78586d8a JG |
37 | |
38 | static | |
ea0e619e | 39 | void bt_notification_packet_begin_destroy(struct bt_object *obj) |
78586d8a | 40 | { |
ea0e619e JG |
41 | struct bt_notification_packet_begin *notification = |
42 | (struct bt_notification_packet_begin *) obj; | |
78586d8a | 43 | |
dbff6338 PP |
44 | BT_LOGD("Destroying packet beginning notification: addr=%p", |
45 | notification); | |
46 | BT_LOGD_STR("Putting packet."); | |
78586d8a JG |
47 | BT_PUT(notification->packet); |
48 | g_free(notification); | |
49 | } | |
50 | ||
51 | static | |
043e2020 | 52 | void bt_notification_packet_end_destroy(struct bt_object *obj) |
78586d8a JG |
53 | { |
54 | struct bt_notification_packet_end *notification = | |
55 | (struct bt_notification_packet_end *) obj; | |
56 | ||
dbff6338 PP |
57 | BT_LOGD("Destroying packet end notification: addr=%p", |
58 | notification); | |
59 | BT_LOGD_STR("Putting packet."); | |
78586d8a JG |
60 | BT_PUT(notification->packet); |
61 | g_free(notification); | |
62 | } | |
63 | ||
ea0e619e | 64 | struct bt_notification *bt_notification_packet_begin_create( |
78586d8a JG |
65 | struct bt_ctf_packet *packet) |
66 | { | |
ea0e619e | 67 | struct bt_notification_packet_begin *notification; |
dbff6338 PP |
68 | struct bt_ctf_stream *stream; |
69 | struct bt_ctf_stream_class *stream_class; | |
78586d8a JG |
70 | |
71 | if (!packet) { | |
dbff6338 | 72 | BT_LOGW_STR("Invalid parameter: packet is NULL."); |
78586d8a JG |
73 | goto error; |
74 | } | |
75 | ||
dbff6338 PP |
76 | stream = bt_ctf_packet_borrow_stream(packet); |
77 | assert(stream); | |
78 | stream_class = bt_ctf_stream_borrow_stream_class(stream); | |
79 | assert(stream_class); | |
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), | |
85 | stream_class, | |
86 | bt_ctf_stream_class_get_name(stream_class), | |
87 | bt_ctf_stream_class_get_id(stream_class)); | |
ea0e619e | 88 | notification = g_new0(struct bt_notification_packet_begin, 1); |
dbff6338 PP |
89 | if (!notification) { |
90 | BT_LOGE_STR("Failed to allocate one packet beginning notification."); | |
91 | goto error; | |
92 | } | |
93 | ||
78586d8a | 94 | bt_notification_init(¬ification->parent, |
ea0e619e JG |
95 | BT_NOTIFICATION_TYPE_PACKET_BEGIN, |
96 | bt_notification_packet_begin_destroy); | |
78586d8a | 97 | notification->packet = bt_get(packet); |
dbff6338 PP |
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), | |
103 | stream_class, | |
104 | bt_ctf_stream_class_get_name(stream_class), | |
105 | bt_ctf_stream_class_get_id(stream_class), notification); | |
78586d8a JG |
106 | return ¬ification->parent; |
107 | error: | |
108 | return NULL; | |
109 | } | |
110 | ||
ea0e619e | 111 | struct bt_ctf_packet *bt_notification_packet_begin_get_packet( |
78586d8a JG |
112 | struct bt_notification *notification) |
113 | { | |
ea0e619e JG |
114 | struct bt_ctf_packet *ret = NULL; |
115 | struct bt_notification_packet_begin *packet_begin; | |
78586d8a | 116 | |
dbff6338 PP |
117 | if (!notification) { |
118 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
119 | goto end; | |
120 | } | |
121 | ||
ea0e619e | 122 | if (notification->type != BT_NOTIFICATION_TYPE_PACKET_BEGIN) { |
dbff6338 PP |
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))); | |
ea0e619e JG |
127 | goto end; |
128 | } | |
129 | ||
130 | packet_begin = container_of(notification, | |
131 | struct bt_notification_packet_begin, parent); | |
132 | ret = bt_get(packet_begin->packet); | |
133 | end: | |
134 | return ret; | |
78586d8a JG |
135 | } |
136 | ||
137 | struct bt_notification *bt_notification_packet_end_create( | |
138 | struct bt_ctf_packet *packet) | |
139 | { | |
140 | struct bt_notification_packet_end *notification; | |
dbff6338 PP |
141 | struct bt_ctf_stream *stream; |
142 | struct bt_ctf_stream_class *stream_class; | |
78586d8a JG |
143 | |
144 | if (!packet) { | |
dbff6338 | 145 | BT_LOGW_STR("Invalid parameter: packet is NULL."); |
78586d8a JG |
146 | goto error; |
147 | } | |
148 | ||
dbff6338 PP |
149 | stream = bt_ctf_packet_borrow_stream(packet); |
150 | assert(stream); | |
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), | |
158 | stream_class, | |
159 | bt_ctf_stream_class_get_name(stream_class), | |
160 | bt_ctf_stream_class_get_id(stream_class)); | |
78586d8a | 161 | notification = g_new0(struct bt_notification_packet_end, 1); |
dbff6338 PP |
162 | if (!notification) { |
163 | BT_LOGE_STR("Failed to allocate one packet end notification."); | |
164 | goto error; | |
165 | } | |
166 | ||
78586d8a JG |
167 | bt_notification_init(¬ification->parent, |
168 | BT_NOTIFICATION_TYPE_PACKET_END, | |
043e2020 | 169 | bt_notification_packet_end_destroy); |
78586d8a | 170 | notification->packet = bt_get(packet); |
dbff6338 PP |
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), | |
176 | stream_class, | |
177 | bt_ctf_stream_class_get_name(stream_class), | |
178 | bt_ctf_stream_class_get_id(stream_class), notification); | |
78586d8a JG |
179 | return ¬ification->parent; |
180 | error: | |
181 | return NULL; | |
182 | } | |
183 | ||
184 | struct bt_ctf_packet *bt_notification_packet_end_get_packet( | |
185 | struct bt_notification *notification) | |
186 | { | |
ea0e619e | 187 | struct bt_ctf_packet *ret = NULL; |
78586d8a JG |
188 | struct bt_notification_packet_end *packet_end; |
189 | ||
dbff6338 PP |
190 | if (!notification) { |
191 | BT_LOGW_STR("Invalid parameter: notification is NULL."); | |
192 | goto end; | |
193 | } | |
194 | ||
ea0e619e | 195 | if (notification->type != BT_NOTIFICATION_TYPE_PACKET_END) { |
dbff6338 PP |
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))); | |
ea0e619e JG |
200 | goto end; |
201 | } | |
202 | ||
78586d8a JG |
203 | packet_end = container_of(notification, |
204 | struct bt_notification_packet_end, parent); | |
ea0e619e JG |
205 | ret = bt_get(packet_end->packet); |
206 | end: | |
207 | return ret; | |
78586d8a | 208 | } |