plugin-so: use list of components instead of glib hash table
[babeltrace.git] / cli / babeltrace.c
index 66c74df44b85ca8024f2ef99cc5e07bd3232bbd0..6cdb8442f146d41891a45efb5e3a1742e3a46022 100644 (file)
@@ -178,7 +178,7 @@ const char *component_type_str(enum bt_component_class_type type)
                return "filter";
        case BT_COMPONENT_CLASS_TYPE_UNKNOWN:
        default:
-               return "unknown";
+               return "(unknown)";
        }
 }
 
@@ -199,13 +199,11 @@ void print_plugin_comp_cls_opt(FILE *fh, const char *plugin_name,
                goto end;
        }
 
-       fprintf(fh, "%s%s--%s%s %s'%s%s%s%s.%s%s%s'",
+       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_reset(),
                bt_common_color_fg_default(),
-               bt_common_color_bold(),
                bt_common_color_fg_blue(),
                shell_plugin_name->str,
                bt_common_color_fg_default(),
@@ -1178,7 +1176,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\", "
@@ -1243,10 +1241,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 +1307,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 +1326,6 @@ error:
        ret = -1;
 
 end:
-       bt_put(conn);
        return ret;
 }
 
@@ -1394,6 +1416,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 +1601,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\"",
@@ -1720,8 +1747,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:
This page took 0.025059 seconds and 4 git commands to generate.