+ }
+
+ bt_value_map_foreach(value, print_map_value, &indent);
+ break;
+ default:
+ assert(false);
+ }
+}
+
+static
+void print_bt_config_component(struct bt_config_component *bt_config_component)
+{
+ printf(" %s.%s:\n", bt_config_component->plugin_name->str,
+ bt_config_component->component_name->str);
+
+ if (bt_config_component->instance_name->len > 0) {
+ printf(" Name: %s\n",
+ bt_config_component->instance_name->str);
+ }
+
+ printf(" Parameters:\n");
+ print_value(bt_config_component->params, 8);
+}
+
+static
+void print_bt_config_components(GPtrArray *array)
+{
+ size_t i;
+
+ for (i = 0; i < array->len; i++) {
+ struct bt_config_component *cfg_component =
+ bt_config_get_component(array, i);
+ print_bt_config_component(cfg_component);
+ BT_PUT(cfg_component);
+ }
+}
+
+static
+void print_plugin_paths(struct bt_value *plugin_paths)
+{
+ printf(" Plugin paths:\n");
+ print_value(plugin_paths, 4);
+}
+
+static
+void print_cfg_convert(struct bt_config *cfg)
+{
+ size_t i;
+
+ printf(" Force correlate: %s\n",
+ cfg->cmd_data.convert.force_correlate ? "yes" : "no");
+ print_plugin_paths(cfg->cmd_data.convert.plugin_paths);
+ printf(" Source component instances:\n");
+ print_bt_config_components(cfg->cmd_data.convert.sources);
+
+ if (cfg->cmd_data.convert.filters->len > 0) {
+ printf(" Filter component instances:\n");
+ print_bt_config_components(cfg->cmd_data.convert.filters);
+ }
+
+ printf(" Sink component instances:\n");
+ print_bt_config_components(cfg->cmd_data.convert.sinks);
+ printf(" Connections:\n");
+
+ for (i = 0; i < cfg->cmd_data.convert.connections->len; i++) {
+ struct bt_config_connection *cfg_connection =
+ g_ptr_array_index(cfg->cmd_data.convert.connections,
+ i);
+
+ printf(" %s%s%s -> %s%s%s\n",
+ cfg_connection->src_instance_name->str,
+ cfg_connection->src_port_name->len > 0 ? "." : "",
+ cfg_connection->src_port_name->str,
+ cfg_connection->dst_instance_name->str,
+ cfg_connection->dst_port_name->len > 0 ? "." : "",
+ cfg_connection->dst_port_name->str);
+ }
+}
+
+static
+void print_cfg_list_plugins(struct bt_config *cfg)
+{
+ print_plugin_paths(cfg->cmd_data.list_plugins.plugin_paths);
+}
+
+static
+void print_cfg(struct bt_config *cfg)
+{
+ if (!babeltrace_verbose) {
+ return;
+ }
+
+ 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_CONVERT:
+ print_cfg_convert(cfg);
+ break;
+ case BT_CONFIG_COMMAND_LIST_PLUGINS:
+ print_cfg_list_plugins(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_component *source,
+ struct bt_config_component *source_cfg,
+ struct bt_component *sink)
+{
+ int ret = 0;
+ enum bt_component_status sink_status;
+ struct bt_component *trimmer = NULL;
+ struct bt_notification_iterator *source_it = NULL;
+ struct bt_notification_iterator *to_sink_it = NULL;
+
+ source_it = bt_component_source_create_notification_iterator(source);
+ if (!source_it) {
+ fprintf(stderr, "Failed to instantiate source iterator. 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. */
+ enum bt_component_status trimmer_status;
+
+ trimmer = create_trimmer(source_cfg);
+ if (!trimmer) {
+ fprintf(stderr, "Failed to create trimmer component. Aborting...\n");
+ ret = -1;