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