}
static struct bt_config_component *find_component(struct bt_config *cfg,
- const char *name, enum bt_component_class_type *type)
+ const char *name)
{
struct bt_config_component *comp;
comp = find_component_in_array(cfg->cmd_data.convert.sources, name);
if (comp) {
- *type = BT_COMPONENT_CLASS_TYPE_SOURCE;
goto end;
}
comp = find_component_in_array(cfg->cmd_data.convert.filters, name);
if (comp) {
- *type = BT_COMPONENT_CLASS_TYPE_FILTER;
goto end;
}
comp = find_component_in_array(cfg->cmd_data.convert.sinks, name);
if (comp) {
- *type = BT_COMPONENT_CLASS_TYPE_SINK;
goto end;
}
struct bt_config_connection *connection =
g_ptr_array_index(cfg->cmd_data.convert.connections, i);
struct bt_config_component *comp;
- enum bt_component_class_type type;
- comp = find_component(cfg, connection->src_instance_name->str,
- &type);
+ comp = find_component(cfg, connection->src_instance_name->str);
bt_put(comp);
if (!comp) {
comp = find_component(cfg,
- connection->dst_instance_name->str, &type);
+ connection->dst_instance_name->str);
bt_put(comp);
if (!comp) {
snprintf(error_buf, error_buf_size,
for (i = 0; i < cfg->cmd_data.convert.connections->len; i++) {
struct bt_config_connection *connection =
g_ptr_array_index(cfg->cmd_data.convert.connections, i);
- enum bt_component_class_type src_type;
- enum bt_component_class_type dst_type;
src_comp = find_component(cfg,
- connection->src_instance_name->str, &src_type);
+ connection->src_instance_name->str);
assert(src_comp);
dst_comp = find_component(cfg,
- connection->dst_instance_name->str, &dst_type);
+ connection->dst_instance_name->str);
assert(dst_comp);
- if (src_type == BT_COMPONENT_CLASS_TYPE_SOURCE) {
- if (dst_type != BT_COMPONENT_CLASS_TYPE_FILTER &&
- dst_type != BT_COMPONENT_CLASS_TYPE_SINK) {
+ if (src_comp->type == BT_COMPONENT_CLASS_TYPE_SOURCE) {
+ if (dst_comp->type != BT_COMPONENT_CLASS_TYPE_FILTER &&
+ dst_comp->type != BT_COMPONENT_CLASS_TYPE_SINK) {
snprintf(error_buf, error_buf_size,
"Invalid connection: source component `%s` not connected to filter or sink component:\n %s\n",
connection->src_instance_name->str,
ret = -1;
goto end;
}
- } else if (src_type == BT_COMPONENT_CLASS_TYPE_FILTER) {
- if (dst_type != BT_COMPONENT_CLASS_TYPE_FILTER &&
- dst_type != BT_COMPONENT_CLASS_TYPE_SINK) {
+ } else if (src_comp->type == BT_COMPONENT_CLASS_TYPE_FILTER) {
+ if (dst_comp->type != BT_COMPONENT_CLASS_TYPE_FILTER &&
+ dst_comp->type != BT_COMPONENT_CLASS_TYPE_SINK) {
snprintf(error_buf, error_buf_size,
"Invalid connection: filter component `%s` not connected to filter or sink component:\n %s\n",
connection->src_instance_name->str,
}
/* Add an implicit muxer filter */
- muxer_cfg_comp = bt_config_component_from_arg("utils.muxer");
+ muxer_cfg_comp = bt_config_component_from_arg(
+ BT_COMPONENT_CLASS_TYPE_FILTER, "utils.muxer");
if (!muxer_cfg_comp) {
goto error;
}
* Return value is owned by the caller.
*/
static
-struct bt_config_component *bt_config_component_create(const char *plugin_name,
- const char *component_name)
+struct bt_config_component *bt_config_component_create(
+ enum bt_component_class_type type,
+ const char *plugin_name, const char *component_name)
{
struct bt_config_component *cfg_component = NULL;
}
bt_object_init(cfg_component, bt_config_component_destroy);
+ cfg_component->type = type;
cfg_component->plugin_name = g_string_new(plugin_name);
if (!cfg_component->plugin_name) {
print_err_oom();
* Creates a component configuration from a command-line source/sink
* option's argument.
*/
-struct bt_config_component *bt_config_component_from_arg(const char *arg)
+struct bt_config_component *bt_config_component_from_arg(
+ enum bt_component_class_type type, const char *arg)
{
struct bt_config_component *bt_config_component = NULL;
char *plugin_name;
goto error;
}
- bt_config_component = bt_config_component_create(plugin_name,
+ bt_config_component = bt_config_component_create(type, plugin_name,
component_name);
if (!bt_config_component) {
goto error;
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);
- }
+ BT_PUT(cfg->cmd_data.help.cfg_component);
break;
default:
assert(false);
}
/* Create a component configuration */
- bt_config_component = bt_config_component_create(plugin_name,
- component_name);
+ bt_config_component = bt_config_component_create(
+ BT_COMPONENT_CLASS_TYPE_SINK, plugin_name, component_name);
if (!bt_config_component) {
goto error;
}
}
/* Create a component configuration */
- bt_config_component = bt_config_component_create("ctf",
- component_name);
+ bt_config_component = bt_config_component_create(
+ BT_COMPONENT_CLASS_TYPE_SOURCE, "ctf", component_name);
if (!bt_config_component) {
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) {
+ cfg->cmd_data.help.cfg_component =
+ bt_config_component_create(BT_COMPONENT_CLASS_TYPE_UNKNOWN,
+ NULL, NULL);
+ if (!cfg->cmd_data.help.cfg_component) {
print_err_oom();
goto error;
}
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);
case OPT_SOURCE:
case OPT_FILTER:
case OPT_SINK:
- if (cfg->cmd_data.help.comp_cls_type !=
+ if (cfg->cmd_data.help.cfg_component->type !=
BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
printf_err("Cannot specify more than one plugin and component class:\n %s\n",
arg);
switch (opt) {
case OPT_SOURCE:
- cfg->cmd_data.help.comp_cls_type =
+ cfg->cmd_data.help.cfg_component->type =
BT_COMPONENT_CLASS_TYPE_SOURCE;
break;
case OPT_FILTER:
- cfg->cmd_data.help.comp_cls_type =
+ cfg->cmd_data.help.cfg_component->type =
BT_COMPONENT_CLASS_TYPE_FILTER;
break;
case OPT_SINK:
- cfg->cmd_data.help.comp_cls_type =
+ cfg->cmd_data.help.cfg_component->type =
BT_COMPONENT_CLASS_TYPE_SINK;
break;
default:
leftover = poptGetArg(pc);
if (leftover) {
- if (cfg->cmd_data.help.comp_cls_type !=
+ if (cfg->cmd_data.help.cfg_component->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);
+ g_string_assign(cfg->cmd_data.help.cfg_component->plugin_name,
+ leftover);
} else {
- if (cfg->cmd_data.help.comp_cls_type ==
+ if (cfg->cmd_data.help.cfg_component->type ==
BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
print_help_usage(stdout);
*retcode = -1;
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,
+ g_string_assign(cfg->cmd_data.help.cfg_component->plugin_name,
+ plugin_name);
+ g_string_assign(cfg->cmd_data.help.cfg_component->component_name,
component_name);
} else {
printf_err("Invalid --source/--filter/--sink option's argument:\n %s\n",
}
/* Note: implicit source never gets positional base params. */
- implicit_source_comp = bt_config_component_from_arg(DEFAULT_SOURCE_COMPONENT_NAME);
+ implicit_source_comp = bt_config_component_from_arg(
+ BT_COMPONENT_CLASS_TYPE_SOURCE, DEFAULT_SOURCE_COMPONENT_NAME);
if (!implicit_source_comp) {
print_err_oom();
goto error;
cur_cfg_comp_dest);
}
- cur_cfg_comp = bt_config_component_from_arg(arg);
+ cur_cfg_comp = bt_config_component_from_arg(
+ BT_COMPONENT_CLASS_TYPE_SOURCE, arg);
if (!cur_cfg_comp) {
printf_err("Invalid format for --source option's argument:\n %s\n",
arg);
cur_cfg_comp_dest);
}
- cur_cfg_comp = bt_config_component_from_arg(arg);
+ cur_cfg_comp = bt_config_component_from_arg(
+ BT_COMPONENT_CLASS_TYPE_SINK, arg);
if (!cur_cfg_comp) {
printf_err("Invalid format for --sink option's argument:\n %s\n",
arg);
if (cfg->cmd_data.convert.sinks->len == 0) {
/* Use implicit sink as default. */
- cur_cfg_comp = bt_config_component_from_arg(DEFAULT_SINK_COMPONENT_NAME);
+ cur_cfg_comp = bt_config_component_from_arg(
+ BT_COMPONENT_CLASS_TYPE_SINK,
+ DEFAULT_SINK_COMPONENT_NAME);
if (!cur_cfg_comp) {
printf_error("Cannot find implicit sink plugin `%s`\n",
DEFAULT_SINK_COMPONENT_NAME);
struct bt_config_component {
struct bt_object base;
+ enum bt_component_class_type type;
GString *plugin_name;
GString *component_name;
struct bt_value *params;
struct bt_value *plugin_paths;
bool omit_system_plugin_path;
bool omit_home_plugin_path;
- enum bt_component_class_type comp_cls_type;
- GString *plugin_name;
- GString *component_name;
+ struct bt_config_component *cfg_component;
} help;
} cmd_data;
};
bool omit_home_plugin_path,
struct bt_value *initial_plugin_paths);
-struct bt_config_component *bt_config_component_from_arg(const char *arg);
+struct bt_config_component *bt_config_component_from_arg(
+ enum bt_component_class_type type, const char *arg);
enum bt_value_status bt_config_append_plugin_paths(
struct bt_value *plugin_paths, const char *arg);
goto end;
}
- plugin = find_plugin(cfg->cmd_data.help.plugin_name->str);
+ plugin = find_plugin(cfg->cmd_data.help.cfg_component->plugin_name->str);
if (!plugin) {
fprintf(stderr, "%s%sCannot find plugin %s%s%s\n",
bt_common_color_bold(), bt_common_color_fg_red(),
bt_common_color_fg_blue(),
- cfg->cmd_data.help.plugin_name->str,
+ cfg->cmd_data.help.cfg_component->plugin_name->str,
bt_common_color_reset());
ret = -1;
goto end;
bt_plugin_get_component_class_count(plugin));
- if (cfg->cmd_data.help.comp_cls_type !=
+ if (cfg->cmd_data.help.cfg_component->type !=
BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
struct bt_component_class *needed_comp_cls =
find_component_class(
- cfg->cmd_data.help.plugin_name->str,
- cfg->cmd_data.help.component_name->str,
- cfg->cmd_data.help.comp_cls_type);
+ cfg->cmd_data.help.cfg_component->plugin_name->str,
+ cfg->cmd_data.help.cfg_component->component_name->str,
+ cfg->cmd_data.help.cfg_component->type);
if (!needed_comp_cls) {
fprintf(stderr, "\n%s%sCannot find component class %s",
bt_common_color_fg_red(),
bt_common_color_reset());
print_plugin_comp_cls_opt(stderr,
- cfg->cmd_data.help.plugin_name->str,
- cfg->cmd_data.help.component_name->str,
- cfg->cmd_data.help.comp_cls_type);
+ cfg->cmd_data.help.cfg_component->plugin_name->str,
+ cfg->cmd_data.help.cfg_component->component_name->str,
+ cfg->cmd_data.help.cfg_component->type);
fprintf(stderr, "\n");
ret = -1;
goto end;
assert(comp_cls);
- if (cfg->cmd_data.help.comp_cls_type !=
+ if (cfg->cmd_data.help.cfg_component->type !=
BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
- if (strcmp(cfg->cmd_data.help.component_name->str,
+ if (strcmp(cfg->cmd_data.help.cfg_component->component_name->str,
comp_class_name) != 0 &&
type ==
- cfg->cmd_data.help.comp_cls_type) {
+ cfg->cmd_data.help.cfg_component->type) {
bt_put(comp_cls);
continue;
}
printf("\n");
print_plugin_comp_cls_opt(stdout,
- cfg->cmd_data.help.plugin_name->str,
+ cfg->cmd_data.help.cfg_component->plugin_name->str,
comp_class_name,
type);
printf("\n");