lib: make trace IR API const-correct
[babeltrace.git] / lib / graph / notification / stream.c
CommitLineData
043e2020 1/*
043e2020
JG
2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
90bd5941
PP
25#define BT_LOG_TAG "NOTIF-STREAM"
26#include <babeltrace/lib-logging-internal.h>
27
e22b45d0 28#include <babeltrace/assert-pre-internal.h>
3d9990ac 29#include <babeltrace/compiler-internal.h>
56e18c4c
PP
30#include <babeltrace/trace-ir/stream-internal.h>
31#include <babeltrace/trace-ir/stream-class.h>
32#include <babeltrace/trace-ir/stream-class-internal.h>
e5be10ef 33#include <babeltrace/graph/private-notification-stream.h>
b2e0c907 34#include <babeltrace/graph/notification-stream-internal.h>
f6ccaed9 35#include <babeltrace/assert-internal.h>
e5be10ef 36#include <babeltrace/object.h>
90bd5941 37#include <inttypes.h>
043e2020
JG
38
39static
40void bt_notification_stream_end_destroy(struct bt_object *obj)
41{
42 struct bt_notification_stream_end *notification =
43 (struct bt_notification_stream_end *) obj;
44
d94d92ac 45 BT_LIB_LOGD("Destroying stream end notification: %!+n",
90bd5941 46 notification);
d94d92ac 47 BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
65300d60 48 BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
44c440bc
PP
49
50 if (notification->default_cv) {
51 bt_clock_value_recycle(notification->default_cv);
d94d92ac 52 notification->default_cv = NULL;
44c440bc
PP
53 }
54
043e2020
JG
55 g_free(notification);
56}
57
e5be10ef 58struct bt_private_notification *bt_private_notification_stream_end_create(
d94d92ac 59 struct bt_self_notification_iterator *self_notif_iter,
40f4ba76 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
d94d92ac 65 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
f6ccaed9 66 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 67 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 68 BT_ASSERT(stream_class);
d94d92ac
PP
69 BT_LIB_LOGD("Creating stream end notification object: "
70 "%![stream-]+s, %![sc-]+S", stream, stream_class);
043e2020 71 notification = g_new0(struct bt_notification_stream_end, 1);
90bd5941
PP
72 if (!notification) {
73 BT_LOGE_STR("Failed to allocate one stream end notification.");
74 goto error;
75 }
76
043e2020
JG
77 bt_notification_init(&notification->parent,
78 BT_NOTIFICATION_TYPE_STREAM_END,
5c563278 79 bt_notification_stream_end_destroy, NULL);
398454ed
PP
80 notification->stream = stream;
81 bt_object_get_no_null_check(notification->stream);
d94d92ac
PP
82 BT_LIB_LOGD("Created stream end notification object: "
83 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
84 stream, stream_class);
e5be10ef
PP
85
86 return (void *) &notification->parent;
043e2020
JG
87error:
88 return NULL;
89}
90
40f4ba76
PP
91struct bt_stream *bt_private_notification_stream_end_borrow_stream(
92 struct bt_private_notification *notification)
043e2020
JG
93{
94 struct bt_notification_stream_end *stream_end;
95
f6ccaed9
PP
96 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
97 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
98 BT_NOTIFICATION_TYPE_STREAM_END);
40f4ba76 99 stream_end = (void *) notification;
094ff7c0 100 return stream_end->stream;
043e2020 101}
3230ee6b 102
40f4ba76
PP
103const struct bt_stream *bt_notification_stream_end_borrow_stream(
104 struct bt_notification *notification)
e5be10ef 105{
40f4ba76 106 return bt_private_notification_stream_end_borrow_stream(
e5be10ef
PP
107 (void *) notification);
108}
109
140e6d94 110void bt_private_notification_stream_end_set_default_clock_value(
e5be10ef
PP
111 struct bt_private_notification *priv_notif,
112 uint64_t value_cycles)
e22b45d0 113{
e5be10ef 114 struct bt_notification *notif = (void *) priv_notif;
44c440bc 115 struct bt_notification_stream_end *se_notif = (void *) notif;
e22b45d0
PP
116
117 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
e22b45d0
PP
118 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
119 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
44c440bc
PP
120 BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
121 "Notification's stream class has no default clock class: "
122 "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
123
140e6d94
PP
124 /* TODO: have the object already created */
125 se_notif->default_cv = bt_clock_value_create(
126 se_notif->stream->class->default_clock_class);
127 BT_ASSERT(se_notif->default_cv);
44c440bc
PP
128 bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
129 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
130 "value=%" PRIu64, value_cycles);
e22b45d0
PP
131}
132
133struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
134 struct bt_notification *notif)
135{
136 struct bt_notification_stream_end *stream_end = (void *) notif;
e22b45d0
PP
137
138 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
139 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
44c440bc 140 return stream_end->default_cv;
e22b45d0
PP
141}
142
3230ee6b
PP
143static
144void bt_notification_stream_begin_destroy(struct bt_object *obj)
145{
146 struct bt_notification_stream_begin *notification =
147 (struct bt_notification_stream_begin *) obj;
148
d94d92ac 149 BT_LIB_LOGD("Destroying stream beginning notification: %!+n",
90bd5941 150 notification);
d94d92ac 151 BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
65300d60 152 BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
44c440bc
PP
153
154 if (notification->default_cv) {
155 bt_clock_value_recycle(notification->default_cv);
d94d92ac 156 notification->default_cv = NULL;
44c440bc
PP
157 }
158
3230ee6b
PP
159 g_free(notification);
160}
161
e5be10ef 162struct bt_private_notification *bt_private_notification_stream_begin_create(
d94d92ac 163 struct bt_self_notification_iterator *self_notif_iter,
40f4ba76 164 struct bt_stream *stream)
3230ee6b
PP
165{
166 struct bt_notification_stream_begin *notification;
50842bdc 167 struct bt_stream_class *stream_class;
3230ee6b 168
d94d92ac 169 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
f6ccaed9 170 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 171 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 172 BT_ASSERT(stream_class);
d94d92ac
PP
173 BT_LIB_LOGD("Creating stream beginning notification object: "
174 "%![stream-]+s, %![sc-]+S", stream, stream_class);
3230ee6b 175 notification = g_new0(struct bt_notification_stream_begin, 1);
90bd5941
PP
176 if (!notification) {
177 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
178 goto error;
179 }
180
3230ee6b
PP
181 bt_notification_init(&notification->parent,
182 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
5c563278 183 bt_notification_stream_begin_destroy, NULL);
398454ed
PP
184 notification->stream = stream;
185 bt_object_get_no_null_check(notification->stream);
d94d92ac
PP
186 BT_LIB_LOGD("Created stream beginning notification object: "
187 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
188 stream, stream_class);
e5be10ef 189 return (void *) &notification->parent;
3230ee6b
PP
190error:
191 return NULL;
192}
193
40f4ba76
PP
194struct bt_stream *bt_private_notification_stream_begin_borrow_stream(
195 struct bt_private_notification *notification)
3230ee6b
PP
196{
197 struct bt_notification_stream_begin *stream_begin;
198
f6ccaed9
PP
199 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
200 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
201 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
40f4ba76 202 stream_begin = (void *) notification;
094ff7c0 203 return stream_begin->stream;
3230ee6b 204}
e22b45d0 205
40f4ba76
PP
206const struct bt_stream *bt_notification_stream_begin_borrow_stream(
207 struct bt_notification *notification)
e5be10ef 208{
40f4ba76 209 return bt_private_notification_stream_begin_borrow_stream(
e5be10ef
PP
210 (void *) notification);
211}
212
140e6d94 213void bt_private_notification_stream_begin_set_default_clock_value(
e5be10ef
PP
214 struct bt_private_notification *priv_notif,
215 uint64_t value_cycles)
e22b45d0 216{
e5be10ef 217 struct bt_notification *notif = (void *) priv_notif;
44c440bc 218 struct bt_notification_stream_begin *sb_notif = (void *) notif;
e22b45d0
PP
219
220 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
e22b45d0
PP
221 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
222 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
44c440bc
PP
223 BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
224 "Notification's stream class has no default clock class: "
225 "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
226
140e6d94
PP
227 /* TODO: have the object already created */
228 sb_notif->default_cv = bt_clock_value_create(
229 sb_notif->stream->class->default_clock_class);
230 BT_ASSERT(sb_notif->default_cv);
44c440bc
PP
231 bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
232 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
233 "value=%" PRIu64, value_cycles);
e22b45d0
PP
234}
235
236struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
237 struct bt_notification *notif)
238{
239 struct bt_notification_stream_begin *stream_begin = (void *) notif;
e22b45d0
PP
240
241 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
242 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
44c440bc 243 return stream_begin->default_cv;
e22b45d0 244}
This page took 0.047255 seconds and 4 git commands to generate.