+ trace = bt_ctf_stream_class_get_trace(stream_class);
+ if (trace) {
+ /*
+ * If the stream class is associated with a trace, then
+ * both those objects are frozen. Also, this event class
+ * is about to be frozen.
+ *
+ * Therefore the event class must be validated here.
+ * The trace and stream class should be valid at this
+ * point.
+ */
+ assert(trace->valid);
+ assert(stream_class->valid);
+ packet_header_type =
+ bt_ctf_trace_get_packet_header_type(trace);
+ packet_context_type =
+ bt_ctf_stream_class_get_packet_context_type(
+ stream_class);
+ event_header_type =
+ bt_ctf_stream_class_get_event_header_type(stream_class);
+ stream_event_ctx_type =
+ bt_ctf_stream_class_get_event_context_type(
+ stream_class);
+ event_context_type =
+ bt_ctf_event_class_get_context_type(event_class);
+ event_payload_type =
+ bt_ctf_event_class_get_payload_type(event_class);
+ ret = bt_ctf_validate_class_types(
+ trace->environment, packet_header_type,
+ packet_context_type, event_header_type,
+ stream_event_ctx_type, event_context_type,
+ event_payload_type, trace->valid,
+ stream_class->valid, event_class->valid,
+ &validation_output, validation_flags);
+ BT_PUT(packet_header_type);
+ BT_PUT(packet_context_type);
+ BT_PUT(event_header_type);
+ BT_PUT(stream_event_ctx_type);
+ BT_PUT(event_context_type);
+ BT_PUT(event_payload_type);
+
+ if (ret) {
+ /*
+ * This means something went wrong during the
+ * validation process, not that the objects are
+ * invalid.
+ */
+ goto end;
+ }
+
+ if ((validation_output.valid_flags & validation_flags) !=
+ validation_flags) {
+ /* Invalid event class */
+ ret = -1;
+ goto end;
+ }
+ }
+
+ /* Only set an event ID if none was explicitly set before */
+ *event_id = bt_ctf_event_class_get_id(event_class);
+ if (*event_id < 0) {
+ if (bt_ctf_event_class_set_id(event_class,
+ stream_class->next_event_id++)) {
+ ret = -1;
+ goto end;
+ }
+ *event_id = stream_class->next_event_id;
+ }
+
+ ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id);
+ if (ret) {
+ goto end;
+ }
+
+ bt_object_set_parent(event_class, stream_class);
+
+ if (trace) {
+ /*
+ * At this point we know that the function will be
+ * successful. Therefore we can replace the event
+ * class's field types with what's in the validation
+ * output structure and mark this event class as valid.
+ */
+ bt_ctf_validation_replace_types(NULL, NULL, event_class,
+ &validation_output, validation_flags);
+ event_class->valid = 1;
+
+ /*
+ * Put what was not moved in
+ * bt_ctf_validation_replace_types().
+ */
+ bt_ctf_validation_output_put_types(&validation_output);
+ }
+
+ /* Add to the event classes of the stream class */