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> |
f6ccaed9 | 35 | #include <babeltrace/assert-internal.h> |
90bd5941 | 36 | #include <inttypes.h> |
043e2020 JG |
37 | |
38 | static | |
39 | void 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 | ||
90bd5941 PP |
44 | BT_LOGD("Destroying stream end notification: addr=%p", |
45 | notification); | |
46 | BT_LOGD_STR("Putting stream."); | |
043e2020 | 47 | BT_PUT(notification->stream); |
e22b45d0 | 48 | bt_clock_value_set_finalize(¬ification->cv_set); |
043e2020 JG |
49 | g_free(notification); |
50 | } | |
51 | ||
52 | struct bt_notification *bt_notification_stream_end_create( | |
5c563278 | 53 | struct bt_graph *graph, struct bt_stream *stream) |
043e2020 JG |
54 | { |
55 | struct bt_notification_stream_end *notification; | |
50842bdc | 56 | struct bt_stream_class *stream_class; |
e22b45d0 | 57 | int ret; |
043e2020 | 58 | |
f6ccaed9 | 59 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 60 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 61 | BT_ASSERT(stream_class); |
90bd5941 PP |
62 | BT_LOGD("Creating stream end notification object: " |
63 | "stream-addr=%p, stream-name=\"%s\", " | |
64 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
65 | "stream-class-id=%" PRId64, | |
50842bdc | 66 | stream, bt_stream_get_name(stream), |
90bd5941 | 67 | stream_class, |
50842bdc PP |
68 | bt_stream_class_get_name(stream_class), |
69 | bt_stream_class_get_id(stream_class)); | |
043e2020 | 70 | notification = g_new0(struct bt_notification_stream_end, 1); |
90bd5941 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(¬ification->parent, |
77 | BT_NOTIFICATION_TYPE_STREAM_END, | |
5c563278 | 78 | bt_notification_stream_end_destroy, NULL); |
043e2020 | 79 | notification->stream = bt_get(stream); |
e22b45d0 PP |
80 | ret = bt_clock_value_set_initialize(¬ification->cv_set); |
81 | if (ret) { | |
82 | goto error; | |
83 | } | |
84 | ||
90bd5941 PP |
85 | BT_LOGD("Created stream end notification object: " |
86 | "stream-addr=%p, stream-name=\"%s\", " | |
87 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
88 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 89 | stream, bt_stream_get_name(stream), |
90bd5941 | 90 | stream_class, |
50842bdc PP |
91 | bt_stream_class_get_name(stream_class), |
92 | bt_stream_class_get_id(stream_class), notification); | |
043e2020 JG |
93 | return ¬ification->parent; |
94 | error: | |
95 | return NULL; | |
96 | } | |
97 | ||
094ff7c0 | 98 | struct bt_stream *bt_notification_stream_end_borrow_stream( |
043e2020 JG |
99 | struct bt_notification *notification) |
100 | { | |
101 | struct bt_notification_stream_end *stream_end; | |
102 | ||
f6ccaed9 PP |
103 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
104 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
105 | BT_NOTIFICATION_TYPE_STREAM_END); | |
043e2020 JG |
106 | stream_end = container_of(notification, |
107 | struct bt_notification_stream_end, parent); | |
094ff7c0 | 108 | return stream_end->stream; |
043e2020 | 109 | } |
3230ee6b | 110 | |
e22b45d0 PP |
111 | int bt_notification_stream_end_set_clock_value(struct bt_notification *notif, |
112 | struct bt_clock_class *clock_class, uint64_t raw_value, | |
113 | bt_bool is_default) | |
114 | { | |
115 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
116 | ||
117 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
118 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
119 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); | |
120 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
121 | BT_ASSERT_PRE(is_default, | |
122 | "You can only set a default clock value as of this version."); | |
123 | return bt_clock_value_set_set_clock_value(&stream_end->cv_set, | |
124 | clock_class, raw_value, is_default); | |
125 | } | |
126 | ||
127 | struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( | |
128 | struct bt_notification *notif) | |
129 | { | |
130 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
131 | struct bt_clock_value *clock_value = NULL; | |
132 | ||
133 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
134 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
135 | clock_value = stream_end->cv_set.default_cv; | |
136 | if (!clock_value) { | |
137 | BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); | |
138 | } | |
139 | ||
140 | return clock_value; | |
141 | } | |
142 | ||
3230ee6b PP |
143 | static |
144 | void bt_notification_stream_begin_destroy(struct bt_object *obj) | |
145 | { | |
146 | struct bt_notification_stream_begin *notification = | |
147 | (struct bt_notification_stream_begin *) obj; | |
148 | ||
90bd5941 PP |
149 | BT_LOGD("Destroying stream beginning notification: addr=%p", |
150 | notification); | |
151 | BT_LOGD_STR("Putting stream."); | |
3230ee6b | 152 | BT_PUT(notification->stream); |
e22b45d0 | 153 | bt_clock_value_set_finalize(¬ification->cv_set); |
3230ee6b PP |
154 | g_free(notification); |
155 | } | |
156 | ||
157 | struct bt_notification *bt_notification_stream_begin_create( | |
5c563278 | 158 | struct bt_graph *graph, struct bt_stream *stream) |
3230ee6b | 159 | { |
e22b45d0 | 160 | int ret; |
3230ee6b | 161 | struct bt_notification_stream_begin *notification; |
50842bdc | 162 | struct bt_stream_class *stream_class; |
3230ee6b | 163 | |
f6ccaed9 | 164 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
3dca2276 | 165 | stream_class = bt_stream_borrow_class(stream); |
f6ccaed9 | 166 | BT_ASSERT(stream_class); |
90bd5941 PP |
167 | BT_LOGD("Creating stream beginning notification object: " |
168 | "stream-addr=%p, stream-name=\"%s\", " | |
169 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
170 | "stream-class-id=%" PRId64, | |
50842bdc | 171 | stream, bt_stream_get_name(stream), |
90bd5941 | 172 | stream_class, |
50842bdc PP |
173 | bt_stream_class_get_name(stream_class), |
174 | bt_stream_class_get_id(stream_class)); | |
3230ee6b | 175 | notification = g_new0(struct bt_notification_stream_begin, 1); |
90bd5941 PP |
176 | if (!notification) { |
177 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
178 | goto error; | |
179 | } | |
180 | ||
3230ee6b PP |
181 | bt_notification_init(¬ification->parent, |
182 | BT_NOTIFICATION_TYPE_STREAM_BEGIN, | |
5c563278 | 183 | bt_notification_stream_begin_destroy, NULL); |
3230ee6b | 184 | notification->stream = bt_get(stream); |
e22b45d0 PP |
185 | ret = bt_clock_value_set_initialize(¬ification->cv_set); |
186 | if (ret) { | |
187 | goto error; | |
188 | } | |
189 | ||
90bd5941 PP |
190 | BT_LOGD("Created stream beginning notification object: " |
191 | "stream-addr=%p, stream-name=\"%s\", " | |
192 | "stream-class-addr=%p, stream-class-name=\"%s\", " | |
193 | "stream-class-id=%" PRId64 ", addr=%p", | |
50842bdc | 194 | stream, bt_stream_get_name(stream), |
90bd5941 | 195 | stream_class, |
50842bdc PP |
196 | bt_stream_class_get_name(stream_class), |
197 | bt_stream_class_get_id(stream_class), notification); | |
3230ee6b PP |
198 | return ¬ification->parent; |
199 | error: | |
200 | return NULL; | |
201 | } | |
202 | ||
094ff7c0 | 203 | struct bt_stream *bt_notification_stream_begin_borrow_stream( |
3230ee6b PP |
204 | struct bt_notification *notification) |
205 | { | |
206 | struct bt_notification_stream_begin *stream_begin; | |
207 | ||
f6ccaed9 PP |
208 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
209 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
210 | BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
3230ee6b PP |
211 | stream_begin = container_of(notification, |
212 | struct bt_notification_stream_begin, parent); | |
094ff7c0 | 213 | return stream_begin->stream; |
3230ee6b | 214 | } |
e22b45d0 PP |
215 | |
216 | int bt_notification_stream_begin_set_clock_value(struct bt_notification *notif, | |
217 | struct bt_clock_class *clock_class, uint64_t raw_value, | |
218 | bt_bool is_default) | |
219 | { | |
220 | struct bt_notification_stream_begin *stream_begin = (void *) notif; | |
221 | ||
222 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
223 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
224 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); | |
225 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
226 | BT_ASSERT_PRE(is_default, | |
227 | "You can only set a default clock value as of this version."); | |
228 | return bt_clock_value_set_set_clock_value(&stream_begin->cv_set, | |
229 | clock_class, raw_value, is_default); | |
230 | } | |
231 | ||
232 | struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value( | |
233 | struct bt_notification *notif) | |
234 | { | |
235 | struct bt_notification_stream_begin *stream_begin = (void *) notif; | |
236 | struct bt_clock_value *clock_value = NULL; | |
237 | ||
238 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
239 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
240 | clock_value = stream_begin->cv_set.default_cv; | |
241 | if (!clock_value) { | |
242 | BT_LIB_LOGV("No default clock value: %![notif-]+n", notif); | |
243 | } | |
244 | ||
245 | return clock_value; | |
246 | } |