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-ir/fields-internal.h>
30 #include <babeltrace/ctf-ir/field-types-internal.h>
31 #include <babeltrace/ctf-ir/event-internal.h>
32 #include <babeltrace/ctf-ir/stream-class.h>
33 #include <babeltrace/ctf-ir/stream-class-internal.h>
34 #include <babeltrace/ctf-ir/trace-internal.h>
35 #include <babeltrace/ctf-ir/validation-internal.h>
36 #include <babeltrace/ctf-ir/utils.h>
37 #include <babeltrace/ref.h>
38 #include <babeltrace/ctf-ir/attributes-internal.h>
39 #include <babeltrace/compiler.h>
42 void bt_ctf_event_class_destroy(struct bt_object
*obj
);
44 void bt_ctf_event_destroy(struct bt_object
*obj
);
46 int set_integer_field_value(struct bt_ctf_field
*field
, uint64_t value
);
48 struct bt_ctf_event_class
*bt_ctf_event_class_create(const char *name
)
51 struct bt_value
*obj
= NULL
;
52 struct bt_ctf_event_class
*event_class
= NULL
;
54 if (bt_ctf_validate_identifier(name
)) {
58 event_class
= g_new0(struct bt_ctf_event_class
, 1);
63 bt_object_init(event_class
, bt_ctf_event_class_destroy
);
64 event_class
->fields
= bt_ctf_field_type_structure_create();
65 if (!event_class
->fields
) {
69 event_class
->attributes
= bt_ctf_attributes_create();
70 if (!event_class
->attributes
) {
74 obj
= bt_value_integer_create_init(-1);
79 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
87 obj
= bt_value_string_create_init(name
);
92 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
108 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
110 struct bt_value
*obj
= NULL
;
111 const char *name
= NULL
;
117 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
118 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
123 if (bt_value_string_get(obj
, &name
)) {
132 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
134 struct bt_value
*obj
= NULL
;
142 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
143 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
148 if (bt_value_integer_get(obj
, &ret
)) {
153 /* means ID is not set */
163 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
167 struct bt_value
*obj
= NULL
;
168 struct bt_ctf_stream_class
*stream_class
= NULL
;
176 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
179 * We don't allow changing the id if the event class has already
180 * been added to a stream class.
186 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
187 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
192 if (bt_value_integer_set(obj
, id
)) {
199 BT_PUT(stream_class
);
203 int bt_ctf_event_class_set_attribute(
204 struct bt_ctf_event_class
*event_class
, const char *name
,
205 struct bt_value
*value
)
209 if (!event_class
|| !name
|| !value
|| event_class
->frozen
) {
214 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel")) {
215 if (!bt_value_is_integer(value
)) {
219 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri")) {
220 if (!bt_value_is_string(value
)) {
225 /* unknown attribute */
230 /* "id" special case: >= 0 */
231 if (!strcmp(name
, "id")) {
234 ret
= bt_value_integer_get(value
, &val
);
246 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
253 int bt_ctf_event_class_get_attribute_count(
254 struct bt_ctf_event_class
*event_class
)
263 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
270 bt_ctf_event_class_get_attribute_name(
271 struct bt_ctf_event_class
*event_class
, int index
)
280 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
287 bt_ctf_event_class_get_attribute_value(struct bt_ctf_event_class
*event_class
,
290 struct bt_value
*ret
;
297 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
304 bt_ctf_event_class_get_attribute_value_by_name(
305 struct bt_ctf_event_class
*event_class
, const char *name
)
307 struct bt_value
*ret
;
309 if (!event_class
|| !name
) {
314 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
322 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
323 struct bt_ctf_event_class
*event_class
)
325 return (struct bt_ctf_stream_class
*) bt_object_get_parent(event_class
);
328 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
329 struct bt_ctf_event_class
*event_class
)
331 struct bt_ctf_field_type
*payload
= NULL
;
337 bt_get(event_class
->fields
);
338 payload
= event_class
->fields
;
343 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
344 struct bt_ctf_field_type
*payload
)
348 if (!event_class
|| !payload
||
349 bt_ctf_field_type_get_type_id(payload
) !=
350 BT_CTF_TYPE_ID_STRUCT
) {
356 bt_put(event_class
->fields
);
357 event_class
->fields
= payload
;
362 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
363 struct bt_ctf_field_type
*type
,
368 if (!event_class
|| !type
|| bt_ctf_validate_identifier(name
) ||
369 event_class
->frozen
) {
374 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
375 BT_CTF_TYPE_ID_STRUCT
) {
380 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
386 int bt_ctf_event_class_get_field_count(
387 struct bt_ctf_event_class
*event_class
)
396 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
397 BT_CTF_TYPE_ID_STRUCT
) {
402 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
407 int bt_ctf_event_class_get_field(struct bt_ctf_event_class
*event_class
,
408 const char **field_name
, struct bt_ctf_field_type
**field_type
,
413 if (!event_class
|| index
< 0) {
418 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
419 BT_CTF_TYPE_ID_STRUCT
) {
424 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
425 field_name
, field_type
, index
);
430 struct bt_ctf_field_type
*bt_ctf_event_class_get_field_by_name(
431 struct bt_ctf_event_class
*event_class
, const char *name
)
434 struct bt_ctf_field_type
*field_type
= NULL
;
436 if (!event_class
|| !name
) {
440 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
441 BT_CTF_TYPE_ID_STRUCT
) {
445 name_quark
= g_quark_try_string(name
);
451 * No need to increment field_type's reference count since getting it
452 * from the structure already does.
454 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
455 event_class
->fields
, name
);
460 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
461 struct bt_ctf_event_class
*event_class
)
463 struct bt_ctf_field_type
*context_type
= NULL
;
465 if (!event_class
|| !event_class
->context
) {
469 bt_get(event_class
->context
);
470 context_type
= event_class
->context
;
475 int bt_ctf_event_class_set_context_type(
476 struct bt_ctf_event_class
*event_class
,
477 struct bt_ctf_field_type
*context
)
481 if (!event_class
|| !context
|| event_class
->frozen
) {
486 if (bt_ctf_field_type_get_type_id(context
) != BT_CTF_TYPE_ID_STRUCT
) {
492 bt_put(event_class
->context
);
493 event_class
->context
= context
;
499 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
504 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
510 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
514 struct bt_value
*obj
;
516 obj
= bt_value_integer_create_init(stream_id
);
523 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
526 if (event_class
->frozen
) {
527 bt_ctf_attributes_freeze(event_class
->attributes
);
535 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
538 enum bt_ctf_validation_flag validation_flags
=
539 BT_CTF_VALIDATION_FLAG_STREAM
|
540 BT_CTF_VALIDATION_FLAG_EVENT
;
541 struct bt_ctf_event
*event
= NULL
;
542 struct bt_ctf_trace
*trace
= NULL
;
543 struct bt_ctf_stream_class
*stream_class
= NULL
;
544 struct bt_ctf_field_type
*packet_header_type
= NULL
;
545 struct bt_ctf_field_type
*packet_context_type
= NULL
;
546 struct bt_ctf_field_type
*event_header_type
= NULL
;
547 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
548 struct bt_ctf_field_type
*event_context_type
= NULL
;
549 struct bt_ctf_field_type
*event_payload_type
= NULL
;
550 struct bt_ctf_field
*event_header
= NULL
;
551 struct bt_ctf_field
*event_context
= NULL
;
552 struct bt_ctf_field
*event_payload
= NULL
;
553 struct bt_value
*environment
= NULL
;
554 struct bt_ctf_validation_output validation_output
= { 0 };
561 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
564 * We disallow the creation of an event if its event class has not been
565 * associated to a stream class.
571 /* A stream class should always have an existing event header type */
572 assert(stream_class
->event_header_type
);
574 /* The event class was frozen when added to its stream class */
575 assert(event_class
->frozen
);
577 /* Validate the trace (if any), the stream class, and the event class */
578 trace
= bt_ctf_stream_class_get_trace(stream_class
);
580 packet_header_type
= bt_ctf_trace_get_packet_header_type(trace
);
581 trace_valid
= trace
->valid
;
583 environment
= trace
->environment
;
586 packet_context_type
= bt_ctf_stream_class_get_packet_context_type(
588 event_header_type
= bt_ctf_stream_class_get_event_header_type(
590 stream_event_ctx_type
= bt_ctf_stream_class_get_event_context_type(
592 event_context_type
= bt_ctf_event_class_get_context_type(event_class
);
593 event_payload_type
= bt_ctf_event_class_get_payload_type(event_class
);
594 ret
= bt_ctf_validate_class_types(environment
, packet_header_type
,
595 packet_context_type
, event_header_type
, stream_event_ctx_type
,
596 event_context_type
, event_payload_type
, trace_valid
,
597 stream_class
->valid
, event_class
->valid
,
598 &validation_output
, validation_flags
);
599 BT_PUT(packet_header_type
);
600 BT_PUT(packet_context_type
);
601 BT_PUT(event_header_type
);
602 BT_PUT(stream_event_ctx_type
);
603 BT_PUT(event_context_type
);
604 BT_PUT(event_payload_type
);
608 * This means something went wrong during the validation
609 * process, not that the objects are invalid.
614 if ((validation_output
.valid_flags
& validation_flags
) !=
616 /* Invalid trace/stream class/event class */
621 * At this point we know the trace (if associated to the stream
622 * class), the stream class, and the event class, with their
623 * current types, are valid. We may proceed with creating
626 event
= g_new0(struct bt_ctf_event
, 1);
631 bt_object_init(event
, bt_ctf_event_destroy
);
634 * event does not share a common ancestor with the event class; it has
635 * to guarantee its existence by holding a reference. This reference
636 * shall be released once the event is associated to a stream since,
637 * from that point, the event and its class will share the same
640 event
->event_class
= bt_get(event_class
);
642 bt_ctf_field_create(validation_output
.event_header_type
);
648 if (validation_output
.event_context_type
) {
649 event_context
= bt_ctf_field_create(
650 validation_output
.event_context_type
);
651 if (!event_context
) {
656 if (validation_output
.event_payload_type
) {
657 event_payload
= bt_ctf_field_create(
658 validation_output
.event_payload_type
);
659 if (!event_payload
) {
665 * At this point all the fields are created, potentially from
666 * validated copies of field types, so that the field types and
667 * fields can be replaced in the trace, stream class,
668 * event class, and created event.
670 bt_ctf_validation_replace_types(trace
, stream_class
,
671 event_class
, &validation_output
, validation_flags
);
672 BT_MOVE(event
->event_header
, event_header
);
673 BT_MOVE(event
->context_payload
, event_context
);
674 BT_MOVE(event
->fields_payload
, event_payload
);
677 * Put what was not moved in bt_ctf_validation_replace_types().
679 bt_ctf_validation_output_put_types(&validation_output
);
682 * Freeze the stream class since the event header must not be changed
685 bt_ctf_stream_class_freeze(stream_class
);
688 * Mark stream class, and event class as valid since
689 * they're all frozen now.
691 stream_class
->valid
= 1;
692 event_class
->valid
= 1;
694 /* Put stuff we borrowed from the event class */
695 BT_PUT(stream_class
);
701 bt_ctf_validation_output_put_types(&validation_output
);
703 BT_PUT(stream_class
);
705 BT_PUT(event_header
);
706 BT_PUT(event_context
);
707 BT_PUT(event_payload
);
708 assert(!packet_header_type
);
709 assert(!packet_context_type
);
710 assert(!event_header_type
);
711 assert(!stream_event_ctx_type
);
712 assert(!event_context_type
);
713 assert(!event_payload_type
);
718 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
720 struct bt_ctf_event_class
*event_class
= NULL
;
726 event_class
= event
->event_class
;
732 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
734 return (struct bt_ctf_stream
*) bt_object_get_parent(event
);
737 struct bt_ctf_clock
*bt_ctf_event_get_clock(struct bt_ctf_event
*event
)
739 struct bt_ctf_clock
*clock
= NULL
;
740 struct bt_ctf_event_class
*event_class
;
741 struct bt_ctf_stream_class
*stream_class
;
747 event_class
= bt_ctf_event_get_class(event
);
752 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
754 goto error_put_event_class
;
757 clock
= bt_ctf_stream_class_get_clock(stream_class
);
759 goto error_put_stream_class
;
762 error_put_stream_class
:
763 bt_put(stream_class
);
764 error_put_event_class
:
770 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
,
772 struct bt_ctf_field
*payload
)
776 if (!event
|| !payload
) {
782 ret
= bt_ctf_field_structure_set_field(event
->fields_payload
,
785 struct bt_ctf_field_type
*payload_type
;
787 payload_type
= bt_ctf_field_get_type(payload
);
789 if (bt_ctf_field_type_compare(payload_type
,
790 event
->event_class
->fields
) == 0) {
791 bt_put(event
->fields_payload
);
793 event
->fields_payload
= payload
;
798 bt_put(payload_type
);
804 struct bt_ctf_field
*bt_ctf_event_get_payload_field(struct bt_ctf_event
*event
)
806 struct bt_ctf_field
*payload
= NULL
;
808 if (!event
|| !event
->fields_payload
) {
812 payload
= event
->fields_payload
;
818 int bt_ctf_event_set_payload_field(struct bt_ctf_event
*event
,
819 struct bt_ctf_field
*payload
)
822 struct bt_ctf_field_type
*payload_type
= NULL
;
824 if (!event
|| !payload
) {
829 payload_type
= bt_ctf_field_get_type(payload
);
835 if (bt_ctf_field_type_get_type_id(payload_type
) !=
836 BT_CTF_TYPE_ID_STRUCT
) {
842 bt_put(event
->fields_payload
);
843 event
->fields_payload
= payload
;
846 bt_put(payload_type
);
850 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
853 struct bt_ctf_field
*field
= NULL
;
860 field
= bt_ctf_field_structure_get_field(event
->fields_payload
,
863 field
= event
->fields_payload
;
870 struct bt_ctf_field
*bt_ctf_event_get_payload_by_index(
871 struct bt_ctf_event
*event
, int index
)
873 struct bt_ctf_field
*field
= NULL
;
875 if (!event
|| index
< 0) {
879 field
= bt_ctf_field_structure_get_field_by_index(event
->fields_payload
,
885 struct bt_ctf_field
*bt_ctf_event_get_header(
886 struct bt_ctf_event
*event
)
888 struct bt_ctf_field
*header
= NULL
;
890 if (!event
|| !event
->event_header
) {
894 header
= event
->event_header
;
900 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
901 struct bt_ctf_field
*header
)
904 struct bt_ctf_field_type
*field_type
= NULL
;
905 struct bt_ctf_stream_class
*stream_class
= NULL
;
907 if (!event
|| !header
) {
912 stream_class
= (struct bt_ctf_stream_class
*) bt_object_get_parent(
915 * Ensure the provided header's type matches the one registered to the
918 field_type
= bt_ctf_field_get_type(header
);
919 if (bt_ctf_field_type_compare(field_type
,
920 stream_class
->event_header_type
)) {
926 bt_put(event
->event_header
);
927 event
->event_header
= header
;
929 bt_put(stream_class
);
934 struct bt_ctf_field
*bt_ctf_event_get_event_context(
935 struct bt_ctf_event
*event
)
937 struct bt_ctf_field
*context
= NULL
;
939 if (!event
|| !event
->context_payload
) {
943 context
= event
->context_payload
;
949 int bt_ctf_event_set_event_context(struct bt_ctf_event
*event
,
950 struct bt_ctf_field
*context
)
953 struct bt_ctf_field_type
*field_type
= NULL
;
955 if (!event
|| !context
) {
960 field_type
= bt_ctf_field_get_type(context
);
961 if (bt_ctf_field_type_compare(field_type
,
962 event
->event_class
->context
)) {
968 bt_put(event
->context_payload
);
969 event
->context_payload
= context
;
975 void bt_ctf_event_get(struct bt_ctf_event
*event
)
980 void bt_ctf_event_put(struct bt_ctf_event
*event
)
986 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
988 struct bt_ctf_event_class
*event_class
;
990 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
991 bt_ctf_attributes_destroy(event_class
->attributes
);
992 bt_put(event_class
->context
);
993 bt_put(event_class
->fields
);
998 void bt_ctf_event_destroy(struct bt_object
*obj
)
1000 struct bt_ctf_event
*event
;
1002 event
= container_of(obj
, struct bt_ctf_event
, base
);
1003 if (!event
->base
.parent
) {
1005 * Event was keeping a reference to its class since it shared no
1006 * common ancestor with it to guarantee they would both have the
1009 bt_put(event
->event_class
);
1011 bt_put(event
->event_header
);
1012 bt_put(event
->context_payload
);
1013 bt_put(event
->fields_payload
);
1018 int set_integer_field_value(struct bt_ctf_field
* field
, uint64_t value
)
1021 struct bt_ctf_field_type
*field_type
= NULL
;
1028 if (!bt_ctf_field_validate(field
)) {
1029 /* Payload already set, skip! (not an error) */
1033 field_type
= bt_ctf_field_get_type(field
);
1036 if (bt_ctf_field_type_get_type_id(field_type
) !=
1037 BT_CTF_TYPE_ID_INTEGER
) {
1038 /* Not an integer and the value is unset, error. */
1043 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
1044 ret
= bt_ctf_field_signed_integer_set_value(field
, (int64_t) value
);
1046 /* Value is out of range, error. */
1050 ret
= bt_ctf_field_unsigned_integer_set_value(field
, value
);
1052 /* Value is out of range, error. */
1062 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
1064 assert(event_class
);
1065 event_class
->frozen
= 1;
1066 bt_ctf_field_type_freeze(event_class
->context
);
1067 bt_ctf_field_type_freeze(event_class
->fields
);
1068 bt_ctf_attributes_freeze(event_class
->attributes
);
1072 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
1073 struct metadata_context
*context
)
1078 struct bt_value
*attr_value
= NULL
;
1080 assert(event_class
);
1083 context
->current_indentation_level
= 1;
1084 g_string_assign(context
->field_name
, "");
1085 g_string_append(context
->string
, "event {\n");
1086 count
= bt_ctf_event_class_get_attribute_count(event_class
);
1093 for (i
= 0; i
< count
; ++i
) {
1094 const char *attr_name
= NULL
;
1096 attr_name
= bt_ctf_event_class_get_attribute_name(
1098 attr_value
= bt_ctf_event_class_get_attribute_value(
1101 if (!attr_name
|| !attr_value
) {
1106 switch (bt_value_get_type(attr_value
)) {
1107 case BT_VALUE_TYPE_INTEGER
:
1111 ret
= bt_value_integer_get(attr_value
, &value
);
1117 g_string_append_printf(context
->string
,
1118 "\t%s = %" PRId64
";\n", attr_name
, value
);
1122 case BT_VALUE_TYPE_STRING
:
1126 ret
= bt_value_string_get(attr_value
, &value
);
1132 g_string_append_printf(context
->string
,
1133 "\t%s = \"%s\";\n", attr_name
, value
);
1138 /* should never happen */
1146 if (event_class
->context
) {
1147 g_string_append(context
->string
, "\tcontext := ");
1148 ret
= bt_ctf_field_type_serialize(event_class
->context
,
1153 g_string_append(context
->string
, ";\n");
1156 if (event_class
->fields
) {
1157 g_string_append(context
->string
, "\tfields := ");
1158 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
1162 g_string_append(context
->string
, ";\n");
1165 g_string_append(context
->string
, "};\n\n");
1167 context
->current_indentation_level
= 0;
1172 void bt_ctf_event_class_set_native_byte_order(
1173 struct bt_ctf_event_class
*event_class
,
1180 assert(byte_order
== 0 || byte_order
== LITTLE_ENDIAN
||
1181 byte_order
== BIG_ENDIAN
);
1183 bt_ctf_field_type_set_native_byte_order(event_class
->context
,
1185 bt_ctf_field_type_set_native_byte_order(event_class
->fields
,
1190 int bt_ctf_event_validate(struct bt_ctf_event
*event
)
1192 /* Make sure each field's payload has been set */
1196 ret
= bt_ctf_field_validate(event
->event_header
);
1201 ret
= bt_ctf_field_validate(event
->fields_payload
);
1206 if (event
->event_class
->context
) {
1207 ret
= bt_ctf_field_validate(event
->context_payload
);
1214 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
1215 struct ctf_stream_pos
*pos
)
1221 if (event
->context_payload
) {
1222 ret
= bt_ctf_field_serialize(event
->context_payload
, pos
);
1228 if (event
->fields_payload
) {
1229 ret
= bt_ctf_field_serialize(event
->fields_payload
, pos
);
1239 int bt_ctf_event_populate_event_header(struct bt_ctf_event
*event
)
1242 struct bt_ctf_field
*id_field
= NULL
, *timestamp_field
= NULL
;
1249 id_field
= bt_ctf_field_structure_get_field(event
->event_header
, "id");
1251 ret
= set_integer_field_value(id_field
,
1252 (uint64_t) bt_ctf_event_class_get_id(
1253 event
->event_class
));
1259 timestamp_field
= bt_ctf_field_structure_get_field(event
->event_header
,
1261 if (timestamp_field
) {
1262 struct bt_ctf_field_type
*timestamp_field_type
=
1263 bt_ctf_field_get_type(timestamp_field
);
1264 struct bt_ctf_clock
*mapped_clock
;
1266 assert(timestamp_field_type
);
1267 mapped_clock
= bt_ctf_field_type_integer_get_mapped_clock(
1268 timestamp_field_type
);
1269 bt_put(timestamp_field_type
);
1273 ret
= bt_ctf_clock_get_time(mapped_clock
, ×tamp
);
1274 bt_put(mapped_clock
);
1279 ret
= set_integer_field_value(timestamp_field
,
1288 bt_put(timestamp_field
);
1292 struct bt_ctf_event
*bt_ctf_event_copy(struct bt_ctf_event
*event
)
1294 struct bt_ctf_event
*copy
= NULL
;
1300 copy
= g_new0(struct bt_ctf_event
, 1);
1305 bt_object_init(copy
, bt_ctf_event_destroy
);
1306 copy
->event_class
= bt_get(event
->event_class
);
1308 if (event
->event_header
) {
1309 copy
->event_header
= bt_ctf_field_copy(event
->event_header
);
1311 if (!copy
->event_header
) {
1316 if (event
->context_payload
) {
1317 copy
->context_payload
= bt_ctf_field_copy(
1318 event
->context_payload
);
1320 if (!copy
->context_payload
) {
1325 if (event
->fields_payload
) {
1326 copy
->fields_payload
= bt_ctf_field_copy(event
->fields_payload
);
1328 if (!copy
->fields_payload
) {