+
+BT_HIDDEN
+bt_component_class_query_method_status support_info_query(
+ bt_self_component_class_source *comp_class,
+ const bt_value *params, bt_logging_level log_level,
+ const bt_value **user_result)
+{
+ const bt_value *input_type_value;
+ const char *input_type;
+ bt_component_class_query_method_status status;
+ bt_value_map_insert_entry_status insert_entry_status;
+ double weight = 0;
+ gchar *metadata_path = NULL;
+ bt_value *result = NULL;
+ struct ctf_metadata_decoder *metadata_decoder = NULL;
+ FILE *metadata_file = NULL;
+ char uuid_str[BT_UUID_STR_LEN + 1];
+ bool has_uuid = false;
+ const bt_value *input_value;
+ const char *input;
+
+ input_type_value = bt_value_map_borrow_entry_value_const(params, "type");
+ BT_ASSERT(input_type_value);
+ BT_ASSERT(bt_value_get_type(input_type_value) == BT_VALUE_TYPE_STRING);
+ input_type = bt_value_string_get(input_type_value);
+
+ if (strcmp(input_type, "directory") != 0) {
+ goto create_result;
+ }
+
+ input_value = bt_value_map_borrow_entry_value_const(params, "input");
+ BT_ASSERT(input_value);
+ BT_ASSERT(bt_value_get_type(input_value) == BT_VALUE_TYPE_STRING);
+ input = bt_value_string_get(input_value);
+
+ metadata_path = g_build_filename(input, CTF_FS_METADATA_FILENAME, NULL);
+ if (!metadata_path) {
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR;
+ goto end;
+ }
+
+ metadata_file = g_fopen(metadata_path, "rb");
+ if (metadata_file) {
+ struct ctf_metadata_decoder_config metadata_decoder_config = { 0 };
+ enum ctf_metadata_decoder_status decoder_status;
+ bt_uuid_t uuid;
+
+ metadata_decoder_config.log_level = log_level;
+ metadata_decoder_config.self_comp_class =
+ bt_self_component_class_source_as_self_component_class(comp_class);
+
+ metadata_decoder = ctf_metadata_decoder_create(
+ &metadata_decoder_config);
+ if (!metadata_decoder) {
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ decoder_status = ctf_metadata_decoder_append_content(
+ metadata_decoder, metadata_file);
+ if (decoder_status != CTF_METADATA_DECODER_STATUS_OK) {
+ BT_LOGW("cannot append metadata content: metadata-decoder-status=%d",
+ decoder_status);
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ /*
+ * We were able to parse the metadata file, so we are
+ * confident it's a CTF trace.
+ */
+ weight = 0.75;
+
+ /* If the trace has a UUID, return the stringified UUID as the group. */
+ if (ctf_metadata_decoder_get_trace_class_uuid(metadata_decoder, uuid) == 0) {
+ bt_uuid_to_str(uuid, uuid_str);
+ has_uuid = true;
+ }
+ }
+
+create_result:
+ result = bt_value_map_create();
+ if (!result) {
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR;
+ goto end;
+ }
+
+ insert_entry_status = bt_value_map_insert_real_entry(result, "weight", weight);
+ if (insert_entry_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
+ status = (int) insert_entry_status;
+ goto end;
+ }
+
+ /* We are not supposed to have weight == 0 and a UUID. */
+ BT_ASSERT(weight > 0 || !has_uuid);
+
+ if (weight > 0 && has_uuid) {
+ insert_entry_status = bt_value_map_insert_string_entry(result, "group", uuid_str);
+ if (insert_entry_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) {
+ status = (int) insert_entry_status;
+ goto end;
+ }
+ }
+
+ *user_result = result;
+ result = NULL;
+ status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
+
+end:
+ g_free(metadata_path);
+ bt_value_put_ref(result);
+ ctf_metadata_decoder_destroy(metadata_decoder);
+
+ return status;
+}