Split CTF IR and CTF writer APIs and implementations
[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>
f6ccaed9
PP
37#include <babeltrace/assert-internal.h>
38#include <babeltrace/assert-pre-internal.h>
dbff6338 39#include <inttypes.h>
78586d8a
JG
40
41static
ea0e619e 42void bt_notification_packet_begin_destroy(struct bt_object *obj)
78586d8a 43{
ea0e619e
JG
44 struct bt_notification_packet_begin *notification =
45 (struct bt_notification_packet_begin *) obj;
78586d8a 46
dbff6338
PP
47 BT_LOGD("Destroying packet beginning notification: addr=%p",
48 notification);
49 BT_LOGD_STR("Putting packet.");
78586d8a
JG
50 BT_PUT(notification->packet);
51 g_free(notification);
52}
53
54static
043e2020 55void bt_notification_packet_end_destroy(struct bt_object *obj)
78586d8a
JG
56{
57 struct bt_notification_packet_end *notification =
58 (struct bt_notification_packet_end *) obj;
59
dbff6338
PP
60 BT_LOGD("Destroying packet end notification: addr=%p",
61 notification);
62 BT_LOGD_STR("Putting packet.");
78586d8a
JG
63 BT_PUT(notification->packet);
64 g_free(notification);
65}
66
ea0e619e 67struct bt_notification *bt_notification_packet_begin_create(
50842bdc 68 struct bt_packet *packet)
78586d8a 69{
ea0e619e 70 struct bt_notification_packet_begin *notification;
50842bdc
PP
71 struct bt_stream *stream;
72 struct bt_stream_class *stream_class;
78586d8a 73
f6ccaed9 74 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
50842bdc 75 stream = bt_packet_borrow_stream(packet);
f6ccaed9 76 BT_ASSERT(stream);
3dca2276 77 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 78 BT_ASSERT(stream_class);
dbff6338
PP
79 BT_LOGD("Creating packet beginning notification object: "
80 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
81 "stream-class-addr=%p, stream-class-name=\"%s\", "
82 "stream-class-id=%" PRId64,
50842bdc 83 packet, stream, bt_stream_get_name(stream),
dbff6338 84 stream_class,
50842bdc
PP
85 bt_stream_class_get_name(stream_class),
86 bt_stream_class_get_id(stream_class));
ea0e619e 87 notification = g_new0(struct bt_notification_packet_begin, 1);
dbff6338
PP
88 if (!notification) {
89 BT_LOGE_STR("Failed to allocate one packet beginning notification.");
90 goto error;
91 }
92
78586d8a 93 bt_notification_init(&notification->parent,
ea0e619e
JG
94 BT_NOTIFICATION_TYPE_PACKET_BEGIN,
95 bt_notification_packet_begin_destroy);
78586d8a 96 notification->packet = bt_get(packet);
dbff6338
PP
97 BT_LOGD("Created packet beginning notification object: "
98 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
99 "stream-class-addr=%p, stream-class-name=\"%s\", "
100 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 101 packet, stream, bt_stream_get_name(stream),
dbff6338 102 stream_class,
50842bdc
PP
103 bt_stream_class_get_name(stream_class),
104 bt_stream_class_get_id(stream_class), notification);
78586d8a
JG
105 return &notification->parent;
106error:
107 return NULL;
108}
109
50842bdc 110struct bt_packet *bt_notification_packet_begin_get_packet(
78586d8a
JG
111 struct bt_notification *notification)
112{
ea0e619e 113 struct bt_notification_packet_begin *packet_begin;
78586d8a 114
f6ccaed9
PP
115 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
116 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
117 BT_NOTIFICATION_TYPE_PACKET_BEGIN);
ea0e619e
JG
118 packet_begin = container_of(notification,
119 struct bt_notification_packet_begin, parent);
f6ccaed9 120 return bt_get(packet_begin->packet);
78586d8a
JG
121}
122
123struct bt_notification *bt_notification_packet_end_create(
50842bdc 124 struct bt_packet *packet)
78586d8a
JG
125{
126 struct bt_notification_packet_end *notification;
50842bdc
PP
127 struct bt_stream *stream;
128 struct bt_stream_class *stream_class;
78586d8a 129
f6ccaed9 130 BT_ASSERT_PRE_NON_NULL(packet, "Packet");
50842bdc 131 stream = bt_packet_borrow_stream(packet);
f6ccaed9 132 BT_ASSERT(stream);
3dca2276 133 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 134 BT_ASSERT(stream_class);
dbff6338
PP
135 BT_LOGD("Creating packet end notification object: "
136 "packet-addr=%p, stream-addr=%p, stream-name=\"%s\", "
137 "stream-class-addr=%p, stream-class-name=\"%s\", "
138 "stream-class-id=%" PRId64,
50842bdc 139 packet, stream, bt_stream_get_name(stream),
dbff6338 140 stream_class,
50842bdc
PP
141 bt_stream_class_get_name(stream_class),
142 bt_stream_class_get_id(stream_class));
78586d8a 143 notification = g_new0(struct bt_notification_packet_end, 1);
dbff6338
PP
144 if (!notification) {
145 BT_LOGE_STR("Failed to allocate one packet end notification.");
146 goto error;
147 }
148
78586d8a
JG
149 bt_notification_init(&notification->parent,
150 BT_NOTIFICATION_TYPE_PACKET_END,
043e2020 151 bt_notification_packet_end_destroy);
78586d8a 152 notification->packet = bt_get(packet);
dbff6338
PP
153 BT_LOGD("Created 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 ", addr=%p",
50842bdc 157 packet, stream, bt_stream_get_name(stream),
dbff6338 158 stream_class,
50842bdc
PP
159 bt_stream_class_get_name(stream_class),
160 bt_stream_class_get_id(stream_class), notification);
78586d8a
JG
161 return &notification->parent;
162error:
163 return NULL;
164}
165
50842bdc 166struct bt_packet *bt_notification_packet_end_get_packet(
78586d8a
JG
167 struct bt_notification *notification)
168{
169 struct bt_notification_packet_end *packet_end;
170
f6ccaed9
PP
171 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
172 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
173 BT_NOTIFICATION_TYPE_PACKET_END);
78586d8a
JG
174 packet_end = container_of(notification,
175 struct bt_notification_packet_end, parent);
f6ccaed9 176 return bt_get(packet_end->packet);
78586d8a 177}
This page took 0.04242 seconds and 4 git commands to generate.