+ results = bt_component_class_query(comp_cls,
+ cfg->cmd_data.query.object->str,
+ cfg->cmd_data.query.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.cfg_component->plugin_name->str,
+ cfg->cmd_data.query.cfg_component->comp_cls_name->str,
+ cfg->cmd_data.query.cfg_component->type);
+ fprintf(stderr, "%s%s with object `%s`%s\n",
+ bt_common_color_bold(),
+ bt_common_color_fg_red(),
+ cfg->cmd_data.query.object->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;
+ struct bt_plugin *plugin = NULL;
+ size_t i;
+
+ ret = load_all_plugins(cfg->plugin_paths);
+ if (ret) {
+ goto end;
+ }
+
+ 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.cfg_component->plugin_name->str,
+ bt_common_color_reset());
+ ret = -1;
+ goto end;
+ }
+
+ print_plugin_info(plugin);
+ printf(" %sComponent classes%s: %d\n",
+ bt_common_color_bold(),
+ bt_common_color_reset(),
+ bt_plugin_get_component_class_count(plugin));
+
+
+ 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.cfg_component->plugin_name->str,
+ cfg->cmd_data.help.cfg_component->comp_cls_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_bold(),
+ bt_common_color_fg_red(),
+ bt_common_color_reset());
+ print_plugin_comp_cls_opt(stderr,
+ cfg->cmd_data.help.cfg_component->plugin_name->str,
+ cfg->cmd_data.help.cfg_component->comp_cls_name->str,
+ cfg->cmd_data.help.cfg_component->type);
+ fprintf(stderr, "\n");
+ ret = -1;
+ goto end;
+ }
+
+ bt_put(needed_comp_cls);
+ }
+
+ for (i = 0; i < bt_plugin_get_component_class_count(plugin); i++) {
+ struct bt_component_class *comp_cls =
+ bt_plugin_get_component_class(plugin, i);
+ const char *comp_class_name =
+ bt_component_class_get_name(comp_cls);
+ const char *comp_class_description =
+ bt_component_class_get_description(comp_cls);
+ const char *comp_class_help =
+ bt_component_class_get_help(comp_cls);
+ enum bt_component_class_type type =
+ bt_component_class_get_type(comp_cls);
+
+ assert(comp_cls);
+
+ if (cfg->cmd_data.help.cfg_component->type !=
+ BT_COMPONENT_CLASS_TYPE_UNKNOWN) {
+ if (strcmp(cfg->cmd_data.help.cfg_component->comp_cls_name->str,
+ comp_class_name) != 0 &&
+ 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.cfg_component->plugin_name->str,
+ comp_class_name,
+ type);
+ printf("\n");
+ printf(" %sDescription%s: %s\n", bt_common_color_bold(),
+ bt_common_color_reset(),
+ comp_class_description ? comp_class_description : "(None)");
+
+ if (comp_class_help) {
+ printf("\n%s\n", comp_class_help);
+ }
+
+ bt_put(comp_cls);
+ }
+
+end:
+ bt_put(plugin);
+ return ret;
+}
+
+static int cmd_list_plugins(struct bt_config *cfg)
+{
+ int ret;
+ int plugins_count, component_classes_count = 0, i;
+
+ ret = load_all_plugins(cfg->plugin_paths);
+ if (ret) {
+ goto end;
+ }
+
+ printf("From the following plugin paths:\n\n");
+ print_value(cfg->plugin_paths, 2);
+ printf("\n");
+ plugins_count = loaded_plugins->len;
+ if (plugins_count == 0) {
+ fprintf(stderr, "%s%sNo plugins found.%s\n",
+ bt_common_color_bold(), bt_common_color_fg_red(),
+ bt_common_color_reset());
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Please make sure your plugin search path is set correctly. You can use\n");
+ fprintf(stderr, "the --plugin-path command-line option or the BABELTRACE_PLUGIN_PATH\n");
+ fprintf(stderr, "environment variable.\n");
+ ret = -1;
+ goto end;
+ }
+
+ for (i = 0; i < plugins_count; i++) {
+ struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i);
+
+ component_classes_count += bt_plugin_get_component_class_count(plugin);
+ }
+
+ printf("Found %s%d%s component classes in %s%d%s plugins.\n",
+ bt_common_color_bold(),
+ component_classes_count,
+ bt_common_color_reset(),
+ bt_common_color_bold(),
+ plugins_count,
+ bt_common_color_reset());
+
+ for (i = 0; i < plugins_count; i++) {
+ int j;
+ struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i);
+
+ component_classes_count =
+ bt_plugin_get_component_class_count(plugin);
+ printf("\n");
+ print_plugin_info(plugin);
+
+ if (component_classes_count == 0) {
+ printf(" %sComponent classes%s: (None)\n",
+ bt_common_color_bold(),
+ bt_common_color_reset());
+ } else {
+ printf(" %sComponent classes%s:\n",
+ bt_common_color_bold(),
+ bt_common_color_reset());
+ }
+
+ for (j = 0; j < component_classes_count; j++) {
+ struct bt_component_class *comp_class =
+ bt_plugin_get_component_class(plugin, j);
+ const char *comp_class_name =
+ bt_component_class_get_name(comp_class);
+ const char *comp_class_description =
+ bt_component_class_get_description(comp_class);
+ enum bt_component_class_type type =
+ bt_component_class_get_type(comp_class);
+
+ printf(" ");
+ print_plugin_comp_cls_opt(stdout,
+ bt_plugin_get_name(plugin), comp_class_name,
+ type);
+
+ if (comp_class_description) {
+ printf(": %s", comp_class_description);
+ }
+
+ printf("\n");
+ bt_put(comp_class);
+ }
+ }
+
+end:
+ return ret;
+}
+
+static int cmd_print_lttng_live_sessions(struct bt_config *cfg)
+{
+ printf("TODO\n");
+ return -1;
+}
+
+static int cmd_print_ctf_metadata(struct bt_config *cfg)
+{
+ int ret = 0;
+ struct bt_component_class *comp_cls = NULL;
+ struct bt_value *results = NULL;
+ struct bt_value *params = NULL;
+ struct bt_value *metadata_text_value = NULL;
+ const char *metadata_text = NULL;
+ static const char * const plugin_name = "ctf";
+ static const char * const comp_cls_name = "fs";
+ static const enum bt_component_class_type comp_cls_type =
+ BT_COMPONENT_CLASS_TYPE_SOURCE;
+
+ assert(cfg->cmd_data.print_ctf_metadata.path);
+ comp_cls = find_component_class(plugin_name, comp_cls_name,
+ comp_cls_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, plugin_name,
+ comp_cls_name, comp_cls_type);
+ fprintf(stderr, "\n");
+ ret = -1;
+ goto end;
+ }
+
+ params = bt_value_map_create();
+ if (!params) {