From c0418dd9b92879bee1401108d888f0f2dc3f619e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 8 Dec 2016 14:10:22 -0500 Subject: [PATCH] Implement the Component Graph API MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 6 +- .../plugin/component-connection-internal.h | 0 .../babeltrace/plugin/component-connection.h | 0 .../plugin/component-graph-internal.h | 55 +++++++++++ include/babeltrace/plugin/component-graph.h | 99 +++++++++++++++++++ lib/plugin-system/Makefile.am | 1 + lib/plugin-system/component-graph.c | 98 ++++++++++++++++++ 7 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 include/babeltrace/plugin/component-connection-internal.h create mode 100644 include/babeltrace/plugin/component-connection.h create mode 100644 include/babeltrace/plugin/component-graph-internal.h create mode 100644 include/babeltrace/plugin/component-graph.h create mode 100644 lib/plugin-system/component-graph.c diff --git a/include/Makefile.am b/include/Makefile.am index 837f1f9c2..121d6a8ba 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 index 000000000..e69de29bb diff --git a/include/babeltrace/plugin/component-connection.h b/include/babeltrace/plugin/component-connection.h new file mode 100644 index 000000000..e69de29bb diff --git a/include/babeltrace/plugin/component-graph-internal.h b/include/babeltrace/plugin/component-graph-internal.h new file mode 100644 index 000000000..ba618b73f --- /dev/null +++ b/include/babeltrace/plugin/component-graph-internal.h @@ -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 + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include + +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 index 000000000..60dfe470d --- /dev/null +++ b/include/babeltrace/plugin/component-graph.h @@ -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 + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include + +#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 */ diff --git a/lib/plugin-system/Makefile.am b/lib/plugin-system/Makefile.am index fddea2488..45f11d883 100644 --- a/lib/plugin-system/Makefile.am +++ b/lib/plugin-system/Makefile.am @@ -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 index 000000000..551d2d44f --- /dev/null +++ b/lib/plugin-system/component-graph.c @@ -0,0 +1,98 @@ +/* + * component-graph.c + * + * Babeltrace Plugin Component Graph + * + * Copyright 2016 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include + +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; +} + -- 2.34.1