Commit | Line | Data |
---|---|---|
11b0cdc8 | 1 | /* |
e2f7325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
de9dd397 | 3 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
11b0cdc8 | 4 | * |
11b0cdc8 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 | ||
350ad6c1 | 24 | #define BT_LOG_TAG "LIB/STREAM-CLASS" |
c2d9d9cf | 25 | #include "lib/logging.h" |
d2f71f12 | 26 | |
578e048b | 27 | #include "lib/assert-pre.h" |
3fadfbc0 | 28 | #include <babeltrace2/trace-ir/trace-const.h> |
578e048b MJ |
29 | #include "compat/compiler.h" |
30 | #include "common/align.h" | |
31 | #include "compat/endian.h" | |
32 | #include "common/assert.h" | |
33 | #include "lib/property.h" | |
dc3fffef | 34 | #include <inttypes.h> |
544d0515 | 35 | #include <stdint.h> |
e011d2c1 | 36 | #include <stdbool.h> |
11b0cdc8 | 37 | |
578e048b MJ |
38 | #include "clock-class.h" |
39 | #include "event-class.h" | |
40 | #include "field-class.h" | |
41 | #include "field.h" | |
42 | #include "field-wrapper.h" | |
43 | #include "resolve-field-path.h" | |
44 | #include "stream-class.h" | |
45 | #include "trace.h" | |
46 | #include "utils.h" | |
d24d5663 | 47 | #include "lib/func-status.h" |
578e048b | 48 | |
bdb288b3 PP |
49 | #define BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(_sc) \ |
50 | BT_ASSERT_PRE_DEV_HOT((_sc), "Stream class", ": %!+S", (_sc)) | |
142c5610 | 51 | |
cb6f1f7d | 52 | static |
44c440bc | 53 | void destroy_stream_class(struct bt_object *obj) |
3ea33115 | 54 | { |
cb6f1f7d PP |
55 | struct bt_stream_class *stream_class = (void *) obj; |
56 | ||
44c440bc PP |
57 | BT_LIB_LOGD("Destroying stream class: %!+S", stream_class); |
58 | BT_LOGD_STR("Putting default clock class."); | |
238b7404 | 59 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class); |
3ea33115 | 60 | |
3dca2276 PP |
61 | if (stream_class->event_classes) { |
62 | BT_LOGD_STR("Destroying event classes."); | |
63 | g_ptr_array_free(stream_class->event_classes, TRUE); | |
238b7404 | 64 | stream_class->event_classes = NULL; |
d2f71f12 PP |
65 | } |
66 | ||
44c440bc PP |
67 | if (stream_class->name.str) { |
68 | g_string_free(stream_class->name.str, TRUE); | |
238b7404 PP |
69 | stream_class->name.str = NULL; |
70 | stream_class->name.value = NULL; | |
3ea33115 JG |
71 | } |
72 | ||
e6276565 | 73 | BT_LOGD_STR("Putting packet context field class."); |
238b7404 | 74 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); |
e6276565 | 75 | BT_LOGD_STR("Putting event common context field class."); |
238b7404 | 76 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_common_context_fc); |
312c056a | 77 | bt_object_pool_finalize(&stream_class->packet_context_field_pool); |
3dca2276 | 78 | g_free(stream_class); |
3ea33115 JG |
79 | } |
80 | ||
312c056a PP |
81 | static |
82 | void free_field_wrapper(struct bt_field_wrapper *field_wrapper, | |
83 | struct bt_stream_class *stream_class) | |
84 | { | |
85 | bt_field_wrapper_destroy((void *) field_wrapper); | |
86 | } | |
87 | ||
44c440bc | 88 | static |
862ca4ed | 89 | bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id) |
44c440bc PP |
90 | { |
91 | uint64_t i; | |
92 | bool is_unique = true; | |
93 | ||
862ca4ed | 94 | for (i = 0; i < tc->stream_classes->len; i++) { |
40f4ba76 | 95 | const struct bt_stream_class *sc = |
862ca4ed | 96 | tc->stream_classes->pdata[i]; |
44c440bc PP |
97 | |
98 | if (sc->id == id) { | |
99 | is_unique = false; | |
100 | goto end; | |
101 | } | |
102 | } | |
103 | ||
104 | end: | |
105 | return is_unique; | |
106 | } | |
107 | ||
108 | static | |
862ca4ed PP |
109 | struct bt_stream_class *create_stream_class_with_id( |
110 | struct bt_trace_class *tc, uint64_t id) | |
2f100782 | 111 | { |
3dca2276 PP |
112 | struct bt_stream_class *stream_class = NULL; |
113 | int ret; | |
2f100782 | 114 | |
862ca4ed PP |
115 | BT_ASSERT(tc); |
116 | BT_ASSERT_PRE(stream_class_id_is_unique(tc, id), | |
117 | "Duplicate stream class ID: %![tc-]+T, id=%" PRIu64, tc, id); | |
118 | BT_LIB_LOGD("Creating stream class object: %![tc-]+T, id=%" PRIu64, | |
119 | tc, id); | |
3dca2276 | 120 | stream_class = g_new0(struct bt_stream_class, 1); |
d2f71f12 | 121 | if (!stream_class) { |
870631a2 PP |
122 | BT_LIB_LOGE_APPEND_CAUSE( |
123 | "Failed to allocate one stream class."); | |
3dca2276 | 124 | goto error; |
d2f71f12 PP |
125 | } |
126 | ||
44c440bc PP |
127 | bt_object_init_shared_with_parent(&stream_class->base, |
128 | destroy_stream_class); | |
129 | ||
130 | stream_class->name.str = g_string_new(NULL); | |
131 | if (!stream_class->name.str) { | |
870631a2 | 132 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
44c440bc PP |
133 | ret = -1; |
134 | goto end; | |
135 | } | |
136 | ||
137 | stream_class->id = id; | |
138 | stream_class->assigns_automatic_event_class_id = true; | |
139 | stream_class->assigns_automatic_stream_id = true; | |
140 | stream_class->event_classes = g_ptr_array_new_with_free_func( | |
141 | (GDestroyNotify) bt_object_try_spec_release); | |
142 | if (!stream_class->event_classes) { | |
870631a2 | 143 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); |
3dca2276 | 144 | goto error; |
2f100782 JG |
145 | } |
146 | ||
312c056a PP |
147 | ret = bt_object_pool_initialize(&stream_class->packet_context_field_pool, |
148 | (bt_object_pool_new_object_func) bt_field_wrapper_new, | |
149 | (bt_object_pool_destroy_object_func) free_field_wrapper, | |
150 | stream_class); | |
151 | if (ret) { | |
870631a2 PP |
152 | BT_LIB_LOGE_APPEND_CAUSE( |
153 | "Failed to initialize packet context field pool: ret=%d", | |
312c056a PP |
154 | ret); |
155 | goto error; | |
156 | } | |
157 | ||
862ca4ed PP |
158 | bt_object_set_parent(&stream_class->base, &tc->base); |
159 | g_ptr_array_add(tc->stream_classes, stream_class); | |
160 | bt_trace_class_freeze(tc); | |
44c440bc | 161 | BT_LIB_LOGD("Created stream class object: %!+S", stream_class); |
312c056a PP |
162 | goto end; |
163 | ||
164 | error: | |
65300d60 | 165 | BT_OBJECT_PUT_REF_AND_RESET(stream_class); |
312c056a PP |
166 | |
167 | end: | |
44c440bc | 168 | return stream_class; |
312c056a PP |
169 | } |
170 | ||
862ca4ed | 171 | struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc) |
312c056a | 172 | { |
862ca4ed PP |
173 | BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); |
174 | BT_ASSERT_PRE(tc->assigns_automatic_stream_class_id, | |
175 | "Trace class does not automatically assigns stream class IDs: " | |
176 | "%![sc-]+T", tc); | |
177 | return create_stream_class_with_id(tc, | |
178 | (uint64_t) tc->stream_classes->len); | |
44c440bc | 179 | } |
312c056a | 180 | |
40f4ba76 | 181 | struct bt_stream_class *bt_stream_class_create_with_id( |
862ca4ed | 182 | struct bt_trace_class *tc, uint64_t id) |
44c440bc | 183 | { |
862ca4ed PP |
184 | BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); |
185 | BT_ASSERT_PRE(!tc->assigns_automatic_stream_class_id, | |
186 | "Trace class automatically assigns stream class IDs: " | |
187 | "%![sc-]+T", tc); | |
188 | return create_stream_class_with_id(tc, id); | |
312c056a PP |
189 | } |
190 | ||
862ca4ed | 191 | struct bt_trace_class *bt_stream_class_borrow_trace_class( |
40f4ba76 | 192 | struct bt_stream_class *stream_class) |
11b0cdc8 | 193 | { |
bdb288b3 | 194 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
862ca4ed | 195 | return bt_stream_class_borrow_trace_class_inline(stream_class); |
11b0cdc8 JG |
196 | } |
197 | ||
862ca4ed | 198 | const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( |
40f4ba76 | 199 | const struct bt_stream_class *stream_class) |
e5be10ef | 200 | { |
862ca4ed | 201 | return bt_stream_class_borrow_trace_class((void *) stream_class); |
e5be10ef PP |
202 | } |
203 | ||
40f4ba76 | 204 | const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class) |
2f100782 | 205 | { |
bdb288b3 | 206 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
44c440bc | 207 | return stream_class->name.value; |
2f100782 JG |
208 | } |
209 | ||
d24d5663 | 210 | enum bt_stream_class_set_name_status bt_stream_class_set_name( |
40f4ba76 | 211 | struct bt_stream_class *stream_class, |
3dca2276 | 212 | const char *name) |
5ca83563 | 213 | { |
44c440bc PP |
214 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
215 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
bdb288b3 | 216 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
44c440bc PP |
217 | g_string_assign(stream_class->name.str, name); |
218 | stream_class->name.value = stream_class->name.str->str; | |
3f7d4d90 | 219 | BT_LIB_LOGD("Set stream class's name: %!+S", stream_class); |
d24d5663 | 220 | return BT_FUNC_STATUS_OK; |
5ca83563 JG |
221 | } |
222 | ||
40f4ba76 | 223 | uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class) |
2f100782 | 224 | { |
bdb288b3 | 225 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
44c440bc | 226 | return stream_class->id; |
2f100782 JG |
227 | } |
228 | ||
44c440bc | 229 | uint64_t bt_stream_class_get_event_class_count( |
40f4ba76 | 230 | const struct bt_stream_class *stream_class) |
29664b2a | 231 | { |
bdb288b3 | 232 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
44c440bc | 233 | return (uint64_t) stream_class->event_classes->len; |
29664b2a PP |
234 | } |
235 | ||
44c440bc PP |
236 | struct bt_event_class *bt_stream_class_borrow_event_class_by_index( |
237 | struct bt_stream_class *stream_class, uint64_t index) | |
0d23acbe | 238 | { |
bdb288b3 PP |
239 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
240 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, stream_class->event_classes->len); | |
44c440bc | 241 | return g_ptr_array_index(stream_class->event_classes, index); |
0d23acbe PP |
242 | } |
243 | ||
40f4ba76 PP |
244 | const struct bt_event_class * |
245 | bt_stream_class_borrow_event_class_by_index_const( | |
246 | const struct bt_stream_class *stream_class, uint64_t index) | |
e5be10ef | 247 | { |
40f4ba76 | 248 | return bt_stream_class_borrow_event_class_by_index( |
e5be10ef PP |
249 | (void *) stream_class, index); |
250 | } | |
251 | ||
44c440bc | 252 | struct bt_event_class *bt_stream_class_borrow_event_class_by_id( |
e5be10ef | 253 | struct bt_stream_class *stream_class, uint64_t id) |
11b0cdc8 | 254 | { |
44c440bc PP |
255 | struct bt_event_class *event_class = NULL; |
256 | uint64_t i; | |
0b9ce69f | 257 | |
bdb288b3 | 258 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
11b0cdc8 | 259 | |
e5be10ef | 260 | for (i = 0; i < stream_class->event_classes->len; i++) { |
44c440bc | 261 | struct bt_event_class *event_class_candidate = |
e5be10ef | 262 | g_ptr_array_index(stream_class->event_classes, i); |
e6a8e8e4 | 263 | |
44c440bc PP |
264 | if (event_class_candidate->id == id) { |
265 | event_class = event_class_candidate; | |
09840de5 PP |
266 | goto end; |
267 | } | |
69dc4535 JG |
268 | } |
269 | ||
69dc4535 | 270 | end: |
44c440bc | 271 | return event_class; |
0863f950 PP |
272 | } |
273 | ||
40f4ba76 PP |
274 | const struct bt_event_class * |
275 | bt_stream_class_borrow_event_class_by_id_const( | |
276 | const struct bt_stream_class *stream_class, uint64_t id) | |
e5be10ef | 277 | { |
40f4ba76 | 278 | return bt_stream_class_borrow_event_class_by_id( |
e5be10ef PP |
279 | (void *) stream_class, id); |
280 | } | |
281 | ||
40f4ba76 PP |
282 | const struct bt_field_class * |
283 | bt_stream_class_borrow_packet_context_field_class_const( | |
284 | const struct bt_stream_class *stream_class) | |
12c8a1a3 | 285 | { |
bdb288b3 | 286 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 287 | return stream_class->packet_context_fc; |
12c8a1a3 JG |
288 | } |
289 | ||
740faaf4 PP |
290 | struct bt_field_class * |
291 | bt_stream_class_borrow_packet_context_field_class( | |
292 | struct bt_stream_class *stream_class) | |
293 | { | |
bdb288b3 | 294 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
740faaf4 PP |
295 | return stream_class->packet_context_fc; |
296 | } | |
297 | ||
d24d5663 PP |
298 | enum bt_stream_class_set_field_class_status |
299 | bt_stream_class_set_packet_context_field_class( | |
40f4ba76 PP |
300 | struct bt_stream_class *stream_class, |
301 | struct bt_field_class *field_class) | |
12c8a1a3 | 302 | { |
44c440bc PP |
303 | int ret; |
304 | struct bt_resolve_field_path_context resolve_ctx = { | |
5cd6d0e5 | 305 | .packet_context = field_class, |
44c440bc PP |
306 | .event_common_context = NULL, |
307 | .event_specific_context = NULL, | |
308 | .event_payload = NULL, | |
309 | }; | |
cb6f1f7d | 310 | |
44c440bc | 311 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
26fc5aed PP |
312 | BT_ASSERT_PRE(stream_class->supports_packets, |
313 | "Stream class does not support packets: %![sc-]+S", | |
314 | stream_class); | |
5cd6d0e5 | 315 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
bdb288b3 | 316 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
864cad70 PP |
317 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
318 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 319 | "Packet context field class is not a structure field class: %!+F", |
5cd6d0e5 | 320 | field_class); |
5cd6d0e5 | 321 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
44c440bc | 322 | if (ret) { |
a6ae8edc PP |
323 | /* |
324 | * This is the only reason for which | |
325 | * bt_resolve_field_paths() can fail: anything else | |
326 | * would be because a precondition is not satisfied. | |
327 | */ | |
d24d5663 | 328 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
cb6f1f7d PP |
329 | goto end; |
330 | } | |
331 | ||
862ca4ed | 332 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 333 | bt_object_put_ref(stream_class->packet_context_fc); |
398454ed PP |
334 | stream_class->packet_context_fc = field_class; |
335 | bt_object_get_no_null_check(stream_class->packet_context_fc); | |
5cd6d0e5 | 336 | bt_field_class_freeze(field_class); |
3f7d4d90 | 337 | BT_LIB_LOGD("Set stream class's packet context field class: %!+S", |
44c440bc | 338 | stream_class); |
cb6f1f7d PP |
339 | |
340 | end: | |
341 | return ret; | |
12c8a1a3 JG |
342 | } |
343 | ||
40f4ba76 PP |
344 | const struct bt_field_class * |
345 | bt_stream_class_borrow_event_common_context_field_class_const( | |
346 | const struct bt_stream_class *stream_class) | |
af181248 | 347 | { |
bdb288b3 | 348 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 349 | return stream_class->event_common_context_fc; |
af181248 JG |
350 | } |
351 | ||
740faaf4 PP |
352 | struct bt_field_class * |
353 | bt_stream_class_borrow_event_common_context_field_class( | |
354 | struct bt_stream_class *stream_class) | |
355 | { | |
bdb288b3 | 356 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
740faaf4 PP |
357 | return stream_class->event_common_context_fc; |
358 | } | |
359 | ||
d24d5663 | 360 | enum bt_stream_class_set_field_class_status |
a6ae8edc | 361 | bt_stream_class_set_event_common_context_field_class( |
40f4ba76 PP |
362 | struct bt_stream_class *stream_class, |
363 | struct bt_field_class *field_class) | |
af181248 | 364 | { |
44c440bc PP |
365 | int ret; |
366 | struct bt_resolve_field_path_context resolve_ctx = { | |
44c440bc | 367 | .packet_context = NULL, |
5cd6d0e5 | 368 | .event_common_context = field_class, |
44c440bc PP |
369 | .event_specific_context = NULL, |
370 | .event_payload = NULL, | |
371 | }; | |
cb6f1f7d | 372 | |
44c440bc | 373 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 374 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
bdb288b3 | 375 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
864cad70 PP |
376 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
377 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 378 | "Event common context field class is not a structure field class: %!+F", |
5cd6d0e5 | 379 | field_class); |
5cd6d0e5 | 380 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
5cd6d0e5 | 381 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
44c440bc | 382 | if (ret) { |
a6ae8edc PP |
383 | /* |
384 | * This is the only reason for which | |
385 | * bt_resolve_field_paths() can fail: anything else | |
386 | * would be because a precondition is not satisfied. | |
387 | */ | |
d24d5663 | 388 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
cb6f1f7d PP |
389 | goto end; |
390 | } | |
391 | ||
862ca4ed | 392 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 393 | bt_object_put_ref(stream_class->event_common_context_fc); |
398454ed PP |
394 | stream_class->event_common_context_fc = field_class; |
395 | bt_object_get_no_null_check(stream_class->event_common_context_fc); | |
5cd6d0e5 | 396 | bt_field_class_freeze(field_class); |
3f7d4d90 | 397 | BT_LIB_LOGD("Set stream class's event common context field class: %!+S", |
44c440bc | 398 | stream_class); |
cb6f1f7d | 399 | |
cb6f1f7d PP |
400 | end: |
401 | return ret; | |
11b0cdc8 JG |
402 | } |
403 | ||
44c440bc | 404 | BT_HIDDEN |
40f4ba76 | 405 | void _bt_stream_class_freeze(const struct bt_stream_class *stream_class) |
8bf65fbd | 406 | { |
5cd6d0e5 | 407 | /* The field classes and default clock class are already frozen */ |
44c440bc PP |
408 | BT_ASSERT(stream_class); |
409 | BT_LIB_LOGD("Freezing stream class: %!+S", stream_class); | |
40f4ba76 | 410 | ((struct bt_stream_class *) stream_class)->frozen = true; |
8bf65fbd JG |
411 | } |
412 | ||
d24d5663 PP |
413 | enum bt_stream_class_set_default_clock_class_status |
414 | bt_stream_class_set_default_clock_class( | |
40f4ba76 | 415 | struct bt_stream_class *stream_class, |
44c440bc | 416 | struct bt_clock_class *clock_class) |
8bf65fbd | 417 | { |
44c440bc PP |
418 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
419 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
bdb288b3 | 420 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
65300d60 | 421 | bt_object_put_ref(stream_class->default_clock_class); |
398454ed PP |
422 | stream_class->default_clock_class = clock_class; |
423 | bt_object_get_no_null_check(stream_class->default_clock_class); | |
44c440bc | 424 | bt_clock_class_freeze(clock_class); |
3f7d4d90 | 425 | BT_LIB_LOGD("Set stream class's default clock class: %!+S", |
44c440bc | 426 | stream_class); |
d24d5663 | 427 | return BT_FUNC_STATUS_OK; |
8bf65fbd JG |
428 | } |
429 | ||
44c440bc PP |
430 | struct bt_clock_class *bt_stream_class_borrow_default_clock_class( |
431 | struct bt_stream_class *stream_class) | |
8bf65fbd | 432 | { |
bdb288b3 | 433 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
44c440bc PP |
434 | return stream_class->default_clock_class; |
435 | } | |
8bf65fbd | 436 | |
40f4ba76 PP |
437 | const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const( |
438 | const struct bt_stream_class *stream_class) | |
439 | { | |
bdb288b3 | 440 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
40f4ba76 PP |
441 | return stream_class->default_clock_class; |
442 | } | |
443 | ||
44c440bc | 444 | bt_bool bt_stream_class_assigns_automatic_event_class_id( |
40f4ba76 | 445 | const struct bt_stream_class *stream_class) |
44c440bc | 446 | { |
bdb288b3 | 447 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
44c440bc | 448 | return (bt_bool) stream_class->assigns_automatic_event_class_id; |
8bf65fbd JG |
449 | } |
450 | ||
40f4ba76 PP |
451 | void bt_stream_class_set_assigns_automatic_event_class_id( |
452 | struct bt_stream_class *stream_class, | |
e5be10ef | 453 | bt_bool value) |
8bf65fbd | 454 | { |
44c440bc | 455 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
bdb288b3 | 456 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
44c440bc | 457 | stream_class->assigns_automatic_event_class_id = (bool) value; |
3f7d4d90 | 458 | BT_LIB_LOGD("Set stream class's automatic event class ID " |
44c440bc | 459 | "assignment property: %!+S", stream_class); |
44c440bc | 460 | } |
8bf65fbd | 461 | |
44c440bc | 462 | bt_bool bt_stream_class_assigns_automatic_stream_id( |
40f4ba76 | 463 | const struct bt_stream_class *stream_class) |
44c440bc | 464 | { |
bdb288b3 | 465 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
44c440bc PP |
466 | return (bt_bool) stream_class->assigns_automatic_stream_id; |
467 | } | |
8bf65fbd | 468 | |
2e90378a PP |
469 | void bt_stream_class_set_supports_discarded_events( |
470 | struct bt_stream_class *stream_class, | |
471 | bt_bool supports_discarded_events, | |
472 | bt_bool with_default_clock_snapshots) | |
473 | { | |
474 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
bdb288b3 | 475 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
2e90378a PP |
476 | BT_ASSERT_PRE(supports_discarded_events || |
477 | !with_default_clock_snapshots, | |
478 | "Discarded events cannot have default clock snapshots when " | |
479 | "not supported: %!+S", stream_class); | |
480 | BT_ASSERT_PRE(!with_default_clock_snapshots || | |
481 | stream_class->default_clock_class, | |
482 | "Stream class has no default clock class: %!+S", stream_class); | |
483 | stream_class->supports_discarded_events = | |
484 | (bool) supports_discarded_events; | |
485 | stream_class->discarded_events_have_default_clock_snapshots = | |
486 | (bool) with_default_clock_snapshots; | |
3f7d4d90 | 487 | BT_LIB_LOGD("Set stream class's discarded events support property: " |
2e90378a PP |
488 | "%!+S", stream_class); |
489 | } | |
490 | ||
491 | bt_bool bt_stream_class_supports_discarded_events( | |
492 | const struct bt_stream_class *stream_class) | |
493 | { | |
bdb288b3 | 494 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
2e90378a PP |
495 | return (bt_bool) stream_class->supports_discarded_events; |
496 | } | |
497 | ||
498 | bt_bool bt_stream_class_discarded_events_have_default_clock_snapshots( | |
499 | const struct bt_stream_class *stream_class) | |
500 | { | |
bdb288b3 | 501 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
2e90378a PP |
502 | return (bt_bool) stream_class->discarded_events_have_default_clock_snapshots; |
503 | } | |
504 | ||
505 | void bt_stream_class_set_supports_discarded_packets( | |
506 | struct bt_stream_class *stream_class, | |
507 | bt_bool supports_discarded_packets, | |
508 | bt_bool with_default_clock_snapshots) | |
509 | { | |
510 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
bdb288b3 | 511 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
26fc5aed PP |
512 | BT_ASSERT_PRE(!supports_discarded_packets || |
513 | stream_class->supports_packets, | |
514 | "Stream class does not support packets: %!+S", | |
515 | stream_class); | |
2e90378a PP |
516 | BT_ASSERT_PRE(supports_discarded_packets || |
517 | !with_default_clock_snapshots, | |
518 | "Discarded packets cannot have default clock snapshots when " | |
519 | "not supported: %!+S", stream_class); | |
520 | BT_ASSERT_PRE(!with_default_clock_snapshots || | |
521 | stream_class->default_clock_class, | |
522 | "Stream class has no default clock class: %!+S", stream_class); | |
523 | stream_class->supports_discarded_packets = | |
524 | (bool) supports_discarded_packets; | |
525 | stream_class->discarded_packets_have_default_clock_snapshots = | |
526 | (bool) with_default_clock_snapshots; | |
3f7d4d90 | 527 | BT_LIB_LOGD("Set stream class's discarded packets support property: " |
2e90378a PP |
528 | "%!+S", stream_class); |
529 | } | |
530 | ||
531 | bt_bool bt_stream_class_supports_discarded_packets( | |
532 | const struct bt_stream_class *stream_class) | |
533 | { | |
bdb288b3 | 534 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
2e90378a PP |
535 | return (bt_bool) stream_class->supports_discarded_packets; |
536 | } | |
537 | ||
538 | bt_bool bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
539 | const struct bt_stream_class *stream_class) | |
540 | { | |
bdb288b3 | 541 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
2e90378a PP |
542 | return (bt_bool) stream_class->discarded_packets_have_default_clock_snapshots; |
543 | } | |
544 | ||
26fc5aed PP |
545 | void bt_stream_class_set_supports_packets( |
546 | struct bt_stream_class *stream_class, | |
547 | bt_bool supports_packets, | |
548 | bt_bool with_beginning_default_clock_snapshot, | |
549 | bt_bool with_end_default_clock_snapshot) | |
550 | { | |
551 | bt_bool with_default_clock_snapshot = | |
552 | with_beginning_default_clock_snapshot || | |
553 | with_end_default_clock_snapshot; | |
554 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
bdb288b3 | 555 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
26fc5aed PP |
556 | BT_ASSERT_PRE(supports_packets || |
557 | !with_default_clock_snapshot, | |
558 | "Packets cannot have default clock snapshots when " | |
559 | "not supported: %!+S", stream_class); | |
560 | BT_ASSERT_PRE(!with_default_clock_snapshot || | |
561 | stream_class->default_clock_class, | |
562 | "Stream class has no default clock class: %!+S", stream_class); | |
563 | BT_ASSERT_PRE(supports_packets || !stream_class->packet_context_fc, | |
564 | "Stream class already has a packet context field class: %!+S", | |
565 | stream_class); | |
566 | BT_ASSERT_PRE(supports_packets || | |
567 | !stream_class->supports_discarded_packets, | |
568 | "Stream class already supports discarded packets: %!+S", | |
569 | stream_class); | |
570 | stream_class->supports_packets = (bool) supports_packets; | |
571 | stream_class->packets_have_beginning_default_clock_snapshot = | |
572 | (bool) with_beginning_default_clock_snapshot; | |
573 | stream_class->packets_have_end_default_clock_snapshot = | |
574 | (bool) with_end_default_clock_snapshot; | |
575 | BT_LIB_LOGD("Set stream class's packets support property: %!+S", | |
576 | stream_class); | |
577 | } | |
578 | ||
579 | bt_bool bt_stream_class_supports_packets( | |
580 | const struct bt_stream_class *stream_class) | |
581 | { | |
582 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
583 | return (bt_bool) stream_class->supports_packets; | |
584 | } | |
585 | ||
586 | bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot( | |
587 | const struct bt_stream_class *stream_class) | |
588 | { | |
bdb288b3 | 589 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
26fc5aed PP |
590 | return (bt_bool) stream_class->packets_have_beginning_default_clock_snapshot; |
591 | } | |
592 | ||
593 | bt_bool bt_stream_class_packets_have_end_default_clock_snapshot( | |
594 | const struct bt_stream_class *stream_class) | |
595 | { | |
bdb288b3 | 596 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
26fc5aed PP |
597 | return (bt_bool) stream_class->packets_have_end_default_clock_snapshot; |
598 | } | |
599 | ||
40f4ba76 PP |
600 | void bt_stream_class_set_assigns_automatic_stream_id( |
601 | struct bt_stream_class *stream_class, | |
e5be10ef | 602 | bt_bool value) |
44c440bc PP |
603 | { |
604 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
bdb288b3 | 605 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
44c440bc | 606 | stream_class->assigns_automatic_stream_id = (bool) value; |
3f7d4d90 | 607 | BT_LIB_LOGD("Set stream class's automatic stream ID " |
44c440bc | 608 | "assignment property: %!+S", stream_class); |
44c440bc | 609 | } |
3dca2276 | 610 | |
c5b9b441 PP |
611 | void bt_stream_class_get_ref(const struct bt_stream_class *stream_class) |
612 | { | |
613 | bt_object_get_ref(stream_class); | |
614 | } | |
615 | ||
616 | void bt_stream_class_put_ref(const struct bt_stream_class *stream_class) | |
617 | { | |
618 | bt_object_put_ref(stream_class); | |
619 | } |