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