- int ret = 0;
- int64_t *event_id = NULL;
- struct bt_trace *trace = NULL;
- struct bt_stream_class *old_stream_class = NULL;
- struct bt_validation_output validation_output = { 0 };
- struct bt_field_type *packet_header_type = NULL;
- struct bt_field_type *packet_context_type = NULL;
- struct bt_field_type *event_header_type = NULL;
- struct bt_field_type *stream_event_ctx_type = NULL;
- struct bt_field_type *event_context_type = NULL;
- struct bt_field_type *event_payload_type = NULL;
- const enum bt_validation_flag validation_flags =
- BT_VALIDATION_FLAG_EVENT;
- struct bt_clock_class *expected_clock_class = NULL;
-
- if (!stream_class) {
- BT_LOGW("Invalid parameter: stream class is NULL: "
- "stream-class-addr=%p", stream_class);
- ret = -1;
- goto end;
- }
-
- trace = bt_stream_class_borrow_trace(stream_class);
- if (trace && trace->is_static) {
- BT_LOGW("Invalid parameter: stream class's trace is static: "
- "trace-addr=%p, trace-name=\"%s\"",
- trace, bt_trace_get_name(trace));
- ret = -1;
- goto end;
- }
-
- if (!stream_class || !event_class) {
- BT_LOGW("Invalid parameter: stream class or event class is NULL: "
- "stream-class-addr=%p, event-class-addr=%p",
- stream_class, event_class);
- ret = -1;
- goto end;
- }
-
- BT_LOGD("Adding event class to stream class: "
- "stream-class-addr=%p, stream-class-name=\"%s\", "
- "stream-class-id=%" PRId64 ", event-class-addr=%p, "
- "event-class-name=\"%s\", event-class-id=%" PRId64,
- stream_class, bt_stream_class_get_name(stream_class),
- bt_stream_class_get_id(stream_class),
- event_class,
- bt_event_class_get_name(event_class),
- bt_event_class_get_id(event_class));
- trace = bt_stream_class_borrow_trace(stream_class);
-
- if (stream_class->frozen) {
- /*
- * We only check that the event class to be added has a
- * single class which matches the stream class's
- * expected clock class if the stream class is frozen.
- * If it's not, then this event class is added "as is"
- * and the validation will be performed when calling
- * either bt_trace_add_stream_class() or
- * bt_event_create(). This is because the stream class's
- * field types (packet context, event header, event
- * context) could change before the next call to one of
- * those two functions.
- */
- expected_clock_class = bt_get(stream_class->clock_class);
-
- /*
- * At this point, `expected_clock_class` can be NULL,
- * and bt_event_class_validate_single_clock_class()
- * below can set it.
- */
- ret = bt_event_class_validate_single_clock_class(
- event_class, &expected_clock_class);
- if (ret) {
- BT_LOGW("Event class contains a field type which is not "
- "recursively mapped to its stream class's "
- "expected clock class: "
- "stream-class-addr=%p, "
- "stream-class-id=%" PRId64 ", "
- "stream-class-name=\"%s\", "
- "expected-clock-class-addr=%p, "
- "expected-clock-class-name=\"%s\"",
- stream_class,
- bt_stream_class_get_id(stream_class),
- bt_stream_class_get_name(stream_class),
- expected_clock_class,
- expected_clock_class ?
- bt_clock_class_get_name(expected_clock_class) :
- NULL);
- goto end;
- }
- }
-
- event_id = g_new(int64_t, 1);
- if (!event_id) {
- BT_LOGE_STR("Failed to allocate one int64_t.");
- ret = -1;
- goto end;
- }