CTF IR -> Trace IR
[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
d229f56b
PP
27#define BT_LOG_TAG "NOTIF-STREAM"
28#include <babeltrace/lib-logging-internal.h>
29
8fc063a2 30#include <babeltrace/assert-pre-internal.h>
3d9990ac 31#include <babeltrace/compiler-internal.h>
108b91d0
PP
32#include <babeltrace/trace-ir/stream-internal.h>
33#include <babeltrace/trace-ir/stream-class.h>
34#include <babeltrace/trace-ir/stream-class-internal.h>
b2e0c907 35#include <babeltrace/graph/notification-stream-internal.h>
03e18d5d 36#include <babeltrace/graph/private-connection-private-notification-iterator.h>
8b45963b 37#include <babeltrace/assert-internal.h>
d229f56b 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
d229f56b
PP
46 BT_LOGD("Destroying stream end notification: addr=%p",
47 notification);
48 BT_LOGD_STR("Putting stream.");
043e2020 49 BT_PUT(notification->stream);
7b33a0e0
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(
03e18d5d
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;
839d52a5 63 struct bt_stream_class *stream_class;
043e2020 64
8b45963b 65 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
8deee039 66 stream_class = bt_stream_borrow_class(stream);
8b45963b 67 BT_ASSERT(stream_class);
d229f56b
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,
839d52a5 72 stream, bt_stream_get_name(stream),
d229f56b 73 stream_class,
839d52a5
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);
d229f56b
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,
f7c3ac09 84 bt_notification_stream_end_destroy, NULL);
043e2020 85 notification->stream = bt_get(stream);
d229f56b
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",
839d52a5 90 stream, bt_stream_get_name(stream),
d229f56b 91 stream_class,
839d52a5
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
5fe68922 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
8b45963b
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);
5fe68922 109 return stream_end->stream;
043e2020 110}
3230ee6b 111
7b33a0e0
PP
112int bt_notification_stream_end_set_default_clock_value(
113 struct bt_notification *notif, uint64_t value_cycles)
8fc063a2 114{
7b33a0e0
PP
115 int ret = 0;
116 struct bt_notification_stream_end *se_notif = (void *) notif;
8fc063a2
PP
117
118 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
8fc063a2
PP
119 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
120 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
7b33a0e0
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;
8fc063a2
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;
8fc063a2
PP
146
147 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
148 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
7b33a0e0 149 return stream_end->default_cv;
8fc063a2
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
d229f56b
PP
158 BT_LOGD("Destroying stream beginning notification: addr=%p",
159 notification);
160 BT_LOGD_STR("Putting stream.");
3230ee6b 161 BT_PUT(notification->stream);
7b33a0e0
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(
03e18d5d
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;
839d52a5 175 struct bt_stream_class *stream_class;
3230ee6b 176
8b45963b 177 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
8deee039 178 stream_class = bt_stream_borrow_class(stream);
8b45963b 179 BT_ASSERT(stream_class);
d229f56b
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,
839d52a5 184 stream, bt_stream_get_name(stream),
d229f56b 185 stream_class,
839d52a5
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);
d229f56b
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,
f7c3ac09 196 bt_notification_stream_begin_destroy, NULL);
3230ee6b 197 notification->stream = bt_get(stream);
d229f56b
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",
839d52a5 202 stream, bt_stream_get_name(stream),
d229f56b 203 stream_class,
839d52a5
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
5fe68922 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
8b45963b
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);
5fe68922 221 return stream_begin->stream;
3230ee6b 222}
8fc063a2 223
7b33a0e0
PP
224int bt_notification_stream_begin_set_default_clock_value(
225 struct bt_notification *notif, uint64_t value_cycles)
8fc063a2 226{
7b33a0e0
PP
227 int ret = 0;
228 struct bt_notification_stream_begin *sb_notif = (void *) notif;
8fc063a2
PP
229
230 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
8fc063a2
PP
231 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
232 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
7b33a0e0
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;
8fc063a2
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;
8fc063a2
PP
258
259 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
260 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
7b33a0e0 261 return stream_begin->default_cv;
8fc063a2 262}
This page took 0.045638 seconds and 4 git commands to generate.