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