Commit | Line | Data |
---|---|---|
043e2020 | 1 | /* |
0554db57 | 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 | ||
90bd5941 PP |
24 | #define BT_LOG_TAG "NOTIF-STREAM" |
25 | #include <babeltrace/lib-logging-internal.h> | |
26 | ||
e22b45d0 | 27 | #include <babeltrace/assert-pre-internal.h> |
3d9990ac | 28 | #include <babeltrace/compiler-internal.h> |
577dc45a 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> | |
96ffdc46 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> |
f6ccaed9 | 35 | #include <babeltrace/assert-internal.h> |
351946b4 | 36 | #include <babeltrace/object.h> |
90bd5941 | 37 | #include <inttypes.h> |
043e2020 JG |
38 | |
39 | static | |
40 | void 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 | ||
d27a81b2 | 45 | BT_LIB_LOGD("Destroying stream end notification: %!+n", |
90bd5941 | 46 | notification); |
d27a81b2 | 47 | BT_LIB_LOGD("Putting stream: %!+s", notification->stream); |
e2317362 | 48 | BT_OBJECT_PUT_REF_AND_RESET(notification->stream); |
61f59358 PP |
49 | |
50 | if (notification->default_cv) { | |
51 | bt_clock_value_recycle(notification->default_cv); | |
d27a81b2 | 52 | notification->default_cv = NULL; |
61f59358 PP |
53 | } |
54 | ||
043e2020 JG |
55 | g_free(notification); |
56 | } | |
57 | ||
96ffdc46 | 58 | struct bt_notification *bt_notification_stream_end_create( |
d27a81b2 | 59 | struct bt_self_notification_iterator *self_notif_iter, |
dadf29b9 | 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 | |
d27a81b2 | 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); |
d27a81b2 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(¬ification->parent, |
78 | BT_NOTIFICATION_TYPE_STREAM_END, | |
5c563278 | 79 | bt_notification_stream_end_destroy, NULL); |
5e8988cb PP |
80 | notification->stream = stream; |
81 | bt_object_get_no_null_check(notification->stream); | |
d27a81b2 PP |
82 | BT_LIB_LOGD("Created stream end notification object: " |
83 | "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification, | |
84 | stream, stream_class); | |
351946b4 PP |
85 | |
86 | return (void *) ¬ification->parent; | |
043e2020 JG |
87 | error: |
88 | return NULL; | |
89 | } | |
90 | ||
96ffdc46 PP |
91 | struct bt_stream *bt_notification_stream_end_borrow_stream( |
92 | struct bt_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); | |
dadf29b9 | 99 | stream_end = (void *) notification; |
094ff7c0 | 100 | return stream_end->stream; |
043e2020 | 101 | } |
3230ee6b | 102 | |
96ffdc46 PP |
103 | const struct bt_stream *bt_notification_stream_end_borrow_stream_const( |
104 | const struct bt_notification *notification) | |
351946b4 | 105 | { |
96ffdc46 | 106 | return bt_notification_stream_end_borrow_stream( |
351946b4 PP |
107 | (void *) notification); |
108 | } | |
109 | ||
96ffdc46 PP |
110 | void bt_notification_stream_end_set_default_clock_value( |
111 | struct bt_notification *notif, uint64_t value_cycles) | |
e22b45d0 | 112 | { |
61f59358 | 113 | struct bt_notification_stream_end *se_notif = (void *) notif; |
e22b45d0 PP |
114 | |
115 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
e22b45d0 PP |
116 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
117 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
61f59358 PP |
118 | BT_ASSERT_PRE(se_notif->stream->class->default_clock_class, |
119 | "Notification's stream class has no default clock class: " | |
120 | "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class); | |
121 | ||
c9987c4e PP |
122 | /* TODO: have the object already created */ |
123 | se_notif->default_cv = bt_clock_value_create( | |
124 | se_notif->stream->class->default_clock_class); | |
125 | BT_ASSERT(se_notif->default_cv); | |
61f59358 PP |
126 | bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles); |
127 | BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, " | |
128 | "value=%" PRIu64, value_cycles); | |
e22b45d0 PP |
129 | } |
130 | ||
131 | struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( | |
132 | struct bt_notification *notif) | |
133 | { | |
134 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
e22b45d0 PP |
135 | |
136 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
137 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
61f59358 | 138 | return stream_end->default_cv; |
e22b45d0 PP |
139 | } |
140 | ||
3230ee6b | 141 | static |
af9fdf14 | 142 | void bt_notification_stream_beginning_destroy(struct bt_object *obj) |
3230ee6b | 143 | { |
af9fdf14 PP |
144 | struct bt_notification_stream_beginning *notification = |
145 | (struct bt_notification_stream_beginning *) obj; | |
3230ee6b | 146 | |
d27a81b2 | 147 | BT_LIB_LOGD("Destroying stream beginning notification: %!+n", |
90bd5941 | 148 | notification); |
d27a81b2 | 149 | BT_LIB_LOGD("Putting stream: %!+s", notification->stream); |
e2317362 | 150 | BT_OBJECT_PUT_REF_AND_RESET(notification->stream); |
61f59358 PP |
151 | |
152 | if (notification->default_cv) { | |
153 | bt_clock_value_recycle(notification->default_cv); | |
d27a81b2 | 154 | notification->default_cv = NULL; |
61f59358 PP |
155 | } |
156 | ||
3230ee6b PP |
157 | g_free(notification); |
158 | } | |
159 | ||
af9fdf14 | 160 | struct bt_notification *bt_notification_stream_beginning_create( |
d27a81b2 | 161 | struct bt_self_notification_iterator *self_notif_iter, |
dadf29b9 | 162 | struct bt_stream *stream) |
3230ee6b | 163 | { |
af9fdf14 | 164 | struct bt_notification_stream_beginning *notification; |
50842bdc | 165 | struct bt_stream_class *stream_class; |
3230ee6b | 166 | |
d27a81b2 | 167 | BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator"); |
f6ccaed9 | 168 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 169 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 170 | BT_ASSERT(stream_class); |
d27a81b2 PP |
171 | BT_LIB_LOGD("Creating stream beginning notification object: " |
172 | "%![stream-]+s, %![sc-]+S", stream, stream_class); | |
af9fdf14 | 173 | notification = g_new0(struct bt_notification_stream_beginning, 1); |
90bd5941 PP |
174 | if (!notification) { |
175 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
176 | goto error; | |
177 | } | |
178 | ||
3230ee6b | 179 | bt_notification_init(¬ification->parent, |
af9fdf14 PP |
180 | BT_NOTIFICATION_TYPE_STREAM_BEGINNING, |
181 | bt_notification_stream_beginning_destroy, NULL); | |
5e8988cb PP |
182 | notification->stream = stream; |
183 | bt_object_get_no_null_check(notification->stream); | |
d27a81b2 PP |
184 | BT_LIB_LOGD("Created stream beginning notification object: " |
185 | "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification, | |
186 | stream, stream_class); | |
351946b4 | 187 | return (void *) ¬ification->parent; |
3230ee6b PP |
188 | error: |
189 | return NULL; | |
190 | } | |
191 | ||
af9fdf14 | 192 | struct bt_stream *bt_notification_stream_beginning_borrow_stream( |
96ffdc46 | 193 | struct bt_notification *notification) |
3230ee6b | 194 | { |
af9fdf14 | 195 | struct bt_notification_stream_beginning *stream_begin; |
3230ee6b | 196 | |
f6ccaed9 PP |
197 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
198 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
af9fdf14 | 199 | BT_NOTIFICATION_TYPE_STREAM_BEGINNING); |
dadf29b9 | 200 | stream_begin = (void *) notification; |
094ff7c0 | 201 | return stream_begin->stream; |
3230ee6b | 202 | } |
e22b45d0 | 203 | |
af9fdf14 | 204 | const struct bt_stream *bt_notification_stream_beginning_borrow_stream_const( |
96ffdc46 | 205 | const struct bt_notification *notification) |
351946b4 | 206 | { |
af9fdf14 | 207 | return bt_notification_stream_beginning_borrow_stream( |
351946b4 PP |
208 | (void *) notification); |
209 | } | |
210 | ||
af9fdf14 | 211 | void bt_notification_stream_beginning_set_default_clock_value( |
96ffdc46 | 212 | struct bt_notification *notif, |
351946b4 | 213 | uint64_t value_cycles) |
e22b45d0 | 214 | { |
af9fdf14 | 215 | struct bt_notification_stream_beginning *sb_notif = (void *) notif; |
e22b45d0 PP |
216 | |
217 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
e22b45d0 | 218 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
af9fdf14 | 219 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGINNING); |
61f59358 PP |
220 | BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class, |
221 | "Notification's stream class has no default clock class: " | |
222 | "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class); | |
223 | ||
c9987c4e PP |
224 | /* TODO: have the object already created */ |
225 | sb_notif->default_cv = bt_clock_value_create( | |
226 | sb_notif->stream->class->default_clock_class); | |
227 | BT_ASSERT(sb_notif->default_cv); | |
61f59358 PP |
228 | bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles); |
229 | BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, " | |
230 | "value=%" PRIu64, value_cycles); | |
e22b45d0 PP |
231 | } |
232 | ||
af9fdf14 | 233 | struct bt_clock_value *bt_notification_stream_beginning_borrow_default_clock_value( |
e22b45d0 PP |
234 | struct bt_notification *notif) |
235 | { | |
af9fdf14 | 236 | struct bt_notification_stream_beginning *stream_begin = (void *) notif; |
e22b45d0 PP |
237 | |
238 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
af9fdf14 | 239 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGINNING); |
61f59358 | 240 | return stream_begin->default_cv; |
e22b45d0 | 241 | } |