- printf_verbose("Found %d component classes.\n", count);
- for (i = 0; i < count; i++) {
- struct bt_component_class *component_class =
- bt_component_factory_get_component_class_index(
- factory, i);
- struct bt_plugin *plugin = bt_component_class_get_plugin(
- component_class);
- const char *plugin_name = bt_plugin_get_name(plugin);
- const char *component_name = bt_component_class_get_name(
- component_class);
- const char *path = bt_plugin_get_path(plugin);
- const char *author = bt_plugin_get_author(plugin);
- const char *license = bt_plugin_get_license(plugin);
- const char *plugin_description = bt_plugin_get_description(
- plugin);
- const char *component_description =
- bt_component_class_get_description(
- component_class);
- enum bt_component_type type = bt_component_class_get_type(
- component_class);
-
- printf_verbose("[%s - %s (%s)]\n", plugin_name, component_name,
- component_type_str(type));
- printf_verbose("\tpath: %s\n", path);
- printf_verbose("\tauthor: %s\n", author);
- printf_verbose("\tlicense: %s\n", license);
- printf_verbose("\tplugin description: %s\n",
- plugin_description ? plugin_description : "None");
- printf_verbose("\tcomponent description: %s\n",
- component_description ? component_description : "None");
-
- bt_put(plugin);
- bt_put(component_class);
- }
-}
-
-int main(int argc, char **argv)
+ printf("Configuration:\n");
+ printf(" Debug mode: %s\n", cfg->debug ? "yes" : "no");
+ printf(" Verbose mode: %s\n", cfg->verbose ? "yes" : "no");
+
+ switch (cfg->command) {
+ case BT_CONFIG_COMMAND_RUN:
+ print_cfg_run(cfg);
+ break;
+ case BT_CONFIG_COMMAND_LIST_PLUGINS:
+ print_cfg_list_plugins(cfg);
+ break;
+ case BT_CONFIG_COMMAND_HELP:
+ print_cfg_help(cfg);
+ break;
+ case BT_CONFIG_COMMAND_QUERY:
+ print_cfg_query(cfg);
+ break;
+ case BT_CONFIG_COMMAND_PRINT_CTF_METADATA:
+ print_cfg_print_ctf_metadata(cfg);
+ break;
+ case BT_CONFIG_COMMAND_PRINT_LTTNG_LIVE_SESSIONS:
+ print_cfg_print_lttng_live_sessions(cfg);
+ break;
+ default:
+ assert(false);
+ }
+}
+
+static
+struct bt_component *create_trimmer(struct bt_config_component *source_cfg)
+{
+ struct bt_component *trimmer = NULL;
+ struct bt_component_class *trimmer_class = NULL;
+ struct bt_value *trimmer_params = NULL;
+ struct bt_value *value;
+
+ trimmer_params = bt_value_map_create();
+ if (!trimmer_params) {
+ goto end;
+ }
+
+ value = bt_value_map_get(source_cfg->params, "begin");
+ if (value) {
+ enum bt_value_status ret;
+
+ ret = bt_value_map_insert(trimmer_params, "begin",
+ value);
+ BT_PUT(value);
+ if (ret) {
+ goto end;
+ }
+ }
+ value = bt_value_map_get(source_cfg->params, "end");
+ if (value) {
+ enum bt_value_status ret;
+
+ ret = bt_value_map_insert(trimmer_params, "end",
+ value);
+ BT_PUT(value);
+ if (ret) {
+ goto end;
+ }
+ }
+ value = bt_value_map_get(source_cfg->params, "clock-gmt");
+ if (value) {
+ enum bt_value_status ret;
+
+ ret = bt_value_map_insert(trimmer_params, "clock-gmt",
+ value);
+ BT_PUT(value);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ trimmer_class = find_component_class("utils", "trimmer",
+ BT_COMPONENT_CLASS_TYPE_FILTER);
+ if (!trimmer_class) {
+ fprintf(stderr, "Could not find trimmer component class. Aborting...\n");
+ goto end;
+ }
+ trimmer = bt_component_create(trimmer_class, "source_trimmer",
+ trimmer_params);
+ if (!trimmer) {
+ goto end;
+ }
+end:
+ bt_put(trimmer_params);
+ bt_put(trimmer_class);
+ return trimmer;
+}
+
+static
+int connect_source_sink(struct bt_graph *graph,
+ struct bt_component *source,
+ struct bt_config_component *source_cfg,
+ struct bt_component *sink)
+{
+ int ret = 0;
+ struct bt_connection *connection = NULL;
+ struct bt_component *trimmer = NULL;
+ struct bt_port *source_port =
+ bt_component_source_get_default_output_port(source);
+ struct bt_port *sink_port =
+ bt_component_sink_get_default_input_port(sink);
+ struct bt_port *to_sink_port = NULL;
+ struct bt_port *trimmer_input_port = NULL;
+
+ if (!source_port) {
+ fprintf(stderr, "Failed to find default source output port. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+ if (!sink_port) {
+ fprintf(stderr, "Failed to find default sink input port. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+
+ if (bt_value_map_has_key(source_cfg->params, "begin")
+ || bt_value_map_has_key(source_cfg->params, "end")) {
+ /* A trimmer must be inserted in the graph. */
+ trimmer = create_trimmer(source_cfg);
+ if (!trimmer) {
+ fprintf(stderr, "Failed to create trimmer component. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+
+ trimmer_input_port = bt_component_filter_get_default_input_port(
+ trimmer);
+ if (!trimmer_input_port) {
+ fprintf(stderr, "Failed to find trimmer input port. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+ to_sink_port = bt_component_filter_get_default_output_port(
+ trimmer);
+ if (!to_sink_port) {
+ fprintf(stderr, "Failed to find trimmer output port. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+
+ connection = bt_graph_connect(graph, source_port,
+ trimmer_input_port);
+ if (!connection) {
+ fprintf(stderr, "Failed to connect source to trimmer. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+ BT_PUT(connection);
+ } else {
+ BT_MOVE(to_sink_port, source_port);
+ }
+
+ connection = bt_graph_connect(graph, to_sink_port, sink_port);
+ if (!connection) {
+ fprintf(stderr, "Failed to connect to sink. Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+end:
+ bt_put(trimmer);
+ bt_put(source_port);
+ bt_put(sink_port);
+ bt_put(to_sink_port);
+ bt_put(connection);
+ return ret;
+}
+
+static
+void add_to_loaded_plugins(struct bt_plugin **plugins)
+{
+ while (*plugins) {
+ struct bt_plugin *plugin = *plugins;
+ /* Check if it's already loaded (from another path). */
+ struct bt_plugin *loaded_plugin =
+ find_plugin(bt_plugin_get_name(plugin));
+
+ if (loaded_plugin) {
+ printf_verbose("Not loading plugin `%s`: already loaded from `%s`\n",
+ bt_plugin_get_path(plugin),
+ bt_plugin_get_path(loaded_plugin));
+ BT_PUT(loaded_plugin);
+ BT_PUT(plugin);
+ } else {
+ /* Transfer ownership to global array. */
+ g_ptr_array_add(loaded_plugins, plugin);
+ }
+ *(plugins++) = NULL;
+ }
+}
+
+static
+int load_dynamic_plugins(struct bt_value *plugin_paths)
+{
+ int nr_paths, i, ret = 0;
+
+ nr_paths = bt_value_array_size(plugin_paths);
+ if (nr_paths < 0) {
+ ret = -1;
+ goto end;
+ }
+
+ for (i = 0; i < nr_paths; i++) {
+ struct bt_value *plugin_path_value = NULL;
+ const char *plugin_path;
+ struct bt_plugin **plugins;
+
+ plugin_path_value = bt_value_array_get(plugin_paths, i);
+ if (bt_value_string_get(plugin_path_value,
+ &plugin_path)) {
+ BT_PUT(plugin_path_value);
+ continue;
+ }
+
+ plugins = bt_plugin_create_all_from_dir(plugin_path, false);
+ if (!plugins) {
+ printf_debug("Unable to dynamically load plugins from path %s.\n",
+ plugin_path);
+ BT_PUT(plugin_path_value);
+ continue;
+ }
+
+ add_to_loaded_plugins(plugins);
+ free(plugins);
+
+ BT_PUT(plugin_path_value);
+ }
+end:
+ return ret;
+}
+
+static
+int load_static_plugins(void)
+{
+ int ret = 0;
+ struct bt_plugin **plugins;
+
+ plugins = bt_plugin_create_all_from_static();
+ if (!plugins) {
+ printf_debug("Unable to load static plugins.\n");
+ ret = -1;
+ goto end;
+ }
+
+ add_to_loaded_plugins(plugins);
+ free(plugins);
+end:
+ return ret;
+}
+
+static int load_all_plugins(struct bt_value *plugin_paths)
+{
+ int ret = 0;
+
+ if (load_dynamic_plugins(plugin_paths)) {
+ fprintf(stderr, "Failed to load dynamic plugins.\n");
+ ret = -1;
+ goto end;
+ }
+
+ 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)