babeltrace-cfg: put comp. class type within struct bt_config_component
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 11 Feb 2017 19:20:21 +0000 (14:20 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
converter/babeltrace-cfg-connect.c
converter/babeltrace-cfg.c
converter/babeltrace-cfg.h
converter/babeltrace.c

index 1e8e29724127a2de38f0520c65a839b0abb8821d..21aa2e8d9229db26048beef3fc85aec32a456240 100644 (file)
@@ -318,25 +318,22 @@ end:
 }
 
 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;
        }
 
@@ -354,14 +351,12 @@ static int validate_all_endpoints_exist(struct bt_config *cfg, char *error_buf,
                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,
@@ -389,19 +384,17 @@ static int validate_connection_directions(struct bt_config *cfg,
        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,
@@ -409,9 +402,9 @@ static int validate_connection_directions(struct bt_config *cfg,
                                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,
@@ -752,7 +745,8 @@ static int auto_connect(struct bt_config *cfg)
        }
 
        /* 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;
        }
index 1426136e74fd77d87ced7991f9e855711d8b57cf..fa678dc7c9b7aa90a3d67cd35b8a02ba886de9d5 100644 (file)
@@ -732,8 +732,9 @@ end:
  * 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;
 
@@ -744,6 +745,7 @@ struct bt_config_component *bt_config_component_create(const char *plugin_name,
        }
 
        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();
@@ -782,7 +784,8 @@ end:
  * 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;
@@ -794,7 +797,7 @@ struct bt_config_component *bt_config_component_from_arg(const char *arg)
                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;
@@ -850,14 +853,7 @@ void bt_config_destroy(struct bt_object *obj)
                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);
@@ -1389,8 +1385,8 @@ int append_sinks_from_legacy_opts(GPtrArray *sinks,
        }
 
        /* 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;
        }
@@ -1518,8 +1514,8 @@ int append_sources_from_legacy_opts(GPtrArray *sources,
                }
 
                /* 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;
                }
@@ -2320,14 +2316,10 @@ static struct bt_config *bt_config_help_create(
                }
        }
 
-       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;
        }
@@ -2411,7 +2403,6 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
                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);
@@ -2456,7 +2447,7 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
                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);
@@ -2465,15 +2456,15 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
 
                        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:
@@ -2509,16 +2500,17 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
 
        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;
@@ -2529,8 +2521,9 @@ struct bt_config *bt_config_help_from_args(int argc, const char *argv[],
                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",
@@ -3022,7 +3015,8 @@ 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);
+       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;
@@ -3124,7 +3118,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                        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);
@@ -3186,7 +3181,8 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
                                        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);
@@ -3562,7 +3558,9 @@ struct bt_config *bt_config_convert_from_args(int argc, const char *argv[],
 
        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);
index 23af3e6801b9bb811fba25be2f9bb0ed60fdba62..6670d2fae058764293e52dcad2f6c28e1a765e2c 100644 (file)
@@ -36,6 +36,7 @@
 
 struct bt_config_component {
        struct bt_object base;
+       enum bt_component_class_type type;
        GString *plugin_name;
        GString *component_name;
        struct bt_value *params;
@@ -88,9 +89,7 @@ struct bt_config {
                        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;
 };
@@ -107,7 +106,8 @@ struct bt_config *bt_config_from_args(int argc, const char *argv[],
                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);
index af7a5ba6157eabb53f4f300d79cff983ab8bba6e..928f623b478d9d07806dfb295a2bb42c08407812 100644 (file)
@@ -644,12 +644,12 @@ static int cmd_help(struct bt_config *cfg)
                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;
@@ -662,13 +662,13 @@ static int cmd_help(struct bt_config *cfg)
                        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",
@@ -676,9 +676,9 @@ static int cmd_help(struct bt_config *cfg)
                                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;
@@ -701,12 +701,12 @@ static int cmd_help(struct bt_config *cfg)
 
                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;
                        }
@@ -714,7 +714,7 @@ static int cmd_help(struct bt_config *cfg)
 
                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");
This page took 0.031618 seconds and 4 git commands to generate.