2 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_LOG_TAG "CTF-WRITER-EVENT"
25 #include <babeltrace/lib-logging-internal.h>
27 #include <babeltrace/assert-pre-internal.h>
28 #include <babeltrace/assert-internal.h>
29 #include <babeltrace/compiler-internal.h>
30 #include <babeltrace/ctf-writer/attributes-internal.h>
31 #include <babeltrace/ctf-writer/clock-class-internal.h>
32 #include <babeltrace/ctf-writer/clock-internal.h>
33 #include <babeltrace/ctf-writer/event-class-internal.h>
34 #include <babeltrace/ctf-writer/event-internal.h>
35 #include <babeltrace/ctf-writer/event.h>
36 #include <babeltrace/ctf-writer/field-types-internal.h>
37 #include <babeltrace/ctf-writer/field-types.h>
38 #include <babeltrace/ctf-writer/fields-internal.h>
39 #include <babeltrace/ctf-writer/fields.h>
40 #include <babeltrace/ctf-writer/stream-class-internal.h>
41 #include <babeltrace/ctf-writer/stream-class.h>
42 #include <babeltrace/ctf-writer/stream-internal.h>
43 #include <babeltrace/ctf-writer/trace-internal.h>
44 #include <babeltrace/ctf-writer/trace.h>
45 #include <babeltrace/ctf-writer/utils.h>
46 #include <babeltrace/ctf-writer/validation-internal.h>
47 #include <babeltrace/object.h>
51 int bt_ctf_event_common_validate_types_for_create(
52 struct bt_ctf_event_class_common
*event_class
,
53 struct bt_ctf_validation_output
*validation_output
,
54 bt_ctf_validation_flag_copy_field_type_func copy_field_type_func
)
57 enum bt_ctf_validation_flag validation_flags
=
58 BT_CTF_VALIDATION_FLAG_STREAM
|
59 BT_CTF_VALIDATION_FLAG_EVENT
;
60 struct bt_ctf_trace_common
*trace
= NULL
;
61 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
62 struct bt_ctf_field_type_common
*packet_header_type
= NULL
;
63 struct bt_ctf_field_type_common
*packet_context_type
= NULL
;
64 struct bt_ctf_field_type_common
*event_header_type
= NULL
;
65 struct bt_ctf_field_type_common
*stream_event_ctx_type
= NULL
;
66 struct bt_ctf_field_type_common
*event_context_type
= NULL
;
67 struct bt_ctf_field_type_common
*event_payload_type
= NULL
;
69 struct bt_value
*environment
= NULL
;
71 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
72 BT_ASSERT(stream_class
);
73 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
75 BT_LOGD_STR("Event class is part of a trace.");
77 bt_ctf_trace_common_borrow_packet_header_field_type(trace
);
78 trace_valid
= trace
->valid
;
79 BT_ASSERT(trace_valid
);
80 environment
= trace
->environment
;
84 bt_ctf_stream_class_common_borrow_packet_context_field_type(
87 bt_ctf_stream_class_common_borrow_event_header_field_type(
89 stream_event_ctx_type
=
90 bt_ctf_stream_class_common_borrow_event_context_field_type(
93 bt_ctf_event_class_common_borrow_context_field_type(event_class
);
95 bt_ctf_event_class_common_borrow_payload_field_type(event_class
);
96 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
97 packet_context_type
, event_header_type
, stream_event_ctx_type
,
98 event_context_type
, event_payload_type
, trace_valid
,
99 stream_class
->valid
, event_class
->valid
,
100 validation_output
, validation_flags
, copy_field_type_func
);
103 * This means something went wrong during the validation
104 * process, not that the objects are invalid.
106 BT_LOGE("Failed to validate event and parents: ret=%d", ret
);
110 if ((validation_output
->valid_flags
& validation_flags
) !=
112 /* Invalid trace/stream class/event class */
113 BT_LOGW("Invalid trace, stream class, or event class: "
114 "valid-flags=0x%x", validation_output
->valid_flags
);
121 bt_ctf_validation_output_put_types(validation_output
);
129 int bt_ctf_event_common_create_fields(
130 struct bt_ctf_stream_class_common
*stream_class
,
131 struct bt_ctf_validation_output
*validation_output
,
132 create_field_func create_field_func
,
133 release_field_func release_field_func
,
134 create_header_field_func create_header_field_func
,
135 release_header_field_func release_header_field_func
,
136 struct bt_ctf_field_wrapper
**header_field
,
137 struct bt_ctf_field_common
**stream_event_context_field
,
138 struct bt_ctf_field_common
**context_field
,
139 struct bt_ctf_field_common
**payload_field
)
143 if (validation_output
->event_header_type
) {
144 BT_LOGD("Creating initial event header field: ft-addr=%p",
145 validation_output
->event_header_type
);
147 create_header_field_func(stream_class
,
148 validation_output
->event_header_type
);
149 if (!*header_field
) {
150 BT_LOGE_STR("Cannot create initial event header field object.");
155 if (validation_output
->stream_event_ctx_type
) {
156 BT_LOGD("Creating initial stream event context field: ft-addr=%p",
157 validation_output
->stream_event_ctx_type
);
158 *stream_event_context_field
= create_field_func(
159 validation_output
->stream_event_ctx_type
);
160 if (!*stream_event_context_field
) {
161 BT_LOGE_STR("Cannot create initial stream event context field object.");
166 if (validation_output
->event_context_type
) {
167 BT_LOGD("Creating initial event context field: ft-addr=%p",
168 validation_output
->event_context_type
);
169 *context_field
= create_field_func(
170 validation_output
->event_context_type
);
171 if (!*context_field
) {
172 BT_LOGE_STR("Cannot create initial event context field object.");
177 if (validation_output
->event_payload_type
) {
178 BT_LOGD("Creating initial event payload field: ft-addr=%p",
179 validation_output
->event_payload_type
);
180 *payload_field
= create_field_func(
181 validation_output
->event_payload_type
);
182 if (!*payload_field
) {
183 BT_LOGE_STR("Cannot create initial event payload field object.");
192 release_header_field_func(*header_field
, stream_class
);
195 if (*stream_event_context_field
) {
196 release_field_func(*stream_event_context_field
);
199 if (*context_field
) {
200 release_field_func(*context_field
);
203 if (*payload_field
) {
204 release_field_func(*payload_field
);
214 int _bt_ctf_event_common_validate(struct bt_ctf_event_common
*event
)
217 struct bt_ctf_stream_class_common
*stream_class
;
220 if (event
->header_field
) {
221 ret
= bt_ctf_field_common_validate_recursive(
222 event
->header_field
->field
);
224 BT_ASSERT_PRE_MSG("Invalid event's header field: "
225 "event-addr=%p, field-addr=%p",
226 event
, event
->header_field
->field
);
231 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event
->class);
234 * We should not have been able to create the event without associating
235 * the event class to a stream class.
237 BT_ASSERT(stream_class
);
239 if (stream_class
->event_context_field_type
) {
240 ret
= bt_ctf_field_common_validate_recursive(
241 event
->stream_event_context_field
);
243 BT_ASSERT_PRE_MSG("Invalid event's stream event context field: "
244 "event-addr=%p, field-addr=%p",
245 event
, event
->stream_event_context_field
);
250 if (event
->class->context_field_type
) {
251 ret
= bt_ctf_field_common_validate_recursive(event
->context_field
);
253 BT_ASSERT_PRE_MSG("Invalid event's payload field: "
254 "event-addr=%p, field-addr=%p",
255 event
, event
->context_field
);
260 ret
= bt_ctf_field_common_validate_recursive(event
->payload_field
);
262 BT_ASSERT_PRE_MSG("Invalid event's payload field: "
263 "event-addr=%p, field-addr=%p",
264 event
, event
->payload_field
);
273 void _bt_ctf_event_common_set_is_frozen(struct bt_ctf_event_common
*event
,
277 BT_LOGD("Freezing event: addr=%p, "
278 "event-class-name=\"%s\", event-class-id=%" PRId64
,
279 event
, bt_ctf_event_class_common_get_name(event
->class),
280 bt_ctf_event_class_common_get_id(event
->class));
282 if (event
->header_field
) {
283 BT_LOGD_STR("Freezing event's header field.");
284 bt_ctf_field_common_set_is_frozen_recursive(
285 event
->header_field
->field
, is_frozen
);
288 if (event
->stream_event_context_field
) {
289 BT_LOGD_STR("Freezing event's stream event context field.");
290 bt_ctf_field_common_set_is_frozen_recursive(
291 event
->stream_event_context_field
, is_frozen
);
294 if (event
->context_field
) {
295 BT_LOGD_STR("Freezing event's context field.");
296 bt_ctf_field_common_set_is_frozen_recursive(event
->context_field
,
300 if (event
->payload_field
) {
301 BT_LOGD_STR("Freezing event's payload field.");
302 bt_ctf_field_common_set_is_frozen_recursive(event
->payload_field
,
306 event
->frozen
= is_frozen
;
310 int bt_ctf_event_common_initialize(struct bt_ctf_event_common
*event
,
311 struct bt_ctf_event_class_common
*event_class
,
312 struct bt_ctf_clock_class
*init_expected_clock_class
,
313 bool is_shared_with_parent
, bt_object_release_func release_func
,
314 bt_ctf_validation_flag_copy_field_type_func field_type_copy_func
,
315 bool must_be_in_trace
,
316 int (*map_clock_classes_func
)(struct bt_ctf_stream_class_common
*stream_class
,
317 struct bt_ctf_field_type_common
*packet_context_field_type
,
318 struct bt_ctf_field_type_common
*event_header_field_type
),
319 create_field_func create_field_func
,
320 release_field_func release_field_func
,
321 create_header_field_func create_header_field_func
,
322 release_header_field_func release_header_field_func
)
325 struct bt_ctf_trace_common
*trace
= NULL
;
326 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
327 struct bt_ctf_field_wrapper
*event_header
= NULL
;
328 struct bt_ctf_field_common
*stream_event_context
= NULL
;
329 struct bt_ctf_field_common
*event_context
= NULL
;
330 struct bt_ctf_field_common
*event_payload
= NULL
;
331 struct bt_ctf_validation_output validation_output
= { 0 };
332 struct bt_ctf_clock_class
*expected_clock_class
=
333 init_expected_clock_class
? bt_object_get_ref(init_expected_clock_class
) :
336 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
337 BT_LOGD("Initializing common event object: event-class-addr=%p, "
338 "event-class-name=\"%s\", event-class-id=%" PRId64
,
339 event_class
, bt_ctf_event_class_common_get_name(event_class
),
340 bt_ctf_event_class_common_get_id(event_class
));
342 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
343 BT_ASSERT_PRE(stream_class
,
344 "Event class is not part of a stream class: event-class-addr=%p",
347 /* The event class was frozen when added to its stream class */
348 BT_ASSERT(event_class
->frozen
);
349 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
351 if (must_be_in_trace
) {
353 "Event class's stream class is not part of a trace: "
354 "ec-addr=%p, sc-addr=%p", event_class
, stream_class
);
358 * This must be called before anything that can fail because on
359 * failure, the caller releases the reference to `event` to
362 if (is_shared_with_parent
) {
363 bt_object_init_shared_with_parent(&event
->base
, release_func
);
365 bt_object_init_unique(&event
->base
);
368 if (!stream_class
->frozen
) {
370 * Because this function freezes the stream class,
371 * validate that this stream class contains at most a
372 * single clock class so that we set its expected clock
373 * class for future checks.
375 ret
= bt_ctf_stream_class_common_validate_single_clock_class(
376 stream_class
, &expected_clock_class
);
378 BT_LOGW("Event class's stream class or one of its event "
379 "classes contains a field type which is not "
380 "recursively mapped to the expected "
382 "stream-class-addr=%p, "
383 "stream-class-id=%" PRId64
", "
384 "stream-class-name=\"%s\", "
385 "expected-clock-class-addr=%p, "
386 "expected-clock-class-name=\"%s\"",
388 bt_ctf_stream_class_common_get_id(stream_class
),
389 bt_ctf_stream_class_common_get_name(stream_class
),
390 expected_clock_class
,
391 expected_clock_class
?
392 bt_ctf_clock_class_get_name(expected_clock_class
) :
398 /* Validate the trace, the stream class, and the event class */
399 ret
= bt_ctf_event_common_validate_types_for_create(
400 event_class
, &validation_output
, field_type_copy_func
);
402 /* bt_ctf_event_common_validate_types_for_create() logs errors */
406 if (map_clock_classes_func
) {
408 * Safe to automatically map selected fields to the
409 * stream's clock's class here because the stream class
410 * is about to be frozen.
412 if (map_clock_classes_func(stream_class
,
413 validation_output
.packet_context_type
,
414 validation_output
.event_header_type
)) {
415 BT_LOGW_STR("Cannot automatically map selected stream class's "
416 "field types to stream class's clock's class.");
422 * event does not share a common ancestor with the event class; it has
423 * to guarantee its existence by holding a reference. This reference
424 * shall be released once the event is associated to a stream since,
425 * from that point, the event and its class will share the same
428 event
->class = bt_object_get_ref(event_class
);
430 ret
= bt_ctf_event_common_create_fields(stream_class
,
432 create_field_func
, release_field_func
,
433 create_header_field_func
, release_header_field_func
,
434 &event_header
, &stream_event_context
, &event_context
,
437 /* bt_ctf_event_common_create_fields() logs errors */
442 * At this point all the fields are created, potentially from
443 * validated copies of field types, so that the field types and
444 * fields can be replaced in the trace, stream class,
445 * event class, and created event.
447 bt_ctf_validation_replace_types(trace
, stream_class
, event_class
,
449 BT_CTF_VALIDATION_FLAG_STREAM
| BT_CTF_VALIDATION_FLAG_EVENT
);
450 event
->header_field
= event_header
;
452 event
->stream_event_context_field
= stream_event_context
;
453 stream_event_context
= NULL
;
454 event
->context_field
= event_context
;
455 event_context
= NULL
;
456 event
->payload_field
= event_payload
;
457 event_payload
= NULL
;
460 * Put what was not moved in bt_ctf_validation_replace_types().
462 bt_ctf_validation_output_put_types(&validation_output
);
465 * Freeze the stream class since the event header must not be changed
468 bt_ctf_stream_class_common_freeze(stream_class
);
471 * It is safe to set the stream class's unique clock class
472 * now because the stream class is frozen.
474 if (expected_clock_class
) {
475 BT_OBJECT_MOVE_REF(stream_class
->clock_class
, expected_clock_class
);
479 * Mark stream class, and event class as valid since
480 * they're all frozen now.
482 stream_class
->valid
= 1;
483 event_class
->valid
= 1;
485 /* Put stuff we borrowed from the event class */
486 BT_LOGD("Initialized event object: addr=%p, event-class-name=\"%s\", "
487 "event-class-id=%" PRId64
,
488 event
, bt_ctf_event_class_common_get_name(event
->class),
489 bt_ctf_event_class_common_get_id(event
->class));
493 bt_ctf_validation_output_put_types(&validation_output
);
494 bt_object_put_ref(expected_clock_class
);
497 release_header_field_func(event_header
, stream_class
);
500 if (stream_event_context
) {
501 release_field_func(stream_event_context
);
505 release_field_func(event_context
);
509 release_field_func(event_payload
);
518 int map_clock_classes_func(struct bt_ctf_stream_class_common
*stream_class
,
519 struct bt_ctf_field_type_common
*packet_context_type
,
520 struct bt_ctf_field_type_common
*event_header_type
)
522 int ret
= bt_ctf_stream_class_map_clock_class(
523 BT_CTF_FROM_COMMON(stream_class
),
524 BT_CTF_FROM_COMMON(packet_context_type
),
525 BT_CTF_FROM_COMMON(event_header_type
));
528 BT_LOGW_STR("Cannot automatically map selected stream class's field types to stream class's clock's class.");
535 void destroy_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
)
537 BT_ASSERT(field_wrapper
);
538 bt_object_put_ref(field_wrapper
->field
);
539 bt_ctf_field_wrapper_destroy(field_wrapper
);
543 struct bt_ctf_field_wrapper
*create_event_header_field(
544 struct bt_ctf_stream_class
*stream_class
,
545 struct bt_ctf_field_type_common
*ft
)
547 struct bt_ctf_field_wrapper
*field_wrapper
= NULL
;
548 struct bt_ctf_field
*field
= bt_ctf_field_create((void *) ft
);
554 field_wrapper
= bt_ctf_field_wrapper_new(NULL
);
555 if (!field_wrapper
) {
559 field_wrapper
->field
= (void *) field
;
564 bt_object_put_ref(field
);
567 destroy_event_header_field(field_wrapper
);
568 field_wrapper
= NULL
;
572 return field_wrapper
;
576 void release_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
577 struct bt_ctf_event_common
*event_common
)
579 BT_ASSERT(field_wrapper
);
580 BT_OBJECT_PUT_REF_AND_RESET(field_wrapper
->field
);
581 bt_ctf_field_wrapper_destroy(field_wrapper
);
585 void bt_ctf_event_destroy(struct bt_object
*obj
)
587 bt_ctf_event_common_finalize(obj
, (void *) bt_object_put_ref
,
588 (void *) release_event_header_field
);
592 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
595 struct bt_ctf_event
*event
= NULL
;
596 struct bt_ctf_clock_class
*expected_clock_class
= NULL
;
598 event
= g_new0(struct bt_ctf_event
, 1);
600 BT_LOGE_STR("Failed to allocate one CTF writer event.");
605 struct bt_ctf_stream_class
*stream_class
=
606 BT_CTF_FROM_COMMON(bt_ctf_event_class_common_borrow_stream_class(
607 BT_CTF_TO_COMMON(event_class
)));
609 if (stream_class
&& stream_class
->clock
) {
610 expected_clock_class
= stream_class
->clock
->clock_class
;
614 ret
= bt_ctf_event_common_initialize(BT_CTF_TO_COMMON(event
),
615 BT_CTF_TO_COMMON(event_class
), expected_clock_class
,
616 true, bt_ctf_event_destroy
,
617 (bt_ctf_validation_flag_copy_field_type_func
)
618 bt_ctf_field_type_copy
,
619 false, map_clock_classes_func
,
620 (create_field_func
) bt_ctf_field_create
,
621 (release_field_func
) bt_object_put_ref
,
622 (create_header_field_func
) create_event_header_field
,
623 (release_header_field_func
) destroy_event_header_field
);
625 /* bt_ctf_event_common_initialize() logs errors */
632 BT_OBJECT_PUT_REF_AND_RESET(event
);
638 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
640 BT_ASSERT_PRE_NON_NULL(event
, "Event");
641 return bt_object_get_ref(bt_ctf_event_common_borrow_class(BT_CTF_TO_COMMON(event
)));
645 struct bt_ctf_stream
*bt_ctf_event_borrow_stream(struct bt_ctf_event
*event
)
648 return (struct bt_ctf_stream
*)
649 bt_object_borrow_parent(&BT_CTF_TO_COMMON(event
)->base
);
652 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
654 BT_ASSERT_PRE_NON_NULL(event
, "Event");
655 return bt_object_get_ref(bt_ctf_event_borrow_stream(event
));
658 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
, const char *name
,
659 struct bt_ctf_field
*field
)
661 BT_ASSERT_PRE_NON_NULL(event
, "Event");
662 BT_ASSERT_PRE_NON_NULL(field
, "Payload field");
663 BT_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
664 return bt_ctf_field_structure_set_field_by_name(
665 (void *) event
->common
.payload_field
, name
, field
);
668 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
671 struct bt_ctf_field
*field
= NULL
;
673 BT_ASSERT_PRE_NON_NULL(event
, "Event");
676 field
= bt_ctf_field_structure_get_field_by_name(
677 BT_CTF_FROM_COMMON(event
->common
.payload_field
), name
);
679 field
= BT_CTF_FROM_COMMON(event
->common
.payload_field
);
680 bt_object_get_ref(field
);
686 struct bt_ctf_field
*bt_ctf_event_get_payload_field(
687 struct bt_ctf_event
*event
)
689 return bt_object_get_ref(bt_ctf_event_common_borrow_payload(BT_CTF_TO_COMMON(event
)));
692 struct bt_ctf_field
*bt_ctf_event_get_header(struct bt_ctf_event
*event
)
694 return bt_object_get_ref(bt_ctf_event_common_borrow_header(BT_CTF_TO_COMMON(event
)));
697 struct bt_ctf_field
*bt_ctf_event_get_context(struct bt_ctf_event
*event
)
699 return bt_object_get_ref(bt_ctf_event_common_borrow_context(BT_CTF_TO_COMMON(event
)));
702 struct bt_ctf_field
*bt_ctf_event_get_stream_event_context(
703 struct bt_ctf_event
*event
)
705 return bt_object_get_ref(bt_ctf_event_common_borrow_stream_event_context(
706 BT_CTF_TO_COMMON(event
)));
710 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
711 struct bt_ctf_stream_pos
*pos
,
712 enum bt_ctf_byte_order native_byte_order
)
719 BT_LOGV_STR("Serializing event's context field.");
720 if (event
->common
.context_field
) {
721 ret
= bt_ctf_field_serialize_recursive(
722 (void *) event
->common
.context_field
, pos
,
725 BT_LOGW("Cannot serialize event's context field: "
726 "event-addr=%p, event-class-name=\"%s\", "
727 "event-class-id=%" PRId64
,
729 bt_ctf_event_class_common_get_name(event
->common
.class),
730 bt_ctf_event_class_common_get_id(event
->common
.class));
735 BT_LOGV_STR("Serializing event's payload field.");
736 if (event
->common
.payload_field
) {
737 ret
= bt_ctf_field_serialize_recursive(
738 (void *) event
->common
.payload_field
, pos
,
741 BT_LOGW("Cannot serialize event's payload field: "
742 "event-addr=%p, event-class-name=\"%s\", "
743 "event-class-id=%" PRId64
,
745 bt_ctf_event_class_common_get_name(event
->common
.class),
746 bt_ctf_event_class_common_get_id(event
->common
.class));
756 void _bt_ctf_event_freeze(struct bt_ctf_event
*event
)
758 _bt_ctf_event_common_set_is_frozen(BT_CTF_TO_COMMON(event
), true);
761 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
762 struct bt_ctf_field
*header
)
764 BT_ASSERT_PRE_NON_NULL(event
, "Event");
765 BT_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
768 * Ensure the provided header's type matches the one registered to the
772 BT_ASSERT_PRE(bt_ctf_field_type_common_compare(
773 ((struct bt_ctf_field_common
*) header
)->type
,
774 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
) == 0,
775 "Header field's type is different from the "
776 "expected field type: event-addr=%p, ft-addr=%p, "
777 "expected-ft-addr=%p",
778 event
, ((struct bt_ctf_field_common
*) header
)->type
,
779 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
);
781 BT_ASSERT_PRE(!bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
,
782 "Setting no event header field, "
783 "but event header field type is not NULL: ",
784 "event-addr=%p, header-ft-addr=%p",
786 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
);
789 bt_object_put_ref(event
->common
.header_field
->field
);
790 event
->common
.header_field
->field
= bt_object_get_ref(header
);
791 BT_LOGV("Set event's header field: event-addr=%p, "
792 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
793 "header-field-addr=%p",
794 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
795 bt_ctf_event_class_common_get_id(event
->common
.class), header
);
799 int bt_ctf_event_common_set_payload(struct bt_ctf_event
*event
,
800 struct bt_ctf_field
*payload
)
802 BT_ASSERT_PRE_NON_NULL(event
, "Event");
803 BT_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
806 BT_ASSERT_PRE(bt_ctf_field_type_common_compare(
807 ((struct bt_ctf_field_common
*) payload
)->type
,
808 event
->common
.class->payload_field_type
) == 0,
809 "Payload field's type is different from the "
810 "expected field type: event-addr=%p, ft-addr=%p, "
811 "expected-ft-addr=%p",
813 ((struct bt_ctf_field_common
*) payload
)->type
,
814 event
->common
.class->payload_field_type
);
816 BT_ASSERT_PRE(!event
->common
.class->payload_field_type
,
817 "Setting no event payload field, "
818 "but event payload field type is not NULL: ",
819 "event-addr=%p, payload-ft-addr=%p",
820 event
, event
->common
.class->payload_field_type
);
823 bt_object_put_ref(event
->common
.payload_field
);
824 event
->common
.payload_field
= bt_object_get_ref(payload
);
825 BT_LOGV("Set event's payload field: event-addr=%p, "
826 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
827 "payload-field-addr=%p",
828 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
829 bt_ctf_event_class_common_get_id(event
->common
.class), payload
);
833 int bt_ctf_event_set_context(struct bt_ctf_event
*event
,
834 struct bt_ctf_field
*context
)
836 BT_ASSERT_PRE_NON_NULL(event
, "Event");
837 BT_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
840 BT_ASSERT_PRE(bt_ctf_field_type_common_compare(
841 ((struct bt_ctf_field_common
*) context
)->type
,
842 event
->common
.class->context_field_type
) == 0,
843 "Context field's type is different from the "
844 "expected field type: event-addr=%p, ft-addr=%p, "
845 "expected-ft-addr=%p",
846 event
, ((struct bt_ctf_field_common
*) context
)->type
,
847 event
->common
.class->context_field_type
);
849 BT_ASSERT_PRE(!event
->common
.class->context_field_type
,
850 "Setting no event context field, "
851 "but event context field type is not NULL: ",
852 "event-addr=%p, context-ft-addr=%p",
853 event
, event
->common
.class->context_field_type
);
856 bt_object_put_ref(event
->common
.context_field
);
857 event
->common
.context_field
= bt_object_get_ref(context
);
858 BT_LOGV("Set event's context field: event-addr=%p, "
859 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
860 "context-field-addr=%p",
861 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
862 bt_ctf_event_class_common_get_id(event
->common
.class), context
);
866 int bt_ctf_event_set_stream_event_context(struct bt_ctf_event
*event
,
867 struct bt_ctf_field
*stream_event_context
)
869 BT_ASSERT_PRE_NON_NULL(event
, "Event");
870 BT_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
872 if (stream_event_context
) {
873 BT_ASSERT_PRE(bt_ctf_field_type_common_compare(
874 ((struct bt_ctf_field_common
*) stream_event_context
)->type
,
875 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
) == 0,
876 "Stream event context field's type is different from the "
877 "expected field type: event-addr=%p, ft-addr=%p, "
878 "expected-ft-addr=%p",
880 ((struct bt_ctf_field_common
*) stream_event_context
)->type
,
881 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
);
883 BT_ASSERT_PRE(!bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
,
884 "Setting no stream event context field, "
885 "but stream event context field type is not NULL: ",
886 "event-addr=%p, context-ft-addr=%p",
888 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
);
891 bt_object_put_ref(event
->common
.stream_event_context_field
);
892 event
->common
.stream_event_context_field
= bt_object_get_ref(stream_event_context
);
893 BT_LOGV("Set event's stream event context field: event-addr=%p, "
894 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
895 "stream-event-context-field-addr=%p",
896 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
897 bt_ctf_event_class_common_get_id(event
->common
.class),
898 stream_event_context
);