Implement the component connection interface
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 10 Feb 2017 15:50:13 +0000 (10:50 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/Makefile.am
include/babeltrace/component/component-connection-internal.h
include/babeltrace/component/component-connection.h
include/babeltrace/component/component-input-internal.h [deleted file]
lib/component/Makefile.am
lib/component/component-connection.c [new file with mode: 0644]
lib/component/input.c [deleted file]

index dbd49630b72160c16e0988bea2e58834cf625a47..30386af88ea93b96c6c12526f19a841ca24347e8 100644 (file)
@@ -134,7 +134,6 @@ noinst_HEADERS = \
        babeltrace/component/component-filter-internal.h \
        babeltrace/component/component-sink-internal.h \
        babeltrace/component/component-source-internal.h \
-       babeltrace/component/component-input-internal.h \
        babeltrace/component/notification/eot-internal.h \
        babeltrace/component/notification/event-internal.h \
        babeltrace/component/notification/iterator-internal.h \
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c552636ed8553afd0d2200edfa0a5f7a52997e5a 100644 (file)
@@ -0,0 +1,56 @@
+#ifndef BABELTRACE_COMPONENT_CONNECTION_INTERNAL_H
+#define BABELTRACE_COMPONENT_CONNECTION_INTERNAL_H
+
+/*
+ * BabelTrace - Component Connection Internal
+ *
+ * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/component/component-connection.h>
+#include <babeltrace/object-internal.h>
+
+struct bt_graph;
+
+struct bt_connection {
+       /*
+        * The graph is a connection's parent and the connection is the parent
+        * of all iterators it has created.
+        */
+       struct bt_object base;
+       /*
+        * Weak references are held to both ports. Their existence is guaranteed
+        * by the existence of the graph and thus, of their respective
+        * components.
+        */
+       /* Downstream port. */
+       struct bt_port *input_port;
+       /* Upstream port. */
+       struct bt_port *output_port;
+};
+
+BT_HIDDEN
+struct bt_connection *bt_connection_create(struct bt_graph *graph,
+               struct bt_port *upstream, struct bt_port *downstream);
+
+#endif /* BABELTRACE_COMPONENT_CONNECTION_INTERNAL_H */
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7bcebcb874f370444f1d8674c6494865204def73 100644 (file)
@@ -0,0 +1,51 @@
+#ifndef BABELTRACE_COMPONENT_CONNECTION_H
+#define BABELTRACE_COMPONENT_CONNECTION_H
+
+/*
+ * BabelTrace - Babeltrace Component Connection Interface
+ *
+ * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_component;
+struct bt_connection;
+
+/* Returns the "downstream" input port. */
+extern struct bt_port *bt_connection_get_input_port(
+               struct bt_connection *connection);
+/* Returns the "upstream" output port. */
+extern struct bt_port *bt_connection_get_output_port(
+               struct bt_connection *connection);
+
+extern struct bt_notification_iterator *
+bt_connection_create_notification_iterator(struct bt_connection *connection);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_COMPONENT_CONNECTION_H */
diff --git a/include/babeltrace/component/component-input-internal.h b/include/babeltrace/component/component-input-internal.h
deleted file mode 100644 (file)
index 4748f31..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef BABELTRACE_COMPONENT_COMPONENT_INPUT_INTERNAL_H
-#define BABELTRACE_COMPONENT_COMPONENT_INPUT_INTERNAL_H
-
-/*
- * BabelTrace - Component Input
- *
- * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <babeltrace/babeltrace-internal.h>
-#include <glib.h>
-#include <stdbool.h>
-
-struct component_input {
-       /* Array of struct bt_notification_iterator pointers. */
-       GPtrArray *iterators;
-       unsigned int min_count;
-       unsigned int max_count;
-       bool validated;
-};
-
-BT_HIDDEN
-int component_input_init(struct component_input *input);
-
-BT_HIDDEN
-int component_input_validate(struct component_input *input);
-
-BT_HIDDEN
-void component_input_fini(struct component_input *input);
-
-#endif /* BABELTRACE_COMPONENT_COMPONENT_INPUT_INTERNAL_H */
index 4af458ca47f7e22e786ecdc2a83c039c9fdceecc..08da9f1914b9d921eabb25ff4e4ee21b8be768a7 100644 (file)
@@ -9,11 +9,11 @@ libcomponent_la_SOURCES = \
        component.c \
        component-class.c \
        component-graph.c \
+       component-connection.c \
        source.c \
        sink.c \
        filter.c \
-       iterator.c \
-       input.c
+       iterator.c
 
 libcomponent_la_LIBADD = \
        notification/libcomponent-notification.la
diff --git a/lib/component/component-connection.c b/lib/component/component-connection.c
new file mode 100644 (file)
index 0000000..3b509c3
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * component-connection.c
+ *
+ * Babeltrace Connection
+ *
+ * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/component/component-connection-internal.h>
+#include <babeltrace/component/component-graph-internal.h>
+#include <babeltrace/component/component-port-internal.h>
+#include <babeltrace/component/component-source-internal.h>
+#include <babeltrace/component/component-filter-internal.h>
+#include <babeltrace/object-internal.h>
+#include <babeltrace/compiler.h>
+#include <glib.h>
+
+static
+void bt_connection_destroy(struct bt_object *obj)
+{
+       struct bt_connection *connection = container_of(obj,
+                       struct bt_connection, base);
+
+       /*
+        * No bt_put on ports as a connection only holds _weak_ references
+        * to them.
+        */
+       g_free(connection);
+}
+
+BT_HIDDEN
+struct bt_connection *bt_connection_create(
+               struct bt_graph *graph,
+               struct bt_port *upstream, struct bt_port *downstream)
+{
+       struct bt_connection *connection = NULL;
+
+       if (bt_port_get_type(upstream) != BT_PORT_TYPE_OUTPUT) {
+               goto end;
+       }
+       if (bt_port_get_type(downstream) != BT_PORT_TYPE_INPUT) {
+               goto end;
+       }
+
+       connection = g_new0(struct bt_connection, 1);
+       if (!connection) {
+               goto end;
+       }
+
+       bt_object_init(connection, bt_connection_destroy);
+       /* Weak references are taken, see comment in header. */
+       connection->output_port = upstream;
+       connection->input_port = downstream;
+       bt_port_add_connection(upstream, connection);
+       bt_port_add_connection(downstream, connection);
+       bt_object_set_parent(connection, &graph->base);
+end:
+       return connection;
+}
+
+struct bt_port *bt_connection_get_input_port(
+               struct bt_connection *connection)
+{
+       return connection ? connection->input_port : NULL;
+}
+
+struct bt_port *bt_connection_get_output_port(
+               struct bt_connection *connection)
+{
+       return connection ? connection->output_port : NULL;
+}
+
+struct bt_notification_iterator *
+bt_connection_create_notification_iterator(struct bt_connection *connection)
+{
+       struct bt_component *upstream_component = NULL;
+       struct bt_notification_iterator *it = NULL;
+
+       if (!connection) {
+               goto end;
+       }
+
+       upstream_component = bt_port_get_component(connection->output_port);
+       assert(upstream_component);
+
+       switch (bt_component_get_class_type(upstream_component)) {
+       case BT_COMPONENT_CLASS_TYPE_SOURCE:
+               it = bt_component_source_create_notification_iterator(
+                               upstream_component);
+               break;
+       case BT_COMPONENT_CLASS_TYPE_FILTER:
+               it = bt_component_filter_create_notification_iterator(
+                               upstream_component);
+               break;
+       default:
+               goto end;
+       }
+end:
+       bt_put(upstream_component);
+       return it;
+}
diff --git a/lib/component/input.c b/lib/component/input.c
deleted file mode 100644 (file)
index c141564..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * input.c
- *
- * Babeltrace Component Input
- *
- * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <babeltrace/component/component-input-internal.h>
-#include <babeltrace/ref.h>
-
-BT_HIDDEN
-int component_input_init(struct component_input *input)
-{
-       input->min_count = 1;
-       input->max_count = 1;
-       input->iterators = g_ptr_array_new_with_free_func(bt_put);
-       if (!input->iterators) {
-               return 1;
-       }
-       return 0;
-}
-
-BT_HIDDEN
-int component_input_validate(struct component_input *input)
-{
-       if (input->min_count > input->max_count) {
-               printf_error("Invalid component configuration; minimum input count > maximum input count.");
-               return 1;
-       }
-       return 0;
-}
-
-BT_HIDDEN
-void component_input_fini(struct component_input *input)
-{
-       g_ptr_array_free(input->iterators, TRUE);
-}
This page took 0.02972 seconds and 4 git commands to generate.