* SOFTWARE.
*/
-#include <babeltrace/component/component-internal.h>
-#include <babeltrace/component/port-internal.h>
+#include <babeltrace/graph/component-internal.h>
+#include <babeltrace/graph/port-internal.h>
+#include <babeltrace/graph/connection-internal.h>
#include <babeltrace/object-internal.h>
-#include <babeltrace/compiler.h>
+#include <babeltrace/compiler-internal.h>
static
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);
}
+struct bt_port *bt_port_from_private_port(
+ struct bt_private_port *private_port)
+{
+ return bt_get(bt_port_from_private(private_port));
+}
+
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;
}
}
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:
return port ? port->type : BT_PORT_TYPE_UNKOWN;
}
-enum bt_port_status bt_port_get_connection_count(struct bt_port *port,
- uint64_t *count)
+struct bt_connection *bt_port_get_connection(struct bt_port *port)
{
- enum bt_port_status status = BT_PORT_STATUS_OK;
+ struct bt_connection *connection = NULL;
- if (!port || !count) {
- status = BT_PORT_STATUS_INVALID;
+ if (!port || !port->connection) {
goto end;
}
- *count = (uint64_t) port->connections->len;
+ connection = bt_get(port->connection);
end:
- return status;
+ return connection;
}
-struct bt_connection *bt_port_get_connection(struct bt_port *port, int index)
+struct bt_component *bt_port_get_component(struct bt_port *port)
{
- struct bt_connection *connection;
-
- if (!port || index < 0 || index >= port->connections->len) {
- connection = NULL;
- goto end;
- }
+ return (struct bt_component *) bt_object_get_parent(port);
+}
- connection = bt_get(g_ptr_array_index(port->connections, index));
-end:
- return connection;
+struct bt_private_connection *bt_private_port_get_private_connection(
+ struct bt_private_port *private_port)
+{
+ return bt_private_connection_from_connection(bt_port_get_connection(
+ bt_port_from_private(private_port)));
}
-struct bt_component *bt_port_get_component(struct bt_port *port)
+struct bt_private_component *bt_private_port_get_private_component(
+ struct bt_private_port *private_port)
{
- return (struct bt_component *) bt_object_get_parent(port);
+ return bt_private_component_from_component(bt_port_get_component(
+ bt_port_from_private(private_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_private_port_remove_from_component(
+ struct bt_private_port *private_port)
{
int ret = 0;
+ struct bt_port *port = bt_port_from_private(private_port);
+ 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);
+ }
+
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;
+}
+
+int bt_private_port_set_user_data(
+ struct bt_private_port *private_port, void *user_data)
+{
+ int ret = 0;
+
+ if (!private_port) {
+ ret = -1;
+ goto end;
+ }
+
+ bt_port_from_private(private_port)->user_data = user_data;
+
+end:
+ return ret;
+}
+
+void *bt_private_port_get_user_data(
+ struct bt_private_port *private_port)
+{
+ return private_port ?
+ bt_port_from_private(private_port)->user_data : NULL;
}