-static
-int convert_append_name_param(enum bt_config_component_dest dest,
- GString *cur_name, GString *cur_name_prefix,
- bt_value *run_args,
- bt_value *all_names,
- GList **source_names, GList **filter_names,
- GList **sink_names)
-{
- int ret = 0;
-
- if (cur_name_prefix->len > 0) {
- /* We're after a --component option */
- GString *name = NULL;
- bool append_name_opt = false;
-
- if (cur_name->len == 0) {
- /*
- * No explicit name was provided for the user
- * component.
- */
- name = get_component_auto_name(cur_name_prefix->str,
- all_names);
- append_name_opt = true;
- } else {
- /*
- * An explicit name was provided for the user
- * component.
- */
- if (bt_value_map_has_entry(all_names,
- cur_name->str)) {
- BT_CLI_LOGE_APPEND_CAUSE("Duplicate component instance name:\n %s",
- cur_name->str);
- goto error;
- }
-
- name = g_string_new(cur_name->str);
- }
-
- if (!name) {
- BT_CLI_LOGE_APPEND_CAUSE_OOM();
- goto error;
- }
-
- /*
- * Remember this name globally, for the uniqueness of
- * all component names.
- */
- if (bt_value_map_insert_entry(all_names, name->str, bt_value_null)) {
- BT_CLI_LOGE_APPEND_CAUSE_OOM();
- goto error;
- }
-
- /*
- * Append the --name option if necessary.
- */
- if (append_name_opt) {
- if (bt_value_array_append_string_element(run_args, "--name")) {
- BT_CLI_LOGE_APPEND_CAUSE_OOM();
- goto error;
- }
-
- if (bt_value_array_append_string_element(run_args, name->str)) {
- BT_CLI_LOGE_APPEND_CAUSE_OOM();
- goto error;
- }
- }
-
- /*
- * Remember this name specifically for the type of the
- * component. This is to create connection arguments.
- */
- switch (dest) {
- case BT_CONFIG_COMPONENT_DEST_SOURCE:
- *source_names = g_list_append(*source_names, name);
- break;
- case BT_CONFIG_COMPONENT_DEST_FILTER:
- *filter_names = g_list_append(*filter_names, name);
- break;
- case BT_CONFIG_COMPONENT_DEST_SINK:
- *sink_names = g_list_append(*sink_names, name);
- break;
- default:
- abort();
- }
-
- g_string_assign(cur_name_prefix, "");
- }
-
- goto end;
-
-error:
- ret = -1;
-
-end:
- return ret;
-}
-