2 * Copyright (c) 2019 EfficiOS Inc. and Linux Foundation
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #define BT_LOG_TAG "CLI-CFG-SRC-AUTO-DISC"
24 #define BT_LOG_OUTPUT_LEVEL log_level
25 #include "logging/log.h"
28 #include "common/common.h"
30 #define BT_AUTODISC_LOG_AND_APPEND(_lvl, _fmt, ...) \
32 BT_LOG_WRITE(_lvl, BT_LOG_TAG, _fmt, ##__VA_ARGS__); \
33 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN( \
34 "Source auto-discovery", _fmt, ##__VA_ARGS__); \
37 #define BT_AUTODISC_LOGE_APPEND_CAUSE(_fmt, ...) \
38 BT_AUTODISC_LOG_AND_APPEND(BT_LOG_ERROR, _fmt, ##__VA_ARGS__)
41 * Define a status enum for inside the auto source discovery code,
42 * as we don't want to return `NO_MATCH` to the caller.
44 typedef enum auto_source_discovery_internal_status
{
45 AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
= AUTO_SOURCE_DISCOVERY_STATUS_OK
,
46 AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR
= AUTO_SOURCE_DISCOVERY_STATUS_ERROR
,
47 AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_MEMORY_ERROR
= AUTO_SOURCE_DISCOVERY_STATUS_MEMORY_ERROR
,
48 AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_INTERRUPTED
= AUTO_SOURCE_DISCOVERY_STATUS_INTERRUPTED
,
49 AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH
= __BT_FUNC_STATUS_NO_MATCH
,
50 } auto_source_discovery_internal_status
;
52 /* Finalize and free a `struct auto_source_discovery_result`. */
55 void auto_source_discovery_result_destroy(struct auto_source_discovery_result
*res
)
59 bt_value_put_ref(res
->inputs
);
60 bt_value_put_ref(res
->original_input_indices
);
65 /* Allocate and initialize a `struct auto_source_discovery_result`. */
68 struct auto_source_discovery_result
*auto_source_discovery_result_create(
69 const char *plugin_name
, const char *source_cc_name
,
70 const char *group
, bt_logging_level log_level
)
72 struct auto_source_discovery_result
*res
;
74 res
= g_new0(struct auto_source_discovery_result
, 1);
76 BT_AUTODISC_LOGE_APPEND_CAUSE(
77 "Failed to allocate a auto_source_discovery_result structure.");
81 res
->plugin_name
= plugin_name
;
82 res
->source_cc_name
= source_cc_name
;
83 res
->group
= g_strdup(group
);
84 if (group
&& !res
->group
) {
85 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to allocate a string.");
89 res
->inputs
= bt_value_array_create();
91 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to allocate an array value.");
95 res
->original_input_indices
= bt_value_array_create();
96 if (!res
->original_input_indices
) {
97 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to allocate an array value.");
103 auto_source_discovery_result_destroy(res
);
110 /* Finalize a `struct auto_source_discovery`. */
112 void auto_source_discovery_fini(struct auto_source_discovery
*auto_disc
)
114 if (auto_disc
->results
) {
115 g_ptr_array_free(auto_disc
->results
, TRUE
);
119 /* Initialize an already allocated `struct auto_source_discovery`. */
121 int auto_source_discovery_init(struct auto_source_discovery
*auto_disc
)
125 auto_disc
->results
= g_ptr_array_new_with_free_func(
126 (GDestroyNotify
) auto_source_discovery_result_destroy
);
128 if (!auto_disc
->results
) {
136 auto_source_discovery_fini(auto_disc
);
145 const bt_value
*borrow_array_value_last_element_const(const bt_value
*array
)
147 uint64_t last_index
= bt_value_array_get_length(array
) - 1;
149 return bt_value_array_borrow_element_by_index_const(array
, last_index
);
153 * Assign `input` to source component class `source_cc_name` of plugin
154 * `plugin_name`, in the group with key `group`.
158 auto_source_discovery_internal_status
auto_source_discovery_add(
159 struct auto_source_discovery
*auto_disc
,
160 const char *plugin_name
,
161 const char *source_cc_name
,
164 uint64_t original_input_index
,
165 bt_logging_level log_level
)
167 auto_source_discovery_internal_status status
;
168 bt_value_array_append_element_status append_status
;
171 struct auto_source_discovery_result
*res
= NULL
;
174 len
= auto_disc
->results
->len
;
178 for (i
= 0; i
< len
; i
++) {
179 res
= g_ptr_array_index(auto_disc
->results
, i
);
181 if (strcmp(res
->plugin_name
, plugin_name
) != 0) {
185 if (strcmp(res
->source_cc_name
, source_cc_name
) != 0) {
189 if (g_strcmp0(res
->group
, group
) != 0) {
198 /* Add a new result entry. */
199 res
= auto_source_discovery_result_create(plugin_name
,
200 source_cc_name
, group
, log_level
);
205 g_ptr_array_add(auto_disc
->results
, res
);
208 append_status
= bt_value_array_append_string_element(res
->inputs
, input
);
209 if (append_status
!= BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
) {
210 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to append a string value.");
215 * Append `original_input_index` to `original_input_indices` if not
216 * there already. We process the `inputs` array in order, so if it is
217 * present, it has to be the last element.
219 if (bt_value_array_is_empty(res
->original_input_indices
)) {
222 const bt_value
*last_index_value
;
226 borrow_array_value_last_element_const(res
->original_input_indices
);
227 last_index
= bt_value_integer_unsigned_get(last_index_value
);
229 BT_ASSERT(last_index
<= original_input_index
);
231 append_index
= (last_index
!= original_input_index
);
235 append_status
= bt_value_array_append_unsigned_integer_element(
236 res
->original_input_indices
, original_input_index
);
238 if (append_status
!= BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
) {
239 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to append an unsigned integer value.");
244 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
;
248 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR
;
255 int convert_weight_value(const bt_value
*weight_value
, double *weight
,
256 const char *plugin_name
, const char *source_cc_name
,
257 const char *input
, const char *input_type
,
258 bt_logging_level log_level
)
260 enum bt_value_type weight_value_type
;
263 weight_value_type
= bt_value_get_type(weight_value
);
265 if (weight_value_type
== BT_VALUE_TYPE_REAL
) {
266 *weight
= bt_value_real_get(weight_value
);
267 } else if (weight_value_type
== BT_VALUE_TYPE_SIGNED_INTEGER
) {
268 /* Accept signed integer as a convenience for "return 0" or "return 1" in Python. */
269 *weight
= bt_value_integer_signed_get(weight_value
);
271 BT_LOGW("babeltrace.support-info query: unexpected type for weight: "
272 "component-class-name=source.%s.%s, input=%s, input-type=%s, "
273 "expected-entry-type=%s, actual-entry-type=%s",
274 plugin_name
, source_cc_name
, input
, input_type
,
275 bt_common_value_type_string(BT_VALUE_TYPE_REAL
),
276 bt_common_value_type_string(bt_value_get_type(weight_value
)));
280 if (*weight
< 0.0 || *weight
> 1.0) {
281 BT_LOGW("babeltrace.support-info query: weight value is out of range [0.0, 1.0]: "
282 "component-class-name=source.%s.%s, input=%s, input-type=%s, "
284 plugin_name
, source_cc_name
, input
, input_type
, *weight
);
299 bt_query_executor_query_status
simple_query(const bt_component_class
*comp_cls
,
300 const char *obj
, const bt_value
*params
,
301 bt_logging_level log_level
, const bt_value
**result
)
303 bt_query_executor_query_status status
;
304 bt_query_executor_set_logging_level_status set_logging_level_status
;
305 bt_query_executor
*query_exec
;
307 query_exec
= bt_query_executor_create(comp_cls
, obj
, params
);
309 BT_AUTODISC_LOGE_APPEND_CAUSE("Cannot create a query executor.");
310 status
= BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR
;
314 set_logging_level_status
= bt_query_executor_set_logging_level(query_exec
, log_level
);
315 if (set_logging_level_status
!= BT_QUERY_EXECUTOR_SET_LOGGING_LEVEL_STATUS_OK
) {
316 BT_AUTODISC_LOGE_APPEND_CAUSE(
317 "Cannot set query executor's logging level: "
319 bt_common_logging_level_string(log_level
));
320 status
= (int) set_logging_level_status
;
324 status
= bt_query_executor_query(query_exec
, result
);
327 bt_query_executor_put_ref(query_exec
);
334 * Query all known source components to see if any of them can handle `input`
335 * as the given `type`(arbitrary string, directory or file).
337 * If `plugin_restrict` is non-NULL, only query source component classes provided
338 * by the plugin with that name.
340 * If `component_class_restrict` is non-NULL, only query source component classes
344 auto_source_discovery_internal_status
support_info_query_all_sources(
346 const char *input_type
,
347 uint64_t original_input_index
,
348 const bt_plugin
**plugins
,
350 const char *component_class_restrict
,
351 enum bt_logging_level log_level
,
352 struct auto_source_discovery
*auto_disc
,
353 const bt_interrupter
*interrupter
)
355 bt_value_map_insert_entry_status insert_status
;
356 bt_value
*query_params
= NULL
;
357 auto_source_discovery_internal_status status
;
359 const struct bt_value
*query_result
= NULL
;
361 const bt_component_class_source
*source
;
362 const bt_plugin
*plugin
;
363 const bt_value
*group
;
365 } winner
= { NULL
, NULL
, NULL
, 0 };
367 if (interrupter
&& bt_interrupter_is_set(interrupter
)) {
368 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_INTERRUPTED
;
372 query_params
= bt_value_map_create();
374 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to allocate a map value.");
378 insert_status
= bt_value_map_insert_string_entry(query_params
, "input", input
);
379 if (insert_status
!= BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
) {
380 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to insert a map entry.");
384 insert_status
= bt_value_map_insert_string_entry(query_params
, "type", input_type
);
385 if (insert_status
!= BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
) {
386 BT_AUTODISC_LOGE_APPEND_CAUSE("Failed to insert a map entry.");
390 for (i_plugins
= 0; i_plugins
< plugin_count
; i_plugins
++) {
391 const bt_plugin
*plugin
;
392 const char *plugin_name
;
393 uint64_t source_count
;
396 plugin
= plugins
[i_plugins
];
397 plugin_name
= bt_plugin_get_name(plugin
);
399 source_count
= bt_plugin_get_source_component_class_count(plugin
);
401 for (i_sources
= 0; i_sources
< source_count
; i_sources
++) {
402 const bt_component_class_source
*source_cc
;
403 const bt_component_class
*cc
;
404 const char *source_cc_name
;
405 bt_query_executor_query_status query_status
;
407 source_cc
= bt_plugin_borrow_source_component_class_by_index_const(plugin
, i_sources
);
408 cc
= bt_component_class_source_as_component_class_const(source_cc
);
409 source_cc_name
= bt_component_class_get_name(cc
);
412 * If the search is restricted to a specific component class, only consider the
413 * component classes with that name.
415 if (component_class_restrict
&& strcmp(component_class_restrict
, source_cc_name
) != 0) {
419 BT_LOGD("babeltrace.support-info query: before: component-class-name=source.%s.%s, input=%s, "
420 "type=%s", plugin_name
, source_cc_name
, input
, input_type
);
422 BT_VALUE_PUT_REF_AND_RESET(query_result
);
423 query_status
= simple_query(cc
, "babeltrace.support-info",
424 query_params
, log_level
, &query_result
);
426 if (query_status
== BT_QUERY_EXECUTOR_QUERY_STATUS_OK
) {
428 const bt_value
*group_value
= NULL
;
429 enum bt_value_type query_result_type
;
431 BT_ASSERT(query_result
);
433 query_result_type
= bt_value_get_type(query_result
);
435 if (query_result_type
== BT_VALUE_TYPE_REAL
|| query_result_type
== BT_VALUE_TYPE_SIGNED_INTEGER
) {
436 if (convert_weight_value(query_result
, &weight
, plugin_name
, source_cc_name
, input
, input_type
, log_level
) != 0) {
437 /* convert_weight_value has already warned. */
440 } else if (query_result_type
== BT_VALUE_TYPE_MAP
) {
441 const bt_value
*weight_value
;
443 if (!bt_value_map_has_entry(query_result
, "weight")) {
444 BT_LOGW("babeltrace.support-info query: result is missing `weight` entry: "
445 "component-class-name=source.%s.%s, input=%s, input-type=%s",
446 bt_plugin_get_name(plugin
),
447 bt_component_class_get_name(cc
), input
,
452 weight_value
= bt_value_map_borrow_entry_value_const(query_result
, "weight");
453 BT_ASSERT(weight_value
);
455 if (convert_weight_value(weight_value
, &weight
, plugin_name
, source_cc_name
, input
, input_type
, log_level
) != 0) {
456 /* convert_weight_value has already warned. */
460 if (bt_value_map_has_entry(query_result
, "group")) {
461 group_value
= bt_value_map_borrow_entry_value_const(query_result
, "group");
462 BT_ASSERT(group_value
);
464 if (bt_value_get_type(group_value
) != BT_VALUE_TYPE_STRING
) {
465 BT_LOGW("babeltrace.support-info query: unexpected type for entry `group`: "
466 "component-class-name=source.%s.%s, input=%s, input-type=%s, "
467 "expected-entry-type=%s,%s, actual-entry-type=%s",
468 bt_plugin_get_name(plugin
),
469 bt_component_class_get_name(cc
), input
,
471 bt_common_value_type_string(BT_VALUE_TYPE_NULL
),
472 bt_common_value_type_string(BT_VALUE_TYPE_STRING
),
473 bt_common_value_type_string(bt_value_get_type(group_value
)));
478 BT_LOGW("babeltrace.support-info query: unexpected result type: "
479 "component-class-name=source.%s.%s, input=%s, input-type=%s, "
480 "expected-types=%s,%s,%s, actual-type=%s",
481 bt_plugin_get_name(plugin
),
482 bt_component_class_get_name(cc
), input
,
484 bt_common_value_type_string(BT_VALUE_TYPE_REAL
),
485 bt_common_value_type_string(BT_VALUE_TYPE_MAP
),
486 bt_common_value_type_string(BT_VALUE_TYPE_SIGNED_INTEGER
),
487 bt_common_value_type_string(bt_value_get_type(query_result
)));
491 BT_LOGD("babeltrace.support-info query: success: component-class-name=source.%s.%s, input=%s, "
492 "type=%s, weight=%f, group=%s\n",
493 bt_plugin_get_name(plugin
), bt_component_class_get_name(cc
), input
,
494 input_type
, weight
, group_value
? bt_value_string_get(group_value
) : "(none)");
496 if (weight
> winner
.weigth
) {
497 winner
.source
= source_cc
;
498 winner
.plugin
= plugin
;
500 bt_value_put_ref(winner
.group
);
501 winner
.group
= group_value
;
502 bt_value_get_ref(winner
.group
);
504 winner
.weigth
= weight
;
506 } else if (query_status
== BT_QUERY_EXECUTOR_QUERY_STATUS_ERROR
) {
507 BT_AUTODISC_LOGE_APPEND_CAUSE("babeltrace.support-info query failed.");
509 } else if (query_status
== BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR
) {
510 BT_AUTODISC_LOGE_APPEND_CAUSE("Memory error.");
513 BT_LOGD("babeltrace.support-info query: failure: component-class-name=source.%s.%s, input=%s, "
514 "type=%s, status=%s\n",
515 bt_plugin_get_name(plugin
), bt_component_class_get_name(cc
), input
,
517 bt_common_func_status_string(query_status
));
523 const char *source_name
;
524 const char *plugin_name
;
527 source_name
= bt_component_class_get_name(
528 bt_component_class_source_as_component_class_const(winner
.source
));
529 plugin_name
= bt_plugin_get_name(winner
.plugin
);
530 group
= winner
.group
? bt_value_string_get(winner
.group
) : NULL
;
532 BT_LOGI("Input awarded: input=%s, type=%s, component-class-name=source.%s.%s, weight=%f, group=%s",
533 input
, input_type
, plugin_name
, source_name
, winner
.weigth
, group
? group
: "(none)");
535 status
= auto_source_discovery_add(auto_disc
, plugin_name
,
536 source_name
, group
, input
, original_input_index
, log_level
);
537 if (status
!= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
) {
541 BT_LOGI("Input not recognized: input=%s, type=%s",
543 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH
;
549 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR
;
552 bt_value_put_ref(query_result
);
553 bt_value_put_ref(query_params
);
554 bt_value_put_ref(winner
.group
);
560 * Look for a source component class that recognizes `input` as an arbitrary
563 * Same return value semantic as `support_info_query_all_sources`.
567 auto_source_discovery_internal_status
auto_discover_source_for_input_as_string(
569 uint64_t original_input_index
,
570 const bt_plugin
**plugins
,
572 const char *component_class_restrict
,
573 enum bt_logging_level log_level
,
574 struct auto_source_discovery
*auto_disc
,
575 const bt_interrupter
*interrupter
)
577 return support_info_query_all_sources(input
, "string",
578 original_input_index
, plugins
, plugin_count
,
579 component_class_restrict
, log_level
, auto_disc
,
584 auto_source_discovery_internal_status
auto_discover_source_for_input_as_dir_or_file_rec(
586 uint64_t original_input_index
,
587 const bt_plugin
**plugins
,
589 const char *component_class_restrict
,
590 enum bt_logging_level log_level
,
591 struct auto_source_discovery
*auto_disc
,
592 const bt_interrupter
*interrupter
)
594 auto_source_discovery_internal_status status
;
595 GError
*error
= NULL
;
597 if (g_file_test(input
->str
, G_FILE_TEST_IS_REGULAR
)) {
599 status
= support_info_query_all_sources(input
->str
,
600 "file", original_input_index
, plugins
, plugin_count
,
601 component_class_restrict
, log_level
, auto_disc
,
603 } else if (g_file_test(input
->str
, G_FILE_TEST_IS_DIR
)) {
606 gsize saved_input_len
;
607 int dir_status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH
;
609 /* It's a directory. */
610 status
= support_info_query_all_sources(input
->str
,
611 "directory", original_input_index
, plugins
,
612 plugin_count
, component_class_restrict
, log_level
,
613 auto_disc
, interrupter
);
618 } else if (status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
||
619 status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_INTERRUPTED
) {
621 * A component class claimed this input as a directory,
622 * don't recurse. Or, we got interrupted.
627 dir
= g_dir_open(input
->str
, 0, &error
);
629 const char *fmt
= "Failed to open directory %s: %s";
630 BT_LOGW(fmt
, input
->str
, error
->message
);
632 if (error
->code
== G_FILE_ERROR_ACCES
) {
633 /* This is not a fatal error, we just skip it. */
634 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH
;
637 BT_AUTODISC_LOGE_APPEND_CAUSE(fmt
, input
->str
,
643 saved_input_len
= input
->len
;
647 dirent
= g_dir_read_name(dir
);
649 g_string_append_c_inline(input
, G_DIR_SEPARATOR
);
650 g_string_append(input
, dirent
);
652 status
= auto_discover_source_for_input_as_dir_or_file_rec(
653 input
, original_input_index
, plugins
, plugin_count
,
654 component_class_restrict
, log_level
, auto_disc
,
657 g_string_truncate(input
, saved_input_len
);
662 } else if (status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_INTERRUPTED
) {
664 } else if (status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
) {
665 dir_status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
;
667 } else if (errno
!= 0) {
668 BT_LOGW_ERRNO("Failed to read directory entry", ": dir=%s", input
->str
);
677 BT_LOGD("Skipping %s, not a file or directory", input
->str
);
678 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_NO_MATCH
;
684 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR
;
696 * Look for a source component class that recognizes `input` as a directory or
697 * file. If `input` is a directory and is not directly recognized, recurse and
698 * apply the same logic to children nodes.
700 * Same return value semantic as `support_info_query_all_sources`.
704 auto_source_discovery_internal_status
auto_discover_source_for_input_as_dir_or_file(
706 uint64_t original_input_index
,
707 const bt_plugin
**plugins
,
709 const char *component_class_restrict
,
710 enum bt_logging_level log_level
,
711 struct auto_source_discovery
*auto_disc
,
712 const bt_interrupter
*interrupter
)
714 GString
*mutable_input
;
715 auto_source_discovery_internal_status status
;
717 mutable_input
= g_string_new(input
);
718 if (!mutable_input
) {
719 status
= AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_ERROR
;
723 status
= auto_discover_source_for_input_as_dir_or_file_rec(
724 mutable_input
, original_input_index
, plugins
, plugin_count
,
725 component_class_restrict
, log_level
, auto_disc
,
728 g_string_free(mutable_input
, TRUE
);
733 auto_source_discovery_status
auto_discover_source_components(
734 const bt_value
*inputs
,
735 const bt_plugin
**plugins
,
737 const char *component_class_restrict
,
738 enum bt_logging_level log_level
,
739 struct auto_source_discovery
*auto_disc
,
740 const bt_interrupter
*interrupter
)
742 uint64_t i_inputs
, input_count
;
743 auto_source_discovery_internal_status internal_status
;
744 auto_source_discovery_status status
;
746 input_count
= bt_value_array_get_length(inputs
);
748 for (i_inputs
= 0; i_inputs
< input_count
; i_inputs
++) {
749 const bt_value
*input_value
;
752 input_value
= bt_value_array_borrow_element_by_index_const(inputs
, i_inputs
);
753 input
= bt_value_string_get(input_value
);
754 internal_status
= auto_discover_source_for_input_as_string(input
, i_inputs
,
755 plugins
, plugin_count
, component_class_restrict
,
756 log_level
, auto_disc
, interrupter
);
757 if (internal_status
< 0 || internal_status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_INTERRUPTED
) {
758 /* Fatal error or we got interrupted. */
759 status
= (auto_source_discovery_status
) internal_status
;
761 } else if (internal_status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_OK
) {
762 /* A component class has claimed this input as an arbitrary string. */
766 internal_status
= auto_discover_source_for_input_as_dir_or_file(input
,
767 i_inputs
, plugins
, plugin_count
,
768 component_class_restrict
, log_level
, auto_disc
, interrupter
);
769 if (internal_status
< 0 || internal_status
== AUTO_SOURCE_DISCOVERY_INTERNAL_STATUS_INTERRUPTED
) {
770 /* Fatal error or we got interrupted. */
771 status
= (auto_source_discovery_status
) internal_status
;
773 } else if (internal_status
== 0) {
775 * This input (or something under it) was recognized.
780 BT_LOGW("No trace was found based on input `%s`.", input
);
783 status
= AUTO_SOURCE_DISCOVERY_STATUS_OK
;