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