4 * Babeltrace CTF IR - Event
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/ctf-writer/event.h>
30 #include <babeltrace/ctf-writer/event-types.h>
31 #include <babeltrace/ctf-writer/event-fields.h>
32 #include <babeltrace/ctf-ir/event-fields-internal.h>
33 #include <babeltrace/ctf-ir/event-types-internal.h>
34 #include <babeltrace/ctf-ir/event-internal.h>
35 #include <babeltrace/ctf-ir/stream-class.h>
36 #include <babeltrace/ctf-ir/stream-class-internal.h>
37 #include <babeltrace/ctf-ir/trace-internal.h>
38 #include <babeltrace/ctf-ir/validation-internal.h>
39 #include <babeltrace/ctf-ir/utils.h>
40 #include <babeltrace/ref.h>
41 #include <babeltrace/ctf-ir/attributes-internal.h>
42 #include <babeltrace/compiler.h>
45 void bt_ctf_event_class_destroy(struct bt_object
*obj
);
47 void bt_ctf_event_destroy(struct bt_object
*obj
);
49 int set_integer_field_value(struct bt_ctf_field
*field
, uint64_t value
);
51 struct bt_ctf_event_class
*bt_ctf_event_class_create(const char *name
)
54 struct bt_value
*obj
= NULL
;
55 struct bt_ctf_event_class
*event_class
= NULL
;
57 if (bt_ctf_validate_identifier(name
)) {
61 event_class
= g_new0(struct bt_ctf_event_class
, 1);
66 bt_object_init(event_class
, bt_ctf_event_class_destroy
);
67 event_class
->fields
= bt_ctf_field_type_structure_create();
68 if (!event_class
->fields
) {
72 event_class
->attributes
= bt_ctf_attributes_create();
73 if (!event_class
->attributes
) {
77 obj
= bt_value_integer_create_init(-1);
82 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
90 obj
= bt_value_string_create_init(name
);
95 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
111 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
113 struct bt_value
*obj
= NULL
;
114 const char *name
= NULL
;
120 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
121 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
126 if (bt_value_string_get(obj
, &name
)) {
135 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
137 struct bt_value
*obj
= NULL
;
145 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
146 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
151 if (bt_value_integer_get(obj
, &ret
)) {
156 /* means ID is not set */
166 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
170 struct bt_value
*obj
= NULL
;
171 struct bt_ctf_stream_class
*stream_class
= NULL
;
179 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
182 * We don't allow changing the id if the event class has already
183 * been added to a stream class.
189 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
190 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
195 if (bt_value_integer_set(obj
, id
)) {
202 BT_PUT(stream_class
);
206 int bt_ctf_event_class_set_attribute(
207 struct bt_ctf_event_class
*event_class
, const char *name
,
208 struct bt_value
*value
)
212 if (!event_class
|| !name
|| !value
|| event_class
->frozen
) {
217 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel")) {
218 if (!bt_value_is_integer(value
)) {
222 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri")) {
223 if (!bt_value_is_string(value
)) {
228 /* unknown attribute */
233 /* "id" special case: >= 0 */
234 if (!strcmp(name
, "id")) {
237 ret
= bt_value_integer_get(value
, &val
);
249 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
256 int bt_ctf_event_class_get_attribute_count(
257 struct bt_ctf_event_class
*event_class
)
266 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
273 bt_ctf_event_class_get_attribute_name(
274 struct bt_ctf_event_class
*event_class
, int index
)
283 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
290 bt_ctf_event_class_get_attribute_value(struct bt_ctf_event_class
*event_class
,
293 struct bt_value
*ret
;
300 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
307 bt_ctf_event_class_get_attribute_value_by_name(
308 struct bt_ctf_event_class
*event_class
, const char *name
)
310 struct bt_value
*ret
;
312 if (!event_class
|| !name
) {
317 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
325 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
326 struct bt_ctf_event_class
*event_class
)
328 return (struct bt_ctf_stream_class
*) bt_object_get_parent(event_class
);
331 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
332 struct bt_ctf_event_class
*event_class
)
334 struct bt_ctf_field_type
*payload
= NULL
;
340 bt_get(event_class
->fields
);
341 payload
= event_class
->fields
;
346 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
347 struct bt_ctf_field_type
*payload
)
351 if (!event_class
|| !payload
||
352 bt_ctf_field_type_get_type_id(payload
) !=
353 BT_CTF_TYPE_ID_STRUCT
) {
359 bt_put(event_class
->fields
);
360 event_class
->fields
= payload
;
365 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
366 struct bt_ctf_field_type
*type
,
371 if (!event_class
|| !type
|| bt_ctf_validate_identifier(name
) ||
372 event_class
->frozen
) {
377 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
378 BT_CTF_TYPE_ID_STRUCT
) {
383 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
389 int bt_ctf_event_class_get_field_count(
390 struct bt_ctf_event_class
*event_class
)
399 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
400 BT_CTF_TYPE_ID_STRUCT
) {
405 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
410 int bt_ctf_event_class_get_field(struct bt_ctf_event_class
*event_class
,
411 const char **field_name
, struct bt_ctf_field_type
**field_type
,
416 if (!event_class
|| index
< 0) {
421 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
422 BT_CTF_TYPE_ID_STRUCT
) {
427 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
428 field_name
, field_type
, index
);
433 struct bt_ctf_field_type
*bt_ctf_event_class_get_field_by_name(
434 struct bt_ctf_event_class
*event_class
, const char *name
)
437 struct bt_ctf_field_type
*field_type
= NULL
;
439 if (!event_class
|| !name
) {
443 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
444 BT_CTF_TYPE_ID_STRUCT
) {
448 name_quark
= g_quark_try_string(name
);
454 * No need to increment field_type's reference count since getting it
455 * from the structure already does.
457 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
458 event_class
->fields
, name
);
463 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
464 struct bt_ctf_event_class
*event_class
)
466 struct bt_ctf_field_type
*context_type
= NULL
;
468 if (!event_class
|| !event_class
->context
) {
472 bt_get(event_class
->context
);
473 context_type
= event_class
->context
;
478 int bt_ctf_event_class_set_context_type(
479 struct bt_ctf_event_class
*event_class
,
480 struct bt_ctf_field_type
*context
)
484 if (!event_class
|| !context
|| event_class
->frozen
) {
489 if (bt_ctf_field_type_get_type_id(context
) != BT_CTF_TYPE_ID_STRUCT
) {
495 bt_put(event_class
->context
);
496 event_class
->context
= context
;
502 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
507 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
513 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
517 struct bt_value
*obj
;
519 obj
= bt_value_integer_create_init(stream_id
);
526 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
529 if (event_class
->frozen
) {
530 bt_ctf_attributes_freeze(event_class
->attributes
);
538 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
541 enum bt_ctf_validation_flag validation_flags
=
542 BT_CTF_VALIDATION_FLAG_STREAM
|
543 BT_CTF_VALIDATION_FLAG_EVENT
;
544 struct bt_ctf_event
*event
= NULL
;
545 struct bt_ctf_trace
*trace
= NULL
;
546 struct bt_ctf_stream_class
*stream_class
= NULL
;
547 struct bt_ctf_field_type
*packet_header_type
= NULL
;
548 struct bt_ctf_field_type
*packet_context_type
= NULL
;
549 struct bt_ctf_field_type
*event_header_type
= NULL
;
550 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
551 struct bt_ctf_field_type
*event_context_type
= NULL
;
552 struct bt_ctf_field_type
*event_payload_type
= NULL
;
553 struct bt_ctf_field
*event_header
= NULL
;
554 struct bt_ctf_field
*event_context
= NULL
;
555 struct bt_ctf_field
*event_payload
= NULL
;
556 struct bt_value
*environment
= NULL
;
557 struct bt_ctf_validation_output validation_output
= { 0 };
564 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
567 * We disallow the creation of an event if its event class has not been
568 * associated to a stream class.
574 /* A stream class should always have an existing event header type */
575 assert(stream_class
->event_header_type
);
577 /* The event class was frozen when added to its stream class */
578 assert(event_class
->frozen
);
580 /* Validate the trace (if any), the stream class, and the event class */
581 trace
= bt_ctf_stream_class_get_trace(stream_class
);
583 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
584 trace_valid
= trace
->valid
;
586 environment
= trace
->environment
;
589 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(
591 event_header_type
= bt_ctf_stream_class_get_event_header_type(
593 stream_event_ctx_type
= bt_ctf_stream_class_get_event_context_type(
595 event_context_type
= bt_ctf_event_class_get_context_type(event_class
);
596 event_payload_type
= bt_ctf_event_class_get_payload_type(event_class
);
597 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
598 packet_context_type
, event_header_type
, stream_event_ctx_type
,
599 event_context_type
, event_payload_type
, trace_valid
,
600 stream_class
->valid
, event_class
->valid
,
601 &validation_output
, validation_flags
);
602 BT_PUT(packet_header_type
);
603 BT_PUT(packet_context_type
);
604 BT_PUT(event_header_type
);
605 BT_PUT(stream_event_ctx_type
);
606 BT_PUT(event_context_type
);
607 BT_PUT(event_payload_type
);
611 * This means something went wrong during the validation
612 * process, not that the objects are invalid.
617 if ((validation_output
.valid_flags
& validation_flags
) !=
619 /* Invalid trace/stream class/event class */
624 * At this point we know the trace (if associated to the stream
625 * class), the stream class, and the event class, with their
626 * current types, are valid. We may proceed with creating
629 event
= g_new0(struct bt_ctf_event
, 1);
634 bt_object_init(event
, bt_ctf_event_destroy
);
637 * event does not share a common ancestor with the event class; it has
638 * to guarantee its existence by holding a reference. This reference
639 * shall be released once the event is associated to a stream since,
640 * from that point, the event and its class will share the same
643 event
->event_class
= bt_get(event_class
);
645 bt_ctf_field_create(validation_output
.event_header_type
);
651 if (validation_output
.event_context_type
) {
652 event_context
= bt_ctf_field_create(
653 validation_output
.event_context_type
);
654 if (!event_context
) {
659 if (validation_output
.event_payload_type
) {
660 event_payload
= bt_ctf_field_create(
661 validation_output
.event_payload_type
);
662 if (!event_payload
) {
668 * At this point all the fields are created, potentially from
669 * validated copies of field types, so that the field types and
670 * fields can be replaced in the trace, stream class,
671 * event class, and created event.
673 bt_ctf_validation_replace_types(trace
, stream_class
,
674 event_class
, &validation_output
, validation_flags
);
675 BT_MOVE(event
->event_header
, event_header
);
676 BT_MOVE(event
->context_payload
, event_context
);
677 BT_MOVE(event
->fields_payload
, event_payload
);
680 * Put what was not moved in bt_ctf_validation_replace_types().
682 bt_ctf_validation_output_put_types(&validation_output
);
685 * Freeze the stream class since the event header must not be changed
688 bt_ctf_stream_class_freeze(stream_class
);
691 * Mark stream class, and event class as valid since
692 * they're all frozen now.
694 stream_class
->valid
= 1;
695 event_class
->valid
= 1;
697 /* Put stuff we borrowed from the event class */
698 BT_PUT(stream_class
);
704 bt_ctf_validation_output_put_types(&validation_output
);
706 BT_PUT(stream_class
);
708 BT_PUT(event_header
);
709 BT_PUT(event_context
);
710 BT_PUT(event_payload
);
711 assert(!packet_header_type
);
712 assert(!packet_context_type
);
713 assert(!event_header_type
);
714 assert(!stream_event_ctx_type
);
715 assert(!event_context_type
);
716 assert(!event_payload_type
);
721 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
723 struct bt_ctf_event_class
*event_class
= NULL
;
729 event_class
= event
->event_class
;
735 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
737 return (struct bt_ctf_stream
*) bt_object_get_parent(event
);
740 struct bt_ctf_clock
*bt_ctf_event_get_clock(struct bt_ctf_event
*event
)
742 struct bt_ctf_clock
*clock
= NULL
;
743 struct bt_ctf_event_class
*event_class
;
744 struct bt_ctf_stream_class
*stream_class
;
750 event_class
= bt_ctf_event_get_class(event
);
755 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
757 goto error_put_event_class
;
760 clock
= bt_ctf_stream_class_get_clock(stream_class
);
762 goto error_put_stream_class
;
765 error_put_stream_class
:
766 bt_put(stream_class
);
767 error_put_event_class
:
773 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
,
775 struct bt_ctf_field
*payload
)
779 if (!event
|| !payload
) {
785 ret
= bt_ctf_field_structure_set_field(event
->fields_payload
,
788 struct bt_ctf_field_type
*payload_type
;
790 payload_type
= bt_ctf_field_get_type(payload
);
792 if (bt_ctf_field_type_compare(payload_type
,
793 event
->event_class
->fields
) == 0) {
794 bt_put(event
->fields_payload
);
796 event
->fields_payload
= payload
;
801 bt_put(payload_type
);
807 struct bt_ctf_field
*bt_ctf_event_get_payload_field(struct bt_ctf_event
*event
)
809 struct bt_ctf_field
*payload
= NULL
;
811 if (!event
|| !event
->fields_payload
) {
815 payload
= event
->fields_payload
;
821 int bt_ctf_event_set_payload_field(struct bt_ctf_event
*event
,
822 struct bt_ctf_field
*payload
)
825 struct bt_ctf_field_type
*payload_type
= NULL
;
827 if (!event
|| !payload
) {
832 payload_type
= bt_ctf_field_get_type(payload
);
838 if (bt_ctf_field_type_get_type_id(payload_type
) !=
839 BT_CTF_TYPE_ID_STRUCT
) {
845 bt_put(event
->fields_payload
);
846 event
->fields_payload
= payload
;
849 bt_put(payload_type
);
853 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
856 struct bt_ctf_field
*field
= NULL
;
863 field
= bt_ctf_field_structure_get_field(event
->fields_payload
,
866 field
= event
->fields_payload
;
873 struct bt_ctf_field
*bt_ctf_event_get_payload_by_index(
874 struct bt_ctf_event
*event
, int index
)
876 struct bt_ctf_field
*field
= NULL
;
878 if (!event
|| index
< 0) {
882 field
= bt_ctf_field_structure_get_field_by_index(event
->fields_payload
,
888 struct bt_ctf_field
*bt_ctf_event_get_header(
889 struct bt_ctf_event
*event
)
891 struct bt_ctf_field
*header
= NULL
;
893 if (!event
|| !event
->event_header
) {
897 header
= event
->event_header
;
903 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
904 struct bt_ctf_field
*header
)
907 struct bt_ctf_field_type
*field_type
= NULL
;
908 struct bt_ctf_stream_class
*stream_class
= NULL
;
910 if (!event
|| !header
) {
915 stream_class
= (struct bt_ctf_stream_class
*) bt_object_get_parent(
918 * Ensure the provided header's type matches the one registered to the
921 field_type
= bt_ctf_field_get_type(header
);
922 if (bt_ctf_field_type_compare(field_type
,
923 stream_class
->event_header_type
)) {
929 bt_put(event
->event_header
);
930 event
->event_header
= header
;
932 bt_put(stream_class
);
937 struct bt_ctf_field
*bt_ctf_event_get_event_context(
938 struct bt_ctf_event
*event
)
940 struct bt_ctf_field
*context
= NULL
;
942 if (!event
|| !event
->context_payload
) {
946 context
= event
->context_payload
;
952 int bt_ctf_event_set_event_context(struct bt_ctf_event
*event
,
953 struct bt_ctf_field
*context
)
956 struct bt_ctf_field_type
*field_type
= NULL
;
958 if (!event
|| !context
) {
963 field_type
= bt_ctf_field_get_type(context
);
964 if (bt_ctf_field_type_compare(field_type
,
965 event
->event_class
->context
)) {
971 bt_put(event
->context_payload
);
972 event
->context_payload
= context
;
978 void bt_ctf_event_get(struct bt_ctf_event
*event
)
983 void bt_ctf_event_put(struct bt_ctf_event
*event
)
989 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
991 struct bt_ctf_event_class
*event_class
;
993 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
994 bt_ctf_attributes_destroy(event_class
->attributes
);
995 bt_put(event_class
->context
);
996 bt_put(event_class
->fields
);
1001 void bt_ctf_event_destroy(struct bt_object
*obj
)
1003 struct bt_ctf_event
*event
;
1005 event
= container_of(obj
, struct bt_ctf_event
, base
);
1006 if (!event
->base
.parent
) {
1008 * Event was keeping a reference to its class since it shared no
1009 * common ancestor with it to guarantee they would both have the
1012 bt_put(event
->event_class
);
1014 bt_put(event
->event_header
);
1015 bt_put(event
->context_payload
);
1016 bt_put(event
->fields_payload
);
1021 int set_integer_field_value(struct bt_ctf_field
* field
, uint64_t value
)
1024 struct bt_ctf_field_type
*field_type
= NULL
;
1031 if (!bt_ctf_field_validate(field
)) {
1032 /* Payload already set, skip! (not an error) */
1036 field_type
= bt_ctf_field_get_type(field
);
1039 if (bt_ctf_field_type_get_type_id(field_type
) !=
1040 BT_CTF_TYPE_ID_INTEGER
) {
1041 /* Not an integer and the value is unset, error. */
1046 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
1047 ret
= bt_ctf_field_signed_integer_set_value(field
, (int64_t) value
);
1049 /* Value is out of range, error. */
1053 ret
= bt_ctf_field_unsigned_integer_set_value(field
, value
);
1055 /* Value is out of range, error. */
1065 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
1067 assert(event_class
);
1068 event_class
->frozen
= 1;
1069 bt_ctf_field_type_freeze(event_class
->context
);
1070 bt_ctf_field_type_freeze(event_class
->fields
);
1071 bt_ctf_attributes_freeze(event_class
->attributes
);
1075 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
1076 struct metadata_context
*context
)
1081 struct bt_value
*attr_value
= NULL
;
1083 assert(event_class
);
1086 context
->current_indentation_level
= 1;
1087 g_string_assign(context
->field_name
, "");
1088 g_string_append(context
->string
, "event {\n");
1089 count
= bt_ctf_event_class_get_attribute_count(event_class
);
1096 for (i
= 0; i
< count
; ++i
) {
1097 const char *attr_name
= NULL
;
1099 attr_name
= bt_ctf_event_class_get_attribute_name(
1101 attr_value
= bt_ctf_event_class_get_attribute_value(
1104 if (!attr_name
|| !attr_value
) {
1109 switch (bt_value_get_type(attr_value
)) {
1110 case BT_VALUE_TYPE_INTEGER
:
1114 ret
= bt_value_integer_get(attr_value
, &value
);
1120 g_string_append_printf(context
->string
,
1121 "\t%s = %" PRId64
";\n", attr_name
, value
);
1125 case BT_VALUE_TYPE_STRING
:
1129 ret
= bt_value_string_get(attr_value
, &value
);
1135 g_string_append_printf(context
->string
,
1136 "\t%s = \"%s\";\n", attr_name
, value
);
1141 /* should never happen */
1149 if (event_class
->context
) {
1150 g_string_append(context
->string
, "\tcontext := ");
1151 ret
= bt_ctf_field_type_serialize(event_class
->context
,
1156 g_string_append(context
->string
, ";\n");
1159 if (event_class
->fields
) {
1160 g_string_append(context
->string
, "\tfields := ");
1161 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
1165 g_string_append(context
->string
, ";\n");
1168 g_string_append(context
->string
, "};\n\n");
1170 context
->current_indentation_level
= 0;
1175 void bt_ctf_event_class_set_native_byte_order(
1176 struct bt_ctf_event_class
*event_class
,
1183 assert(byte_order
== 0 || byte_order
== LITTLE_ENDIAN
||
1184 byte_order
== BIG_ENDIAN
);
1186 bt_ctf_field_type_set_native_byte_order(event_class
->context
,
1188 bt_ctf_field_type_set_native_byte_order(event_class
->fields
,
1193 int bt_ctf_event_validate(struct bt_ctf_event
*event
)
1195 /* Make sure each field's payload has been set */
1199 ret
= bt_ctf_field_validate(event
->event_header
);
1204 ret
= bt_ctf_field_validate(event
->fields_payload
);
1209 if (event
->event_class
->context
) {
1210 ret
= bt_ctf_field_validate(event
->context_payload
);
1217 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
1218 struct ctf_stream_pos
*pos
)
1224 if (event
->context_payload
) {
1225 ret
= bt_ctf_field_serialize(event
->context_payload
, pos
);
1231 if (event
->fields_payload
) {
1232 ret
= bt_ctf_field_serialize(event
->fields_payload
, pos
);
1242 int bt_ctf_event_populate_event_header(struct bt_ctf_event
*event
)
1245 struct bt_ctf_field
*id_field
= NULL
, *timestamp_field
= NULL
;
1252 id_field
= bt_ctf_field_structure_get_field(event
->event_header
, "id");
1254 ret
= set_integer_field_value(id_field
,
1255 (uint64_t) bt_ctf_event_class_get_id(
1256 event
->event_class
));
1262 timestamp_field
= bt_ctf_field_structure_get_field(event
->event_header
,
1264 if (timestamp_field
) {
1265 struct bt_ctf_field_type
*timestamp_field_type
=
1266 bt_ctf_field_get_type(timestamp_field
);
1267 struct bt_ctf_clock
*mapped_clock
;
1269 assert(timestamp_field_type
);
1270 mapped_clock
= bt_ctf_field_type_integer_get_mapped_clock(
1271 timestamp_field_type
);
1272 bt_put(timestamp_field_type
);
1276 ret
= bt_ctf_clock_get_time(mapped_clock
, ×tamp
);
1277 bt_put(mapped_clock
);
1282 ret
= set_integer_field_value(timestamp_field
,
1291 bt_put(timestamp_field
);
1295 struct bt_ctf_event
*bt_ctf_event_copy(struct bt_ctf_event
*event
)
1297 struct bt_ctf_event
*copy
= NULL
;
1303 copy
= g_new0(struct bt_ctf_event
, 1);
1308 bt_object_init(copy
, bt_ctf_event_destroy
);
1309 copy
->event_class
= bt_get(event
->event_class
);
1311 if (event
->event_header
) {
1312 copy
->event_header
= bt_ctf_field_copy(event
->event_header
);
1314 if (!copy
->event_header
) {
1319 if (event
->context_payload
) {
1320 copy
->context_payload
= bt_ctf_field_copy(
1321 event
->context_payload
);
1323 if (!copy
->context_payload
) {
1328 if (event
->fields_payload
) {
1329 copy
->fields_payload
= bt_ctf_field_copy(event
->fields_payload
);
1331 if (!copy
->fields_payload
) {