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