Commit | Line | Data |
---|---|---|
11b0cdc8 | 1 | /* |
e2f7325d | 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 | ||
d2f71f12 PP |
24 | #define BT_LOG_TAG "STREAM-CLASS" |
25 | #include <babeltrace/lib-logging-internal.h> | |
26 | ||
3dca2276 | 27 | #include <babeltrace/assert-pre-internal.h> |
56e18c4c PP |
28 | #include <babeltrace/trace-ir/clock-class-internal.h> |
29 | #include <babeltrace/trace-ir/event-class-internal.h> | |
c6bd8523 PP |
30 | #include <babeltrace/trace-ir/field-class-internal.h> |
31 | #include <babeltrace/trace-ir/field-internal.h> | |
56e18c4c | 32 | #include <babeltrace/trace-ir/stream-class-internal.h> |
40f4ba76 | 33 | #include <babeltrace/trace-ir/trace-const.h> |
e5be10ef | 34 | #include <babeltrace/trace-ir/trace-internal.h> |
56e18c4c PP |
35 | #include <babeltrace/trace-ir/utils-internal.h> |
36 | #include <babeltrace/trace-ir/field-wrapper-internal.h> | |
37 | #include <babeltrace/trace-ir/resolve-field-path-internal.h> | |
65300d60 | 38 | #include <babeltrace/object.h> |
3d9990ac PP |
39 | #include <babeltrace/compiler-internal.h> |
40 | #include <babeltrace/align-internal.h> | |
41 | #include <babeltrace/endian-internal.h> | |
f6ccaed9 | 42 | #include <babeltrace/assert-internal.h> |
44c440bc | 43 | #include <babeltrace/property-internal.h> |
dc3fffef | 44 | #include <inttypes.h> |
544d0515 | 45 | #include <stdint.h> |
e011d2c1 | 46 | #include <stdbool.h> |
11b0cdc8 | 47 | |
44c440bc PP |
48 | #define BT_ASSERT_PRE_STREAM_CLASS_HOT(_sc) \ |
49 | BT_ASSERT_PRE_HOT((_sc), "Stream class", ": %!+S", (_sc)) | |
142c5610 | 50 | |
cb6f1f7d | 51 | static |
44c440bc | 52 | void destroy_stream_class(struct bt_object *obj) |
3ea33115 | 53 | { |
cb6f1f7d PP |
54 | struct bt_stream_class *stream_class = (void *) obj; |
55 | ||
44c440bc PP |
56 | BT_LIB_LOGD("Destroying stream class: %!+S", stream_class); |
57 | BT_LOGD_STR("Putting default clock class."); | |
238b7404 | 58 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->default_clock_class); |
3ea33115 | 59 | |
3dca2276 PP |
60 | if (stream_class->event_classes) { |
61 | BT_LOGD_STR("Destroying event classes."); | |
62 | g_ptr_array_free(stream_class->event_classes, TRUE); | |
238b7404 | 63 | stream_class->event_classes = NULL; |
d2f71f12 PP |
64 | } |
65 | ||
44c440bc PP |
66 | if (stream_class->name.str) { |
67 | g_string_free(stream_class->name.str, TRUE); | |
238b7404 PP |
68 | stream_class->name.str = NULL; |
69 | stream_class->name.value = NULL; | |
3ea33115 JG |
70 | } |
71 | ||
e6276565 | 72 | BT_LOGD_STR("Putting event header field class."); |
238b7404 | 73 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_header_fc); |
e6276565 | 74 | BT_LOGD_STR("Putting packet context field class."); |
238b7404 | 75 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); |
e6276565 | 76 | BT_LOGD_STR("Putting event common context field class."); |
238b7404 | 77 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_common_context_fc); |
312c056a PP |
78 | bt_object_pool_finalize(&stream_class->event_header_field_pool); |
79 | bt_object_pool_finalize(&stream_class->packet_context_field_pool); | |
3dca2276 | 80 | g_free(stream_class); |
3ea33115 JG |
81 | } |
82 | ||
312c056a 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 | ||
44c440bc PP |
90 | BT_ASSERT_PRE_FUNC |
91 | static | |
862ca4ed | 92 | bool stream_class_id_is_unique(const struct bt_trace_class *tc, uint64_t id) |
44c440bc PP |
93 | { |
94 | uint64_t i; | |
95 | bool is_unique = true; | |
96 | ||
862ca4ed | 97 | for (i = 0; i < tc->stream_classes->len; i++) { |
40f4ba76 | 98 | const struct bt_stream_class *sc = |
862ca4ed | 99 | tc->stream_classes->pdata[i]; |
44c440bc PP |
100 | |
101 | if (sc->id == id) { | |
102 | is_unique = false; | |
103 | goto end; | |
104 | } | |
105 | } | |
106 | ||
107 | end: | |
108 | return is_unique; | |
109 | } | |
110 | ||
111 | static | |
862ca4ed PP |
112 | struct bt_stream_class *create_stream_class_with_id( |
113 | struct bt_trace_class *tc, uint64_t id) | |
2f100782 | 114 | { |
3dca2276 PP |
115 | struct bt_stream_class *stream_class = NULL; |
116 | int ret; | |
2f100782 | 117 | |
862ca4ed PP |
118 | BT_ASSERT(tc); |
119 | BT_ASSERT_PRE(stream_class_id_is_unique(tc, id), | |
120 | "Duplicate stream class ID: %![tc-]+T, id=%" PRIu64, tc, id); | |
121 | BT_LIB_LOGD("Creating stream class object: %![tc-]+T, id=%" PRIu64, | |
122 | tc, id); | |
3dca2276 | 123 | stream_class = g_new0(struct bt_stream_class, 1); |
d2f71f12 | 124 | if (!stream_class) { |
3dca2276 PP |
125 | BT_LOGE_STR("Failed to allocate one stream class."); |
126 | goto error; | |
d2f71f12 PP |
127 | } |
128 | ||
44c440bc PP |
129 | bt_object_init_shared_with_parent(&stream_class->base, |
130 | destroy_stream_class); | |
131 | ||
132 | stream_class->name.str = g_string_new(NULL); | |
133 | if (!stream_class->name.str) { | |
134 | BT_LOGE_STR("Failed to allocate a GString."); | |
135 | ret = -1; | |
136 | goto end; | |
137 | } | |
138 | ||
139 | stream_class->id = id; | |
140 | stream_class->assigns_automatic_event_class_id = true; | |
141 | stream_class->assigns_automatic_stream_id = true; | |
142 | stream_class->event_classes = g_ptr_array_new_with_free_func( | |
143 | (GDestroyNotify) bt_object_try_spec_release); | |
144 | if (!stream_class->event_classes) { | |
145 | BT_LOGE_STR("Failed to allocate a GPtrArray."); | |
3dca2276 | 146 | goto error; |
2f100782 JG |
147 | } |
148 | ||
312c056a PP |
149 | ret = bt_object_pool_initialize(&stream_class->event_header_field_pool, |
150 | (bt_object_pool_new_object_func) bt_field_wrapper_new, | |
151 | (bt_object_pool_destroy_object_func) free_field_wrapper, | |
152 | stream_class); | |
153 | if (ret) { | |
154 | BT_LOGE("Failed to initialize event header field pool: ret=%d", | |
155 | ret); | |
156 | goto error; | |
157 | } | |
158 | ||
159 | ret = bt_object_pool_initialize(&stream_class->packet_context_field_pool, | |
160 | (bt_object_pool_new_object_func) bt_field_wrapper_new, | |
161 | (bt_object_pool_destroy_object_func) free_field_wrapper, | |
162 | stream_class); | |
163 | if (ret) { | |
164 | BT_LOGE("Failed to initialize packet context field pool: ret=%d", | |
165 | ret); | |
166 | goto error; | |
167 | } | |
168 | ||
862ca4ed PP |
169 | bt_object_set_parent(&stream_class->base, &tc->base); |
170 | g_ptr_array_add(tc->stream_classes, stream_class); | |
171 | bt_trace_class_freeze(tc); | |
44c440bc | 172 | BT_LIB_LOGD("Created stream class object: %!+S", stream_class); |
312c056a PP |
173 | goto end; |
174 | ||
175 | error: | |
65300d60 | 176 | BT_OBJECT_PUT_REF_AND_RESET(stream_class); |
312c056a PP |
177 | |
178 | end: | |
44c440bc | 179 | return stream_class; |
312c056a PP |
180 | } |
181 | ||
862ca4ed | 182 | struct bt_stream_class *bt_stream_class_create(struct bt_trace_class *tc) |
312c056a | 183 | { |
862ca4ed PP |
184 | BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); |
185 | BT_ASSERT_PRE(tc->assigns_automatic_stream_class_id, | |
186 | "Trace class does not automatically assigns stream class IDs: " | |
187 | "%![sc-]+T", tc); | |
188 | return create_stream_class_with_id(tc, | |
189 | (uint64_t) tc->stream_classes->len); | |
44c440bc | 190 | } |
312c056a | 191 | |
40f4ba76 | 192 | struct bt_stream_class *bt_stream_class_create_with_id( |
862ca4ed | 193 | struct bt_trace_class *tc, uint64_t id) |
44c440bc | 194 | { |
862ca4ed PP |
195 | BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); |
196 | BT_ASSERT_PRE(!tc->assigns_automatic_stream_class_id, | |
197 | "Trace class automatically assigns stream class IDs: " | |
198 | "%![sc-]+T", tc); | |
199 | return create_stream_class_with_id(tc, id); | |
312c056a PP |
200 | } |
201 | ||
862ca4ed | 202 | struct bt_trace_class *bt_stream_class_borrow_trace_class( |
40f4ba76 | 203 | struct bt_stream_class *stream_class) |
11b0cdc8 | 204 | { |
44c440bc | 205 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
862ca4ed | 206 | return bt_stream_class_borrow_trace_class_inline(stream_class); |
11b0cdc8 JG |
207 | } |
208 | ||
862ca4ed | 209 | const struct bt_trace_class *bt_stream_class_borrow_trace_class_const( |
40f4ba76 | 210 | const struct bt_stream_class *stream_class) |
e5be10ef | 211 | { |
862ca4ed | 212 | return bt_stream_class_borrow_trace_class((void *) stream_class); |
e5be10ef PP |
213 | } |
214 | ||
40f4ba76 | 215 | const char *bt_stream_class_get_name(const struct bt_stream_class *stream_class) |
2f100782 | 216 | { |
cb6f1f7d | 217 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
44c440bc | 218 | return stream_class->name.value; |
2f100782 JG |
219 | } |
220 | ||
40f4ba76 PP |
221 | int bt_stream_class_set_name( |
222 | struct bt_stream_class *stream_class, | |
3dca2276 | 223 | const char *name) |
5ca83563 | 224 | { |
44c440bc PP |
225 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
226 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
227 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
228 | g_string_assign(stream_class->name.str, name); | |
229 | stream_class->name.value = stream_class->name.str->str; | |
230 | BT_LIB_LOGV("Set stream class's name: %!+S", stream_class); | |
231 | return 0; | |
5ca83563 JG |
232 | } |
233 | ||
40f4ba76 | 234 | uint64_t bt_stream_class_get_id(const struct bt_stream_class *stream_class) |
2f100782 | 235 | { |
cb6f1f7d | 236 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
44c440bc | 237 | return stream_class->id; |
2f100782 JG |
238 | } |
239 | ||
44c440bc | 240 | uint64_t bt_stream_class_get_event_class_count( |
40f4ba76 | 241 | const struct bt_stream_class *stream_class) |
29664b2a | 242 | { |
44c440bc PP |
243 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
244 | return (uint64_t) stream_class->event_classes->len; | |
29664b2a PP |
245 | } |
246 | ||
44c440bc PP |
247 | struct bt_event_class *bt_stream_class_borrow_event_class_by_index( |
248 | struct bt_stream_class *stream_class, uint64_t index) | |
0d23acbe | 249 | { |
44c440bc PP |
250 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
251 | BT_ASSERT_PRE_VALID_INDEX(index, stream_class->event_classes->len); | |
252 | return g_ptr_array_index(stream_class->event_classes, index); | |
0d23acbe PP |
253 | } |
254 | ||
40f4ba76 PP |
255 | const struct bt_event_class * |
256 | bt_stream_class_borrow_event_class_by_index_const( | |
257 | const struct bt_stream_class *stream_class, uint64_t index) | |
e5be10ef | 258 | { |
40f4ba76 | 259 | return bt_stream_class_borrow_event_class_by_index( |
e5be10ef PP |
260 | (void *) stream_class, index); |
261 | } | |
262 | ||
44c440bc | 263 | struct bt_event_class *bt_stream_class_borrow_event_class_by_id( |
e5be10ef | 264 | struct bt_stream_class *stream_class, uint64_t id) |
11b0cdc8 | 265 | { |
44c440bc PP |
266 | struct bt_event_class *event_class = NULL; |
267 | uint64_t i; | |
0b9ce69f | 268 | |
862ca4ed | 269 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
11b0cdc8 | 270 | |
e5be10ef | 271 | for (i = 0; i < stream_class->event_classes->len; i++) { |
44c440bc | 272 | struct bt_event_class *event_class_candidate = |
e5be10ef | 273 | g_ptr_array_index(stream_class->event_classes, i); |
e6a8e8e4 | 274 | |
44c440bc PP |
275 | if (event_class_candidate->id == id) { |
276 | event_class = event_class_candidate; | |
09840de5 PP |
277 | goto end; |
278 | } | |
69dc4535 JG |
279 | } |
280 | ||
69dc4535 | 281 | end: |
44c440bc | 282 | return event_class; |
0863f950 PP |
283 | } |
284 | ||
40f4ba76 PP |
285 | const struct bt_event_class * |
286 | bt_stream_class_borrow_event_class_by_id_const( | |
287 | const struct bt_stream_class *stream_class, uint64_t id) | |
e5be10ef | 288 | { |
40f4ba76 | 289 | return bt_stream_class_borrow_event_class_by_id( |
e5be10ef PP |
290 | (void *) stream_class, id); |
291 | } | |
292 | ||
40f4ba76 PP |
293 | const struct bt_field_class * |
294 | bt_stream_class_borrow_packet_context_field_class_const( | |
295 | const struct bt_stream_class *stream_class) | |
12c8a1a3 | 296 | { |
cb6f1f7d | 297 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 298 | return stream_class->packet_context_fc; |
12c8a1a3 JG |
299 | } |
300 | ||
40f4ba76 PP |
301 | int bt_stream_class_set_packet_context_field_class( |
302 | struct bt_stream_class *stream_class, | |
303 | struct bt_field_class *field_class) | |
12c8a1a3 | 304 | { |
44c440bc PP |
305 | int ret; |
306 | struct bt_resolve_field_path_context resolve_ctx = { | |
307 | .packet_header = NULL, | |
5cd6d0e5 | 308 | .packet_context = field_class, |
44c440bc PP |
309 | .event_header = NULL, |
310 | .event_common_context = NULL, | |
311 | .event_specific_context = NULL, | |
312 | .event_payload = NULL, | |
313 | }; | |
cb6f1f7d | 314 | |
44c440bc | 315 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 316 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
44c440bc | 317 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
864cad70 PP |
318 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
319 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 320 | "Packet context field class is not a structure field class: %!+F", |
5cd6d0e5 | 321 | field_class); |
44c440bc | 322 | resolve_ctx.packet_header = |
862ca4ed | 323 | bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc; |
5cd6d0e5 | 324 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); |
44c440bc | 325 | if (ret) { |
cb6f1f7d PP |
326 | goto end; |
327 | } | |
328 | ||
862ca4ed | 329 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 330 | bt_object_put_ref(stream_class->packet_context_fc); |
398454ed PP |
331 | stream_class->packet_context_fc = field_class; |
332 | bt_object_get_no_null_check(stream_class->packet_context_fc); | |
5cd6d0e5 | 333 | bt_field_class_freeze(field_class); |
e6276565 | 334 | BT_LIB_LOGV("Set stream class's packet context field class: %!+S", |
44c440bc | 335 | stream_class); |
cb6f1f7d PP |
336 | |
337 | end: | |
338 | return ret; | |
12c8a1a3 JG |
339 | } |
340 | ||
40f4ba76 PP |
341 | const struct bt_field_class *bt_stream_class_borrow_event_header_field_class_const( |
342 | const struct bt_stream_class *stream_class) | |
662e778c | 343 | { |
cb6f1f7d | 344 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 345 | return stream_class->event_header_fc; |
662e778c JG |
346 | } |
347 | ||
40f4ba76 PP |
348 | int bt_stream_class_set_event_header_field_class( |
349 | struct bt_stream_class *stream_class, | |
350 | struct bt_field_class *field_class) | |
662e778c | 351 | { |
44c440bc PP |
352 | int ret; |
353 | struct bt_resolve_field_path_context resolve_ctx = { | |
354 | .packet_header = NULL, | |
355 | .packet_context = NULL, | |
5cd6d0e5 | 356 | .event_header = field_class, |
44c440bc PP |
357 | .event_common_context = NULL, |
358 | .event_specific_context = NULL, | |
359 | .event_payload = NULL, | |
360 | }; | |
cb6f1f7d | 361 | |
44c440bc | 362 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 363 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
44c440bc | 364 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
864cad70 PP |
365 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
366 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 367 | "Event header field class is not a structure field class: %!+F", |
5cd6d0e5 | 368 | field_class); |
44c440bc | 369 | resolve_ctx.packet_header = |
862ca4ed | 370 | bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc; |
5cd6d0e5 PP |
371 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
372 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
44c440bc | 373 | if (ret) { |
cb6f1f7d PP |
374 | goto end; |
375 | } | |
376 | ||
862ca4ed | 377 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 378 | bt_object_put_ref(stream_class->event_header_fc); |
398454ed PP |
379 | stream_class->event_header_fc = field_class; |
380 | bt_object_get_no_null_check(stream_class->event_header_fc); | |
5cd6d0e5 | 381 | bt_field_class_freeze(field_class); |
e6276565 | 382 | BT_LIB_LOGV("Set stream class's event header field class: %!+S", |
44c440bc | 383 | stream_class); |
cb6f1f7d | 384 | |
cb6f1f7d PP |
385 | end: |
386 | return ret; | |
662e778c JG |
387 | } |
388 | ||
40f4ba76 PP |
389 | const struct bt_field_class * |
390 | bt_stream_class_borrow_event_common_context_field_class_const( | |
391 | const struct bt_stream_class *stream_class) | |
af181248 | 392 | { |
cb6f1f7d | 393 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 394 | return stream_class->event_common_context_fc; |
af181248 JG |
395 | } |
396 | ||
40f4ba76 PP |
397 | int bt_stream_class_set_event_common_context_field_class( |
398 | struct bt_stream_class *stream_class, | |
399 | struct bt_field_class *field_class) | |
af181248 | 400 | { |
44c440bc PP |
401 | int ret; |
402 | struct bt_resolve_field_path_context resolve_ctx = { | |
403 | .packet_header = NULL, | |
404 | .packet_context = NULL, | |
405 | .event_header = NULL, | |
5cd6d0e5 | 406 | .event_common_context = field_class, |
44c440bc PP |
407 | .event_specific_context = NULL, |
408 | .event_payload = NULL, | |
409 | }; | |
cb6f1f7d | 410 | |
44c440bc | 411 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
5cd6d0e5 | 412 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
44c440bc | 413 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
864cad70 PP |
414 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
415 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
e6276565 | 416 | "Event common context field class is not a structure field class: %!+F", |
5cd6d0e5 | 417 | field_class); |
44c440bc | 418 | resolve_ctx.packet_header = |
862ca4ed | 419 | bt_stream_class_borrow_trace_class_inline(stream_class)->packet_header_fc; |
5cd6d0e5 PP |
420 | resolve_ctx.packet_context = stream_class->packet_context_fc; |
421 | resolve_ctx.event_header = stream_class->event_header_fc; | |
422 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
44c440bc | 423 | if (ret) { |
cb6f1f7d PP |
424 | goto end; |
425 | } | |
426 | ||
862ca4ed | 427 | bt_field_class_make_part_of_trace_class(field_class); |
65300d60 | 428 | bt_object_put_ref(stream_class->event_common_context_fc); |
398454ed PP |
429 | stream_class->event_common_context_fc = field_class; |
430 | bt_object_get_no_null_check(stream_class->event_common_context_fc); | |
5cd6d0e5 | 431 | bt_field_class_freeze(field_class); |
e6276565 | 432 | BT_LIB_LOGV("Set stream class's event common context field class: %!+S", |
44c440bc | 433 | stream_class); |
cb6f1f7d | 434 | |
cb6f1f7d PP |
435 | end: |
436 | return ret; | |
11b0cdc8 JG |
437 | } |
438 | ||
44c440bc | 439 | BT_HIDDEN |
40f4ba76 | 440 | void _bt_stream_class_freeze(const struct bt_stream_class *stream_class) |
8bf65fbd | 441 | { |
5cd6d0e5 | 442 | /* The field classes and default clock class are already frozen */ |
44c440bc PP |
443 | BT_ASSERT(stream_class); |
444 | BT_LIB_LOGD("Freezing stream class: %!+S", stream_class); | |
40f4ba76 | 445 | ((struct bt_stream_class *) stream_class)->frozen = true; |
8bf65fbd JG |
446 | } |
447 | ||
40f4ba76 PP |
448 | int bt_stream_class_set_default_clock_class( |
449 | struct bt_stream_class *stream_class, | |
44c440bc | 450 | struct bt_clock_class *clock_class) |
8bf65fbd | 451 | { |
44c440bc PP |
452 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
453 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
454 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
65300d60 | 455 | bt_object_put_ref(stream_class->default_clock_class); |
398454ed PP |
456 | stream_class->default_clock_class = clock_class; |
457 | bt_object_get_no_null_check(stream_class->default_clock_class); | |
44c440bc PP |
458 | bt_clock_class_freeze(clock_class); |
459 | BT_LIB_LOGV("Set stream class's default clock class: %!+S", | |
460 | stream_class); | |
461 | return 0; | |
8bf65fbd JG |
462 | } |
463 | ||
44c440bc PP |
464 | struct bt_clock_class *bt_stream_class_borrow_default_clock_class( |
465 | struct bt_stream_class *stream_class) | |
8bf65fbd | 466 | { |
44c440bc PP |
467 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
468 | return stream_class->default_clock_class; | |
469 | } | |
8bf65fbd | 470 | |
40f4ba76 PP |
471 | const struct bt_clock_class *bt_stream_class_borrow_default_clock_class_const( |
472 | const struct bt_stream_class *stream_class) | |
473 | { | |
474 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
475 | return stream_class->default_clock_class; | |
476 | } | |
477 | ||
44c440bc | 478 | bt_bool bt_stream_class_assigns_automatic_event_class_id( |
40f4ba76 | 479 | const struct bt_stream_class *stream_class) |
44c440bc PP |
480 | { |
481 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
482 | return (bt_bool) stream_class->assigns_automatic_event_class_id; | |
8bf65fbd JG |
483 | } |
484 | ||
40f4ba76 PP |
485 | void bt_stream_class_set_assigns_automatic_event_class_id( |
486 | struct bt_stream_class *stream_class, | |
e5be10ef | 487 | bt_bool value) |
8bf65fbd | 488 | { |
44c440bc PP |
489 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
490 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
491 | stream_class->assigns_automatic_event_class_id = (bool) value; | |
492 | BT_LIB_LOGV("Set stream class's automatic event class ID " | |
493 | "assignment property: %!+S", stream_class); | |
44c440bc | 494 | } |
8bf65fbd | 495 | |
44c440bc | 496 | bt_bool bt_stream_class_assigns_automatic_stream_id( |
40f4ba76 | 497 | const struct bt_stream_class *stream_class) |
44c440bc PP |
498 | { |
499 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
500 | return (bt_bool) stream_class->assigns_automatic_stream_id; | |
501 | } | |
8bf65fbd | 502 | |
40f4ba76 PP |
503 | void bt_stream_class_set_assigns_automatic_stream_id( |
504 | struct bt_stream_class *stream_class, | |
e5be10ef | 505 | bt_bool value) |
44c440bc PP |
506 | { |
507 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
508 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
509 | stream_class->assigns_automatic_stream_id = (bool) value; | |
510 | BT_LIB_LOGV("Set stream class's automatic stream ID " | |
511 | "assignment property: %!+S", stream_class); | |
44c440bc | 512 | } |
3dca2276 | 513 | |
44c440bc | 514 | bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot( |
40f4ba76 | 515 | const struct bt_stream_class *stream_class) |
44c440bc PP |
516 | { |
517 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
518 | return (bt_bool) stream_class->packets_have_discarded_event_counter_snapshot; | |
8bf65fbd JG |
519 | } |
520 | ||
40f4ba76 PP |
521 | void bt_stream_class_set_packets_have_discarded_event_counter_snapshot( |
522 | struct bt_stream_class *stream_class, | |
e5be10ef | 523 | bt_bool value) |
11b0cdc8 | 524 | { |
44c440bc PP |
525 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
526 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
527 | stream_class->packets_have_discarded_event_counter_snapshot = | |
528 | (bool) value; | |
529 | BT_LIB_LOGV("Set stream class's " | |
530 | "\"packets have discarded event counter snapshot\" property: " | |
531 | "%!+S", stream_class); | |
44c440bc | 532 | } |
11b0cdc8 | 533 | |
44c440bc | 534 | bt_bool bt_stream_class_packets_have_packet_counter_snapshot( |
40f4ba76 | 535 | const struct bt_stream_class *stream_class) |
44c440bc PP |
536 | { |
537 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
538 | return (bt_bool) stream_class->packets_have_packet_counter_snapshot; | |
11b0cdc8 JG |
539 | } |
540 | ||
40f4ba76 PP |
541 | void bt_stream_class_set_packets_have_packet_counter_snapshot( |
542 | struct bt_stream_class *stream_class, | |
e5be10ef | 543 | bt_bool value) |
2a3ced3c | 544 | { |
44c440bc PP |
545 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
546 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
547 | stream_class->packets_have_packet_counter_snapshot = | |
548 | (bool) value; | |
549 | BT_LIB_LOGV("Set stream class's " | |
550 | "\"packets have packet counter snapshot\" property: " | |
551 | "%!+S", stream_class); | |
44c440bc | 552 | } |
2a3ced3c | 553 | |
44c440bc | 554 | bt_bool bt_stream_class_packets_have_default_beginning_clock_value( |
40f4ba76 | 555 | const struct bt_stream_class *stream_class) |
44c440bc PP |
556 | { |
557 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
558 | return (bt_bool) stream_class->packets_have_default_beginning_cv; | |
559 | } | |
2a3ced3c | 560 | |
40f4ba76 PP |
561 | void bt_stream_class_set_packets_have_default_beginning_clock_value( |
562 | struct bt_stream_class *stream_class, | |
e5be10ef | 563 | bt_bool value) |
44c440bc PP |
564 | { |
565 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
566 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
567 | BT_ASSERT_PRE(!value || stream_class->default_clock_class, | |
568 | "Stream class does not have a default clock class: %!+S", | |
569 | stream_class); | |
570 | stream_class->packets_have_default_beginning_cv = (bool) value; | |
571 | BT_LIB_LOGV("Set stream class's " | |
572 | "\"packets have default beginning clock value\" property: " | |
573 | "%!+S", stream_class); | |
44c440bc | 574 | } |
2a3ced3c | 575 | |
44c440bc | 576 | bt_bool bt_stream_class_packets_have_default_end_clock_value( |
40f4ba76 | 577 | const struct bt_stream_class *stream_class) |
44c440bc PP |
578 | { |
579 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
580 | return (bt_bool) stream_class->packets_have_default_end_cv; | |
581 | } | |
2a3ced3c | 582 | |
40f4ba76 PP |
583 | void bt_stream_class_set_packets_have_default_end_clock_value( |
584 | struct bt_stream_class *stream_class, | |
e5be10ef | 585 | bt_bool value) |
44c440bc PP |
586 | { |
587 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
588 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
589 | BT_ASSERT_PRE(!value || stream_class->default_clock_class, | |
590 | "Stream class does not have a default clock class: %!+S", | |
591 | stream_class); | |
592 | stream_class->packets_have_default_end_cv = (bool) value; | |
593 | BT_LIB_LOGV("Set stream class's " | |
594 | "\"packets have default end clock value\" property: " | |
595 | "%!+S", stream_class); | |
44c440bc | 596 | } |
2a3ced3c | 597 | |
44c440bc | 598 | bt_bool bt_stream_class_default_clock_is_always_known( |
40f4ba76 | 599 | const struct bt_stream_class *stream_class) |
44c440bc PP |
600 | { |
601 | /* BT_CLOCK_VALUE_STATUS_UNKNOWN is not supported as of 2.0 */ | |
602 | return BT_TRUE; | |
2a3ced3c | 603 | } |