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/*
e2f7325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de9dd397 3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
11b0cdc8 4 *
11b0cdc8
JG
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
350ad6c1 24#define BT_LOG_TAG "LIB/STREAM-CLASS"
c2d9d9cf 25#include "lib/logging.h"
d2f71f12 26
578e048b 27#include "lib/assert-pre.h"
3fadfbc0 28#include <babeltrace2/trace-ir/trace-const.h>
578e048b
MJ
29#include "compat/compiler.h"
30#include "common/align.h"
31#include "compat/endian.h"
32#include "common/assert.h"
33#include "lib/property.h"
dc3fffef 34#include <inttypes.h>
544d0515 35#include <stdint.h>
e011d2c1 36#include <stdbool.h>
11b0cdc8 37
578e048b
MJ
38#include "clock-class.h"
39#include "event-class.h"
40#include "field-class.h"
41#include "field.h"
42#include "field-wrapper.h"
43#include "resolve-field-path.h"
44#include "stream-class.h"
45#include "trace.h"
46#include "utils.h"
c6962c96 47#include "lib/value.h"
d24d5663 48#include "lib/func-status.h"
578e048b 49
bdb288b3
PP
50#define BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(_sc) \
51 BT_ASSERT_PRE_DEV_HOT((_sc), "Stream class", ": %!+S", (_sc))
142c5610 52
cb6f1f7d 53static
44c440bc 54void destroy_stream_class(struct bt_object *obj)
3ea33115 55{
cb6f1f7d
PP
56 struct bt_stream_class *stream_class = (void *) obj;
57
44c440bc
PP
58 BT_LIB_LOGD("Destroying stream class: %!+S", stream_class);
59 BT_LOGD_STR("Putting default clock class.");
c6962c96 60 BT_OBJECT_PUT_REF_AND_RESET(stream_class->user_attributes);
238b7404 61 BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class);
3ea33115 62
3dca2276
PP
63 if (stream_class->event_classes) {
64 BT_LOGD_STR("Destroying event classes.");
65 g_ptr_array_free(stream_class->event_classes, TRUE);
238b7404 66 stream_class->event_classes = NULL;
d2f71f12
PP
67 }
68
44c440bc
PP
69 if (stream_class->name.str) {
70 g_string_free(stream_class->name.str, TRUE);
238b7404
PP
71 stream_class->name.str = NULL;
72 stream_class->name.value = NULL;
3ea33115
JG
73 }
74
e6276565 75 BT_LOGD_STR("Putting packet context field class.");
238b7404 76 BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc);
e6276565 77 BT_LOGD_STR("Putting event common context field class.");
238b7404 78 BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_common_context_fc);
312c056a 79 bt_object_pool_finalize(&stream_class->packet_context_field_pool);
3dca2276 80 g_free(stream_class);
3ea33115
JG
81}
82
312c056a
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
44c440bc 90static
862ca4ed 91bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id)
44c440bc
PP
92{
93 uint64_t i;
94 bool is_unique = true;
95
862ca4ed 96 for (i = 0; i < tc->stream_classes->len; i++) {
40f4ba76 97 const struct bt_stream_class *sc =
862ca4ed 98 tc->stream_classes->pdata[i];
44c440bc
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
862ca4ed
PP
111struct bt_stream_class *create_stream_class_with_id(
112 struct bt_trace_class *tc, uint64_t id)
2f100782 113{
3dca2276
PP
114 struct bt_stream_class *stream_class = NULL;
115 int ret;
2f100782 116
862ca4ed
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);
3dca2276 122 stream_class = g_new0(struct bt_stream_class, 1);
d2f71f12 123 if (!stream_class) {
870631a2
PP
124 BT_LIB_LOGE_APPEND_CAUSE(
125 "Failed to allocate one stream class.");
3dca2276 126 goto error;
d2f71f12
PP
127 }
128
44c440bc
PP
129 bt_object_init_shared_with_parent(&stream_class->base,
130 destroy_stream_class);
c6962c96
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 }
44c440bc
PP
137
138 stream_class->name.str = g_string_new(NULL);
139 if (!stream_class->name.str) {
870631a2 140 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
c6962c96 141 goto error;
44c440bc
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) {
870631a2 150 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
3dca2276 151 goto error;
2f100782
JG
152 }
153
312c056a
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) {
870631a2
PP
159 BT_LIB_LOGE_APPEND_CAUSE(
160 "Failed to initialize packet context field pool: ret=%d",
312c056a
PP
161 ret);
162 goto error;
163 }
164
862ca4ed
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);
44c440bc 168 BT_LIB_LOGD("Created stream class object: %!+S", stream_class);
312c056a
PP
169 goto end;
170
171error:
65300d60 172 BT_OBJECT_PUT_REF_AND_RESET(stream_class);
312c056a
PP
173
174end:
44c440bc 175 return stream_class;
312c056a
PP
176}
177
862ca4ed 178struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc)
312c056a 179{
862ca4ed
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);
44c440bc 186}
312c056a 187
40f4ba76 188struct bt_stream_class *bt_stream_class_create_with_id(
862ca4ed 189 struct bt_trace_class *tc, uint64_t id)
44c440bc 190{
862ca4ed
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);
312c056a
PP
196}
197
862ca4ed 198struct bt_trace_class *bt_stream_class_borrow_trace_class(
40f4ba76 199 struct bt_stream_class *stream_class)
11b0cdc8 200{
bdb288b3 201 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
862ca4ed 202 return bt_stream_class_borrow_trace_class_inline(stream_class);
11b0cdc8
JG
203}
204
862ca4ed 205const struct bt_trace_class *bt_stream_class_borrow_trace_class_const(
40f4ba76 206 const struct bt_stream_class *stream_class)
e5be10ef 207{
862ca4ed 208 return bt_stream_class_borrow_trace_class((void *) stream_class);
e5be10ef
PP
209}
210
40f4ba76 211const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class)
2f100782 212{
bdb288b3 213 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
44c440bc 214 return stream_class->name.value;
2f100782
JG
215}
216
d24d5663 217enum bt_stream_class_set_name_status bt_stream_class_set_name(
40f4ba76 218 struct bt_stream_class *stream_class,
3dca2276 219 const char *name)
5ca83563 220{
44c440bc
PP
221 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
222 BT_ASSERT_PRE_NON_NULL(name, "Name");
bdb288b3 223 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
44c440bc
PP
224 g_string_assign(stream_class->name.str, name);
225 stream_class->name.value = stream_class->name.str->str;
3f7d4d90 226 BT_LIB_LOGD("Set stream class's name: %!+S", stream_class);
d24d5663 227 return BT_FUNC_STATUS_OK;
5ca83563
JG
228}
229
40f4ba76 230uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class)
2f100782 231{
bdb288b3 232 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
44c440bc 233 return stream_class->id;
2f100782
JG
234}
235
44c440bc 236uint64_t bt_stream_class_get_event_class_count(
40f4ba76 237 const struct bt_stream_class *stream_class)
29664b2a 238{
bdb288b3 239 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
44c440bc 240 return (uint64_t) stream_class->event_classes->len;
29664b2a
PP
241}
242
44c440bc
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{
bdb288b3
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);
44c440bc 248 return g_ptr_array_index(stream_class->event_classes, index);
0d23acbe
PP
249}
250
40f4ba76
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)
e5be10ef 254{
40f4ba76 255 return bt_stream_class_borrow_event_class_by_index(
e5be10ef
PP
256 (void *) stream_class, index);
257}
258
44c440bc 259struct bt_event_class *bt_stream_class_borrow_event_class_by_id(
e5be10ef 260 struct bt_stream_class *stream_class, uint64_t id)
11b0cdc8 261{
44c440bc
PP
262 struct bt_event_class *event_class = NULL;
263 uint64_t i;
0b9ce69f 264
bdb288b3 265 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
11b0cdc8 266
e5be10ef 267 for (i = 0; i < stream_class->event_classes->len; i++) {
44c440bc 268 struct bt_event_class *event_class_candidate =
e5be10ef 269 g_ptr_array_index(stream_class->event_classes, i);
e6a8e8e4 270
44c440bc
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:
44c440bc 278 return event_class;
0863f950
PP
279}
280
40f4ba76
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)
e5be10ef 284{
40f4ba76 285 return bt_stream_class_borrow_event_class_by_id(
e5be10ef
PP
286 (void *) stream_class, id);
287}
288
40f4ba76
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{
bdb288b3 293 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
5cd6d0e5 294 return stream_class->packet_context_fc;
12c8a1a3
JG
295}
296
740faaf4
PP
297struct bt_field_class *
298bt_stream_class_borrow_packet_context_field_class(
299 struct bt_stream_class *stream_class)
300{
bdb288b3 301 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
740faaf4
PP
302 return stream_class->packet_context_fc;
303}
304
d24d5663
PP
305enum bt_stream_class_set_field_class_status
306bt_stream_class_set_packet_context_field_class(
40f4ba76
PP
307 struct bt_stream_class *stream_class,
308 struct bt_field_class *field_class)
12c8a1a3 309{
44c440bc
PP
310 int ret;
311 struct bt_resolve_field_path_context resolve_ctx = {
5cd6d0e5 312 .packet_context = field_class,
44c440bc
PP
313 .event_common_context = NULL,
314 .event_specific_context = NULL,
315 .event_payload = NULL,
316 };
cb6f1f7d 317
44c440bc 318 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
26fc5aed
PP
319 BT_ASSERT_PRE(stream_class->supports_packets,
320 "Stream class does not support packets: %![sc-]+S",
321 stream_class);
5cd6d0e5 322 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
bdb288b3 323 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
864cad70
PP
324 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
325 BT_FIELD_CLASS_TYPE_STRUCTURE,
e6276565 326 "Packet context field class is not a structure field class: %!+F",
5cd6d0e5 327 field_class);
5cd6d0e5 328 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
44c440bc 329 if (ret) {
a6ae8edc
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 */
d24d5663 335 ret = BT_FUNC_STATUS_MEMORY_ERROR;
cb6f1f7d
PP
336 goto end;
337 }
338
862ca4ed 339 bt_field_class_make_part_of_trace_class(field_class);
65300d60 340 bt_object_put_ref(stream_class->packet_context_fc);
398454ed 341 stream_class->packet_context_fc = field_class;
6871026b 342 bt_object_get_ref_no_null_check(stream_class->packet_context_fc);
5cd6d0e5 343 bt_field_class_freeze(field_class);
3f7d4d90 344 BT_LIB_LOGD("Set stream class's packet context field class: %!+S",
44c440bc 345 stream_class);
cb6f1f7d
PP
346
347end:
348 return ret;
12c8a1a3
JG
349}
350
40f4ba76
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{
bdb288b3 355 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
5cd6d0e5 356 return stream_class->event_common_context_fc;
af181248
JG
357}
358
740faaf4
PP
359struct bt_field_class *
360bt_stream_class_borrow_event_common_context_field_class(
361 struct bt_stream_class *stream_class)
362{
bdb288b3 363 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
740faaf4
PP
364 return stream_class->event_common_context_fc;
365}
366
d24d5663 367enum bt_stream_class_set_field_class_status
a6ae8edc 368bt_stream_class_set_event_common_context_field_class(
40f4ba76
PP
369 struct bt_stream_class *stream_class,
370 struct bt_field_class *field_class)
af181248 371{
44c440bc
PP
372 int ret;
373 struct bt_resolve_field_path_context resolve_ctx = {
44c440bc 374 .packet_context = NULL,
5cd6d0e5 375 .event_common_context = field_class,
44c440bc
PP
376 .event_specific_context = NULL,
377 .event_payload = NULL,
378 };
cb6f1f7d 379
44c440bc 380 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
5cd6d0e5 381 BT_ASSERT_PRE_NON_NULL(field_class, "Field class");
bdb288b3 382 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
864cad70
PP
383 BT_ASSERT_PRE(bt_field_class_get_type(field_class) ==
384 BT_FIELD_CLASS_TYPE_STRUCTURE,
e6276565 385 "Event common context field class is not a structure field class: %!+F",
5cd6d0e5 386 field_class);
5cd6d0e5 387 resolve_ctx.packet_context = stream_class->packet_context_fc;
5cd6d0e5 388 ret = bt_resolve_field_paths(field_class, &resolve_ctx);
44c440bc 389 if (ret) {
a6ae8edc
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 */
d24d5663 395 ret = BT_FUNC_STATUS_MEMORY_ERROR;
cb6f1f7d
PP
396 goto end;
397 }
398
862ca4ed 399 bt_field_class_make_part_of_trace_class(field_class);
65300d60 400 bt_object_put_ref(stream_class->event_common_context_fc);
398454ed 401 stream_class->event_common_context_fc = field_class;
6871026b 402 bt_object_get_ref_no_null_check(stream_class->event_common_context_fc);
5cd6d0e5 403 bt_field_class_freeze(field_class);
3f7d4d90 404 BT_LIB_LOGD("Set stream class's event common context field class: %!+S",
44c440bc 405 stream_class);
cb6f1f7d 406
cb6f1f7d
PP
407end:
408 return ret;
11b0cdc8
JG
409}
410
44c440bc 411BT_HIDDEN
40f4ba76 412void _bt_stream_class_freeze(const struct bt_stream_class *stream_class)
8bf65fbd 413{
5cd6d0e5 414 /* The field classes and default clock class are already frozen */
44c440bc 415 BT_ASSERT(stream_class);
c6962c96
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);
44c440bc 419 BT_LIB_LOGD("Freezing stream class: %!+S", stream_class);
40f4ba76 420 ((struct bt_stream_class *) stream_class)->frozen = true;
8bf65fbd
JG
421}
422
d24d5663
PP
423enum bt_stream_class_set_default_clock_class_status
424bt_stream_class_set_default_clock_class(
40f4ba76 425 struct bt_stream_class *stream_class,
44c440bc 426 struct bt_clock_class *clock_class)
8bf65fbd 427{
44c440bc
PP
428 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
429 BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
bdb288b3 430 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
65300d60 431 bt_object_put_ref(stream_class->default_clock_class);
398454ed 432 stream_class->default_clock_class = clock_class;
6871026b 433 bt_object_get_ref_no_null_check(stream_class->default_clock_class);
44c440bc 434 bt_clock_class_freeze(clock_class);
3f7d4d90 435 BT_LIB_LOGD("Set stream class's default clock class: %!+S",
44c440bc 436 stream_class);
d24d5663 437 return BT_FUNC_STATUS_OK;
8bf65fbd
JG
438}
439
44c440bc
PP
440struct bt_clock_class *bt_stream_class_borrow_default_clock_class(
441 struct bt_stream_class *stream_class)
8bf65fbd 442{
bdb288b3 443 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
44c440bc
PP
444 return stream_class->default_clock_class;
445}
8bf65fbd 446
40f4ba76
PP
447const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const(
448 const struct bt_stream_class *stream_class)
449{
bdb288b3 450 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
40f4ba76
PP
451 return stream_class->default_clock_class;
452}
453
44c440bc 454bt_bool bt_stream_class_assigns_automatic_event_class_id(
40f4ba76 455 const struct bt_stream_class *stream_class)
44c440bc 456{
bdb288b3 457 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
44c440bc 458 return (bt_bool) stream_class->assigns_automatic_event_class_id;
8bf65fbd
JG
459}
460
40f4ba76
PP
461void bt_stream_class_set_assigns_automatic_event_class_id(
462 struct bt_stream_class *stream_class,
e5be10ef 463 bt_bool value)
8bf65fbd 464{
44c440bc 465 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
bdb288b3 466 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
44c440bc 467 stream_class->assigns_automatic_event_class_id = (bool) value;
3f7d4d90 468 BT_LIB_LOGD("Set stream class's automatic event class ID "
44c440bc 469 "assignment property: %!+S", stream_class);
44c440bc 470}
8bf65fbd 471
44c440bc 472bt_bool bt_stream_class_assigns_automatic_stream_id(
40f4ba76 473 const struct bt_stream_class *stream_class)
44c440bc 474{
bdb288b3 475 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
44c440bc
PP
476 return (bt_bool) stream_class->assigns_automatic_stream_id;
477}
8bf65fbd 478
2e90378a
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");
bdb288b3 485 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
2e90378a
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;
3f7d4d90 497 BT_LIB_LOGD("Set stream class's discarded events support property: "
2e90378a
PP
498 "%!+S", stream_class);
499}
500
501bt_bool bt_stream_class_supports_discarded_events(
502 const struct bt_stream_class *stream_class)
503{
bdb288b3 504 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
2e90378a
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{
bdb288b3 511 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
2e90378a
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");
bdb288b3 521 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
26fc5aed
PP
522 BT_ASSERT_PRE(!supports_discarded_packets ||
523 stream_class->supports_packets,
524 "Stream class does not support packets: %!+S",
525 stream_class);
2e90378a
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;
3f7d4d90 537 BT_LIB_LOGD("Set stream class's discarded packets support property: "
2e90378a
PP
538 "%!+S", stream_class);
539}
540
541bt_bool bt_stream_class_supports_discarded_packets(
542 const struct bt_stream_class *stream_class)
543{
bdb288b3 544 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
2e90378a
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{
bdb288b3 551 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
2e90378a
PP
552 return (bt_bool) stream_class->discarded_packets_have_default_clock_snapshots;
553}
554
26fc5aed
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");
bdb288b3 565 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
26fc5aed
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{
bdb288b3 599 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
26fc5aed
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{
bdb288b3 606 BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class");
26fc5aed
PP
607 return (bt_bool) stream_class->packets_have_end_default_clock_snapshot;
608}
609
40f4ba76
PP
610void bt_stream_class_set_assigns_automatic_stream_id(
611 struct bt_stream_class *stream_class,
e5be10ef 612 bt_bool value)
44c440bc
PP
613{
614 BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
bdb288b3 615 BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class);
44c440bc 616 stream_class->assigns_automatic_stream_id = (bool) value;
3f7d4d90 617 BT_LIB_LOGD("Set stream class's automatic stream ID "
44c440bc 618 "assignment property: %!+S", stream_class);
44c440bc 619}
3dca2276 620
c6962c96
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);
6871026b 644 bt_object_put_ref_no_null_check(stream_class->user_attributes);
c6962c96 645 stream_class->user_attributes = (void *) user_attributes;
6871026b 646 bt_object_get_ref_no_null_check(stream_class->user_attributes);
c6962c96
PP
647}
648
c5b9b441
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.1154 seconds and 4 git commands to generate.