+ old_stream_class = bt_ctf_event_class_get_stream_class(event_class);
+ if (old_stream_class) {
+ /* Event class is already associated to a stream class. */
+ ret = -1;
+ goto end;
+ }
+
+ 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) {