- int ret = 0;
- size_t i;
- struct bt_ctf_trace *trace;
- struct bt_ctf_field_type *packet_header_type = NULL;
-
- BT_LOGD("Serializing stream class's metadata: "
- "stream-class-addr=%p, stream-class-name=\"%s\", "
- "stream-class-id=%" PRId64 ", metadata-context-addr=%p",
- stream_class, bt_ctf_stream_class_get_name(stream_class),
- bt_ctf_stream_class_get_id(stream_class), context);
- g_string_assign(context->field_name, "");
- context->current_indentation_level = 1;
- if (!stream_class->id_set) {
- BT_LOGW_STR("Stream class's ID is not set.");
- ret = -1;
- goto end;
- }
-
- g_string_append(context->string, "stream {\n");
-
- /*
- * The reference to the trace is only borrowed since the
- * serialization of the stream class might have been triggered
- * by the trace's destruction. In such a case, the trace's
- * reference count would, unexepectedly, go through the sequence
- * 1 -> 0 -> 1 -> 0 -> ..., provoking an endless loop of destruction
- * and serialization.
- */
- trace = bt_ctf_stream_class_borrow_trace(stream_class);
- assert(trace);
- packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
- trace = NULL;
- if (packet_header_type) {
- struct bt_ctf_field_type *stream_id_type;
-
- stream_id_type =
- bt_ctf_field_type_structure_get_field_type_by_name(
- packet_header_type, "stream_id");
- if (stream_id_type) {
- /*
- * Only set the stream's id if the trace's packet header
- * contains a stream_id field. This field is only
- * needed if the trace contains only one stream
- * class.
- */
- g_string_append_printf(context->string,
- "\tid = %" PRId64 ";\n", stream_class->id);
- }
- bt_put(stream_id_type);
- }
- if (stream_class->event_header_type) {
- BT_LOGD_STR("Serializing stream class's event header field type's metadata.");
- g_string_append(context->string, "\tevent.header := ");
- ret = bt_ctf_field_type_serialize(stream_class->event_header_type,
- context);
- if (ret) {
- BT_LOGW("Cannot serialize stream class's event header field type's metadata: "
- "ret=%d", ret);
- goto end;
- }
- g_string_append(context->string, ";");
- }
-
-
- if (stream_class->packet_context_type) {
- BT_LOGD_STR("Serializing stream class's packet context field type's metadata.");
- g_string_append(context->string, "\n\n\tpacket.context := ");
- ret = bt_ctf_field_type_serialize(stream_class->packet_context_type,
- context);
- if (ret) {
- BT_LOGW("Cannot serialize stream class's packet context field type's metadata: "
- "ret=%d", ret);
- goto end;
- }
- g_string_append(context->string, ";");
- }
-
- if (stream_class->event_context_type) {
- BT_LOGD_STR("Serializing stream class's event context field type's metadata.");
- g_string_append(context->string, "\n\n\tevent.context := ");
- ret = bt_ctf_field_type_serialize(
- stream_class->event_context_type, context);
- if (ret) {
- BT_LOGW("Cannot serialize stream class's event context field type's metadata: "
- "ret=%d", ret);
- goto end;
- }
- g_string_append(context->string, ";");
- }
-
- g_string_append(context->string, "\n};\n\n");
-
- for (i = 0; i < stream_class->event_classes->len; i++) {
- struct bt_ctf_event_class *event_class =
- stream_class->event_classes->pdata[i];
-
- ret = bt_ctf_event_class_serialize(event_class, context);
- if (ret) {
- BT_LOGW("Cannot serialize event class's metadata: "
- "event-class-addr=%p, event-class-name=\"%s\", "
- "event-class-id=%" PRId64,
- event_class,
- bt_ctf_event_class_get_name(event_class),
- bt_ctf_event_class_get_id(event_class));
- goto end;
- }
- }
-end:
- bt_put(packet_header_type);
- context->current_indentation_level = 0;
- return ret;