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