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