From 784cdc68b1cd40ca7ade4e0753830e45d0f524f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 10 Feb 2017 10:50:13 -0500 Subject: [PATCH] Implement the component connection interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/Makefile.am | 1 - .../component/component-connection-internal.h | 56 ++++++++ .../component/component-connection.h | 51 ++++++++ .../component/component-input-internal.h | 51 -------- lib/component/Makefile.am | 4 +- lib/component/component-connection.c | 121 ++++++++++++++++++ lib/component/input.c | 58 --------- 7 files changed, 230 insertions(+), 112 deletions(-) delete mode 100644 include/babeltrace/component/component-input-internal.h create mode 100644 lib/component/component-connection.c delete mode 100644 lib/component/input.c diff --git a/include/Makefile.am b/include/Makefile.am index dbd49630..30386af8 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -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 \ diff --git a/include/babeltrace/component/component-connection-internal.h b/include/babeltrace/component/component-connection-internal.h index e69de29b..c552636e 100644 --- a/include/babeltrace/component/component-connection-internal.h +++ b/include/babeltrace/component/component-connection-internal.h @@ -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 + * + * 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 + +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 */ diff --git a/include/babeltrace/component/component-connection.h b/include/babeltrace/component/component-connection.h index e69de29b..7bcebcb8 100644 --- a/include/babeltrace/component/component-connection.h +++ b/include/babeltrace/component/component-connection.h @@ -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 + * + * 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. + */ + +#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 index 4748f31c..00000000 --- a/include/babeltrace/component/component-input-internal.h +++ /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 - * - * 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 - -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 */ diff --git a/lib/component/Makefile.am b/lib/component/Makefile.am index 4af458ca..08da9f19 100644 --- a/lib/component/Makefile.am +++ b/lib/component/Makefile.am @@ -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 index 00000000..3b509c39 --- /dev/null +++ b/lib/component/component-connection.c @@ -0,0 +1,121 @@ +/* + * component-connection.c + * + * Babeltrace Connection + * + * Copyright 2017 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 +#include +#include +#include +#include + +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 index c1415640..00000000 --- a/lib/component/input.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * input.c - * - * Babeltrace Component Input - * - * 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 - -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); -} -- 2.34.1