Visibility: split graph API into public and private interfaces
[babeltrace.git] / lib / component / sink.c
index 509ea89c60ad9f7f277539b0e690262accb74fc8..91fa2353313ad310c5d0d718ed6cb46d4d15c1b5 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/values.h>
-#include <babeltrace/component/sink-internal.h>
+#include <babeltrace/component/component-sink-internal.h>
 #include <babeltrace/component/component-internal.h>
 #include <babeltrace/component/notification/notification.h>
 
@@ -37,7 +37,6 @@ enum bt_component_status bt_component_sink_validate(
                struct bt_component *component)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_component_sink *sink;
 
        if (!component) {
                ret = BT_COMPONENT_STATUS_INVALID;
@@ -49,33 +48,17 @@ enum bt_component_status bt_component_sink_validate(
                goto end;
        }
 
-       if (component->class->type != BT_COMPONENT_TYPE_SINK) {
+       if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       if (!sink->consume) {
-               printf_error("Invalid sink component; no notification consumption callback defined.");
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       ret = component_input_validate(&sink->input);
-       if (ret) {
-               goto end;
-       }
 end:
        return ret;
 }
 
-static
+BT_HIDDEN
 void bt_component_sink_destroy(struct bt_component *component)
 {
-       struct bt_component_sink *sink = container_of(component,
-                       struct bt_component_sink, parent);
-
-       component_input_fini(&sink->input);
 }
 
 BT_HIDDEN
@@ -83,307 +66,124 @@ struct bt_component *bt_component_sink_create(
                struct bt_component_class *class, struct bt_value *params)
 {
        struct bt_component_sink *sink = NULL;
-       enum bt_component_status ret;
 
        sink = g_new0(struct bt_component_sink, 1);
        if (!sink) {
                goto end;
        }
 
-       sink->parent.class = bt_get(class);
-       ret = bt_component_init(&sink->parent, bt_component_sink_destroy);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
-/*
-       ret = bt_component_sink_register_notification_type(&sink->parent,
-               BT_NOTIFICATION_TYPE_EVENT);
-       if (ret != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-*/
-       if (component_input_init(&sink->input)) {
-               goto error;
-       }
 end:
        return sink ? &sink->parent : NULL;
-error:
-       BT_PUT(sink);
-       return NULL;
-}
-
-static
-enum bt_component_status validate_inputs(struct bt_component_sink *sink)
-{
-       size_t array_size = sink->input.iterators->len;
-
-       if (array_size < sink->input.min_count ||
-                       array_size > sink->input.max_count) {
-               return BT_COMPONENT_STATUS_INVALID;
-       }
-
-       return BT_COMPONENT_STATUS_OK;
 }
 
+BT_HIDDEN
 enum bt_component_status bt_component_sink_consume(
                struct bt_component *component)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_component_sink *sink = NULL;
+       struct bt_component_class_sink *sink_class = NULL;
 
        if (!component) {
                ret = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
+       if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
                ret = BT_COMPONENT_STATUS_UNSUPPORTED;
                goto end;
        }
 
-       sink = container_of(component, struct bt_component_sink, parent);
-       if (!sink->input.validated) {
-               ret = validate_inputs(sink);
-               if (ret != BT_COMPONENT_STATUS_OK) {
-                       goto end;
-               }
-               sink->input.validated = true;
-       }
-
-       assert(sink->consume);
-       ret = sink->consume(component);
+       sink_class = container_of(component->class, struct bt_component_class_sink, parent);
+       assert(sink_class->methods.consume);
+       ret = sink_class->methods.consume(bt_private_component_from_component(component));
 end:
        return ret;
 }
-/*
-static
-enum bt_component_status bt_component_sink_register_notification_type(
-               struct bt_component *component, enum bt_notification_type type)
-{
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-       struct bt_component_sink *sink = NULL;
-
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
 
-       if (type <= BT_NOTIFICATION_TYPE_UNKNOWN ||
-               type >= BT_NOTIFICATION_TYPE_NR) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-       sink = container_of(component, struct bt_component_sink, parent);
-       if (type == BT_NOTIFICATION_TYPE_ALL) {
-               sink->registered_notifications_mask = ~(notification_mask_t) 0;
-       } else {
-               sink->registered_notifications_mask |=
-                       (notification_mask_t) 1 << type;
-       }
-end:
-       return ret;
-}
-*/
-enum bt_component_status bt_component_sink_set_consume_cb(
-               struct bt_component *component,
-               bt_component_sink_consume_cb consume)
+enum bt_component_status bt_component_sink_get_input_port_count(
+               struct bt_component *component, uint64_t *count)
 {
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
 
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component || !count ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       sink->consume = consume;
+       *count = bt_component_get_input_port_count(component);
 end:
-       return ret;
+       return status;
 }
 
-enum bt_component_status bt_component_sink_set_add_iterator_cb(
-               struct bt_component *component,
-               bt_component_sink_add_iterator_cb add_iterator)
+struct bt_port *bt_component_sink_get_input_port(
+               struct bt_component *component, const char *name)
 {
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_port *port = NULL;
 
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component || !name ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       sink->add_iterator = add_iterator;
+       port = bt_component_get_input_port(component, name);
 end:
-       return ret;
+       return port;
 }
 
-enum bt_component_status bt_component_sink_set_minimum_input_count(
-               struct bt_component *component,
-               unsigned int minimum)
+struct bt_port *bt_component_sink_get_input_port_at_index(
+               struct bt_component *component, int index)
 {
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_port *port = NULL;
 
-       if (!component) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
                goto end;
        }
 
-       sink = container_of(component, struct bt_component_sink, parent);
-       sink->input.min_count = minimum;
+       port = bt_component_get_input_port_at_index(component, index);
 end:
-       return ret;
+       return port;
 }
 
-enum bt_component_status bt_component_sink_set_maximum_input_count(
-               struct bt_component *component,
-               unsigned int maximum)
+struct bt_port *bt_component_sink_get_default_input_port(
+               struct bt_component *component)
 {
-       struct bt_component_sink *sink;
-       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_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (!component->initializing) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       sink->input.max_count = maximum;
-end:
-       return ret;
+       return bt_component_sink_get_input_port(component,
+                       DEFAULT_INPUT_PORT_NAME);
 }
 
-enum bt_component_status
-bt_component_sink_get_input_count(struct bt_component *component,
-               unsigned int *count)
+struct bt_private_port *
+bt_private_component_sink_get_input_private_port_at_index(
+               struct bt_private_component *private_component, int index)
 {
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component || !count) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       *count = (unsigned int) sink->input.iterators->len;
-end:
-       return ret;
+       return bt_private_port_from_port(
+               bt_component_sink_get_input_port_at_index(
+                       bt_component_from_private(private_component), index));
 }
 
-enum bt_component_status
-bt_component_sink_get_input_iterator(struct bt_component *component,
-               unsigned int input, struct bt_notification_iterator **iterator)
+struct bt_private_port *bt_private_component_sink_get_default_private_input_port(
+               struct bt_private_component *private_component)
 {
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
-
-       if (!component || !iterator) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       if (input >= (unsigned int) sink->input.iterators->len) {
-               ret = BT_COMPONENT_STATUS_INVALID;
-               goto end;
-       }
-
-       *iterator = bt_get(g_ptr_array_index(sink->input.iterators, input));
-end:
-       return ret;
+       return bt_private_port_from_port(
+               bt_component_sink_get_default_input_port(
+                       bt_component_from_private(private_component)));
 }
 
-enum bt_component_status
-bt_component_sink_add_iterator(struct bt_component *component,
-               struct bt_notification_iterator *iterator)
+struct bt_private_port *bt_private_component_sink_add_input_private_port(
+               struct bt_private_component *private_component,
+               const char *name)
 {
-       struct bt_component_sink *sink;
-       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_port *port = NULL;
+       struct bt_component *component =
+               bt_component_from_private(private_component);
 
-       if (!component || !iterator) {
-               ret = BT_COMPONENT_STATUS_INVALID;
+       if (!component ||
+                       component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
                goto end;
        }
 
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       sink = container_of(component, struct bt_component_sink, parent);
-       if (sink->input.iterators->len == sink->input.max_count) {
-               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
-               goto end;
-       }
-
-       if (sink->add_iterator) {
-               ret = sink->add_iterator(component, iterator);
-               if (ret != BT_COMPONENT_STATUS_OK) {
-                       goto end;
-               }
-       }
-
-       g_ptr_array_add(sink->input.iterators, bt_get(iterator));
+       port = bt_component_add_input_port(component, name);
 end:
-       return ret;
+       return bt_private_port_from_port(port);
 }
This page took 0.028153 seconds and 4 git commands to generate.