Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / lib / graph / notification / stream.c
1 /*
2 * Babeltrace Plug-in Stream-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-STREAM"
28 #include <babeltrace/lib-logging-internal.h>
29
30 #include <babeltrace/compiler-internal.h>
31 #include <babeltrace/ctf-ir/stream-internal.h>
32 #include <babeltrace/ctf-ir/stream-class.h>
33 #include <babeltrace/graph/notification-stream-internal.h>
34 #include <inttypes.h>
35
36 static
37 void bt_notification_stream_end_destroy(struct bt_object *obj)
38 {
39 struct bt_notification_stream_end *notification =
40 (struct bt_notification_stream_end *) obj;
41
42 BT_LOGD("Destroying stream end notification: addr=%p",
43 notification);
44 BT_LOGD_STR("Putting stream.");
45 BT_PUT(notification->stream);
46 g_free(notification);
47 }
48
49 struct bt_notification *bt_notification_stream_end_create(
50 struct bt_stream *stream)
51 {
52 struct bt_notification_stream_end *notification;
53 struct bt_stream_class *stream_class;
54
55 if (!stream) {
56 BT_LOGW_STR("Invalid parameter: stream is NULL.");
57 goto error;
58 }
59
60 stream_class = bt_stream_borrow_stream_class(stream);
61 assert(stream_class);
62
63 if (stream->pos.fd >= 0) {
64 BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
65 "stream-addr=%p, stream-name=\"%s\", "
66 "stream-class-addr=%p, stream-class-name\"%s\", "
67 "stream-class-id=%" PRId64,
68 stream, bt_stream_get_name(stream), stream_class,
69 bt_stream_class_get_name(stream_class),
70 bt_stream_class_get_id(stream_class));
71 goto error;
72 }
73
74 BT_LOGD("Creating stream end notification object: "
75 "stream-addr=%p, stream-name=\"%s\", "
76 "stream-class-addr=%p, stream-class-name=\"%s\", "
77 "stream-class-id=%" PRId64,
78 stream, bt_stream_get_name(stream),
79 stream_class,
80 bt_stream_class_get_name(stream_class),
81 bt_stream_class_get_id(stream_class));
82 notification = g_new0(struct bt_notification_stream_end, 1);
83 if (!notification) {
84 BT_LOGE_STR("Failed to allocate one stream end notification.");
85 goto error;
86 }
87
88 bt_notification_init(&notification->parent,
89 BT_NOTIFICATION_TYPE_STREAM_END,
90 bt_notification_stream_end_destroy);
91 notification->stream = bt_get(stream);
92 BT_LOGD("Created stream end notification object: "
93 "stream-addr=%p, stream-name=\"%s\", "
94 "stream-class-addr=%p, stream-class-name=\"%s\", "
95 "stream-class-id=%" PRId64 ", addr=%p",
96 stream, bt_stream_get_name(stream),
97 stream_class,
98 bt_stream_class_get_name(stream_class),
99 bt_stream_class_get_id(stream_class), notification);
100 return &notification->parent;
101 error:
102 return NULL;
103 }
104
105 struct bt_stream *bt_notification_stream_end_get_stream(
106 struct bt_notification *notification)
107 {
108 struct bt_notification_stream_end *stream_end;
109 struct bt_stream *stream = NULL;
110
111 if (!notification) {
112 BT_LOGW_STR("Invalid parameter: notification is NULL.");
113 goto end;
114 }
115
116 if (notification->type != BT_NOTIFICATION_TYPE_STREAM_END) {
117 BT_LOGW("Invalid parameter: notification is not a stream end notification: "
118 "addr%p, notif-type=%s",
119 notification, bt_notification_type_string(
120 bt_notification_get_type(notification)));
121 goto end;
122 }
123
124 stream_end = container_of(notification,
125 struct bt_notification_stream_end, parent);
126 stream = bt_get(stream_end->stream);
127
128 end:
129 return stream;
130 }
131
132 static
133 void bt_notification_stream_begin_destroy(struct bt_object *obj)
134 {
135 struct bt_notification_stream_begin *notification =
136 (struct bt_notification_stream_begin *) obj;
137
138 BT_LOGD("Destroying stream beginning notification: addr=%p",
139 notification);
140 BT_LOGD_STR("Putting stream.");
141 BT_PUT(notification->stream);
142 g_free(notification);
143 }
144
145 struct bt_notification *bt_notification_stream_begin_create(
146 struct bt_stream *stream)
147 {
148 struct bt_notification_stream_begin *notification;
149 struct bt_stream_class *stream_class;
150
151 if (!stream) {
152 BT_LOGW_STR("Invalid parameter: stream is NULL.");
153 goto error;
154 }
155
156 stream_class = bt_stream_borrow_stream_class(stream);
157 assert(stream_class);
158
159 if (stream->pos.fd >= 0) {
160 BT_LOGW("Invalid parameter: stream is a CTF writer stream: "
161 "stream-addr=%p, stream-name=\"%s\", "
162 "stream-class-addr=%p, stream-class-name\"%s\", "
163 "stream-class-id=%" PRId64,
164 stream, bt_stream_get_name(stream), stream_class,
165 bt_stream_class_get_name(stream_class),
166 bt_stream_class_get_id(stream_class));
167 goto error;
168 }
169
170 BT_LOGD("Creating stream beginning notification object: "
171 "stream-addr=%p, stream-name=\"%s\", "
172 "stream-class-addr=%p, stream-class-name=\"%s\", "
173 "stream-class-id=%" PRId64,
174 stream, bt_stream_get_name(stream),
175 stream_class,
176 bt_stream_class_get_name(stream_class),
177 bt_stream_class_get_id(stream_class));
178 notification = g_new0(struct bt_notification_stream_begin, 1);
179 if (!notification) {
180 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
181 goto error;
182 }
183
184 bt_notification_init(&notification->parent,
185 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
186 bt_notification_stream_begin_destroy);
187 notification->stream = bt_get(stream);
188 BT_LOGD("Created stream beginning notification object: "
189 "stream-addr=%p, stream-name=\"%s\", "
190 "stream-class-addr=%p, stream-class-name=\"%s\", "
191 "stream-class-id=%" PRId64 ", addr=%p",
192 stream, bt_stream_get_name(stream),
193 stream_class,
194 bt_stream_class_get_name(stream_class),
195 bt_stream_class_get_id(stream_class), notification);
196 return &notification->parent;
197 error:
198 return NULL;
199 }
200
201 struct bt_stream *bt_notification_stream_begin_get_stream(
202 struct bt_notification *notification)
203 {
204 struct bt_notification_stream_begin *stream_begin;
205 struct bt_stream *stream = NULL;
206
207 if (!notification) {
208 BT_LOGW_STR("Invalid parameter: notification is NULL.");
209 goto end;
210 }
211
212 if (notification->type != BT_NOTIFICATION_TYPE_STREAM_BEGIN) {
213 BT_LOGW("Invalid parameter: notification is not a stream beginning notification: "
214 "addr%p, notif-type=%s",
215 notification, bt_notification_type_string(
216 bt_notification_get_type(notification)));
217 goto end;
218 }
219
220 stream_begin = container_of(notification,
221 struct bt_notification_stream_begin, parent);
222 stream = bt_get(stream_begin->stream);
223
224 end:
225 return stream;
226 }
This page took 0.034451 seconds and 4 git commands to generate.