+#include <inttypes.h>
+#include <inttypes.h>
+#include <stdlib.h>
+
+BT_HIDDEN
+void bt_ctf_event_class_common_finalize(struct bt_ctf_object *obj)
+{
+ struct bt_ctf_event_class_common *event_class;
+
+ event_class = container_of(obj, struct bt_ctf_event_class_common, base);
+ BT_LOGD("Finalizing common event class: addr=%p, name=\"%s\", id=%" PRId64,
+ event_class, bt_ctf_event_class_common_get_name(event_class),
+ bt_ctf_event_class_common_get_id(event_class));
+
+ if (event_class->name) {
+ g_string_free(event_class->name, TRUE);
+ }
+
+ if (event_class->emf_uri) {
+ g_string_free(event_class->emf_uri, TRUE);
+ }
+
+ BT_LOGD_STR("Putting context field type.");
+ bt_ctf_object_put_ref(event_class->context_field_type);
+ BT_LOGD_STR("Putting payload field type.");
+ bt_ctf_object_put_ref(event_class->payload_field_type);
+}
+
+BT_HIDDEN
+int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common *event_class,
+ const char *name, bt_ctf_object_release_func release_func,
+ bt_ctf_field_type_structure_create_func ft_struct_create_func)
+{
+ int ret = 0;
+
+ BT_LOGD("Initializing common event class object: name=\"%s\"",
+ name);
+ bt_ctf_object_init_shared_with_parent(&event_class->base, release_func);
+ event_class->payload_field_type = ft_struct_create_func();
+ if (!event_class->payload_field_type) {
+ BT_LOGE_STR("Cannot create event class's initial payload field type object.");
+ goto error;
+ }
+
+ event_class->id = -1;
+ event_class->name = g_string_new(name);
+ if (!event_class->name) {
+ BT_LOGE_STR("Failed to allocate a GString.");
+ goto error;
+ }
+
+ event_class->emf_uri = g_string_new(NULL);
+ if (!event_class->emf_uri) {
+ BT_LOGE_STR("Failed to allocate a GString.");
+ goto error;
+ }
+
+ event_class->log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED;
+ BT_LOGD("Initialized common event class object: addr=%p, name=\"%s\"",
+ event_class, bt_ctf_event_class_common_get_name(event_class));
+ return ret;
+
+error:
+ ret = -1;
+ return ret;
+}
+
+BT_HIDDEN
+void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common *event_class)
+{
+ BT_ASSERT(event_class);
+
+ if (event_class->frozen) {
+ return;
+ }
+
+ BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64,
+ event_class, bt_ctf_event_class_common_get_name(event_class),
+ bt_ctf_event_class_common_get_id(event_class));
+ event_class->frozen = 1;
+ BT_LOGD_STR("Freezing event class's context field type.");
+ bt_ctf_field_type_common_freeze(event_class->context_field_type);
+ BT_LOGD_STR("Freezing event class's payload field type.");
+ bt_ctf_field_type_common_freeze(event_class->payload_field_type);
+}
+
+BT_HIDDEN
+int bt_ctf_event_class_common_validate_single_clock_class(
+ struct bt_ctf_event_class_common *event_class,
+ struct bt_ctf_clock_class **expected_clock_class)
+{
+ int ret = 0;
+
+ BT_ASSERT(event_class);
+ BT_ASSERT(expected_clock_class);
+ ret = bt_ctf_field_type_common_validate_single_clock_class(
+ event_class->context_field_type,
+ expected_clock_class);
+ if (ret) {
+ BT_LOGW("Event class's context field type "
+ "is not recursively mapped to the "
+ "expected clock class: "
+ "event-class-addr=%p, "
+ "event-class-name=\"%s\", "
+ "event-class-id=%" PRId64 ", "
+ "ft-addr=%p",
+ event_class,
+ bt_ctf_event_class_common_get_name(event_class),
+ event_class->id,
+ event_class->context_field_type);
+ goto end;
+ }
+
+ ret = bt_ctf_field_type_common_validate_single_clock_class(
+ event_class->payload_field_type,
+ expected_clock_class);
+ if (ret) {
+ BT_LOGW("Event class's payload field type "
+ "is not recursively mapped to the "
+ "expected clock class: "
+ "event-class-addr=%p, "
+ "event-class-name=\"%s\", "
+ "event-class-id=%" PRId64 ", "
+ "ft-addr=%p",
+ event_class,
+ bt_ctf_event_class_common_get_name(event_class),
+ event_class->id,
+ event_class->payload_field_type);
+ goto end;
+ }
+
+end:
+ return ret;
+}