+ if (load_static_plugins()) {
+ fprintf(stderr, "Failed to load static plugins.\n");
+ ret = -1;
+ goto end;
+ }
+
+end:
+ return ret;
+}
+
+static void print_plugin_info(struct bt_plugin *plugin)
+{
+ unsigned int major, minor, patch;
+ const char *extra;
+ enum bt_plugin_status version_status;
+ const char *plugin_name;
+ const char *path;
+ const char *author;
+ const char *license;
+ const char *plugin_description;
+
+ plugin_name = bt_plugin_get_name(plugin);
+ path = bt_plugin_get_path(plugin);
+ author = bt_plugin_get_author(plugin);
+ license = bt_plugin_get_license(plugin);
+ plugin_description = bt_plugin_get_description(plugin);
+ version_status = bt_plugin_get_version(plugin, &major, &minor,
+ &patch, &extra);
+ printf("%s%s%s%s:\n", bt_common_color_bold(),
+ bt_common_color_fg_blue(), plugin_name,
+ bt_common_color_reset());
+ printf(" %sPath%s: %s\n", bt_common_color_bold(),
+ bt_common_color_reset(), path ? path : "(None)");
+
+ if (version_status == BT_PLUGIN_STATUS_OK) {
+ printf(" %sVersion%s: %u.%u.%u",
+ bt_common_color_bold(), bt_common_color_reset(),
+ major, minor, patch);
+
+ if (extra) {
+ printf("%s", extra);
+ }
+
+ printf("\n");
+ }
+
+ printf(" %sDescription%s: %s\n", bt_common_color_bold(),
+ bt_common_color_reset(),
+ plugin_description ? plugin_description : "(None)");
+ printf(" %sAuthor%s: %s\n", bt_common_color_bold(),
+ bt_common_color_reset(), author ? author : "(Unknown)");
+ printf(" %sLicense%s: %s\n", bt_common_color_bold(),
+ bt_common_color_reset(),
+ license ? license : "(Unknown)");
+}
+
+static int cmd_query(struct bt_config *cfg)
+{
+ int ret;
+ struct bt_component_class *comp_cls = NULL;
+ struct bt_value *results = NULL;
+
+ ret = load_all_plugins(cfg->plugin_paths);
+ if (ret) {
+ goto end;
+ }
+
+ comp_cls = find_component_class(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);
+ 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.cfg_component->plugin_name->str,
+ cfg->cmd_data.query.cfg_component->comp_cls_name->str,
+ cfg->cmd_data.query.cfg_component->type);
+ fprintf(stderr, "\n");
+ ret = -1;
+ goto end;
+ }
+
+ 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;