Document libbabeltrace2's C API
[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.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_NO_ERROR();
181 BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
182 BT_ASSERT_PRE(tc->assigns_automatic_stream_class_id,
183 "Trace class does not automatically assigns stream class IDs: "
184 "%![sc-]+T", tc);
185 return create_stream_class_with_id(tc,
186 (uint64_t) tc->stream_classes->len);
187 }
188
189 struct bt_stream_class *bt_stream_class_create_with_id(
190 struct bt_trace_class *tc, uint64_t id)
191 {
192 BT_ASSERT_PRE_NO_ERROR();
193 BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
194 BT_ASSERT_PRE(!tc->assigns_automatic_stream_class_id,
195 "Trace class automatically assigns stream class IDs: "
196 "%![sc-]+T", tc);
197 return create_stream_class_with_id(tc, id);
198 }
199
200 struct bt_trace_class *bt_stream_class_borrow_trace_class(
201 struct bt_stream_class *stream_class)
202 {
203 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
204 return bt_stream_class_borrow_trace_class_inline(stream_class);
205 }
206
207 const struct bt_trace_class *bt_stream_class_borrow_trace_class_const(
208 const struct bt_stream_class *stream_class)
209 {
210 return bt_stream_class_borrow_trace_class((void *) stream_class);
211 }
212
213 const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class)
214 {
215 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
216 return stream_class->name.value;
217 }
218
219 enum bt_stream_class_set_name_status bt_stream_class_set_name(
220 struct bt_stream_class *stream_class,
221 const char *name)
222 {
223 BT_ASSERT_PRE_NO_ERROR();
224 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
225 BT_ASSERT_PRE_NON_NULL(name, "Name");
226 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
227 g_string_assign(stream_class->name.str, name);
228 stream_class->name.value = stream_class->name.str->str;
229 BT_LIB_LOGD("Set stream class's name: %!+S", stream_class);
230 return BT_FUNC_STATUS_OK;
231 }
232
233 uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class)
234 {
235 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
236 return stream_class->id;
237 }
238
239 uint64_t bt_stream_class_get_event_class_count(
240 const struct bt_stream_class *stream_class)
241 {
242 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
243 return (uint64_t) stream_class->event_classes->len;
244 }
245
246 struct bt_event_class *bt_stream_class_borrow_event_class_by_index(
247 struct bt_stream_class *stream_class, uint64_t index)
248 {
249 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
250 BT_ASSERT_PRE_DEV_VALID_INDEX(index, stream_class->event_classes->len);
251 return g_ptr_array_index(stream_class->event_classes, index);
252 }
253
254 const struct bt_event_class *
255 bt_stream_class_borrow_event_class_by_index_const(
256 const struct bt_stream_class *stream_class, uint64_t index)
257 {
258 return bt_stream_class_borrow_event_class_by_index(
259 (void *) stream_class, index);
260 }
261
262 struct bt_event_class *bt_stream_class_borrow_event_class_by_id(
263 struct bt_stream_class *stream_class, uint64_t id)
264 {
265 struct bt_event_class *event_class = NULL;
266 uint64_t i;
267
268 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
269
270 for (i = 0; i < stream_class->event_classes->len; i++) {
271 struct bt_event_class *event_class_candidate =
272 g_ptr_array_index(stream_class->event_classes, i);
273
274 if (event_class_candidate->id == id) {
275 event_class = event_class_candidate;
276 goto end;
277 }
278 }
279
280 end:
281 return event_class;
282 }
283
284 const struct bt_event_class *
285 bt_stream_class_borrow_event_class_by_id_const(
286 const struct bt_stream_class *stream_class, uint64_t id)
287 {
288 return bt_stream_class_borrow_event_class_by_id(
289 (void *) stream_class, id);
290 }
291
292 const struct bt_field_class *
293 bt_stream_class_borrow_packet_context_field_class_const(
294 const struct bt_stream_class *stream_class)
295 {
296 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
297 return stream_class->packet_context_fc;
298 }
299
300 struct bt_field_class *
301 bt_stream_class_borrow_packet_context_field_class(
302 struct bt_stream_class *stream_class)
303 {
304 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
305 return stream_class->packet_context_fc;
306 }
307
308 enum bt_stream_class_set_field_class_status
309 bt_stream_class_set_packet_context_field_class(
310 struct bt_stream_class *stream_class,
311 struct bt_field_class *field_class)
312 {
313 int ret;
314 struct bt_resolve_field_path_context resolve_ctx = {
315 .packet_context = field_class,
316 .event_common_context = NULL,
317 .event_specific_context = NULL,
318 .event_payload = NULL,
319 };
320
321 BT_ASSERT_PRE_NO_ERROR();
322 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
323 BT_ASSERT_PRE(stream_class->supports_packets,
324 "Stream class does not support packets: %![sc-]+S",
325 stream_class);
326 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
327 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
328 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
329 BT_FIELD_CLASS_TYPE_STRUCTURE,
330 "Packet context field class is not a structure field class: %!+F",
331 field_class);
332 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
333 if (ret) {
334 /*
335 * This is the only reason for which
336 * bt_resolve_field_paths() can fail: anything else
337 * would be because a precondition is not satisfied.
338 */
339 ret = BT_FUNC_STATUS_MEMORY_ERROR;
340 goto end;
341 }
342
343 bt_field_class_make_part_of_trace_class(field_class);
344 bt_object_put_ref(stream_class->packet_context_fc);
345 stream_class->packet_context_fc = field_class;
346 bt_object_get_ref_no_null_check(stream_class->packet_context_fc);
347 bt_field_class_freeze(field_class);
348 BT_LIB_LOGD("Set stream class's packet context field class: %!+S",
349 stream_class);
350
351 end:
352 return ret;
353 }
354
355 const struct bt_field_class *
356 bt_stream_class_borrow_event_common_context_field_class_const(
357 const struct bt_stream_class *stream_class)
358 {
359 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
360 return stream_class->event_common_context_fc;
361 }
362
363 struct bt_field_class *
364 bt_stream_class_borrow_event_common_context_field_class(
365 struct bt_stream_class *stream_class)
366 {
367 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
368 return stream_class->event_common_context_fc;
369 }
370
371 enum bt_stream_class_set_field_class_status
372 bt_stream_class_set_event_common_context_field_class(
373 struct bt_stream_class *stream_class,
374 struct bt_field_class *field_class)
375 {
376 int ret;
377 struct bt_resolve_field_path_context resolve_ctx = {
378 .packet_context = NULL,
379 .event_common_context = field_class,
380 .event_specific_context = NULL,
381 .event_payload = NULL,
382 };
383
384 BT_ASSERT_PRE_NO_ERROR();
385 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
386 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
387 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
388 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
389 BT_FIELD_CLASS_TYPE_STRUCTURE,
390 "Event common context field class is not a structure field class: %!+F",
391 field_class);
392 resolve_ctx.packet_context = stream_class->packet_context_fc;
393 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
394 if (ret) {
395 /*
396 * This is the only reason for which
397 * bt_resolve_field_paths() can fail: anything else
398 * would be because a precondition is not satisfied.
399 */
400 ret = BT_FUNC_STATUS_MEMORY_ERROR;
401 goto end;
402 }
403
404 bt_field_class_make_part_of_trace_class(field_class);
405 bt_object_put_ref(stream_class->event_common_context_fc);
406 stream_class->event_common_context_fc = field_class;
407 bt_object_get_ref_no_null_check(stream_class->event_common_context_fc);
408 bt_field_class_freeze(field_class);
409 BT_LIB_LOGD("Set stream class's event common context field class: %!+S",
410 stream_class);
411
412 end:
413 return ret;
414 }
415
416 BT_HIDDEN
417 void _bt_stream_class_freeze(const struct bt_stream_class *stream_class)
418 {
419 /* The field classes and default clock class are already frozen */
420 BT_ASSERT(stream_class);
421 BT_LIB_LOGD("Freezing stream class's user attributes: %!+v",
422 stream_class->user_attributes);
423 bt_value_freeze(stream_class->user_attributes);
424 BT_LIB_LOGD("Freezing stream class: %!+S", stream_class);
425 ((struct bt_stream_class *) stream_class)->frozen = true;
426 }
427
428 enum bt_stream_class_set_default_clock_class_status
429 bt_stream_class_set_default_clock_class(
430 struct bt_stream_class *stream_class,
431 struct bt_clock_class *clock_class)
432 {
433 BT_ASSERT_PRE_NO_ERROR();
434 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
435 BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
436 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
437 bt_object_put_ref(stream_class->default_clock_class);
438 stream_class->default_clock_class = clock_class;
439 bt_object_get_ref_no_null_check(stream_class->default_clock_class);
440 bt_clock_class_freeze(clock_class);
441 BT_LIB_LOGD("Set stream class's default clock class: %!+S",
442 stream_class);
443 return BT_FUNC_STATUS_OK;
444 }
445
446 struct bt_clock_class *bt_stream_class_borrow_default_clock_class(
447 struct bt_stream_class *stream_class)
448 {
449 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
450 return stream_class->default_clock_class;
451 }
452
453 const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const(
454 const struct bt_stream_class *stream_class)
455 {
456 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
457 return stream_class->default_clock_class;
458 }
459
460 bt_bool bt_stream_class_assigns_automatic_event_class_id(
461 const struct bt_stream_class *stream_class)
462 {
463 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
464 return (bt_bool) stream_class->assigns_automatic_event_class_id;
465 }
466
467 void bt_stream_class_set_assigns_automatic_event_class_id(
468 struct bt_stream_class *stream_class,
469 bt_bool value)
470 {
471 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
472 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
473 stream_class->assigns_automatic_event_class_id = (bool) value;
474 BT_LIB_LOGD("Set stream class's automatic event class ID "
475 "assignment property: %!+S", stream_class);
476 }
477
478 bt_bool bt_stream_class_assigns_automatic_stream_id(
479 const struct bt_stream_class *stream_class)
480 {
481 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
482 return (bt_bool) stream_class->assigns_automatic_stream_id;
483 }
484
485 void bt_stream_class_set_supports_discarded_events(
486 struct bt_stream_class *stream_class,
487 bt_bool supports_discarded_events,
488 bt_bool with_default_clock_snapshots)
489 {
490 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
491 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
492 BT_ASSERT_PRE(supports_discarded_events ||
493 !with_default_clock_snapshots,
494 "Discarded events cannot have default clock snapshots when "
495 "not supported: %!+S", stream_class);
496 BT_ASSERT_PRE(!with_default_clock_snapshots ||
497 stream_class->default_clock_class,
498 "Stream class has no default clock class: %!+S", stream_class);
499 stream_class->supports_discarded_events =
500 (bool) supports_discarded_events;
501 stream_class->discarded_events_have_default_clock_snapshots =
502 (bool) with_default_clock_snapshots;
503 BT_LIB_LOGD("Set stream class's discarded events support property: "
504 "%!+S", stream_class);
505 }
506
507 bt_bool bt_stream_class_supports_discarded_events(
508 const struct bt_stream_class *stream_class)
509 {
510 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
511 return (bt_bool) stream_class->supports_discarded_events;
512 }
513
514 bt_bool bt_stream_class_discarded_events_have_default_clock_snapshots(
515 const struct bt_stream_class *stream_class)
516 {
517 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
518 return (bt_bool) stream_class->discarded_events_have_default_clock_snapshots;
519 }
520
521 void bt_stream_class_set_supports_discarded_packets(
522 struct bt_stream_class *stream_class,
523 bt_bool supports_discarded_packets,
524 bt_bool with_default_clock_snapshots)
525 {
526 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
527 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
528 BT_ASSERT_PRE(!supports_discarded_packets ||
529 stream_class->supports_packets,
530 "Stream class does not support packets: %!+S",
531 stream_class);
532 BT_ASSERT_PRE(supports_discarded_packets ||
533 !with_default_clock_snapshots,
534 "Discarded packets cannot have default clock snapshots when "
535 "not supported: %!+S", stream_class);
536 BT_ASSERT_PRE(!with_default_clock_snapshots ||
537 stream_class->default_clock_class,
538 "Stream class has no default clock class: %!+S", stream_class);
539 stream_class->supports_discarded_packets =
540 (bool) supports_discarded_packets;
541 stream_class->discarded_packets_have_default_clock_snapshots =
542 (bool) with_default_clock_snapshots;
543 BT_LIB_LOGD("Set stream class's discarded packets support property: "
544 "%!+S", stream_class);
545 }
546
547 bt_bool bt_stream_class_supports_discarded_packets(
548 const struct bt_stream_class *stream_class)
549 {
550 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
551 return (bt_bool) stream_class->supports_discarded_packets;
552 }
553
554 bt_bool bt_stream_class_discarded_packets_have_default_clock_snapshots(
555 const struct bt_stream_class *stream_class)
556 {
557 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
558 return (bt_bool) stream_class->discarded_packets_have_default_clock_snapshots;
559 }
560
561 void bt_stream_class_set_supports_packets(
562 struct bt_stream_class *stream_class,
563 bt_bool supports_packets,
564 bt_bool with_beginning_default_clock_snapshot,
565 bt_bool with_end_default_clock_snapshot)
566 {
567 bt_bool with_default_clock_snapshot =
568 with_beginning_default_clock_snapshot ||
569 with_end_default_clock_snapshot;
570 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
571 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
572 BT_ASSERT_PRE(supports_packets ||
573 !with_default_clock_snapshot,
574 "Packets cannot have default clock snapshots when "
575 "not supported: %!+S", stream_class);
576 BT_ASSERT_PRE(!with_default_clock_snapshot ||
577 stream_class->default_clock_class,
578 "Stream class has no default clock class: %!+S", stream_class);
579 BT_ASSERT_PRE(supports_packets || !stream_class->packet_context_fc,
580 "Stream class already has a packet context field class: %!+S",
581 stream_class);
582 BT_ASSERT_PRE(supports_packets ||
583 !stream_class->supports_discarded_packets,
584 "Stream class already supports discarded packets: %!+S",
585 stream_class);
586 stream_class->supports_packets = (bool) supports_packets;
587 stream_class->packets_have_beginning_default_clock_snapshot =
588 (bool) with_beginning_default_clock_snapshot;
589 stream_class->packets_have_end_default_clock_snapshot =
590 (bool) with_end_default_clock_snapshot;
591 BT_LIB_LOGD("Set stream class's packets support property: %!+S",
592 stream_class);
593 }
594
595 bt_bool bt_stream_class_supports_packets(
596 const struct bt_stream_class *stream_class)
597 {
598 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
599 return (bt_bool) stream_class->supports_packets;
600 }
601
602 bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot(
603 const struct bt_stream_class *stream_class)
604 {
605 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
606 return (bt_bool) stream_class->packets_have_beginning_default_clock_snapshot;
607 }
608
609 bt_bool bt_stream_class_packets_have_end_default_clock_snapshot(
610 const struct bt_stream_class *stream_class)
611 {
612 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
613 return (bt_bool) stream_class->packets_have_end_default_clock_snapshot;
614 }
615
616 void bt_stream_class_set_assigns_automatic_stream_id(
617 struct bt_stream_class *stream_class,
618 bt_bool value)
619 {
620 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
621 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
622 stream_class->assigns_automatic_stream_id = (bool) value;
623 BT_LIB_LOGD("Set stream class's automatic stream ID "
624 "assignment property: %!+S", stream_class);
625 }
626
627 const struct bt_value *bt_stream_class_borrow_user_attributes_const(
628 const struct bt_stream_class *stream_class)
629 {
630 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
631 return stream_class->user_attributes;
632 }
633
634 struct bt_value *bt_stream_class_borrow_user_attributes(
635 struct bt_stream_class *stream_class)
636 {
637 return (void *) bt_stream_class_borrow_user_attributes_const(
638 (void *) stream_class);
639 }
640
641 void bt_stream_class_set_user_attributes(
642 struct bt_stream_class *stream_class,
643 const struct bt_value *user_attributes)
644 {
645 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
646 BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes");
647 BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP,
648 "User attributes object is not a map value object.");
649 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
650 bt_object_put_ref_no_null_check(stream_class->user_attributes);
651 stream_class->user_attributes = (void *) user_attributes;
652 bt_object_get_ref_no_null_check(stream_class->user_attributes);
653 }
654
655 void bt_stream_class_get_ref(const struct bt_stream_class *stream_class)
656 {
657 bt_object_get_ref(stream_class);
658 }
659
660 void bt_stream_class_put_ref(const struct bt_stream_class *stream_class)
661 {
662 bt_object_put_ref(stream_class);
663 }
This page took 0.046981 seconds and 4 git commands to generate.