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