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