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> |
577dc45a PP |
29 | #include <babeltrace/trace-ir/clock-class-internal.h> |
30 | #include <babeltrace/trace-ir/event-class-internal.h> | |
c82deff2 | 31 | #include <babeltrace/trace-ir/field-classes-internal.h> |
577dc45a PP |
32 | #include <babeltrace/trace-ir/fields-internal.h> |
33 | #include <babeltrace/trace-ir/stream-class-internal.h> | |
351946b4 PP |
34 | #include <babeltrace/trace-ir/private-trace.h> |
35 | #include <babeltrace/trace-ir/trace-internal.h> | |
577dc45a 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> | |
e2317362 | 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> |
61f59358 | 44 | #include <babeltrace/property-internal.h> |
dc3fffef | 45 | #include <inttypes.h> |
544d0515 | 46 | #include <stdint.h> |
e011d2c1 | 47 | #include <stdbool.h> |
11b0cdc8 | 48 | |
61f59358 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 |
61f59358 | 53 | void destroy_stream_class(struct bt_object *obj) |
3ea33115 | 54 | { |
cb6f1f7d PP |
55 | struct bt_stream_class *stream_class = (void *) obj; |
56 | ||
61f59358 PP |
57 | BT_LIB_LOGD("Destroying stream class: %!+S", stream_class); |
58 | BT_LOGD_STR("Putting default clock class."); | |
53b97e38 | 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); | |
53b97e38 | 64 | stream_class->event_classes = NULL; |
d2f71f12 PP |
65 | } |
66 | ||
61f59358 PP |
67 | if (stream_class->name.str) { |
68 | g_string_free(stream_class->name.str, TRUE); | |
53b97e38 PP |
69 | stream_class->name.str = NULL; |
70 | stream_class->name.value = NULL; | |
3ea33115 JG |
71 | } |
72 | ||
c82deff2 | 73 | BT_LOGD_STR("Putting event header field classe."); |
53b97e38 | 74 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->event_header_fc); |
c82deff2 | 75 | BT_LOGD_STR("Putting packet context field classe."); |
53b97e38 | 76 | BT_OBJECT_PUT_REF_AND_RESET(stream_class->packet_context_fc); |
c82deff2 | 77 | BT_LOGD_STR("Putting event common context field classe."); |
53b97e38 | 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 | ||
61f59358 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 | { |
3dca2276 PP |
116 | struct bt_stream_class *stream_class = NULL; |
117 | int ret; | |
2f100782 | 118 | |
61f59358 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); | |
3dca2276 | 125 | stream_class = g_new0(struct bt_stream_class, 1); |
d2f71f12 | 126 | if (!stream_class) { |
3dca2276 PP |
127 | BT_LOGE_STR("Failed to allocate one stream class."); |
128 | goto error; | |
d2f71f12 PP |
129 | } |
130 | ||
61f59358 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."); | |
3dca2276 | 148 | goto error; |
2f100782 JG |
149 | } |
150 | ||
312c056a 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 | ||
61f59358 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); | |
312c056a PP |
175 | goto end; |
176 | ||
177 | error: | |
e2317362 | 178 | BT_OBJECT_PUT_REF_AND_RESET(stream_class); |
312c056a PP |
179 | |
180 | end: | |
61f59358 | 181 | return stream_class; |
312c056a PP |
182 | } |
183 | ||
351946b4 PP |
184 | struct bt_private_stream_class *bt_private_stream_class_create( |
185 | struct bt_private_trace *priv_trace) | |
312c056a | 186 | { |
351946b4 PP |
187 | struct bt_trace *trace = (void *) priv_trace; |
188 | ||
61f59358 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); | |
351946b4 | 193 | return (void *) create_stream_class_with_id(trace, |
61f59358 PP |
194 | (uint64_t) trace->stream_classes->len); |
195 | } | |
312c056a | 196 | |
351946b4 PP |
197 | struct bt_private_stream_class *bt_private_stream_class_create_with_id( |
198 | struct bt_private_trace *priv_trace, uint64_t id) | |
61f59358 | 199 | { |
351946b4 PP |
200 | struct bt_trace *trace = (void *) priv_trace; |
201 | ||
61f59358 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); | |
351946b4 | 206 | return (void *) create_stream_class_with_id(trace, id); |
312c056a PP |
207 | } |
208 | ||
094ff7c0 | 209 | struct bt_trace *bt_stream_class_borrow_trace(struct bt_stream_class *stream_class) |
11b0cdc8 | 210 | { |
61f59358 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 | ||
351946b4 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 | ||
3dca2276 | 221 | const char *bt_stream_class_get_name(struct bt_stream_class *stream_class) |
2f100782 | 222 | { |
cb6f1f7d | 223 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
61f59358 | 224 | return stream_class->name.value; |
2f100782 JG |
225 | } |
226 | ||
351946b4 PP |
227 | int bt_private_stream_class_set_name( |
228 | struct bt_private_stream_class *priv_stream_class, | |
3dca2276 | 229 | const char *name) |
5ca83563 | 230 | { |
351946b4 PP |
231 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
232 | ||
61f59358 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 | ||
61f59358 | 242 | uint64_t bt_stream_class_get_id(struct bt_stream_class *stream_class) |
2f100782 | 243 | { |
cb6f1f7d | 244 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
61f59358 | 245 | return stream_class->id; |
2f100782 JG |
246 | } |
247 | ||
61f59358 PP |
248 | uint64_t bt_stream_class_get_event_class_count( |
249 | struct bt_stream_class *stream_class) | |
29664b2a | 250 | { |
61f59358 PP |
251 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
252 | return (uint64_t) stream_class->event_classes->len; | |
29664b2a PP |
253 | } |
254 | ||
61f59358 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 | { |
61f59358 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 | ||
351946b4 | 263 | struct bt_private_event_class * |
aa4d5da5 | 264 | bt_private_stream_class_borrow_event_class_by_index( |
351946b4 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 | ||
61f59358 | 271 | struct bt_event_class *bt_stream_class_borrow_event_class_by_id( |
351946b4 | 272 | struct bt_stream_class *stream_class, uint64_t id) |
11b0cdc8 | 273 | { |
61f59358 PP |
274 | struct bt_event_class *event_class = NULL; |
275 | uint64_t i; | |
0b9ce69f | 276 | |
351946b4 | 277 | BT_ASSERT_PRE_NON_NULL(stream_class, "Trace"); |
11b0cdc8 | 278 | |
351946b4 | 279 | for (i = 0; i < stream_class->event_classes->len; i++) { |
61f59358 | 280 | struct bt_event_class *event_class_candidate = |
351946b4 | 281 | g_ptr_array_index(stream_class->event_classes, i); |
e6a8e8e4 | 282 | |
61f59358 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: |
61f59358 | 290 | return event_class; |
0863f950 PP |
291 | } |
292 | ||
351946b4 | 293 | struct bt_private_event_class * |
aa4d5da5 | 294 | bt_private_stream_class_borrow_event_class_by_id( |
351946b4 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 | ||
c82deff2 | 301 | struct bt_field_class *bt_stream_class_borrow_packet_context_field_class( |
50842bdc | 302 | struct bt_stream_class *stream_class) |
12c8a1a3 | 303 | { |
cb6f1f7d | 304 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
c82deff2 | 305 | return stream_class->packet_context_fc; |
12c8a1a3 JG |
306 | } |
307 | ||
351946b4 | 308 | struct bt_private_field_class * |
aa4d5da5 | 309 | bt_private_stream_class_borrow_packet_context_field_class( |
351946b4 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 | ||
aa4d5da5 | 316 | int bt_private_stream_class_set_packet_context_field_class( |
351946b4 PP |
317 | struct bt_private_stream_class *priv_stream_class, |
318 | struct bt_private_field_class *priv_field_class) | |
12c8a1a3 | 319 | { |
61f59358 | 320 | int ret; |
351946b4 PP |
321 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
322 | struct bt_field_class *field_class = (void *) priv_field_class; | |
61f59358 PP |
323 | struct bt_resolve_field_path_context resolve_ctx = { |
324 | .packet_header = NULL, | |
c82deff2 | 325 | .packet_context = field_class, |
61f59358 PP |
326 | .event_header = NULL, |
327 | .event_common_context = NULL, | |
328 | .event_specific_context = NULL, | |
329 | .event_payload = NULL, | |
330 | }; | |
cb6f1f7d | 331 | |
61f59358 | 332 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
c82deff2 | 333 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
61f59358 | 334 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
63749226 PP |
335 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
336 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
c82deff2 PP |
337 | "Packet context field classe is not a structure field classe: %!+F", |
338 | field_class); | |
61f59358 | 339 | resolve_ctx.packet_header = |
c82deff2 PP |
340 | bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; |
341 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
61f59358 | 342 | if (ret) { |
cb6f1f7d PP |
343 | goto end; |
344 | } | |
345 | ||
c82deff2 | 346 | bt_field_class_make_part_of_trace(field_class); |
e2317362 | 347 | bt_object_put_ref(stream_class->packet_context_fc); |
5e8988cb PP |
348 | stream_class->packet_context_fc = field_class; |
349 | bt_object_get_no_null_check(stream_class->packet_context_fc); | |
c82deff2 PP |
350 | bt_field_class_freeze(field_class); |
351 | BT_LIB_LOGV("Set stream class's packet context field classe: %!+S", | |
61f59358 | 352 | stream_class); |
cb6f1f7d PP |
353 | |
354 | end: | |
355 | return ret; | |
12c8a1a3 JG |
356 | } |
357 | ||
c82deff2 | 358 | struct bt_field_class *bt_stream_class_borrow_event_header_field_class( |
50842bdc | 359 | struct bt_stream_class *stream_class) |
662e778c | 360 | { |
cb6f1f7d | 361 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
c82deff2 | 362 | return stream_class->event_header_fc; |
662e778c JG |
363 | } |
364 | ||
351946b4 | 365 | struct bt_private_field_class * |
aa4d5da5 | 366 | bt_private_stream_class_borrow_event_header_field_class( |
351946b4 PP |
367 | struct bt_private_stream_class *stream_class) |
368 | { | |
369 | return (void *) bt_stream_class_borrow_event_header_field_class( | |
370 | (void *) stream_class); | |
371 | } | |
372 | ||
aa4d5da5 | 373 | int bt_private_stream_class_set_event_header_field_class( |
351946b4 PP |
374 | struct bt_private_stream_class *priv_stream_class, |
375 | struct bt_private_field_class *priv_field_class) | |
662e778c | 376 | { |
61f59358 | 377 | int ret; |
351946b4 PP |
378 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
379 | struct bt_field_class *field_class = (void *) priv_field_class; | |
61f59358 PP |
380 | struct bt_resolve_field_path_context resolve_ctx = { |
381 | .packet_header = NULL, | |
382 | .packet_context = NULL, | |
c82deff2 | 383 | .event_header = field_class, |
61f59358 PP |
384 | .event_common_context = NULL, |
385 | .event_specific_context = NULL, | |
386 | .event_payload = NULL, | |
387 | }; | |
cb6f1f7d | 388 | |
61f59358 | 389 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
c82deff2 | 390 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
61f59358 | 391 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
63749226 PP |
392 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
393 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
c82deff2 PP |
394 | "Event header field classe is not a structure field classe: %!+F", |
395 | field_class); | |
61f59358 | 396 | resolve_ctx.packet_header = |
c82deff2 PP |
397 | bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; |
398 | resolve_ctx.packet_context = stream_class->packet_context_fc; | |
399 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
61f59358 | 400 | if (ret) { |
cb6f1f7d PP |
401 | goto end; |
402 | } | |
403 | ||
c82deff2 | 404 | bt_field_class_make_part_of_trace(field_class); |
e2317362 | 405 | bt_object_put_ref(stream_class->event_header_fc); |
5e8988cb PP |
406 | stream_class->event_header_fc = field_class; |
407 | bt_object_get_no_null_check(stream_class->event_header_fc); | |
c82deff2 PP |
408 | bt_field_class_freeze(field_class); |
409 | BT_LIB_LOGV("Set stream class's event header field classe: %!+S", | |
61f59358 | 410 | stream_class); |
cb6f1f7d | 411 | |
cb6f1f7d PP |
412 | end: |
413 | return ret; | |
662e778c JG |
414 | } |
415 | ||
c82deff2 | 416 | struct bt_field_class *bt_stream_class_borrow_event_common_context_field_class( |
50842bdc | 417 | struct bt_stream_class *stream_class) |
af181248 | 418 | { |
cb6f1f7d | 419 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
c82deff2 | 420 | return stream_class->event_common_context_fc; |
af181248 JG |
421 | } |
422 | ||
351946b4 | 423 | struct bt_private_field_class * |
aa4d5da5 | 424 | bt_private_stream_class_borrow_event_common_context_field_class( |
351946b4 PP |
425 | struct bt_private_stream_class *stream_class) |
426 | { | |
427 | return (void *) bt_stream_class_borrow_event_common_context_field_class( | |
428 | (void *) stream_class); | |
429 | } | |
430 | ||
aa4d5da5 | 431 | int bt_private_stream_class_set_event_common_context_field_class( |
351946b4 PP |
432 | struct bt_private_stream_class *priv_stream_class, |
433 | struct bt_private_field_class *priv_field_class) | |
af181248 | 434 | { |
61f59358 | 435 | int ret; |
351946b4 PP |
436 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
437 | struct bt_field_class *field_class = (void *) priv_field_class; | |
61f59358 PP |
438 | struct bt_resolve_field_path_context resolve_ctx = { |
439 | .packet_header = NULL, | |
440 | .packet_context = NULL, | |
441 | .event_header = NULL, | |
c82deff2 | 442 | .event_common_context = field_class, |
61f59358 PP |
443 | .event_specific_context = NULL, |
444 | .event_payload = NULL, | |
445 | }; | |
cb6f1f7d | 446 | |
61f59358 | 447 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
c82deff2 | 448 | BT_ASSERT_PRE_NON_NULL(field_class, "Field class"); |
61f59358 | 449 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); |
63749226 PP |
450 | BT_ASSERT_PRE(bt_field_class_get_type(field_class) == |
451 | BT_FIELD_CLASS_TYPE_STRUCTURE, | |
c82deff2 PP |
452 | "Event common context field classe is not a structure field classe: %!+F", |
453 | field_class); | |
61f59358 | 454 | resolve_ctx.packet_header = |
c82deff2 PP |
455 | bt_stream_class_borrow_trace_inline(stream_class)->packet_header_fc; |
456 | resolve_ctx.packet_context = stream_class->packet_context_fc; | |
457 | resolve_ctx.event_header = stream_class->event_header_fc; | |
458 | ret = bt_resolve_field_paths(field_class, &resolve_ctx); | |
61f59358 | 459 | if (ret) { |
cb6f1f7d PP |
460 | goto end; |
461 | } | |
462 | ||
c82deff2 | 463 | bt_field_class_make_part_of_trace(field_class); |
e2317362 | 464 | bt_object_put_ref(stream_class->event_common_context_fc); |
5e8988cb PP |
465 | stream_class->event_common_context_fc = field_class; |
466 | bt_object_get_no_null_check(stream_class->event_common_context_fc); | |
c82deff2 PP |
467 | bt_field_class_freeze(field_class); |
468 | BT_LIB_LOGV("Set stream class's event common context field classe: %!+S", | |
61f59358 | 469 | stream_class); |
cb6f1f7d | 470 | |
cb6f1f7d PP |
471 | end: |
472 | return ret; | |
11b0cdc8 JG |
473 | } |
474 | ||
61f59358 PP |
475 | BT_HIDDEN |
476 | void _bt_stream_class_freeze(struct bt_stream_class *stream_class) | |
8bf65fbd | 477 | { |
c82deff2 | 478 | /* The field classes and default clock class are already frozen */ |
61f59358 PP |
479 | BT_ASSERT(stream_class); |
480 | BT_LIB_LOGD("Freezing stream class: %!+S", stream_class); | |
481 | stream_class->frozen = true; | |
8bf65fbd JG |
482 | } |
483 | ||
351946b4 PP |
484 | int bt_private_stream_class_set_default_clock_class( |
485 | struct bt_private_stream_class *priv_stream_class, | |
61f59358 | 486 | struct bt_clock_class *clock_class) |
8bf65fbd | 487 | { |
351946b4 PP |
488 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
489 | ||
61f59358 PP |
490 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
491 | BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class"); | |
492 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
e2317362 | 493 | bt_object_put_ref(stream_class->default_clock_class); |
5e8988cb PP |
494 | stream_class->default_clock_class = clock_class; |
495 | bt_object_get_no_null_check(stream_class->default_clock_class); | |
61f59358 PP |
496 | bt_clock_class_freeze(clock_class); |
497 | BT_LIB_LOGV("Set stream class's default clock class: %!+S", | |
498 | stream_class); | |
499 | return 0; | |
8bf65fbd JG |
500 | } |
501 | ||
61f59358 PP |
502 | struct bt_clock_class *bt_stream_class_borrow_default_clock_class( |
503 | struct bt_stream_class *stream_class) | |
8bf65fbd | 504 | { |
61f59358 PP |
505 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
506 | return stream_class->default_clock_class; | |
507 | } | |
8bf65fbd | 508 | |
61f59358 PP |
509 | bt_bool bt_stream_class_assigns_automatic_event_class_id( |
510 | struct bt_stream_class *stream_class) | |
511 | { | |
512 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
513 | return (bt_bool) stream_class->assigns_automatic_event_class_id; | |
8bf65fbd JG |
514 | } |
515 | ||
c9987c4e | 516 | void bt_private_stream_class_set_assigns_automatic_event_class_id( |
351946b4 PP |
517 | struct bt_private_stream_class *priv_stream_class, |
518 | bt_bool value) | |
8bf65fbd | 519 | { |
351946b4 PP |
520 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
521 | ||
61f59358 PP |
522 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
523 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
524 | stream_class->assigns_automatic_event_class_id = (bool) value; | |
525 | BT_LIB_LOGV("Set stream class's automatic event class ID " | |
526 | "assignment property: %!+S", stream_class); | |
61f59358 | 527 | } |
8bf65fbd | 528 | |
61f59358 PP |
529 | bt_bool bt_stream_class_assigns_automatic_stream_id( |
530 | struct bt_stream_class *stream_class) | |
531 | { | |
532 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
533 | return (bt_bool) stream_class->assigns_automatic_stream_id; | |
534 | } | |
8bf65fbd | 535 | |
c9987c4e | 536 | void bt_private_stream_class_set_assigns_automatic_stream_id( |
351946b4 PP |
537 | struct bt_private_stream_class *priv_stream_class, |
538 | bt_bool value) | |
61f59358 | 539 | { |
351946b4 PP |
540 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
541 | ||
61f59358 PP |
542 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
543 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
544 | stream_class->assigns_automatic_stream_id = (bool) value; | |
545 | BT_LIB_LOGV("Set stream class's automatic stream ID " | |
546 | "assignment property: %!+S", stream_class); | |
61f59358 | 547 | } |
3dca2276 | 548 | |
61f59358 PP |
549 | bt_bool bt_stream_class_packets_have_discarded_event_counter_snapshot( |
550 | struct bt_stream_class *stream_class) | |
551 | { | |
552 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
553 | return (bt_bool) stream_class->packets_have_discarded_event_counter_snapshot; | |
8bf65fbd JG |
554 | } |
555 | ||
c9987c4e | 556 | void bt_private_stream_class_set_packets_have_discarded_event_counter_snapshot( |
351946b4 PP |
557 | struct bt_private_stream_class *priv_stream_class, |
558 | bt_bool value) | |
11b0cdc8 | 559 | { |
351946b4 PP |
560 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
561 | ||
61f59358 PP |
562 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
563 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
564 | stream_class->packets_have_discarded_event_counter_snapshot = | |
565 | (bool) value; | |
566 | BT_LIB_LOGV("Set stream class's " | |
567 | "\"packets have discarded event counter snapshot\" property: " | |
568 | "%!+S", stream_class); | |
61f59358 | 569 | } |
11b0cdc8 | 570 | |
61f59358 PP |
571 | bt_bool bt_stream_class_packets_have_packet_counter_snapshot( |
572 | struct bt_stream_class *stream_class) | |
573 | { | |
574 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
575 | return (bt_bool) stream_class->packets_have_packet_counter_snapshot; | |
11b0cdc8 JG |
576 | } |
577 | ||
c9987c4e | 578 | void bt_private_stream_class_set_packets_have_packet_counter_snapshot( |
351946b4 PP |
579 | struct bt_private_stream_class *priv_stream_class, |
580 | bt_bool value) | |
2a3ced3c | 581 | { |
351946b4 PP |
582 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
583 | ||
61f59358 PP |
584 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
585 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
586 | stream_class->packets_have_packet_counter_snapshot = | |
587 | (bool) value; | |
588 | BT_LIB_LOGV("Set stream class's " | |
589 | "\"packets have packet counter snapshot\" property: " | |
590 | "%!+S", stream_class); | |
61f59358 | 591 | } |
2a3ced3c | 592 | |
61f59358 PP |
593 | bt_bool bt_stream_class_packets_have_default_beginning_clock_value( |
594 | struct bt_stream_class *stream_class) | |
595 | { | |
596 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
597 | return (bt_bool) stream_class->packets_have_default_beginning_cv; | |
598 | } | |
2a3ced3c | 599 | |
c9987c4e | 600 | void bt_private_stream_class_set_packets_have_default_beginning_clock_value( |
351946b4 PP |
601 | struct bt_private_stream_class *priv_stream_class, |
602 | bt_bool value) | |
61f59358 | 603 | { |
351946b4 PP |
604 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
605 | ||
61f59358 PP |
606 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
607 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
608 | BT_ASSERT_PRE(!value || stream_class->default_clock_class, | |
609 | "Stream class does not have a default clock class: %!+S", | |
610 | stream_class); | |
611 | stream_class->packets_have_default_beginning_cv = (bool) value; | |
612 | BT_LIB_LOGV("Set stream class's " | |
613 | "\"packets have default beginning clock value\" property: " | |
614 | "%!+S", stream_class); | |
61f59358 | 615 | } |
2a3ced3c | 616 | |
61f59358 PP |
617 | bt_bool bt_stream_class_packets_have_default_end_clock_value( |
618 | struct bt_stream_class *stream_class) | |
619 | { | |
620 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); | |
621 | return (bt_bool) stream_class->packets_have_default_end_cv; | |
622 | } | |
2a3ced3c | 623 | |
c9987c4e | 624 | void bt_private_stream_class_set_packets_have_default_end_clock_value( |
351946b4 PP |
625 | struct bt_private_stream_class *priv_stream_class, |
626 | bt_bool value) | |
61f59358 | 627 | { |
351946b4 PP |
628 | struct bt_stream_class *stream_class = (void *) priv_stream_class; |
629 | ||
61f59358 PP |
630 | BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); |
631 | BT_ASSERT_PRE_STREAM_CLASS_HOT(stream_class); | |
632 | BT_ASSERT_PRE(!value || stream_class->default_clock_class, | |
633 | "Stream class does not have a default clock class: %!+S", | |
634 | stream_class); | |
635 | stream_class->packets_have_default_end_cv = (bool) value; | |
636 | BT_LIB_LOGV("Set stream class's " | |
637 | "\"packets have default end clock value\" property: " | |
638 | "%!+S", stream_class); | |
61f59358 | 639 | } |
2a3ced3c | 640 | |
61f59358 PP |
641 | bt_bool bt_stream_class_default_clock_is_always_known( |
642 | struct bt_stream_class *stream_class) | |
643 | { | |
644 | /* BT_CLOCK_VALUE_STATUS_UNKNOWN is not supported as of 2.0 */ | |
645 | return BT_TRUE; | |
2a3ced3c | 646 | } |