X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=cli%2Fbabeltrace.c;h=4e35b8b6dd057024f8e53d96244c6479e0ccb05a;hb=36712f1d9ad9269638e493ca36a50979fe4da989;hp=8e4755a6f4204c6efce8061a6e556007d8f2552e;hpb=ea9f8b298e259ae01504091093fcf3d1edf6b3b8;p=babeltrace.git diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 8e4755a6..4e35b8b6 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -1178,7 +1178,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( uint64_t i; int64_t (*port_count_fn)(struct bt_component *); struct bt_port *(*port_by_index_fn)(struct bt_component *, uint64_t); - void *conn = NULL; + enum bt_graph_status status = BT_GRAPH_STATUS_ERROR; BT_LOGI("Connecting upstream port to the next available downstream port: " "upstream-port-addr=%p, upstream-port-name=\"%s\", " @@ -1190,7 +1190,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( cfg_conn->downstream_comp_name->str); assert(downstreamp_comp_name_quark > 0); downstream_comp = g_hash_table_lookup(ctx->components, - (gpointer) (long) downstreamp_comp_name_quark); + GUINT_TO_POINTER(downstreamp_comp_name_quark)); if (!downstream_comp) { BT_LOGE("Cannot find downstream component: comp-name=\"%s\", " "conn-arg=\"%s\"", cfg_conn->downstream_comp_name->str, @@ -1243,10 +1243,35 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( cfg_conn->downstream_port_glob->str, -1ULL, downstream_port_name, -1ULL)) { /* We have a winner! */ - conn = bt_graph_connect_ports(ctx->graph, - upstream_port, downstream_port); + status = bt_graph_connect_ports(ctx->graph, + upstream_port, downstream_port, NULL); bt_put(downstream_port); - if (!conn) { + switch (status) { + case BT_GRAPH_STATUS_OK: + break; + case BT_GRAPH_STATUS_CANCELED: + BT_LOGI_STR("Graph was canceled by user."); + status = BT_GRAPH_STATUS_OK; + break; + case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: + BT_LOGE("A component refused a connection to one of its ports: " + "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " + "upstream-port-addr=%p, upstream-port-name=\"%s\", " + "downstream-comp-addr=%p, downstream-comp-name=\"%s\", " + "downstream-port-addr=%p, downstream-port-name=\"%s\", " + "conn-arg=\"%s\"", + upstream_comp, bt_component_get_name(upstream_comp), + upstream_port, bt_port_get_name(upstream_port), + downstream_comp, cfg_conn->downstream_comp_name->str, + downstream_port, downstream_port_name, + cfg_conn->arg->str); + fprintf(stderr, + "A component refused a connection to one of its ports (`%s` to `%s`): %s\n", + bt_port_get_name(upstream_port), + downstream_port_name, + cfg_conn->arg->str); + break; + default: BT_LOGE("Cannot create connection: graph refuses to connect ports: " "upstream-comp-addr=%p, upstream-comp-name=\"%s\", " "upstream-port-addr=%p, upstream-port-name=\"%s\", " @@ -1284,7 +1309,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component( bt_put(downstream_port); } - if (!conn) { + if (status != BT_GRAPH_STATUS_OK) { BT_LOGE("Cannot create connection: cannot find a matching downstream port for upstream port: " "upstream-port-addr=%p, upstream-port-name=\"%s\", " "downstream-comp-name=\"%s\", conn-arg=\"%s\"", @@ -1303,7 +1328,6 @@ error: ret = -1; end: - bt_put(conn); return ret; } @@ -1394,6 +1418,11 @@ void graph_port_added_listener(struct bt_port *port, void *data) "comp-name=\"%s\", port-addr=%p, port-name=\"%s\"", comp, comp ? bt_component_get_name(comp) : "", port, bt_port_get_name(port)); + + if (!ctx->connect_ports) { + goto end; + } + if (!comp) { BT_LOGW_STR("Port has no component."); goto end; @@ -1574,9 +1603,9 @@ int cmd_run_ctx_create_components_from_config_components( goto error; } - comp = bt_component_create(comp_cls, - cfg_comp->instance_name->str, cfg_comp->params); - if (!comp) { + ret = bt_graph_add_component(ctx->graph, comp_cls, + cfg_comp->instance_name->str, cfg_comp->params, &comp); + if (ret) { BT_LOGE("Cannot create component: plugin-name=\"%s\", " "comp-cls-name=\"%s\", comp-cls-type=%d, " "comp-name=\"%s\"", @@ -1596,7 +1625,7 @@ int cmd_run_ctx_create_components_from_config_components( quark = g_quark_from_string(cfg_comp->instance_name->str); assert(quark > 0); g_hash_table_insert(ctx->components, - (gpointer) (long) quark, comp); + GUINT_TO_POINTER(quark), comp); comp = NULL; BT_PUT(comp_cls); } @@ -1720,8 +1749,6 @@ const char *bt_graph_status_str(enum bt_graph_status status) return "BT_GRAPH_STATUS_END"; case BT_GRAPH_STATUS_OK: return "BT_GRAPH_STATUS_OK"; - case BT_GRAPH_STATUS_ALREADY_IN_A_GRAPH: - return "BT_GRAPH_STATUS_ALREADY_IN_A_GRAPH"; case BT_GRAPH_STATUS_INVALID: return "BT_GRAPH_STATUS_INVALID"; case BT_GRAPH_STATUS_NO_SINK: