Rename <babeltrace/component/...> -> <babeltrace/graph/...>
[babeltrace.git] / lib / component / component.c
index 7a72fe797f02713acf1451f5f242c0f87676d2c3..e8c4b5af7c14e2167386c9d1886bfcd2ef20a442 100644 (file)
  * SOFTWARE.
  */
 
-#include <babeltrace/component/component.h>
-#include <babeltrace/component/component-internal.h>
-#include <babeltrace/component/component-class-internal.h>
-#include <babeltrace/component/component-source-internal.h>
-#include <babeltrace/component/component-filter-internal.h>
-#include <babeltrace/component/component-sink-internal.h>
-#include <babeltrace/component/connection-internal.h>
-#include <babeltrace/component/graph-internal.h>
-#include <babeltrace/component/notification/iterator-internal.h>
+#include <babeltrace/graph/private-component.h>
+#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-internal.h>
+#include <babeltrace/graph/component-class-internal.h>
+#include <babeltrace/graph/component-source-internal.h>
+#include <babeltrace/graph/component-filter-internal.h>
+#include <babeltrace/graph/component-sink-internal.h>
+#include <babeltrace/graph/private-connection.h>
+#include <babeltrace/graph/connection-internal.h>
+#include <babeltrace/graph/graph-internal.h>
+#include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/private-notification-iterator.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/ref.h>
@@ -79,8 +82,9 @@ void bt_component_destroy(struct bt_object *obj)
         * User data is destroyed first, followed by the concrete component
         * instance.
         */
-       if (component->class->methods.destroy) {
-               component->class->methods.destroy(component);
+       if (component->class->methods.finalize) {
+               component->class->methods.finalize(
+                       bt_private_component_from_component(component));
        }
 
        if (component->destroy) {
@@ -100,84 +104,16 @@ void bt_component_destroy(struct bt_object *obj)
        g_free(component);
 }
 
-enum bt_component_class_type bt_component_get_class_type(
-               struct bt_component *component)
+struct bt_component *bt_component_from_private_component(
+               struct bt_private_component *private_component)
 {
-       return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN;
+       return bt_get(bt_component_from_private(private_component));
 }
 
-BT_HIDDEN
-struct bt_notification_iterator *bt_component_create_iterator(
-               struct bt_component *component, void *init_method_data)
+enum bt_component_class_type bt_component_get_class_type(
+               struct bt_component *component)
 {
-       enum bt_notification_iterator_status ret_iterator;
-       enum bt_component_class_type type;
-       struct bt_notification_iterator *iterator = NULL;
-       struct bt_component_class *class = component->class;
-
-       if (!component) {
-               goto error;
-       }
-
-       type = bt_component_get_class_type(component);
-       if (type != BT_COMPONENT_CLASS_TYPE_SOURCE &&
-                       type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               /* Unsupported operation. */
-               goto error;
-       }
-
-       iterator = bt_notification_iterator_create(component);
-       if (!iterator) {
-               goto error;
-       }
-
-       switch (type) {
-       case BT_COMPONENT_CLASS_TYPE_SOURCE:
-       {
-               struct bt_component_class_source *source_class;
-               enum bt_notification_iterator_status status;
-
-               source_class = container_of(class, struct bt_component_class_source, parent);
-
-               if (source_class->methods.iterator.init) {
-                       status = source_class->methods.iterator.init(component,
-                                       iterator, init_method_data);
-                       if (status < 0) {
-                               goto error;
-                       }
-               }
-               break;
-       }
-       case BT_COMPONENT_CLASS_TYPE_FILTER:
-       {
-               struct bt_component_class_filter *filter_class;
-               enum bt_notification_iterator_status status;
-
-               filter_class = container_of(class, struct bt_component_class_filter, parent);
-
-               if (filter_class->methods.iterator.init) {
-                       status = filter_class->methods.iterator.init(component,
-                                       iterator, init_method_data);
-                       if (status < 0) {
-                               goto error;
-                       }
-               }
-               break;
-       }
-       default:
-               /* Unreachable. */
-               assert(0);
-       }
-
-       ret_iterator = bt_notification_iterator_validate(iterator);
-       if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
-               goto error;
-       }
-
-       return iterator;
-error:
-       BT_PUT(iterator);
-       return iterator;
+       return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN;
 }
 
 static
@@ -187,6 +123,7 @@ struct bt_port *bt_component_add_port(
 {
        size_t i;
        struct bt_port *new_port = NULL;
+       struct bt_graph *graph = NULL;
 
        if (!name || strlen(name) == 0) {
                goto end;
@@ -221,6 +158,16 @@ struct bt_port *bt_component_add_port(
         * is now protected by the component's own lifetime.
         */
        g_ptr_array_add(ports, new_port);
+
+       /*
+        * Notify the graph's creator that a new port was added.
+        */
+       graph = bt_component_get_graph(component);
+       if (graph) {
+               bt_graph_notify_port_added(graph, new_port);
+               BT_PUT(graph);
+       }
+
 end:
        return new_port;
 }
@@ -315,7 +262,8 @@ struct bt_component *bt_component_create_with_init_method_data(
        component->initializing = true;
 
        if (component_class->methods.init) {
-               ret = component_class->methods.init(component, params,
+               ret = component_class->methods.init(
+                       bt_private_component_from_component(component), params,
                        init_method_data);
                component->initializing = false;
                if (ret != BT_COMPONENT_STATUS_OK) {
@@ -379,15 +327,21 @@ struct bt_component_class *bt_component_get_class(
        return component ? bt_get(component->class) : NULL;
 }
 
-void *bt_component_get_private_data(struct bt_component *component)
+void *bt_private_component_get_user_data(
+               struct bt_private_component *private_component)
 {
+       struct bt_component *component =
+               bt_component_from_private(private_component);
+
        return component ? component->user_data : NULL;
 }
 
-enum bt_component_status
-bt_component_set_private_data(struct bt_component *component,
+enum bt_component_status bt_private_component_set_user_data(
+               struct bt_private_component *private_component,
                void *data)
 {
+       struct bt_component *component =
+               bt_component_from_private(private_component);
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
        if (!component || !component->initializing) {
@@ -515,6 +469,7 @@ void bt_component_remove_port_at_index(struct bt_component *component,
                GPtrArray *ports, size_t index)
 {
        struct bt_port *port;
+       struct bt_graph *graph;
 
        assert(ports);
        assert(index < ports->len);
@@ -531,7 +486,14 @@ void bt_component_remove_port_at_index(struct bt_component *component,
        /* Detach port from its component parent */
        BT_PUT(port->base.parent);
 
-       // TODO: notify graph user: component's port removed
+       /*
+        * Notify the graph's creator that a port is removed.
+        */
+       graph = bt_component_get_graph(component);
+       if (graph) {
+               bt_graph_notify_port_removed(graph, component, port);
+               BT_PUT(graph);
+       }
 }
 
 BT_HIDDEN
@@ -572,16 +534,20 @@ end:
 
 BT_HIDDEN
 enum bt_component_status bt_component_accept_port_connection(
-               struct bt_component *comp, struct bt_port *port)
+               struct bt_component *comp, struct bt_port *self_port,
+               struct bt_port *other_port)
 {
        enum bt_component_status status = BT_COMPONENT_STATUS_OK;
 
        assert(comp);
-       assert(port);
+       assert(self_port);
+       assert(other_port);
 
        if (comp->class->methods.accept_port_connection) {
                status = comp->class->methods.accept_port_connection(
-                       comp, port);
+                       bt_private_component_from_component(comp),
+                       bt_private_port_from_port(self_port),
+                       other_port);
        }
 
        return status;
@@ -595,6 +561,8 @@ void bt_component_port_disconnected(struct bt_component *comp,
        assert(port);
 
        if (comp->class->methods.port_disconnected) {
-               comp->class->methods.port_disconnected(comp, port);
+               comp->class->methods.port_disconnected(
+                       bt_private_component_from_component(comp),
+                       bt_private_port_from_port(port));
        }
 }
This page took 0.02879 seconds and 4 git commands to generate.