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