Visibility: split graph API into public and private interfaces
[babeltrace.git] / lib / component / filter.c
index 2c9fb471aba62fc5e6f0bec0c6ba1aac5156e548..2b1eb51f9d0a7c6cecc5a32c54ac154aedff26d0 100644 (file)
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/values.h>
-#include <babeltrace/component/input.h>
-#include <babeltrace/component/filter-internal.h>
+#include <babeltrace/component/component-filter-internal.h>
 #include <babeltrace/component/component-internal.h>
+#include <babeltrace/component/component-class-internal.h>
 #include <babeltrace/component/notification/notification.h>
 #include <babeltrace/component/notification/iterator-internal.h>
 
-enum bt_component_status bt_component_filter_set_iterator_init_cb(
-               struct bt_component *component,
-               bt_component_filter_init_iterator_cb init_iterator)
+BT_HIDDEN
+void bt_component_filter_destroy(struct bt_component *component)
 {
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+}
 
-       if (component->class->type != BT_COMPONENT_TYPE_FILTER ||
-                       !component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+BT_HIDDEN
+struct bt_component *bt_component_filter_create(
+               struct bt_component_class *class, struct bt_value *params)
+{
+       struct bt_component_filter *filter = NULL;
+
+       filter = g_new0(struct bt_component_filter, 1);
+       if (!filter) {
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       filter->init_iterator = init_iterator;
 end:
-       return ret;
+       return filter ? &filter->parent : NULL;
 }
 
-enum bt_component_status bt_component_filter_set_add_iterator_cb(
-               struct bt_component *component,
-               bt_component_filter_add_iterator_cb add_iterator)
+BT_HIDDEN
+enum bt_component_status bt_component_filter_validate(
+               struct bt_component *component)
 {
-       struct bt_component_filter *filter;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
        if (!component) {
@@ -65,240 +65,195 @@ enum bt_component_status bt_component_filter_set_add_iterator_cb(
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+       if (!component->class) {
+               ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (!component->initializing) {
+       if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       filter->add_iterator = add_iterator;
+       /* Enforce iterator limits. */
 end:
        return ret;
 }
 
-enum bt_component_status bt_component_filter_set_minimum_input_count(
-               struct bt_component *component,
-               unsigned int minimum)
+enum bt_component_status bt_component_filter_get_input_port_count(
+               struct bt_component *component, uint64_t *count)
 {
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
 
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component || !count ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       filter->input.min_count = minimum;
+       *count = bt_component_get_input_port_count(component);
 end:
-       return ret;
+       return status;
 }
 
-enum bt_component_status bt_component_filter_set_maximum_input_count(
-               struct bt_component *component,
-               unsigned int maximum)
+struct bt_port *bt_component_filter_get_input_port(
+               struct bt_component *component, const char *name)
 {
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
+       struct bt_port *port = NULL;
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component || !name ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       filter->input.max_count = maximum;
+       port = bt_component_get_input_port(component, name);
 end:
-       return ret;
+       return port;
 }
 
-enum bt_component_status
-bt_component_filter_get_input_count(struct bt_component *component,
-               unsigned int *count)
+struct bt_port *bt_component_filter_get_input_port_at_index(
+               struct bt_component *component, int index)
 {
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_port *port = NULL;
 
-       if (!component || !count) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       *count = (unsigned int) filter->input.iterators->len;
+       port = bt_component_get_input_port_at_index(component, index);
 end:
-       return ret;
+       return port;
 }
 
-enum bt_component_status
-bt_component_filter_get_input_iterator(struct bt_component *component,
-               unsigned int input, struct bt_notification_iterator **iterator)
+struct bt_port *bt_component_filter_get_default_input_port(
+               struct bt_component *component)
 {
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component || !iterator) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
+       return bt_component_filter_get_input_port(component,
+                       DEFAULT_INPUT_PORT_NAME);
+}
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
+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;
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       if (input >= (unsigned int) filter->input.iterators->len) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component || !count ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       *iterator = bt_get(g_ptr_array_index(filter->input.iterators, input));
+       *count = bt_component_get_output_port_count(component);
 end:
-       return ret;
+       return status;
 }
 
-enum bt_component_status bt_component_filter_add_iterator(
-               struct bt_component *component,
-               struct bt_notification_iterator *iterator)
+struct bt_port *bt_component_filter_get_output_port(
+               struct bt_component *component, const char *name)
 {
-       struct bt_component_filter *filter;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_port *port = NULL;
 
-       if (!component || !iterator) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component || !name ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
+       port = bt_component_get_output_port(component, name);
+end:
+       return port;
+}
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       if (filter->input.iterators->len == filter->input.max_count) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
+struct bt_port *bt_component_filter_get_output_port_at_index(
+               struct bt_component *component, int index)
+{
+       struct bt_port *port = NULL;
 
-       if (filter->add_iterator) {
-               ret = filter->add_iterator(component, iterator);
-               if (ret != BT_COMPONENT_STATUS_OK) {
-                       goto end;
-               }
+       if (!component ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+               goto end;
        }
 
-       g_ptr_array_add(filter->input.iterators, bt_get(iterator));
+       port = bt_component_get_output_port_at_index(component, index);
 end:
-       return ret;
+       return port;
 }
 
-struct bt_notification_iterator *bt_component_filter_create_iterator(
+struct bt_port *bt_component_filter_get_default_output_port(
                struct bt_component *component)
 {
-       return bt_component_create_iterator(component);
+       return bt_component_filter_get_output_port(component,
+                       DEFAULT_OUTPUT_PORT_NAME);
 }
 
-static
-void bt_component_filter_destroy(struct bt_component *component)
+struct bt_private_port *
+bt_private_component_filter_get_input_private_port_at_index(
+               struct bt_private_component *private_component, int index)
 {
-       struct bt_component_filter *filter = container_of(component,
-                       struct bt_component_filter, parent);
+       return bt_private_port_from_port(
+               bt_component_filter_get_input_port_at_index(
+                       bt_component_from_private(private_component), index));
+}
 
-       component_input_fini(&filter->input);
+struct bt_private_port *
+bt_private_component_filter_get_default_private_input_port(
+               struct bt_private_component *private_component)
+{
+       return bt_private_port_from_port(
+               bt_component_filter_get_default_input_port(
+                       bt_component_from_private(private_component)));
 }
 
-BT_HIDDEN
-struct bt_component *bt_component_filter_create(
-               struct bt_component_class *class, struct bt_value *params)
+struct bt_private_port *bt_private_component_filter_add_input_private_port(
+               struct bt_private_component *private_component,
+               const char *name)
 {
-       struct bt_component_filter *filter = NULL;
-       enum bt_component_status ret;
+       struct bt_port *port = NULL;
+       struct bt_component *component =
+               bt_component_from_private(private_component);
 
-       filter = g_new0(struct bt_component_filter, 1);
-       if (!filter) {
+       if (!component ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       filter->parent.class = bt_get(class);
-       ret = bt_component_init(&filter->parent, bt_component_filter_destroy);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
-       if (component_input_init(&filter->input)) {
-               goto error;
-       }
+       port = bt_component_add_input_port(component, name);
 end:
-       return filter ? &filter->parent : NULL;
-error:
-       BT_PUT(filter);
-       goto end;
+       return bt_private_port_from_port(port);
 }
 
-BT_HIDDEN
-enum bt_component_status bt_component_filter_validate(
-               struct bt_component *component)
+struct bt_private_port *
+bt_private_component_filter_get_output_private_port_at_index(
+               struct bt_private_component *private_component, int index)
 {
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_component_filter *filter;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
+       return bt_private_port_from_port(
+               bt_component_filter_get_output_port_at_index(
+                       bt_component_from_private(private_component), index));
+}
 
-       if (!component->class) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
+struct bt_private_port *
+bt_private_component_filter_get_default_private_output_port(
+               struct bt_private_component *private_component)
+{
+       return bt_private_port_from_port(
+               bt_component_filter_get_default_output_port(
+                       bt_component_from_private(private_component)));
+}
 
-       if (component->class->type != BT_COMPONENT_TYPE_FILTER) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
+struct bt_private_port *bt_private_component_filter_add_output_private_port(
+               struct bt_private_component *private_component,
+               const char *name)
+{
+       struct bt_port *port = NULL;
+       struct bt_component *component =
+               bt_component_from_private(private_component);
 
-       filter = container_of(component, struct bt_component_filter, parent);
-       if (!filter->init_iterator) {
-               printf_error("Invalid filter component; no iterator initialization callback defined.");
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
                goto end;
        }
 
-       ret = component_input_validate(&filter->input);
-       if (ret) {
-               goto end;
-       }
+       port = bt_component_add_output_port(component, name);
 end:
-       return ret;
+       return bt_private_port_from_port(port);
 }
This page took 0.028699 seconds and 4 git commands to generate.