2 * SPDX-License-Identifier: MIT
4 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
8 #define BT_LOG_TAG "CTF-WRITER/EVENT"
14 #include <babeltrace2-ctf-writer/event.h>
15 #include <babeltrace2-ctf-writer/fields.h>
16 #include <babeltrace2-ctf-writer/field-types.h>
17 #include <babeltrace2-ctf-writer/object.h>
18 #include <babeltrace2-ctf-writer/stream-class.h>
19 #include <babeltrace2-ctf-writer/trace.h>
20 #include <babeltrace2-ctf-writer/utils.h>
22 #include "common/assert.h"
23 #include "compat/compiler.h"
25 #include "assert-pre.h"
26 #include "attributes.h"
27 #include "clock-class.h"
29 #include "event-class.h"
32 #include "field-types.h"
33 #include "stream-class.h"
36 #include "validation.h"
39 int bt_ctf_event_common_validate_types_for_create(
40 struct bt_ctf_event_class_common
*event_class
,
41 struct bt_ctf_validation_output
*validation_output
,
42 bt_ctf_validation_flag_copy_field_type_func copy_field_type_func
)
45 enum bt_ctf_validation_flag validation_flags
=
46 BT_CTF_VALIDATION_FLAG_STREAM
|
47 BT_CTF_VALIDATION_FLAG_EVENT
;
48 struct bt_ctf_trace_common
*trace
= NULL
;
49 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
50 struct bt_ctf_field_type_common
*packet_header_type
= NULL
;
51 struct bt_ctf_field_type_common
*packet_context_type
= NULL
;
52 struct bt_ctf_field_type_common
*event_header_type
= NULL
;
53 struct bt_ctf_field_type_common
*stream_event_ctx_type
= NULL
;
54 struct bt_ctf_field_type_common
*event_context_type
= NULL
;
55 struct bt_ctf_field_type_common
*event_payload_type
= NULL
;
57 struct bt_ctf_private_value
*environment
= NULL
;
59 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
60 BT_ASSERT_DBG(stream_class
);
61 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
63 BT_LOGD_STR("Event class is part of a trace.");
65 bt_ctf_trace_common_borrow_packet_header_field_type(trace
);
66 trace_valid
= trace
->valid
;
67 BT_ASSERT_DBG(trace_valid
);
68 environment
= trace
->environment
;
72 bt_ctf_stream_class_common_borrow_packet_context_field_type(
75 bt_ctf_stream_class_common_borrow_event_header_field_type(
77 stream_event_ctx_type
=
78 bt_ctf_stream_class_common_borrow_event_context_field_type(
81 bt_ctf_event_class_common_borrow_context_field_type(event_class
);
83 bt_ctf_event_class_common_borrow_payload_field_type(event_class
);
84 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
85 packet_context_type
, event_header_type
, stream_event_ctx_type
,
86 event_context_type
, event_payload_type
, trace_valid
,
87 stream_class
->valid
, event_class
->valid
,
88 validation_output
, validation_flags
, copy_field_type_func
);
91 * This means something went wrong during the validation
92 * process, not that the objects are invalid.
94 BT_LOGE("Failed to validate event and parents: ret=%d", ret
);
98 if ((validation_output
->valid_flags
& validation_flags
) !=
100 /* Invalid trace/stream class/event class */
101 BT_LOGW("Invalid trace, stream class, or event class: "
102 "valid-flags=0x%x", validation_output
->valid_flags
);
109 bt_ctf_validation_output_put_types(validation_output
);
117 int bt_ctf_event_common_create_fields(
118 struct bt_ctf_stream_class_common
*stream_class
,
119 struct bt_ctf_validation_output
*validation_output
,
120 create_field_func_type create_field_func
,
121 release_field_func_type release_field_func
,
122 create_header_field_func_type create_header_field_func
,
123 release_header_field_func_type release_header_field_func
,
124 struct bt_ctf_field_wrapper
**header_field
,
125 struct bt_ctf_field_common
**stream_event_context_field
,
126 struct bt_ctf_field_common
**context_field
,
127 struct bt_ctf_field_common
**payload_field
)
131 if (validation_output
->event_header_type
) {
132 BT_LOGD("Creating initial event header field: ft-addr=%p",
133 validation_output
->event_header_type
);
135 create_header_field_func(stream_class
,
136 validation_output
->event_header_type
);
137 if (!*header_field
) {
138 BT_LOGE_STR("Cannot create initial event header field object.");
143 if (validation_output
->stream_event_ctx_type
) {
144 BT_LOGD("Creating initial stream event context field: ft-addr=%p",
145 validation_output
->stream_event_ctx_type
);
146 *stream_event_context_field
= create_field_func(
147 validation_output
->stream_event_ctx_type
);
148 if (!*stream_event_context_field
) {
149 BT_LOGE_STR("Cannot create initial stream event context field object.");
154 if (validation_output
->event_context_type
) {
155 BT_LOGD("Creating initial event context field: ft-addr=%p",
156 validation_output
->event_context_type
);
157 *context_field
= create_field_func(
158 validation_output
->event_context_type
);
159 if (!*context_field
) {
160 BT_LOGE_STR("Cannot create initial event context field object.");
165 if (validation_output
->event_payload_type
) {
166 BT_LOGD("Creating initial event payload field: ft-addr=%p",
167 validation_output
->event_payload_type
);
168 *payload_field
= create_field_func(
169 validation_output
->event_payload_type
);
170 if (!*payload_field
) {
171 BT_LOGE_STR("Cannot create initial event payload field object.");
180 release_header_field_func(*header_field
, stream_class
);
183 if (*stream_event_context_field
) {
184 release_field_func(*stream_event_context_field
);
187 if (*context_field
) {
188 release_field_func(*context_field
);
191 if (*payload_field
) {
192 release_field_func(*payload_field
);
201 int _bt_ctf_event_common_validate(struct bt_ctf_event_common
*event
)
204 struct bt_ctf_stream_class_common
*stream_class
;
206 BT_ASSERT_DBG(event
);
207 if (event
->header_field
) {
208 ret
= bt_ctf_field_common_validate_recursive(
209 event
->header_field
->field
);
211 BT_CTF_ASSERT_PRE_MSG("Invalid event's header field: "
212 "event-addr=%p, field-addr=%p",
213 event
, event
->header_field
->field
);
218 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event
->class);
221 * We should not have been able to create the event without associating
222 * the event class to a stream class.
224 BT_ASSERT_DBG(stream_class
);
226 if (stream_class
->event_context_field_type
) {
227 ret
= bt_ctf_field_common_validate_recursive(
228 event
->stream_event_context_field
);
230 BT_CTF_ASSERT_PRE_MSG("Invalid event's stream event context field: "
231 "event-addr=%p, field-addr=%p",
232 event
, event
->stream_event_context_field
);
237 if (event
->class->context_field_type
) {
238 ret
= bt_ctf_field_common_validate_recursive(event
->context_field
);
240 BT_CTF_ASSERT_PRE_MSG("Invalid event's payload field: "
241 "event-addr=%p, field-addr=%p",
242 event
, event
->context_field
);
247 ret
= bt_ctf_field_common_validate_recursive(event
->payload_field
);
249 BT_CTF_ASSERT_PRE_MSG("Invalid event's payload field: "
250 "event-addr=%p, field-addr=%p",
251 event
, event
->payload_field
);
259 void _bt_ctf_event_common_set_is_frozen(struct bt_ctf_event_common
*event
,
262 BT_ASSERT_DBG(event
);
263 BT_LOGD("Freezing event: addr=%p, "
264 "event-class-name=\"%s\", event-class-id=%" PRId64
,
265 event
, bt_ctf_event_class_common_get_name(event
->class),
266 bt_ctf_event_class_common_get_id(event
->class));
268 if (event
->header_field
) {
269 BT_LOGD_STR("Freezing event's header field.");
270 bt_ctf_field_common_set_is_frozen_recursive(
271 event
->header_field
->field
, is_frozen
);
274 if (event
->stream_event_context_field
) {
275 BT_LOGD_STR("Freezing event's stream event context field.");
276 bt_ctf_field_common_set_is_frozen_recursive(
277 event
->stream_event_context_field
, is_frozen
);
280 if (event
->context_field
) {
281 BT_LOGD_STR("Freezing event's context field.");
282 bt_ctf_field_common_set_is_frozen_recursive(event
->context_field
,
286 if (event
->payload_field
) {
287 BT_LOGD_STR("Freezing event's payload field.");
288 bt_ctf_field_common_set_is_frozen_recursive(event
->payload_field
,
292 event
->frozen
= is_frozen
;
295 int bt_ctf_event_common_initialize(struct bt_ctf_event_common
*event
,
296 struct bt_ctf_event_class_common
*event_class
,
297 struct bt_ctf_clock_class
*init_expected_clock_class
,
298 bool is_shared_with_parent
, bt_ctf_object_release_func release_func
,
299 bt_ctf_validation_flag_copy_field_type_func field_type_copy_func
,
300 bool must_be_in_trace
,
301 int (*map_clock_classes_func
)(struct bt_ctf_stream_class_common
*stream_class
,
302 struct bt_ctf_field_type_common
*packet_context_field_type
,
303 struct bt_ctf_field_type_common
*event_header_field_type
),
304 create_field_func_type create_field_func
,
305 release_field_func_type release_field_func
,
306 create_header_field_func_type create_header_field_func
,
307 release_header_field_func_type release_header_field_func
)
310 struct bt_ctf_trace_common
*trace
= NULL
;
311 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
312 struct bt_ctf_field_wrapper
*event_header
= NULL
;
313 struct bt_ctf_field_common
*stream_event_context
= NULL
;
314 struct bt_ctf_field_common
*event_context
= NULL
;
315 struct bt_ctf_field_common
*event_payload
= NULL
;
316 struct bt_ctf_validation_output validation_output
= { 0 };
317 struct bt_ctf_clock_class
*expected_clock_class
=
318 init_expected_clock_class
? bt_ctf_object_get_ref(init_expected_clock_class
) :
321 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
322 BT_LOGD("Initializing common event object: event-class-addr=%p, "
323 "event-class-name=\"%s\", event-class-id=%" PRId64
,
324 event_class
, bt_ctf_event_class_common_get_name(event_class
),
325 bt_ctf_event_class_common_get_id(event_class
));
327 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
328 BT_CTF_ASSERT_PRE(stream_class
,
329 "Event class is not part of a stream class: event-class-addr=%p",
332 /* The event class was frozen when added to its stream class */
333 BT_ASSERT_DBG(event_class
->frozen
);
334 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
336 if (must_be_in_trace
) {
337 BT_CTF_ASSERT_PRE(trace
,
338 "Event class's stream class is not part of a trace: "
339 "ec-addr=%p, sc-addr=%p", event_class
, stream_class
);
343 * This must be called before anything that can fail because on
344 * failure, the caller releases the reference to `event` to
347 if (is_shared_with_parent
) {
348 bt_ctf_object_init_shared_with_parent(&event
->base
, release_func
);
350 bt_ctf_object_init_unique(&event
->base
);
353 if (!stream_class
->frozen
) {
355 * Because this function freezes the stream class,
356 * validate that this stream class contains at most a
357 * single clock class so that we set its expected clock
358 * class for future checks.
360 ret
= bt_ctf_stream_class_common_validate_single_clock_class(
361 stream_class
, &expected_clock_class
);
363 BT_LOGW("Event class's stream class or one of its event "
364 "classes contains a field type which is not "
365 "recursively mapped to the expected "
367 "stream-class-addr=%p, "
368 "stream-class-id=%" PRId64
", "
369 "stream-class-name=\"%s\", "
370 "expected-clock-class-addr=%p, "
371 "expected-clock-class-name=\"%s\"",
373 bt_ctf_stream_class_common_get_id(stream_class
),
374 bt_ctf_stream_class_common_get_name(stream_class
),
375 expected_clock_class
,
376 expected_clock_class
?
377 bt_ctf_clock_class_get_name(expected_clock_class
) :
383 /* Validate the trace, the stream class, and the event class */
384 ret
= bt_ctf_event_common_validate_types_for_create(
385 event_class
, &validation_output
, field_type_copy_func
);
387 /* bt_ctf_event_common_validate_types_for_create() logs errors */
391 if (map_clock_classes_func
) {
393 * Safe to automatically map selected fields to the
394 * stream's clock's class here because the stream class
395 * is about to be frozen.
397 if (map_clock_classes_func(stream_class
,
398 validation_output
.packet_context_type
,
399 validation_output
.event_header_type
)) {
400 BT_LOGW_STR("Cannot automatically map selected stream class's "
401 "field types to stream class's clock's class.");
407 * event does not share a common ancestor with the event class; it has
408 * to guarantee its existence by holding a reference. This reference
409 * shall be released once the event is associated to a stream since,
410 * from that point, the event and its class will share the same
413 event
->class = bt_ctf_object_get_ref(event_class
);
415 ret
= bt_ctf_event_common_create_fields(stream_class
,
417 create_field_func
, release_field_func
,
418 create_header_field_func
, release_header_field_func
,
419 &event_header
, &stream_event_context
, &event_context
,
422 /* bt_ctf_event_common_create_fields() logs errors */
427 * At this point all the fields are created, potentially from
428 * validated copies of field types, so that the field types and
429 * fields can be replaced in the trace, stream class,
430 * event class, and created event.
432 bt_ctf_validation_replace_types(trace
, stream_class
, event_class
,
434 BT_CTF_VALIDATION_FLAG_STREAM
| BT_CTF_VALIDATION_FLAG_EVENT
);
435 event
->header_field
= event_header
;
437 event
->stream_event_context_field
= stream_event_context
;
438 stream_event_context
= NULL
;
439 event
->context_field
= event_context
;
440 event_context
= NULL
;
441 event
->payload_field
= event_payload
;
442 event_payload
= NULL
;
445 * Put what was not moved in bt_ctf_validation_replace_types().
447 bt_ctf_validation_output_put_types(&validation_output
);
450 * Freeze the stream class since the event header must not be changed
453 bt_ctf_stream_class_common_freeze(stream_class
);
456 * It is safe to set the stream class's unique clock class
457 * now because the stream class is frozen.
459 if (expected_clock_class
) {
460 BT_CTF_OBJECT_MOVE_REF(stream_class
->clock_class
, expected_clock_class
);
464 * Mark stream class, and event class as valid since
465 * they're all frozen now.
467 stream_class
->valid
= 1;
468 event_class
->valid
= 1;
470 /* Put stuff we borrowed from the event class */
471 BT_LOGD("Initialized event object: addr=%p, event-class-name=\"%s\", "
472 "event-class-id=%" PRId64
,
473 event
, bt_ctf_event_class_common_get_name(event
->class),
474 bt_ctf_event_class_common_get_id(event
->class));
478 bt_ctf_validation_output_put_types(&validation_output
);
479 bt_ctf_object_put_ref(expected_clock_class
);
482 release_header_field_func(event_header
, stream_class
);
485 if (stream_event_context
) {
486 release_field_func(stream_event_context
);
490 release_field_func(event_context
);
494 release_field_func(event_payload
);
504 int map_clock_classes_func(struct bt_ctf_stream_class_common
*stream_class
,
505 struct bt_ctf_field_type_common
*packet_context_type
,
506 struct bt_ctf_field_type_common
*event_header_type
)
508 int ret
= bt_ctf_stream_class_map_clock_class(
509 BT_CTF_FROM_COMMON(stream_class
),
510 BT_CTF_FROM_COMMON(packet_context_type
),
511 BT_CTF_FROM_COMMON(event_header_type
));
514 BT_LOGW_STR("Cannot automatically map selected stream class's field types to stream class's clock's class.");
521 void destroy_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
522 struct bt_ctf_stream_class
*stream_class
__attribute__((unused
)))
524 BT_ASSERT_DBG(field_wrapper
);
525 bt_ctf_object_put_ref(field_wrapper
->field
);
526 bt_ctf_field_wrapper_destroy(field_wrapper
);
530 struct bt_ctf_field_wrapper
*create_event_header_field(
531 struct bt_ctf_stream_class
*stream_class
,
532 struct bt_ctf_field_type_common
*ft
)
534 struct bt_ctf_field_wrapper
*field_wrapper
= NULL
;
535 struct bt_ctf_field
*field
= bt_ctf_field_create((void *) ft
);
541 field_wrapper
= bt_ctf_field_wrapper_new(NULL
);
542 if (!field_wrapper
) {
546 field_wrapper
->field
= (void *) field
;
551 bt_ctf_object_put_ref(field
);
554 destroy_event_header_field(field_wrapper
, stream_class
);
555 field_wrapper
= NULL
;
559 return field_wrapper
;
563 void release_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
564 struct bt_ctf_event_common
*event_common
__attribute__((unused
)))
566 BT_ASSERT_DBG(field_wrapper
);
567 BT_CTF_OBJECT_PUT_REF_AND_RESET(field_wrapper
->field
);
568 bt_ctf_field_wrapper_destroy(field_wrapper
);
572 void bt_ctf_event_destroy(struct bt_ctf_object
*obj
)
574 bt_ctf_event_common_finalize(obj
, (void *) bt_ctf_object_put_ref
,
575 (void *) release_event_header_field
);
580 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
583 struct bt_ctf_event
*event
= NULL
;
584 struct bt_ctf_clock_class
*expected_clock_class
= NULL
;
586 event
= g_new0(struct bt_ctf_event
, 1);
588 BT_LOGE_STR("Failed to allocate one CTF writer event.");
593 struct bt_ctf_stream_class
*stream_class
=
594 BT_CTF_FROM_COMMON(bt_ctf_event_class_common_borrow_stream_class(
595 BT_CTF_TO_COMMON(event_class
)));
597 if (stream_class
&& stream_class
->clock
) {
598 expected_clock_class
= stream_class
->clock
->clock_class
;
602 ret
= bt_ctf_event_common_initialize(BT_CTF_TO_COMMON(event
),
603 BT_CTF_TO_COMMON(event_class
), expected_clock_class
,
604 true, bt_ctf_event_destroy
,
605 (bt_ctf_validation_flag_copy_field_type_func
)
606 bt_ctf_field_type_copy
,
607 false, map_clock_classes_func
,
608 (create_field_func_type
) bt_ctf_field_create
,
609 (release_field_func_type
) bt_ctf_object_put_ref
,
610 (create_header_field_func_type
) create_event_header_field
,
611 (release_header_field_func_type
) destroy_event_header_field
);
613 /* bt_ctf_event_common_initialize() logs errors */
620 BT_CTF_OBJECT_PUT_REF_AND_RESET(event
);
627 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
629 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
630 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_class(BT_CTF_TO_COMMON(event
)));
634 struct bt_ctf_stream
*bt_ctf_event_borrow_stream(struct bt_ctf_event
*event
)
636 BT_ASSERT_DBG(event
);
637 return (struct bt_ctf_stream
*)
638 bt_ctf_object_borrow_parent(&BT_CTF_TO_COMMON(event
)->base
);
642 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
644 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
645 return bt_ctf_object_get_ref(bt_ctf_event_borrow_stream(event
));
649 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
, const char *name
,
650 struct bt_ctf_field
*field
)
652 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
653 BT_CTF_ASSERT_PRE_NON_NULL(field
, "Payload field");
654 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
655 return bt_ctf_field_structure_set_field_by_name(
656 (void *) event
->common
.payload_field
, name
, field
);
660 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
663 struct bt_ctf_field
*field
= NULL
;
665 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
668 field
= bt_ctf_field_structure_get_field_by_name(
669 BT_CTF_FROM_COMMON(event
->common
.payload_field
), name
);
671 field
= BT_CTF_FROM_COMMON(event
->common
.payload_field
);
672 bt_ctf_object_get_ref(field
);
679 struct bt_ctf_field
*bt_ctf_event_get_payload_field(
680 struct bt_ctf_event
*event
)
682 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_payload(BT_CTF_TO_COMMON(event
)));
686 struct bt_ctf_field
*bt_ctf_event_get_header(struct bt_ctf_event
*event
)
688 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_header(BT_CTF_TO_COMMON(event
)));
692 struct bt_ctf_field
*bt_ctf_event_get_context(struct bt_ctf_event
*event
)
694 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_context(BT_CTF_TO_COMMON(event
)));
698 struct bt_ctf_field
*bt_ctf_event_get_stream_event_context(
699 struct bt_ctf_event
*event
)
701 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_stream_event_context(
702 BT_CTF_TO_COMMON(event
)));
705 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
706 struct bt_ctfser
*ctfser
,
707 enum bt_ctf_byte_order native_byte_order
)
711 BT_ASSERT_DBG(event
);
712 BT_ASSERT_DBG(ctfser
);
714 BT_LOGT_STR("Serializing event's context field.");
715 if (event
->common
.context_field
) {
716 ret
= bt_ctf_field_serialize_recursive(
717 (void *) event
->common
.context_field
, ctfser
,
720 BT_LOGW("Cannot serialize event's context field: "
721 "event-addr=%p, event-class-name=\"%s\", "
722 "event-class-id=%" PRId64
,
724 bt_ctf_event_class_common_get_name(event
->common
.class),
725 bt_ctf_event_class_common_get_id(event
->common
.class));
730 BT_LOGT_STR("Serializing event's payload field.");
731 if (event
->common
.payload_field
) {
732 ret
= bt_ctf_field_serialize_recursive(
733 (void *) event
->common
.payload_field
, ctfser
,
736 BT_LOGW("Cannot serialize event's payload field: "
737 "event-addr=%p, event-class-name=\"%s\", "
738 "event-class-id=%" PRId64
,
740 bt_ctf_event_class_common_get_name(event
->common
.class),
741 bt_ctf_event_class_common_get_id(event
->common
.class));
751 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
752 struct bt_ctf_field
*header
)
754 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
755 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
758 * Ensure the provided header's type matches the one registered to the
762 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
763 ((struct bt_ctf_field_common
*) header
)->type
,
764 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
) == 0,
765 "Header field's type is different from the "
766 "expected field type: event-addr=%p, ft-addr=%p, "
767 "expected-ft-addr=%p",
768 event
, ((struct bt_ctf_field_common
*) header
)->type
,
769 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
);
771 BT_CTF_ASSERT_PRE(!bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
,
772 "Setting no event header field, "
773 "but event header field type is not NULL: "
774 "event-addr=%p, header-ft-addr=%p",
776 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
);
779 bt_ctf_object_put_ref(event
->common
.header_field
->field
);
780 event
->common
.header_field
->field
= bt_ctf_object_get_ref(header
);
781 BT_LOGT("Set event's header field: event-addr=%p, "
782 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
783 "header-field-addr=%p",
784 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
785 bt_ctf_event_class_common_get_id(event
->common
.class), header
);
789 int bt_ctf_event_common_set_payload(struct bt_ctf_event
*event
,
790 struct bt_ctf_field
*payload
)
792 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
793 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
796 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
797 ((struct bt_ctf_field_common
*) payload
)->type
,
798 event
->common
.class->payload_field_type
) == 0,
799 "Payload field's type is different from the "
800 "expected field type: event-addr=%p, ft-addr=%p, "
801 "expected-ft-addr=%p",
803 ((struct bt_ctf_field_common
*) payload
)->type
,
804 event
->common
.class->payload_field_type
);
806 BT_CTF_ASSERT_PRE(!event
->common
.class->payload_field_type
,
807 "Setting no event payload field, "
808 "but event payload field type is not NULL: "
809 "event-addr=%p, payload-ft-addr=%p",
810 event
, event
->common
.class->payload_field_type
);
813 bt_ctf_object_put_ref(event
->common
.payload_field
);
814 event
->common
.payload_field
= bt_ctf_object_get_ref(payload
);
815 BT_LOGT("Set event's payload field: event-addr=%p, "
816 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
817 "payload-field-addr=%p",
818 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
819 bt_ctf_event_class_common_get_id(event
->common
.class), payload
);
824 int bt_ctf_event_set_context(struct bt_ctf_event
*event
,
825 struct bt_ctf_field
*context
)
827 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
828 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
831 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
832 ((struct bt_ctf_field_common
*) context
)->type
,
833 event
->common
.class->context_field_type
) == 0,
834 "Context field's type is different from the "
835 "expected field type: event-addr=%p, ft-addr=%p, "
836 "expected-ft-addr=%p",
837 event
, ((struct bt_ctf_field_common
*) context
)->type
,
838 event
->common
.class->context_field_type
);
840 BT_CTF_ASSERT_PRE(!event
->common
.class->context_field_type
,
841 "Setting no event context field, "
842 "but event context field type is not NULL: "
843 "event-addr=%p, context-ft-addr=%p",
844 event
, event
->common
.class->context_field_type
);
847 bt_ctf_object_put_ref(event
->common
.context_field
);
848 event
->common
.context_field
= bt_ctf_object_get_ref(context
);
849 BT_LOGT("Set event's context field: event-addr=%p, "
850 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
851 "context-field-addr=%p",
852 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
853 bt_ctf_event_class_common_get_id(event
->common
.class), context
);
858 int bt_ctf_event_set_stream_event_context(struct bt_ctf_event
*event
,
859 struct bt_ctf_field
*stream_event_context
)
861 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
862 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
864 if (stream_event_context
) {
865 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
866 ((struct bt_ctf_field_common
*) stream_event_context
)->type
,
867 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
) == 0,
868 "Stream event context field's type is different from the "
869 "expected field type: event-addr=%p, ft-addr=%p, "
870 "expected-ft-addr=%p",
872 ((struct bt_ctf_field_common
*) stream_event_context
)->type
,
873 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
);
875 BT_CTF_ASSERT_PRE(!bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
,
876 "Setting no stream event context field, "
877 "but stream event context field type is not NULL: "
878 "event-addr=%p, context-ft-addr=%p",
880 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
);
883 bt_ctf_object_put_ref(event
->common
.stream_event_context_field
);
884 event
->common
.stream_event_context_field
= bt_ctf_object_get_ref(stream_event_context
);
885 BT_LOGT("Set event's stream event context field: event-addr=%p, "
886 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
887 "stream-event-context-field-addr=%p",
888 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
889 bt_ctf_event_class_common_get_id(event
->common
.class),
890 stream_event_context
);