Commit | Line | Data |
---|---|---|
11b0cdc8 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
de9dd397 | 5 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
11b0cdc8 JG |
6 | */ |
7 | ||
350ad6c1 | 8 | #define BT_LOG_TAG "LIB/STREAM-CLASS" |
c2d9d9cf | 9 | #include "lib/logging.h" |
d2f71f12 | 10 | |
d98421f2 | 11 | #include "lib/assert-cond.h" |
43c59509 | 12 | #include <babeltrace2/trace-ir/trace.h> |
578e048b MJ |
13 | #include "compat/compiler.h" |
14 | #include "common/align.h" | |
15 | #include "compat/endian.h" | |
16 | #include "common/assert.h" | |
17 | #include "lib/property.h" | |
dc3fffef | 18 | #include <inttypes.h> |
544d0515 | 19 | #include <stdint.h> |
e011d2c1 | 20 | #include <stdbool.h> |
11b0cdc8 | 21 | |
578e048b MJ |
22 | #include "clock-class.h" |
23 | #include "event-class.h" | |
24 | #include "field-class.h" | |
25 | #include "field.h" | |
26 | #include "field-wrapper.h" | |
27 | #include "resolve-field-path.h" | |
28 | #include "stream-class.h" | |
29 | #include "trace.h" | |
30 | #include "utils.h" | |
c6962c96 | 31 | #include "lib/value.h" |
d24d5663 | 32 | #include "lib/func-status.h" |
578e048b | 33 | |
d5b13b9b | 34 | #define BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(_sc) \ |
1778c2a4 PP |
35 | BT_ASSERT_PRE_DEV_HOT("stream-class", (_sc), "Stream class", \ |
36 | ": %!+S", (_sc)) | |
142c5610 | 37 | |
cb6f1f7d | 38 | static |
44c440bc | 39 | void destroy_stream_class(struct bt_object *obj) |
3ea33115 | 40 | { |
cb6f1f7d PP |
41 | struct bt_stream_class *stream_class = (void *) obj; |
42 | ||
44c440bc PP |
43 | BT_LIB_LOGD("Destroying stream class: %!+S", stream_class); |
44 | BT_LOGD_STR("Putting default clock class."); | |
c6962c96 | 45 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->user_attributes); |
238b7404 | 46 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class); |
3ea33115 | 47 | |
3dca2276 PP |
48 | if (stream_class->event_classes) { |
49 | BT_LOGD_STR("Destroying event classes."); | |
50 | g_ptr_array_free(stream_class->event_classes, TRUE); | |
238b7404 | 51 | stream_class->event_classes = NULL; |
d2f71f12 PP |
52 | } |
53 | ||
44c440bc PP |
54 | if (stream_class->name.str) { |
55 | g_string_free(stream_class->name.str, TRUE); | |
238b7404 PP |
56 | stream_class->name.str = NULL; |
57 | stream_class->name.value = NULL; | |
3ea33115 JG |
58 | } |
59 | ||
e6276565 | 60 | BT_LOGD_STR("Putting packet context field class."); |
238b7404 | 61 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); |
e6276565 | 62 | BT_LOGD_STR("Putting event common context field class."); |
238b7404 | 63 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_common_context_fc); |
312c056a | 64 | bt_object_pool_finalize(&stream_class->packet_context_field_pool); |
3dca2276 | 65 | g_free(stream_class); |
3ea33115 JG |
66 | } |
67 | ||
312c056a PP |
68 | static |
69 | void free_field_wrapper(struct bt_field_wrapper *field_wrapper, | |
70 | struct bt_stream_class *stream_class) | |
71 | { | |
72 | bt_field_wrapper_destroy((void *) field_wrapper); | |
73 | } | |
74 | ||
44c440bc | 75 | static |
862ca4ed | 76 | bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id) |
44c440bc PP |
77 | { |
78 | uint64_t i; | |
79 | bool is_unique = true; | |
80 | ||
862ca4ed | 81 | for (i = 0; i < tc->stream_classes->len; i++) { |
40f4ba76 | 82 | const struct bt_stream_class *sc = |
862ca4ed | 83 | tc->stream_classes->pdata[i]; |
44c440bc PP |
84 | |
85 | if (sc->id == id) { | |
86 | is_unique = false; | |
87 | goto end; | |
88 | } | |
89 | } | |
90 | ||
91 | end: | |
92 | return is_unique; | |
93 | } | |
94 | ||
95 | static | |
862ca4ed PP |
96 | struct bt_stream_class *create_stream_class_with_id( |
97 | struct bt_trace_class *tc, uint64_t id) | |
2f100782 | 98 | { |
3dca2276 PP |
99 | struct bt_stream_class *stream_class = NULL; |
100 | int ret; | |
2f100782 | 101 | |
862ca4ed | 102 | BT_ASSERT(tc); |
1778c2a4 PP |
103 | BT_ASSERT_PRE("stream-class-id-is-unique", |
104 | stream_class_id_is_unique(tc, id), | |
862ca4ed PP |
105 | "Duplicate stream class ID: %![tc-]+T, id=%" PRIu64, tc, id); |
106 | BT_LIB_LOGD("Creating stream class object: %![tc-]+T, id=%" PRIu64, | |
107 | tc, id); | |
3dca2276 | 108 | stream_class = g_new0(struct bt_stream_class, 1); |
d2f71f12 | 109 | if (!stream_class) { |
870631a2 PP |
110 | BT_LIB_LOGE_APPEND_CAUSE( |
111 | "Failed to allocate one stream class."); | |
3dca2276 | 112 | goto error; |
d2f71f12 PP |
113 | } |
114 | ||
44c440bc PP |
115 | bt_object_init_shared_with_parent(&stream_class->base, |
116 | destroy_stream_class); | |
c6962c96 PP |
117 | stream_class->user_attributes = bt_value_map_create(); |
118 | if (!stream_class->user_attributes) { | |
119 | BT_LIB_LOGE_APPEND_CAUSE( | |
120 | "Failed to create a map value object."); | |
121 | goto error; | |
122 | } | |
44c440bc PP |
123 | |
124 | stream_class->name.str = g_string_new(NULL); | |
125 | if (!stream_class->name.str) { | |
870631a2 | 126 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
c6962c96 | 127 | goto error; |
44c440bc PP |
128 | } |
129 | ||
130 | stream_class->id = id; | |
131 | stream_class->assigns_automatic_event_class_id = true; | |
132 | stream_class->assigns_automatic_stream_id = true; | |
133 | stream_class->event_classes = g_ptr_array_new_with_free_func( | |
134 | (GDestroyNotify) bt_object_try_spec_release); | |
135 | if (!stream_class->event_classes) { | |
870631a2 | 136 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); |
3dca2276 | 137 | goto error; |
2f100782 JG |
138 | } |
139 | ||
312c056a PP |
140 | ret = bt_object_pool_initialize(&stream_class->packet_context_field_pool, |
141 | (bt_object_pool_new_object_func) bt_field_wrapper_new, | |
142 | (bt_object_pool_destroy_object_func) free_field_wrapper, | |
143 | stream_class); | |
144 | if (ret) { | |
870631a2 PP |
145 | BT_LIB_LOGE_APPEND_CAUSE( |
146 | "Failed to initialize packet context field pool: ret=%d", | |
312c056a PP |
147 | ret); |
148 | goto error; | |
149 | } | |
150 | ||
862ca4ed PP |
151 | bt_object_set_parent(&stream_class->base, &tc->base); |
152 | g_ptr_array_add(tc->stream_classes, stream_class); | |
153 | bt_trace_class_freeze(tc); | |
44c440bc | 154 | BT_LIB_LOGD("Created stream class object: %!+S", stream_class); |
312c056a PP |
155 | goto end; |
156 | ||
157 | error: | |
65300d60 | 158 | BT_OBJECT_PUT_REF_AND_RESET(stream_class); |
312c056a PP |
159 | |
160 | end: | |
44c440bc | 161 | return stream_class; |
312c056a PP |
162 | } |
163 | ||
862ca4ed | 164 | struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc) |
312c056a | 165 | { |
17f3083a | 166 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b | 167 | BT_ASSERT_PRE_TC_NON_NULL(tc); |
1778c2a4 PP |
168 | BT_ASSERT_PRE("trace-class-automatically-assigns-stream-class-ids", |
169 | tc->assigns_automatic_stream_class_id, | |
862ca4ed PP |
170 | "Trace class does not automatically assigns stream class IDs: " |
171 | "%![sc-]+T", tc); | |
172 | return create_stream_class_with_id(tc, | |
173 | (uint64_t) tc->stream_classes->len); | |
44c440bc | 174 | } |
312c056a | 175 | |
40f4ba76 | 176 | struct bt_stream_class *bt_stream_class_create_with_id( |
862ca4ed | 177 | struct bt_trace_class *tc, uint64_t id) |
44c440bc | 178 | { |
17f3083a | 179 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b | 180 | BT_ASSERT_PRE_TC_NON_NULL(tc); |
1778c2a4 PP |
181 | BT_ASSERT_PRE( |
182 | "trace-class-does-not-automatically-assigns-stream-class-ids", | |
183 | !tc->assigns_automatic_stream_class_id, | |
862ca4ed PP |
184 | "Trace class automatically assigns stream class IDs: " |
185 | "%![sc-]+T", tc); | |
186 | return create_stream_class_with_id(tc, id); | |
312c056a PP |
187 | } |
188 | ||
862ca4ed | 189 | struct bt_trace_class *bt_stream_class_borrow_trace_class( |
40f4ba76 | 190 | struct bt_stream_class *stream_class) |
11b0cdc8 | 191 | { |
d5b13b9b | 192 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
862ca4ed | 193 | return bt_stream_class_borrow_trace_class_inline(stream_class); |
11b0cdc8 JG |
194 | } |
195 | ||
862ca4ed | 196 | const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( |
40f4ba76 | 197 | const struct bt_stream_class *stream_class) |
e5be10ef | 198 | { |
862ca4ed | 199 | return bt_stream_class_borrow_trace_class((void *) stream_class); |
e5be10ef PP |
200 | } |
201 | ||
40f4ba76 | 202 | const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class) |
2f100782 | 203 | { |
d5b13b9b | 204 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
44c440bc | 205 | return stream_class->name.value; |
2f100782 JG |
206 | } |
207 | ||
d24d5663 | 208 | enum bt_stream_class_set_name_status bt_stream_class_set_name( |
40f4ba76 | 209 | struct bt_stream_class *stream_class, |
3dca2276 | 210 | const char *name) |
5ca83563 | 211 | { |
17f3083a | 212 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b PP |
213 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
214 | BT_ASSERT_PRE_NAME_NON_NULL(name); | |
bdb288b3 | 215 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
44c440bc PP |
216 | g_string_assign(stream_class->name.str, name); |
217 | stream_class->name.value = stream_class->name.str->str; | |
3f7d4d90 | 218 | BT_LIB_LOGD("Set stream class's name: %!+S", stream_class); |
d24d5663 | 219 | return BT_FUNC_STATUS_OK; |
5ca83563 JG |
220 | } |
221 | ||
40f4ba76 | 222 | uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class) |
2f100782 | 223 | { |
d5b13b9b | 224 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
44c440bc | 225 | return stream_class->id; |
2f100782 JG |
226 | } |
227 | ||
44c440bc | 228 | uint64_t bt_stream_class_get_event_class_count( |
40f4ba76 | 229 | const struct bt_stream_class *stream_class) |
29664b2a | 230 | { |
d5b13b9b | 231 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
44c440bc | 232 | return (uint64_t) stream_class->event_classes->len; |
29664b2a PP |
233 | } |
234 | ||
44c440bc PP |
235 | struct bt_event_class *bt_stream_class_borrow_event_class_by_index( |
236 | struct bt_stream_class *stream_class, uint64_t index) | |
0d23acbe | 237 | { |
d5b13b9b | 238 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
bdb288b3 | 239 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, stream_class->event_classes->len); |
44c440bc | 240 | return g_ptr_array_index(stream_class->event_classes, index); |
0d23acbe PP |
241 | } |
242 | ||
40f4ba76 PP |
243 | const struct bt_event_class * |
244 | bt_stream_class_borrow_event_class_by_index_const( | |
245 | const struct bt_stream_class *stream_class, uint64_t index) | |
e5be10ef | 246 | { |
40f4ba76 | 247 | return bt_stream_class_borrow_event_class_by_index( |
e5be10ef PP |
248 | (void *) stream_class, index); |
249 | } | |
250 | ||
44c440bc | 251 | struct bt_event_class *bt_stream_class_borrow_event_class_by_id( |
e5be10ef | 252 | struct bt_stream_class *stream_class, uint64_t id) |
11b0cdc8 | 253 | { |
44c440bc PP |
254 | struct bt_event_class *event_class = NULL; |
255 | uint64_t i; | |
0b9ce69f | 256 | |
d5b13b9b | 257 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
11b0cdc8 | 258 | |
e5be10ef | 259 | for (i = 0; i < stream_class->event_classes->len; i++) { |
44c440bc | 260 | struct bt_event_class *event_class_candidate = |
e5be10ef | 261 | g_ptr_array_index(stream_class->event_classes, i); |
e6a8e8e4 | 262 | |
44c440bc PP |
263 | if (event_class_candidate->id == id) { |
264 | event_class = event_class_candidate; | |
09840de5 PP |
265 | goto end; |
266 | } | |
69dc4535 JG |
267 | } |
268 | ||
69dc4535 | 269 | end: |
44c440bc | 270 | return event_class; |
0863f950 PP |
271 | } |
272 | ||
40f4ba76 PP |
273 | const struct bt_event_class * |
274 | bt_stream_class_borrow_event_class_by_id_const( | |
275 | const struct bt_stream_class *stream_class, uint64_t id) | |
e5be10ef | 276 | { |
40f4ba76 | 277 | return bt_stream_class_borrow_event_class_by_id( |
e5be10ef PP |
278 | (void *) stream_class, id); |
279 | } | |
280 | ||
40f4ba76 PP |
281 | const struct bt_field_class * |
282 | bt_stream_class_borrow_packet_context_field_class_const( | |
283 | const struct bt_stream_class *stream_class) | |
12c8a1a3 | 284 | { |
d5b13b9b | 285 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
5cd6d0e5 | 286 | return stream_class->packet_context_fc; |
12c8a1a3 JG |
287 | } |
288 | ||
740faaf4 PP |
289 | struct bt_field_class * |
290 | bt_stream_class_borrow_packet_context_field_class( | |
291 | struct bt_stream_class *stream_class) | |
292 | { | |
d5b13b9b | 293 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
740faaf4 PP |
294 | return stream_class->packet_context_fc; |
295 | } | |
296 | ||
d24d5663 PP |
297 | enum bt_stream_class_set_field_class_status |
298 | bt_stream_class_set_packet_context_field_class( | |
40f4ba76 PP |
299 | struct bt_stream_class *stream_class, |
300 | struct bt_field_class *field_class) | |
12c8a1a3 | 301 | { |
44c440bc PP |
302 | int ret; |
303 | struct bt_resolve_field_path_context resolve_ctx = { | |
5cd6d0e5 | 304 | .packet_context = field_class, |
44c440bc PP |
305 | .event_common_context = NULL, |
306 | .event_specific_context = NULL, | |
307 | .event_payload = NULL, | |
308 | }; | |
cb6f1f7d | 309 | |
17f3083a | 310 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b | 311 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
1778c2a4 PP |
312 | BT_ASSERT_PRE("supports-packets", |
313 | stream_class->supports_packets, | |
26fc5aed PP |
314 | "Stream class does not support packets: %![sc-]+S", |
315 | stream_class); | |
d5b13b9b | 316 | BT_ASSERT_PRE_FC_NON_NULL(field_class); |
bdb288b3 | 317 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
1778c2a4 PP |
318 | BT_ASSERT_PRE_FC_IS_STRUCT("field-class", field_class, |
319 | "Packet context field class"); | |
320 | ret = bt_resolve_field_paths(field_class, &resolve_ctx, __func__); | |
44c440bc | 321 | if (ret) { |
a6ae8edc PP |
322 | /* |
323 | * This is the only reason for which | |
324 | * bt_resolve_field_paths() can fail: anything else | |
325 | * would be because a precondition is not satisfied. | |
326 | */ | |
d24d5663 | 327 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
cb6f1f7d PP |
328 | goto end; |
329 | } | |
330 | ||
862ca4ed | 331 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 332 | bt_object_put_ref(stream_class->packet_context_fc); |
398454ed | 333 | stream_class->packet_context_fc = field_class; |
6871026b | 334 | bt_object_get_ref_no_null_check(stream_class->packet_context_fc); |
5cd6d0e5 | 335 | bt_field_class_freeze(field_class); |
3f7d4d90 | 336 | BT_LIB_LOGD("Set stream class's packet context field class: %!+S", |
44c440bc | 337 | stream_class); |
cb6f1f7d PP |
338 | |
339 | end: | |
340 | return ret; | |
12c8a1a3 JG |
341 | } |
342 | ||
40f4ba76 PP |
343 | const struct bt_field_class * |
344 | bt_stream_class_borrow_event_common_context_field_class_const( | |
345 | const struct bt_stream_class *stream_class) | |
af181248 | 346 | { |
d5b13b9b | 347 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
5cd6d0e5 | 348 | return stream_class->event_common_context_fc; |
af181248 JG |
349 | } |
350 | ||
740faaf4 PP |
351 | struct bt_field_class * |
352 | bt_stream_class_borrow_event_common_context_field_class( | |
353 | struct bt_stream_class *stream_class) | |
354 | { | |
d5b13b9b | 355 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
740faaf4 PP |
356 | return stream_class->event_common_context_fc; |
357 | } | |
358 | ||
d24d5663 | 359 | enum bt_stream_class_set_field_class_status |
a6ae8edc | 360 | bt_stream_class_set_event_common_context_field_class( |
40f4ba76 PP |
361 | struct bt_stream_class *stream_class, |
362 | struct bt_field_class *field_class) | |
af181248 | 363 | { |
44c440bc PP |
364 | int ret; |
365 | struct bt_resolve_field_path_context resolve_ctx = { | |
44c440bc | 366 | .packet_context = NULL, |
5cd6d0e5 | 367 | .event_common_context = field_class, |
44c440bc PP |
368 | .event_specific_context = NULL, |
369 | .event_payload = NULL, | |
370 | }; | |
cb6f1f7d | 371 | |
17f3083a | 372 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b PP |
373 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
374 | BT_ASSERT_PRE_FC_NON_NULL(field_class); | |
bdb288b3 | 375 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
1778c2a4 | 376 | BT_ASSERT_PRE_FC_IS_STRUCT("field-class", field_class, |
d5b13b9b | 377 | "Event common context field class"); |
5cd6d0e5 | 378 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
1778c2a4 | 379 | ret = bt_resolve_field_paths(field_class, &resolve_ctx, __func__); |
44c440bc | 380 | if (ret) { |
a6ae8edc PP |
381 | /* |
382 | * This is the only reason for which | |
383 | * bt_resolve_field_paths() can fail: anything else | |
384 | * would be because a precondition is not satisfied. | |
385 | */ | |
d24d5663 | 386 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
cb6f1f7d PP |
387 | goto end; |
388 | } | |
389 | ||
862ca4ed | 390 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 391 | bt_object_put_ref(stream_class->event_common_context_fc); |
398454ed | 392 | stream_class->event_common_context_fc = field_class; |
6871026b | 393 | bt_object_get_ref_no_null_check(stream_class->event_common_context_fc); |
5cd6d0e5 | 394 | bt_field_class_freeze(field_class); |
3f7d4d90 | 395 | BT_LIB_LOGD("Set stream class's event common context field class: %!+S", |
44c440bc | 396 | stream_class); |
cb6f1f7d | 397 | |
cb6f1f7d PP |
398 | end: |
399 | return ret; | |
11b0cdc8 JG |
400 | } |
401 | ||
44c440bc | 402 | BT_HIDDEN |
40f4ba76 | 403 | void _bt_stream_class_freeze(const struct bt_stream_class *stream_class) |
8bf65fbd | 404 | { |
5cd6d0e5 | 405 | /* The field classes and default clock class are already frozen */ |
44c440bc | 406 | BT_ASSERT(stream_class); |
c6962c96 PP |
407 | BT_LIB_LOGD("Freezing stream class's user attributes: %!+v", |
408 | stream_class->user_attributes); | |
409 | bt_value_freeze(stream_class->user_attributes); | |
44c440bc | 410 | BT_LIB_LOGD("Freezing stream class: %!+S", stream_class); |
40f4ba76 | 411 | ((struct bt_stream_class *) stream_class)->frozen = true; |
8bf65fbd JG |
412 | } |
413 | ||
d24d5663 PP |
414 | enum bt_stream_class_set_default_clock_class_status |
415 | bt_stream_class_set_default_clock_class( | |
40f4ba76 | 416 | struct bt_stream_class *stream_class, |
44c440bc | 417 | struct bt_clock_class *clock_class) |
8bf65fbd | 418 | { |
17f3083a | 419 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b PP |
420 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
421 | BT_ASSERT_PRE_CLK_CLS_NON_NULL(clock_class); | |
bdb288b3 | 422 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
65300d60 | 423 | bt_object_put_ref(stream_class->default_clock_class); |
398454ed | 424 | stream_class->default_clock_class = clock_class; |
6871026b | 425 | bt_object_get_ref_no_null_check(stream_class->default_clock_class); |
44c440bc | 426 | bt_clock_class_freeze(clock_class); |
3f7d4d90 | 427 | BT_LIB_LOGD("Set stream class's default clock class: %!+S", |
44c440bc | 428 | stream_class); |
d24d5663 | 429 | return BT_FUNC_STATUS_OK; |
8bf65fbd JG |
430 | } |
431 | ||
44c440bc PP |
432 | struct bt_clock_class *bt_stream_class_borrow_default_clock_class( |
433 | struct bt_stream_class *stream_class) | |
8bf65fbd | 434 | { |
d5b13b9b | 435 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
44c440bc PP |
436 | return stream_class->default_clock_class; |
437 | } | |
8bf65fbd | 438 | |
40f4ba76 PP |
439 | const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const( |
440 | const struct bt_stream_class *stream_class) | |
441 | { | |
d5b13b9b | 442 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
40f4ba76 PP |
443 | return stream_class->default_clock_class; |
444 | } | |
445 | ||
44c440bc | 446 | bt_bool bt_stream_class_assigns_automatic_event_class_id( |
40f4ba76 | 447 | const struct bt_stream_class *stream_class) |
44c440bc | 448 | { |
d5b13b9b | 449 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
44c440bc | 450 | return (bt_bool) stream_class->assigns_automatic_event_class_id; |
8bf65fbd JG |
451 | } |
452 | ||
40f4ba76 PP |
453 | void bt_stream_class_set_assigns_automatic_event_class_id( |
454 | struct bt_stream_class *stream_class, | |
e5be10ef | 455 | bt_bool value) |
8bf65fbd | 456 | { |
d5b13b9b | 457 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
bdb288b3 | 458 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
44c440bc | 459 | stream_class->assigns_automatic_event_class_id = (bool) value; |
3f7d4d90 | 460 | BT_LIB_LOGD("Set stream class's automatic event class ID " |
44c440bc | 461 | "assignment property: %!+S", stream_class); |
44c440bc | 462 | } |
8bf65fbd | 463 | |
44c440bc | 464 | bt_bool bt_stream_class_assigns_automatic_stream_id( |
40f4ba76 | 465 | const struct bt_stream_class *stream_class) |
44c440bc | 466 | { |
d5b13b9b | 467 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
44c440bc PP |
468 | return (bt_bool) stream_class->assigns_automatic_stream_id; |
469 | } | |
8bf65fbd | 470 | |
2e90378a PP |
471 | void bt_stream_class_set_supports_discarded_events( |
472 | struct bt_stream_class *stream_class, | |
473 | bt_bool supports_discarded_events, | |
474 | bt_bool with_default_clock_snapshots) | |
475 | { | |
d5b13b9b | 476 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
bdb288b3 | 477 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
1778c2a4 PP |
478 | BT_ASSERT_PRE("supports-discarded-events-for-default-clock-snapshots", |
479 | supports_discarded_events || | |
480 | !with_default_clock_snapshots, | |
2e90378a PP |
481 | "Discarded events cannot have default clock snapshots when " |
482 | "not supported: %!+S", stream_class); | |
1778c2a4 PP |
483 | BT_ASSERT_PRE("has-default-clock-class-for-default-clock-snapshots", |
484 | !with_default_clock_snapshots || | |
485 | stream_class->default_clock_class, | |
2e90378a PP |
486 | "Stream class has no default clock class: %!+S", stream_class); |
487 | stream_class->supports_discarded_events = | |
488 | (bool) supports_discarded_events; | |
489 | stream_class->discarded_events_have_default_clock_snapshots = | |
490 | (bool) with_default_clock_snapshots; | |
3f7d4d90 | 491 | BT_LIB_LOGD("Set stream class's discarded events support property: " |
2e90378a PP |
492 | "%!+S", stream_class); |
493 | } | |
494 | ||
495 | bt_bool bt_stream_class_supports_discarded_events( | |
496 | const struct bt_stream_class *stream_class) | |
497 | { | |
d5b13b9b | 498 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
2e90378a PP |
499 | return (bt_bool) stream_class->supports_discarded_events; |
500 | } | |
501 | ||
502 | bt_bool bt_stream_class_discarded_events_have_default_clock_snapshots( | |
503 | const struct bt_stream_class *stream_class) | |
504 | { | |
d5b13b9b | 505 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
2e90378a PP |
506 | return (bt_bool) stream_class->discarded_events_have_default_clock_snapshots; |
507 | } | |
508 | ||
509 | void bt_stream_class_set_supports_discarded_packets( | |
510 | struct bt_stream_class *stream_class, | |
511 | bt_bool supports_discarded_packets, | |
512 | bt_bool with_default_clock_snapshots) | |
513 | { | |
d5b13b9b | 514 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
bdb288b3 | 515 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
1778c2a4 PP |
516 | BT_ASSERT_PRE("supports-packets-for-discarded-packets-support", |
517 | !supports_discarded_packets || | |
518 | stream_class->supports_packets, | |
26fc5aed PP |
519 | "Stream class does not support packets: %!+S", |
520 | stream_class); | |
1778c2a4 PP |
521 | BT_ASSERT_PRE("supports-discarded-packets-for-default-clock-snapshots", |
522 | supports_discarded_packets || | |
523 | !with_default_clock_snapshots, | |
2e90378a PP |
524 | "Discarded packets cannot have default clock snapshots when " |
525 | "not supported: %!+S", stream_class); | |
1778c2a4 PP |
526 | BT_ASSERT_PRE("has-default-clock-class-for-default-clock-snapshots", |
527 | !with_default_clock_snapshots || | |
528 | stream_class->default_clock_class, | |
2e90378a PP |
529 | "Stream class has no default clock class: %!+S", stream_class); |
530 | stream_class->supports_discarded_packets = | |
531 | (bool) supports_discarded_packets; | |
532 | stream_class->discarded_packets_have_default_clock_snapshots = | |
533 | (bool) with_default_clock_snapshots; | |
3f7d4d90 | 534 | BT_LIB_LOGD("Set stream class's discarded packets support property: " |
2e90378a PP |
535 | "%!+S", stream_class); |
536 | } | |
537 | ||
538 | bt_bool bt_stream_class_supports_discarded_packets( | |
539 | const struct bt_stream_class *stream_class) | |
540 | { | |
d5b13b9b | 541 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
2e90378a PP |
542 | return (bt_bool) stream_class->supports_discarded_packets; |
543 | } | |
544 | ||
545 | bt_bool bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
546 | const struct bt_stream_class *stream_class) | |
547 | { | |
d5b13b9b | 548 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
2e90378a PP |
549 | return (bt_bool) stream_class->discarded_packets_have_default_clock_snapshots; |
550 | } | |
551 | ||
26fc5aed PP |
552 | void bt_stream_class_set_supports_packets( |
553 | struct bt_stream_class *stream_class, | |
554 | bt_bool supports_packets, | |
555 | bt_bool with_beginning_default_clock_snapshot, | |
556 | bt_bool with_end_default_clock_snapshot) | |
557 | { | |
558 | bt_bool with_default_clock_snapshot = | |
559 | with_beginning_default_clock_snapshot || | |
560 | with_end_default_clock_snapshot; | |
d5b13b9b | 561 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
bdb288b3 | 562 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
1778c2a4 PP |
563 | BT_ASSERT_PRE("supports-packets-for-default-clock-snapshot", |
564 | supports_packets || | |
565 | !with_default_clock_snapshot, | |
26fc5aed PP |
566 | "Packets cannot have default clock snapshots when " |
567 | "not supported: %!+S", stream_class); | |
1778c2a4 PP |
568 | BT_ASSERT_PRE("has-default-clock-class-for-default-clock-snapshot", |
569 | !with_default_clock_snapshot || | |
570 | stream_class->default_clock_class, | |
26fc5aed | 571 | "Stream class has no default clock class: %!+S", stream_class); |
1778c2a4 PP |
572 | BT_ASSERT_PRE("supports-packets-for-packet-context-field-class", |
573 | supports_packets || !stream_class->packet_context_fc, | |
26fc5aed PP |
574 | "Stream class already has a packet context field class: %!+S", |
575 | stream_class); | |
1778c2a4 PP |
576 | BT_ASSERT_PRE("supports-packets-for-discarded-packets-support", |
577 | supports_packets || !stream_class->supports_discarded_packets, | |
26fc5aed PP |
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 | ||
589 | bt_bool bt_stream_class_supports_packets( | |
590 | const struct bt_stream_class *stream_class) | |
591 | { | |
d5b13b9b | 592 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
26fc5aed PP |
593 | return (bt_bool) stream_class->supports_packets; |
594 | } | |
595 | ||
596 | bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot( | |
597 | const struct bt_stream_class *stream_class) | |
598 | { | |
d5b13b9b | 599 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
26fc5aed PP |
600 | return (bt_bool) stream_class->packets_have_beginning_default_clock_snapshot; |
601 | } | |
602 | ||
603 | bt_bool bt_stream_class_packets_have_end_default_clock_snapshot( | |
604 | const struct bt_stream_class *stream_class) | |
605 | { | |
d5b13b9b | 606 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
26fc5aed PP |
607 | return (bt_bool) stream_class->packets_have_end_default_clock_snapshot; |
608 | } | |
609 | ||
40f4ba76 PP |
610 | void bt_stream_class_set_assigns_automatic_stream_id( |
611 | struct bt_stream_class *stream_class, | |
e5be10ef | 612 | bt_bool value) |
44c440bc | 613 | { |
d5b13b9b | 614 | BT_ASSERT_PRE_SC_NON_NULL(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 |
621 | const struct bt_value *bt_stream_class_borrow_user_attributes_const( |
622 | const struct bt_stream_class *stream_class) | |
623 | { | |
d5b13b9b | 624 | BT_ASSERT_PRE_DEV_SC_NON_NULL(stream_class); |
c6962c96 PP |
625 | return stream_class->user_attributes; |
626 | } | |
627 | ||
628 | struct 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 | ||
635 | void bt_stream_class_set_user_attributes( | |
636 | struct bt_stream_class *stream_class, | |
637 | const struct bt_value *user_attributes) | |
638 | { | |
d5b13b9b PP |
639 | BT_ASSERT_PRE_SC_NON_NULL(stream_class); |
640 | BT_ASSERT_PRE_USER_ATTRS_NON_NULL(user_attributes); | |
641 | BT_ASSERT_PRE_USER_ATTRS_IS_MAP(user_attributes); | |
c6962c96 | 642 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
6871026b | 643 | bt_object_put_ref_no_null_check(stream_class->user_attributes); |
c6962c96 | 644 | stream_class->user_attributes = (void *) user_attributes; |
6871026b | 645 | bt_object_get_ref_no_null_check(stream_class->user_attributes); |
c6962c96 PP |
646 | } |
647 | ||
c5b9b441 PP |
648 | void bt_stream_class_get_ref(const struct bt_stream_class *stream_class) |
649 | { | |
650 | bt_object_get_ref(stream_class); | |
651 | } | |
652 | ||
653 | void bt_stream_class_put_ref(const struct bt_stream_class *stream_class) | |
654 | { | |
655 | bt_object_put_ref(stream_class); | |
656 | } |