Allow a component to remove a port and any user to disconnect one
[babeltrace.git] / lib / component / filter.c
index 8abd5a6d38c2b1be421fdd0547ec9faf83266315..da08c7fe7834dad6be1861ebea6689544895f041 100644 (file)
@@ -48,57 +48,24 @@ struct bt_notification_iterator *bt_component_filter_create_notification_iterato
        return bt_component_create_iterator(component, init_method_data);
 }
 
-static
+BT_HIDDEN
 void bt_component_filter_destroy(struct bt_component *component)
 {
-       struct bt_component_filter *filter = container_of(component,
-                       struct bt_component_filter, parent);
-
-       if (filter->input_ports) {
-               g_ptr_array_free(filter->input_ports, TRUE);
-       }
-
-       if (filter->output_ports) {
-               g_ptr_array_free(filter->output_ports, TRUE);
-       }
 }
 
 BT_HIDDEN
 struct bt_component *bt_component_filter_create(
                struct bt_component_class *class, struct bt_value *params)
 {
-       int ret;
        struct bt_component_filter *filter = NULL;
-       enum bt_component_status status;
 
        filter = g_new0(struct bt_component_filter, 1);
        if (!filter) {
                goto end;
        }
 
-       filter->parent.class = bt_get(class);
-       status = bt_component_init(&filter->parent, bt_component_filter_destroy);
-       if (status != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
-       ret = bt_component_init_input_ports(&filter->parent,
-                       &filter->input_ports);
-       if (ret) {
-               goto error;
-       }
-
-       ret = bt_component_init_output_ports(&filter->parent,
-                       &filter->output_ports);
-       if (ret) {
-               goto error;
-       }
-
 end:
        return filter ? &filter->parent : NULL;
-error:
-       BT_PUT(filter);
-       goto end;
 }
 
 BT_HIDDEN
@@ -131,20 +98,14 @@ enum bt_component_status bt_component_filter_get_input_port_count(
                struct bt_component *component, uint64_t *count)
 {
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
-       struct bt_component_filter *filter;
 
-       if (!component || !count) {
+       if (!component || !count ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               status = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       *count = (uint64_t) filter->input_ports->len;
+       *count = bt_component_get_input_port_count(component);
 end:
        return status;
 }
@@ -152,33 +113,29 @@ end:
 struct bt_port *bt_component_filter_get_input_port(
                struct bt_component *component, const char *name)
 {
-       struct bt_component_filter *filter;
-       struct bt_port *ret_port = NULL;
+       struct bt_port *port = NULL;
 
        if (!component || !name ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       ret_port = bt_component_get_port(filter->input_ports, name);
+       port = bt_component_get_input_port(component, name);
 end:
-       return ret_port;
+       return port;
 }
 
 struct bt_port *bt_component_filter_get_input_port_at_index(
                struct bt_component *component, int index)
 {
        struct bt_port *port = NULL;
-       struct bt_component_filter *filter;
 
        if (!component ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       port = bt_component_get_port_at_index(filter->input_ports, index);
+       port = bt_component_get_input_port_at_index(component, index);
 end:
        return port;
 }
@@ -193,59 +150,30 @@ struct bt_port *bt_component_filter_get_default_input_port(
 struct bt_port *bt_component_filter_add_input_port(
                struct bt_component *component, const char *name)
 {
-       struct bt_port *port;
-       struct bt_component_filter *filter;
+       struct bt_port *port = NULL;
 
        if (!component ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               port = NULL;
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       port = bt_component_add_port(component, filter->input_ports,
-                       BT_PORT_TYPE_INPUT, name);
+       port = bt_component_add_input_port(component, name);
 end:
        return port;
 }
 
-enum bt_component_status bt_component_filter_remove_input_port(
-               struct bt_component *component, const char *name)
-{
-       enum bt_component_status status;
-       struct bt_component_filter *filter;
-
-       if (!component ||
-                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               status = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       status = bt_component_remove_port(component, filter->input_ports,
-                       name);
-end:
-       return status;
-}
-
 enum bt_component_status bt_component_filter_get_output_port_count(
                struct bt_component *component, uint64_t *count)
 {
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
-       struct bt_component_filter *filter;
 
-       if (!component || !count) {
+       if (!component || !count ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               status = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       *count = (uint64_t) filter->output_ports->len;
+       *count = bt_component_get_output_port_count(component);
 end:
        return status;
 }
@@ -253,33 +181,29 @@ end:
 struct bt_port *bt_component_filter_get_output_port(
                struct bt_component *component, const char *name)
 {
-       struct bt_component_filter *filter;
-       struct bt_port *ret_port = NULL;
+       struct bt_port *port = NULL;
 
        if (!component || !name ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       ret_port = bt_component_get_port(filter->output_ports, name);
+       port = bt_component_get_output_port(component, name);
 end:
-       return ret_port;
+       return port;
 }
 
 struct bt_port *bt_component_filter_get_output_port_at_index(
                struct bt_component *component, int index)
 {
        struct bt_port *port = NULL;
-       struct bt_component_filter *filter;
 
        if (!component ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       port = bt_component_get_port_at_index(filter->output_ports, index);
+       port = bt_component_get_output_port_at_index(component, index);
 end:
        return port;
 }
@@ -294,37 +218,14 @@ struct bt_port *bt_component_filter_get_default_output_port(
 struct bt_port *bt_component_filter_add_output_port(
                struct bt_component *component, const char *name)
 {
-       struct bt_port *port;
-       struct bt_component_filter *filter;
+       struct bt_port *port = NULL;
 
        if (!component ||
                        component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               port = NULL;
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       port = bt_component_add_port(component, filter->output_ports,
-                       BT_PORT_TYPE_OUTPUT, name);
+       port = bt_component_add_output_port(component, name);
 end:
        return port;
 }
-
-enum bt_component_status bt_component_filter_remove_output_port(
-               struct bt_component *component, const char *name)
-{
-       enum bt_component_status status;
-       struct bt_component_filter *filter;
-
-       if (!component ||
-                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               status = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       status = bt_component_remove_port(component, filter->output_ports,
-                       name);
-end:
-       return status;
-}
This page took 0.025501 seconds and 4 git commands to generate.