Rename bt_ctf_X -> bt_X, maintain backward compat. for pre-2.0 CTF writer
[babeltrace.git] / lib / graph / notification / stream.c
CommitLineData
043e2020
JG
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
90bd5941
PP
27#define BT_LOG_TAG "NOTIF-STREAM"
28#include <babeltrace/lib-logging-internal.h>
29
3d9990ac 30#include <babeltrace/compiler-internal.h>
3230ee6b 31#include <babeltrace/ctf-ir/stream-internal.h>
9d408fca 32#include <babeltrace/ctf-ir/stream-class.h>
b2e0c907 33#include <babeltrace/graph/notification-stream-internal.h>
90bd5941 34#include <inttypes.h>
043e2020
JG
35
36static
37void 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
90bd5941
PP
42 BT_LOGD("Destroying stream end notification: addr=%p",
43 notification);
44 BT_LOGD_STR("Putting stream.");
043e2020
JG
45 BT_PUT(notification->stream);
46 g_free(notification);
47}
48
49struct bt_notification *bt_notification_stream_end_create(
50842bdc 50 struct bt_stream *stream)
043e2020
JG
51{
52 struct bt_notification_stream_end *notification;
50842bdc 53 struct bt_stream_class *stream_class;
043e2020 54
90bd5941
PP
55 if (!stream) {
56 BT_LOGW_STR("Invalid parameter: stream is NULL.");
043e2020
JG
57 goto error;
58 }
59
50842bdc 60 stream_class = bt_stream_borrow_stream_class(stream);
90bd5941
PP
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,
50842bdc
PP
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));
90bd5941
PP
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,
50842bdc 78 stream, bt_stream_get_name(stream),
90bd5941 79 stream_class,
50842bdc
PP
80 bt_stream_class_get_name(stream_class),
81 bt_stream_class_get_id(stream_class));
043e2020 82 notification = g_new0(struct bt_notification_stream_end, 1);
90bd5941
PP
83 if (!notification) {
84 BT_LOGE_STR("Failed to allocate one stream end notification.");
85 goto error;
86 }
87
043e2020
JG
88 bt_notification_init(&notification->parent,
89 BT_NOTIFICATION_TYPE_STREAM_END,
90 bt_notification_stream_end_destroy);
91 notification->stream = bt_get(stream);
90bd5941
PP
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",
50842bdc 96 stream, bt_stream_get_name(stream),
90bd5941 97 stream_class,
50842bdc
PP
98 bt_stream_class_get_name(stream_class),
99 bt_stream_class_get_id(stream_class), notification);
043e2020
JG
100 return &notification->parent;
101error:
102 return NULL;
103}
104
50842bdc 105struct bt_stream *bt_notification_stream_end_get_stream(
043e2020
JG
106 struct bt_notification *notification)
107{
108 struct bt_notification_stream_end *stream_end;
50842bdc 109 struct bt_stream *stream = NULL;
90bd5941
PP
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 }
043e2020
JG
123
124 stream_end = container_of(notification,
125 struct bt_notification_stream_end, parent);
90bd5941
PP
126 stream = bt_get(stream_end->stream);
127
128end:
129 return stream;
043e2020 130}
3230ee6b
PP
131
132static
133void 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
90bd5941
PP
138 BT_LOGD("Destroying stream beginning notification: addr=%p",
139 notification);
140 BT_LOGD_STR("Putting stream.");
3230ee6b
PP
141 BT_PUT(notification->stream);
142 g_free(notification);
143}
144
145struct bt_notification *bt_notification_stream_begin_create(
50842bdc 146 struct bt_stream *stream)
3230ee6b
PP
147{
148 struct bt_notification_stream_begin *notification;
50842bdc 149 struct bt_stream_class *stream_class;
3230ee6b 150
90bd5941
PP
151 if (!stream) {
152 BT_LOGW_STR("Invalid parameter: stream is NULL.");
3230ee6b
PP
153 goto error;
154 }
155
50842bdc 156 stream_class = bt_stream_borrow_stream_class(stream);
90bd5941
PP
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,
50842bdc
PP
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));
90bd5941
PP
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,
50842bdc 174 stream, bt_stream_get_name(stream),
90bd5941 175 stream_class,
50842bdc
PP
176 bt_stream_class_get_name(stream_class),
177 bt_stream_class_get_id(stream_class));
3230ee6b 178 notification = g_new0(struct bt_notification_stream_begin, 1);
90bd5941
PP
179 if (!notification) {
180 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
181 goto error;
182 }
183
3230ee6b
PP
184 bt_notification_init(&notification->parent,
185 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
186 bt_notification_stream_begin_destroy);
187 notification->stream = bt_get(stream);
90bd5941
PP
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",
50842bdc 192 stream, bt_stream_get_name(stream),
90bd5941 193 stream_class,
50842bdc
PP
194 bt_stream_class_get_name(stream_class),
195 bt_stream_class_get_id(stream_class), notification);
3230ee6b
PP
196 return &notification->parent;
197error:
198 return NULL;
199}
200
50842bdc 201struct bt_stream *bt_notification_stream_begin_get_stream(
3230ee6b
PP
202 struct bt_notification *notification)
203{
204 struct bt_notification_stream_begin *stream_begin;
50842bdc 205 struct bt_stream *stream = NULL;
90bd5941
PP
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 }
3230ee6b
PP
219
220 stream_begin = container_of(notification,
221 struct bt_notification_stream_begin, parent);
90bd5941
PP
222 stream = bt_get(stream_begin->stream);
223
224end:
225 return stream;
3230ee6b 226}
This page took 0.04308 seconds and 4 git commands to generate.