babeltrace(1): add the query-info command
[babeltrace.git] / converter / babeltrace.c
index af7a5ba6157eabb53f4f300d79cff983ab8bba6e..e30dc13e6983c2ead97e3ae5be71970945357188 100644 (file)
@@ -633,6 +633,63 @@ static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
                bt_common_color_reset());
 }
 
+static int cmd_query_info(struct bt_config *cfg)
+{
+       int ret;
+       struct bt_component_class *comp_cls = NULL;
+       struct bt_value *results = NULL;
+
+       ret = load_all_plugins(cfg->cmd_data.list_plugins.plugin_paths);
+       if (ret) {
+               goto end;
+       }
+
+       comp_cls = find_component_class(cfg->cmd_data.query_info.cfg_component->plugin_name->str,
+               cfg->cmd_data.query_info.cfg_component->component_name->str,
+               cfg->cmd_data.query_info.cfg_component->type);
+       if (!comp_cls) {
+               fprintf(stderr, "%s%sCannot find component class %s",
+                       bt_common_color_bold(),
+                       bt_common_color_fg_red(),
+                       bt_common_color_reset());
+               print_plugin_comp_cls_opt(stderr,
+                       cfg->cmd_data.query_info.cfg_component->plugin_name->str,
+                       cfg->cmd_data.query_info.cfg_component->component_name->str,
+                       cfg->cmd_data.query_info.cfg_component->type);
+               fprintf(stderr, "\n");
+               ret = -1;
+               goto end;
+       }
+
+       results = bt_component_class_query_info(comp_cls,
+               cfg->cmd_data.query_info.action->str,
+               cfg->cmd_data.query_info.cfg_component->params);
+       if (!results) {
+               fprintf(stderr, "%s%sFailed to query info to %s",
+                       bt_common_color_bold(),
+                       bt_common_color_fg_red(),
+                       bt_common_color_reset());
+               print_plugin_comp_cls_opt(stderr,
+                       cfg->cmd_data.query_info.cfg_component->plugin_name->str,
+                       cfg->cmd_data.query_info.cfg_component->component_name->str,
+                       cfg->cmd_data.query_info.cfg_component->type);
+               fprintf(stderr, "%s%s with action `%s`%s\n",
+                       bt_common_color_bold(),
+                       bt_common_color_fg_red(),
+                       cfg->cmd_data.query_info.action->str,
+                       bt_common_color_reset());
+               ret = -1;
+               goto end;
+       }
+
+       print_value(results, 0);
+
+end:
+       bt_put(comp_cls);
+       bt_put(results);
+       return ret;
+}
+
 static int cmd_help(struct bt_config *cfg)
 {
        int ret;
@@ -644,12 +701,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 +719,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 +733,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 +758,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 +771,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");
@@ -977,6 +1034,9 @@ int main(int argc, const char **argv)
        case BT_CONFIG_COMMAND_HELP:
                ret = cmd_help(cfg);
                break;
+       case BT_CONFIG_COMMAND_QUERY_INFO:
+               ret = cmd_query_info(cfg);
+               break;
        default:
                assert(false);
        }
This page took 0.02717 seconds and 4 git commands to generate.