Commit | Line | Data |
---|---|---|
11b0cdc8 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
de9dd397 | 3 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
11b0cdc8 | 4 | * |
11b0cdc8 JG |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
b03487ab | 24 | #define BT_LOG_TAG "LIB/STREAM-CLASS" |
1633ef46 | 25 | #include "lib/logging.h" |
d2f71f12 | 26 | |
57952005 | 27 | #include "lib/assert-pre.h" |
7704a0af | 28 | #include <babeltrace2/trace-ir/trace.h> |
57952005 MJ |
29 | #include "compat/compiler.h" |
30 | #include "common/align.h" | |
31 | #include "compat/endian.h" | |
32 | #include "common/assert.h" | |
33 | #include "lib/property.h" | |
dc3fffef | 34 | #include <inttypes.h> |
544d0515 | 35 | #include <stdint.h> |
e011d2c1 | 36 | #include <stdbool.h> |
11b0cdc8 | 37 | |
57952005 MJ |
38 | #include "clock-class.h" |
39 | #include "event-class.h" | |
40 | #include "field-class.h" | |
41 | #include "field.h" | |
42 | #include "field-wrapper.h" | |
43 | #include "resolve-field-path.h" | |
44 | #include "stream-class.h" | |
45 | #include "trace.h" | |
46 | #include "utils.h" | |
af90138b | 47 | #include "lib/value.h" |
fb25b9e3 | 48 | #include "lib/func-status.h" |
57952005 | 49 | |
fa6cfec3 PP |
50 | #define BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(_sc) \ |
51 | BT_ASSERT_PRE_DEV_HOT((_sc), "Stream class", ": %!+S", (_sc)) | |
142c5610 | 52 | |
18acc6f8 | 53 | static |
7b33a0e0 | 54 | void destroy_stream_class(struct bt_object *obj) |
3ea33115 | 55 | { |
18acc6f8 PP |
56 | struct bt_stream_class *stream_class = (void *) obj; |
57 | ||
7b33a0e0 PP |
58 | BT_LIB_LOGD("Destroying stream class: %!+S", stream_class); |
59 | BT_LOGD_STR("Putting default clock class."); | |
af90138b | 60 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->user_attributes); |
1248f5ea | 61 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class); |
3ea33115 | 62 | |
8deee039 PP |
63 | if (stream_class->event_classes) { |
64 | BT_LOGD_STR("Destroying event classes."); | |
65 | g_ptr_array_free(stream_class->event_classes, TRUE); | |
1248f5ea | 66 | stream_class->event_classes = NULL; |
d2f71f12 PP |
67 | } |
68 | ||
7b33a0e0 PP |
69 | if (stream_class->name.str) { |
70 | g_string_free(stream_class->name.str, TRUE); | |
1248f5ea PP |
71 | stream_class->name.str = NULL; |
72 | stream_class->name.value = NULL; | |
3ea33115 JG |
73 | } |
74 | ||
66fd07a5 | 75 | BT_LOGD_STR("Putting packet context field class."); |
1248f5ea | 76 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); |
66fd07a5 | 77 | BT_LOGD_STR("Putting event common context field class."); |
1248f5ea | 78 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_common_context_fc); |
a6918753 | 79 | bt_object_pool_finalize(&stream_class->packet_context_field_pool); |
8deee039 | 80 | g_free(stream_class); |
3ea33115 JG |
81 | } |
82 | ||
a6918753 PP |
83 | static |
84 | void free_field_wrapper(struct bt_field_wrapper *field_wrapper, | |
85 | struct bt_stream_class *stream_class) | |
86 | { | |
87 | bt_field_wrapper_destroy((void *) field_wrapper); | |
88 | } | |
89 | ||
7b33a0e0 | 90 | static |
10b7a2e4 | 91 | bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id) |
7b33a0e0 PP |
92 | { |
93 | uint64_t i; | |
94 | bool is_unique = true; | |
95 | ||
10b7a2e4 | 96 | for (i = 0; i < tc->stream_classes->len; i++) { |
78cf9df6 | 97 | const struct bt_stream_class *sc = |
10b7a2e4 | 98 | tc->stream_classes->pdata[i]; |
7b33a0e0 PP |
99 | |
100 | if (sc->id == id) { | |
101 | is_unique = false; | |
102 | goto end; | |
103 | } | |
104 | } | |
105 | ||
106 | end: | |
107 | return is_unique; | |
108 | } | |
109 | ||
110 | static | |
10b7a2e4 PP |
111 | struct bt_stream_class *create_stream_class_with_id( |
112 | struct bt_trace_class *tc, uint64_t id) | |
2f100782 | 113 | { |
8deee039 PP |
114 | struct bt_stream_class *stream_class = NULL; |
115 | int ret; | |
2f100782 | 116 | |
10b7a2e4 PP |
117 | BT_ASSERT(tc); |
118 | BT_ASSERT_PRE(stream_class_id_is_unique(tc, id), | |
119 | "Duplicate stream class ID: %![tc-]+T, id=%" PRIu64, tc, id); | |
120 | BT_LIB_LOGD("Creating stream class object: %![tc-]+T, id=%" PRIu64, | |
121 | tc, id); | |
8deee039 | 122 | stream_class = g_new0(struct bt_stream_class, 1); |
d2f71f12 | 123 | if (!stream_class) { |
a8f90e5d PP |
124 | BT_LIB_LOGE_APPEND_CAUSE( |
125 | "Failed to allocate one stream class."); | |
8deee039 | 126 | goto error; |
d2f71f12 PP |
127 | } |
128 | ||
7b33a0e0 PP |
129 | bt_object_init_shared_with_parent(&stream_class->base, |
130 | destroy_stream_class); | |
af90138b PP |
131 | stream_class->user_attributes = bt_value_map_create(); |
132 | if (!stream_class->user_attributes) { | |
133 | BT_LIB_LOGE_APPEND_CAUSE( | |
134 | "Failed to create a map value object."); | |
135 | goto error; | |
136 | } | |
7b33a0e0 PP |
137 | |
138 | stream_class->name.str = g_string_new(NULL); | |
139 | if (!stream_class->name.str) { | |
a8f90e5d | 140 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
af90138b | 141 | goto error; |
7b33a0e0 PP |
142 | } |
143 | ||
144 | stream_class->id = id; | |
145 | stream_class->assigns_automatic_event_class_id = true; | |
146 | stream_class->assigns_automatic_stream_id = true; | |
147 | stream_class->event_classes = g_ptr_array_new_with_free_func( | |
148 | (GDestroyNotify) bt_object_try_spec_release); | |
149 | if (!stream_class->event_classes) { | |
a8f90e5d | 150 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); |
8deee039 | 151 | goto error; |
2f100782 JG |
152 | } |
153 | ||
a6918753 PP |
154 | ret = bt_object_pool_initialize(&stream_class->packet_context_field_pool, |
155 | (bt_object_pool_new_object_func) bt_field_wrapper_new, | |
156 | (bt_object_pool_destroy_object_func) free_field_wrapper, | |
157 | stream_class); | |
158 | if (ret) { | |
a8f90e5d PP |
159 | BT_LIB_LOGE_APPEND_CAUSE( |
160 | "Failed to initialize packet context field pool: ret=%d", | |
a6918753 PP |
161 | ret); |
162 | goto error; | |
163 | } | |
164 | ||
10b7a2e4 PP |
165 | bt_object_set_parent(&stream_class->base, &tc->base); |
166 | g_ptr_array_add(tc->stream_classes, stream_class); | |
167 | bt_trace_class_freeze(tc); | |
7b33a0e0 | 168 | BT_LIB_LOGD("Created stream class object: %!+S", stream_class); |
a6918753 PP |
169 | goto end; |
170 | ||
171 | error: | |
8138bfe1 | 172 | BT_OBJECT_PUT_REF_AND_RESET(stream_class); |
a6918753 PP |
173 | |
174 | end: | |
7b33a0e0 | 175 | return stream_class; |
a6918753 PP |
176 | } |
177 | ||
10b7a2e4 | 178 | struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc) |
a6918753 | 179 | { |
7c7324d3 | 180 | BT_ASSERT_PRE_NO_ERROR(); |
10b7a2e4 PP |
181 | BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); |
182 | BT_ASSERT_PRE(tc->assigns_automatic_stream_class_id, | |
183 | "Trace class does not automatically assigns stream class IDs: " | |
184 | "%![sc-]+T", tc); | |
185 | return create_stream_class_with_id(tc, | |
186 | (uint64_t) tc->stream_classes->len); | |
7b33a0e0 | 187 | } |
a6918753 | 188 | |
78cf9df6 | 189 | struct bt_stream_class *bt_stream_class_create_with_id( |
10b7a2e4 | 190 | struct bt_trace_class *tc, uint64_t id) |
7b33a0e0 | 191 | { |
7c7324d3 | 192 | BT_ASSERT_PRE_NO_ERROR(); |
10b7a2e4 PP |
193 | BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); |
194 | BT_ASSERT_PRE(!tc->assigns_automatic_stream_class_id, | |
195 | "Trace class automatically assigns stream class IDs: " | |
196 | "%![sc-]+T", tc); | |
197 | return create_stream_class_with_id(tc, id); | |
a6918753 PP |
198 | } |
199 | ||
10b7a2e4 | 200 | struct bt_trace_class *bt_stream_class_borrow_trace_class( |
78cf9df6 | 201 | struct bt_stream_class *stream_class) |
11b0cdc8 | 202 | { |
fa6cfec3 | 203 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
10b7a2e4 | 204 | return bt_stream_class_borrow_trace_class_inline(stream_class); |
11b0cdc8 JG |
205 | } |
206 | ||
10b7a2e4 | 207 | const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( |
78cf9df6 | 208 | const struct bt_stream_class *stream_class) |
9e550e5f | 209 | { |
10b7a2e4 | 210 | return bt_stream_class_borrow_trace_class((void *) stream_class); |
9e550e5f PP |
211 | } |
212 | ||
78cf9df6 | 213 | const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class) |
2f100782 | 214 | { |
fa6cfec3 | 215 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 | 216 | return stream_class->name.value; |
2f100782 JG |
217 | } |
218 | ||
fb25b9e3 | 219 | enum bt_stream_class_set_name_status bt_stream_class_set_name( |
78cf9df6 | 220 | struct bt_stream_class *stream_class, |
8deee039 | 221 | const char *name) |
5ca83563 | 222 | { |
7c7324d3 | 223 | BT_ASSERT_PRE_NO_ERROR(); |
7b33a0e0 PP |
224 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
225 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
fa6cfec3 | 226 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
7b33a0e0 PP |
227 | g_string_assign(stream_class->name.str, name); |
228 | stream_class->name.value = stream_class->name.str->str; | |
a684a357 | 229 | BT_LIB_LOGD("Set stream class's name: %!+S", stream_class); |
fb25b9e3 | 230 | return BT_FUNC_STATUS_OK; |
5ca83563 JG |
231 | } |
232 | ||
78cf9df6 | 233 | uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class) |
2f100782 | 234 | { |
fa6cfec3 | 235 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 | 236 | return stream_class->id; |
2f100782 JG |
237 | } |
238 | ||
7b33a0e0 | 239 | uint64_t bt_stream_class_get_event_class_count( |
78cf9df6 | 240 | const struct bt_stream_class *stream_class) |
29664b2a | 241 | { |
fa6cfec3 | 242 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 | 243 | return (uint64_t) stream_class->event_classes->len; |
29664b2a PP |
244 | } |
245 | ||
7b33a0e0 PP |
246 | struct bt_event_class *bt_stream_class_borrow_event_class_by_index( |
247 | struct bt_stream_class *stream_class, uint64_t index) | |
0d23acbe | 248 | { |
fa6cfec3 PP |
249 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
250 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, stream_class->event_classes->len); | |
7b33a0e0 | 251 | return g_ptr_array_index(stream_class->event_classes, index); |
0d23acbe PP |
252 | } |
253 | ||
78cf9df6 PP |
254 | const struct bt_event_class * |
255 | bt_stream_class_borrow_event_class_by_index_const( | |
256 | const struct bt_stream_class *stream_class, uint64_t index) | |
9e550e5f | 257 | { |
78cf9df6 | 258 | return bt_stream_class_borrow_event_class_by_index( |
9e550e5f PP |
259 | (void *) stream_class, index); |
260 | } | |
261 | ||
7b33a0e0 | 262 | struct bt_event_class *bt_stream_class_borrow_event_class_by_id( |
9e550e5f | 263 | struct bt_stream_class *stream_class, uint64_t id) |
11b0cdc8 | 264 | { |
7b33a0e0 PP |
265 | struct bt_event_class *event_class = NULL; |
266 | uint64_t i; | |
0b9ce69f | 267 | |
fa6cfec3 | 268 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
11b0cdc8 | 269 | |
9e550e5f | 270 | for (i = 0; i < stream_class->event_classes->len; i++) { |
7b33a0e0 | 271 | struct bt_event_class *event_class_candidate = |
9e550e5f | 272 | g_ptr_array_index(stream_class->event_classes, i); |
e6a8e8e4 | 273 | |
7b33a0e0 PP |
274 | if (event_class_candidate->id == id) { |
275 | event_class = event_class_candidate; | |
09840de5 PP |
276 | goto end; |
277 | } | |
69dc4535 JG |
278 | } |
279 | ||
69dc4535 | 280 | end: |
7b33a0e0 | 281 | return event_class; |
0863f950 PP |
282 | } |
283 | ||
78cf9df6 PP |
284 | const struct bt_event_class * |
285 | bt_stream_class_borrow_event_class_by_id_const( | |
286 | const struct bt_stream_class *stream_class, uint64_t id) | |
9e550e5f | 287 | { |
78cf9df6 | 288 | return bt_stream_class_borrow_event_class_by_id( |
9e550e5f PP |
289 | (void *) stream_class, id); |
290 | } | |
291 | ||
78cf9df6 PP |
292 | const struct bt_field_class * |
293 | bt_stream_class_borrow_packet_context_field_class_const( | |
294 | const struct bt_stream_class *stream_class) | |
12c8a1a3 | 295 | { |
fa6cfec3 | 296 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
939190b3 | 297 | return stream_class->packet_context_fc; |
12c8a1a3 JG |
298 | } |
299 | ||
909d0a89 PP |
300 | struct bt_field_class * |
301 | bt_stream_class_borrow_packet_context_field_class( | |
302 | struct bt_stream_class *stream_class) | |
303 | { | |
fa6cfec3 | 304 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
909d0a89 PP |
305 | return stream_class->packet_context_fc; |
306 | } | |
307 | ||
fb25b9e3 PP |
308 | enum bt_stream_class_set_field_class_status |
309 | bt_stream_class_set_packet_context_field_class( | |
78cf9df6 PP |
310 | struct bt_stream_class *stream_class, |
311 | struct bt_field_class *field_class) | |
12c8a1a3 | 312 | { |
7b33a0e0 PP |
313 | int ret; |
314 | struct bt_resolve_field_path_context resolve_ctx = { | |
939190b3 | 315 | .packet_context = field_class, |
7b33a0e0 PP |
316 | .event_common_context = NULL, |
317 | .event_specific_context = NULL, | |
318 | .event_payload = NULL, | |
319 | }; | |
18acc6f8 | 320 | |
7c7324d3 | 321 | BT_ASSERT_PRE_NO_ERROR(); |
7b33a0e0 | 322 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
37a93d41 PP |
323 | BT_ASSERT_PRE(stream_class->supports_packets, |
324 | "Stream class does not support packets: %![sc-]+S", | |
325 | stream_class); | |
939190b3 | 326 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
fa6cfec3 | 327 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
af0c18e3 PP |
328 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
329 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
66fd07a5 | 330 | "Packet context field class is not a structure field class: %!+F", |
939190b3 | 331 | field_class); |
939190b3 | 332 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
7b33a0e0 | 333 | if (ret) { |
36a28778 PP |
334 | /* |
335 | * This is the only reason for which | |
336 | * bt_resolve_field_paths() can fail: anything else | |
337 | * would be because a precondition is not satisfied. | |
338 | */ | |
fb25b9e3 | 339 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
18acc6f8 PP |
340 | goto end; |
341 | } | |
342 | ||
10b7a2e4 | 343 | bt_field_class_make_part_of_trace_class(field_class); |
8138bfe1 | 344 | bt_object_put_ref(stream_class->packet_context_fc); |
4b70020d | 345 | stream_class->packet_context_fc = field_class; |
864aa43f | 346 | bt_object_get_ref_no_null_check(stream_class->packet_context_fc); |
939190b3 | 347 | bt_field_class_freeze(field_class); |
a684a357 | 348 | BT_LIB_LOGD("Set stream class's packet context field class: %!+S", |
7b33a0e0 | 349 | stream_class); |
18acc6f8 PP |
350 | |
351 | end: | |
352 | return ret; | |
12c8a1a3 JG |
353 | } |
354 | ||
78cf9df6 PP |
355 | const struct bt_field_class * |
356 | bt_stream_class_borrow_event_common_context_field_class_const( | |
357 | const struct bt_stream_class *stream_class) | |
af181248 | 358 | { |
fa6cfec3 | 359 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
939190b3 | 360 | return stream_class->event_common_context_fc; |
af181248 JG |
361 | } |
362 | ||
909d0a89 PP |
363 | struct bt_field_class * |
364 | bt_stream_class_borrow_event_common_context_field_class( | |
365 | struct bt_stream_class *stream_class) | |
366 | { | |
fa6cfec3 | 367 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
909d0a89 PP |
368 | return stream_class->event_common_context_fc; |
369 | } | |
370 | ||
fb25b9e3 | 371 | enum bt_stream_class_set_field_class_status |
36a28778 | 372 | bt_stream_class_set_event_common_context_field_class( |
78cf9df6 PP |
373 | struct bt_stream_class *stream_class, |
374 | struct bt_field_class *field_class) | |
af181248 | 375 | { |
7b33a0e0 PP |
376 | int ret; |
377 | struct bt_resolve_field_path_context resolve_ctx = { | |
7b33a0e0 | 378 | .packet_context = NULL, |
939190b3 | 379 | .event_common_context = field_class, |
7b33a0e0 PP |
380 | .event_specific_context = NULL, |
381 | .event_payload = NULL, | |
382 | }; | |
18acc6f8 | 383 | |
7c7324d3 | 384 | BT_ASSERT_PRE_NO_ERROR(); |
7b33a0e0 | 385 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 386 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
fa6cfec3 | 387 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
af0c18e3 PP |
388 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
389 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
66fd07a5 | 390 | "Event common context field class is not a structure field class: %!+F", |
939190b3 | 391 | field_class); |
939190b3 | 392 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
939190b3 | 393 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
7b33a0e0 | 394 | if (ret) { |
36a28778 PP |
395 | /* |
396 | * This is the only reason for which | |
397 | * bt_resolve_field_paths() can fail: anything else | |
398 | * would be because a precondition is not satisfied. | |
399 | */ | |
fb25b9e3 | 400 | ret = BT_FUNC_STATUS_MEMORY_ERROR; |
18acc6f8 PP |
401 | goto end; |
402 | } | |
403 | ||
10b7a2e4 | 404 | bt_field_class_make_part_of_trace_class(field_class); |
8138bfe1 | 405 | bt_object_put_ref(stream_class->event_common_context_fc); |
4b70020d | 406 | stream_class->event_common_context_fc = field_class; |
864aa43f | 407 | bt_object_get_ref_no_null_check(stream_class->event_common_context_fc); |
939190b3 | 408 | bt_field_class_freeze(field_class); |
a684a357 | 409 | BT_LIB_LOGD("Set stream class's event common context field class: %!+S", |
7b33a0e0 | 410 | stream_class); |
18acc6f8 | 411 | |
18acc6f8 PP |
412 | end: |
413 | return ret; | |
11b0cdc8 JG |
414 | } |
415 | ||
7b33a0e0 | 416 | BT_HIDDEN |
78cf9df6 | 417 | void _bt_stream_class_freeze(const struct bt_stream_class *stream_class) |
8bf65fbd | 418 | { |
939190b3 | 419 | /* The field classes and default clock class are already frozen */ |
7b33a0e0 | 420 | BT_ASSERT(stream_class); |
af90138b PP |
421 | BT_LIB_LOGD("Freezing stream class's user attributes: %!+v", |
422 | stream_class->user_attributes); | |
423 | bt_value_freeze(stream_class->user_attributes); | |
7b33a0e0 | 424 | BT_LIB_LOGD("Freezing stream class: %!+S", stream_class); |
78cf9df6 | 425 | ((struct bt_stream_class *) stream_class)->frozen = true; |
8bf65fbd JG |
426 | } |
427 | ||
fb25b9e3 PP |
428 | enum bt_stream_class_set_default_clock_class_status |
429 | bt_stream_class_set_default_clock_class( | |
78cf9df6 | 430 | struct bt_stream_class *stream_class, |
7b33a0e0 | 431 | struct bt_clock_class *clock_class) |
8bf65fbd | 432 | { |
7c7324d3 | 433 | BT_ASSERT_PRE_NO_ERROR(); |
7b33a0e0 PP |
434 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
435 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
fa6cfec3 | 436 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
8138bfe1 | 437 | bt_object_put_ref(stream_class->default_clock_class); |
4b70020d | 438 | stream_class->default_clock_class = clock_class; |
864aa43f | 439 | bt_object_get_ref_no_null_check(stream_class->default_clock_class); |
7b33a0e0 | 440 | bt_clock_class_freeze(clock_class); |
a684a357 | 441 | BT_LIB_LOGD("Set stream class's default clock class: %!+S", |
7b33a0e0 | 442 | stream_class); |
fb25b9e3 | 443 | return BT_FUNC_STATUS_OK; |
8bf65fbd JG |
444 | } |
445 | ||
7b33a0e0 PP |
446 | struct bt_clock_class *bt_stream_class_borrow_default_clock_class( |
447 | struct bt_stream_class *stream_class) | |
8bf65fbd | 448 | { |
fa6cfec3 | 449 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 PP |
450 | return stream_class->default_clock_class; |
451 | } | |
8bf65fbd | 452 | |
78cf9df6 PP |
453 | const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const( |
454 | const struct bt_stream_class *stream_class) | |
455 | { | |
fa6cfec3 | 456 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
78cf9df6 PP |
457 | return stream_class->default_clock_class; |
458 | } | |
459 | ||
7b33a0e0 | 460 | bt_bool bt_stream_class_assigns_automatic_event_class_id( |
78cf9df6 | 461 | const struct bt_stream_class *stream_class) |
7b33a0e0 | 462 | { |
fa6cfec3 | 463 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 | 464 | return (bt_bool) stream_class->assigns_automatic_event_class_id; |
8bf65fbd JG |
465 | } |
466 | ||
78cf9df6 PP |
467 | void bt_stream_class_set_assigns_automatic_event_class_id( |
468 | struct bt_stream_class *stream_class, | |
9e550e5f | 469 | bt_bool value) |
8bf65fbd | 470 | { |
7b33a0e0 | 471 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
fa6cfec3 | 472 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
7b33a0e0 | 473 | stream_class->assigns_automatic_event_class_id = (bool) value; |
a684a357 | 474 | BT_LIB_LOGD("Set stream class's automatic event class ID " |
7b33a0e0 | 475 | "assignment property: %!+S", stream_class); |
7b33a0e0 | 476 | } |
8bf65fbd | 477 | |
7b33a0e0 | 478 | bt_bool bt_stream_class_assigns_automatic_stream_id( |
78cf9df6 | 479 | const struct bt_stream_class *stream_class) |
7b33a0e0 | 480 | { |
fa6cfec3 | 481 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 PP |
482 | return (bt_bool) stream_class->assigns_automatic_stream_id; |
483 | } | |
8bf65fbd | 484 | |
77037b2b PP |
485 | void bt_stream_class_set_supports_discarded_events( |
486 | struct bt_stream_class *stream_class, | |
487 | bt_bool supports_discarded_events, | |
488 | bt_bool with_default_clock_snapshots) | |
489 | { | |
490 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
fa6cfec3 | 491 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
77037b2b PP |
492 | BT_ASSERT_PRE(supports_discarded_events || |
493 | !with_default_clock_snapshots, | |
494 | "Discarded events cannot have default clock snapshots when " | |
495 | "not supported: %!+S", stream_class); | |
496 | BT_ASSERT_PRE(!with_default_clock_snapshots || | |
497 | stream_class->default_clock_class, | |
498 | "Stream class has no default clock class: %!+S", stream_class); | |
499 | stream_class->supports_discarded_events = | |
500 | (bool) supports_discarded_events; | |
501 | stream_class->discarded_events_have_default_clock_snapshots = | |
502 | (bool) with_default_clock_snapshots; | |
a684a357 | 503 | BT_LIB_LOGD("Set stream class's discarded events support property: " |
77037b2b PP |
504 | "%!+S", stream_class); |
505 | } | |
506 | ||
507 | bt_bool bt_stream_class_supports_discarded_events( | |
508 | const struct bt_stream_class *stream_class) | |
509 | { | |
fa6cfec3 | 510 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
77037b2b PP |
511 | return (bt_bool) stream_class->supports_discarded_events; |
512 | } | |
513 | ||
514 | bt_bool bt_stream_class_discarded_events_have_default_clock_snapshots( | |
515 | const struct bt_stream_class *stream_class) | |
516 | { | |
fa6cfec3 | 517 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
77037b2b PP |
518 | return (bt_bool) stream_class->discarded_events_have_default_clock_snapshots; |
519 | } | |
520 | ||
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 | { | |
526 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
fa6cfec3 | 527 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
37a93d41 PP |
528 | BT_ASSERT_PRE(!supports_discarded_packets || |
529 | stream_class->supports_packets, | |
530 | "Stream class does not support packets: %!+S", | |
531 | stream_class); | |
77037b2b PP |
532 | BT_ASSERT_PRE(supports_discarded_packets || |
533 | !with_default_clock_snapshots, | |
534 | "Discarded packets cannot have default clock snapshots when " | |
535 | "not supported: %!+S", stream_class); | |
536 | BT_ASSERT_PRE(!with_default_clock_snapshots || | |
537 | stream_class->default_clock_class, | |
538 | "Stream class has no default clock class: %!+S", stream_class); | |
539 | stream_class->supports_discarded_packets = | |
540 | (bool) supports_discarded_packets; | |
541 | stream_class->discarded_packets_have_default_clock_snapshots = | |
542 | (bool) with_default_clock_snapshots; | |
a684a357 | 543 | BT_LIB_LOGD("Set stream class's discarded packets support property: " |
77037b2b PP |
544 | "%!+S", stream_class); |
545 | } | |
546 | ||
547 | bt_bool bt_stream_class_supports_discarded_packets( | |
548 | const struct bt_stream_class *stream_class) | |
549 | { | |
fa6cfec3 | 550 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
77037b2b PP |
551 | return (bt_bool) stream_class->supports_discarded_packets; |
552 | } | |
553 | ||
554 | bt_bool bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
555 | const struct bt_stream_class *stream_class) | |
556 | { | |
fa6cfec3 | 557 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
77037b2b PP |
558 | return (bt_bool) stream_class->discarded_packets_have_default_clock_snapshots; |
559 | } | |
560 | ||
37a93d41 PP |
561 | void bt_stream_class_set_supports_packets( |
562 | struct bt_stream_class *stream_class, | |
563 | bt_bool supports_packets, | |
564 | bt_bool with_beginning_default_clock_snapshot, | |
565 | bt_bool with_end_default_clock_snapshot) | |
566 | { | |
567 | bt_bool with_default_clock_snapshot = | |
568 | with_beginning_default_clock_snapshot || | |
569 | with_end_default_clock_snapshot; | |
570 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
fa6cfec3 | 571 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
37a93d41 PP |
572 | BT_ASSERT_PRE(supports_packets || |
573 | !with_default_clock_snapshot, | |
574 | "Packets cannot have default clock snapshots when " | |
575 | "not supported: %!+S", stream_class); | |
576 | BT_ASSERT_PRE(!with_default_clock_snapshot || | |
577 | stream_class->default_clock_class, | |
578 | "Stream class has no default clock class: %!+S", stream_class); | |
579 | BT_ASSERT_PRE(supports_packets || !stream_class->packet_context_fc, | |
580 | "Stream class already has a packet context field class: %!+S", | |
581 | stream_class); | |
582 | BT_ASSERT_PRE(supports_packets || | |
583 | !stream_class->supports_discarded_packets, | |
584 | "Stream class already supports discarded packets: %!+S", | |
585 | stream_class); | |
586 | stream_class->supports_packets = (bool) supports_packets; | |
587 | stream_class->packets_have_beginning_default_clock_snapshot = | |
588 | (bool) with_beginning_default_clock_snapshot; | |
589 | stream_class->packets_have_end_default_clock_snapshot = | |
590 | (bool) with_end_default_clock_snapshot; | |
591 | BT_LIB_LOGD("Set stream class's packets support property: %!+S", | |
592 | stream_class); | |
593 | } | |
594 | ||
595 | bt_bool bt_stream_class_supports_packets( | |
596 | const struct bt_stream_class *stream_class) | |
597 | { | |
598 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
599 | return (bt_bool) stream_class->supports_packets; | |
600 | } | |
601 | ||
602 | bt_bool bt_stream_class_packets_have_beginning_default_clock_snapshot( | |
603 | const struct bt_stream_class *stream_class) | |
604 | { | |
fa6cfec3 | 605 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
37a93d41 PP |
606 | return (bt_bool) stream_class->packets_have_beginning_default_clock_snapshot; |
607 | } | |
608 | ||
609 | bt_bool bt_stream_class_packets_have_end_default_clock_snapshot( | |
610 | const struct bt_stream_class *stream_class) | |
611 | { | |
fa6cfec3 | 612 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); |
37a93d41 PP |
613 | return (bt_bool) stream_class->packets_have_end_default_clock_snapshot; |
614 | } | |
615 | ||
78cf9df6 PP |
616 | void bt_stream_class_set_assigns_automatic_stream_id( |
617 | struct bt_stream_class *stream_class, | |
9e550e5f | 618 | bt_bool value) |
7b33a0e0 PP |
619 | { |
620 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
fa6cfec3 | 621 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); |
7b33a0e0 | 622 | stream_class->assigns_automatic_stream_id = (bool) value; |
a684a357 | 623 | BT_LIB_LOGD("Set stream class's automatic stream ID " |
7b33a0e0 | 624 | "assignment property: %!+S", stream_class); |
7b33a0e0 | 625 | } |
8deee039 | 626 | |
af90138b PP |
627 | const struct bt_value *bt_stream_class_borrow_user_attributes_const( |
628 | const struct bt_stream_class *stream_class) | |
629 | { | |
630 | BT_ASSERT_PRE_DEV_NON_NULL(stream_class, "Stream class"); | |
631 | return stream_class->user_attributes; | |
632 | } | |
633 | ||
634 | struct bt_value *bt_stream_class_borrow_user_attributes( | |
635 | struct bt_stream_class *stream_class) | |
636 | { | |
637 | return (void *) bt_stream_class_borrow_user_attributes_const( | |
638 | (void *) stream_class); | |
639 | } | |
640 | ||
641 | void bt_stream_class_set_user_attributes( | |
642 | struct bt_stream_class *stream_class, | |
643 | const struct bt_value *user_attributes) | |
644 | { | |
645 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
646 | BT_ASSERT_PRE_NON_NULL(user_attributes, "User attributes"); | |
647 | BT_ASSERT_PRE(user_attributes->type == BT_VALUE_TYPE_MAP, | |
648 | "User attributes object is not a map value object."); | |
649 | BT_ASSERT_PRE_DEV_STREAM_CLASS_HOT(stream_class); | |
864aa43f | 650 | bt_object_put_ref_no_null_check(stream_class->user_attributes); |
af90138b | 651 | stream_class->user_attributes = (void *) user_attributes; |
864aa43f | 652 | bt_object_get_ref_no_null_check(stream_class->user_attributes); |
af90138b PP |
653 | } |
654 | ||
8c6884d9 PP |
655 | void bt_stream_class_get_ref(const struct bt_stream_class *stream_class) |
656 | { | |
657 | bt_object_get_ref(stream_class); | |
658 | } | |
659 | ||
660 | void bt_stream_class_put_ref(const struct bt_stream_class *stream_class) | |
661 | { | |
662 | bt_object_put_ref(stream_class); | |
663 | } |