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> | |
9e550e5f PP |
34 | #include <babeltrace/trace-ir/private-trace.h> |
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 | |
93 | bool stream_class_id_is_unique(struct bt_trace *trace, uint64_t id) | |
94 | { | |
95 | uint64_t i; | |
96 | bool is_unique = true; | |
97 | ||
98 | for (i = 0; i < trace->stream_classes->len; i++) { | |
99 | struct bt_stream_class *sc = | |
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 | ||
9e550e5f PP |
184 | struct bt_private_stream_class *bt_private_stream_class_create( |
185 | struct bt_private_trace *priv_trace) | |
a6918753 | 186 | { |
9e550e5f PP |
187 | struct bt_trace *trace = (void *) priv_trace; |
188 | ||
7b33a0e0 PP |
189 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); |
190 | BT_ASSERT_PRE(trace->assigns_automatic_stream_class_id, | |
191 | "Trace does not automatically assigns stream class IDs: " | |
192 | "%![sc-]+t", trace); | |
9e550e5f | 193 | return (void *) create_stream_class_with_id(trace, |
7b33a0e0 PP |
194 | (uint64_t) trace->stream_classes->len); |
195 | } | |
a6918753 | 196 | |
9e550e5f PP |
197 | struct bt_private_stream_class *bt_private_stream_class_create_with_id( |
198 | struct bt_private_trace *priv_trace, uint64_t id) | |
7b33a0e0 | 199 | { |
9e550e5f PP |
200 | struct bt_trace *trace = (void *) priv_trace; |
201 | ||
7b33a0e0 PP |
202 | BT_ASSERT_PRE_NON_NULL(trace, "Trace"); |
203 | BT_ASSERT_PRE(!trace->assigns_automatic_stream_class_id, | |
204 | "Trace automatically assigns stream class IDs: " | |
205 | "%![sc-]+t", trace); | |
9e550e5f | 206 | return (void *) create_stream_class_with_id(trace, id); |
a6918753 PP |
207 | } |
208 | ||
5fe68922 | 209 | struct bt_trace *bt_stream_class_borrow_trace(struct bt_stream_class *stream_class) |
11b0cdc8 | 210 | { |
7b33a0e0 PP |
211 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
212 | return bt_stream_class_borrow_trace_inline(stream_class); | |
11b0cdc8 JG |
213 | } |
214 | ||
9e550e5f PP |
215 | struct bt_private_trace *bt_private_stream_class_borrow_trace( |
216 | struct bt_private_stream_class *stream_class) | |
217 | { | |
218 | return (void *) bt_stream_class_borrow_trace((void *) stream_class); | |
219 | } | |
220 | ||
8deee039 | 221 | const char *bt_stream_class_get_name(struct bt_stream_class *stream_class) |
2f100782 | 222 | { |
18acc6f8 | 223 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 | 224 | return stream_class->name.value; |
2f100782 JG |
225 | } |
226 | ||
9e550e5f PP |
227 | int bt_private_stream_class_set_name( |
228 | struct bt_private_stream_class *priv_stream_class, | |
8deee039 | 229 | const char *name) |
5ca83563 | 230 | { |
9e550e5f PP |
231 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
232 | ||
7b33a0e0 PP |
233 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
234 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
235 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
236 | g_string_assign(stream_class->name.str, name); | |
237 | stream_class->name.value = stream_class->name.str->str; | |
238 | BT_LIB_LOGV("Set stream class's name: %!+S", stream_class); | |
239 | return 0; | |
5ca83563 JG |
240 | } |
241 | ||
7b33a0e0 | 242 | uint64_t bt_stream_class_get_id(struct bt_stream_class *stream_class) |
2f100782 | 243 | { |
18acc6f8 | 244 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
7b33a0e0 | 245 | return stream_class->id; |
2f100782 JG |
246 | } |
247 | ||
7b33a0e0 PP |
248 | uint64_t bt_stream_class_get_event_class_count( |
249 | struct bt_stream_class *stream_class) | |
29664b2a | 250 | { |
7b33a0e0 PP |
251 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
252 | return (uint64_t) stream_class->event_classes->len; | |
29664b2a PP |
253 | } |
254 | ||
7b33a0e0 PP |
255 | struct bt_event_class *bt_stream_class_borrow_event_class_by_index( |
256 | struct bt_stream_class *stream_class, uint64_t index) | |
0d23acbe | 257 | { |
7b33a0e0 PP |
258 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
259 | BT_ASSERT_PRE_VALID_INDEX(index, stream_class->event_classes->len); | |
260 | return g_ptr_array_index(stream_class->event_classes, index); | |
0d23acbe PP |
261 | } |
262 | ||
9e550e5f | 263 | struct bt_private_event_class * |
96854e6a | 264 | bt_private_stream_class_borrow_event_class_by_index( |
9e550e5f PP |
265 | struct bt_private_stream_class *stream_class, uint64_t index) |
266 | { | |
267 | return (void *) bt_stream_class_borrow_event_class_by_index( | |
268 | (void *) stream_class, index); | |
269 | } | |
270 | ||
7b33a0e0 | 271 | struct bt_event_class *bt_stream_class_borrow_event_class_by_id( |
9e550e5f | 272 | struct bt_stream_class *stream_class, uint64_t id) |
11b0cdc8 | 273 | { |
7b33a0e0 PP |
274 | struct bt_event_class *event_class = NULL; |
275 | uint64_t i; | |
0b9ce69f | 276 | |
9e550e5f | 277 | BT_ASSERT_PRE_NON_NULL(stream_class, "Trace"); |
11b0cdc8 | 278 | |
9e550e5f | 279 | for (i = 0; i < stream_class->event_classes->len; i++) { |
7b33a0e0 | 280 | struct bt_event_class *event_class_candidate = |
9e550e5f | 281 | g_ptr_array_index(stream_class->event_classes, i); |
e6a8e8e4 | 282 | |
7b33a0e0 PP |
283 | if (event_class_candidate->id == id) { |
284 | event_class = event_class_candidate; | |
09840de5 PP |
285 | goto end; |
286 | } | |
69dc4535 JG |
287 | } |
288 | ||
69dc4535 | 289 | end: |
7b33a0e0 | 290 | return event_class; |
0863f950 PP |
291 | } |
292 | ||
9e550e5f | 293 | struct bt_private_event_class * |
96854e6a | 294 | bt_private_stream_class_borrow_event_class_by_id( |
9e550e5f PP |
295 | struct bt_private_stream_class *stream_class, uint64_t id) |
296 | { | |
297 | return (void *) bt_stream_class_borrow_event_class_by_id( | |
298 | (void *) stream_class, id); | |
299 | } | |
300 | ||
939190b3 | 301 | struct bt_field_class *bt_stream_class_borrow_packet_context_field_class( |
839d52a5 | 302 | struct bt_stream_class *stream_class) |
12c8a1a3 | 303 | { |
18acc6f8 | 304 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 305 | return stream_class->packet_context_fc; |
12c8a1a3 JG |
306 | } |
307 | ||
9e550e5f | 308 | struct bt_private_field_class * |
96854e6a | 309 | bt_private_stream_class_borrow_packet_context_field_class( |
9e550e5f PP |
310 | struct bt_private_stream_class *stream_class) |
311 | { | |
312 | return (void *) bt_stream_class_borrow_packet_context_field_class( | |
313 | (void *) stream_class); | |
314 | } | |
315 | ||
96854e6a | 316 | int bt_private_stream_class_set_packet_context_field_class( |
9e550e5f PP |
317 | struct bt_private_stream_class *priv_stream_class, |
318 | struct bt_private_field_class *priv_field_class) | |
12c8a1a3 | 319 | { |
7b33a0e0 | 320 | int ret; |
9e550e5f PP |
321 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
322 | struct bt_field_class *field_class = (void *) priv_field_class; | |
7b33a0e0 PP |
323 | struct bt_resolve_field_path_context resolve_ctx = { |
324 | .packet_header = NULL, | |
939190b3 | 325 | .packet_context = field_class, |
7b33a0e0 PP |
326 | .event_header = NULL, |
327 | .event_common_context = NULL, | |
328 | .event_specific_context = NULL, | |
329 | .event_payload = NULL, | |
330 | }; | |
18acc6f8 | 331 | |
7b33a0e0 | 332 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 333 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
7b33a0e0 | 334 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
af0c18e3 PP |
335 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
336 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
939190b3 PP |
337 | "Packet context field classe is not a structure field classe: %!+F", |
338 | field_class); | |
7b33a0e0 | 339 | resolve_ctx.packet_header = |
939190b3 PP |
340 | bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; |
341 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
7b33a0e0 | 342 | if (ret) { |
18acc6f8 PP |
343 | goto end; |
344 | } | |
345 | ||
939190b3 | 346 | bt_field_class_make_part_of_trace(field_class); |
8138bfe1 PP |
347 | bt_object_put_ref(stream_class->packet_context_fc); |
348 | stream_class->packet_context_fc = bt_object_get_ref(field_class); | |
939190b3 PP |
349 | bt_field_class_freeze(field_class); |
350 | BT_LIB_LOGV("Set stream class's packet context field classe: %!+S", | |
7b33a0e0 | 351 | stream_class); |
18acc6f8 PP |
352 | |
353 | end: | |
354 | return ret; | |
12c8a1a3 JG |
355 | } |
356 | ||
939190b3 | 357 | struct bt_field_class *bt_stream_class_borrow_event_header_field_class( |
839d52a5 | 358 | struct bt_stream_class *stream_class) |
662e778c | 359 | { |
18acc6f8 | 360 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 361 | return stream_class->event_header_fc; |
662e778c JG |
362 | } |
363 | ||
9e550e5f | 364 | struct bt_private_field_class * |
96854e6a | 365 | bt_private_stream_class_borrow_event_header_field_class( |
9e550e5f PP |
366 | struct bt_private_stream_class *stream_class) |
367 | { | |
368 | return (void *) bt_stream_class_borrow_event_header_field_class( | |
369 | (void *) stream_class); | |
370 | } | |
371 | ||
96854e6a | 372 | int bt_private_stream_class_set_event_header_field_class( |
9e550e5f PP |
373 | struct bt_private_stream_class *priv_stream_class, |
374 | struct bt_private_field_class *priv_field_class) | |
662e778c | 375 | { |
7b33a0e0 | 376 | int ret; |
9e550e5f PP |
377 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
378 | struct bt_field_class *field_class = (void *) priv_field_class; | |
7b33a0e0 PP |
379 | struct bt_resolve_field_path_context resolve_ctx = { |
380 | .packet_header = NULL, | |
381 | .packet_context = NULL, | |
939190b3 | 382 | .event_header = field_class, |
7b33a0e0 PP |
383 | .event_common_context = NULL, |
384 | .event_specific_context = NULL, | |
385 | .event_payload = NULL, | |
386 | }; | |
18acc6f8 | 387 | |
7b33a0e0 | 388 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 389 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
7b33a0e0 | 390 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
af0c18e3 PP |
391 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
392 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
939190b3 PP |
393 | "Event header field classe is not a structure field classe: %!+F", |
394 | field_class); | |
7b33a0e0 | 395 | resolve_ctx.packet_header = |
939190b3 PP |
396 | bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; |
397 | resolve_ctx.packet_context = stream_class->packet_context_fc; | |
398 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
7b33a0e0 | 399 | if (ret) { |
18acc6f8 PP |
400 | goto end; |
401 | } | |
402 | ||
939190b3 | 403 | bt_field_class_make_part_of_trace(field_class); |
8138bfe1 PP |
404 | bt_object_put_ref(stream_class->event_header_fc); |
405 | stream_class->event_header_fc = bt_object_get_ref(field_class); | |
939190b3 PP |
406 | bt_field_class_freeze(field_class); |
407 | BT_LIB_LOGV("Set stream class's event header field classe: %!+S", | |
7b33a0e0 | 408 | stream_class); |
18acc6f8 | 409 | |
18acc6f8 PP |
410 | end: |
411 | return ret; | |
662e778c JG |
412 | } |
413 | ||
939190b3 | 414 | struct bt_field_class *bt_stream_class_borrow_event_common_context_field_class( |
839d52a5 | 415 | struct bt_stream_class *stream_class) |
af181248 | 416 | { |
18acc6f8 | 417 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 418 | return stream_class->event_common_context_fc; |
af181248 JG |
419 | } |
420 | ||
9e550e5f | 421 | struct bt_private_field_class * |
96854e6a | 422 | bt_private_stream_class_borrow_event_common_context_field_class( |
9e550e5f PP |
423 | struct bt_private_stream_class *stream_class) |
424 | { | |
425 | return (void *) bt_stream_class_borrow_event_common_context_field_class( | |
426 | (void *) stream_class); | |
427 | } | |
428 | ||
96854e6a | 429 | int bt_private_stream_class_set_event_common_context_field_class( |
9e550e5f PP |
430 | struct bt_private_stream_class *priv_stream_class, |
431 | struct bt_private_field_class *priv_field_class) | |
af181248 | 432 | { |
7b33a0e0 | 433 | int ret; |
9e550e5f PP |
434 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
435 | struct bt_field_class *field_class = (void *) priv_field_class; | |
7b33a0e0 PP |
436 | struct bt_resolve_field_path_context resolve_ctx = { |
437 | .packet_header = NULL, | |
438 | .packet_context = NULL, | |
439 | .event_header = NULL, | |
939190b3 | 440 | .event_common_context = field_class, |
7b33a0e0 PP |
441 | .event_specific_context = NULL, |
442 | .event_payload = NULL, | |
443 | }; | |
18acc6f8 | 444 | |
7b33a0e0 | 445 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
939190b3 | 446 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
7b33a0e0 | 447 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
af0c18e3 PP |
448 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
449 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
939190b3 PP |
450 | "Event common context field classe is not a structure field classe: %!+F", |
451 | field_class); | |
7b33a0e0 | 452 | resolve_ctx.packet_header = |
939190b3 PP |
453 | bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; |
454 | resolve_ctx.packet_context = stream_class->packet_context_fc; | |
455 | resolve_ctx.event_header = stream_class->event_header_fc; | |
456 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
7b33a0e0 | 457 | if (ret) { |
18acc6f8 PP |
458 | goto end; |
459 | } | |
460 | ||
939190b3 | 461 | bt_field_class_make_part_of_trace(field_class); |
8138bfe1 PP |
462 | bt_object_put_ref(stream_class->event_common_context_fc); |
463 | stream_class->event_common_context_fc = bt_object_get_ref(field_class); | |
939190b3 PP |
464 | bt_field_class_freeze(field_class); |
465 | BT_LIB_LOGV("Set stream class's event common context field classe: %!+S", | |
7b33a0e0 | 466 | stream_class); |
18acc6f8 | 467 | |
18acc6f8 PP |
468 | end: |
469 | return ret; | |
11b0cdc8 JG |
470 | } |
471 | ||
7b33a0e0 PP |
472 | BT_HIDDEN |
473 | void _bt_stream_class_freeze(struct bt_stream_class *stream_class) | |
8bf65fbd | 474 | { |
939190b3 | 475 | /* The field classes and default clock class are already frozen */ |
7b33a0e0 PP |
476 | BT_ASSERT(stream_class); |
477 | BT_LIB_LOGD("Freezing stream class: %!+S", stream_class); | |
478 | stream_class->frozen = true; | |
8bf65fbd JG |
479 | } |
480 | ||
9e550e5f PP |
481 | int bt_private_stream_class_set_default_clock_class( |
482 | struct bt_private_stream_class *priv_stream_class, | |
7b33a0e0 | 483 | struct bt_clock_class *clock_class) |
8bf65fbd | 484 | { |
9e550e5f PP |
485 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
486 | ||
7b33a0e0 PP |
487 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
488 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
489 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
8138bfe1 PP |
490 | bt_object_put_ref(stream_class->default_clock_class); |
491 | stream_class->default_clock_class = bt_object_get_ref(clock_class); | |
7b33a0e0 PP |
492 | bt_clock_class_freeze(clock_class); |
493 | BT_LIB_LOGV("Set stream class's default clock class: %!+S", | |
494 | stream_class); | |
495 | return 0; | |
8bf65fbd JG |
496 | } |
497 | ||
7b33a0e0 PP |
498 | struct bt_clock_class *bt_stream_class_borrow_default_clock_class( |
499 | struct bt_stream_class *stream_class) | |
8bf65fbd | 500 | { |
7b33a0e0 PP |
501 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
502 | return stream_class->default_clock_class; | |
503 | } | |
8bf65fbd | 504 | |
7b33a0e0 PP |
505 | bt_bool bt_stream_class_assigns_automatic_event_class_id( |
506 | struct bt_stream_class *stream_class) | |
507 | { | |
508 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
509 | return (bt_bool) stream_class->assigns_automatic_event_class_id; | |
8bf65fbd JG |
510 | } |
511 | ||
c8bbf821 | 512 | void bt_private_stream_class_set_assigns_automatic_event_class_id( |
9e550e5f PP |
513 | struct bt_private_stream_class *priv_stream_class, |
514 | bt_bool value) | |
8bf65fbd | 515 | { |
9e550e5f PP |
516 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
517 | ||
7b33a0e0 PP |
518 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
519 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
520 | stream_class->assigns_automatic_event_class_id = (bool) value; | |
521 | BT_LIB_LOGV("Set stream class's automatic event class ID " | |
522 | "assignment property: %!+S", stream_class); | |
7b33a0e0 | 523 | } |
8bf65fbd | 524 | |
7b33a0e0 PP |
525 | bt_bool bt_stream_class_assigns_automatic_stream_id( |
526 | struct bt_stream_class *stream_class) | |
527 | { | |
528 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
529 | return (bt_bool) stream_class->assigns_automatic_stream_id; | |
530 | } | |
8bf65fbd | 531 | |
c8bbf821 | 532 | void bt_private_stream_class_set_assigns_automatic_stream_id( |
9e550e5f PP |
533 | struct bt_private_stream_class *priv_stream_class, |
534 | bt_bool value) | |
7b33a0e0 | 535 | { |
9e550e5f PP |
536 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
537 | ||
7b33a0e0 PP |
538 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
539 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
540 | stream_class->assigns_automatic_stream_id = (bool) value; | |
541 | BT_LIB_LOGV("Set stream class's automatic stream ID " | |
542 | "assignment property: %!+S", stream_class); | |
7b33a0e0 | 543 | } |
8deee039 | 544 | |
7b33a0e0 PP |
545 | bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot( |
546 | struct bt_stream_class *stream_class) | |
547 | { | |
548 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
549 | return (bt_bool) stream_class->packets_have_discarded_event_counter_snapshot; | |
8bf65fbd JG |
550 | } |
551 | ||
c8bbf821 | 552 | void bt_private_stream_class_set_packets_have_discarded_event_counter_snapshot( |
9e550e5f PP |
553 | struct bt_private_stream_class *priv_stream_class, |
554 | bt_bool value) | |
11b0cdc8 | 555 | { |
9e550e5f PP |
556 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
557 | ||
7b33a0e0 PP |
558 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
559 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
560 | stream_class->packets_have_discarded_event_counter_snapshot = | |
561 | (bool) value; | |
562 | BT_LIB_LOGV("Set stream class's " | |
563 | "\"packets have discarded event counter snapshot\" property: " | |
564 | "%!+S", stream_class); | |
7b33a0e0 | 565 | } |
11b0cdc8 | 566 | |
7b33a0e0 PP |
567 | bt_bool bt_stream_class_packets_have_packet_counter_snapshot( |
568 | struct bt_stream_class *stream_class) | |
569 | { | |
570 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
571 | return (bt_bool) stream_class->packets_have_packet_counter_snapshot; | |
11b0cdc8 JG |
572 | } |
573 | ||
c8bbf821 | 574 | void bt_private_stream_class_set_packets_have_packet_counter_snapshot( |
9e550e5f PP |
575 | struct bt_private_stream_class *priv_stream_class, |
576 | bt_bool value) | |
8c4a29ba | 577 | { |
9e550e5f PP |
578 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
579 | ||
7b33a0e0 PP |
580 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
581 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
582 | stream_class->packets_have_packet_counter_snapshot = | |
583 | (bool) value; | |
584 | BT_LIB_LOGV("Set stream class's " | |
585 | "\"packets have packet counter snapshot\" property: " | |
586 | "%!+S", stream_class); | |
7b33a0e0 | 587 | } |
8c4a29ba | 588 | |
7b33a0e0 PP |
589 | bt_bool bt_stream_class_packets_have_default_beginning_clock_value( |
590 | struct bt_stream_class *stream_class) | |
591 | { | |
592 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
593 | return (bt_bool) stream_class->packets_have_default_beginning_cv; | |
594 | } | |
8c4a29ba | 595 | |
c8bbf821 | 596 | void bt_private_stream_class_set_packets_have_default_beginning_clock_value( |
9e550e5f PP |
597 | struct bt_private_stream_class *priv_stream_class, |
598 | bt_bool value) | |
7b33a0e0 | 599 | { |
9e550e5f PP |
600 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
601 | ||
7b33a0e0 PP |
602 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
603 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
604 | BT_ASSERT_PRE(!value || stream_class->default_clock_class, | |
605 | "Stream class does not have a default clock class: %!+S", | |
606 | stream_class); | |
607 | stream_class->packets_have_default_beginning_cv = (bool) value; | |
608 | BT_LIB_LOGV("Set stream class's " | |
609 | "\"packets have default beginning clock value\" property: " | |
610 | "%!+S", stream_class); | |
7b33a0e0 | 611 | } |
8c4a29ba | 612 | |
7b33a0e0 PP |
613 | bt_bool bt_stream_class_packets_have_default_end_clock_value( |
614 | struct bt_stream_class *stream_class) | |
615 | { | |
616 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
617 | return (bt_bool) stream_class->packets_have_default_end_cv; | |
618 | } | |
8c4a29ba | 619 | |
c8bbf821 | 620 | void bt_private_stream_class_set_packets_have_default_end_clock_value( |
9e550e5f PP |
621 | struct bt_private_stream_class *priv_stream_class, |
622 | bt_bool value) | |
7b33a0e0 | 623 | { |
9e550e5f PP |
624 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
625 | ||
7b33a0e0 PP |
626 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
627 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
628 | BT_ASSERT_PRE(!value || stream_class->default_clock_class, | |
629 | "Stream class does not have a default clock class: %!+S", | |
630 | stream_class); | |
631 | stream_class->packets_have_default_end_cv = (bool) value; | |
632 | BT_LIB_LOGV("Set stream class's " | |
633 | "\"packets have default end clock value\" property: " | |
634 | "%!+S", stream_class); | |
7b33a0e0 | 635 | } |
8c4a29ba | 636 | |
7b33a0e0 PP |
637 | bt_bool bt_stream_class_default_clock_is_always_known( |
638 | struct bt_stream_class *stream_class) | |
639 | { | |
640 | /* BT_CLOCK_VALUE_STATUS_UNKNOWN is not supported as of 2.0 */ | |
641 | return BT_TRUE; | |
8c4a29ba | 642 | } |