- int ret, i;
- int64_t stream_id;
- struct bt_ctf_validation_output trace_sc_validation_output = { 0 };
- struct bt_ctf_validation_output *ec_validation_outputs = NULL;
- const enum bt_ctf_validation_flag trace_sc_validation_flags =
- BT_CTF_VALIDATION_FLAG_TRACE |
- BT_CTF_VALIDATION_FLAG_STREAM;
- const enum bt_ctf_validation_flag ec_validation_flags =
- BT_CTF_VALIDATION_FLAG_EVENT;
- struct bt_ctf_field_type *packet_header_type = NULL;
- struct bt_ctf_field_type *packet_context_type = NULL;
- struct bt_ctf_field_type *event_header_type = NULL;
- struct bt_ctf_field_type *stream_event_ctx_type = NULL;
- int event_class_count;
- struct bt_ctf_trace *current_parent_trace = NULL;
-
- if (!trace || !stream_class) {
- ret = -1;
- goto end;
- }
-
- /*
- * At the end of this function we freeze the trace, so its
- * native byte order must NOT be BT_CTF_BYTE_ORDER_NATIVE.
- */
- if (trace->native_byte_order == BT_CTF_BYTE_ORDER_NATIVE) {
- ret = -1;
- goto end;
- }
-
- current_parent_trace = bt_ctf_stream_class_get_trace(stream_class);
- if (current_parent_trace) {
- /* Stream class is already associated to a trace, abort. */
- ret = -1;
- goto end;
- }
-
- event_class_count =
- bt_ctf_stream_class_get_event_class_count(stream_class);
- assert(event_class_count >= 0);
-
- /* Check for duplicate stream classes */
- for (i = 0; i < trace->stream_classes->len; i++) {
- if (trace->stream_classes->pdata[i] == stream_class) {
- /* Stream class already registered to the trace */
- ret = -1;
- goto end;
- }
- }
-
- if (stream_class->clock) {
- struct bt_ctf_clock_class *stream_clock_class =
- stream_class->clock->clock_class;
-
- if (trace->is_created_by_writer) {
- /*
- * Make sure this clock was also added to the
- * trace (potentially through its CTF writer
- * owner).
- */
- size_t i;
-
- for (i = 0; i < trace->clocks->len; i++) {
- if (trace->clocks->pdata[i] ==
- stream_clock_class) {
- /* Found! */
- break;
- }
- }
-
- if (i == trace->clocks->len) {
- /* Not found */
- ret = -1;
- goto end;
- }
- } else {
- /*
- * This trace was NOT created by a CTF writer,
- * thus do not allow the stream class to add to
- * have a clock at all. Those are two
- * independent APIs (non-writer and writer
- * APIs), and isolating them simplifies things.
- */
- ret = -1;
- goto end;
- }
- }
-
- /*
- * 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);