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