Implement the Component Graph API
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Dec 2016 19:10:22 +0000 (14:10 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:08 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/Makefile.am
include/babeltrace/plugin/component-connection-internal.h [new file with mode: 0644]
include/babeltrace/plugin/component-connection.h [new file with mode: 0644]
include/babeltrace/plugin/component-graph-internal.h [new file with mode: 0644]
include/babeltrace/plugin/component-graph.h [new file with mode: 0644]
lib/plugin-system/Makefile.am
lib/plugin-system/component-graph.c [new file with mode: 0644]

index 837f1f9c232f04736c5d873f738409957e43eb47..121d6a8ba2bb4f83096f82a4cf4907446e3aebb2 100644 (file)
@@ -41,7 +41,9 @@ babeltraceplugininclude_HEADERS = \
        babeltrace/plugin/plugin.h \
        babeltrace/plugin/component.h \
        babeltrace/plugin/component-class.h \
+       babeltrace/plugin/component-connection.h \
        babeltrace/plugin/component-factory.h \
+       babeltrace/plugin/component-graph.h \
        babeltrace/plugin/source.h \
        babeltrace/plugin/sink.h \
        babeltrace/plugin/filter.h \
@@ -113,9 +115,11 @@ noinst_HEADERS = \
        babeltrace/compat/mman.h \
        babeltrace/endian.h \
        babeltrace/mmap-align.h \
+       babeltrace/plugin/component-class-internal.h \
+       babeltrace/plugin/component-connection-internal.h \
        babeltrace/plugin/component-factory-internal.h \
        babeltrace/plugin/component-internal.h \
-       babeltrace/plugin/component-class-internal.h \
+       babeltrace/plugin/component-graph-internal.h \
        babeltrace/plugin/plugin-internal.h \
        babeltrace/plugin/filter-internal.h \
        babeltrace/plugin/sink-internal.h \
diff --git a/include/babeltrace/plugin/component-connection-internal.h b/include/babeltrace/plugin/component-connection-internal.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/include/babeltrace/plugin/component-connection.h b/include/babeltrace/plugin/component-connection.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/include/babeltrace/plugin/component-graph-internal.h b/include/babeltrace/plugin/component-graph-internal.h
new file mode 100644 (file)
index 0000000..ba618b7
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef BABELTRACE_PLUGIN_COMPONENT_GRAPH_INTERNAL_H
+#define BABELTRACE_PLUGIN_COMPONENT_GRAPH_INTERNAL_H
+
+/*
+ * BabelTrace - Component Graph Internal
+ *
+ * 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/plugin/component-graph.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/object-internal.h>
+#include <glib.h>
+
+struct bt_component_graph {
+       struct bt_object base;
+       /* Array of pointers to bt_component_connection. */
+       GPtrArray *connections;
+       /*
+        * Array of pointers to bt_component.
+        *
+        * Components which were added to the graph, but have not been connected
+        * yet.
+        */
+       GPtrArray *loose_components;
+       /*
+        * Array of pointers to sink bt_component.
+        *
+        * A reference is held to the Sink components in order to implement the
+        * "run" interface, which executes the sinks in a round-robin pattern.
+        */
+       GPtrArray *sinks;
+};
+
+#endif /* BABELTRACE_PLUGIN_COMPONENT_GRAPH_INTERNAL_H */
diff --git a/include/babeltrace/plugin/component-graph.h b/include/babeltrace/plugin/component-graph.h
new file mode 100644 (file)
index 0000000..60dfe47
--- /dev/null
@@ -0,0 +1,99 @@
+#ifndef BABELTRACE_PLUGIN_COMPONENT_GRAPH_H
+#define BABELTRACE_PLUGIN_COMPONENT_GRAPH_H
+
+/*
+ * BabelTrace - Babeltrace Component Graph Interface
+ *
+ * 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/plugin/component-class.h>
+#include <babeltrace/plugin/component.h>
+#include <babeltrace/values.h>
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum bt_component_graph_status {
+       BT_COMPONENT_GRAPH_STATUS_OK = 0,
+};
+
+/*
+Graph Ownership:
+
+                  Graph
+                    ^
+                    |
+               Connection
+                 ^     ^
+                /       \
+         ComponentA    ComponentB
+
+1) A graph only owns a set of connections.
+2) Components should _never_ own each other.
+3) A component can keep the complete graph "alive".
+
+*/
+extern struct bt_component_graph *bt_component_graph_create(void);
+
+/**
+ * Creates a connection object which owns both components, invokes the
+ * components' connection callback, and add the connection to the component
+ * graph's set of connection.
+ *
+ * Will add any component that is not already part of the graph.
+ */
+extern enum bt_component_graph_status bt_component_graph_connect(
+               struct bt_component_graph *graph, struct bt_component *upstream,
+               struct bt_component *downstream);
+
+/**
+ * Add component to the graph
+ */
+extern enum bt_component_graph_status bt_component_graph_add_component(
+               struct bt_component_graph *graph,
+               struct bt_component *component);
+
+/**
+ * Add a component as a "sibling" of the origin component. Sibling share
+ * connections equivalent to each other at the time of connection (same
+ * parents and children).
+ */
+extern enum bt_component_graph_status bt_component_graph_add_component_as_sibling(
+               struct bt_component_graph *graph, struct bt_component *origin,
+               struct bt_component *new_component);
+
+/**
+ * Runs "bt_component_sink_consume()" on all sinks in round-robin until they all
+ * indicate that the end is reached on that an error occured.
+ */
+extern enum bt_component_graph_status bt_component_graph_run(
+               struct bt_component_graph *graph);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_PLUGIN_COMPONENT_GRAPH_H */
index fddea24881f7798d249a0adc0d6cf3e71e0b9c41..45f11d8839e2cf07f617e8a3fc04772a6df84684 100644 (file)
@@ -9,6 +9,7 @@ libplugin_system_la_SOURCES = \
        component.c \
        component-class.c \
        component-factory.c \
+       component-graph.c \
        plugin.c \
        source.c \
        sink.c \
diff --git a/lib/plugin-system/component-graph.c b/lib/plugin-system/component-graph.c
new file mode 100644 (file)
index 0000000..551d2d4
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * component-graph.c
+ *
+ * Babeltrace Plugin Component Graph
+ *
+ * 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/plugin/component-graph-internal.h>
+#include <babeltrace/compiler.h>
+
+static void bt_component_graph_destroy(struct bt_object *obj)
+{
+       struct bt_component_graph *graph = container_of(obj,
+                       struct bt_component_graph, base);
+
+       if (graph->connections) {
+               g_ptr_array_free(graph->connections, TRUE);
+       }
+       if (graph->sinks) {
+               g_ptr_array_free(graph->sinks, TRUE);
+       }
+       g_free(graph);
+}
+
+struct bt_component_graph *bt_component_graph_create(void)
+{
+       struct bt_component_graph *graph;
+
+       graph = g_new0(struct bt_component_graph, 1);
+       if (!graph) {
+               goto end;
+       }
+
+       bt_object_init(graph, bt_component_graph_destroy);
+
+       graph->connections = g_ptr_array_new_with_free_func(bt_put);
+       if (!graph->connections) {
+               goto error;
+       }
+       graph->sinks = g_ptr_array_new_with_free_func(bt_put);
+       if (!graph->sinks) {
+               goto error;
+       }
+end:
+       return graph;
+error:
+       BT_PUT(graph);
+       goto end;
+}
+
+enum bt_component_graph_status bt_component_graph_connect(
+               struct bt_component_graph *graph, struct bt_component *upstream,
+               struct bt_component *downstream)
+{
+       return BT_COMPONENT_GRAPH_STATUS_OK;
+}
+
+enum bt_component_graph_status bt_component_graph_add_component(
+               struct bt_component_graph *graph,
+               struct bt_component *component)
+{
+       return BT_COMPONENT_GRAPH_STATUS_OK;
+}
+
+enum bt_component_graph_status bt_component_graph_add_component_as_sibling(
+               struct bt_component_graph *graph, struct bt_component *origin,
+               struct bt_component *new_component)
+{
+       return BT_COMPONENT_GRAPH_STATUS_OK;
+}
+
+enum bt_component_graph_status bt_component_graph_run(
+               struct bt_component_graph *graph)
+{
+       return BT_COMPONENT_GRAPH_STATUS_OK;
+}
+
This page took 0.028146 seconds and 4 git commands to generate.