Commit | Line | Data |
---|---|---|
043e2020 JG |
1 | /* |
2 | * Babeltrace Plug-in Stream-related Notifications | |
3 | * | |
4 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
5 | * | |
6 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 | * SOFTWARE. | |
25 | */ | |
26 | ||
90bd5941 PP |
27 | #define BT_LOG_TAG "NOTIF-STREAM" |
28 | #include <babeltrace/lib-logging-internal.h> | |
29 | ||
e22b45d0 | 30 | #include <babeltrace/assert-pre-internal.h> |
3d9990ac | 31 | #include <babeltrace/compiler-internal.h> |
3230ee6b | 32 | #include <babeltrace/ctf-ir/stream-internal.h> |
9d408fca | 33 | #include <babeltrace/ctf-ir/stream-class.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> |
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 | ||
90bd5941 PP |
45 | BT_LOGD("Destroying stream end notification: addr=%p", |
46 | notification); | |
47 | BT_LOGD_STR("Putting stream."); | |
043e2020 | 48 | BT_PUT(notification->stream); |
e22b45d0 | 49 | bt_clock_value_set_finalize(¬ification->cv_set); |
043e2020 JG |
50 | g_free(notification); |
51 | } | |
52 | ||
53 | struct bt_notification *bt_notification_stream_end_create( | |
f0010051 PP |
54 | struct bt_private_connection_private_notification_iterator *notif_iter, |
55 | struct bt_stream *stream) | |
043e2020 JG |
56 | { |
57 | struct bt_notification_stream_end *notification; | |
50842bdc | 58 | struct bt_stream_class *stream_class; |
e22b45d0 | 59 | int ret; |
043e2020 | 60 | |
f6ccaed9 | 61 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 62 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 63 | BT_ASSERT(stream_class); |
90bd5941 PP |
64 | BT_LOGD("Creating stream end notification object: " |
65 | "stream-addr=%p, stream-name=\"%s\", " | |
66 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
67 | "stream-class-id=%" PRId64, | |
50842bdc | 68 | stream, bt_stream_get_name(stream), |
90bd5941 | 69 | stream_class, |
50842bdc PP |
70 | bt_stream_class_get_name(stream_class), |
71 | bt_stream_class_get_id(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(¬ification->parent, |
79 | BT_NOTIFICATION_TYPE_STREAM_END, | |
5c563278 | 80 | bt_notification_stream_end_destroy, NULL); |
043e2020 | 81 | notification->stream = bt_get(stream); |
e22b45d0 PP |
82 | ret = bt_clock_value_set_initialize(¬ification->cv_set); |
83 | if (ret) { | |
84 | goto error; | |
85 | } | |
86 | ||
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); | |
043e2020 JG |
95 | return ¬ification->parent; |
96 | error: | |
97 | return NULL; | |
98 | } | |
99 | ||
094ff7c0 | 100 | struct bt_stream *bt_notification_stream_end_borrow_stream( |
043e2020 JG |
101 | struct bt_notification *notification) |
102 | { | |
103 | struct bt_notification_stream_end *stream_end; | |
104 | ||
f6ccaed9 PP |
105 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
106 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
107 | BT_NOTIFICATION_TYPE_STREAM_END); | |
043e2020 JG |
108 | stream_end = container_of(notification, |
109 | struct bt_notification_stream_end, parent); | |
094ff7c0 | 110 | return stream_end->stream; |
043e2020 | 111 | } |
3230ee6b | 112 | |
e22b45d0 PP |
113 | int bt_notification_stream_end_set_clock_value(struct bt_notification *notif, |
114 | struct bt_clock_class *clock_class, uint64_t raw_value, | |
115 | bt_bool is_default) | |
116 | { | |
117 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
118 | ||
119 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
120 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
121 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); | |
122 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
123 | BT_ASSERT_PRE(is_default, | |
124 | "You can only set a default clock value as of this version."); | |
125 | return bt_clock_value_set_set_clock_value(&stream_end->cv_set, | |
126 | clock_class, raw_value, is_default); | |
127 | } | |
128 | ||
129 | struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( | |
130 | struct bt_notification *notif) | |
131 | { | |
132 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
133 | struct bt_clock_value *clock_value = NULL; | |
134 | ||
135 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
136 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
137 | clock_value = stream_end->cv_set.default_cv; | |
138 | if (!clock_value) { | |
139 | BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); | |
140 | } | |
141 | ||
142 | return clock_value; | |
143 | } | |
144 | ||
3230ee6b PP |
145 | static |
146 | void bt_notification_stream_begin_destroy(struct bt_object *obj) | |
147 | { | |
148 | struct bt_notification_stream_begin *notification = | |
149 | (struct bt_notification_stream_begin *) obj; | |
150 | ||
90bd5941 PP |
151 | BT_LOGD("Destroying stream beginning notification: addr=%p", |
152 | notification); | |
153 | BT_LOGD_STR("Putting stream."); | |
3230ee6b | 154 | BT_PUT(notification->stream); |
e22b45d0 | 155 | bt_clock_value_set_finalize(¬ification->cv_set); |
3230ee6b PP |
156 | g_free(notification); |
157 | } | |
158 | ||
159 | struct bt_notification *bt_notification_stream_begin_create( | |
f0010051 PP |
160 | struct bt_private_connection_private_notification_iterator *notif_iter, |
161 | struct bt_stream *stream) | |
3230ee6b | 162 | { |
e22b45d0 | 163 | int ret; |
3230ee6b | 164 | struct bt_notification_stream_begin *notification; |
50842bdc | 165 | struct bt_stream_class *stream_class; |
3230ee6b | 166 | |
f6ccaed9 | 167 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 168 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 169 | BT_ASSERT(stream_class); |
90bd5941 PP |
170 | BT_LOGD("Creating stream beginning notification object: " |
171 | "stream-addr=%p, stream-name=\"%s\", " | |
172 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
173 | "stream-class-id=%" PRId64, | |
50842bdc | 174 | stream, bt_stream_get_name(stream), |
90bd5941 | 175 | stream_class, |
50842bdc PP |
176 | bt_stream_class_get_name(stream_class), |
177 | bt_stream_class_get_id(stream_class)); | |
3230ee6b | 178 | notification = g_new0(struct bt_notification_stream_begin, 1); |
90bd5941 PP |
179 | if (!notification) { |
180 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
181 | goto error; | |
182 | } | |
183 | ||
3230ee6b PP |
184 | bt_notification_init(¬ification->parent, |
185 | BT_NOTIFICATION_TYPE_STREAM_BEGIN, | |
5c563278 | 186 | bt_notification_stream_begin_destroy, NULL); |
3230ee6b | 187 | notification->stream = bt_get(stream); |
e22b45d0 PP |
188 | ret = bt_clock_value_set_initialize(¬ification->cv_set); |
189 | if (ret) { | |
190 | goto error; | |
191 | } | |
192 | ||
90bd5941 PP |
193 | BT_LOGD("Created stream beginning notification object: " |
194 | "stream-addr=%p, stream-name=\"%s\", " | |
195 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
196 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 197 | stream, bt_stream_get_name(stream), |
90bd5941 | 198 | stream_class, |
50842bdc PP |
199 | bt_stream_class_get_name(stream_class), |
200 | bt_stream_class_get_id(stream_class), notification); | |
3230ee6b PP |
201 | return ¬ification->parent; |
202 | error: | |
203 | return NULL; | |
204 | } | |
205 | ||
094ff7c0 | 206 | struct bt_stream *bt_notification_stream_begin_borrow_stream( |
3230ee6b PP |
207 | struct bt_notification *notification) |
208 | { | |
209 | struct bt_notification_stream_begin *stream_begin; | |
210 | ||
f6ccaed9 PP |
211 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
212 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
213 | BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
3230ee6b PP |
214 | stream_begin = container_of(notification, |
215 | struct bt_notification_stream_begin, parent); | |
094ff7c0 | 216 | return stream_begin->stream; |
3230ee6b | 217 | } |
e22b45d0 PP |
218 | |
219 | int bt_notification_stream_begin_set_clock_value(struct bt_notification *notif, | |
220 | struct bt_clock_class *clock_class, uint64_t raw_value, | |
221 | bt_bool is_default) | |
222 | { | |
223 | struct bt_notification_stream_begin *stream_begin = (void *) notif; | |
224 | ||
225 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
226 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
227 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); | |
228 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
229 | BT_ASSERT_PRE(is_default, | |
230 | "You can only set a default clock value as of this version."); | |
231 | return bt_clock_value_set_set_clock_value(&stream_begin->cv_set, | |
232 | clock_class, raw_value, is_default); | |
233 | } | |
234 | ||
235 | struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value( | |
236 | struct bt_notification *notif) | |
237 | { | |
238 | struct bt_notification_stream_begin *stream_begin = (void *) notif; | |
239 | struct bt_clock_value *clock_value = NULL; | |
240 | ||
241 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
242 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
243 | clock_value = stream_begin->cv_set.default_cv; | |
244 | if (!clock_value) { | |
245 | BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); | |
246 | } | |
247 | ||
248 | return clock_value; | |
249 | } |