lib: graph: add "self" and some "private" APIs
[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,
e5be10ef 60 struct bt_private_stream *priv_stream)
043e2020 61{
e5be10ef 62 struct bt_stream *stream = (void *) priv_stream;
043e2020 63 struct bt_notification_stream_end *notification;
50842bdc 64 struct bt_stream_class *stream_class;
043e2020 65
d94d92ac 66 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
f6ccaed9 67 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 68 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 69 BT_ASSERT(stream_class);
d94d92ac
PP
70 BT_LIB_LOGD("Creating stream end notification object: "
71 "%![stream-]+s, %![sc-]+S", stream, stream_class);
043e2020 72 notification = g_new0(struct bt_notification_stream_end, 1);
90bd5941
PP
73 if (!notification) {
74 BT_LOGE_STR("Failed to allocate one stream end notification.");
75 goto error;
76 }
77
043e2020
JG
78 bt_notification_init(&notification->parent,
79 BT_NOTIFICATION_TYPE_STREAM_END,
5c563278 80 bt_notification_stream_end_destroy, NULL);
65300d60 81 notification->stream = bt_object_get_ref(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
094ff7c0 91struct bt_stream *bt_notification_stream_end_borrow_stream(
043e2020
JG
92 struct bt_notification *notification)
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);
043e2020
JG
99 stream_end = container_of(notification,
100 struct bt_notification_stream_end, parent);
094ff7c0 101 return stream_end->stream;
043e2020 102}
3230ee6b 103
e5be10ef
PP
104struct bt_private_stream *bt_private_notification_stream_end_borrow_stream(
105 struct bt_private_notification *notification)
106{
107 return (void *) bt_notification_stream_end_borrow_stream(
108 (void *) notification);
109}
110
111int bt_private_notification_stream_end_set_default_clock_value(
112 struct bt_private_notification *priv_notif,
113 uint64_t value_cycles)
e22b45d0 114{
44c440bc 115 int ret = 0;
e5be10ef 116 struct bt_notification *notif = (void *) priv_notif;
44c440bc 117 struct bt_notification_stream_end *se_notif = (void *) notif;
e22b45d0
PP
118
119 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
e22b45d0
PP
120 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
121 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
44c440bc
PP
122 BT_ASSERT_PRE(se_notif->stream->class->default_clock_class,
123 "Notification's stream class has no default clock class: "
124 "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class);
125
126 if (!se_notif->default_cv) {
127 se_notif->default_cv = bt_clock_value_create(
128 se_notif->stream->class->default_clock_class);
129 if (!se_notif->default_cv) {
130 ret = -1;
131 goto end;
132 }
133 }
134
135 bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles);
136 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
137 "value=%" PRIu64, value_cycles);
138
139end:
140 return ret;
e22b45d0
PP
141}
142
143struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value(
144 struct bt_notification *notif)
145{
146 struct bt_notification_stream_end *stream_end = (void *) notif;
e22b45d0
PP
147
148 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
149 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END);
44c440bc 150 return stream_end->default_cv;
e22b45d0
PP
151}
152
3230ee6b
PP
153static
154void bt_notification_stream_begin_destroy(struct bt_object *obj)
155{
156 struct bt_notification_stream_begin *notification =
157 (struct bt_notification_stream_begin *) obj;
158
d94d92ac 159 BT_LIB_LOGD("Destroying stream beginning notification: %!+n",
90bd5941 160 notification);
d94d92ac 161 BT_LIB_LOGD("Putting stream: %!+s", notification->stream);
65300d60 162 BT_OBJECT_PUT_REF_AND_RESET(notification->stream);
44c440bc
PP
163
164 if (notification->default_cv) {
165 bt_clock_value_recycle(notification->default_cv);
d94d92ac 166 notification->default_cv = NULL;
44c440bc
PP
167 }
168
3230ee6b
PP
169 g_free(notification);
170}
171
e5be10ef 172struct bt_private_notification *bt_private_notification_stream_begin_create(
d94d92ac 173 struct bt_self_notification_iterator *self_notif_iter,
e5be10ef 174 struct bt_private_stream *priv_stream)
3230ee6b 175{
e5be10ef 176 struct bt_stream *stream = (void *) priv_stream;
3230ee6b 177 struct bt_notification_stream_begin *notification;
50842bdc 178 struct bt_stream_class *stream_class;
3230ee6b 179
d94d92ac 180 BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator");
f6ccaed9 181 BT_ASSERT_PRE_NON_NULL(stream, "Stream");
3dca2276 182 stream_class = bt_stream_borrow_class(stream);
f6ccaed9 183 BT_ASSERT(stream_class);
d94d92ac
PP
184 BT_LIB_LOGD("Creating stream beginning notification object: "
185 "%![stream-]+s, %![sc-]+S", stream, stream_class);
3230ee6b 186 notification = g_new0(struct bt_notification_stream_begin, 1);
90bd5941
PP
187 if (!notification) {
188 BT_LOGE_STR("Failed to allocate one stream beginning notification.");
189 goto error;
190 }
191
3230ee6b
PP
192 bt_notification_init(&notification->parent,
193 BT_NOTIFICATION_TYPE_STREAM_BEGIN,
5c563278 194 bt_notification_stream_begin_destroy, NULL);
65300d60 195 notification->stream = bt_object_get_ref(stream);
d94d92ac
PP
196 BT_LIB_LOGD("Created stream beginning notification object: "
197 "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification,
198 stream, stream_class);
e5be10ef 199 return (void *) &notification->parent;
3230ee6b
PP
200error:
201 return NULL;
202}
203
094ff7c0 204struct bt_stream *bt_notification_stream_begin_borrow_stream(
3230ee6b
PP
205 struct bt_notification *notification)
206{
207 struct bt_notification_stream_begin *stream_begin;
208
f6ccaed9
PP
209 BT_ASSERT_PRE_NON_NULL(notification, "Notification");
210 BT_ASSERT_PRE_NOTIF_IS_TYPE(notification,
211 BT_NOTIFICATION_TYPE_STREAM_BEGIN);
3230ee6b
PP
212 stream_begin = container_of(notification,
213 struct bt_notification_stream_begin, parent);
094ff7c0 214 return stream_begin->stream;
3230ee6b 215}
e22b45d0 216
e5be10ef
PP
217struct bt_private_stream *bt_private_notification_stream_begin_borrow_stream(
218 struct bt_private_notification *notification)
219{
220 return (void *) bt_notification_stream_begin_borrow_stream(
221 (void *) notification);
222}
223
224int bt_private_notification_stream_begin_set_default_clock_value(
225 struct bt_private_notification *priv_notif,
226 uint64_t value_cycles)
e22b45d0 227{
44c440bc 228 int ret = 0;
e5be10ef 229 struct bt_notification *notif = (void *) priv_notif;
44c440bc 230 struct bt_notification_stream_begin *sb_notif = (void *) notif;
e22b45d0
PP
231
232 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
e22b45d0
PP
233 BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif);
234 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
44c440bc
PP
235 BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class,
236 "Notification's stream class has no default clock class: "
237 "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class);
238
239 if (!sb_notif->default_cv) {
240 sb_notif->default_cv = bt_clock_value_create(
241 sb_notif->stream->class->default_clock_class);
242 if (!sb_notif->default_cv) {
243 ret = -1;
244 goto end;
245 }
246 }
247
248 bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles);
249 BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, "
250 "value=%" PRIu64, value_cycles);
251
252end:
253 return ret;
e22b45d0
PP
254}
255
256struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value(
257 struct bt_notification *notif)
258{
259 struct bt_notification_stream_begin *stream_begin = (void *) notif;
e22b45d0
PP
260
261 BT_ASSERT_PRE_NON_NULL(notif, "Notification");
262 BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN);
44c440bc 263 return stream_begin->default_cv;
e22b45d0 264}
This page took 0.047534 seconds and 4 git commands to generate.