Make API CTF-agnostic
[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
e22b45d0 30#include <babeltrace/assert-pre-internal.h>
3d9990ac 31#include <babeltrace/compiler-internal.h>
3230ee6b 32#include <babeltrace/ctf-ir/stream-internal.h>
9d408fca 33#include <babeltrace/ctf-ir/stream-class.h>
44c440bc 34#include <babeltrace/ctf-ir/stream-class-internal.h>
b2e0c907 35#include <babeltrace/graph/notification-stream-internal.h>
f0010051 36#include <babeltrace/graph/private-connection-private-notification-iterator.h>
f6ccaed9 37#include <babeltrace/assert-internal.h>
90bd5941 38#include <inttypes.h>
043e2020
JG
39
40static
41void bt_notification_stream_end_destroy(struct bt_object *obj)
42{
43 struct bt_notification_stream_end *notification =
44 (struct bt_notification_stream_end *) obj;
45
90bd5941
PP
46 BT_LOGD("Destroying stream end notification: addr=%p",
47 notification);
48 BT_LOGD_STR("Putting stream.");
043e2020 49 BT_PUT(notification->stream);
44c440bc
PP
50
51 if (notification->default_cv) {
52 bt_clock_value_recycle(notification->default_cv);
53 }
54
043e2020
JG
55 g_free(notification);
56}
57
58struct bt_notification *bt_notification_stream_end_create(
f0010051
PP
59 struct bt_private_connection_private_notification_iterator *notif_iter,
60 struct bt_stream *stream)
043e2020
JG
61{
62 struct bt_notification_stream_end *notification;
50842bdc 63 struct bt_stream_class *stream_class;
043e2020 64
f6ccaed9 65 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 66 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 67 BT_ASSERT(stream_class);
90bd5941
PP
68 BT_LOGD("Creating stream end notification object: "
69 "stream-addr=%p, stream-name=\"%s\", "
70 "stream-class-addr=%p, stream-class-name=\"%s\", "
71 "stream-class-id=%" PRId64,
50842bdc 72 stream, bt_stream_get_name(stream),
90bd5941 73 stream_class,
50842bdc
PP
74 bt_stream_class_get_name(stream_class),
75 bt_stream_class_get_id(stream_class));
043e2020 76 notification = g_new0(struct bt_notification_stream_end, 1);
90bd5941
PP
77 if (!notification) {
78 BT_LOGE_STR("Failed to allocate one stream end notification.");
79 goto error;
80 }
81
043e2020
JG
82 bt_notification_init(&notification->parent,
83 BT_NOTIFICATION_TYPE_STREAM_END,
5c563278 84 bt_notification_stream_end_destroy, NULL);
043e2020 85 notification->stream = bt_get(stream);
90bd5941
PP
86 BT_LOGD("Created stream end notification object: "
87 "stream-addr=%p, stream-name=\"%s\", "
88 "stream-class-addr=%p, stream-class-name=\"%s\", "
89 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 90 stream, bt_stream_get_name(stream),
90bd5941 91 stream_class,
50842bdc
PP
92 bt_stream_class_get_name(stream_class),
93 bt_stream_class_get_id(stream_class), notification);
043e2020
JG
94 return &notification->parent;
95error:
96 return NULL;
97}
98
094ff7c0 99struct bt_stream *bt_notification_stream_end_borrow_stream(
043e2020
JG
100 struct bt_notification *notification)
101{
102 struct bt_notification_stream_end *stream_end;
103
f6ccaed9
PP
104 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
105 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
106 BT_NOTIFICATION_TYPE_STREAM_END);
043e2020
JG
107 stream_end = container_of(notification,
108 struct bt_notification_stream_end, parent);
094ff7c0 109 return stream_end->stream;
043e2020 110}
3230ee6b 111
44c440bc
PP
112int bt_notification_stream_end_set_default_clock_value(
113 struct bt_notification *notif, uint64_t value_cycles)
e22b45d0 114{
44c440bc
PP
115 int ret = 0;
116 struct bt_notification_stream_end *se_notif = (void *) notif;
e22b45d0
PP
117
118 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
e22b45d0
PP
119 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
120 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
44c440bc
PP
121 BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
122 "Notification's stream class has no default clock class: "
123 "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
124
125 if (!se_notif->default_cv) {
126 se_notif->default_cv = bt_clock_value_create(
127 se_notif->stream->class->default_clock_class);
128 if (!se_notif->default_cv) {
129 ret = -1;
130 goto end;
131 }
132 }
133
134 bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
135 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
136 "value=%" PRIu64, value_cycles);
137
138end:
139 return ret;
e22b45d0
PP
140}
141
142struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
143 struct bt_notification *notif)
144{
145 struct bt_notification_stream_end *stream_end = (void *) notif;
e22b45d0
PP
146
147 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
148 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
44c440bc 149 return stream_end->default_cv;
e22b45d0
PP
150}
151
3230ee6b
PP
152static
153void bt_notification_stream_begin_destroy(struct bt_object *obj)
154{
155 struct bt_notification_stream_begin *notification =
156 (struct bt_notification_stream_begin *) obj;
157
90bd5941
PP
158 BT_LOGD("Destroying stream beginning notification: addr=%p",
159 notification);
160 BT_LOGD_STR("Putting stream.");
3230ee6b 161 BT_PUT(notification->stream);
44c440bc
PP
162
163 if (notification->default_cv) {
164 bt_clock_value_recycle(notification->default_cv);
165 }
166
3230ee6b
PP
167 g_free(notification);
168}
169
170struct bt_notification *bt_notification_stream_begin_create(
f0010051
PP
171 struct bt_private_connection_private_notification_iterator *notif_iter,
172 struct bt_stream *stream)
3230ee6b
PP
173{
174 struct bt_notification_stream_begin *notification;
50842bdc 175 struct bt_stream_class *stream_class;
3230ee6b 176
f6ccaed9 177 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 178 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 179 BT_ASSERT(stream_class);
90bd5941
PP
180 BT_LOGD("Creating stream beginning notification object: "
181 "stream-addr=%p, stream-name=\"%s\", "
182 "stream-class-addr=%p, stream-class-name=\"%s\", "
183 "stream-class-id=%" PRId64,
50842bdc 184 stream, bt_stream_get_name(stream),
90bd5941 185 stream_class,
50842bdc
PP
186 bt_stream_class_get_name(stream_class),
187 bt_stream_class_get_id(stream_class));
3230ee6b 188 notification = g_new0(struct bt_notification_stream_begin, 1);
90bd5941
PP
189 if (!notification) {
190 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
191 goto error;
192 }
193
3230ee6b
PP
194 bt_notification_init(&notification->parent,
195 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
5c563278 196 bt_notification_stream_begin_destroy, NULL);
3230ee6b 197 notification->stream = bt_get(stream);
90bd5941
PP
198 BT_LOGD("Created stream beginning notification object: "
199 "stream-addr=%p, stream-name=\"%s\", "
200 "stream-class-addr=%p, stream-class-name=\"%s\", "
201 "stream-class-id=%" PRId64 ", addr=%p",
50842bdc 202 stream, bt_stream_get_name(stream),
90bd5941 203 stream_class,
50842bdc
PP
204 bt_stream_class_get_name(stream_class),
205 bt_stream_class_get_id(stream_class), notification);
3230ee6b
PP
206 return &notification->parent;
207error:
208 return NULL;
209}
210
094ff7c0 211struct bt_stream *bt_notification_stream_begin_borrow_stream(
3230ee6b
PP
212 struct bt_notification *notification)
213{
214 struct bt_notification_stream_begin *stream_begin;
215
f6ccaed9
PP
216 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
217 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
218 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
3230ee6b
PP
219 stream_begin = container_of(notification,
220 struct bt_notification_stream_begin, parent);
094ff7c0 221 return stream_begin->stream;
3230ee6b 222}
e22b45d0 223
44c440bc
PP
224int bt_notification_stream_begin_set_default_clock_value(
225 struct bt_notification *notif, uint64_t value_cycles)
e22b45d0 226{
44c440bc
PP
227 int ret = 0;
228 struct bt_notification_stream_begin *sb_notif = (void *) notif;
e22b45d0
PP
229
230 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
e22b45d0
PP
231 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
232 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
44c440bc
PP
233 BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
234 "Notification's stream class has no default clock class: "
235 "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
236
237 if (!sb_notif->default_cv) {
238 sb_notif->default_cv = bt_clock_value_create(
239 sb_notif->stream->class->default_clock_class);
240 if (!sb_notif->default_cv) {
241 ret = -1;
242 goto end;
243 }
244 }
245
246 bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
247 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
248 "value=%" PRIu64, value_cycles);
249
250end:
251 return ret;
e22b45d0
PP
252}
253
254struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
255 struct bt_notification *notif)
256{
257 struct bt_notification_stream_begin *stream_begin = (void *) notif;
e22b45d0
PP
258
259 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
260 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
44c440bc 261 return stream_begin->default_cv;
e22b45d0 262}
This page took 0.049059 seconds and 4 git commands to generate.