bt2: test query info API
[babeltrace.git] / converter / babeltrace-cfg.c
index 1d4e7537394f1933acf2590310d6ea738b1a2de9..1426136e74fd77d87ced7991f9e855711d8b57cf 100644 (file)
@@ -37,6 +37,7 @@
 #include <sys/types.h>
 #include <pwd.h>
 #include "babeltrace-cfg.h"
+#include "babeltrace-cfg-connect.h"
 
 #define DEFAULT_SOURCE_COMPONENT_NAME  "ctf.fs"
 #define DEFAULT_SINK_COMPONENT_NAME    "text.text"
@@ -712,6 +713,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 +756,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) {
@@ -771,7 +782,6 @@ end:
  * Creates a component configuration from a command-line source/sink
  * option's argument.
  */
-static
 struct bt_config_component *bt_config_component_from_arg(const char *arg)
 {
        struct bt_config_component *bt_config_component = NULL;
@@ -820,17 +830,35 @@ void bt_config_destroy(struct bt_object *obj)
                        g_ptr_array_free(cfg->cmd_data.convert.sources, TRUE);
                }
 
+               if (cfg->cmd_data.convert.filters) {
+                       g_ptr_array_free(cfg->cmd_data.convert.filters, TRUE);
+               }
+
                if (cfg->cmd_data.convert.sinks) {
                        g_ptr_array_free(cfg->cmd_data.convert.sinks, TRUE);
                }
 
+               if (cfg->cmd_data.convert.connections) {
+                       g_ptr_array_free(cfg->cmd_data.convert.connections,
+                               TRUE);
+               }
+
                BT_PUT(cfg->cmd_data.convert.plugin_paths);
                break;
-
        case BT_CONFIG_COMMAND_LIST_PLUGINS:
                BT_PUT(cfg->cmd_data.list_plugins.plugin_paths);
                break;
+       case BT_CONFIG_COMMAND_HELP:
+               BT_PUT(cfg->cmd_data.help.plugin_paths);
+
+               if (cfg->cmd_data.help.plugin_name) {
+                       g_string_free(cfg->cmd_data.help.plugin_name, TRUE);
+               }
 
+               if (cfg->cmd_data.help.component_name) {
+                       g_string_free(cfg->cmd_data.help.component_name, TRUE);
+               }
+               break;
        default:
                assert(false);
        }
@@ -1334,7 +1362,7 @@ int append_sinks_from_legacy_opts(GPtrArray *sinks,
                component_name = "metadata-text";
                break;
        case LEGACY_OUTPUT_FORMAT_DUMMY:
-               plugin_name = "dummy";
+               plugin_name = "utils";
                component_name = "dummy";
                break;
        default:
@@ -1655,7 +1683,7 @@ void print_output_legacy_to_sinks(
                enum legacy_output_format legacy_output_format,
                struct text_legacy_opts *text_legacy_opts)
 {
-       const char *input_format;
+       const char *output_format;
        GString *str = NULL;
 
        str = g_string_new("    ");
@@ -1666,22 +1694,22 @@ void print_output_legacy_to_sinks(
 
        switch (legacy_output_format) {
        case LEGACY_OUTPUT_FORMAT_TEXT:
-               input_format = "text";
+               output_format = "text";
                break;
        case LEGACY_OUTPUT_FORMAT_CTF_METADATA:
-               input_format = "ctf-metadata";
+               output_format = "ctf-metadata";
                break;
        case LEGACY_OUTPUT_FORMAT_DUMMY:
-               input_format = "dummy";
+               output_format = "dummy";
                break;
        default:
                assert(false);
        }
 
        printf_err("Both `%s` legacy output format and non-legacy sink component\ninstances(s) specified.\n\n",
-               input_format);
+               output_format);
        printf_err("Specify the following non-legacy sink component instance instead of the\nlegacy `%s` output format options:\n\n",
-               input_format);
+               output_format);
        g_string_append(str, "-o ");
 
        switch (legacy_output_format) {
@@ -1692,7 +1720,7 @@ void print_output_legacy_to_sinks(
                g_string_append(str, "ctf.metadata-text");
                break;
        case LEGACY_OUTPUT_FORMAT_DUMMY:
-               g_string_append(str, "dummy.dummy");
+               g_string_append(str, "utils.dummy");
                break;
        default:
                assert(false);
@@ -1979,15 +2007,18 @@ enum {
        OPT_CLOCK_OFFSET,
        OPT_CLOCK_OFFSET_NS,
        OPT_CLOCK_SECONDS,
+       OPT_CONNECT,
        OPT_DEBUG,
        OPT_DEBUG_INFO_DIR,
        OPT_DEBUG_INFO_FULL_PATH,
        OPT_DEBUG_INFO_TARGET_PREFIX,
        OPT_END,
        OPT_FIELDS,
+       OPT_FILTER,
        OPT_HELP,
        OPT_INPUT_FORMAT,
        OPT_LIST,
+       OPT_NAME,
        OPT_NAMES,
        OPT_NO_DELTA,
        OPT_OMIT_HOME_PLUGIN_PATH,
@@ -2191,6 +2222,13 @@ static struct bt_config *bt_config_convert_create(
                goto error;
        }
 
+       cfg->cmd_data.convert.filters = g_ptr_array_new_with_free_func(
+               (GDestroyNotify) bt_put);
+       if (!cfg->cmd_data.convert.filters) {
+               print_err_oom();
+               goto error;
+       }
+
        cfg->cmd_data.convert.sinks = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_put);
        if (!cfg->cmd_data.convert.sinks) {
@@ -2198,6 +2236,13 @@ static struct bt_config *bt_config_convert_create(
                goto error;
        }
 
+       cfg->cmd_data.convert.connections = g_ptr_array_new_with_free_func(
+               (GDestroyNotify) bt_config_connection_destroy);
+       if (!cfg->cmd_data.convert.connections) {
+               print_err_oom();
+               goto error;
+       }
+
        if (initial_plugin_paths) {
                cfg->cmd_data.convert.plugin_paths =
                        bt_get(initial_plugin_paths);
@@ -2251,6 +2296,276 @@ end:
        return cfg;
 }
 
+static struct bt_config *bt_config_help_create(
+               struct bt_value *initial_plugin_paths)
+{
+       struct bt_config *cfg;
+
+       /* Create config */
+       cfg = bt_config_base_create(BT_CONFIG_COMMAND_HELP);
+       if (!cfg) {
+               print_err_oom();
+               goto error;
+       }
+
+       if (initial_plugin_paths) {
+               cfg->cmd_data.help.plugin_paths =
+                       bt_get(initial_plugin_paths);
+       } else {
+               cfg->cmd_data.help.plugin_paths =
+                       bt_value_array_create();
+               if (!cfg->cmd_data.help.plugin_paths) {
+                       print_err_oom();
+                       goto error;
+               }
+       }
+
+       cfg->cmd_data.help.plugin_name = g_string_new(NULL);
+       if (!cfg->cmd_data.help.plugin_name) {
+               print_err_oom();
+               goto error;
+       }
+
+       cfg->cmd_data.help.component_name = g_string_new(NULL);
+       if (!cfg->cmd_data.help.component_name) {
+               print_err_oom();
+               goto error;
+       }
+
+       goto end;
+
+error:
+       BT_PUT(cfg);
+
+end:
+       return cfg;
+}
+
+/*
+ * Prints the help command usage.
+ */
+static
+void print_help_usage(FILE *fp)
+{
+       fprintf(fp, "Usage: babeltrace [GENERAL OPTIONS] help [OPTIONS] PLUGIN\n");
+       fprintf(fp, "       babeltrace [GENERAL OPTIONS] help [OPTIONS] --source PLUGIN.COMPCLS\n");
+       fprintf(fp, "       babeltrace [GENERAL OPTIONS] help [OPTIONS] --filter PLUGIN.COMPCLS\n");
+       fprintf(fp, "       babeltrace [GENERAL OPTIONS] help [OPTIONS] --sink PLUGIN.COMPCLS\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "Options:\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "      --filter=PLUGIN.COMPCLS       Get help for the filter component class\n");
+       fprintf(fp, "                                    COMPCLS found in the plugin PLUGIN\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");
+       fprintf(fp, "      --plugin-path=PATH[:PATH]...  Add PATH to the list of paths from which\n");
+       fprintf(fp, "                                    dynamic plugins can be loaded\n");
+       fprintf(fp, "      --sink=PLUGIN.COMPCLS         Get help for the sink component class\n");
+       fprintf(fp, "                                    COMPCLS found in the plugin PLUGIN\n");
+       fprintf(fp, "      --source=PLUGIN.COMPCLS       Get help for the source component class\n");
+       fprintf(fp, "                                    COMPCLS found in the plugin PLUGIN\n");
+       fprintf(fp, "  -h  --help                        Show this help and quit\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "See `babeltrace --help` for the list of general options.\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "Use `babeltrace list-plugins` to show the list of available plugins.\n");
+}
+
+static struct poptOption help_long_options[] = {
+       /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
+       { "filter", '\0', POPT_ARG_STRING, NULL, OPT_FILTER, NULL, NULL },
+       { "help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL },
+       { "omit-home-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_HOME_PLUGIN_PATH, NULL, NULL },
+       { "omit-system-plugin-path", '\0', POPT_ARG_NONE, NULL, OPT_OMIT_SYSTEM_PLUGIN_PATH, NULL, NULL },
+       { "plugin-path", '\0', POPT_ARG_STRING, NULL, OPT_PLUGIN_PATH, NULL, NULL },
+       { "sink", '\0', POPT_ARG_STRING, NULL, OPT_SINK, NULL, NULL },
+       { "source", '\0', POPT_ARG_STRING, NULL, OPT_SOURCE, NULL, NULL },
+       { NULL, 0, 0, NULL, 0, NULL, NULL },
+};
+
+/*
+ * Creates a Babeltrace config object from the arguments of a help
+ * command.
+ *
+ * *retcode is set to the appropriate exit code to use.
+ */
+struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
+               int *retcode, bool omit_system_plugin_path,
+               bool omit_home_plugin_path,
+               struct bt_value *initial_plugin_paths)
+{
+       poptContext pc = NULL;
+       char *arg = NULL;
+       int opt;
+       int ret;
+       struct bt_config *cfg = NULL;
+       const char *leftover;
+       char *plugin_name = NULL, *component_name = NULL;
+       char *plugin_comp_cls_names = NULL;
+
+       *retcode = 0;
+       cfg = bt_config_help_create(initial_plugin_paths);
+       if (!cfg) {
+               print_err_oom();
+               goto error;
+       }
+
+       cfg->cmd_data.help.comp_cls_type = BT_COMPONENT_CLASS_TYPE_UNKNOWN;
+       cfg->cmd_data.help.omit_system_plugin_path = omit_system_plugin_path;
+       cfg->cmd_data.help.omit_home_plugin_path = omit_home_plugin_path;
+       ret = append_env_var_plugin_paths(cfg->cmd_data.help.plugin_paths);
+       if (ret) {
+               printf_err("Cannot append plugin paths from BABELTRACE_PLUGIN_PATH\n");
+               goto error;
+       }
+
+       /* Parse options */
+       pc = poptGetContext(NULL, argc, (const char **) argv,
+               help_long_options, 0);
+       if (!pc) {
+               printf_err("Cannot get popt context\n");
+               goto error;
+       }
+
+       poptReadDefaultConfig(pc, 0);
+
+       while ((opt = poptGetNextOpt(pc)) > 0) {
+               arg = poptGetOptArg(pc);
+
+               switch (opt) {
+               case OPT_PLUGIN_PATH:
+                       if (bt_common_is_setuid_setgid()) {
+                               printf_debug("Skipping non-system plugin paths for setuid/setgid binary\n");
+                       } else {
+                               if (bt_config_append_plugin_paths(
+                                               cfg->cmd_data.help.plugin_paths,
+                                               arg)) {
+                                       printf_err("Invalid --plugin-path option's argument:\n    %s\n",
+                                               arg);
+                                       goto error;
+                               }
+                       }
+                       break;
+               case OPT_OMIT_SYSTEM_PLUGIN_PATH:
+                       cfg->cmd_data.help.omit_system_plugin_path = true;
+                       break;
+               case OPT_OMIT_HOME_PLUGIN_PATH:
+                       cfg->cmd_data.help.omit_home_plugin_path = true;
+                       break;
+               case OPT_SOURCE:
+               case OPT_FILTER:
+               case OPT_SINK:
+                       if (cfg->cmd_data.help.comp_cls_type !=
+                                       BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+                               printf_err("Cannot specify more than one plugin and component class:\n    %s\n",
+                                       arg);
+                               goto error;
+                       }
+
+                       switch (opt) {
+                       case OPT_SOURCE:
+                               cfg->cmd_data.help.comp_cls_type =
+                                       BT_COMPONENT_CLASS_TYPE_SOURCE;
+                               break;
+                       case OPT_FILTER:
+                               cfg->cmd_data.help.comp_cls_type =
+                                       BT_COMPONENT_CLASS_TYPE_FILTER;
+                               break;
+                       case OPT_SINK:
+                               cfg->cmd_data.help.comp_cls_type =
+                                       BT_COMPONENT_CLASS_TYPE_SINK;
+                               break;
+                       default:
+                               assert(false);
+                       }
+                       plugin_comp_cls_names = strdup(arg);
+                       if (!plugin_comp_cls_names) {
+                               print_err_oom();
+                               goto error;
+                       }
+                       break;
+               case OPT_HELP:
+                       print_help_usage(stdout);
+                       *retcode = -1;
+                       BT_PUT(cfg);
+                       goto end;
+               default:
+                       printf_err("Unknown command-line option specified (option code %d)\n",
+                               opt);
+                       goto error;
+               }
+
+               free(arg);
+               arg = NULL;
+       }
+
+       /* Check for option parsing error */
+       if (opt < -1) {
+               printf_err("While parsing command-line options, at option %s: %s\n",
+                       poptBadOption(pc, 0), poptStrerror(opt));
+               goto error;
+       }
+
+       leftover = poptGetArg(pc);
+       if (leftover) {
+               if (cfg->cmd_data.help.comp_cls_type !=
+                                       BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+                       printf_err("Cannot specify plugin name and --source/--filter/--sink component class:\n    %s\n",
+                               leftover);
+                       goto error;
+               }
+
+               g_string_assign(cfg->cmd_data.help.plugin_name, leftover);
+       } else {
+               if (cfg->cmd_data.help.comp_cls_type ==
+                                       BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+                       print_help_usage(stdout);
+                       *retcode = -1;
+                       BT_PUT(cfg);
+                       goto end;
+               }
+
+               plugin_component_names_from_arg(plugin_comp_cls_names,
+                       &plugin_name, &component_name);
+               if (plugin_name && component_name) {
+                       g_string_assign(cfg->cmd_data.help.plugin_name, plugin_name);
+                       g_string_assign(cfg->cmd_data.help.component_name,
+                               component_name);
+               } else {
+                       printf_err("Invalid --source/--filter/--sink option's argument:\n    %s\n",
+                               plugin_comp_cls_names);
+                       goto error;
+               }
+       }
+
+       if (append_home_and_system_plugin_paths(
+                       cfg->cmd_data.help.plugin_paths,
+                       cfg->cmd_data.help.omit_system_plugin_path,
+                       cfg->cmd_data.help.omit_home_plugin_path)) {
+               printf_err("Cannot append home and system plugin paths\n");
+               goto error;
+       }
+
+       goto end;
+
+error:
+       *retcode = 1;
+       BT_PUT(cfg);
+
+end:
+       free(plugin_comp_cls_names);
+       g_free(plugin_name);
+       g_free(component_name);
+
+       if (pc) {
+               poptFreeContext(pc);
+       }
+
+       free(arg);
+       return cfg;
+}
+
 /*
  * Prints the list-plugins command usage.
  */
@@ -2269,6 +2584,8 @@ void print_list_plugins_usage(FILE *fp)
        fprintf(fp, "  -h  --help                        Show this help and quit\n");
        fprintf(fp, "\n");
        fprintf(fp, "See `babeltrace --help` for the list of general options.\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "Use `babeltrace help` to get help for a specific plugin or component class.\n");
 }
 
 static struct poptOption list_plugins_long_options[] = {
@@ -2335,7 +2652,8 @@ struct bt_config *bt_config_list_plugins_from_args(int argc, const char *argv[],
                                if (bt_config_append_plugin_paths(
                                                cfg->cmd_data.list_plugins.plugin_paths,
                                                arg)) {
-                                       printf_err("Invalid --plugin-path option's argument\n");
+                                       printf_err("Invalid --plugin-path option's argument:\n    %s\n",
+                                               arg);
                                        goto error;
                                }
                        }
@@ -2397,7 +2715,6 @@ end:
        return cfg;
 }
 
-
 /*
  * Prints the legacy, Babeltrace 1.x command usage. Those options are
  * still compatible in Babeltrace 2.x, but it is recommended to use
@@ -2475,10 +2792,15 @@ void print_convert_usage(FILE *fp)
        fprintf(fp, "      --begin=BEGIN                 Set the `begin` parameter of the latest\n");
        fprintf(fp, "                                    source component instance to BEGIN\n");
        fprintf(fp, "                                    (see the suggested format of BEGIN below)\n");
+       fprintf(fp, "  -c, --connect=CONNECTION          Connect two component instances (see the\n");
+       fprintf(fp, "                                    expected format of CONNECTION below)\n");
        fprintf(fp, "  -d, --debug                       Enable debug mode\n");
        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");
@@ -2511,6 +2833,26 @@ void print_convert_usage(FILE *fp)
        fprintf(fp, "\n");
        fprintf(fp, "    [YYYY-MM-DD [hh:mm:]]ss[.nnnnnnnnn]\n");
        fprintf(fp, "\n\n");
+       fprintf(fp, "Expected format of CONNECTION\n");
+       fprintf(fp, "-----------------------------\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "    SRC[.SRCPORT]:DST[.DSTPORT]\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "SRC and DST are the names of the source and destination component\n");
+       fprintf(fp, "instances to connect together. You can set the name of a component\n");
+       fprintf(fp, "instance with the --name option.\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "SRCPORT and DSTPORT are the optional source and destination ports to use\n");
+       fprintf(fp, "for the connection. When the port is not specified, the default port is\n");
+       fprintf(fp, "used.\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "You can connect a source component to a filter or sink component. You\n");
+       fprintf(fp, "can connect a filter component to a sink component.\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "Example:\n");
+       fprintf(fp, "\n");
+       fprintf(fp, "    my-filter.top10:json-out\n");
+       fprintf(fp, "\n\n");
        fprintf(fp, "Expected format of PARAMS\n");
        fprintf(fp, "-------------------------\n");
        fprintf(fp, "\n");
@@ -2553,6 +2895,7 @@ static struct poptOption convert_long_options[] = {
        { "clock-offset", '\0', POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET, NULL, NULL },
        { "clock-offset-ns", '\0', POPT_ARG_STRING, NULL, OPT_CLOCK_OFFSET_NS, NULL, NULL },
        { "clock-seconds", '\0', POPT_ARG_NONE, NULL, OPT_CLOCK_SECONDS, NULL, NULL },
+       { "connect", 'c', POPT_ARG_STRING, NULL, OPT_CONNECT, NULL, NULL },
        { "debug", 'd', POPT_ARG_NONE, NULL, OPT_DEBUG, NULL, NULL },
        { "debug-info-dir", 0, POPT_ARG_STRING, NULL, OPT_DEBUG_INFO_DIR, NULL, NULL },
        { "debug-info-full-path", 0, POPT_ARG_NONE, NULL, OPT_DEBUG_INFO_FULL_PATH, NULL, NULL },
@@ -2561,6 +2904,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 },
@@ -2607,6 +2951,9 @@ 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;
+       struct bt_value *connection_args = NULL;
+       char error_buf[256] = { 0 };
 
        *retcode = 0;
        memset(&ctf_legacy_opts, 0, sizeof(ctf_legacy_opts));
@@ -2656,6 +3003,18 @@ 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;
+       }
+
+       connection_args = bt_value_array_create();
+       if (!connection_args) {
+               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");
@@ -2664,15 +3023,15 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
        /* Note: implicit source never gets positional base params. */
        implicit_source_comp = bt_config_component_from_arg(DEFAULT_SOURCE_COMPONENT_NAME);
-       if (implicit_source_comp) {
-               cur_cfg_comp = implicit_source_comp;
-               cur_is_implicit_source = true;
-               use_implicit_source = true;
-       } else {
-               printf_debug("Cannot find implicit source plugin \"%s\"",
-                       DEFAULT_SOURCE_COMPONENT_NAME);
+       if (!implicit_source_comp) {
+               print_err_oom();
+               goto error;
        }
 
+       cur_cfg_comp = implicit_source_comp;
+       cur_is_implicit_source = true;
+       use_implicit_source = true;
+
        /* Parse options */
        pc = poptGetContext(NULL, argc, (const char **) argv,
                convert_long_options, 0);
@@ -2694,7 +3053,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                if (bt_config_append_plugin_paths(
                                                cfg->cmd_data.convert.plugin_paths,
                                                arg)) {
-                                       printf_err("Invalid --plugin-path option's argument\n");
+                                       printf_err("Invalid --plugin-path option's argument:\n    %s\n",
+                                               arg);
                                        goto error;
                                }
                        }
@@ -2851,8 +3211,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        struct bt_value *params_to_set;
 
                        if (!cur_cfg_comp) {
-                               printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
-                                       DEFAULT_SOURCE_COMPONENT_NAME);
+                               printf_err("Cannot add parameters to unavailable default source component `%s`:\n    %s\n",
+                                       DEFAULT_SOURCE_COMPONENT_NAME, arg);
                                goto error;
                        }
 
@@ -2877,8 +3237,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                }
                case OPT_PATH:
                        if (!cur_cfg_comp) {
-                               printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
-                                       DEFAULT_SOURCE_COMPONENT_NAME);
+                               printf_err("Cannot add `path` parameter to unavailable default source component `%s`:\n    %s\n",
+                                       DEFAULT_SOURCE_COMPONENT_NAME, arg);
                                goto error;
                        }
 
@@ -2890,6 +3250,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);
@@ -2919,7 +3300,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
                        text_legacy_opts.names = names_from_arg(arg);
                        if (!text_legacy_opts.names) {
-                               printf_err("Invalid --names option's argument\n");
+                               printf_err("Invalid --names option's argument:\n    %s\n",
+                                       arg);
                                goto error;
                        }
                        break;
@@ -2931,7 +3313,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
                        text_legacy_opts.fields = fields_from_arg(arg);
                        if (!text_legacy_opts.fields) {
-                               printf_err("Invalid --fields option's argument\n");
+                               printf_err("Invalid --fields option's argument:\n    %s\n",
+                                       arg);
                                goto error;
                        }
                        break;
@@ -2963,7 +3346,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        }
 
                        if (parse_int64(arg, &val)) {
-                               printf_err("Invalid --clock-offset option's argument\n");
+                               printf_err("Invalid --clock-offset option's argument:\n    %s\n",
+                                       arg);
                                goto error;
                        }
 
@@ -2980,7 +3364,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        }
 
                        if (parse_int64(arg, &val)) {
-                               printf_err("Invalid --clock-offset-ns option's argument\n");
+                               printf_err("Invalid --clock-offset-ns option's argument:\n    %s\n",
+                                       arg);
                                goto error;
                        }
 
@@ -2995,12 +3380,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        break;
                case OPT_BEGIN:
                        if (!cur_cfg_comp) {
-                               printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
-                                       DEFAULT_SOURCE_COMPONENT_NAME);
+                               printf_err("Cannot add `begin` parameter to unavailable default source component `%s`:\n    %s\n",
+                                       DEFAULT_SOURCE_COMPONENT_NAME, arg);
                                goto error;
                        }
                        if (cur_cfg_comp_dest != BT_CONFIG_COMPONENT_DEST_SOURCE) {
-                               printf_err("--begin option must follow a --source option\n");
+                               printf_err("--begin option must follow a --source option:\n    %s\n",
+                                       arg);
                                goto error;
                        }
                        if (bt_value_map_insert_string(cur_cfg_comp->params,
@@ -3011,12 +3397,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        break;
                case OPT_END:
                        if (!cur_cfg_comp) {
-                               printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
-                                       DEFAULT_SOURCE_COMPONENT_NAME);
+                               printf_err("Cannot add `end` parameter to unavailable default source component `%s`:\n    %s\n",
+                                       DEFAULT_SOURCE_COMPONENT_NAME, arg);
                                goto error;
                        }
                        if (cur_cfg_comp_dest != BT_CONFIG_COMPONENT_DEST_SOURCE) {
-                               printf_err("--end option must follow a --source option\n");
+                               printf_err("--end option must follow a --source option:\n    %s\n",
+                                       arg);
                                goto error;
                        }
                        if (bt_value_map_insert_string(cur_cfg_comp->params,
@@ -3030,16 +3417,18 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        const char *begin, *end;
 
                        if (!cur_cfg_comp) {
-                               printf_err("Can not apply parameter to unavailable default source component \"%s\".\n",
-                                       DEFAULT_SOURCE_COMPONENT_NAME);
+                               printf_err("Cannot add `begin` and `end` parameters to unavailable default source component `%s`:\n    %s\n",
+                                       DEFAULT_SOURCE_COMPONENT_NAME, arg);
                                goto error;
                        }
                        if (cur_cfg_comp_dest != BT_CONFIG_COMPONENT_DEST_SOURCE) {
-                               printf_err("--timerange option must follow a --source option\n");
+                               printf_err("--timerange option must follow a --source option:\n    %s\n",
+                                       arg);
                                goto error;
                        }
                        if (split_timerange(arg, &begin, &end)) {
-                               printf_err("Invalid --timerange format, expecting: begin,end or [begin,end] (where [] are actual brackets)\n");
+                               printf_err("Invalid --timerange format: expecting BEGIN,END or [BEGIN,END]:\n    %s\n",
+                                       arg);
                                goto error;
                        }
                        if (bt_value_map_insert_string(cur_cfg_comp->params,
@@ -3054,6 +3443,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                        }
                        break;
                }
+               case OPT_CONNECT:
+                       if (bt_value_array_append_string(connection_args,
+                                       arg)) {
+                               print_err_oom();
+                               goto error;
+                       }
+                       break;
                case OPT_HELP:
                        print_convert_usage(stdout);
                        *retcode = -1;
@@ -3168,7 +3564,7 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                /* Use implicit sink as default. */
                cur_cfg_comp = bt_config_component_from_arg(DEFAULT_SINK_COMPONENT_NAME);
                if (!cur_cfg_comp) {
-                       printf_error("Cannot find implicit sink plugin \"%s\"\n",
+                       printf_error("Cannot find implicit sink plugin `%s`\n",
                                DEFAULT_SINK_COMPONENT_NAME);
                }
                add_cfg_comp(cfg, cur_cfg_comp,
@@ -3176,6 +3572,13 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                cur_cfg_comp = NULL;
        }
 
+       ret = bt_config_create_connections(cfg, connection_args,
+               error_buf, 256);
+       if (ret) {
+               printf_err("Cannot creation connections:\n%s", error_buf);
+               goto error;
+       }
+
        goto end;
 
 error:
@@ -3206,6 +3609,8 @@ end:
        BT_PUT(text_legacy_opts.names);
        BT_PUT(text_legacy_opts.fields);
        BT_PUT(legacy_input_paths);
+       BT_PUT(instance_names);
+       BT_PUT(connection_args);
        return cfg;
 }
 
@@ -3228,6 +3633,7 @@ void print_gen_usage(FILE *fp)
        fprintf(fp, "Available commands:\n");
        fprintf(fp, "\n");
        fprintf(fp, "    convert       Build a trace conversion graph and run it (default)\n");
+       fprintf(fp, "    help          Get help for a plugin or a component class\n");
        fprintf(fp, "    list-plugins  List available plugins and their content\n");
        fprintf(fp, "\n");
        fprintf(fp, "Use `babeltrace COMMAND --help` to show the help of COMMAND.\n");
@@ -3275,20 +3681,18 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[],
                        print_legacy_usage(stdout);
                        goto end;
                } else {
+                       bool has_command = true;
+
                        /*
                         * First unknown argument: is it a known command
                         * name?
                         */
                        if (strcmp(cur_arg, "convert") == 0) {
                                command = BT_CONFIG_COMMAND_CONVERT;
-                               command_argv = &argv[i];
-                               command_argc = argc - i;
-                               command_name = cur_arg;
                        } else if (strcmp(cur_arg, "list-plugins") == 0) {
                                command = BT_CONFIG_COMMAND_LIST_PLUGINS;
-                               command_argv = &argv[i];
-                               command_argc = argc - i;
-                               command_name = cur_arg;
+                       } else if (strcmp(cur_arg, "help") == 0) {
+                               command = BT_CONFIG_COMMAND_HELP;
                        } else {
                                /*
                                 * Unknown argument, but not a known
@@ -3299,6 +3703,13 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[],
                                command = BT_CONFIG_COMMAND_CONVERT;
                                command_argv = argv;
                                command_argc = argc;
+                               has_command = false;
+                       }
+
+                       if (has_command) {
+                               command_argv = &argv[i];
+                               command_argc = argc - i;
+                               command_name = cur_arg;
                        }
                        break;
                }
@@ -3329,6 +3740,11 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[],
                        command_argv, retcode, omit_system_plugin_path,
                        omit_home_plugin_path, initial_plugin_paths);
                break;
+       case BT_CONFIG_COMMAND_HELP:
+               config = bt_config_help_from_args(command_argc,
+                       command_argv, retcode, omit_system_plugin_path,
+                       omit_home_plugin_path, initial_plugin_paths);
+               break;
        default:
                assert(false);
        }
This page took 0.033726 seconds and 4 git commands to generate.