Commit | Line | Data |
---|---|---|
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> |
f0010051 | 35 | #include <babeltrace/graph/private-connection-private-notification-iterator.h> |
f6ccaed9 | 36 | #include <babeltrace/assert-internal.h> |
e5be10ef | 37 | #include <babeltrace/object.h> |
90bd5941 | 38 | #include <inttypes.h> |
043e2020 JG |
39 | |
40 | static | |
41 | void 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 | ||
90bd5941 PP |
46 | BT_LOGD("Destroying stream end notification: addr=%p", |
47 | notification); | |
48 | BT_LOGD_STR("Putting stream."); | |
65300d60 | 49 | BT_OBJECT_PUT_REF_AND_RESET(notification->stream); |
44c440bc 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 | ||
e5be10ef | 58 | struct bt_private_notification *bt_private_notification_stream_end_create( |
f0010051 | 59 | struct bt_private_connection_private_notification_iterator *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 | |
f6ccaed9 | 66 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 67 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 68 | BT_ASSERT(stream_class); |
90bd5941 PP |
69 | BT_LOGD("Creating stream end notification object: " |
70 | "stream-addr=%p, stream-name=\"%s\", " | |
71 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
72 | "stream-class-id=%" PRId64, | |
50842bdc | 73 | stream, bt_stream_get_name(stream), |
90bd5941 | 74 | stream_class, |
50842bdc PP |
75 | bt_stream_class_get_name(stream_class), |
76 | bt_stream_class_get_id(stream_class)); | |
043e2020 | 77 | notification = g_new0(struct bt_notification_stream_end, 1); |
90bd5941 PP |
78 | if (!notification) { |
79 | BT_LOGE_STR("Failed to allocate one stream end notification."); | |
80 | goto error; | |
81 | } | |
82 | ||
043e2020 JG |
83 | bt_notification_init(¬ification->parent, |
84 | BT_NOTIFICATION_TYPE_STREAM_END, | |
5c563278 | 85 | bt_notification_stream_end_destroy, NULL); |
65300d60 | 86 | notification->stream = bt_object_get_ref(stream); |
90bd5941 PP |
87 | BT_LOGD("Created stream end notification object: " |
88 | "stream-addr=%p, stream-name=\"%s\", " | |
89 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
90 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 91 | stream, bt_stream_get_name(stream), |
90bd5941 | 92 | stream_class, |
50842bdc PP |
93 | bt_stream_class_get_name(stream_class), |
94 | bt_stream_class_get_id(stream_class), notification); | |
e5be10ef PP |
95 | |
96 | return (void *) ¬ification->parent; | |
043e2020 JG |
97 | error: |
98 | return NULL; | |
99 | } | |
100 | ||
094ff7c0 | 101 | struct bt_stream *bt_notification_stream_end_borrow_stream( |
043e2020 JG |
102 | struct bt_notification *notification) |
103 | { | |
104 | struct bt_notification_stream_end *stream_end; | |
105 | ||
f6ccaed9 PP |
106 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
107 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
108 | BT_NOTIFICATION_TYPE_STREAM_END); | |
043e2020 JG |
109 | stream_end = container_of(notification, |
110 | struct bt_notification_stream_end, parent); | |
094ff7c0 | 111 | return stream_end->stream; |
043e2020 | 112 | } |
3230ee6b | 113 | |
e5be10ef PP |
114 | struct bt_private_stream *bt_private_notification_stream_end_borrow_stream( |
115 | struct bt_private_notification *notification) | |
116 | { | |
117 | return (void *) bt_notification_stream_end_borrow_stream( | |
118 | (void *) notification); | |
119 | } | |
120 | ||
121 | int bt_private_notification_stream_end_set_default_clock_value( | |
122 | struct bt_private_notification *priv_notif, | |
123 | uint64_t value_cycles) | |
e22b45d0 | 124 | { |
44c440bc | 125 | int ret = 0; |
e5be10ef | 126 | struct bt_notification *notif = (void *) priv_notif; |
44c440bc | 127 | struct bt_notification_stream_end *se_notif = (void *) notif; |
e22b45d0 PP |
128 | |
129 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
e22b45d0 PP |
130 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
131 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
44c440bc PP |
132 | BT_ASSERT_PRE(se_notif->stream->class->default_clock_class, |
133 | "Notification's stream class has no default clock class: " | |
134 | "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class); | |
135 | ||
136 | if (!se_notif->default_cv) { | |
137 | se_notif->default_cv = bt_clock_value_create( | |
138 | se_notif->stream->class->default_clock_class); | |
139 | if (!se_notif->default_cv) { | |
140 | ret = -1; | |
141 | goto end; | |
142 | } | |
143 | } | |
144 | ||
145 | bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles); | |
146 | BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, " | |
147 | "value=%" PRIu64, value_cycles); | |
148 | ||
149 | end: | |
150 | return ret; | |
e22b45d0 PP |
151 | } |
152 | ||
153 | struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( | |
154 | struct bt_notification *notif) | |
155 | { | |
156 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
e22b45d0 PP |
157 | |
158 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
159 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
44c440bc | 160 | return stream_end->default_cv; |
e22b45d0 PP |
161 | } |
162 | ||
3230ee6b PP |
163 | static |
164 | void bt_notification_stream_begin_destroy(struct bt_object *obj) | |
165 | { | |
166 | struct bt_notification_stream_begin *notification = | |
167 | (struct bt_notification_stream_begin *) obj; | |
168 | ||
90bd5941 PP |
169 | BT_LOGD("Destroying stream beginning notification: addr=%p", |
170 | notification); | |
171 | BT_LOGD_STR("Putting stream."); | |
65300d60 | 172 | BT_OBJECT_PUT_REF_AND_RESET(notification->stream); |
44c440bc PP |
173 | |
174 | if (notification->default_cv) { | |
175 | bt_clock_value_recycle(notification->default_cv); | |
176 | } | |
177 | ||
3230ee6b PP |
178 | g_free(notification); |
179 | } | |
180 | ||
e5be10ef | 181 | struct bt_private_notification *bt_private_notification_stream_begin_create( |
f0010051 | 182 | struct bt_private_connection_private_notification_iterator *notif_iter, |
e5be10ef | 183 | struct bt_private_stream *priv_stream) |
3230ee6b | 184 | { |
e5be10ef | 185 | struct bt_stream *stream = (void *) priv_stream; |
3230ee6b | 186 | struct bt_notification_stream_begin *notification; |
50842bdc | 187 | struct bt_stream_class *stream_class; |
3230ee6b | 188 | |
f6ccaed9 | 189 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 190 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 191 | BT_ASSERT(stream_class); |
90bd5941 PP |
192 | BT_LOGD("Creating stream beginning notification object: " |
193 | "stream-addr=%p, stream-name=\"%s\", " | |
194 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
195 | "stream-class-id=%" PRId64, | |
50842bdc | 196 | stream, bt_stream_get_name(stream), |
90bd5941 | 197 | stream_class, |
50842bdc PP |
198 | bt_stream_class_get_name(stream_class), |
199 | bt_stream_class_get_id(stream_class)); | |
3230ee6b | 200 | notification = g_new0(struct bt_notification_stream_begin, 1); |
90bd5941 PP |
201 | if (!notification) { |
202 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
203 | goto error; | |
204 | } | |
205 | ||
3230ee6b PP |
206 | bt_notification_init(¬ification->parent, |
207 | BT_NOTIFICATION_TYPE_STREAM_BEGIN, | |
5c563278 | 208 | bt_notification_stream_begin_destroy, NULL); |
65300d60 | 209 | notification->stream = bt_object_get_ref(stream); |
90bd5941 PP |
210 | BT_LOGD("Created stream beginning notification object: " |
211 | "stream-addr=%p, stream-name=\"%s\", " | |
212 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
213 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 214 | stream, bt_stream_get_name(stream), |
90bd5941 | 215 | stream_class, |
50842bdc PP |
216 | bt_stream_class_get_name(stream_class), |
217 | bt_stream_class_get_id(stream_class), notification); | |
e5be10ef | 218 | return (void *) ¬ification->parent; |
3230ee6b PP |
219 | error: |
220 | return NULL; | |
221 | } | |
222 | ||
094ff7c0 | 223 | struct bt_stream *bt_notification_stream_begin_borrow_stream( |
3230ee6b PP |
224 | struct bt_notification *notification) |
225 | { | |
226 | struct bt_notification_stream_begin *stream_begin; | |
227 | ||
f6ccaed9 PP |
228 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
229 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
230 | BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
3230ee6b PP |
231 | stream_begin = container_of(notification, |
232 | struct bt_notification_stream_begin, parent); | |
094ff7c0 | 233 | return stream_begin->stream; |
3230ee6b | 234 | } |
e22b45d0 | 235 | |
e5be10ef PP |
236 | struct bt_private_stream *bt_private_notification_stream_begin_borrow_stream( |
237 | struct bt_private_notification *notification) | |
238 | { | |
239 | return (void *) bt_notification_stream_begin_borrow_stream( | |
240 | (void *) notification); | |
241 | } | |
242 | ||
243 | int bt_private_notification_stream_begin_set_default_clock_value( | |
244 | struct bt_private_notification *priv_notif, | |
245 | uint64_t value_cycles) | |
e22b45d0 | 246 | { |
44c440bc | 247 | int ret = 0; |
e5be10ef | 248 | struct bt_notification *notif = (void *) priv_notif; |
44c440bc | 249 | struct bt_notification_stream_begin *sb_notif = (void *) notif; |
e22b45d0 PP |
250 | |
251 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
e22b45d0 PP |
252 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
253 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
44c440bc PP |
254 | BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class, |
255 | "Notification's stream class has no default clock class: " | |
256 | "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class); | |
257 | ||
258 | if (!sb_notif->default_cv) { | |
259 | sb_notif->default_cv = bt_clock_value_create( | |
260 | sb_notif->stream->class->default_clock_class); | |
261 | if (!sb_notif->default_cv) { | |
262 | ret = -1; | |
263 | goto end; | |
264 | } | |
265 | } | |
266 | ||
267 | bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles); | |
268 | BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, " | |
269 | "value=%" PRIu64, value_cycles); | |
270 | ||
271 | end: | |
272 | return ret; | |
e22b45d0 PP |
273 | } |
274 | ||
275 | struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value( | |
276 | struct bt_notification *notif) | |
277 | { | |
278 | struct bt_notification_stream_begin *stream_begin = (void *) notif; | |
e22b45d0 PP |
279 | |
280 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
281 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
44c440bc | 282 | return stream_begin->default_cv; |
e22b45d0 | 283 | } |