X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=lib%2Fcomponent%2Fport.c;h=e5fcd46ca487fdc255ad953bb4615e10def4fb51;hb=72b913fbad1753b5b122bfb54c1e7936eaf9d0ef;hp=8aa9a462fe4eaca6a842a079ac08675d390bd3fc;hpb=6fbd4105b92d0da8b3c5818a5b7c5b07850f4a01;p=babeltrace.git diff --git a/lib/component/port.c b/lib/component/port.c index 8aa9a462..e5fcd46c 100644 --- a/lib/component/port.c +++ b/lib/component/port.c @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -39,9 +40,6 @@ void bt_port_destroy(struct bt_object *obj) if (port->name) { g_string_free(port->name, TRUE); } - if (port->connections) { - g_ptr_array_free(port->connections, TRUE); - } g_free(port); } @@ -49,14 +47,13 @@ BT_HIDDEN struct bt_port *bt_port_create(struct bt_component *parent_component, enum bt_port_type type, const char *name) { - struct bt_port *port; + struct bt_port *port = NULL; assert(name); assert(parent_component); assert(type == BT_PORT_TYPE_INPUT || type == BT_PORT_TYPE_OUTPUT); - if (*name == '\0') { - port = NULL; + if (strlen(name) == 0) { goto end; } @@ -73,13 +70,6 @@ struct bt_port *bt_port_create(struct bt_component *parent_component, } port->type = type; - port->connections = g_ptr_array_new(); - if (!port->connections) { - BT_PUT(port); - goto end; - } - - port->max_connection_count = 1; bt_object_set_parent(port, &parent_component->base); end: @@ -96,31 +86,15 @@ enum bt_port_type bt_port_get_type(struct bt_port *port) return port ? port->type : BT_PORT_TYPE_UNKOWN; } -enum bt_port_status bt_port_get_connection_count(struct bt_port *port, - uint64_t *count) -{ - enum bt_port_status status = BT_PORT_STATUS_OK; - - if (!port || !count) { - status = BT_PORT_STATUS_INVALID; - goto end; - } - - *count = (uint64_t) port->connections->len; -end: - return status; -} - -struct bt_connection *bt_port_get_connection(struct bt_port *port, int index) +struct bt_connection *bt_port_get_connection(struct bt_port *port) { - struct bt_connection *connection; + struct bt_connection *connection = NULL; - if (!port || index < 0 || index >= port->connections->len) { - connection = NULL; + if (!port || !port->connection) { goto end; } - connection = bt_get(g_ptr_array_index(port->connections, index)); + connection = bt_get(port->connection); end: return connection; } @@ -131,51 +105,63 @@ struct bt_component *bt_port_get_component(struct bt_port *port) } BT_HIDDEN -int bt_port_add_connection(struct bt_port *port, +void bt_port_set_connection(struct bt_port *port, struct bt_connection *connection) +{ + /* + * Don't take a reference on connection as its existence is + * guaranteed by the existence of the graph in which the + * connection exists. + */ + port->connection = connection; +} + +int bt_port_remove_from_component(struct bt_port *port) { int ret = 0; + struct bt_component *comp = NULL; - if (port->connections->len == port->max_connection_count) { + if (!port) { ret = -1; goto end; } - /* - * Don't take a reference on connection as its existence is guaranteed - * by the existence of the graph in which the connection exists. - */ - g_ptr_array_add(port->connections, connection); + comp = (void *) bt_object_get_parent(port); + ret = bt_component_remove_port(comp, port); + end: + bt_put(comp); return ret; } -enum bt_port_status bt_port_get_maximum_connection_count( - struct bt_port *port, uint64_t *count) +int bt_port_disconnect(struct bt_port *port) { - enum bt_port_status status = BT_PORT_STATUS_OK; + int ret = 0; - if (!port || !count) { - status = BT_PORT_STATUS_INVALID; + if (!port) { + ret = -1; goto end; } - *count = port->max_connection_count; + if (port->connection) { + bt_connection_disconnect_ports(port->connection, NULL); + } + end: - return status; + return ret; } -enum bt_port_status bt_port_set_maximum_connection_count( - struct bt_port *port, uint64_t count) +int bt_port_is_connected(struct bt_port *port) { - enum bt_port_status status = BT_PORT_STATUS_OK; + int ret; - if (!port || count < port->connections->len || count == 0) { - status = BT_PORT_STATUS_INVALID; + if (!port) { + ret = -1; goto end; } - port->max_connection_count = count; + ret = port->connection ? 1 : 0; + end: - return status; + return ret; }