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
);
202 int _bt_ctf_event_common_validate(struct bt_ctf_event_common
*event
)
205 struct bt_ctf_stream_class_common
*stream_class
;
207 BT_ASSERT_DBG(event
);
208 if (event
->header_field
) {
209 ret
= bt_ctf_field_common_validate_recursive(
210 event
->header_field
->field
);
212 BT_CTF_ASSERT_PRE_MSG("Invalid event's header field: "
213 "event-addr=%p, field-addr=%p",
214 event
, event
->header_field
->field
);
219 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event
->class);
222 * We should not have been able to create the event without associating
223 * the event class to a stream class.
225 BT_ASSERT_DBG(stream_class
);
227 if (stream_class
->event_context_field_type
) {
228 ret
= bt_ctf_field_common_validate_recursive(
229 event
->stream_event_context_field
);
231 BT_CTF_ASSERT_PRE_MSG("Invalid event's stream event context field: "
232 "event-addr=%p, field-addr=%p",
233 event
, event
->stream_event_context_field
);
238 if (event
->class->context_field_type
) {
239 ret
= bt_ctf_field_common_validate_recursive(event
->context_field
);
241 BT_CTF_ASSERT_PRE_MSG("Invalid event's payload field: "
242 "event-addr=%p, field-addr=%p",
243 event
, event
->context_field
);
248 ret
= bt_ctf_field_common_validate_recursive(event
->payload_field
);
250 BT_CTF_ASSERT_PRE_MSG("Invalid event's payload field: "
251 "event-addr=%p, field-addr=%p",
252 event
, event
->payload_field
);
261 void _bt_ctf_event_common_set_is_frozen(struct bt_ctf_event_common
*event
,
264 BT_ASSERT_DBG(event
);
265 BT_LOGD("Freezing event: addr=%p, "
266 "event-class-name=\"%s\", event-class-id=%" PRId64
,
267 event
, bt_ctf_event_class_common_get_name(event
->class),
268 bt_ctf_event_class_common_get_id(event
->class));
270 if (event
->header_field
) {
271 BT_LOGD_STR("Freezing event's header field.");
272 bt_ctf_field_common_set_is_frozen_recursive(
273 event
->header_field
->field
, is_frozen
);
276 if (event
->stream_event_context_field
) {
277 BT_LOGD_STR("Freezing event's stream event context field.");
278 bt_ctf_field_common_set_is_frozen_recursive(
279 event
->stream_event_context_field
, is_frozen
);
282 if (event
->context_field
) {
283 BT_LOGD_STR("Freezing event's context field.");
284 bt_ctf_field_common_set_is_frozen_recursive(event
->context_field
,
288 if (event
->payload_field
) {
289 BT_LOGD_STR("Freezing event's payload field.");
290 bt_ctf_field_common_set_is_frozen_recursive(event
->payload_field
,
294 event
->frozen
= is_frozen
;
298 int bt_ctf_event_common_initialize(struct bt_ctf_event_common
*event
,
299 struct bt_ctf_event_class_common
*event_class
,
300 struct bt_ctf_clock_class
*init_expected_clock_class
,
301 bool is_shared_with_parent
, bt_ctf_object_release_func release_func
,
302 bt_ctf_validation_flag_copy_field_type_func field_type_copy_func
,
303 bool must_be_in_trace
,
304 int (*map_clock_classes_func
)(struct bt_ctf_stream_class_common
*stream_class
,
305 struct bt_ctf_field_type_common
*packet_context_field_type
,
306 struct bt_ctf_field_type_common
*event_header_field_type
),
307 create_field_func_type create_field_func
,
308 release_field_func_type release_field_func
,
309 create_header_field_func_type create_header_field_func
,
310 release_header_field_func_type release_header_field_func
)
313 struct bt_ctf_trace_common
*trace
= NULL
;
314 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
315 struct bt_ctf_field_wrapper
*event_header
= NULL
;
316 struct bt_ctf_field_common
*stream_event_context
= NULL
;
317 struct bt_ctf_field_common
*event_context
= NULL
;
318 struct bt_ctf_field_common
*event_payload
= NULL
;
319 struct bt_ctf_validation_output validation_output
= { 0 };
320 struct bt_ctf_clock_class
*expected_clock_class
=
321 init_expected_clock_class
? bt_ctf_object_get_ref(init_expected_clock_class
) :
324 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
325 BT_LOGD("Initializing common event object: event-class-addr=%p, "
326 "event-class-name=\"%s\", event-class-id=%" PRId64
,
327 event_class
, bt_ctf_event_class_common_get_name(event_class
),
328 bt_ctf_event_class_common_get_id(event_class
));
330 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
331 BT_CTF_ASSERT_PRE(stream_class
,
332 "Event class is not part of a stream class: event-class-addr=%p",
335 /* The event class was frozen when added to its stream class */
336 BT_ASSERT_DBG(event_class
->frozen
);
337 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
339 if (must_be_in_trace
) {
340 BT_CTF_ASSERT_PRE(trace
,
341 "Event class's stream class is not part of a trace: "
342 "ec-addr=%p, sc-addr=%p", event_class
, stream_class
);
346 * This must be called before anything that can fail because on
347 * failure, the caller releases the reference to `event` to
350 if (is_shared_with_parent
) {
351 bt_ctf_object_init_shared_with_parent(&event
->base
, release_func
);
353 bt_ctf_object_init_unique(&event
->base
);
356 if (!stream_class
->frozen
) {
358 * Because this function freezes the stream class,
359 * validate that this stream class contains at most a
360 * single clock class so that we set its expected clock
361 * class for future checks.
363 ret
= bt_ctf_stream_class_common_validate_single_clock_class(
364 stream_class
, &expected_clock_class
);
366 BT_LOGW("Event class's stream class or one of its event "
367 "classes contains a field type which is not "
368 "recursively mapped to the expected "
370 "stream-class-addr=%p, "
371 "stream-class-id=%" PRId64
", "
372 "stream-class-name=\"%s\", "
373 "expected-clock-class-addr=%p, "
374 "expected-clock-class-name=\"%s\"",
376 bt_ctf_stream_class_common_get_id(stream_class
),
377 bt_ctf_stream_class_common_get_name(stream_class
),
378 expected_clock_class
,
379 expected_clock_class
?
380 bt_ctf_clock_class_get_name(expected_clock_class
) :
386 /* Validate the trace, the stream class, and the event class */
387 ret
= bt_ctf_event_common_validate_types_for_create(
388 event_class
, &validation_output
, field_type_copy_func
);
390 /* bt_ctf_event_common_validate_types_for_create() logs errors */
394 if (map_clock_classes_func
) {
396 * Safe to automatically map selected fields to the
397 * stream's clock's class here because the stream class
398 * is about to be frozen.
400 if (map_clock_classes_func(stream_class
,
401 validation_output
.packet_context_type
,
402 validation_output
.event_header_type
)) {
403 BT_LOGW_STR("Cannot automatically map selected stream class's "
404 "field types to stream class's clock's class.");
410 * event does not share a common ancestor with the event class; it has
411 * to guarantee its existence by holding a reference. This reference
412 * shall be released once the event is associated to a stream since,
413 * from that point, the event and its class will share the same
416 event
->class = bt_ctf_object_get_ref(event_class
);
418 ret
= bt_ctf_event_common_create_fields(stream_class
,
420 create_field_func
, release_field_func
,
421 create_header_field_func
, release_header_field_func
,
422 &event_header
, &stream_event_context
, &event_context
,
425 /* bt_ctf_event_common_create_fields() logs errors */
430 * At this point all the fields are created, potentially from
431 * validated copies of field types, so that the field types and
432 * fields can be replaced in the trace, stream class,
433 * event class, and created event.
435 bt_ctf_validation_replace_types(trace
, stream_class
, event_class
,
437 BT_CTF_VALIDATION_FLAG_STREAM
| BT_CTF_VALIDATION_FLAG_EVENT
);
438 event
->header_field
= event_header
;
440 event
->stream_event_context_field
= stream_event_context
;
441 stream_event_context
= NULL
;
442 event
->context_field
= event_context
;
443 event_context
= NULL
;
444 event
->payload_field
= event_payload
;
445 event_payload
= NULL
;
448 * Put what was not moved in bt_ctf_validation_replace_types().
450 bt_ctf_validation_output_put_types(&validation_output
);
453 * Freeze the stream class since the event header must not be changed
456 bt_ctf_stream_class_common_freeze(stream_class
);
459 * It is safe to set the stream class's unique clock class
460 * now because the stream class is frozen.
462 if (expected_clock_class
) {
463 BT_CTF_OBJECT_MOVE_REF(stream_class
->clock_class
, expected_clock_class
);
467 * Mark stream class, and event class as valid since
468 * they're all frozen now.
470 stream_class
->valid
= 1;
471 event_class
->valid
= 1;
473 /* Put stuff we borrowed from the event class */
474 BT_LOGD("Initialized event object: addr=%p, event-class-name=\"%s\", "
475 "event-class-id=%" PRId64
,
476 event
, bt_ctf_event_class_common_get_name(event
->class),
477 bt_ctf_event_class_common_get_id(event
->class));
481 bt_ctf_validation_output_put_types(&validation_output
);
482 bt_ctf_object_put_ref(expected_clock_class
);
485 release_header_field_func(event_header
, stream_class
);
488 if (stream_event_context
) {
489 release_field_func(stream_event_context
);
493 release_field_func(event_context
);
497 release_field_func(event_payload
);
507 int map_clock_classes_func(struct bt_ctf_stream_class_common
*stream_class
,
508 struct bt_ctf_field_type_common
*packet_context_type
,
509 struct bt_ctf_field_type_common
*event_header_type
)
511 int ret
= bt_ctf_stream_class_map_clock_class(
512 BT_CTF_FROM_COMMON(stream_class
),
513 BT_CTF_FROM_COMMON(packet_context_type
),
514 BT_CTF_FROM_COMMON(event_header_type
));
517 BT_LOGW_STR("Cannot automatically map selected stream class's field types to stream class's clock's class.");
524 void destroy_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
525 struct bt_ctf_stream_class
*stream_class
)
527 BT_ASSERT_DBG(field_wrapper
);
528 bt_ctf_object_put_ref(field_wrapper
->field
);
529 bt_ctf_field_wrapper_destroy(field_wrapper
);
533 struct bt_ctf_field_wrapper
*create_event_header_field(
534 struct bt_ctf_stream_class
*stream_class
,
535 struct bt_ctf_field_type_common
*ft
)
537 struct bt_ctf_field_wrapper
*field_wrapper
= NULL
;
538 struct bt_ctf_field
*field
= bt_ctf_field_create((void *) ft
);
544 field_wrapper
= bt_ctf_field_wrapper_new(NULL
);
545 if (!field_wrapper
) {
549 field_wrapper
->field
= (void *) field
;
554 bt_ctf_object_put_ref(field
);
557 destroy_event_header_field(field_wrapper
, stream_class
);
558 field_wrapper
= NULL
;
562 return field_wrapper
;
566 void release_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
567 struct bt_ctf_event_common
*event_common
)
569 BT_ASSERT_DBG(field_wrapper
);
570 BT_CTF_OBJECT_PUT_REF_AND_RESET(field_wrapper
->field
);
571 bt_ctf_field_wrapper_destroy(field_wrapper
);
575 void bt_ctf_event_destroy(struct bt_ctf_object
*obj
)
577 bt_ctf_event_common_finalize(obj
, (void *) bt_ctf_object_put_ref
,
578 (void *) release_event_header_field
);
582 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
585 struct bt_ctf_event
*event
= NULL
;
586 struct bt_ctf_clock_class
*expected_clock_class
= NULL
;
588 event
= g_new0(struct bt_ctf_event
, 1);
590 BT_LOGE_STR("Failed to allocate one CTF writer event.");
595 struct bt_ctf_stream_class
*stream_class
=
596 BT_CTF_FROM_COMMON(bt_ctf_event_class_common_borrow_stream_class(
597 BT_CTF_TO_COMMON(event_class
)));
599 if (stream_class
&& stream_class
->clock
) {
600 expected_clock_class
= stream_class
->clock
->clock_class
;
604 ret
= bt_ctf_event_common_initialize(BT_CTF_TO_COMMON(event
),
605 BT_CTF_TO_COMMON(event_class
), expected_clock_class
,
606 true, bt_ctf_event_destroy
,
607 (bt_ctf_validation_flag_copy_field_type_func
)
608 bt_ctf_field_type_copy
,
609 false, map_clock_classes_func
,
610 (create_field_func_type
) bt_ctf_field_create
,
611 (release_field_func_type
) bt_ctf_object_put_ref
,
612 (create_header_field_func_type
) create_event_header_field
,
613 (release_header_field_func_type
) destroy_event_header_field
);
615 /* bt_ctf_event_common_initialize() logs errors */
622 BT_CTF_OBJECT_PUT_REF_AND_RESET(event
);
628 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
630 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
631 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_class(BT_CTF_TO_COMMON(event
)));
635 struct bt_ctf_stream
*bt_ctf_event_borrow_stream(struct bt_ctf_event
*event
)
637 BT_ASSERT_DBG(event
);
638 return (struct bt_ctf_stream
*)
639 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
));
648 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
, const char *name
,
649 struct bt_ctf_field
*field
)
651 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
652 BT_CTF_ASSERT_PRE_NON_NULL(field
, "Payload field");
653 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
654 return bt_ctf_field_structure_set_field_by_name(
655 (void *) event
->common
.payload_field
, name
, field
);
658 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
661 struct bt_ctf_field
*field
= NULL
;
663 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
666 field
= bt_ctf_field_structure_get_field_by_name(
667 BT_CTF_FROM_COMMON(event
->common
.payload_field
), name
);
669 field
= BT_CTF_FROM_COMMON(event
->common
.payload_field
);
670 bt_ctf_object_get_ref(field
);
676 struct bt_ctf_field
*bt_ctf_event_get_payload_field(
677 struct bt_ctf_event
*event
)
679 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_payload(BT_CTF_TO_COMMON(event
)));
682 struct bt_ctf_field
*bt_ctf_event_get_header(struct bt_ctf_event
*event
)
684 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_header(BT_CTF_TO_COMMON(event
)));
687 struct bt_ctf_field
*bt_ctf_event_get_context(struct bt_ctf_event
*event
)
689 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_context(BT_CTF_TO_COMMON(event
)));
692 struct bt_ctf_field
*bt_ctf_event_get_stream_event_context(
693 struct bt_ctf_event
*event
)
695 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_stream_event_context(
696 BT_CTF_TO_COMMON(event
)));
700 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
701 struct bt_ctfser
*ctfser
,
702 enum bt_ctf_byte_order native_byte_order
)
706 BT_ASSERT_DBG(event
);
707 BT_ASSERT_DBG(ctfser
);
709 BT_LOGT_STR("Serializing event's context field.");
710 if (event
->common
.context_field
) {
711 ret
= bt_ctf_field_serialize_recursive(
712 (void *) event
->common
.context_field
, ctfser
,
715 BT_LOGW("Cannot serialize event's context field: "
716 "event-addr=%p, event-class-name=\"%s\", "
717 "event-class-id=%" PRId64
,
719 bt_ctf_event_class_common_get_name(event
->common
.class),
720 bt_ctf_event_class_common_get_id(event
->common
.class));
725 BT_LOGT_STR("Serializing event's payload field.");
726 if (event
->common
.payload_field
) {
727 ret
= bt_ctf_field_serialize_recursive(
728 (void *) event
->common
.payload_field
, ctfser
,
731 BT_LOGW("Cannot serialize event's payload field: "
732 "event-addr=%p, event-class-name=\"%s\", "
733 "event-class-id=%" PRId64
,
735 bt_ctf_event_class_common_get_name(event
->common
.class),
736 bt_ctf_event_class_common_get_id(event
->common
.class));
745 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
746 struct bt_ctf_field
*header
)
748 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
749 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
752 * Ensure the provided header's type matches the one registered to the
756 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
757 ((struct bt_ctf_field_common
*) header
)->type
,
758 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
) == 0,
759 "Header field's type is different from the "
760 "expected field type: event-addr=%p, ft-addr=%p, "
761 "expected-ft-addr=%p",
762 event
, ((struct bt_ctf_field_common
*) header
)->type
,
763 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
);
765 BT_CTF_ASSERT_PRE(!bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
,
766 "Setting no event header field, "
767 "but event header field type is not NULL: "
768 "event-addr=%p, header-ft-addr=%p",
770 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_header_field_type
);
773 bt_ctf_object_put_ref(event
->common
.header_field
->field
);
774 event
->common
.header_field
->field
= bt_ctf_object_get_ref(header
);
775 BT_LOGT("Set event's header field: event-addr=%p, "
776 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
777 "header-field-addr=%p",
778 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
779 bt_ctf_event_class_common_get_id(event
->common
.class), header
);
783 int bt_ctf_event_common_set_payload(struct bt_ctf_event
*event
,
784 struct bt_ctf_field
*payload
)
786 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
787 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
790 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
791 ((struct bt_ctf_field_common
*) payload
)->type
,
792 event
->common
.class->payload_field_type
) == 0,
793 "Payload field's type is different from the "
794 "expected field type: event-addr=%p, ft-addr=%p, "
795 "expected-ft-addr=%p",
797 ((struct bt_ctf_field_common
*) payload
)->type
,
798 event
->common
.class->payload_field_type
);
800 BT_CTF_ASSERT_PRE(!event
->common
.class->payload_field_type
,
801 "Setting no event payload field, "
802 "but event payload field type is not NULL: "
803 "event-addr=%p, payload-ft-addr=%p",
804 event
, event
->common
.class->payload_field_type
);
807 bt_ctf_object_put_ref(event
->common
.payload_field
);
808 event
->common
.payload_field
= bt_ctf_object_get_ref(payload
);
809 BT_LOGT("Set event's payload field: event-addr=%p, "
810 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
811 "payload-field-addr=%p",
812 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
813 bt_ctf_event_class_common_get_id(event
->common
.class), payload
);
817 int bt_ctf_event_set_context(struct bt_ctf_event
*event
,
818 struct bt_ctf_field
*context
)
820 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
821 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
824 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
825 ((struct bt_ctf_field_common
*) context
)->type
,
826 event
->common
.class->context_field_type
) == 0,
827 "Context field's type is different from the "
828 "expected field type: event-addr=%p, ft-addr=%p, "
829 "expected-ft-addr=%p",
830 event
, ((struct bt_ctf_field_common
*) context
)->type
,
831 event
->common
.class->context_field_type
);
833 BT_CTF_ASSERT_PRE(!event
->common
.class->context_field_type
,
834 "Setting no event context field, "
835 "but event context field type is not NULL: "
836 "event-addr=%p, context-ft-addr=%p",
837 event
, event
->common
.class->context_field_type
);
840 bt_ctf_object_put_ref(event
->common
.context_field
);
841 event
->common
.context_field
= bt_ctf_object_get_ref(context
);
842 BT_LOGT("Set event's context field: event-addr=%p, "
843 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
844 "context-field-addr=%p",
845 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
846 bt_ctf_event_class_common_get_id(event
->common
.class), context
);
850 int bt_ctf_event_set_stream_event_context(struct bt_ctf_event
*event
,
851 struct bt_ctf_field
*stream_event_context
)
853 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
854 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
856 if (stream_event_context
) {
857 BT_CTF_ASSERT_PRE(bt_ctf_field_type_common_compare(
858 ((struct bt_ctf_field_common
*) stream_event_context
)->type
,
859 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
) == 0,
860 "Stream event context field's type is different from the "
861 "expected field type: event-addr=%p, ft-addr=%p, "
862 "expected-ft-addr=%p",
864 ((struct bt_ctf_field_common
*) stream_event_context
)->type
,
865 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
);
867 BT_CTF_ASSERT_PRE(!bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
,
868 "Setting no stream event context field, "
869 "but stream event context field type is not NULL: "
870 "event-addr=%p, context-ft-addr=%p",
872 bt_ctf_event_class_common_borrow_stream_class(event
->common
.class)->event_context_field_type
);
875 bt_ctf_object_put_ref(event
->common
.stream_event_context_field
);
876 event
->common
.stream_event_context_field
= bt_ctf_object_get_ref(stream_event_context
);
877 BT_LOGT("Set event's stream event context field: event-addr=%p, "
878 "event-class-name=\"%s\", event-class-id=%" PRId64
", "
879 "stream-event-context-field-addr=%p",
880 event
, bt_ctf_event_class_common_get_name(event
->common
.class),
881 bt_ctf_event_class_common_get_id(event
->common
.class),
882 stream_event_context
);