#include <babeltrace/component/component-sink.h>
#include <babeltrace/component/component-filter.h>
#include <babeltrace/component/component-class.h>
+#include <babeltrace/component/port.h>
+#include <babeltrace/component/graph.h>
+#include <babeltrace/component/connection.h>
#include <babeltrace/component/notification/iterator.h>
#include <babeltrace/ref.h>
#include <babeltrace/values.h>
}
}
+static char *escape_name_for_shell(const char *input)
+{
+ char *output = g_malloc0(strlen(input) * 5 + 1);
+ const char *in;
+ char *out = output;
+
+ if (!output) {
+ goto end;
+ }
+
+ for (in = input; *in != '\0'; in++) {
+ switch (*in) {
+ case '\\':
+ *out++ = '\\';
+ *out++ = '\\';
+ break;
+ case '\'':
+ *out++ = '\'';
+ *out++ = '"';
+ *out++ = '\'';
+ *out++ = '"';
+ *out++ = '\'';
+ break;
+ case '.':
+ *out++ = '\\';
+ *out++ = '.';
+ break;
+ default:
+ *out++ = *in;
+ break;
+ }
+ }
+
+end:
+ return output;
+}
+
+static
+const char *component_type_str(enum bt_component_class_type type)
+{
+ switch (type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ return "source";
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ return "sink";
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ return "filter";
+ case BT_COMPONENT_CLASS_TYPE_UNKNOWN:
+ default:
+ return "unknown";
+ }
+}
+
+static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
+ const char *comp_cls_name, enum bt_component_class_type type)
+{
+ char *shell_plugin_name = NULL;
+ char *shell_comp_cls_name = NULL;
+
+ shell_plugin_name = escape_name_for_shell(plugin_name);
+ if (!shell_plugin_name) {
+ goto end;
+ }
+
+ shell_comp_cls_name = escape_name_for_shell(comp_cls_name);
+ if (!shell_comp_cls_name) {
+ goto end;
+ }
+
+ fprintf(fh, "%s%s--%s%s %s'%s%s%s%s.%s%s%s'",
+ bt_common_color_bold(),
+ bt_common_color_fg_cyan(),
+ component_type_str(type),
+ bt_common_color_reset(),
+ bt_common_color_fg_default(),
+ bt_common_color_bold(),
+ bt_common_color_fg_blue(),
+ shell_plugin_name,
+ bt_common_color_fg_default(),
+ bt_common_color_fg_yellow(),
+ shell_comp_cls_name,
+ bt_common_color_reset());
+
+end:
+ g_free(shell_plugin_name);
+ g_free(shell_comp_cls_name);
+}
+
static
void print_value(struct bt_value *, size_t);
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);
+ printf(" ");
+ print_plugin_comp_cls_opt(stdout, bt_config_component->plugin_name->str,
+ bt_config_component->component_name->str,
+ bt_config_component->type);
+ printf(":\n");
if (bt_config_component->instance_name->len > 0) {
printf(" Name: %s\n",
}
static
-int connect_source_sink(struct bt_component *source,
+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;
- enum bt_component_status sink_status;
+ struct bt_connection *connection = NULL;
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;
- }
+ 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. */
- enum bt_component_status trimmer_status;
-
trimmer = create_trimmer(source_cfg);
if (!trimmer) {
fprintf(stderr, "Failed to create trimmer component. Aborting...\n");
goto end;
}
- trimmer_status = bt_component_filter_add_iterator(trimmer,
- source_it);
- BT_PUT(source_it);
- if (trimmer_status != BT_COMPONENT_STATUS_OK) {
- fprintf(stderr, "Failed to connect source to trimmer. Aborting...\n");
+ 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;
}
- to_sink_it = bt_component_filter_create_notification_iterator(trimmer);
- if (!to_sink_it) {
- fprintf(stderr, "Failed to instantiate trimmer iterator. Aborting...\n");
+ 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_it, source_it);
+ BT_MOVE(to_sink_port, source_port);
}
- sink_status = bt_component_sink_add_iterator(sink, to_sink_it);
- if (sink_status != BT_COMPONENT_STATUS_OK) {
- fprintf(stderr, "Failed to connect to sink component. Aborting...\n");
+ 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_it);
- bt_put(to_sink_it);
+ bt_put(source_port);
+ bt_put(sink_port);
+ bt_put(to_sink_port);
+ bt_put(connection);
return ret;
}
return ret;
}
-static
-const char *component_type_str(enum bt_component_class_type type)
-{
- switch (type) {
- case BT_COMPONENT_CLASS_TYPE_SOURCE:
- return "source";
- case BT_COMPONENT_CLASS_TYPE_SINK:
- return "sink";
- case BT_COMPONENT_CLASS_TYPE_FILTER:
- return "filter";
- case BT_COMPONENT_CLASS_TYPE_UNKNOWN:
- default:
- return "unknown";
- }
-}
-
static int load_all_plugins(struct bt_value *plugin_paths)
{
int ret = 0;
license ? license : "(Unknown)");
}
-static void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
- const char *comp_cls_name, enum bt_component_class_type type)
-{
- fprintf(fh, "%s%s--%s%s %s%s%s.%s%s%s",
- bt_common_color_bold(),
- bt_common_color_fg_cyan(),
- component_type_str(type),
- bt_common_color_fg_default(),
- bt_common_color_fg_blue(),
- plugin_name,
- bt_common_color_fg_default(),
- bt_common_color_fg_yellow(),
- comp_cls_name,
- bt_common_color_reset());
-}
-
static int cmd_query(struct bt_config *cfg)
{
int ret;
struct bt_component_class *sink_class = NULL;
struct bt_component *source = NULL, *sink = NULL;
struct bt_value *source_params = NULL, *sink_params = NULL;
- enum bt_component_status sink_status;
struct bt_config_component *source_cfg = NULL, *sink_cfg = NULL;
+ struct bt_graph *graph = NULL;
ret = load_all_plugins(cfg->cmd_data.convert.plugin_paths);
if (ret) {
source_cfg->component_name->str,
BT_COMPONENT_CLASS_TYPE_SOURCE);
if (!source_class) {
- fprintf(stderr, "Could not find %s.%s source component class. Aborting...\n",
- source_cfg->plugin_name->str,
- source_cfg->component_name->str);
+ fprintf(stderr, "Could not find ");
+ print_plugin_comp_cls_opt(stderr, source_cfg->plugin_name->str,
+ source_cfg->component_name->str, BT_COMPONENT_CLASS_TYPE_SOURCE);
+ fprintf(stderr, ". Aborting...\n");
ret = -1;
goto end;
}
sink_cfg->component_name->str,
BT_COMPONENT_CLASS_TYPE_SINK);
if (!sink_class) {
- fprintf(stderr, "Could not find %s.%s output component class. Aborting...\n",
- sink_cfg->plugin_name->str,
- sink_cfg->component_name->str);
+ fprintf(stderr, "Could not find ");
+ print_plugin_comp_cls_opt(stderr, sink_cfg->plugin_name->str,
+ sink_cfg->component_name->str, BT_COMPONENT_CLASS_TYPE_SINK);
+ fprintf(stderr, ". Aborting...\n");
+ ret = -1;
+ goto end;
+ }
+
+ graph = bt_graph_create();
+ if (!graph) {
ret = -1;
goto end;
}
goto end;
}
- ret = connect_source_sink(source, source_cfg, sink);
+ ret = connect_source_sink(graph, source, source_cfg, sink);
if (ret) {
ret = -1;
goto end;
}
while (true) {
- sink_status = bt_component_sink_consume(sink);
- switch (sink_status) {
- case BT_COMPONENT_STATUS_AGAIN:
+ enum bt_graph_status graph_status;
+
+ graph_status = bt_graph_run(graph, NULL);
+ switch (graph_status) {
+ case BT_GRAPH_STATUS_AGAIN:
/* Wait for an arbitraty 500 ms. */
usleep(500000);
break;
- case BT_COMPONENT_STATUS_OK:
- break;
case BT_COMPONENT_STATUS_END:
goto end;
default:
}
end:
- BT_PUT(sink_class);
- BT_PUT(source_class);
- BT_PUT(source);
- BT_PUT(sink);
- BT_PUT(source_params);
- BT_PUT(sink_params);
- BT_PUT(sink_cfg);
- BT_PUT(source_cfg);
+ bt_put(sink_class);
+ bt_put(source_class);
+ bt_put(source);
+ bt_put(sink);
+ bt_put(source_params);
+ bt_put(sink_params);
+ bt_put(sink_cfg);
+ bt_put(source_cfg);
+ bt_put(graph);
return ret;
}