- 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_get_name(event_class),
- bt_ctf_event_class_get_id(event_class));
- event_class->frozen = 1;
- event_class->name = bt_ctf_event_class_get_name(event_class);
- event_class->id = bt_ctf_event_class_get_id(event_class);
- BT_LOGD_STR("Freezing event class's context field type.");
- bt_ctf_field_type_freeze(event_class->context);
- BT_LOGD_STR("Freezing event class's payload field type.");
- bt_ctf_field_type_freeze(event_class->fields);
- BT_LOGD_STR("Freezing event class's attributes.");
- bt_ctf_attributes_freeze(event_class->attributes);
-}
-
-BT_HIDDEN
-int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class,
- struct metadata_context *context)
-{
- int64_t i;
- int64_t count;
- int ret = 0;
- struct bt_value *attr_value = NULL;
-
- assert(event_class);
- assert(context);
- BT_LOGD("Serializing event class's metadata: "
- "event-class-addr=%p, event-class-name=\"%s\", "
- "event-class-id=%" PRId64 ", metadata-context-addr=%p",
- event_class, bt_ctf_event_class_get_name(event_class),
- bt_ctf_event_class_get_id(event_class), context);
- context->current_indentation_level = 1;
- g_string_assign(context->field_name, "");
- g_string_append(context->string, "event {\n");
- count = bt_ctf_event_class_get_attribute_count(event_class);
- assert(count >= 0);
-
- for (i = 0; i < count; ++i) {
- const char *attr_name = NULL;
-
- attr_name = bt_ctf_event_class_get_attribute_name_by_index(
- event_class, i);
- assert(attr_name);
- attr_value = bt_ctf_event_class_get_attribute_value_by_index(
- event_class, i);
- assert(attr_value);
-
- switch (bt_value_get_type(attr_value)) {
- case BT_VALUE_TYPE_INTEGER:
- {
- int64_t value;
-
- ret = bt_value_integer_get(attr_value, &value);
- assert(ret == 0);
- g_string_append_printf(context->string,
- "\t%s = %" PRId64 ";\n", attr_name, value);
- break;
- }
-
- case BT_VALUE_TYPE_STRING:
- {
- const char *value;
-
- ret = bt_value_string_get(attr_value, &value);
- assert(ret == 0);
- g_string_append_printf(context->string,
- "\t%s = \"%s\";\n", attr_name, value);
- break;
- }
-
- default:
- /* should never happen */
- abort();
- break;
- }
-
- BT_PUT(attr_value);
- }
-
- if (event_class->context) {
- g_string_append(context->string, "\tcontext := ");
- BT_LOGD_STR("Serializing event class's context field type metadata.");
- ret = bt_ctf_field_type_serialize(event_class->context,
- context);
- if (ret) {
- BT_LOGW("Cannot serialize event class's context field type's metadata: "
- "ret=%d", ret);
- goto end;
- }
- g_string_append(context->string, ";\n");
- }
-
- if (event_class->fields) {
- g_string_append(context->string, "\tfields := ");
- BT_LOGD_STR("Serializing event class's payload field type metadata.");
- ret = bt_ctf_field_type_serialize(event_class->fields, context);
- if (ret) {
- BT_LOGW("Cannot serialize event class's payload field type's metadata: "
- "ret=%d", ret);
- goto end;
- }
- g_string_append(context->string, ";\n");
- }
-
- g_string_append(context->string, "};\n\n");
-end:
- context->current_indentation_level = 0;
- BT_PUT(attr_value);
- return ret;