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 | ||
d229f56b PP |
25 | #define BT_LOG_TAG "NOTIF-STREAM" |
26 | #include <babeltrace/lib-logging-internal.h> | |
27 | ||
8fc063a2 | 28 | #include <babeltrace/assert-pre-internal.h> |
3d9990ac | 29 | #include <babeltrace/compiler-internal.h> |
108b91d0 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> | |
7b53201c PP |
33 | #include <babeltrace/graph/notification-stream.h> |
34 | #include <babeltrace/graph/notification-stream-const.h> | |
b2e0c907 | 35 | #include <babeltrace/graph/notification-stream-internal.h> |
8b45963b | 36 | #include <babeltrace/assert-internal.h> |
9e550e5f | 37 | #include <babeltrace/object.h> |
d229f56b | 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 | ||
834e9996 | 46 | BT_LIB_LOGD("Destroying stream end notification: %!+n", |
d229f56b | 47 | notification); |
834e9996 | 48 | BT_LIB_LOGD("Putting stream: %!+s", notification->stream); |
8138bfe1 | 49 | BT_OBJECT_PUT_REF_AND_RESET(notification->stream); |
7b33a0e0 PP |
50 | |
51 | if (notification->default_cv) { | |
52 | bt_clock_value_recycle(notification->default_cv); | |
834e9996 | 53 | notification->default_cv = NULL; |
7b33a0e0 PP |
54 | } |
55 | ||
043e2020 JG |
56 | g_free(notification); |
57 | } | |
58 | ||
7b53201c | 59 | struct bt_notification *bt_notification_stream_end_create( |
834e9996 | 60 | struct bt_self_notification_iterator *self_notif_iter, |
78cf9df6 | 61 | struct bt_stream *stream) |
043e2020 JG |
62 | { |
63 | struct bt_notification_stream_end *notification; | |
839d52a5 | 64 | struct bt_stream_class *stream_class; |
043e2020 | 65 | |
834e9996 | 66 | BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator"); |
8b45963b | 67 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
8deee039 | 68 | stream_class = bt_stream_borrow_class(stream); |
8b45963b | 69 | BT_ASSERT(stream_class); |
834e9996 PP |
70 | BT_LIB_LOGD("Creating stream end notification object: " |
71 | "%![stream-]+s, %![sc-]+S", stream, stream_class); | |
043e2020 | 72 | notification = g_new0(struct bt_notification_stream_end, 1); |
d229f56b 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, | |
f7c3ac09 | 80 | bt_notification_stream_end_destroy, NULL); |
4b70020d PP |
81 | notification->stream = stream; |
82 | bt_object_get_no_null_check(notification->stream); | |
834e9996 PP |
83 | BT_LIB_LOGD("Created stream end notification object: " |
84 | "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification, | |
85 | stream, stream_class); | |
9e550e5f PP |
86 | |
87 | return (void *) ¬ification->parent; | |
043e2020 JG |
88 | error: |
89 | return NULL; | |
90 | } | |
91 | ||
7b53201c PP |
92 | struct bt_stream *bt_notification_stream_end_borrow_stream( |
93 | struct bt_notification *notification) | |
043e2020 JG |
94 | { |
95 | struct bt_notification_stream_end *stream_end; | |
96 | ||
8b45963b PP |
97 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
98 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
99 | BT_NOTIFICATION_TYPE_STREAM_END); | |
78cf9df6 | 100 | stream_end = (void *) notification; |
5fe68922 | 101 | return stream_end->stream; |
043e2020 | 102 | } |
3230ee6b | 103 | |
7b53201c PP |
104 | const struct bt_stream *bt_notification_stream_end_borrow_stream_const( |
105 | const struct bt_notification *notification) | |
9e550e5f | 106 | { |
7b53201c | 107 | return bt_notification_stream_end_borrow_stream( |
9e550e5f PP |
108 | (void *) notification); |
109 | } | |
110 | ||
7b53201c PP |
111 | void bt_notification_stream_end_set_default_clock_value( |
112 | struct bt_notification *notif, uint64_t value_cycles) | |
8fc063a2 | 113 | { |
7b33a0e0 | 114 | struct bt_notification_stream_end *se_notif = (void *) notif; |
8fc063a2 PP |
115 | |
116 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
8fc063a2 PP |
117 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
118 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
7b33a0e0 PP |
119 | BT_ASSERT_PRE(se_notif->stream->class->default_clock_class, |
120 | "Notification's stream class has no default clock class: " | |
121 | "%![notif-]+n, %![sc-]+S", notif, se_notif->stream->class); | |
122 | ||
c8bbf821 PP |
123 | /* TODO: have the object already created */ |
124 | se_notif->default_cv = bt_clock_value_create( | |
125 | se_notif->stream->class->default_clock_class); | |
126 | BT_ASSERT(se_notif->default_cv); | |
7b33a0e0 PP |
127 | bt_clock_value_set_value_inline(se_notif->default_cv, value_cycles); |
128 | BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, " | |
129 | "value=%" PRIu64, value_cycles); | |
8fc063a2 PP |
130 | } |
131 | ||
132 | struct bt_clock_value *bt_notification_stream_end_borrow_default_clock_value( | |
133 | struct bt_notification *notif) | |
134 | { | |
135 | struct bt_notification_stream_end *stream_end = (void *) notif; | |
8fc063a2 PP |
136 | |
137 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
138 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_END); | |
7b33a0e0 | 139 | return stream_end->default_cv; |
8fc063a2 PP |
140 | } |
141 | ||
3230ee6b PP |
142 | static |
143 | void bt_notification_stream_begin_destroy(struct bt_object *obj) | |
144 | { | |
145 | struct bt_notification_stream_begin *notification = | |
146 | (struct bt_notification_stream_begin *) obj; | |
147 | ||
834e9996 | 148 | BT_LIB_LOGD("Destroying stream beginning notification: %!+n", |
d229f56b | 149 | notification); |
834e9996 | 150 | BT_LIB_LOGD("Putting stream: %!+s", notification->stream); |
8138bfe1 | 151 | BT_OBJECT_PUT_REF_AND_RESET(notification->stream); |
7b33a0e0 PP |
152 | |
153 | if (notification->default_cv) { | |
154 | bt_clock_value_recycle(notification->default_cv); | |
834e9996 | 155 | notification->default_cv = NULL; |
7b33a0e0 PP |
156 | } |
157 | ||
3230ee6b PP |
158 | g_free(notification); |
159 | } | |
160 | ||
7b53201c | 161 | struct bt_notification *bt_notification_stream_begin_create( |
834e9996 | 162 | struct bt_self_notification_iterator *self_notif_iter, |
78cf9df6 | 163 | struct bt_stream *stream) |
3230ee6b PP |
164 | { |
165 | struct bt_notification_stream_begin *notification; | |
839d52a5 | 166 | struct bt_stream_class *stream_class; |
3230ee6b | 167 | |
834e9996 | 168 | BT_ASSERT_PRE_NON_NULL(self_notif_iter, "Notification iterator"); |
8b45963b | 169 | BT_ASSERT_PRE_NON_NULL(stream, "Stream"); |
8deee039 | 170 | stream_class = bt_stream_borrow_class(stream); |
8b45963b | 171 | BT_ASSERT(stream_class); |
834e9996 PP |
172 | BT_LIB_LOGD("Creating stream beginning notification object: " |
173 | "%![stream-]+s, %![sc-]+S", stream, stream_class); | |
3230ee6b | 174 | notification = g_new0(struct bt_notification_stream_begin, 1); |
d229f56b PP |
175 | if (!notification) { |
176 | BT_LOGE_STR("Failed to allocate one stream beginning notification."); | |
177 | goto error; | |
178 | } | |
179 | ||
3230ee6b PP |
180 | bt_notification_init(¬ification->parent, |
181 | BT_NOTIFICATION_TYPE_STREAM_BEGIN, | |
f7c3ac09 | 182 | bt_notification_stream_begin_destroy, NULL); |
4b70020d PP |
183 | notification->stream = stream; |
184 | bt_object_get_no_null_check(notification->stream); | |
834e9996 PP |
185 | BT_LIB_LOGD("Created stream beginning notification object: " |
186 | "%![notif-]+n, %![stream-]+s, %![sc-]+S", notification, | |
187 | stream, stream_class); | |
9e550e5f | 188 | return (void *) ¬ification->parent; |
3230ee6b PP |
189 | error: |
190 | return NULL; | |
191 | } | |
192 | ||
7b53201c PP |
193 | struct bt_stream *bt_notification_stream_begin_borrow_stream( |
194 | struct bt_notification *notification) | |
3230ee6b PP |
195 | { |
196 | struct bt_notification_stream_begin *stream_begin; | |
197 | ||
8b45963b PP |
198 | BT_ASSERT_PRE_NON_NULL(notification, "Notification"); |
199 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notification, | |
200 | BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
78cf9df6 | 201 | stream_begin = (void *) notification; |
5fe68922 | 202 | return stream_begin->stream; |
3230ee6b | 203 | } |
8fc063a2 | 204 | |
7b53201c PP |
205 | const struct bt_stream *bt_notification_stream_begin_borrow_stream_const( |
206 | const struct bt_notification *notification) | |
9e550e5f | 207 | { |
7b53201c | 208 | return bt_notification_stream_begin_borrow_stream( |
9e550e5f PP |
209 | (void *) notification); |
210 | } | |
211 | ||
7b53201c PP |
212 | void bt_notification_stream_begin_set_default_clock_value( |
213 | struct bt_notification *notif, | |
9e550e5f | 214 | uint64_t value_cycles) |
8fc063a2 | 215 | { |
7b33a0e0 | 216 | struct bt_notification_stream_begin *sb_notif = (void *) notif; |
8fc063a2 PP |
217 | |
218 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
8fc063a2 PP |
219 | BT_ASSERT_PRE_HOT(notif, "Notification", ": %!+n", notif); |
220 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
7b33a0e0 PP |
221 | BT_ASSERT_PRE(sb_notif->stream->class->default_clock_class, |
222 | "Notification's stream class has no default clock class: " | |
223 | "%![notif-]+n, %![sc-]+S", notif, sb_notif->stream->class); | |
224 | ||
c8bbf821 PP |
225 | /* TODO: have the object already created */ |
226 | sb_notif->default_cv = bt_clock_value_create( | |
227 | sb_notif->stream->class->default_clock_class); | |
228 | BT_ASSERT(sb_notif->default_cv); | |
7b33a0e0 PP |
229 | bt_clock_value_set_value_inline(sb_notif->default_cv, value_cycles); |
230 | BT_LIB_LOGV("Set notification's default clock value: %![notif-]+n, " | |
231 | "value=%" PRIu64, value_cycles); | |
8fc063a2 PP |
232 | } |
233 | ||
234 | struct bt_clock_value *bt_notification_stream_begin_borrow_default_clock_value( | |
235 | struct bt_notification *notif) | |
236 | { | |
237 | struct bt_notification_stream_begin *stream_begin = (void *) notif; | |
8fc063a2 PP |
238 | |
239 | BT_ASSERT_PRE_NON_NULL(notif, "Notification"); | |
240 | BT_ASSERT_PRE_NOTIF_IS_TYPE(notif, BT_NOTIFICATION_TYPE_STREAM_BEGIN); | |
7b33a0e0 | 241 | return stream_begin->default_cv; |
8fc063a2 | 242 | } |