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/utils.h>
39 #include <babeltrace/ctf-ir/common-internal.h>
40 #include <babeltrace/ctf-ir/ref.h>
41 #include <babeltrace/ctf-ir/attributes-internal.h>
42 #include <babeltrace/compiler.h>
45 void bt_ctf_event_class_destroy(struct bt_ref
*ref
);
47 void bt_ctf_event_destroy(struct bt_ref
*ref
);
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_ctf_base_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
,
107 bt_ctf_event_class_put(event_class
);
115 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
117 struct bt_value
*obj
= NULL
;
118 const char *name
= NULL
;
124 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
125 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
130 if (bt_value_string_get(obj
, &name
)) {
140 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
142 struct bt_value
*obj
= NULL
;
150 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
151 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
156 if (bt_value_integer_get(obj
, &ret
)) {
161 /* means ID is not set */
172 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
176 struct bt_value
*obj
= NULL
;
183 if (event_class
->stream_class
) {
185 * We don't allow changing the id if the event class has already
186 * been added to a stream class.
192 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
193 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
198 if (bt_value_integer_set(obj
, id
)) {
209 int bt_ctf_event_class_set_attribute(
210 struct bt_ctf_event_class
*event_class
, const char *name
,
211 struct bt_value
*value
)
215 if (!event_class
|| !name
|| !value
|| event_class
->frozen
) {
220 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel")) {
221 if (!bt_value_is_integer(value
)) {
225 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri")) {
226 if (!bt_value_is_string(value
)) {
231 /* unknown attribute */
236 /* "id" special case: >= 0 */
237 if (!strcmp(name
, "id")) {
240 ret
= bt_value_integer_get(value
, &val
);
252 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
259 int bt_ctf_event_class_get_attribute_count(
260 struct bt_ctf_event_class
*event_class
)
269 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
276 bt_ctf_event_class_get_attribute_name(
277 struct bt_ctf_event_class
*event_class
, int index
)
286 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
293 bt_ctf_event_class_get_attribute_value(struct bt_ctf_event_class
*event_class
,
296 struct bt_value
*ret
;
303 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
310 bt_ctf_event_class_get_attribute_value_by_name(
311 struct bt_ctf_event_class
*event_class
, const char *name
)
313 struct bt_value
*ret
;
315 if (!event_class
|| !name
) {
320 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
328 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
329 struct bt_ctf_event_class
*event_class
)
331 struct bt_ctf_stream_class
*stream_class
= NULL
;
337 stream_class
= event_class
->stream_class
;
338 bt_ctf_stream_class_get(stream_class
);
343 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
344 struct bt_ctf_event_class
*event_class
)
346 struct bt_ctf_field_type
*payload
= NULL
;
352 bt_ctf_field_type_get(event_class
->fields
);
353 payload
= event_class
->fields
;
358 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
359 struct bt_ctf_field_type
*payload
)
363 if (!event_class
|| !payload
||
364 bt_ctf_field_type_get_type_id(payload
) != CTF_TYPE_STRUCT
) {
369 bt_ctf_field_type_get(payload
);
370 bt_ctf_field_type_put(event_class
->fields
);
371 event_class
->fields
= payload
;
376 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
377 struct bt_ctf_field_type
*type
,
382 if (!event_class
|| !type
|| bt_ctf_validate_identifier(name
) ||
383 event_class
->frozen
) {
388 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
394 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
400 int bt_ctf_event_class_get_field_count(
401 struct bt_ctf_event_class
*event_class
)
410 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
416 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
421 int bt_ctf_event_class_get_field(struct bt_ctf_event_class
*event_class
,
422 const char **field_name
, struct bt_ctf_field_type
**field_type
,
427 if (!event_class
|| index
< 0) {
432 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
438 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
439 field_name
, field_type
, index
);
444 struct bt_ctf_field_type
*bt_ctf_event_class_get_field_by_name(
445 struct bt_ctf_event_class
*event_class
, const char *name
)
448 struct bt_ctf_field_type
*field_type
= NULL
;
450 if (!event_class
|| !name
) {
454 if (bt_ctf_field_type_get_type_id(event_class
->fields
) !=
459 name_quark
= g_quark_try_string(name
);
465 * No need to increment field_type's reference count since getting it
466 * from the structure already does.
468 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
469 event_class
->fields
, name
);
474 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
475 struct bt_ctf_event_class
*event_class
)
477 struct bt_ctf_field_type
*context_type
= NULL
;
479 if (!event_class
|| !event_class
->context
) {
483 bt_ctf_field_type_get(event_class
->context
);
484 context_type
= event_class
->context
;
489 int bt_ctf_event_class_set_context_type(
490 struct bt_ctf_event_class
*event_class
,
491 struct bt_ctf_field_type
*context
)
495 if (!event_class
|| !context
|| event_class
->frozen
) {
500 if (bt_ctf_field_type_get_type_id(context
) != CTF_TYPE_STRUCT
) {
505 bt_ctf_field_type_get(context
);
506 bt_ctf_field_type_put(event_class
->context
);
507 event_class
->context
= context
;
513 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
515 bt_ctf_get(event_class
);
518 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
520 bt_ctf_put(event_class
);
524 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
528 struct bt_value
*obj
;
530 obj
= bt_value_integer_create_init(stream_id
);
537 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
546 struct bt_ctf_event
*bt_ctf_event_create(struct bt_ctf_event_class
*event_class
)
548 struct bt_ctf_event
*event
= NULL
;
555 * The event class does not keep ownership of the stream class to
556 * which it as been added. Therefore, it can't assume it has been
557 * set. However, we disallow the creation of an event if its
558 * associated stream class has been reclaimed.
560 if (!event_class
->stream_class
) {
563 assert(event_class
->stream_class
->event_header_type
);
564 event
= g_new0(struct bt_ctf_event
, 1);
569 bt_ctf_base_init(event
, bt_ctf_event_destroy
);
570 bt_ctf_event_class_get(event_class
);
571 bt_ctf_event_class_freeze(event_class
);
572 event
->event_class
= event_class
;
574 event
->event_header
= bt_ctf_field_create(
575 event_class
->stream_class
->event_header_type
);
576 if (!event
->event_header
) {
579 if (event_class
->context
) {
580 event
->context_payload
= bt_ctf_field_create(
581 event_class
->context
);
582 if (!event
->context_payload
) {
586 event
->fields_payload
= bt_ctf_field_create(event_class
->fields
);
587 if (!event
->fields_payload
) {
592 * Freeze the stream class since the event header must not be changed
595 bt_ctf_stream_class_freeze(event_class
->stream_class
);
600 bt_ctf_event_destroy(&event
->base
.ref_count
);
606 struct bt_ctf_event_class
*bt_ctf_event_get_class(struct bt_ctf_event
*event
)
608 struct bt_ctf_event_class
*event_class
= NULL
;
614 event_class
= event
->event_class
;
615 bt_ctf_event_class_get(event_class
);
620 struct bt_ctf_stream
*bt_ctf_event_get_stream(struct bt_ctf_event
*event
)
622 struct bt_ctf_stream
*stream
= NULL
;
628 stream
= event
->stream
;
630 bt_ctf_stream_get(stream
);
636 struct bt_ctf_clock
*bt_ctf_event_get_clock(struct bt_ctf_event
*event
)
638 struct bt_ctf_clock
*clock
= NULL
;
639 struct bt_ctf_event_class
*event_class
;
640 struct bt_ctf_stream_class
*stream_class
;
646 event_class
= bt_ctf_event_get_class(event
);
651 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
653 goto error_put_event_class
;
656 clock
= bt_ctf_stream_class_get_clock(stream_class
);
658 goto error_put_stream_class
;
661 error_put_stream_class
:
662 bt_ctf_stream_class_put(stream_class
);
663 error_put_event_class
:
664 bt_ctf_event_class_put(event_class
);
669 int bt_ctf_event_set_payload(struct bt_ctf_event
*event
,
671 struct bt_ctf_field
*payload
)
675 if (!event
|| !payload
) {
681 ret
= bt_ctf_field_structure_set_field(event
->fields_payload
,
684 struct bt_ctf_field_type
*payload_type
;
686 payload_type
= bt_ctf_field_get_type(payload
);
687 if (payload_type
== event
->event_class
->fields
) {
688 bt_ctf_field_put(event
->fields_payload
);
689 bt_ctf_field_get(payload
);
690 event
->fields_payload
= payload
;
695 bt_ctf_field_type_put(payload_type
);
701 struct bt_ctf_field
*bt_ctf_event_get_payload_field(struct bt_ctf_event
*event
)
703 struct bt_ctf_field
*payload
= NULL
;
705 if (!event
|| !event
->fields_payload
) {
709 payload
= event
->fields_payload
;
710 bt_ctf_field_get(payload
);
715 int bt_ctf_event_set_payload_field(struct bt_ctf_event
*event
,
716 struct bt_ctf_field
*payload
)
719 struct bt_ctf_field_type
*payload_type
= NULL
;
721 if (!event
|| !payload
) {
726 payload_type
= bt_ctf_field_get_type(payload
);
732 if (bt_ctf_field_type_get_type_id(payload_type
) != CTF_TYPE_STRUCT
) {
737 bt_ctf_field_get(payload
);
738 if (event
->fields_payload
) {
739 bt_ctf_field_put(event
->fields_payload
);
741 event
->fields_payload
= payload
;
745 bt_ctf_field_type_put(payload_type
);
750 struct bt_ctf_field
*bt_ctf_event_get_payload(struct bt_ctf_event
*event
,
753 struct bt_ctf_field
*field
= NULL
;
760 field
= bt_ctf_field_structure_get_field(event
->fields_payload
,
763 field
= event
->fields_payload
;
764 bt_ctf_field_get(field
);
770 struct bt_ctf_field
*bt_ctf_event_get_payload_by_index(
771 struct bt_ctf_event
*event
, int index
)
773 struct bt_ctf_field
*field
= NULL
;
775 if (!event
|| index
< 0) {
779 field
= bt_ctf_field_structure_get_field_by_index(event
->fields_payload
,
785 struct bt_ctf_field
*bt_ctf_event_get_header(
786 struct bt_ctf_event
*event
)
788 struct bt_ctf_field
*header
= NULL
;
790 if (!event
|| !event
->event_header
) {
794 header
= event
->event_header
;
795 bt_ctf_field_get(header
);
800 int bt_ctf_event_set_header(struct bt_ctf_event
*event
,
801 struct bt_ctf_field
*header
)
804 struct bt_ctf_field_type
*field_type
= NULL
;
806 if (!event
|| !header
) {
811 /* Could be NULL since an event class doesn't own a stream class */
812 if (!event
->event_class
->stream_class
) {
818 * Ensure the provided header's type matches the one registered to the
821 field_type
= bt_ctf_field_get_type(header
);
822 if (field_type
!= event
->event_class
->stream_class
->event_header_type
) {
827 bt_ctf_field_get(header
);
828 bt_ctf_field_put(event
->event_header
);
829 event
->event_header
= header
;
832 bt_ctf_field_type_put(field_type
);
837 struct bt_ctf_field
*bt_ctf_event_get_event_context(
838 struct bt_ctf_event
*event
)
840 struct bt_ctf_field
*context
= NULL
;
842 if (!event
|| !event
->context_payload
) {
846 context
= event
->context_payload
;
847 bt_ctf_field_get(context
);
852 int bt_ctf_event_set_event_context(struct bt_ctf_event
*event
,
853 struct bt_ctf_field
*context
)
856 struct bt_ctf_field_type
*field_type
= NULL
;
858 if (!event
|| !context
) {
863 field_type
= bt_ctf_field_get_type(context
);
864 if (field_type
!= event
->event_class
->context
) {
869 bt_ctf_field_get(context
);
870 bt_ctf_field_put(event
->context_payload
);
871 event
->context_payload
= context
;
874 bt_ctf_field_type_put(field_type
);
879 void bt_ctf_event_get(struct bt_ctf_event
*event
)
884 void bt_ctf_event_put(struct bt_ctf_event
*event
)
890 void bt_ctf_event_class_destroy(struct bt_ref
*ref
)
892 struct bt_ctf_event_class
*event_class
;
893 struct bt_ctf_base
*base
;
900 * Don't call put() on the stream class. See comment in
901 * bt_ctf_event_class_set_stream_class for explanation.
903 base
= container_of(ref
, struct bt_ctf_base
, ref_count
);
904 event_class
= container_of(base
, struct bt_ctf_event_class
, base
);
905 if (event_class
->attributes
) {
906 bt_ctf_attributes_destroy(event_class
->attributes
);
908 if (event_class
->context
) {
909 bt_ctf_field_type_put(event_class
->context
);
911 if (event_class
->fields
) {
912 bt_ctf_field_type_put(event_class
->fields
);
918 void bt_ctf_event_destroy(struct bt_ref
*ref
)
920 struct bt_ctf_event
*event
;
921 struct bt_ctf_base
*base
;
927 base
= container_of(ref
, struct bt_ctf_base
, ref_count
);
928 event
= container_of(base
, struct bt_ctf_event
, base
);
929 if (event
->event_class
) {
930 bt_ctf_event_class_put(event
->event_class
);
932 if (event
->event_header
) {
933 bt_ctf_field_put(event
->event_header
);
935 if (event
->context_payload
) {
936 bt_ctf_field_put(event
->context_payload
);
938 if (event
->fields_payload
) {
939 bt_ctf_field_put(event
->fields_payload
);
945 int set_integer_field_value(struct bt_ctf_field
* field
, uint64_t value
)
948 struct bt_ctf_field_type
*field_type
= NULL
;
955 if (!bt_ctf_field_validate(field
)) {
956 /* Payload already set, skip! (not an error) */
960 field_type
= bt_ctf_field_get_type(field
);
963 if (bt_ctf_field_type_get_type_id(field_type
) != CTF_TYPE_INTEGER
) {
964 /* Not an integer and the value is unset, error. */
969 if (bt_ctf_field_type_integer_get_signed(field_type
)) {
970 ret
= bt_ctf_field_signed_integer_set_value(field
, (int64_t) value
);
972 /* Value is out of range, error. */
976 ret
= bt_ctf_field_unsigned_integer_set_value(field
, value
);
978 /* Value is out of range, error. */
983 bt_ctf_field_type_put(field_type
);
988 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
991 event_class
->frozen
= 1;
992 bt_ctf_field_type_freeze(event_class
->context
);
993 bt_ctf_field_type_freeze(event_class
->fields
);
994 bt_ctf_attributes_freeze(event_class
->attributes
);
998 int bt_ctf_event_class_set_stream_class(struct bt_ctf_event_class
*event_class
,
999 struct bt_ctf_stream_class
*stream_class
)
1008 /* Allow a NULL stream_class to unset the current stream_class */
1009 if (stream_class
&& event_class
->stream_class
) {
1014 event_class
->stream_class
= stream_class
;
1016 * We don't get() the stream_class since doing so would introduce
1017 * a circular ownership between event classes and stream classes.
1019 * A stream class will always unset itself from its events before
1020 * being destroyed. This ensures that a user won't get a pointer
1021 * to a stale stream class instance from an event class.
1028 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
1029 struct metadata_context
*context
)
1034 struct bt_value
*attr_value
= NULL
;
1036 assert(event_class
);
1039 context
->current_indentation_level
= 1;
1040 g_string_assign(context
->field_name
, "");
1041 g_string_append(context
->string
, "event {\n");
1042 count
= bt_ctf_event_class_get_attribute_count(event_class
);
1049 for (i
= 0; i
< count
; ++i
) {
1050 const char *attr_name
= NULL
;
1052 attr_name
= bt_ctf_event_class_get_attribute_name(
1054 attr_value
= bt_ctf_event_class_get_attribute_value(
1057 if (!attr_name
|| !attr_value
) {
1062 switch (bt_value_get_type(attr_value
)) {
1063 case BT_VALUE_TYPE_INTEGER
:
1067 ret
= bt_value_integer_get(attr_value
, &value
);
1073 g_string_append_printf(context
->string
,
1074 "\t%s = %" PRId64
";\n", attr_name
, value
);
1078 case BT_VALUE_TYPE_STRING
:
1082 ret
= bt_value_string_get(attr_value
, &value
);
1088 g_string_append_printf(context
->string
,
1089 "\t%s = \"%s\";\n", attr_name
, value
);
1094 /* should never happen */
1099 BT_VALUE_PUT(attr_value
);
1102 if (event_class
->context
) {
1103 g_string_append(context
->string
, "\tcontext := ");
1104 ret
= bt_ctf_field_type_serialize(event_class
->context
,
1109 g_string_append(context
->string
, ";\n");
1112 if (event_class
->fields
) {
1113 g_string_append(context
->string
, "\tfields := ");
1114 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
1118 g_string_append(context
->string
, ";\n");
1121 g_string_append(context
->string
, "};\n\n");
1123 context
->current_indentation_level
= 0;
1124 BT_VALUE_PUT(attr_value
);
1128 void bt_ctf_event_class_set_native_byte_order(
1129 struct bt_ctf_event_class
*event_class
,
1136 bt_ctf_field_type_set_native_byte_order(event_class
->context
,
1138 bt_ctf_field_type_set_native_byte_order(event_class
->fields
,
1143 int bt_ctf_event_validate(struct bt_ctf_event
*event
)
1145 /* Make sure each field's payload has been set */
1149 ret
= bt_ctf_field_validate(event
->event_header
);
1154 ret
= bt_ctf_field_validate(event
->fields_payload
);
1159 if (event
->event_class
->context
) {
1160 ret
= bt_ctf_field_validate(event
->context_payload
);
1167 int bt_ctf_event_serialize(struct bt_ctf_event
*event
,
1168 struct ctf_stream_pos
*pos
)
1174 if (event
->context_payload
) {
1175 ret
= bt_ctf_field_serialize(event
->context_payload
, pos
);
1181 if (event
->fields_payload
) {
1182 ret
= bt_ctf_field_serialize(event
->fields_payload
, pos
);
1192 int bt_ctf_event_populate_event_header(struct bt_ctf_event
*event
)
1195 struct bt_ctf_field
*id_field
= NULL
, *timestamp_field
= NULL
;
1202 id_field
= bt_ctf_field_structure_get_field(event
->event_header
, "id");
1204 ret
= set_integer_field_value(id_field
,
1205 (uint64_t) bt_ctf_event_class_get_id(
1206 event
->event_class
));
1212 timestamp_field
= bt_ctf_field_structure_get_field(event
->event_header
,
1214 if (timestamp_field
) {
1215 struct bt_ctf_field_type
*timestamp_field_type
=
1216 bt_ctf_field_get_type(timestamp_field
);
1217 struct bt_ctf_clock
*mapped_clock
;
1219 assert(timestamp_field_type
);
1220 mapped_clock
= bt_ctf_field_type_integer_get_mapped_clock(
1221 timestamp_field_type
);
1222 bt_ctf_field_type_put(timestamp_field_type
);
1224 uint64_t timestamp
= bt_ctf_clock_get_time(
1227 bt_ctf_clock_put(mapped_clock
);
1228 if (timestamp
== (uint64_t) -1ULL) {
1232 ret
= set_integer_field_value(timestamp_field
,
1241 bt_ctf_field_put(id_field
);
1243 if (timestamp_field
) {
1244 bt_ctf_field_put(timestamp_field
);
1250 int bt_ctf_event_set_stream(struct bt_ctf_event
*event
,
1251 struct bt_ctf_stream
*stream
)
1260 if (event
->stream
&& stream
) {
1261 /* Already attached to a stream */
1266 event
->stream
= stream
;
1271 struct bt_ctf_event
*bt_ctf_event_copy(struct bt_ctf_event
*event
)
1273 struct bt_ctf_event
*copy
= NULL
;
1279 copy
= g_new0(struct bt_ctf_event
, 1);
1284 bt_ctf_base_init(copy
, bt_ctf_event_destroy
);
1285 copy
->event_class
= event
->event_class
;
1286 bt_ctf_event_class_get(copy
->event_class
);
1287 copy
->stream
= event
->stream
;
1289 if (event
->event_header
) {
1290 copy
->event_header
= bt_ctf_field_copy(event
->event_header
);
1292 if (!copy
->event_header
) {
1297 if (event
->context_payload
) {
1298 copy
->context_payload
= bt_ctf_field_copy(
1299 event
->context_payload
);
1301 if (!copy
->context_payload
) {
1306 if (event
->fields_payload
) {
1307 copy
->fields_payload
= bt_ctf_field_copy(event
->fields_payload
);
1309 if (!copy
->fields_payload
) {
1318 if (copy
->event_class
) {
1319 bt_ctf_event_class_put(copy
->event_class
);
1322 if (copy
->event_header
) {
1323 bt_ctf_field_put(copy
->event_header
);
1326 if (copy
->context_payload
) {
1327 bt_ctf_field_put(copy
->context_payload
);
1330 if (copy
->fields_payload
) {
1331 bt_ctf_field_put(copy
->fields_payload
);