babeltrace convert: add --name option
[babeltrace.git] / converter / babeltrace-cfg.c
index 999c773ff1ff103034acb0ad5fc8027da9bfafb5..6d8ff8d9846e23853853cf8af577369139dbde70 100644 (file)
@@ -712,6 +712,10 @@ void bt_config_component_destroy(struct bt_object *obj)
                g_string_free(bt_config_component->component_name, TRUE);
        }
 
+       if (bt_config_component->instance_name) {
+               g_string_free(bt_config_component->instance_name, TRUE);
+       }
+
        BT_PUT(bt_config_component->params);
        g_free(bt_config_component);
 
@@ -751,6 +755,12 @@ struct bt_config_component *bt_config_component_create(const char *plugin_name,
                goto error;
        }
 
+       cfg_component->instance_name = g_string_new(NULL);
+       if (!cfg_component->instance_name) {
+               print_err_oom();
+               goto error;
+       }
+
        /* Start with empty parameters */
        cfg_component->params = bt_value_map_create();
        if (!cfg_component->params) {
@@ -1998,6 +2008,7 @@ enum {
        OPT_HELP,
        OPT_INPUT_FORMAT,
        OPT_LIST,
+       OPT_NAME,
        OPT_NAMES,
        OPT_NO_DELTA,
        OPT_OMIT_HOME_PLUGIN_PATH,
@@ -2761,6 +2772,9 @@ void print_convert_usage(FILE *fp)
        fprintf(fp, "      --end=END                     Set the `end` parameter of the latest\n");
        fprintf(fp, "                                    source component instance to END\n");
        fprintf(fp, "                                    (see the suggested format of BEGIN below)\n");
+       fprintf(fp, "      --name=NAME                   Set the name of the latest component\n");
+       fprintf(fp, "                                    instance to NAME (must be unique amongst\n");
+       fprintf(fp, "                                    all the names of the component instances)\n");
        fprintf(fp, "      --omit-home-plugin-path       Omit home plugins from plugin search path\n");
        fprintf(fp, "                                    (~/.local/lib/babeltrace/plugins)\n");
        fprintf(fp, "      --omit-system-plugin-path     Omit system plugins from plugin search path\n");
@@ -2843,6 +2857,7 @@ static struct poptOption convert_long_options[] = {
        { "fields", 'f', POPT_ARG_STRING, NULL, OPT_FIELDS, NULL, NULL },
        { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
        { "input-format", 'i', POPT_ARG_STRING, NULL, OPT_INPUT_FORMAT, NULL, NULL },
+       { "name", '\0', POPT_ARG_STRING, NULL, OPT_NAME, NULL, NULL },
        { "names", 'n', POPT_ARG_STRING, NULL, OPT_NAMES, NULL, NULL },
        { "no-delta", '\0', POPT_ARG_NONE, NULL, OPT_NO_DELTA, NULL, NULL },
        { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
@@ -2889,6 +2904,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
        struct bt_value *cur_base_params = NULL;
        int opt, ret = 0;
        struct bt_config *cfg = NULL;
+       struct bt_value *instance_names = NULL;
 
        *retcode = 0;
        memset(&ctf_legacy_opts, 0, sizeof(ctf_legacy_opts));
@@ -2938,6 +2954,12 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                goto error;
        }
 
+       instance_names = bt_value_map_create();
+       if (!instance_names) {
+               print_err_oom();
+               goto error;
+       }
+
        ret = append_env_var_plugin_paths(cfg->cmd_data.convert.plugin_paths);
        if (ret) {
                printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
@@ -3173,6 +3195,27 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                goto error;
                        }
                        break;
+               case OPT_NAME:
+                       if (!cur_cfg_comp) {
+                               printf_err("Cannot set the name of unavailable default source component `%s`:\n    %s\n",
+                                       DEFAULT_SOURCE_COMPONENT_NAME, arg);
+                               goto error;
+                       }
+
+                       if (bt_value_map_has_key(instance_names, arg)) {
+                               printf_err("Duplicate component instance name:\n    %s\n",
+                                       arg);
+                               goto error;
+                       }
+
+                       g_string_assign(cur_cfg_comp->instance_name, arg);
+
+                       if (bt_value_map_insert(instance_names,
+                                       arg, bt_value_null)) {
+                               print_err_oom();
+                               goto error;
+                       }
+                       break;
                case OPT_BASE_PARAMS:
                {
                        struct bt_value *params = bt_value_from_arg(arg);
@@ -3497,6 +3540,7 @@ end:
        BT_PUT(text_legacy_opts.names);
        BT_PUT(text_legacy_opts.fields);
        BT_PUT(legacy_input_paths);
+       BT_PUT(instance_names);
        return cfg;
 }
 
This page took 0.025573 seconds and 4 git commands to generate.