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