+ /*
+ * If the stream class has a clock, register this clock to this
+ * trace if not already done.
+ */
+ if (stream_class->clock) {
+ const char *clock_name =
+ bt_ctf_clock_get_name(stream_class->clock);
+ struct bt_ctf_clock *trace_clock;
+
+ assert(clock_name);
+ trace_clock = bt_ctf_trace_get_clock_by_name(trace, clock_name);
+ bt_put(trace_clock);
+ if (trace_clock) {
+ if (trace_clock != stream_class->clock) {
+ /*
+ * Error: two different clocks in the
+ * trace would share the same name.
+ */
+ ret = -1;
+ goto end;
+ }
+ } else {
+ clock_to_add_to_trace = bt_get(stream_class->clock);
+ }
+ }
+
+ /*
+ * We're about to freeze both the trace and the stream class.
+ * Also, each event class contained in this stream class are
+ * already frozen.
+ *
+ * This trace, this stream class, and all its event classes
+ * should be valid at this point.
+ *
+ * Validate trace and stream class first, then each event
+ * class of this stream class can be validated individually.
+ */
+ 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);
+ ret = bt_ctf_validate_class_types(trace->environment,
+ packet_header_type, packet_context_type, event_header_type,
+ stream_event_ctx_type, NULL, NULL, trace->valid,
+ stream_class->valid, 1, &trace_sc_validation_output,
+ trace_sc_validation_flags);
+ BT_PUT(packet_header_type);
+ BT_PUT(packet_context_type);
+ BT_PUT(event_header_type);
+ BT_PUT(stream_event_ctx_type);
+