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