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"
30 #include <babeltrace2-ctf-writer/event.h>
31 #include <babeltrace2-ctf-writer/fields.h>
32 #include <babeltrace2-ctf-writer/field-types.h>
33 #include <babeltrace2-ctf-writer/object.h>
34 #include <babeltrace2-ctf-writer/stream-class.h>
35 #include <babeltrace2-ctf-writer/trace.h>
36 #include <babeltrace2-ctf-writer/utils.h>
38 #include "common/assert.h"
39 #include "compat/compiler.h"
41 #include "assert-pre.h"
42 #include "attributes.h"
43 #include "clock-class.h"
45 #include "event-class.h"
48 #include "field-types.h"
49 #include "stream-class.h"
52 #include "validation.h"
55 int bt_ctf_event_common_validate_types_for_create(
56 struct bt_ctf_event_class_common
*event_class
,
57 struct bt_ctf_validation_output
*validation_output
,
58 bt_ctf_validation_flag_copy_field_type_func copy_field_type_func
)
61 enum bt_ctf_validation_flag validation_flags
=
62 BT_CTF_VALIDATION_FLAG_STREAM
|
63 BT_CTF_VALIDATION_FLAG_EVENT
;
64 struct bt_ctf_trace_common
*trace
= NULL
;
65 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
66 struct bt_ctf_field_type_common
*packet_header_type
= NULL
;
67 struct bt_ctf_field_type_common
*packet_context_type
= NULL
;
68 struct bt_ctf_field_type_common
*event_header_type
= NULL
;
69 struct bt_ctf_field_type_common
*stream_event_ctx_type
= NULL
;
70 struct bt_ctf_field_type_common
*event_context_type
= NULL
;
71 struct bt_ctf_field_type_common
*event_payload_type
= NULL
;
73 struct bt_ctf_private_value
*environment
= NULL
;
75 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
76 BT_ASSERT_DBG(stream_class
);
77 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
79 BT_LOGD_STR("Event class is part of a trace.");
81 bt_ctf_trace_common_borrow_packet_header_field_type(trace
);
82 trace_valid
= trace
->valid
;
83 BT_ASSERT_DBG(trace_valid
);
84 environment
= trace
->environment
;
88 bt_ctf_stream_class_common_borrow_packet_context_field_type(
91 bt_ctf_stream_class_common_borrow_event_header_field_type(
93 stream_event_ctx_type
=
94 bt_ctf_stream_class_common_borrow_event_context_field_type(
97 bt_ctf_event_class_common_borrow_context_field_type(event_class
);
99 bt_ctf_event_class_common_borrow_payload_field_type(event_class
);
100 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
101 packet_context_type
, event_header_type
, stream_event_ctx_type
,
102 event_context_type
, event_payload_type
, trace_valid
,
103 stream_class
->valid
, event_class
->valid
,
104 validation_output
, validation_flags
, copy_field_type_func
);
107 * This means something went wrong during the validation
108 * process, not that the objects are invalid.
110 BT_LOGE("Failed to validate event and parents: ret=%d", ret
);
114 if ((validation_output
->valid_flags
& validation_flags
) !=
116 /* Invalid trace/stream class/event class */
117 BT_LOGW("Invalid trace, stream class, or event class: "
118 "valid-flags=0x%x", validation_output
->valid_flags
);
125 bt_ctf_validation_output_put_types(validation_output
);
133 int bt_ctf_event_common_create_fields(
134 struct bt_ctf_stream_class_common
*stream_class
,
135 struct bt_ctf_validation_output
*validation_output
,
136 create_field_func_type create_field_func
,
137 release_field_func_type release_field_func
,
138 create_header_field_func_type create_header_field_func
,
139 release_header_field_func_type release_header_field_func
,
140 struct bt_ctf_field_wrapper
**header_field
,
141 struct bt_ctf_field_common
**stream_event_context_field
,
142 struct bt_ctf_field_common
**context_field
,
143 struct bt_ctf_field_common
**payload_field
)
147 if (validation_output
->event_header_type
) {
148 BT_LOGD("Creating initial event header field: ft-addr=%p",
149 validation_output
->event_header_type
);
151 create_header_field_func(stream_class
,
152 validation_output
->event_header_type
);
153 if (!*header_field
) {
154 BT_LOGE_STR("Cannot create initial event header field object.");
159 if (validation_output
->stream_event_ctx_type
) {
160 BT_LOGD("Creating initial stream event context field: ft-addr=%p",
161 validation_output
->stream_event_ctx_type
);
162 *stream_event_context_field
= create_field_func(
163 validation_output
->stream_event_ctx_type
);
164 if (!*stream_event_context_field
) {
165 BT_LOGE_STR("Cannot create initial stream event context field object.");
170 if (validation_output
->event_context_type
) {
171 BT_LOGD("Creating initial event context field: ft-addr=%p",
172 validation_output
->event_context_type
);
173 *context_field
= create_field_func(
174 validation_output
->event_context_type
);
175 if (!*context_field
) {
176 BT_LOGE_STR("Cannot create initial event context field object.");
181 if (validation_output
->event_payload_type
) {
182 BT_LOGD("Creating initial event payload field: ft-addr=%p",
183 validation_output
->event_payload_type
);
184 *payload_field
= create_field_func(
185 validation_output
->event_payload_type
);
186 if (!*payload_field
) {
187 BT_LOGE_STR("Cannot create initial event payload field object.");
196 release_header_field_func(*header_field
, stream_class
);
199 if (*stream_event_context_field
) {
200 release_field_func(*stream_event_context_field
);
203 if (*context_field
) {
204 release_field_func(*context_field
);
207 if (*payload_field
) {
208 release_field_func(*payload_field
);
218 int _bt_ctf_event_common_validate(struct bt_ctf_event_common
*event
)
221 struct bt_ctf_stream_class_common
*stream_class
;
223 BT_ASSERT_DBG(event
);
224 if (event
->header_field
) {
225 ret
= bt_ctf_field_common_validate_recursive(
226 event
->header_field
->field
);
228 BT_CTF_ASSERT_PRE_MSG("Invalid event's header field: "
229 "event-addr=%p, field-addr=%p",
230 event
, event
->header_field
->field
);
235 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event
->class);
238 * We should not have been able to create the event without associating
239 * the event class to a stream class.
241 BT_ASSERT_DBG(stream_class
);
243 if (stream_class
->event_context_field_type
) {
244 ret
= bt_ctf_field_common_validate_recursive(
245 event
->stream_event_context_field
);
247 BT_CTF_ASSERT_PRE_MSG("Invalid event's stream event context field: "
248 "event-addr=%p, field-addr=%p",
249 event
, event
->stream_event_context_field
);
254 if (event
->class->context_field_type
) {
255 ret
= bt_ctf_field_common_validate_recursive(event
->context_field
);
257 BT_CTF_ASSERT_PRE_MSG("Invalid event's payload field: "
258 "event-addr=%p, field-addr=%p",
259 event
, event
->context_field
);
264 ret
= bt_ctf_field_common_validate_recursive(event
->payload_field
);
266 BT_CTF_ASSERT_PRE_MSG("Invalid event's payload field: "
267 "event-addr=%p, field-addr=%p",
268 event
, event
->payload_field
);
277 void _bt_ctf_event_common_set_is_frozen(struct bt_ctf_event_common
*event
,
280 BT_ASSERT_DBG(event
);
281 BT_LOGD("Freezing event: addr=%p, "
282 "event-class-name=\"%s\", event-class-id=%" PRId64
,
283 event
, bt_ctf_event_class_common_get_name(event
->class),
284 bt_ctf_event_class_common_get_id(event
->class));
286 if (event
->header_field
) {
287 BT_LOGD_STR("Freezing event's header field.");
288 bt_ctf_field_common_set_is_frozen_recursive(
289 event
->header_field
->field
, is_frozen
);
292 if (event
->stream_event_context_field
) {
293 BT_LOGD_STR("Freezing event's stream event context field.");
294 bt_ctf_field_common_set_is_frozen_recursive(
295 event
->stream_event_context_field
, is_frozen
);
298 if (event
->context_field
) {
299 BT_LOGD_STR("Freezing event's context field.");
300 bt_ctf_field_common_set_is_frozen_recursive(event
->context_field
,
304 if (event
->payload_field
) {
305 BT_LOGD_STR("Freezing event's payload field.");
306 bt_ctf_field_common_set_is_frozen_recursive(event
->payload_field
,
310 event
->frozen
= is_frozen
;
314 int bt_ctf_event_common_initialize(struct bt_ctf_event_common
*event
,
315 struct bt_ctf_event_class_common
*event_class
,
316 struct bt_ctf_clock_class
*init_expected_clock_class
,
317 bool is_shared_with_parent
, bt_ctf_object_release_func release_func
,
318 bt_ctf_validation_flag_copy_field_type_func field_type_copy_func
,
319 bool must_be_in_trace
,
320 int (*map_clock_classes_func
)(struct bt_ctf_stream_class_common
*stream_class
,
321 struct bt_ctf_field_type_common
*packet_context_field_type
,
322 struct bt_ctf_field_type_common
*event_header_field_type
),
323 create_field_func_type create_field_func
,
324 release_field_func_type release_field_func
,
325 create_header_field_func_type create_header_field_func
,
326 release_header_field_func_type release_header_field_func
)
329 struct bt_ctf_trace_common
*trace
= NULL
;
330 struct bt_ctf_stream_class_common
*stream_class
= NULL
;
331 struct bt_ctf_field_wrapper
*event_header
= NULL
;
332 struct bt_ctf_field_common
*stream_event_context
= NULL
;
333 struct bt_ctf_field_common
*event_context
= NULL
;
334 struct bt_ctf_field_common
*event_payload
= NULL
;
335 struct bt_ctf_validation_output validation_output
= { 0 };
336 struct bt_ctf_clock_class
*expected_clock_class
=
337 init_expected_clock_class
? bt_ctf_object_get_ref(init_expected_clock_class
) :
340 BT_CTF_ASSERT_PRE_NON_NULL(event_class
, "Event class");
341 BT_LOGD("Initializing common event object: event-class-addr=%p, "
342 "event-class-name=\"%s\", event-class-id=%" PRId64
,
343 event_class
, bt_ctf_event_class_common_get_name(event_class
),
344 bt_ctf_event_class_common_get_id(event_class
));
346 stream_class
= bt_ctf_event_class_common_borrow_stream_class(event_class
);
347 BT_CTF_ASSERT_PRE(stream_class
,
348 "Event class is not part of a stream class: event-class-addr=%p",
351 /* The event class was frozen when added to its stream class */
352 BT_ASSERT_DBG(event_class
->frozen
);
353 trace
= bt_ctf_stream_class_common_borrow_trace(stream_class
);
355 if (must_be_in_trace
) {
356 BT_CTF_ASSERT_PRE(trace
,
357 "Event class's stream class is not part of a trace: "
358 "ec-addr=%p, sc-addr=%p", event_class
, stream_class
);
362 * This must be called before anything that can fail because on
363 * failure, the caller releases the reference to `event` to
366 if (is_shared_with_parent
) {
367 bt_ctf_object_init_shared_with_parent(&event
->base
, release_func
);
369 bt_ctf_object_init_unique(&event
->base
);
372 if (!stream_class
->frozen
) {
374 * Because this function freezes the stream class,
375 * validate that this stream class contains at most a
376 * single clock class so that we set its expected clock
377 * class for future checks.
379 ret
= bt_ctf_stream_class_common_validate_single_clock_class(
380 stream_class
, &expected_clock_class
);
382 BT_LOGW("Event class's stream class or one of its event "
383 "classes contains a field type which is not "
384 "recursively mapped to the expected "
386 "stream-class-addr=%p, "
387 "stream-class-id=%" PRId64
", "
388 "stream-class-name=\"%s\", "
389 "expected-clock-class-addr=%p, "
390 "expected-clock-class-name=\"%s\"",
392 bt_ctf_stream_class_common_get_id(stream_class
),
393 bt_ctf_stream_class_common_get_name(stream_class
),
394 expected_clock_class
,
395 expected_clock_class
?
396 bt_ctf_clock_class_get_name(expected_clock_class
) :
402 /* Validate the trace, the stream class, and the event class */
403 ret
= bt_ctf_event_common_validate_types_for_create(
404 event_class
, &validation_output
, field_type_copy_func
);
406 /* bt_ctf_event_common_validate_types_for_create() logs errors */
410 if (map_clock_classes_func
) {
412 * Safe to automatically map selected fields to the
413 * stream's clock's class here because the stream class
414 * is about to be frozen.
416 if (map_clock_classes_func(stream_class
,
417 validation_output
.packet_context_type
,
418 validation_output
.event_header_type
)) {
419 BT_LOGW_STR("Cannot automatically map selected stream class's "
420 "field types to stream class's clock's class.");
426 * event does not share a common ancestor with the event class; it has
427 * to guarantee its existence by holding a reference. This reference
428 * shall be released once the event is associated to a stream since,
429 * from that point, the event and its class will share the same
432 event
->class = bt_ctf_object_get_ref(event_class
);
434 ret
= bt_ctf_event_common_create_fields(stream_class
,
436 create_field_func
, release_field_func
,
437 create_header_field_func
, release_header_field_func
,
438 &event_header
, &stream_event_context
, &event_context
,
441 /* bt_ctf_event_common_create_fields() logs errors */
446 * At this point all the fields are created, potentially from
447 * validated copies of field types, so that the field types and
448 * fields can be replaced in the trace, stream class,
449 * event class, and created event.
451 bt_ctf_validation_replace_types(trace
, stream_class
, event_class
,
453 BT_CTF_VALIDATION_FLAG_STREAM
| BT_CTF_VALIDATION_FLAG_EVENT
);
454 event
->header_field
= event_header
;
456 event
->stream_event_context_field
= stream_event_context
;
457 stream_event_context
= NULL
;
458 event
->context_field
= event_context
;
459 event_context
= NULL
;
460 event
->payload_field
= event_payload
;
461 event_payload
= NULL
;
464 * Put what was not moved in bt_ctf_validation_replace_types().
466 bt_ctf_validation_output_put_types(&validation_output
);
469 * Freeze the stream class since the event header must not be changed
472 bt_ctf_stream_class_common_freeze(stream_class
);
475 * It is safe to set the stream class's unique clock class
476 * now because the stream class is frozen.
478 if (expected_clock_class
) {
479 BT_CTF_OBJECT_MOVE_REF(stream_class
->clock_class
, expected_clock_class
);
483 * Mark stream class, and event class as valid since
484 * they're all frozen now.
486 stream_class
->valid
= 1;
487 event_class
->valid
= 1;
489 /* Put stuff we borrowed from the event class */
490 BT_LOGD("Initialized event object: addr=%p, event-class-name=\"%s\", "
491 "event-class-id=%" PRId64
,
492 event
, bt_ctf_event_class_common_get_name(event
->class),
493 bt_ctf_event_class_common_get_id(event
->class));
497 bt_ctf_validation_output_put_types(&validation_output
);
498 bt_ctf_object_put_ref(expected_clock_class
);
501 release_header_field_func(event_header
, stream_class
);
504 if (stream_event_context
) {
505 release_field_func(stream_event_context
);
509 release_field_func(event_context
);
513 release_field_func(event_payload
);
523 int map_clock_classes_func(struct bt_ctf_stream_class_common
*stream_class
,
524 struct bt_ctf_field_type_common
*packet_context_type
,
525 struct bt_ctf_field_type_common
*event_header_type
)
527 int ret
= bt_ctf_stream_class_map_clock_class(
528 BT_CTF_FROM_COMMON(stream_class
),
529 BT_CTF_FROM_COMMON(packet_context_type
),
530 BT_CTF_FROM_COMMON(event_header_type
));
533 BT_LOGW_STR("Cannot automatically map selected stream class's field types to stream class's clock's class.");
540 void destroy_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
541 struct bt_ctf_stream_class
*stream_class
)
543 BT_ASSERT_DBG(field_wrapper
);
544 bt_ctf_object_put_ref(field_wrapper
->field
);
545 bt_ctf_field_wrapper_destroy(field_wrapper
);
549 struct bt_ctf_field_wrapper
*create_event_header_field(
550 struct bt_ctf_stream_class
*stream_class
,
551 struct bt_ctf_field_type_common
*ft
)
553 struct bt_ctf_field_wrapper
*field_wrapper
= NULL
;
554 struct bt_ctf_field
*field
= bt_ctf_field_create((void *) ft
);
560 field_wrapper
= bt_ctf_field_wrapper_new(NULL
);
561 if (!field_wrapper
) {
565 field_wrapper
->field
= (void *) field
;
570 bt_ctf_object_put_ref(field
);
573 destroy_event_header_field(field_wrapper
, stream_class
);
574 field_wrapper
= NULL
;
578 return field_wrapper
;
582 void release_event_header_field(struct bt_ctf_field_wrapper
*field_wrapper
,
583 struct bt_ctf_event_common
*event_common
)
585 BT_ASSERT_DBG(field_wrapper
);
586 BT_CTF_OBJECT_PUT_REF_AND_RESET(field_wrapper
->field
);
587 bt_ctf_field_wrapper_destroy(field_wrapper
);
591 void bt_ctf_event_destroy(struct bt_ctf_object
*obj
)
593 bt_ctf_event_common_finalize(obj
, (void *) bt_ctf_object_put_ref
,
594 (void *) release_event_header_field
);
598 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
601 struct bt_ctf_event
*event
= NULL
;
602 struct bt_ctf_clock_class
*expected_clock_class
= NULL
;
604 event
= g_new0(struct bt_ctf_event
, 1);
606 BT_LOGE_STR("Failed to allocate one CTF writer event.");
611 struct bt_ctf_stream_class
*stream_class
=
612 BT_CTF_FROM_COMMON(bt_ctf_event_class_common_borrow_stream_class(
613 BT_CTF_TO_COMMON(event_class
)));
615 if (stream_class
&& stream_class
->clock
) {
616 expected_clock_class
= stream_class
->clock
->clock_class
;
620 ret
= bt_ctf_event_common_initialize(BT_CTF_TO_COMMON(event
),
621 BT_CTF_TO_COMMON(event_class
), expected_clock_class
,
622 true, bt_ctf_event_destroy
,
623 (bt_ctf_validation_flag_copy_field_type_func
)
624 bt_ctf_field_type_copy
,
625 false, map_clock_classes_func
,
626 (create_field_func_type
) bt_ctf_field_create
,
627 (release_field_func_type
) bt_ctf_object_put_ref
,
628 (create_header_field_func_type
) create_event_header_field
,
629 (release_header_field_func_type
) destroy_event_header_field
);
631 /* bt_ctf_event_common_initialize() logs errors */
638 BT_CTF_OBJECT_PUT_REF_AND_RESET(event
);
644 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
646 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
647 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_class(BT_CTF_TO_COMMON(event
)));
651 struct bt_ctf_stream
*bt_ctf_event_borrow_stream(struct bt_ctf_event
*event
)
653 BT_ASSERT_DBG(event
);
654 return (struct bt_ctf_stream
*)
655 bt_ctf_object_borrow_parent(&BT_CTF_TO_COMMON(event
)->base
);
658 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
660 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
661 return bt_ctf_object_get_ref(bt_ctf_event_borrow_stream(event
));
664 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
, const char *name
,
665 struct bt_ctf_field
*field
)
667 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
668 BT_CTF_ASSERT_PRE_NON_NULL(field
, "Payload field");
669 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
670 return bt_ctf_field_structure_set_field_by_name(
671 (void *) event
->common
.payload_field
, name
, field
);
674 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
677 struct bt_ctf_field
*field
= NULL
;
679 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
682 field
= bt_ctf_field_structure_get_field_by_name(
683 BT_CTF_FROM_COMMON(event
->common
.payload_field
), name
);
685 field
= BT_CTF_FROM_COMMON(event
->common
.payload_field
);
686 bt_ctf_object_get_ref(field
);
692 struct bt_ctf_field
*bt_ctf_event_get_payload_field(
693 struct bt_ctf_event
*event
)
695 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_payload(BT_CTF_TO_COMMON(event
)));
698 struct bt_ctf_field
*bt_ctf_event_get_header(struct bt_ctf_event
*event
)
700 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_header(BT_CTF_TO_COMMON(event
)));
703 struct bt_ctf_field
*bt_ctf_event_get_context(struct bt_ctf_event
*event
)
705 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_context(BT_CTF_TO_COMMON(event
)));
708 struct bt_ctf_field
*bt_ctf_event_get_stream_event_context(
709 struct bt_ctf_event
*event
)
711 return bt_ctf_object_get_ref(bt_ctf_event_common_borrow_stream_event_context(
712 BT_CTF_TO_COMMON(event
)));
716 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
717 struct bt_ctfser
*ctfser
,
718 enum bt_ctf_byte_order native_byte_order
)
722 BT_ASSERT_DBG(event
);
723 BT_ASSERT_DBG(ctfser
);
725 BT_LOGT_STR("Serializing event's context field.");
726 if (event
->common
.context_field
) {
727 ret
= bt_ctf_field_serialize_recursive(
728 (void *) event
->common
.context_field
, ctfser
,
731 BT_LOGW("Cannot serialize event's context 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));
741 BT_LOGT_STR("Serializing event's payload field.");
742 if (event
->common
.payload_field
) {
743 ret
= bt_ctf_field_serialize_recursive(
744 (void *) event
->common
.payload_field
, ctfser
,
747 BT_LOGW("Cannot serialize event's payload field: "
748 "event-addr=%p, event-class-name=\"%s\", "
749 "event-class-id=%" PRId64
,
751 bt_ctf_event_class_common_get_name(event
->common
.class),
752 bt_ctf_event_class_common_get_id(event
->common
.class));
761 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
762 struct bt_ctf_field
*header
)
764 BT_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
765 BT_CTF_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_CTF_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_CTF_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_ctf_object_put_ref(event
->common
.header_field
->field
);
790 event
->common
.header_field
->field
= bt_ctf_object_get_ref(header
);
791 BT_LOGT("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_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
803 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
806 BT_CTF_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_CTF_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_ctf_object_put_ref(event
->common
.payload_field
);
824 event
->common
.payload_field
= bt_ctf_object_get_ref(payload
);
825 BT_LOGT("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_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
837 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
840 BT_CTF_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_CTF_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_ctf_object_put_ref(event
->common
.context_field
);
857 event
->common
.context_field
= bt_ctf_object_get_ref(context
);
858 BT_LOGT("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_CTF_ASSERT_PRE_NON_NULL(event
, "Event");
870 BT_CTF_ASSERT_PRE_EVENT_COMMON_HOT(BT_CTF_TO_COMMON(event
), "Event");
872 if (stream_event_context
) {
873 BT_CTF_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_CTF_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_ctf_object_put_ref(event
->common
.stream_event_context_field
);
892 event
->common
.stream_event_context_field
= bt_ctf_object_get_ref(stream_event_context
);
893 BT_LOGT("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
);