Stream class API: use status
[babeltrace.git] / 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
d2f71f12
PP
24#define BT_LOG_TAG "STREAM-CLASS"
25#include <babeltrace/lib-logging-internal.h>
26
8deee039 27#include <babeltrace/assert-pre-internal.h>
108b91d0
PP
28#include <babeltrace/trace-ir/clock-class-internal.h>
29#include <babeltrace/trace-ir/event-class-internal.h>
0f15f666
PP
30#include <babeltrace/trace-ir/field-class-internal.h>
31#include <babeltrace/trace-ir/field-internal.h>
108b91d0 32#include <babeltrace/trace-ir/stream-class-internal.h>
78cf9df6 33#include <babeltrace/trace-ir/trace-const.h>
9e550e5f 34#include <babeltrace/trace-ir/trace-internal.h>
108b91d0
PP
35#include <babeltrace/trace-ir/utils-internal.h>
36#include <babeltrace/trace-ir/field-wrapper-internal.h>
37#include <babeltrace/trace-ir/resolve-field-path-internal.h>
3d9990ac
PP
38#include <babeltrace/compiler-internal.h>
39#include <babeltrace/align-internal.h>
40#include <babeltrace/endian-internal.h>
8b45963b 41#include <babeltrace/assert-internal.h>
7b33a0e0 42#include <babeltrace/property-internal.h>
dc3fffef 43#include <inttypes.h>
544d0515 44#include <stdint.h>
e011d2c1 45#include <stdbool.h>
11b0cdc8 46
7b33a0e0
PP
47#define BT_ASSERT_PRE_STREAM_CLASS_HOT(_sc) \
48 BT_ASSERT_PRE_HOT((_sc), "Stream class", ": %!+S", (_sc))
142c5610 49
18acc6f8 50static
7b33a0e0 51void destroy_stream_class(struct bt_object *obj)
3ea33115 52{
18acc6f8
PP
53 struct bt_stream_class *stream_class = (void *) obj;
54
7b33a0e0
PP
55 BT_LIB_LOGD("Destroying stream class: %!+S", stream_class);
56 BT_LOGD_STR("Putting default clock class.");
1248f5ea 57 BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class);
3ea33115 58
8deee039
PP
59 if (stream_class->event_classes) {
60 BT_LOGD_STR("Destroying event classes.");
61 g_ptr_array_free(stream_class->event_classes, TRUE);
1248f5ea 62 stream_class->event_classes = NULL;
d2f71f12
PP
63 }
64
7b33a0e0
PP
65 if (stream_class->name.str) {
66 g_string_free(stream_class->name.str, TRUE);
1248f5ea
PP
67 stream_class->name.str = NULL;
68 stream_class->name.value = NULL;
3ea33115
JG
69 }
70
66fd07a5 71 BT_LOGD_STR("Putting event header field class.");
1248f5ea 72 BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_header_fc);
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
PP
77 bt_object_pool_finalize(&stream_class->event_header_field_pool);
78 bt_object_pool_finalize(&stream_class->packet_context_field_pool);
8deee039 79 g_free(stream_class);
3ea33115
JG
80}
81
a6918753
PP
82static
83void free_field_wrapper(struct bt_field_wrapper *field_wrapper,
84 struct bt_stream_class *stream_class)
85{
86 bt_field_wrapper_destroy((void *) field_wrapper);
87}
88
7b33a0e0
PP
89BT_ASSERT_PRE_FUNC
90static
10b7a2e4 91bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id)
7b33a0e0
PP
92{
93 uint64_t i;
94 bool is_unique = true;
95
10b7a2e4 96 for (i = 0; i < tc->stream_classes->len; i++) {
78cf9df6 97 const struct bt_stream_class *sc =
10b7a2e4 98 tc->stream_classes->pdata[i];
7b33a0e0
PP
99
100 if (sc->id == id) {
101 is_unique = false;
102 goto end;
103 }
104 }
105
106end:
107 return is_unique;
108}
109
110static
10b7a2e4
PP
111struct bt_stream_class *create_stream_class_with_id(
112 struct bt_trace_class *tc, uint64_t id)
2f100782 113{
8deee039
PP
114 struct bt_stream_class *stream_class = NULL;
115 int ret;
2f100782 116
10b7a2e4
PP
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);
8deee039 122 stream_class = g_new0(struct bt_stream_class, 1);
d2f71f12 123 if (!stream_class) {
8deee039
PP
124 BT_LOGE_STR("Failed to allocate one stream class.");
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) {
133 BT_LOGE_STR("Failed to allocate a GString.");
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) {
144 BT_LOGE_STR("Failed to allocate a GPtrArray.");
8deee039 145 goto error;
2f100782
JG
146 }
147
a6918753
PP
148 ret = bt_object_pool_initialize(&stream_class->event_header_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) {
153 BT_LOGE("Failed to initialize event header field pool: ret=%d",
154 ret);
155 goto error;
156 }
157
158 ret = bt_object_pool_initialize(&stream_class->packet_context_field_pool,
159 (bt_object_pool_new_object_func) bt_field_wrapper_new,
160 (bt_object_pool_destroy_object_func) free_field_wrapper,
161 stream_class);
162 if (ret) {
163 BT_LOGE("Failed to initialize packet context field pool: ret=%d",
164 ret);
165 goto error;
166 }
167
10b7a2e4
PP
168 bt_object_set_parent(&stream_class->base, &tc->base);
169 g_ptr_array_add(tc->stream_classes, stream_class);
170 bt_trace_class_freeze(tc);
7b33a0e0 171 BT_LIB_LOGD("Created stream class object: %!+S", stream_class);
a6918753
PP
172 goto end;
173
174error:
8138bfe1 175 BT_OBJECT_PUT_REF_AND_RESET(stream_class);
a6918753
PP
176
177end:
7b33a0e0 178 return stream_class;
a6918753
PP
179}
180
10b7a2e4 181struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc)
a6918753 182{
10b7a2e4
PP
183 BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
184 BT_ASSERT_PRE(tc->assigns_automatic_stream_class_id,
185 "Trace class does not automatically assigns stream class IDs: "
186 "%![sc-]+T", tc);
187 return create_stream_class_with_id(tc,
188 (uint64_t) tc->stream_classes->len);
7b33a0e0 189}
a6918753 190
78cf9df6 191struct bt_stream_class *bt_stream_class_create_with_id(
10b7a2e4 192 struct bt_trace_class *tc, uint64_t id)
7b33a0e0 193{
10b7a2e4
PP
194 BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
195 BT_ASSERT_PRE(!tc->assigns_automatic_stream_class_id,
196 "Trace class automatically assigns stream class IDs: "
197 "%![sc-]+T", tc);
198 return create_stream_class_with_id(tc, id);
a6918753
PP
199}
200
10b7a2e4 201struct bt_trace_class *bt_stream_class_borrow_trace_class(
78cf9df6 202 struct bt_stream_class *stream_class)
11b0cdc8 203{
7b33a0e0 204 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
10b7a2e4 205 return bt_stream_class_borrow_trace_class_inline(stream_class);
11b0cdc8
JG
206}
207
10b7a2e4 208const struct bt_trace_class *bt_stream_class_borrow_trace_class_const(
78cf9df6 209 const struct bt_stream_class *stream_class)
9e550e5f 210{
10b7a2e4 211 return bt_stream_class_borrow_trace_class((void *) stream_class);
9e550e5f
PP
212}
213
78cf9df6 214const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class)
2f100782 215{
18acc6f8 216 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
7b33a0e0 217 return stream_class->name.value;
2f100782
JG
218}
219
36a28778 220enum bt_stream_class_status bt_stream_class_set_name(
78cf9df6 221 struct bt_stream_class *stream_class,
8deee039 222 const char *name)
5ca83563 223{
7b33a0e0
PP
224 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
225 BT_ASSERT_PRE_NON_NULL(name, "Name");
226 BT_ASSERT_PRE_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_LOGV("Set stream class's name: %!+S", stream_class);
36a28778 230 return BT_STREAM_CLASS_STATUS_OK;
5ca83563
JG
231}
232
78cf9df6 233uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class)
2f100782 234{
18acc6f8 235 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
7b33a0e0 236 return stream_class->id;
2f100782
JG
237}
238
7b33a0e0 239uint64_t bt_stream_class_get_event_class_count(
78cf9df6 240 const struct bt_stream_class *stream_class)
29664b2a 241{
7b33a0e0
PP
242 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
243 return (uint64_t) stream_class->event_classes->len;
29664b2a
PP
244}
245
7b33a0e0
PP
246struct bt_event_class *bt_stream_class_borrow_event_class_by_index(
247 struct bt_stream_class *stream_class, uint64_t index)
0d23acbe 248{
7b33a0e0
PP
249 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
250 BT_ASSERT_PRE_VALID_INDEX(index, stream_class->event_classes->len);
251 return g_ptr_array_index(stream_class->event_classes, index);
0d23acbe
PP
252}
253
78cf9df6
PP
254const struct bt_event_class *
255bt_stream_class_borrow_event_class_by_index_const(
256 const struct bt_stream_class *stream_class, uint64_t index)
9e550e5f 257{
78cf9df6 258 return bt_stream_class_borrow_event_class_by_index(
9e550e5f
PP
259 (void *) stream_class, index);
260}
261
7b33a0e0 262struct bt_event_class *bt_stream_class_borrow_event_class_by_id(
9e550e5f 263 struct bt_stream_class *stream_class, uint64_t id)
11b0cdc8 264{
7b33a0e0
PP
265 struct bt_event_class *event_class = NULL;
266 uint64_t i;
0b9ce69f 267
10b7a2e4 268 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
11b0cdc8 269
9e550e5f 270 for (i = 0; i < stream_class->event_classes->len; i++) {
7b33a0e0 271 struct bt_event_class *event_class_candidate =
9e550e5f 272 g_ptr_array_index(stream_class->event_classes, i);
e6a8e8e4 273
7b33a0e0
PP
274 if (event_class_candidate->id == id) {
275 event_class = event_class_candidate;
09840de5
PP
276 goto end;
277 }
69dc4535
JG
278 }
279
69dc4535 280end:
7b33a0e0 281 return event_class;
0863f950
PP
282}
283
78cf9df6
PP
284const struct bt_event_class *
285bt_stream_class_borrow_event_class_by_id_const(
286 const struct bt_stream_class *stream_class, uint64_t id)
9e550e5f 287{
78cf9df6 288 return bt_stream_class_borrow_event_class_by_id(
9e550e5f
PP
289 (void *) stream_class, id);
290}
291
78cf9df6
PP
292const struct bt_field_class *
293bt_stream_class_borrow_packet_context_field_class_const(
294 const struct bt_stream_class *stream_class)
12c8a1a3 295{
18acc6f8 296 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
939190b3 297 return stream_class->packet_context_fc;
12c8a1a3
JG
298}
299
36a28778 300enum bt_stream_class_status bt_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 = {
306 .packet_header = NULL,
939190b3 307 .packet_context = field_class,
7b33a0e0
PP
308 .event_header = NULL,
309 .event_common_context = NULL,
310 .event_specific_context = NULL,
311 .event_payload = NULL,
312 };
18acc6f8 313
7b33a0e0 314 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
939190b3 315 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
7b33a0e0 316 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
af0c18e3
PP
317 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
318 BT_FIELD_CLASS_TYPE_STRUCTURE,
66fd07a5 319 "Packet context field class is not a structure field class: %!+F",
939190b3 320 field_class);
7b33a0e0 321 resolve_ctx.packet_header =
10b7a2e4 322 bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc;
939190b3 323 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
7b33a0e0 324 if (ret) {
36a28778
PP
325 /*
326 * This is the only reason for which
327 * bt_resolve_field_paths() can fail: anything else
328 * would be because a precondition is not satisfied.
329 */
330 ret = BT_STREAM_CLASS_STATUS_NOMEM;
18acc6f8
PP
331 goto end;
332 }
333
10b7a2e4 334 bt_field_class_make_part_of_trace_class(field_class);
8138bfe1 335 bt_object_put_ref(stream_class->packet_context_fc);
4b70020d
PP
336 stream_class->packet_context_fc = field_class;
337 bt_object_get_no_null_check(stream_class->packet_context_fc);
939190b3 338 bt_field_class_freeze(field_class);
66fd07a5 339 BT_LIB_LOGV("Set stream class's packet context field class: %!+S",
7b33a0e0 340 stream_class);
18acc6f8
PP
341
342end:
343 return ret;
12c8a1a3
JG
344}
345
78cf9df6
PP
346const struct bt_field_class *bt_stream_class_borrow_event_header_field_class_const(
347 const struct bt_stream_class *stream_class)
662e778c 348{
18acc6f8 349 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
939190b3 350 return stream_class->event_header_fc;
662e778c
JG
351}
352
36a28778 353enum bt_stream_class_status bt_stream_class_set_event_header_field_class(
78cf9df6
PP
354 struct bt_stream_class *stream_class,
355 struct bt_field_class *field_class)
662e778c 356{
7b33a0e0
PP
357 int ret;
358 struct bt_resolve_field_path_context resolve_ctx = {
359 .packet_header = NULL,
360 .packet_context = NULL,
939190b3 361 .event_header = field_class,
7b33a0e0
PP
362 .event_common_context = NULL,
363 .event_specific_context = NULL,
364 .event_payload = NULL,
365 };
18acc6f8 366
7b33a0e0 367 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
939190b3 368 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
7b33a0e0 369 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
af0c18e3
PP
370 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
371 BT_FIELD_CLASS_TYPE_STRUCTURE,
66fd07a5 372 "Event header field class is not a structure field class: %!+F",
939190b3 373 field_class);
7b33a0e0 374 resolve_ctx.packet_header =
10b7a2e4 375 bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc;
939190b3
PP
376 resolve_ctx.packet_context = stream_class->packet_context_fc;
377 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
7b33a0e0 378 if (ret) {
36a28778
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 */
384 ret = BT_STREAM_CLASS_STATUS_NOMEM;
18acc6f8
PP
385 goto end;
386 }
387
10b7a2e4 388 bt_field_class_make_part_of_trace_class(field_class);
8138bfe1 389 bt_object_put_ref(stream_class->event_header_fc);
4b70020d
PP
390 stream_class->event_header_fc = field_class;
391 bt_object_get_no_null_check(stream_class->event_header_fc);
939190b3 392 bt_field_class_freeze(field_class);
66fd07a5 393 BT_LIB_LOGV("Set stream class's event header field class: %!+S",
7b33a0e0 394 stream_class);
18acc6f8 395
18acc6f8
PP
396end:
397 return ret;
662e778c
JG
398}
399
78cf9df6
PP
400const struct bt_field_class *
401bt_stream_class_borrow_event_common_context_field_class_const(
402 const struct bt_stream_class *stream_class)
af181248 403{
18acc6f8 404 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
939190b3 405 return stream_class->event_common_context_fc;
af181248
JG
406}
407
36a28778
PP
408enum bt_stream_class_status
409bt_stream_class_set_event_common_context_field_class(
78cf9df6
PP
410 struct bt_stream_class *stream_class,
411 struct bt_field_class *field_class)
af181248 412{
7b33a0e0
PP
413 int ret;
414 struct bt_resolve_field_path_context resolve_ctx = {
415 .packet_header = NULL,
416 .packet_context = NULL,
417 .event_header = NULL,
939190b3 418 .event_common_context = field_class,
7b33a0e0
PP
419 .event_specific_context = NULL,
420 .event_payload = NULL,
421 };
18acc6f8 422
7b33a0e0 423 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
939190b3 424 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
7b33a0e0 425 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
af0c18e3
PP
426 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
427 BT_FIELD_CLASS_TYPE_STRUCTURE,
66fd07a5 428 "Event common context field class is not a structure field class: %!+F",
939190b3 429 field_class);
7b33a0e0 430 resolve_ctx.packet_header =
10b7a2e4 431 bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc;
939190b3
PP
432 resolve_ctx.packet_context = stream_class->packet_context_fc;
433 resolve_ctx.event_header = stream_class->event_header_fc;
434 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
7b33a0e0 435 if (ret) {
36a28778
PP
436 /*
437 * This is the only reason for which
438 * bt_resolve_field_paths() can fail: anything else
439 * would be because a precondition is not satisfied.
440 */
441 ret = BT_STREAM_CLASS_STATUS_NOMEM;
18acc6f8
PP
442 goto end;
443 }
444
10b7a2e4 445 bt_field_class_make_part_of_trace_class(field_class);
8138bfe1 446 bt_object_put_ref(stream_class->event_common_context_fc);
4b70020d
PP
447 stream_class->event_common_context_fc = field_class;
448 bt_object_get_no_null_check(stream_class->event_common_context_fc);
939190b3 449 bt_field_class_freeze(field_class);
66fd07a5 450 BT_LIB_LOGV("Set stream class's event common context field class: %!+S",
7b33a0e0 451 stream_class);
18acc6f8 452
18acc6f8
PP
453end:
454 return ret;
11b0cdc8
JG
455}
456
7b33a0e0 457BT_HIDDEN
78cf9df6 458void _bt_stream_class_freeze(const struct bt_stream_class *stream_class)
8bf65fbd 459{
939190b3 460 /* The field classes and default clock class are already frozen */
7b33a0e0
PP
461 BT_ASSERT(stream_class);
462 BT_LIB_LOGD("Freezing stream class: %!+S", stream_class);
78cf9df6 463 ((struct bt_stream_class *) stream_class)->frozen = true;
8bf65fbd
JG
464}
465
36a28778 466enum bt_stream_class_status bt_stream_class_set_default_clock_class(
78cf9df6 467 struct bt_stream_class *stream_class,
7b33a0e0 468 struct bt_clock_class *clock_class)
8bf65fbd 469{
7b33a0e0
PP
470 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
471 BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
472 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
8138bfe1 473 bt_object_put_ref(stream_class->default_clock_class);
4b70020d
PP
474 stream_class->default_clock_class = clock_class;
475 bt_object_get_no_null_check(stream_class->default_clock_class);
7b33a0e0
PP
476 bt_clock_class_freeze(clock_class);
477 BT_LIB_LOGV("Set stream class's default clock class: %!+S",
478 stream_class);
36a28778 479 return BT_STREAM_CLASS_STATUS_OK;
8bf65fbd
JG
480}
481
7b33a0e0
PP
482struct bt_clock_class *bt_stream_class_borrow_default_clock_class(
483 struct bt_stream_class *stream_class)
8bf65fbd 484{
7b33a0e0
PP
485 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
486 return stream_class->default_clock_class;
487}
8bf65fbd 488
78cf9df6
PP
489const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const(
490 const struct bt_stream_class *stream_class)
491{
492 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
493 return stream_class->default_clock_class;
494}
495
7b33a0e0 496bt_bool bt_stream_class_assigns_automatic_event_class_id(
78cf9df6 497 const struct bt_stream_class *stream_class)
7b33a0e0
PP
498{
499 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
500 return (bt_bool) stream_class->assigns_automatic_event_class_id;
8bf65fbd
JG
501}
502
78cf9df6
PP
503void bt_stream_class_set_assigns_automatic_event_class_id(
504 struct bt_stream_class *stream_class,
9e550e5f 505 bt_bool value)
8bf65fbd 506{
7b33a0e0
PP
507 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
508 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
509 stream_class->assigns_automatic_event_class_id = (bool) value;
510 BT_LIB_LOGV("Set stream class's automatic event class ID "
511 "assignment property: %!+S", stream_class);
7b33a0e0 512}
8bf65fbd 513
7b33a0e0 514bt_bool bt_stream_class_assigns_automatic_stream_id(
78cf9df6 515 const struct bt_stream_class *stream_class)
7b33a0e0
PP
516{
517 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
518 return (bt_bool) stream_class->assigns_automatic_stream_id;
519}
8bf65fbd 520
78cf9df6
PP
521void bt_stream_class_set_assigns_automatic_stream_id(
522 struct bt_stream_class *stream_class,
9e550e5f 523 bt_bool value)
7b33a0e0
PP
524{
525 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
526 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
527 stream_class->assigns_automatic_stream_id = (bool) value;
528 BT_LIB_LOGV("Set stream class's automatic stream ID "
529 "assignment property: %!+S", stream_class);
7b33a0e0 530}
8deee039 531
7b33a0e0 532bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot(
78cf9df6 533 const struct bt_stream_class *stream_class)
7b33a0e0
PP
534{
535 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
536 return (bt_bool) stream_class->packets_have_discarded_event_counter_snapshot;
8bf65fbd
JG
537}
538
78cf9df6
PP
539void bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
540 struct bt_stream_class *stream_class,
9e550e5f 541 bt_bool value)
11b0cdc8 542{
7b33a0e0
PP
543 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
544 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
545 stream_class->packets_have_discarded_event_counter_snapshot =
546 (bool) value;
547 BT_LIB_LOGV("Set stream class's "
548 "\"packets have discarded event counter snapshot\" property: "
549 "%!+S", stream_class);
7b33a0e0 550}
11b0cdc8 551
7b33a0e0 552bt_bool bt_stream_class_packets_have_packet_counter_snapshot(
78cf9df6 553 const struct bt_stream_class *stream_class)
7b33a0e0
PP
554{
555 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
556 return (bt_bool) stream_class->packets_have_packet_counter_snapshot;
11b0cdc8
JG
557}
558
78cf9df6
PP
559void bt_stream_class_set_packets_have_packet_counter_snapshot(
560 struct bt_stream_class *stream_class,
9e550e5f 561 bt_bool value)
8c4a29ba 562{
7b33a0e0
PP
563 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
564 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
565 stream_class->packets_have_packet_counter_snapshot =
566 (bool) value;
567 BT_LIB_LOGV("Set stream class's "
568 "\"packets have packet counter snapshot\" property: "
569 "%!+S", stream_class);
7b33a0e0 570}
8c4a29ba 571
ecbb78c0 572bt_bool bt_stream_class_packets_have_default_beginning_clock_snapshot(
78cf9df6 573 const struct bt_stream_class *stream_class)
7b33a0e0
PP
574{
575 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
ecbb78c0 576 return (bt_bool) stream_class->packets_have_default_beginning_cs;
7b33a0e0 577}
8c4a29ba 578
ecbb78c0 579void bt_stream_class_set_packets_have_default_beginning_clock_snapshot(
78cf9df6 580 struct bt_stream_class *stream_class,
9e550e5f 581 bt_bool value)
7b33a0e0
PP
582{
583 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
584 BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class);
585 BT_ASSERT_PRE(!value || stream_class->default_clock_class,
586 "Stream class does not have a default clock class: %!+S",
587 stream_class);
ecbb78c0 588 stream_class->packets_have_default_beginning_cs = (bool) value;
7b33a0e0 589 BT_LIB_LOGV("Set stream class's "
ecbb78c0 590 "\"packets have default beginning clock snapshot\" property: "
7b33a0e0 591 "%!+S", stream_class);
7b33a0e0 592}
8c4a29ba 593
ecbb78c0 594bt_bool bt_stream_class_packets_have_default_end_clock_snapshot(
78cf9df6 595 const struct bt_stream_class *stream_class)
7b33a0e0
PP
596{
597 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
ecbb78c0 598 return (bt_bool) stream_class->packets_have_default_end_cs;
7b33a0e0 599}
8c4a29ba 600
ecbb78c0 601void bt_stream_class_set_packets_have_default_end_clock_snapshot(
78cf9df6 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 BT_ASSERT_PRE(!value || stream_class->default_clock_class,
608 "Stream class does not have a default clock class: %!+S",
609 stream_class);
ecbb78c0 610 stream_class->packets_have_default_end_cs = (bool) value;
7b33a0e0 611 BT_LIB_LOGV("Set stream class's "
ecbb78c0 612 "\"packets have default end clock snapshot\" property: "
7b33a0e0 613 "%!+S", stream_class);
7b33a0e0 614}
8c4a29ba 615
7b33a0e0 616bt_bool bt_stream_class_default_clock_is_always_known(
78cf9df6 617 const struct bt_stream_class *stream_class)
7b33a0e0 618{
a13b98e1 619 /* BT_CLOCK_SNAPSHOT_STATE_UNKNOWN is not supported as of 2.0 */
7b33a0e0 620 return BT_TRUE;
8c4a29ba 621}
8c6884d9
PP
622
623void bt_stream_class_get_ref(const struct bt_stream_class *stream_class)
624{
625 bt_object_get_ref(stream_class);
626}
627
628void bt_stream_class_put_ref(const struct bt_stream_class *stream_class)
629{
630 bt_object_put_ref(stream_class);
631}
This page took 0.082445 seconds and 4 git commands to generate.