lib/graph/notification/packet.c: add logging
[babeltrace.git] / lib / graph / notification / packet.c
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
27 #define BT_LOG_TAG "NOTIF-PACKET"
28 #include <babeltrace/lib-logging-internal.h>
29
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>
36 #include <inttypes.h>
37
38 static
39 void bt_notification_packet_begin_destroy(struct bt_object *obj)
40 {
41 struct bt_notification_packet_begin *notification =
42 (struct bt_notification_packet_begin *) obj;
43
44 BT_LOGD("Destroying packet beginning notification: addr=%p",
45 notification);
46 BT_LOGD_STR("Putting packet.");
47 BT_PUT(notification->packet);
48 g_free(notification);
49 }
50
51 static
52 void bt_notification_packet_end_destroy(struct bt_object *obj)
53 {
54 struct bt_notification_packet_end *notification =
55 (struct bt_notification_packet_end *) obj;
56
57 BT_LOGD("Destroying packet end notification: addr=%p",
58 notification);
59 BT_LOGD_STR("Putting packet.");
60 BT_PUT(notification->packet);
61 g_free(notification);
62 }
63
64 struct bt_notification *bt_notification_packet_begin_create(
65 struct bt_ctf_packet *packet)
66 {
67 struct bt_notification_packet_begin *notification;
68 struct bt_ctf_stream *stream;
69 struct bt_ctf_stream_class *stream_class;
70
71 if (!packet) {
72 BT_LOGW_STR("Invalid parameter: packet is NULL.");
73 goto error;
74 }
75
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));
88 notification = g_new0(struct bt_notification_packet_begin, 1);
89 if (!notification) {
90 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
91 goto error;
92 }
93
94 bt_notification_init(&notification->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),
103 stream_class,
104 bt_ctf_stream_class_get_name(stream_class),
105 bt_ctf_stream_class_get_id(stream_class), notification);
106 return &notification->parent;
107 error:
108 return NULL;
109 }
110
111 struct bt_ctf_packet *bt_notification_packet_begin_get_packet(
112 struct bt_notification *notification)
113 {
114 struct bt_ctf_packet *ret = NULL;
115 struct bt_notification_packet_begin *packet_begin;
116
117 if (!notification) {
118 BT_LOGW_STR("Invalid parameter: notification is NULL.");
119 goto end;
120 }
121
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)));
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;
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;
141 struct bt_ctf_stream *stream;
142 struct bt_ctf_stream_class *stream_class;
143
144 if (!packet) {
145 BT_LOGW_STR("Invalid parameter: packet is NULL.");
146 goto error;
147 }
148
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));
161 notification = g_new0(struct bt_notification_packet_end, 1);
162 if (!notification) {
163 BT_LOGE_STR("Failed to allocate one packet end notification.");
164 goto error;
165 }
166
167 bt_notification_init(&notification->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),
176 stream_class,
177 bt_ctf_stream_class_get_name(stream_class),
178 bt_ctf_stream_class_get_id(stream_class), notification);
179 return &notification->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 {
187 struct bt_ctf_packet *ret = NULL;
188 struct bt_notification_packet_end *packet_end;
189
190 if (!notification) {
191 BT_LOGW_STR("Invalid parameter: notification is NULL.");
192 goto end;
193 }
194
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)));
200 goto end;
201 }
202
203 packet_end = container_of(notification,
204 struct bt_notification_packet_end, parent);
205 ret = bt_get(packet_end->packet);
206 end:
207 return ret;
208 }
This page took 0.038701 seconds and 5 git commands to generate.