#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"
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);
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) {
* 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;
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:
component_name = "metadata-text";
break;
case LEGACY_OUTPUT_FORMAT_DUMMY:
- plugin_name = "dummy";
+ plugin_name = "utils";
component_name = "dummy";
break;
default:
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(" ");
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) {
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);
OPT_CLOCK_OFFSET,
OPT_CLOCK_OFFSET_NS,
OPT_CLOCK_SECONDS,
+ OPT_CONNECT,
OPT_DEBUG,
OPT_DEBUG_INFO_DIR,
OPT_DEBUG_INFO_FULL_PATH,
OPT_HELP,
OPT_INPUT_FORMAT,
OPT_LIST,
+ OPT_NAME,
OPT_NAMES,
OPT_NO_DELTA,
OPT_OMIT_HOME_PLUGIN_PATH,
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) {
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);
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");
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");
{ "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 },
{ "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 },
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));
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");
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);
}
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;
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:
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;
}