Allow a component to remove a port and any user to disconnect one
[babeltrace.git] / lib / component / source.c
index 8b5de6b6178161f28e946e99f0d1e5aaf5ec1c5f..da40aa87a822a9797ee22b4aac77d88393b0d69e 100644 (file)
@@ -59,47 +59,24 @@ end:
        return ret;
 }
 
-static
+BT_HIDDEN
 void bt_component_source_destroy(struct bt_component *component)
 {
-       struct bt_component_source *source = container_of(component,
-                       struct bt_component_source, parent);
-
-       if (source->output_ports) {
-               g_ptr_array_free(source->output_ports, TRUE);
-       }
 }
 
-
 BT_HIDDEN
 struct bt_component *bt_component_source_create(
                struct bt_component_class *class, struct bt_value *params)
 {
-       int ret;
        struct bt_component_source *source = NULL;
-       enum bt_component_status status;
 
        source = g_new0(struct bt_component_source, 1);
        if (!source) {
                goto end;
        }
 
-       source->parent.class = bt_get(class);
-       status = bt_component_init(&source->parent, bt_component_source_destroy);
-       if (status != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
-       ret = bt_component_init_output_ports(&source->parent, &source->output_ports);
-       if (ret) {
-               goto error;
-       }
-
 end:
        return source ? &source->parent : NULL;
-error:
-       BT_PUT(source);
-       goto end;
 }
 
 BT_HIDDEN
@@ -120,20 +97,14 @@ enum bt_component_status bt_component_source_get_output_port_count(
                struct bt_component *component, uint64_t *count)
 {
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
-       struct bt_component_source *source;
 
-       if (!component || !count) {
+       if (!component || !count ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
                status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
-               status = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       source = container_of(component, struct bt_component_source, parent);
-       *count = (uint64_t) source->output_ports->len;
+       *count = bt_component_get_output_port_count(component);
 end:
        return status;
 }
@@ -141,33 +112,29 @@ end:
 struct bt_port *bt_component_source_get_output_port(
                struct bt_component *component, const char *name)
 {
-       struct bt_component_source *source;
-       struct bt_port *ret_port = NULL;
+       struct bt_port *port = NULL;
 
        if (!component || !name ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
                goto end;
        }
 
-       source = container_of(component, struct bt_component_source, parent);
-       ret_port = bt_component_get_port(source->output_ports, name);
+       port = bt_component_get_output_port(component, name);
 end:
-       return ret_port;
+       return port;
 }
 
 struct bt_port *bt_component_source_get_output_port_at_index(
                struct bt_component *component, int index)
 {
        struct bt_port *port = NULL;
-       struct bt_component_source *source;
 
        if (!component ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
                goto end;
        }
 
-       source = container_of(component, struct bt_component_source, parent);
-       port = bt_component_get_port_at_index(source->output_ports, index);
+       port = bt_component_get_output_port_at_index(component, index);
 end:
        return port;
 }
@@ -182,37 +149,14 @@ struct bt_port *bt_component_source_get_default_output_port(
 struct bt_port *bt_component_source_add_output_port(
                struct bt_component *component, const char *name)
 {
-       struct bt_port *port;
-       struct bt_component_source *source;
+       struct bt_port *port = NULL;
 
        if (!component ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
-               port = NULL;
                goto end;
        }
 
-       source = container_of(component, struct bt_component_source, parent);
-       port = bt_component_add_port(component, source->output_ports,
-                       BT_PORT_TYPE_OUTPUT, name);
+       port = bt_component_add_output_port(component, name);
 end:
        return port;
 }
-
-enum bt_component_status bt_component_source_remove_output_port(
-               struct bt_component *component, const char *name)
-{
-       enum bt_component_status status;
-       struct bt_component_source *source;
-
-       if (!component ||
-                       component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
-               status = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       source = container_of(component, struct bt_component_source, parent);
-       status = bt_component_remove_port(component, source->output_ports,
-                       name);
-end:
-       return status;
-}
This page took 0.025262 seconds and 4 git commands to generate.