+ /*
+ * The condition to automatically set the ID are:
+ *
+ * 1. The event header field "id" exists and is an integer
+ * field.
+ * 2. The event header field "id" is NOT set.
+ */
+ id_field = bt_ctf_field_structure_get_field(event->event_header, "id");
+ if (id_field && !bt_ctf_field_is_set(id_field)) {
+ ret = set_integer_field_value(id_field,
+ (uint64_t) bt_ctf_event_class_get_id(
+ event->event_class));
+ if (ret) {
+ goto end;
+ }
+ }
+
+ /*
+ * The conditions to automatically set the timestamp are:
+ *
+ * 1. The event header field "timestamp" exists and is an
+ * integer field.
+ * 2. This stream's class has a registered clock (set with
+ * bt_ctf_stream_class_set_clock()).
+ * 3. The event header field "timestamp" has its type mapped to
+ * a clock class which is also the clock class of this
+ * stream's class's registered clock.
+ * 4. The event header field "timestamp" is NOT set.
+ */
+ timestamp_field = bt_ctf_field_structure_get_field(event->event_header,
+ "timestamp");
+ if (timestamp_field && !bt_ctf_field_is_set(timestamp_field) &&
+ stream->stream_class->clock) {
+ struct bt_ctf_clock_class *stream_class_clock_class =
+ stream->stream_class->clock->clock_class;
+ struct bt_ctf_field_type *timestamp_field_type =
+ bt_ctf_field_get_type(timestamp_field);
+
+ assert(timestamp_field_type);
+ mapped_clock_class =
+ bt_ctf_field_type_integer_get_mapped_clock_class(
+ timestamp_field_type);
+ BT_PUT(timestamp_field_type);
+ if (mapped_clock_class == stream_class_clock_class) {
+ uint64_t timestamp;
+
+ ret = bt_ctf_clock_get_value(
+ stream->stream_class->clock,
+ ×tamp);
+ if (ret) {
+ goto end;
+ }
+
+ ret = set_integer_field_value(timestamp_field,
+ timestamp);
+ if (ret) {
+ goto end;
+ }
+ }
+ }
+
+end:
+ bt_put(id_field);
+ bt_put(timestamp_field);
+ bt_put(mapped_clock_class);
+ return ret;
+}
+
+int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
+ struct bt_ctf_event *event)
+{
+ int ret = 0;
+
+ if (!stream || !event || stream->pos.fd < 0) {
+ ret = -1;