From 4725a2013cb518374822ccb490610b45f74dbdbf Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 20 Dec 2018 08:40:39 -0500 Subject: [PATCH] lib: fully configure graph (add components, connect ports), then run This patch makes the graph API force you to completely configure the graph, that is, add components and connect their ports, before you run it. When you run it, the graph is considered fully configured, and at this point you cannot add components or connect ports. This also means that components cannot remove or disconnect their own ports anymore. Therefore all the disconnection and port removal listeners and notifiers are removed. The purpose of this change is to make seeking possible for all message iterators. If a component can remove and add ports at will, considering that message iterators are completely independent, then seeking backwards is impossible without a scandalous hack because some message iterators are gone for good and cannot be created again since the ports do not exist anymore. This change implies that a `src.ctf.lttng-live` component will need to merge its messages itself to offer a single port on which you can create a single message iterator. If the LTTng live protocol supports seeking in the future, then, with a single port, the message iterator has total control to recreate old messages which belong to already ended streams. Note that this could apply to other, similar component classes as well. Offering a single stream per port is possible when the number of streams is known at component initialization time, which is the case for `src.ctf.fs`. `flt.utils.muxer` still adds a new input port on port connection, but this is all done before we call bt_graph_run(), which marks the graph as being completely configured. An output port message iterator marks its graph as being configured as soon as you call bt_port_output_message_iterator_next(), because you don't call bt_graph_run() in this situation. A graph's "configured" state is only set and checked in developer mode. New preconditions are: bt_self_component_port_input_message_iterator_next(): The graph is fully configured. bt_graph_add_source_component(): bt_graph_add_source_component_with_init_method_data(): bt_graph_add_filter_component(): bt_graph_add_filter_component_with_init_method_data(): bt_graph_add_sink_component(): bt_graph_add_sink_component_with_init_method_data(): bt_graph_connect_ports(): bt_self_component_source_add_output_port(): bt_self_component_filter_add_output_port(): bt_self_component_filter_add_input_port(): bt_self_component_sink_add_input_port(): The graph is not fully configured. Signed-off-by: Philippe Proulx --- .../babeltrace/graph/component-class-filter.h | 20 - .../graph/component-class-internal.h | 4 - .../babeltrace/graph/component-class-sink.h | 10 - .../babeltrace/graph/component-class-source.h | 9 - include/babeltrace/graph/component-internal.h | 4 - .../babeltrace/graph/connection-internal.h | 3 - include/babeltrace/graph/graph-internal.h | 38 +- include/babeltrace/graph/graph.h | 115 +--- .../babeltrace/graph/self-component-port.h | 4 - include/babeltrace/plugin/plugin-dev.h | 102 --- lib/graph/component-class.c | 52 -- lib/graph/component.c | 180 +----- lib/graph/connection.c | 32 - lib/graph/graph.c | 580 +---------------- lib/graph/iterator.c | 9 + lib/graph/port.c | 23 - lib/plugin/plugin-so.c | 80 --- plugins/utils/muxer/muxer.c | 30 +- plugins/utils/muxer/muxer.h | 5 - plugins/utils/plugin.c | 2 - tests/lib/test_graph_topo.c | 600 +----------------- 21 files changed, 58 insertions(+), 1844 deletions(-) diff --git a/include/babeltrace/graph/component-class-filter.h b/include/babeltrace/graph/component-class-filter.h index f0f99582..890cfdfa 100644 --- a/include/babeltrace/graph/component-class-filter.h +++ b/include/babeltrace/graph/component-class-filter.h @@ -105,16 +105,6 @@ typedef bt_self_component_status bt_self_component_port_output *self_port, const bt_port_input *other_port); -typedef void -(*bt_component_class_filter_input_port_disconnected_method)( - bt_self_component_filter *self_component, - bt_self_component_port_input *self_port); - -typedef void -(*bt_component_class_filter_output_port_disconnected_method)( - bt_self_component_filter *self_component, - bt_self_component_port_output *self_port); - static inline bt_component_class *bt_component_class_filter_as_component_class( bt_component_class_filter *comp_cls_filter) @@ -157,16 +147,6 @@ bt_component_class_filter_set_output_port_connected_method( bt_component_class_filter *comp_class, bt_component_class_filter_output_port_connected_method method); -extern bt_component_class_status -bt_component_class_filter_set_input_port_disconnected_method( - bt_component_class_filter *comp_class, - bt_component_class_filter_input_port_disconnected_method method); - -extern bt_component_class_status -bt_component_class_filter_set_output_port_disconnected_method( - bt_component_class_filter *comp_class, - bt_component_class_filter_output_port_disconnected_method method); - extern bt_component_class_status bt_component_class_filter_set_query_method( bt_component_class_filter *comp_class, diff --git a/include/babeltrace/graph/component-class-internal.h b/include/babeltrace/graph/component-class-internal.h index 741129ee..33813334 100644 --- a/include/babeltrace/graph/component-class-internal.h +++ b/include/babeltrace/graph/component-class-internal.h @@ -73,7 +73,6 @@ struct bt_component_class_source { bt_component_class_source_query_method query; bt_component_class_source_accept_output_port_connection_method accept_output_port_connection; bt_component_class_source_output_port_connected_method output_port_connected; - bt_component_class_source_output_port_disconnected_method output_port_disconnected; } methods; }; @@ -85,7 +84,6 @@ struct bt_component_class_sink { bt_component_class_sink_query_method query; bt_component_class_sink_accept_input_port_connection_method accept_input_port_connection; bt_component_class_sink_input_port_connected_method input_port_connected; - bt_component_class_sink_input_port_disconnected_method input_port_disconnected; bt_component_class_sink_consume_method consume; } methods; }; @@ -103,8 +101,6 @@ struct bt_component_class_filter { bt_component_class_filter_accept_output_port_connection_method accept_output_port_connection; bt_component_class_filter_input_port_connected_method input_port_connected; bt_component_class_filter_output_port_connected_method output_port_connected; - bt_component_class_filter_input_port_disconnected_method input_port_disconnected; - bt_component_class_filter_output_port_disconnected_method output_port_disconnected; } methods; }; diff --git a/include/babeltrace/graph/component-class-sink.h b/include/babeltrace/graph/component-class-sink.h index 3ad4d285..003f549f 100644 --- a/include/babeltrace/graph/component-class-sink.h +++ b/include/babeltrace/graph/component-class-sink.h @@ -72,11 +72,6 @@ typedef bt_self_component_status bt_self_component_port_input *self_port, const bt_port_output *other_port); -typedef void -(*bt_component_class_sink_input_port_disconnected_method)( - bt_self_component_sink *self_component, - bt_self_component_port_input *self_port); - typedef bt_self_component_status (*bt_component_class_sink_consume_method)( bt_self_component_sink *self_component); @@ -110,11 +105,6 @@ bt_component_class_sink_set_input_port_connected_method( bt_component_class_sink *comp_class, bt_component_class_sink_input_port_connected_method method); -extern bt_component_class_status -bt_component_class_sink_set_input_port_disconnected_method( - bt_component_class_sink *comp_class, - bt_component_class_sink_input_port_disconnected_method method); - extern bt_component_class_status bt_component_class_sink_set_query_method( bt_component_class_sink *comp_class, bt_component_class_sink_query_method method); diff --git a/include/babeltrace/graph/component-class-source.h b/include/babeltrace/graph/component-class-source.h index 000164c0..845a341e 100644 --- a/include/babeltrace/graph/component-class-source.h +++ b/include/babeltrace/graph/component-class-source.h @@ -92,10 +92,6 @@ typedef bt_self_component_status bt_self_component_port_output *self_port, const bt_port_input *other_port); -typedef void (*bt_component_class_source_output_port_disconnected_method)( - bt_self_component_source *self_component, - bt_self_component_port_output *self_port); - static inline bt_component_class *bt_component_class_source_as_component_class( bt_component_class_source *comp_cls_source) @@ -128,11 +124,6 @@ bt_component_class_source_set_output_port_connected_method( bt_component_class_source *comp_class, bt_component_class_source_output_port_connected_method method); -extern bt_component_class_status -bt_component_class_source_set_output_port_disconnected_method( - bt_component_class_source *comp_class, - bt_component_class_source_output_port_disconnected_method method); - extern bt_component_class_status bt_component_class_source_set_query_method( bt_component_class_source *comp_class, diff --git a/include/babeltrace/graph/component-internal.h b/include/babeltrace/graph/component-internal.h index 49c62d3f..d5555f1a 100644 --- a/include/babeltrace/graph/component-internal.h +++ b/include/babeltrace/graph/component-internal.h @@ -89,10 +89,6 @@ enum bt_self_component_status bt_component_port_connected( struct bt_component *comp, struct bt_port *self_port, struct bt_port *other_port); -BT_HIDDEN -void bt_component_port_disconnected(struct bt_component *comp, - struct bt_port *port); - BT_HIDDEN void bt_component_set_graph(struct bt_component *component, struct bt_graph *graph); diff --git a/include/babeltrace/graph/connection-internal.h b/include/babeltrace/graph/connection-internal.h index 72167919..1500b111 100644 --- a/include/babeltrace/graph/connection-internal.h +++ b/include/babeltrace/graph/connection-internal.h @@ -56,11 +56,8 @@ struct bt_connection { GPtrArray *iterators; bool notified_upstream_port_connected; - bool notified_upstream_port_disconnected; bool notified_downstream_port_connected; - bool notified_downstream_port_disconnected; bool notified_graph_ports_connected; - bool notified_graph_ports_disconnected; }; BT_HIDDEN diff --git a/include/babeltrace/graph/graph-internal.h b/include/babeltrace/graph/graph-internal.h index 7c1ac085..dc1399a8 100644 --- a/include/babeltrace/graph/graph-internal.h +++ b/include/babeltrace/graph/graph-internal.h @@ -73,23 +73,21 @@ struct bt_graph { */ bool can_consume; + /* + * True if the graph is configured, that is, components are + * added and connected. + */ + bool is_configured; + struct { GArray *source_output_port_added; GArray *filter_output_port_added; GArray *filter_input_port_added; GArray *sink_input_port_added; - GArray *source_output_port_removed; - GArray *filter_output_port_removed; - GArray *filter_input_port_removed; - GArray *sink_input_port_removed; GArray *source_filter_ports_connected; GArray *source_sink_ports_connected; GArray *filter_filter_ports_connected; GArray *filter_sink_ports_connected; - GArray *source_filter_ports_disconnected; - GArray *source_sink_ports_disconnected; - GArray *filter_filter_ports_disconnected; - GArray *filter_sink_ports_disconnected; } listeners; /* Pool of `struct bt_message_event *` */ @@ -131,6 +129,19 @@ void _bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume) # define bt_graph_set_can_consume(_graph, _can_consume) #endif +static inline +void _bt_graph_set_is_configured(struct bt_graph *graph, bool is_configured) +{ + BT_ASSERT(graph); + graph->is_configured = is_configured; +} + +#ifdef BT_DEV_MODE +# define bt_graph_set_is_configured _bt_graph_set_is_configured +#else +# define bt_graph_set_is_configured(_graph, _is_configured) +#endif + BT_HIDDEN enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, struct bt_component_sink *sink); @@ -138,21 +149,10 @@ enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, BT_HIDDEN void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port); -BT_HIDDEN -void bt_graph_notify_port_removed(struct bt_graph *graph, - struct bt_component *comp, struct bt_port *port); - BT_HIDDEN void bt_graph_notify_ports_connected(struct bt_graph *graph, struct bt_port *upstream_port, struct bt_port *downstream_port); -BT_HIDDEN -void bt_graph_notify_ports_disconnected(struct bt_graph *graph, - struct bt_component *upstream_comp, - struct bt_component *downstream_comp, - struct bt_port *upstream_port, - struct bt_port *downstream_port); - BT_HIDDEN void bt_graph_remove_connection(struct bt_graph *graph, struct bt_connection *connection); diff --git a/include/babeltrace/graph/graph.h b/include/babeltrace/graph/graph.h index 33b109ec..967bc91d 100644 --- a/include/babeltrace/graph/graph.h +++ b/include/babeltrace/graph/graph.h @@ -56,22 +56,6 @@ typedef void (*bt_graph_filter_component_output_port_added_listener_func)( const bt_component_filter *component, const bt_port_output *port, void *data); -typedef void (*bt_graph_filter_component_input_port_removed_listener_func)( - const bt_component_filter *component, - const bt_port_input *port, void *data); - -typedef void (*bt_graph_sink_component_input_port_removed_listener_func)( - const bt_component_sink *component, - const bt_port_input *port, void *data); - -typedef void (*bt_graph_source_component_output_port_removed_listener_func)( - const bt_component_source *component, - const bt_port_output *port, void *data); - -typedef void (*bt_graph_filter_component_output_port_removed_listener_func)( - const bt_component_filter *component, - const bt_port_output *port, void *data); - typedef void (*bt_graph_source_filter_component_ports_connected_listener_func)( const bt_component_source *source_component, const bt_component_filter *filter_component, @@ -97,34 +81,6 @@ typedef void (*bt_graph_filter_sink_component_ports_connected_listener_func)( const bt_port_output *upstream_port, const bt_port_input *downstream_port, void *data); -typedef void (*bt_graph_source_filter_component_ports_disconnected_listener_func)( - const bt_component_source *source_component, - const bt_component_filter *filter_component, - const bt_port_output *upstream_port, - const bt_port_input *downstream_port, - void *data); - -typedef void (*bt_graph_source_sink_component_ports_disconnected_listener_func)( - const bt_component_source *source_component, - const bt_component_sink *sink_component, - const bt_port_output *upstream_port, - const bt_port_input *downstream_port, - void *data); - -typedef void (*bt_graph_filter_filter_component_ports_disconnected_listener_func)( - const bt_component_filter *filter_component_upstream, - const bt_component_filter *filter_component_downstream, - const bt_port_output *upstream_port, - const bt_port_input *downstream_port, - void *data); - -typedef void (*bt_graph_filter_sink_component_ports_disconnected_listener_func)( - const bt_component_filter *filter_component, - const bt_component_sink *sink_component, - const bt_port_output *upstream_port, - const bt_port_input *downstream_port, - void *data); - typedef void (* bt_graph_listener_removed_func)(void *data); extern bt_graph *bt_graph_create(void); @@ -171,65 +127,32 @@ extern bt_graph_status bt_graph_connect_ports(bt_graph *graph, extern bt_graph_status bt_graph_run(bt_graph *graph); -extern bt_graph_status bt_graph_consume( - bt_graph *graph); +extern bt_graph_status bt_graph_consume(bt_graph *graph); -extern bt_graph_status -bt_graph_add_filter_component_input_port_added_listener( +extern bt_graph_status bt_graph_add_filter_component_input_port_added_listener( bt_graph *graph, bt_graph_filter_component_input_port_added_listener_func listener, bt_graph_listener_removed_func listener_removed, void *data, int *listener_id); -extern bt_graph_status -bt_graph_add_sink_component_input_port_added_listener( +extern bt_graph_status bt_graph_add_sink_component_input_port_added_listener( bt_graph *graph, bt_graph_sink_component_input_port_added_listener_func listener, bt_graph_listener_removed_func listener_removed, void *data, int *listener_id); -extern bt_graph_status -bt_graph_add_source_component_output_port_added_listener( +extern bt_graph_status bt_graph_add_source_component_output_port_added_listener( bt_graph *graph, bt_graph_source_component_output_port_added_listener_func listener, bt_graph_listener_removed_func listener_removed, void *data, int *listener_id); -extern bt_graph_status -bt_graph_add_filter_component_output_port_added_listener( +extern bt_graph_status bt_graph_add_filter_component_output_port_added_listener( bt_graph *graph, bt_graph_filter_component_output_port_added_listener_func listener, bt_graph_listener_removed_func listener_removed, void *data, int *listener_id); -extern bt_graph_status -bt_graph_add_filter_component_input_port_removed_listener( - bt_graph *graph, - bt_graph_filter_component_input_port_removed_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - -extern bt_graph_status -bt_graph_add_sink_component_input_port_removed_listener( - bt_graph *graph, - bt_graph_sink_component_input_port_removed_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - -extern bt_graph_status -bt_graph_add_source_component_output_port_removed_listener( - bt_graph *graph, - bt_graph_source_component_output_port_removed_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - -extern bt_graph_status -bt_graph_add_filter_component_output_port_removed_listener( - bt_graph *graph, - bt_graph_filter_component_output_port_removed_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - extern bt_graph_status bt_graph_add_source_filter_component_ports_connected_listener( bt_graph *graph, @@ -258,34 +181,6 @@ bt_graph_add_filter_sink_component_ports_connected_listener( bt_graph_listener_removed_func listener_removed, void *data, int *listener_id); -extern bt_graph_status -bt_graph_add_source_filter_component_ports_disconnected_listener( - bt_graph *graph, - bt_graph_source_filter_component_ports_disconnected_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - -extern bt_graph_status -bt_graph_add_filter_filter_component_ports_disconnected_listener( - bt_graph *graph, - bt_graph_filter_filter_component_ports_disconnected_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - -extern bt_graph_status -bt_graph_add_source_sink_component_ports_disconnected_listener( - bt_graph *graph, - bt_graph_source_sink_component_ports_disconnected_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - -extern bt_graph_status -bt_graph_add_filter_sink_component_ports_disconnected_listener( - bt_graph *graph, - bt_graph_filter_sink_component_ports_disconnected_listener_func listener, - bt_graph_listener_removed_func listener_removed, void *data, - int *listener_id); - extern bt_graph_status bt_graph_cancel(bt_graph *graph); #ifdef __cplusplus diff --git a/include/babeltrace/graph/self-component-port.h b/include/babeltrace/graph/self-component-port.h index b396afff..ad5daeb8 100644 --- a/include/babeltrace/graph/self-component-port.h +++ b/include/babeltrace/graph/self-component-port.h @@ -46,10 +46,6 @@ const bt_port *bt_self_component_port_as_port( extern bt_self_component *bt_self_component_port_borrow_component( bt_self_component_port *self_port); -extern bt_self_component_port_status -bt_self_component_port_remove_from_component( - bt_self_component_port *self_port); - extern void *bt_self_component_port_get_data( const bt_self_component_port *self_port); diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index 5b941a3b..09986c45 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -184,8 +184,6 @@ enum __bt_plugin_component_class_descriptor_attribute_type { BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD = 6, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD = 7, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD = 8, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD = 9, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD = 10, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD = 11, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD = 12, }; @@ -243,14 +241,6 @@ struct __bt_plugin_component_class_descriptor_attribute { bt_component_class_source_output_port_connected_method source_output_port_connected_method; bt_component_class_filter_output_port_connected_method filter_output_port_connected_method; - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD */ - bt_component_class_filter_input_port_disconnected_method filter_input_port_disconnected_method; - bt_component_class_sink_input_port_disconnected_method sink_input_port_disconnected_method; - - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD */ - bt_component_class_source_output_port_disconnected_method source_output_port_disconnected_method; - bt_component_class_filter_output_port_disconnected_method filter_output_port_disconnected_method; - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD */ bt_component_class_source_message_iterator_init_method source_msg_iter_init_method; bt_component_class_filter_message_iterator_init_method filter_msg_iter_init_method; @@ -858,54 +848,6 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_output_port_connected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD, _id, _comp_class_id, filter, _x) -/* - * Defines an input port disconnected method attribute attached to a - * specific filter component class descriptor. - * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Port disconnected method - * (bt_component_class_filter_input_port_disconnected_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_input_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, filter, _x) - -/* - * Defines an input port disconnected method attribute attached to a - * specific sink component class descriptor. - * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Port disconnected method - * (bt_component_class_sink_input_port_disconnected_method). - */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_input_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, sink, _x) - -/* - * Defines an output port disconnected method attribute attached to a - * specific source component class descriptor. - * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Port disconnected method - * (bt_component_class_source_output_port_disconnected_method). - */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_output_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, source, _x) - -/* - * Defines an output port disconnected method attribute attached to a - * specific filter component class descriptor. - * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Port disconnected method - * (bt_component_class_filter_output_port_disconnected_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_output_port_disconnected_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD, _id, _comp_class_id, filter, _x) - /* * Defines an iterator initialization method attribute attached to a * specific source component class descriptor. @@ -1298,50 +1240,6 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ #define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD(_name, _x) \ BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_CONNECTED_METHOD_WITH_ID(auto, _name, _x) -/* - * Defines an input port disconnected method attribute attached to a - * filter component class descriptor which is attached to the automatic - * plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_filter_input_port_disconnected_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an input port disconnected method attribute attached to a - * sink component class descriptor which is attached to the automatic - * plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_sink_input_port_disconnected_method). - */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_SINK_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an output port disconnected method attribute attached to a - * source component class descriptor which is attached to the automatic - * plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_source_output_port_disconnected_method). - */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an output port disconnected method attribute attached to a - * filter component class descriptor which is attached to the automatic - * plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Port disconnected (bt_component_class_filter_output_port_disconnected_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_OUTPUT_PORT_DISCONNECTED_METHOD_WITH_ID(auto, _name, _x) - /* * Defines an iterator initialization method attribute attached to a * source component class descriptor which is attached to the automatic diff --git a/lib/graph/component-class.c b/lib/graph/component-class.c index 165816ba..c3fd7c8a 100644 --- a/lib/graph/component-class.c +++ b/lib/graph/component-class.c @@ -466,58 +466,6 @@ int bt_component_class_filter_set_output_port_connected_method( return BT_COMPONENT_CLASS_STATUS_OK; } -int bt_component_class_filter_set_input_port_disconnected_method( - struct bt_component_class_filter *comp_cls, - bt_component_class_filter_input_port_disconnected_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); - comp_cls->methods.input_port_disconnected = method; - BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method" - ": %!+C", comp_cls); - return BT_COMPONENT_CLASS_STATUS_OK; -} - -int bt_component_class_sink_set_input_port_disconnected_method( - struct bt_component_class_sink *comp_cls, - bt_component_class_sink_input_port_disconnected_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); - comp_cls->methods.input_port_disconnected = method; - BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method" - ": %!+C", comp_cls); - return BT_COMPONENT_CLASS_STATUS_OK; -} - -int bt_component_class_source_set_output_port_disconnected_method( - struct bt_component_class_source *comp_cls, - bt_component_class_source_output_port_disconnected_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); - comp_cls->methods.output_port_disconnected = method; - BT_LIB_LOGV("Set source component class's \"output port disconnected\" method" - ": %!+C", comp_cls); - return BT_COMPONENT_CLASS_STATUS_OK; -} - -int bt_component_class_filter_set_output_port_disconnected_method( - struct bt_component_class_filter *comp_cls, - bt_component_class_filter_output_port_disconnected_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); - comp_cls->methods.output_port_disconnected = method; - BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method" - ": %!+C", comp_cls); - return BT_COMPONENT_CLASS_STATUS_OK; -} - int bt_component_class_source_set_message_iterator_init_method( struct bt_component_class_source *comp_cls, bt_component_class_source_message_iterator_init_method method) diff --git a/lib/graph/component.c b/lib/graph/component.c index 84193127..48454d64 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -204,6 +204,9 @@ struct bt_port *add_port( BT_ASSERT_PRE(graph && !bt_graph_is_canceled(graph), "Component's graph is canceled: %![comp-]+c, %![graph-]+g", component, graph); + BT_ASSERT_PRE(!graph->is_configured, + "Component's graph is already configured: " + "%![comp-]+c, %![graph-]+g", component, graph); // TODO: Validate that the name is not already used. @@ -453,110 +456,6 @@ struct bt_port_output *bt_component_add_output_port( BT_PORT_TYPE_OUTPUT, name, user_data); } -static -void remove_port_by_index(struct bt_component *component, - GPtrArray *ports, uint64_t index) -{ - struct bt_port *port; - struct bt_graph *graph; - - BT_ASSERT(ports); - BT_ASSERT(index < ports->len); - port = g_ptr_array_index(ports, index); - BT_LIB_LOGD("Removing port from component: %![comp-]+c, %![port-]+p", - component, port); - - /* Disconnect both ports of this port's connection, if any */ - if (port->connection) { - bt_connection_end(port->connection, true); - } - - /* - * The port's current reference count can be 0 at this point, - * which means its parent (component) keeps it alive. We are - * about to remove the port from its parent's container (with - * the g_ptr_array_remove_index() call below), which in this - * case would destroy it. This is not good because we still - * need the port for the bt_graph_notify_port_removed() call - * below (in which its component is `NULL` as expected because - * of the bt_object_set_parent() call below). - * - * To avoid a destroyed port during the message callback, - * get a reference now, and put it (destroying the port if its - * reference count is 0 at this point) after notifying the - * graph's user. - */ - bt_object_get_no_null_check(&port->base); - - /* - * Remove from parent's array of ports (weak refs). This never - * destroys the port object because its reference count is at - * least 1 thanks to the bt_object_get_no_null_check() call - * above. - */ - g_ptr_array_remove_index(ports, index); - - /* Detach port from its component parent */ - bt_object_set_parent(&port->base, NULL); - - /* - * Notify the graph's creator that a port is removed. - */ - graph = bt_component_borrow_graph(component); - if (graph) { - bt_graph_notify_port_removed(graph, component, port); - } - - BT_LIB_LOGD("Removed port from component: %![comp-]+c, %![port-]+p", - component, port); - - /* - * Put the local reference. If this port's reference count was 0 - * when entering this function, it is 1 now, so it is destroyed - * immediately. - */ - bt_object_put_no_null_check(&port->base); -} - -BT_HIDDEN -void bt_component_remove_port(struct bt_component *component, - struct bt_port *port) -{ - uint64_t i; - GPtrArray *ports = NULL; - - BT_ASSERT(component); - BT_ASSERT(port); - - switch (port->type) { - case BT_PORT_TYPE_INPUT: - ports = component->input_ports; - break; - case BT_PORT_TYPE_OUTPUT: - ports = component->output_ports; - break; - default: - abort(); - } - - BT_ASSERT(ports); - - for (i = 0; i < ports->len; i++) { - struct bt_port *cur_port = g_ptr_array_index(ports, i); - - if (cur_port == port) { - remove_port_by_index(component, ports, i); - goto end; - } - } - - BT_LIB_LOGW("Port to remove from component was not found: " - "%![comp-]+c, %![port-]+p", component, port); - -end: - return; -} - BT_HIDDEN enum bt_self_component_status bt_component_accept_port_connection( struct bt_component *comp, struct bt_port *self_port, @@ -706,79 +605,16 @@ enum bt_self_component_status bt_component_port_connected( status = method(comp, self_port, (void *) other_port); BT_LOGD("User method returned: status=%s", bt_self_component_status_string(status)); + BT_ASSERT_PRE(status == BT_SELF_COMPONENT_STATUS_OK || + status == BT_SELF_COMPONENT_STATUS_ERROR || + status == BT_SELF_COMPONENT_STATUS_NOMEM, + "Unexpected returned component status: status=%s", + bt_self_component_status_string(status)); } return status; } -BT_HIDDEN -void bt_component_port_disconnected(struct bt_component *comp, - struct bt_port *port) -{ - typedef void (*method_t)(void *, void *); - - method_t method = NULL; - - BT_ASSERT(comp); - BT_ASSERT(port); - - switch (comp->class->type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - { - struct bt_component_class_source *src_cc = (void *) comp->class; - - switch (port->type) { - case BT_PORT_TYPE_OUTPUT: - method = (method_t) src_cc->methods.output_port_disconnected; - break; - default: - abort(); - } - - break; - } - case BT_COMPONENT_CLASS_TYPE_FILTER: - { - struct bt_component_class_filter *flt_cc = (void *) comp->class; - - switch (port->type) { - case BT_PORT_TYPE_INPUT: - method = (method_t) flt_cc->methods.input_port_disconnected; - break; - case BT_PORT_TYPE_OUTPUT: - method = (method_t) flt_cc->methods.output_port_disconnected; - break; - default: - abort(); - } - - break; - } - case BT_COMPONENT_CLASS_TYPE_SINK: - { - struct bt_component_class_sink *sink_cc = (void *) comp->class; - - switch (port->type) { - case BT_PORT_TYPE_INPUT: - method = (method_t) sink_cc->methods.input_port_disconnected; - break; - default: - abort(); - } - - break; - } - default: - abort(); - } - - if (method) { - BT_LIB_LOGD("Calling user's \"port disconnected\" method: " - "%![comp-]+c, %![port-]+p", comp, port); - method(comp, port); - } -} - BT_HIDDEN void bt_component_add_destroy_listener(struct bt_component *component, bt_component_destroy_listener_func func, void *data) diff --git a/lib/graph/connection.c b/lib/graph/connection.c index d490c5dc..965c5eaa 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -157,11 +157,8 @@ end: BT_HIDDEN void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) { - struct bt_component *downstream_comp = NULL; - struct bt_component *upstream_comp = NULL; struct bt_port *downstream_port = conn->downstream_port; struct bt_port *upstream_port = conn->upstream_port; - struct bt_graph *graph = bt_connection_borrow_graph(conn); size_t i; BT_LIB_LOGD("Ending connection: %!+x, try-remove-from-graph=%d", @@ -179,8 +176,6 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) if (downstream_port) { BT_LIB_LOGD("Disconnecting connection's downstream port: %!+p", downstream_port); - downstream_comp = bt_port_borrow_component_inline( - downstream_port); bt_port_set_connection(downstream_port, NULL); conn->downstream_port = NULL; } @@ -188,37 +183,10 @@ void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph) if (upstream_port) { BT_LIB_LOGD("Disconnecting connection's upstream port: %!+p", upstream_port); - upstream_comp = bt_port_borrow_component_inline( - upstream_port); bt_port_set_connection(upstream_port, NULL); conn->upstream_port = NULL; } - if (downstream_comp && conn->notified_downstream_port_connected && - !conn->notified_downstream_port_disconnected) { - /* bt_component_port_disconnected() logs details */ - bt_component_port_disconnected(downstream_comp, - downstream_port); - conn->notified_downstream_port_disconnected = true; - } - - if (upstream_comp && conn->notified_upstream_port_connected && - !conn->notified_upstream_port_disconnected) { - /* bt_component_port_disconnected() logs details */ - bt_component_port_disconnected(upstream_comp, upstream_port); - conn->notified_upstream_port_disconnected = true; - } - - BT_ASSERT(graph); - - if (conn->notified_graph_ports_connected && - !conn->notified_graph_ports_disconnected) { - /* bt_graph_notify_ports_disconnected() logs details */ - bt_graph_notify_ports_disconnected(graph, upstream_comp, - downstream_comp, upstream_port, downstream_port); - conn->notified_graph_ports_disconnected = true; - } - /* * It is safe to put the local port references now that we don't * need them anymore. This could indeed destroy them. diff --git a/lib/graph/graph.c b/lib/graph/graph.c index f2895418..f0a919f6 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -49,14 +49,9 @@ typedef void (*port_added_func_t)(const void *, const void *, void *); -typedef void (*port_removed_func_t)(const void *, const void *, void *); - typedef void (*ports_connected_func_t)(const void *, const void *, const void *, const void *, void *); -typedef void (*ports_disconnected_func_t)(const void *, const void *, - const void *, const void *, void *); - typedef enum bt_self_component_status (*comp_init_method_t)(const void *, const void *, void *); @@ -70,21 +65,11 @@ struct bt_graph_listener_port_added { port_added_func_t func; }; -struct bt_graph_listener_port_removed { - struct bt_graph_listener base; - port_removed_func_t func; -}; - struct bt_graph_listener_ports_connected { struct bt_graph_listener base; ports_connected_func_t func; }; -struct bt_graph_listener_ports_disconnected { - struct bt_graph_listener base; - ports_disconnected_func_t func; -}; - #define INIT_LISTENERS_ARRAY(_type, _listeners) \ do { \ _listeners = g_array_new(FALSE, TRUE, sizeof(_type)); \ @@ -156,14 +141,6 @@ void destroy_graph(struct bt_object *obj) graph->listeners.filter_input_port_added); CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added, graph->listeners.sink_input_port_added); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, - graph->listeners.source_output_port_removed); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, - graph->listeners.filter_output_port_removed); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, - graph->listeners.filter_input_port_removed); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_removed, - graph->listeners.sink_input_port_removed); CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected, graph->listeners.source_filter_ports_connected); CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected, @@ -172,14 +149,6 @@ void destroy_graph(struct bt_object *obj) graph->listeners.source_sink_ports_connected); CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected, graph->listeners.filter_sink_ports_connected); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, - graph->listeners.source_filter_ports_disconnected); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, - graph->listeners.filter_filter_ports_disconnected); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, - graph->listeners.source_sink_ports_disconnected); - CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_disconnected, - graph->listeners.filter_sink_ports_disconnected); if (graph->messages) { g_ptr_array_free(graph->messages, TRUE); @@ -223,26 +192,6 @@ void destroy_graph(struct bt_object *obj) graph->listeners.sink_input_port_added = NULL; } - if (graph->listeners.source_output_port_removed) { - g_array_free(graph->listeners.source_output_port_removed, TRUE); - graph->listeners.source_output_port_removed = NULL; - } - - if (graph->listeners.filter_output_port_removed) { - g_array_free(graph->listeners.filter_output_port_removed, TRUE); - graph->listeners.filter_output_port_removed = NULL; - } - - if (graph->listeners.filter_input_port_removed) { - g_array_free(graph->listeners.filter_input_port_removed, TRUE); - graph->listeners.filter_input_port_removed = NULL; - } - - if (graph->listeners.sink_input_port_removed) { - g_array_free(graph->listeners.sink_input_port_removed, TRUE); - graph->listeners.sink_input_port_removed = NULL; - } - if (graph->listeners.source_filter_ports_connected) { g_array_free(graph->listeners.source_filter_ports_connected, TRUE); @@ -267,30 +216,6 @@ void destroy_graph(struct bt_object *obj) graph->listeners.filter_sink_ports_connected = NULL; } - if (graph->listeners.source_filter_ports_disconnected) { - g_array_free(graph->listeners.source_filter_ports_disconnected, - TRUE); - graph->listeners.source_filter_ports_disconnected = NULL; - } - - if (graph->listeners.source_sink_ports_disconnected) { - g_array_free(graph->listeners.source_sink_ports_disconnected, - TRUE); - graph->listeners.source_sink_ports_disconnected = NULL; - } - - if (graph->listeners.filter_filter_ports_disconnected) { - g_array_free(graph->listeners.filter_filter_ports_disconnected, - TRUE); - graph->listeners.filter_filter_ports_disconnected = NULL; - } - - if (graph->listeners.filter_sink_ports_disconnected) { - g_array_free(graph->listeners.filter_sink_ports_disconnected, - TRUE); - graph->listeners.filter_sink_ports_disconnected = NULL; - } - bt_object_pool_finalize(&graph->event_msg_pool); bt_object_pool_finalize(&graph->packet_begin_msg_pool); bt_object_pool_finalize(&graph->packet_end_msg_pool); @@ -388,38 +313,6 @@ struct bt_graph *bt_graph_create(void) goto error; } - INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, - graph->listeners.source_output_port_removed); - - if (!graph->listeners.source_output_port_removed) { - ret = -1; - goto error; - } - - INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, - graph->listeners.filter_output_port_removed); - - if (!graph->listeners.filter_output_port_removed) { - ret = -1; - goto error; - } - - INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, - graph->listeners.filter_input_port_removed); - - if (!graph->listeners.filter_input_port_removed) { - ret = -1; - goto error; - } - - INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_removed, - graph->listeners.sink_input_port_removed); - - if (!graph->listeners.sink_input_port_removed) { - ret = -1; - goto error; - } - INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected, graph->listeners.source_filter_ports_connected); @@ -452,38 +345,6 @@ struct bt_graph *bt_graph_create(void) goto error; } - INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, - graph->listeners.source_filter_ports_disconnected); - - if (!graph->listeners.source_filter_ports_disconnected) { - ret = -1; - goto error; - } - - INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, - graph->listeners.source_sink_ports_disconnected); - - if (!graph->listeners.source_sink_ports_disconnected) { - ret = -1; - goto error; - } - - INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, - graph->listeners.filter_filter_ports_disconnected); - - if (!graph->listeners.filter_filter_ports_disconnected) { - ret = -1; - goto error; - } - - INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_disconnected, - graph->listeners.filter_sink_ports_disconnected); - - if (!graph->listeners.filter_sink_ports_disconnected) { - ret = -1; - goto error; - } - ret = bt_object_pool_initialize(&graph->event_msg_pool, (bt_object_pool_new_object_func) bt_message_event_new, (bt_object_pool_destroy_object_func) destroy_message_event, @@ -545,6 +406,8 @@ enum bt_graph_status bt_graph_connect_ports( BT_ASSERT_PRE_NON_NULL(upstream_port, "Upstream port"); BT_ASSERT_PRE_NON_NULL(downstream_port, "Downstream port port"); BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); + BT_ASSERT_PRE(!graph->is_configured, + "Graph is already configured: %!+g", graph); BT_ASSERT_PRE(!bt_port_is_connected(upstream_port), "Upstream port is already connected: %!+p", upstream_port); BT_ASSERT_PRE(!bt_port_is_connected(downstream_port), @@ -808,8 +671,7 @@ end: return status; } -enum bt_graph_status bt_graph_consume( - struct bt_graph *graph) +enum bt_graph_status bt_graph_consume(struct bt_graph *graph) { enum bt_graph_status status; @@ -817,9 +679,10 @@ enum bt_graph_status bt_graph_consume( BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); BT_ASSERT_PRE(graph->can_consume, "Cannot consume graph in its current state: %!+g", graph); - bt_graph_set_can_consume(graph, BT_FALSE); + bt_graph_set_can_consume(graph, false); + bt_graph_set_is_configured(graph, true); status = consume_no_check(graph); - bt_graph_set_can_consume(graph, BT_TRUE); + bt_graph_set_can_consume(graph, true); return status; } @@ -831,7 +694,8 @@ enum bt_graph_status bt_graph_run(struct bt_graph *graph) BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); BT_ASSERT_PRE(graph->can_consume, "Cannot consume graph in its current state: %!+g", graph); - bt_graph_set_can_consume(graph, BT_FALSE); + bt_graph_set_can_consume(graph, false); + bt_graph_set_is_configured(graph, true); BT_LIB_LOGV("Running graph: %!+g", graph); do { @@ -876,7 +740,7 @@ enum bt_graph_status bt_graph_run(struct bt_graph *graph) end: BT_LIB_LOGV("Graph ran: %![graph-]+g, status=%s", graph, bt_graph_status_string(status)); - bt_graph_set_can_consume(graph, BT_TRUE); + bt_graph_set_can_consume(graph, true); return status; } @@ -1020,146 +884,6 @@ bt_graph_add_sink_component_input_port_added_listener( return BT_GRAPH_STATUS_OK; } -enum bt_graph_status -bt_graph_add_source_component_output_port_removed_listener( - struct bt_graph *graph, - bt_graph_source_component_output_port_removed_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_port_removed listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (port_removed_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.source_output_port_removed, listener); - listener_id = graph->listeners.source_output_port_removed->len - 1; - BT_LIB_LOGV("Added \"source component output port removed\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - -enum bt_graph_status -bt_graph_add_filter_component_output_port_removed_listener( - struct bt_graph *graph, - bt_graph_filter_component_output_port_removed_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_port_removed listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (port_removed_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.filter_output_port_removed, listener); - listener_id = graph->listeners.filter_output_port_removed->len - 1; - BT_LIB_LOGV("Added \"filter component output port removed\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - -enum bt_graph_status -bt_graph_add_filter_component_input_port_removed_listener( - struct bt_graph *graph, - bt_graph_filter_component_input_port_removed_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_port_removed listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (port_removed_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.filter_input_port_removed, listener); - listener_id = graph->listeners.filter_input_port_removed->len - 1; - BT_LIB_LOGV("Added \"filter component input port removed\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - -enum bt_graph_status -bt_graph_add_sink_component_input_port_removed_listener( - struct bt_graph *graph, - bt_graph_sink_component_input_port_removed_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_port_removed listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (port_removed_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.sink_input_port_removed, listener); - listener_id = graph->listeners.sink_input_port_removed->len - 1; - BT_LIB_LOGV("Added \"sink component input port removed\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - enum bt_graph_status bt_graph_add_source_filter_component_ports_connected_listener( struct bt_graph *graph, @@ -1304,150 +1028,6 @@ bt_graph_add_filter_sink_component_ports_connected_listener( return BT_GRAPH_STATUS_OK; } -enum bt_graph_status -bt_graph_add_source_filter_component_ports_disconnected_listener( - struct bt_graph *graph, - bt_graph_source_filter_component_ports_disconnected_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_ports_disconnected listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (ports_disconnected_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.source_filter_ports_disconnected, - listener); - listener_id = graph->listeners.source_filter_ports_disconnected->len - 1; - BT_LIB_LOGV("Added \"source to filter component ports disconnected\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - -enum bt_graph_status -bt_graph_add_source_sink_component_ports_disconnected_listener( - struct bt_graph *graph, - bt_graph_source_sink_component_ports_disconnected_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_ports_disconnected listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (ports_disconnected_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.source_sink_ports_disconnected, - listener); - listener_id = graph->listeners.source_sink_ports_disconnected->len - 1; - BT_LIB_LOGV("Added \"source to sink component ports disconnected\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - -enum bt_graph_status -bt_graph_add_filter_filter_component_ports_disconnected_listener( - struct bt_graph *graph, - bt_graph_filter_filter_component_ports_disconnected_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_ports_disconnected listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (ports_disconnected_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.filter_filter_ports_disconnected, - listener); - listener_id = graph->listeners.filter_filter_ports_disconnected->len - 1; - BT_LIB_LOGV("Added \"filter to filter component ports disconnected\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - -enum bt_graph_status -bt_graph_add_filter_sink_component_ports_disconnected_listener( - struct bt_graph *graph, - bt_graph_filter_sink_component_ports_disconnected_listener_func func, - bt_graph_listener_removed_func listener_removed, void *data, - int *out_listener_id) -{ - struct bt_graph_listener_ports_disconnected listener = { - .base = { - .removed = listener_removed, - .data = data, - }, - .func = (ports_disconnected_func_t) func, - }; - int listener_id; - - BT_ASSERT_PRE_NON_NULL(graph, "Graph"); - BT_ASSERT_PRE_NON_NULL(func, "Listener"); - BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener"); - BT_ASSERT_PRE(!graph->in_remove_listener, - "Graph currently executing a \"listener removed\" listener: " - "%!+g", graph); - g_array_append_val(graph->listeners.filter_sink_ports_disconnected, - listener); - listener_id = graph->listeners.filter_sink_ports_disconnected->len - 1; - BT_LIB_LOGV("Added \"filter to sink component ports disconnected\" listener to graph: " - "%![graph-]+g, listener-addr=%p, id=%d", graph, listener, - listener_id); - - if (listener_id) { - *out_listener_id = listener_id; - } - - return BT_GRAPH_STATUS_OK; -} - BT_HIDDEN void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port) { @@ -1516,72 +1096,6 @@ void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port) } } -BT_HIDDEN -void bt_graph_notify_port_removed(struct bt_graph *graph, - struct bt_component *comp, struct bt_port *port) -{ - uint64_t i; - GArray *listeners; - - BT_ASSERT(graph); - BT_ASSERT(port); - BT_LIB_LOGV("Notifying graph listeners that a port was removed: " - "%![graph-]+g, %![comp-]+c, %![port-]+p", graph, comp, port); - - switch (comp->class->type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - { - switch (port->type) { - case BT_PORT_TYPE_OUTPUT: - listeners = graph->listeners.source_output_port_removed; - break; - default: - abort(); - } - - break; - } - case BT_COMPONENT_CLASS_TYPE_FILTER: - { - switch (port->type) { - case BT_PORT_TYPE_INPUT: - listeners = graph->listeners.filter_input_port_removed; - break; - case BT_PORT_TYPE_OUTPUT: - listeners = graph->listeners.filter_output_port_removed; - break; - default: - abort(); - } - - break; - } - case BT_COMPONENT_CLASS_TYPE_SINK: - { - switch (port->type) { - case BT_PORT_TYPE_INPUT: - listeners = graph->listeners.sink_input_port_removed; - break; - default: - abort(); - } - - break; - } - default: - abort(); - } - - for (i = 0; i < listeners->len; i++) { - struct bt_graph_listener_port_removed *listener = - &g_array_index(listeners, - struct bt_graph_listener_port_removed, i); - - BT_ASSERT(listener->func); - listener->func(comp, port, listener->base.data); - } -} - BT_HIDDEN void bt_graph_notify_ports_connected(struct bt_graph *graph, struct bt_port *upstream_port, struct bt_port *downstream_port) @@ -1652,79 +1166,7 @@ void bt_graph_notify_ports_connected(struct bt_graph *graph, } } -BT_HIDDEN -void bt_graph_notify_ports_disconnected(struct bt_graph *graph, - struct bt_component *upstream_comp, - struct bt_component *downstream_comp, - struct bt_port *upstream_port, - struct bt_port *downstream_port) -{ - uint64_t i; - GArray *listeners; - - BT_ASSERT(graph); - BT_ASSERT(upstream_comp); - BT_ASSERT(downstream_comp); - BT_ASSERT(upstream_port); - BT_ASSERT(downstream_port); - BT_LIB_LOGV("Notifying graph listeners that ports were disconnected: " - "%![graph-]+g, %![up-port-]+p, %![down-port-]+p, " - "%![up-comp-]+c, %![down-comp-]+c", - graph, upstream_port, downstream_port, upstream_comp, - downstream_comp); - - switch (upstream_comp->class->type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - { - switch (downstream_comp->class->type) { - case BT_COMPONENT_CLASS_TYPE_FILTER: - listeners = - graph->listeners.source_filter_ports_disconnected; - break; - case BT_COMPONENT_CLASS_TYPE_SINK: - listeners = - graph->listeners.source_sink_ports_disconnected; - break; - default: - abort(); - } - - break; - } - case BT_COMPONENT_CLASS_TYPE_FILTER: - { - switch (downstream_comp->class->type) { - case BT_COMPONENT_CLASS_TYPE_FILTER: - listeners = - graph->listeners.filter_filter_ports_disconnected; - break; - case BT_COMPONENT_CLASS_TYPE_SINK: - listeners = - graph->listeners.filter_sink_ports_disconnected; - break; - default: - abort(); - } - - break; - } - default: - abort(); - } - - for (i = 0; i < listeners->len; i++) { - struct bt_graph_listener_ports_disconnected *listener = - &g_array_index(listeners, - struct bt_graph_listener_ports_disconnected, i); - - BT_ASSERT(listener->func); - listener->func(upstream_comp, downstream_comp, - upstream_port, downstream_port, listener->base.data); - } -} - -enum bt_graph_status bt_graph_cancel( - struct bt_graph *graph) +enum bt_graph_status bt_graph_cancel(struct bt_graph *graph) { BT_ASSERT_PRE_NON_NULL(graph, "Graph"); @@ -1792,6 +1234,8 @@ enum bt_graph_status add_component_with_init_method_data( BT_ASSERT_PRE_NON_NULL(graph, "Graph"); BT_ASSERT_PRE_NON_NULL(name, "Name"); BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph); + BT_ASSERT_PRE(!graph->is_configured, + "Graph is already configured: %!+g", graph); BT_ASSERT_PRE(!component_name_exists(graph, name), "Duplicate component name: %!+g, name=\"%s\"", graph, name); BT_ASSERT_PRE(!params || bt_value_is_map(params), diff --git a/lib/graph/iterator.c b/lib/graph/iterator.c index 95429fb5..51fa8d91 100644 --- a/lib/graph/iterator.c +++ b/lib/graph/iterator.c @@ -751,6 +751,9 @@ bt_self_component_port_input_message_iterator_next( "iterator is in the wrong state: %!+i", iterator); BT_ASSERT(iterator->upstream_component); BT_ASSERT(iterator->upstream_component->class); + BT_ASSERT_PRE(bt_component_borrow_graph(iterator->upstream_component)->is_configured, + "Graph is not configured: %!+g", + bt_component_borrow_graph(iterator->upstream_component)); BT_LIB_LOGD("Getting next self component input port " "message iterator's messages: %!+i", iterator); comp_cls = iterator->upstream_component->class; @@ -843,6 +846,12 @@ enum bt_message_iterator_status bt_port_output_message_iterator_next( BT_LIB_LOGD("Getting next output port message iterator's messages: " "%!+i", iterator); + /* + * As soon as the user calls this function, we mark the graph as + * being definitely configured. + */ + bt_graph_set_is_configured(iterator->graph, true); + graph_status = bt_graph_consume_sink_no_check(iterator->graph, iterator->colander); switch (graph_status) { diff --git a/lib/graph/port.c b/lib/graph/port.c index 86d01b92..a04049a1 100644 --- a/lib/graph/port.c +++ b/lib/graph/port.c @@ -167,29 +167,6 @@ end: return ret; } -enum bt_self_component_port_status bt_self_component_port_remove_from_component( - struct bt_self_component_port *self_port) -{ - struct bt_port *port = (void *) self_port; - struct bt_component *comp = NULL; - - BT_ASSERT_PRE_NON_NULL(port, "Port"); - BT_ASSERT_PRE(port_connection_iterators_are_finalized(port), - "At least one message iterator using this port has the wrong state."); - comp = (void *) bt_object_borrow_parent(&port->base); - if (!comp) { - BT_LIB_LOGV("Port already removed from its component: %!+p", - port); - goto end; - } - - /* bt_component_remove_port() logs details */ - bt_component_remove_port(comp, port); - -end: - return BT_SELF_PORT_STATUS_OK; -} - bt_bool bt_port_is_connected(const struct bt_port *port) { BT_ASSERT_PRE_NON_NULL(port, "Port"); diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index 2f936a79..94df0b32 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -297,7 +297,6 @@ enum bt_plugin_status bt_plugin_so_init( bt_component_class_source_query_method query; bt_component_class_source_accept_output_port_connection_method accept_output_port_connection; bt_component_class_source_output_port_connected_method output_port_connected; - bt_component_class_source_output_port_disconnected_method output_port_disconnected; bt_component_class_source_message_iterator_init_method msg_iter_init; bt_component_class_source_message_iterator_finalize_method msg_iter_finalize; } source; @@ -310,8 +309,6 @@ enum bt_plugin_status bt_plugin_so_init( bt_component_class_filter_accept_output_port_connection_method accept_output_port_connection; bt_component_class_filter_input_port_connected_method input_port_connected; bt_component_class_filter_output_port_connected_method output_port_connected; - bt_component_class_filter_input_port_disconnected_method input_port_disconnected; - bt_component_class_filter_output_port_disconnected_method output_port_disconnected; bt_component_class_filter_message_iterator_init_method msg_iter_init; bt_component_class_filter_message_iterator_finalize_method msg_iter_finalize; } filter; @@ -322,7 +319,6 @@ enum bt_plugin_status bt_plugin_so_init( bt_component_class_sink_query_method query; bt_component_class_sink_accept_input_port_connection_method accept_input_port_connection; bt_component_class_sink_input_port_connected_method input_port_connected; - bt_component_class_sink_input_port_disconnected_method input_port_disconnected; } sink; } methods; }; @@ -592,34 +588,6 @@ enum bt_plugin_status bt_plugin_so_init( abort(); } break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD: - switch (cc_type) { - case BT_COMPONENT_CLASS_TYPE_FILTER: - cc_full_descr->methods.filter.input_port_disconnected = - cur_cc_descr_attr->value.filter_input_port_disconnected_method; - break; - case BT_COMPONENT_CLASS_TYPE_SINK: - cc_full_descr->methods.sink.input_port_disconnected = - cur_cc_descr_attr->value.sink_input_port_disconnected_method; - break; - default: - abort(); - } - break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD: - switch (cc_type) { - case BT_COMPONENT_CLASS_TYPE_SOURCE: - cc_full_descr->methods.source.output_port_disconnected = - cur_cc_descr_attr->value.source_output_port_disconnected_method; - break; - case BT_COMPONENT_CLASS_TYPE_FILTER: - cc_full_descr->methods.filter.output_port_disconnected = - cur_cc_descr_attr->value.filter_output_port_disconnected_method; - break; - default: - abort(); - } - break; case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD: switch (cc_type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: @@ -849,18 +817,6 @@ enum bt_plugin_status bt_plugin_so_init( } } - if (cc_full_descr->methods.source.output_port_disconnected) { - ret = bt_component_class_source_set_output_port_disconnected_method( - src_comp_class, - cc_full_descr->methods.source.output_port_disconnected); - if (ret) { - BT_LOGE_STR("Cannot set source component class's \"output port disconnected\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); - goto end; - } - } - if (cc_full_descr->methods.source.msg_iter_init) { ret = bt_component_class_source_set_message_iterator_init_method( src_comp_class, @@ -971,30 +927,6 @@ enum bt_plugin_status bt_plugin_so_init( } } - if (cc_full_descr->methods.filter.input_port_disconnected) { - ret = bt_component_class_filter_set_input_port_disconnected_method( - flt_comp_class, - cc_full_descr->methods.filter.input_port_disconnected); - if (ret) { - BT_LOGE_STR("Cannot set filter component class's \"input port disconnected\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); - goto end; - } - } - - if (cc_full_descr->methods.filter.output_port_disconnected) { - ret = bt_component_class_filter_set_output_port_disconnected_method( - flt_comp_class, - cc_full_descr->methods.filter.output_port_disconnected); - if (ret) { - BT_LOGE_STR("Cannot set filter component class's \"output port disconnected\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); - goto end; - } - } - if (cc_full_descr->methods.filter.msg_iter_init) { ret = bt_component_class_filter_set_message_iterator_init_method( flt_comp_class, @@ -1081,18 +1013,6 @@ enum bt_plugin_status bt_plugin_so_init( } } - if (cc_full_descr->methods.sink.input_port_disconnected) { - ret = bt_component_class_sink_set_input_port_disconnected_method( - sink_comp_class, - cc_full_descr->methods.sink.input_port_disconnected); - if (ret) { - BT_LOGE_STR("Cannot set sink component class's \"input port disconnected\" method."); - status = BT_PLUGIN_STATUS_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); - goto end; - } - } - break; default: abort(); diff --git a/plugins/utils/muxer/muxer.c b/plugins/utils/muxer/muxer.c index 19c6b768..032fef41 100644 --- a/plugins/utils/muxer/muxer.c +++ b/plugins/utils/muxer/muxer.c @@ -1117,10 +1117,10 @@ bt_self_message_iterator_status muxer_msg_iter_do_next( BT_SELF_MESSAGE_ITERATOR_STATUS_OK; uint64_t i = 0; - while (i < capacity && status == BT_MESSAGE_ITERATOR_STATUS_OK) { + while (i < capacity && status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK) { status = muxer_msg_iter_do_next_one(muxer_comp, muxer_msg_iter, &msgs[i]); - if (status == BT_MESSAGE_ITERATOR_STATUS_OK) { + if (status == BT_SELF_MESSAGE_ITERATOR_STATUS_OK) { i++; } } @@ -1462,29 +1462,3 @@ bt_self_component_status muxer_input_port_connected( end: return status; } - -BT_HIDDEN -void muxer_input_port_disconnected( - bt_self_component_filter *self_component, - bt_self_component_port_input *self_port) -{ - struct muxer_comp *muxer_comp = - bt_self_component_get_data( - bt_self_component_filter_as_self_component( - self_component)); - const bt_port *port = - bt_self_component_port_as_port( - bt_self_component_port_input_as_self_component_port( - self_port)); - - BT_ASSERT(port); - BT_ASSERT(muxer_comp); - - /* One more available input port */ - muxer_comp->available_input_ports++; - BT_LOGD("Leaving disconnected input port available for future connections: " - "comp-addr=%p, muxer-comp-addr=%p, port-addr=%p, " - "port-name=\"%s\", avail-input-port-count=%zu", - self_component, muxer_comp, port, bt_port_get_name(port), - muxer_comp->available_input_ports); -} diff --git a/plugins/utils/muxer/muxer.h b/plugins/utils/muxer/muxer.h index ba439e23..1e706c0a 100644 --- a/plugins/utils/muxer/muxer.h +++ b/plugins/utils/muxer/muxer.h @@ -58,9 +58,4 @@ bt_self_component_status muxer_input_port_connected( bt_self_component_port_input *self_port, const bt_port_output *other_port); -BT_HIDDEN -void muxer_input_port_disconnected( - bt_self_component_filter *self_component, - bt_self_component_port_input *self_port); - #endif /* BABELTRACE_PLUGINS_UTILS_MUXER_H */ diff --git a/plugins/utils/plugin.c b/plugins/utils/plugin.c index bec501d9..814e3f25 100644 --- a/plugins/utils/plugin.c +++ b/plugins/utils/plugin.c @@ -71,8 +71,6 @@ BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(muxer, "Sort messages from multiple input ports to a single output port by time."); BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(muxer, muxer_init); BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD(muxer, muxer_finalize); -BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_DISCONNECTED_METHOD(muxer, - muxer_input_port_disconnected); BT_PLUGIN_FILTER_COMPONENT_CLASS_INPUT_PORT_CONNECTED_METHOD(muxer, muxer_input_port_connected); BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD(muxer, diff --git a/tests/lib/test_graph_topo.c b/tests/lib/test_graph_topo.c index 7c63ec2c..cf73109a 100644 --- a/tests/lib/test_graph_topo.c +++ b/tests/lib/test_graph_topo.c @@ -26,21 +26,16 @@ #include "tap/tap.h" -#define NR_TESTS 99 +#define NR_TESTS 48 enum event_type { SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION, SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION, SRC_COMP_OUTPUT_PORT_CONNECTED, SINK_COMP_INPUT_PORT_CONNECTED, - SRC_COMP_OUTPUT_PORT_DISCONNECTED, - SINK_COMP_INPUT_PORT_DISCONNECTED, GRAPH_SRC_OUTPUT_PORT_ADDED, GRAPH_SINK_INPUT_PORT_ADDED, - GRAPH_SRC_OUTPUT_PORT_REMOVED, - GRAPH_SINK_INPUT_PORT_REMOVED, GRAPH_SRC_SINK_PORTS_CONNECTED, - GRAPH_SRC_SINK_PORTS_DISCONNECTED, }; enum test { @@ -49,8 +44,6 @@ enum test { TEST_SRC_PORT_CONNECTED_ERROR, TEST_SINK_PORT_CONNECTED_ERROR, TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED, - TEST_SINK_REMOVES_PORT_IN_CONSUME, - TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT, }; struct event { @@ -81,16 +74,6 @@ struct event { const bt_port *other_port; } sink_comp_input_port_connected; - struct { - const bt_component *comp; - const bt_port *self_port; - } src_comp_output_port_disconnected; - - struct { - const bt_component *comp; - const bt_port *self_port; - } sink_comp_input_port_disconnected; - struct { const bt_component *comp; const bt_port *port; @@ -101,29 +84,12 @@ struct event { const bt_port *port; } graph_sink_input_port_added; - struct { - const bt_component *comp; - const bt_port *port; - } graph_src_output_port_removed; - - struct { - const bt_component *comp; - const bt_port *port; - } graph_sink_input_port_removed; - struct { const bt_component *upstream_comp; const bt_component *downstream_comp; const bt_port *upstream_port; const bt_port *downstream_port; } graph_src_sink_ports_connected; - - struct { - const bt_component *upstream_comp; - const bt_component *downstream_comp; - const bt_port *upstream_port; - const bt_port *downstream_port; - } graph_src_sink_ports_disconnected; } data; }; @@ -216,28 +182,6 @@ bool compare_events(struct event *ev_a, struct event *ev_b) return false; } break; - case SRC_COMP_OUTPUT_PORT_DISCONNECTED: - if (ev_a->data.src_comp_output_port_disconnected.comp != - ev_b->data.src_comp_output_port_disconnected.comp) { - return false; - } - - if (ev_a->data.src_comp_output_port_disconnected.self_port != - ev_b->data.src_comp_output_port_disconnected.self_port) { - return false; - } - break; - case SINK_COMP_INPUT_PORT_DISCONNECTED: - if (ev_a->data.sink_comp_input_port_disconnected.comp != - ev_b->data.sink_comp_input_port_disconnected.comp) { - return false; - } - - if (ev_a->data.sink_comp_input_port_disconnected.self_port != - ev_b->data.sink_comp_input_port_disconnected.self_port) { - return false; - } - break; case GRAPH_SRC_OUTPUT_PORT_ADDED: if (ev_a->data.graph_src_output_port_added.comp != ev_b->data.graph_src_output_port_added.comp) { @@ -260,28 +204,6 @@ bool compare_events(struct event *ev_a, struct event *ev_b) return false; } break; - case GRAPH_SRC_OUTPUT_PORT_REMOVED: - if (ev_a->data.graph_src_output_port_removed.comp != - ev_b->data.graph_src_output_port_removed.comp) { - return false; - } - - if (ev_a->data.graph_src_output_port_removed.port != - ev_b->data.graph_src_output_port_removed.port) { - return false; - } - break; - case GRAPH_SINK_INPUT_PORT_REMOVED: - if (ev_a->data.graph_sink_input_port_removed.comp != - ev_b->data.graph_sink_input_port_removed.comp) { - return false; - } - - if (ev_a->data.graph_sink_input_port_removed.port != - ev_b->data.graph_sink_input_port_removed.port) { - return false; - } - break; case GRAPH_SRC_SINK_PORTS_CONNECTED: if (ev_a->data.graph_src_sink_ports_connected.upstream_comp != ev_b->data.graph_src_sink_ports_connected.upstream_comp) { @@ -303,27 +225,6 @@ bool compare_events(struct event *ev_a, struct event *ev_b) return false; } break; - case GRAPH_SRC_SINK_PORTS_DISCONNECTED: - if (ev_a->data.graph_src_sink_ports_disconnected.upstream_comp != - ev_b->data.graph_src_sink_ports_disconnected.upstream_comp) { - return false; - } - - if (ev_a->data.graph_src_sink_ports_disconnected.downstream_comp != - ev_b->data.graph_src_sink_ports_disconnected.downstream_comp) { - return false; - } - - if (ev_a->data.graph_src_sink_ports_disconnected.upstream_port != - ev_b->data.graph_src_sink_ports_disconnected.upstream_port) { - return false; - } - - if (ev_a->data.graph_src_sink_ports_disconnected.downstream_port != - ev_b->data.graph_src_sink_ports_disconnected.downstream_port) { - return false; - } - break; default: abort(); } @@ -483,55 +384,6 @@ bt_self_component_status sink_input_port_connected( } } -static -void src_output_port_disconnected(bt_self_component_source *self_comp, - bt_self_component_port_output *self_comp_port) -{ - int ret; - struct event event = { - .type = SRC_COMP_OUTPUT_PORT_DISCONNECTED, - .data.src_comp_output_port_disconnected = { - .comp = bt_self_component_as_component( - bt_self_component_source_as_self_component( - self_comp)), - .self_port = bt_self_component_port_as_port( - bt_self_component_port_output_as_self_component_port( - self_comp_port)), - }, - }; - - append_event(&event); - - switch (current_test) { - case TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT: - ret = bt_self_component_port_remove_from_component( - bt_self_component_port_output_as_self_component_port( - self_comp_port)); - BT_ASSERT(ret == 0); - default: - break; - } -} - -static -void sink_input_port_disconnected(bt_self_component_sink *self_comp, - bt_self_component_port_input *self_comp_port) -{ - struct event event = { - .type = SINK_COMP_INPUT_PORT_DISCONNECTED, - .data.sink_comp_input_port_disconnected = { - .comp = bt_self_component_as_component( - bt_self_component_sink_as_self_component( - self_comp)), - .self_port = bt_self_component_port_as_port( - bt_self_component_port_input_as_self_component_port( - self_comp_port)), - }, - }; - - append_event(&event); -} - static bt_self_component_status src_init( bt_self_component_source *self_comp, @@ -562,24 +414,6 @@ static bt_self_component_status sink_consume( bt_self_component_sink *self_comp) { - bt_self_component_port_input *def_port; - int ret; - - switch (current_test) { - case TEST_SINK_REMOVES_PORT_IN_CONSUME: - case TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT: - def_port = bt_self_component_sink_borrow_input_port_by_name( - self_comp, "in"); - BT_ASSERT(def_port); - ret = bt_self_component_port_remove_from_component( - bt_self_component_port_input_as_self_component_port( - def_port)); - BT_ASSERT(ret == 0); - break; - default: - break; - } - return BT_SELF_COMPONENT_STATUS_OK; } @@ -613,36 +447,6 @@ void graph_sink_input_port_added(const bt_component_sink *comp, append_event(&event); } -static -void graph_src_output_port_removed(const bt_component_source *comp, - const bt_port_output *port, void *data) -{ - struct event event = { - .type = GRAPH_SRC_OUTPUT_PORT_REMOVED, - .data.graph_src_output_port_removed = { - .comp = bt_component_source_as_component_const(comp), - .port = bt_port_output_as_port_const(port), - }, - }; - - append_event(&event); -} - -static -void graph_sink_input_port_removed(const bt_component_sink *comp, - const bt_port_input *port, void *data) -{ - struct event event = { - .type = GRAPH_SINK_INPUT_PORT_REMOVED, - .data.graph_sink_input_port_removed = { - .comp = bt_component_sink_as_component_const(comp), - .port = bt_port_input_as_port_const(port), - }, - }; - - append_event(&event); -} - static void graph_src_sink_ports_connected(const bt_component_source *upstream_comp, const bt_component_sink *downstream_comp, @@ -666,29 +470,6 @@ void graph_src_sink_ports_connected(const bt_component_source *upstream_comp, append_event(&event); } -static -void graph_src_sink_ports_disconnected(const bt_component_source *upstream_comp, - const bt_component_sink *downstream_comp, - const bt_port_output *upstream_port, - const bt_port_input *downstream_port, void *data) -{ - struct event event = { - .type = GRAPH_SRC_SINK_PORTS_DISCONNECTED, - .data.graph_src_sink_ports_disconnected = { - .upstream_comp = - bt_component_source_as_component_const(upstream_comp), - .downstream_comp = - bt_component_sink_as_component_const(downstream_comp), - .upstream_port = - bt_port_output_as_port_const(upstream_port), - .downstream_port = - bt_port_input_as_port_const(downstream_port), - }, - }; - - append_event(&event); -} - static void init_test(void) { @@ -706,9 +487,6 @@ void init_test(void) ret = bt_component_class_source_set_output_port_connected_method( src_comp_class, src_output_port_connected); BT_ASSERT(ret == 0); - ret = bt_component_class_source_set_output_port_disconnected_method( - src_comp_class, src_output_port_disconnected); - BT_ASSERT(ret == 0); sink_comp_class = bt_component_class_sink_create("sink", sink_consume); BT_ASSERT(sink_comp_class); @@ -721,9 +499,6 @@ void init_test(void) ret = bt_component_class_sink_set_input_port_connected_method( sink_comp_class, sink_input_port_connected); BT_ASSERT(ret == 0); - ret = bt_component_class_sink_set_input_port_disconnected_method( - sink_comp_class, sink_input_port_disconnected); - BT_ASSERT(ret == 0); events = g_array_new(FALSE, TRUE, sizeof(struct event)); BT_ASSERT(events); } @@ -773,18 +548,9 @@ bt_graph *create_graph(void) ret = bt_graph_add_sink_component_input_port_added_listener( graph, graph_sink_input_port_added, NULL, NULL, NULL); BT_ASSERT(ret >= 0); - ret = bt_graph_add_source_component_output_port_removed_listener( - graph, graph_src_output_port_removed, NULL, NULL, NULL); - BT_ASSERT(ret >= 0); - ret = bt_graph_add_sink_component_input_port_removed_listener( - graph, graph_sink_input_port_removed, NULL, NULL, NULL); - BT_ASSERT(ret >= 0); ret = bt_graph_add_source_sink_component_ports_connected_listener( graph, graph_src_sink_ports_connected, NULL, NULL, NULL); BT_ASSERT(ret >= 0); - ret = bt_graph_add_source_sink_component_ports_disconnected_listener( - graph, graph_src_sink_ports_disconnected, NULL, NULL, NULL); - BT_ASSERT(ret >= 0); return graph; } @@ -796,354 +562,6 @@ void prepare_test(enum test test, const char *name) diag("test: %s", name); } -static -void test_sink_removes_port_in_consume_then_src_removes_disconnected_port(void) -{ - int ret; - const bt_component_source *src; - const bt_component_sink *sink; - const bt_component *gsrc; - const bt_component *gsink; - bt_graph *graph; - const bt_port_output *src_def_port; - const bt_port_input *sink_def_port; - const bt_port *gsrc_def_port; - const bt_port *gsink_def_port; - struct event event; - bt_graph_status status; - size_t src_accept_port_connection_pos; - size_t sink_accept_port_connection_pos; - size_t src_port_connected_pos; - size_t sink_port_connected_pos; - size_t graph_ports_connected_pos; - size_t src_port_disconnected_pos; - size_t sink_port_disconnected_pos; - size_t graph_ports_disconnected_pos; - size_t graph_port_removed_src_pos; - size_t graph_port_removed_sink_pos; - - prepare_test(TEST_SINK_REMOVES_PORT_IN_CONSUME_THEN_SRC_REMOVES_DISCONNECTED_PORT, - "sink removes port in consume, then source removes disconnected port"); - graph = create_graph(); - BT_ASSERT(graph); - src = create_src(graph); - sink = create_sink(graph); - src_def_port = bt_component_source_borrow_output_port_by_name_const(src, - "out"); - BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, - "in"); - BT_ASSERT(sink_def_port); - status = bt_graph_connect_ports(graph, src_def_port, - sink_def_port, NULL); - BT_ASSERT(status == 0); - gsrc = bt_component_source_as_component_const(src); - gsink = bt_component_sink_as_component_const(sink); - gsrc_def_port = bt_port_output_as_port_const(src_def_port); - gsink_def_port = bt_port_input_as_port_const(sink_def_port); - - /* We're supposed to have 7 events so far */ - ok(events->len == 7, "we have the expected number of events (before consume)"); - - /* Source's port added */ - event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; - event.data.graph_src_output_port_added.comp = gsrc; - event.data.graph_src_output_port_added.port = gsrc_def_port; - ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); - - /* Sink's port added */ - event.type = GRAPH_SINK_INPUT_PORT_ADDED; - event.data.graph_sink_input_port_added.comp = gsink; - event.data.graph_sink_input_port_added.port = gsink_def_port; - ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); - - /* Source's accept port connection */ - event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; - event.data.src_comp_accept_output_port_connection.comp = gsrc; - event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; - event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; - ok(has_event(&event), "got the expected source's accept port connection event"); - src_accept_port_connection_pos = event_pos(&event); - - /* Sink's accept port connection */ - event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; - event.data.sink_comp_accept_input_port_connection.comp = gsink; - event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; - event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; - ok(has_event(&event), "got the expected sink's accept port connection event"); - sink_accept_port_connection_pos = event_pos(&event); - - /* Source's port connected */ - event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; - event.data.src_comp_output_port_connected.comp = gsrc; - event.data.src_comp_output_port_connected.self_port = gsrc_def_port; - event.data.src_comp_output_port_connected.other_port = gsink_def_port; - ok(has_event(&event), "got the expected source's port connected event"); - src_port_connected_pos = event_pos(&event); - - /* Sink's port connected */ - event.type = SINK_COMP_INPUT_PORT_CONNECTED; - event.data.sink_comp_input_port_connected.comp = gsink; - event.data.sink_comp_input_port_connected.self_port = gsink_def_port; - event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; - ok(has_event(&event), "got the expected sink's port connected event"); - sink_port_connected_pos = event_pos(&event); - - /* Graph's ports connected */ - event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; - event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; - event.data.graph_src_sink_ports_connected.downstream_comp = gsink; - event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; - event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; - ok(has_event(&event), "got the expected graph's ports connected event"); - graph_ports_connected_pos = event_pos(&event); - - /* Order of events */ - ok(src_port_connected_pos < graph_ports_connected_pos, - "event order is good (1)"); - ok(sink_port_connected_pos < graph_ports_connected_pos, - "event order is good (2)"); - ok(src_accept_port_connection_pos < src_port_connected_pos, - "event order is good (3)"); - ok(sink_accept_port_connection_pos < sink_port_connected_pos, - "event order is good (4)"); - - /* Consume sink once */ - clear_events(); - ret = bt_graph_consume(graph); - BT_ASSERT(ret == 0); - - /* We're supposed to have 5 new events */ - ok(events->len == 5, "we have the expected number of events (after consume)"); - - /* Source's port disconnected */ - event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; - event.data.src_comp_output_port_disconnected.comp = gsrc; - event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; - ok(has_event(&event), "got the expected source's port disconnected event"); - src_port_disconnected_pos = event_pos(&event); - - /* Sink's port disconnected */ - event.type = SINK_COMP_INPUT_PORT_DISCONNECTED; - event.data.sink_comp_input_port_disconnected.comp = gsink; - event.data.sink_comp_input_port_disconnected.self_port = gsink_def_port; - ok(has_event(&event), "got the expected sink's port disconnected event"); - sink_port_disconnected_pos = event_pos(&event); - - /* Graph's ports disconnected */ - event.type = GRAPH_SRC_SINK_PORTS_DISCONNECTED; - event.data.graph_src_sink_ports_disconnected.upstream_comp = gsrc; - event.data.graph_src_sink_ports_disconnected.downstream_comp = gsink; - event.data.graph_src_sink_ports_disconnected.upstream_port = gsrc_def_port; - event.data.graph_src_sink_ports_disconnected.downstream_port = gsink_def_port; - ok(has_event(&event), "got the expected graph's ports disconnected event"); - graph_ports_disconnected_pos = event_pos(&event); - - /* Graph's port removed (sink) */ - event.type = GRAPH_SINK_INPUT_PORT_REMOVED; - event.data.graph_sink_input_port_removed.comp = gsink; - event.data.graph_sink_input_port_removed.port = gsink_def_port; - ok(has_event(&event), "got the expected graph's port removed event (for sink)"); - graph_port_removed_sink_pos = event_pos(&event); - - /* Graph's port removed (source) */ - event.type = GRAPH_SRC_OUTPUT_PORT_REMOVED; - event.data.graph_src_output_port_removed.comp = gsrc; - event.data.graph_src_output_port_removed.port = gsrc_def_port; - ok(has_event(&event), "got the expected graph's port removed event (for source)"); - graph_port_removed_src_pos = event_pos(&event); - - /* Order of events */ - ok(src_port_disconnected_pos < graph_ports_disconnected_pos, - "event order is good (5)"); - ok(src_port_disconnected_pos < graph_port_removed_sink_pos, - "event order is good (6)"); - ok(src_port_disconnected_pos < graph_port_removed_src_pos, - "event order is good (7)"); - ok(sink_port_disconnected_pos < graph_ports_disconnected_pos, - "event order is good (8)"); - ok(sink_port_disconnected_pos < graph_port_removed_sink_pos, - "event order is good (9)"); - ok(sink_port_disconnected_pos < graph_port_removed_src_pos, - "event order is good (10)"); - ok(graph_ports_disconnected_pos < graph_port_removed_sink_pos, - "event order is good (11)"); - ok(graph_port_removed_src_pos < graph_ports_disconnected_pos, - "event order is good (12)"); - ok(graph_port_removed_src_pos < graph_port_removed_sink_pos, - "event order is good (13)"); - - bt_graph_put_ref(graph); - bt_component_sink_put_ref(sink); - bt_component_source_put_ref(src); -} - -static -void test_sink_removes_port_in_consume(void) -{ - int ret; - const bt_component_source *src; - const bt_component_sink *sink; - const bt_component *gsrc; - const bt_component *gsink; - bt_graph *graph; - const bt_port_output *src_def_port; - const bt_port_input *sink_def_port; - const bt_port *gsrc_def_port; - const bt_port *gsink_def_port; - struct event event; - bt_graph_status status; - size_t src_accept_port_connection_pos; - size_t sink_accept_port_connection_pos; - size_t src_port_connected_pos; - size_t sink_port_connected_pos; - size_t graph_ports_connected_pos; - size_t src_port_disconnected_pos; - size_t sink_port_disconnected_pos; - size_t graph_ports_disconnected_pos; - size_t graph_port_removed_sink_pos; - - prepare_test(TEST_SINK_REMOVES_PORT_IN_CONSUME, - "sink removes port in consume"); - graph = create_graph(); - BT_ASSERT(graph); - src = create_src(graph); - sink = create_sink(graph); - src_def_port = bt_component_source_borrow_output_port_by_name_const(src, - "out"); - BT_ASSERT(src_def_port); - sink_def_port = bt_component_sink_borrow_input_port_by_name_const(sink, - "in"); - BT_ASSERT(sink_def_port); - status = bt_graph_connect_ports(graph, src_def_port, - sink_def_port, NULL); - BT_ASSERT(status == 0); - gsrc = bt_component_source_as_component_const(src); - gsink = bt_component_sink_as_component_const(sink); - gsrc_def_port = bt_port_output_as_port_const(src_def_port); - gsink_def_port = bt_port_input_as_port_const(sink_def_port); - - /* We're supposed to have 7 events so far */ - ok(events->len == 7, "we have the expected number of events (before consume)"); - - /* Source's port added */ - event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; - event.data.graph_src_output_port_added.comp = gsrc; - event.data.graph_src_output_port_added.port = gsrc_def_port; - ok(has_event(&event), "got the expected graph's port added event (for source, initial)"); - - /* Sink's port added */ - event.type = GRAPH_SINK_INPUT_PORT_ADDED; - event.data.graph_sink_input_port_added.comp = gsink; - event.data.graph_sink_input_port_added.port = gsink_def_port; - ok(has_event(&event), "got the expected graph's port added event (for sink, initial)"); - - /* Source's accept port connection */ - event.type = SRC_COMP_ACCEPT_OUTPUT_PORT_CONNECTION; - event.data.src_comp_accept_output_port_connection.comp = gsrc; - event.data.src_comp_accept_output_port_connection.self_port = gsrc_def_port; - event.data.src_comp_accept_output_port_connection.other_port = gsink_def_port; - ok(has_event(&event), "got the expected source's accept port connection event"); - src_accept_port_connection_pos = event_pos(&event); - - /* Sink's accept port connection */ - event.type = SINK_COMP_ACCEPT_INPUT_PORT_CONNECTION; - event.data.sink_comp_accept_input_port_connection.comp = gsink; - event.data.sink_comp_accept_input_port_connection.self_port = gsink_def_port; - event.data.sink_comp_accept_input_port_connection.other_port = gsrc_def_port; - ok(has_event(&event), "got the expected sink's accept port connection event"); - sink_accept_port_connection_pos = event_pos(&event); - - /* Source's port connected */ - event.type = SRC_COMP_OUTPUT_PORT_CONNECTED; - event.data.src_comp_output_port_connected.comp = gsrc; - event.data.src_comp_output_port_connected.self_port = gsrc_def_port; - event.data.src_comp_output_port_connected.other_port = gsink_def_port; - ok(has_event(&event), "got the expected source's port connected event"); - src_port_connected_pos = event_pos(&event); - - /* Sink's port connected */ - event.type = SINK_COMP_INPUT_PORT_CONNECTED; - event.data.sink_comp_input_port_connected.comp = gsink; - event.data.sink_comp_input_port_connected.self_port = gsink_def_port; - event.data.sink_comp_input_port_connected.other_port = gsrc_def_port; - ok(has_event(&event), "got the expected sink's port connected event"); - sink_port_connected_pos = event_pos(&event); - - /* Graph's ports connected */ - event.type = GRAPH_SRC_SINK_PORTS_CONNECTED; - event.data.graph_src_sink_ports_connected.upstream_comp = gsrc; - event.data.graph_src_sink_ports_connected.downstream_comp = gsink; - event.data.graph_src_sink_ports_connected.upstream_port = gsrc_def_port; - event.data.graph_src_sink_ports_connected.downstream_port = gsink_def_port; - ok(has_event(&event), "got the expected graph's ports connected event"); - graph_ports_connected_pos = event_pos(&event); - - /* Order of events */ - ok(src_port_connected_pos < graph_ports_connected_pos, - "event order is good (1)"); - ok(sink_port_connected_pos < graph_ports_connected_pos, - "event order is good (2)"); - ok(src_accept_port_connection_pos < src_port_connected_pos, - "event order is good (3)"); - ok(sink_accept_port_connection_pos < sink_port_connected_pos, - "event order is good (4)"); - - /* Consume sink once */ - clear_events(); - ret = bt_graph_consume(graph); - BT_ASSERT(ret == 0); - - /* We're supposed to have 4 new events */ - ok(events->len == 4, "we have the expected number of events (after consume)"); - - /* Source's port disconnected */ - event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; - event.data.src_comp_output_port_disconnected.comp = gsrc; - event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; - ok(has_event(&event), "got the expected source's port disconnected event"); - src_port_disconnected_pos = event_pos(&event); - - /* Sink's port disconnected */ - event.type = SINK_COMP_INPUT_PORT_DISCONNECTED; - event.data.sink_comp_input_port_disconnected.comp = gsink; - event.data.sink_comp_input_port_disconnected.self_port = gsink_def_port; - ok(has_event(&event), "got the expected sink's port disconnected event"); - sink_port_disconnected_pos = event_pos(&event); - - /* Graph's ports disconnected */ - event.type = GRAPH_SRC_SINK_PORTS_DISCONNECTED; - event.data.graph_src_sink_ports_disconnected.upstream_comp = gsrc; - event.data.graph_src_sink_ports_disconnected.downstream_comp = gsink; - event.data.graph_src_sink_ports_disconnected.upstream_port = gsrc_def_port; - event.data.graph_src_sink_ports_disconnected.downstream_port = gsink_def_port; - ok(has_event(&event), "got the expected graph's ports disconnected event"); - graph_ports_disconnected_pos = event_pos(&event); - - /* Graph's port removed (sink) */ - event.type = GRAPH_SINK_INPUT_PORT_REMOVED; - event.data.graph_sink_input_port_removed.comp = gsink; - event.data.graph_sink_input_port_removed.port = gsink_def_port; - ok(has_event(&event), "got the expected graph's port removed event (for sink)"); - graph_port_removed_sink_pos = event_pos(&event); - - /* Order of events */ - ok(src_port_disconnected_pos < graph_ports_disconnected_pos, - "event order is good (5)"); - ok(src_port_disconnected_pos < graph_port_removed_sink_pos, - "event order is good (7)"); - ok(sink_port_disconnected_pos < graph_ports_disconnected_pos, - "event order is good (8)"); - ok(sink_port_disconnected_pos < graph_port_removed_sink_pos, - "event order is good (10)"); - ok(graph_ports_disconnected_pos < graph_port_removed_sink_pos, - "event order is good (11)"); - - bt_component_sink_put_ref(sink); - bt_component_source_put_ref(src); - bt_graph_put_ref(graph); -} - static void test_src_adds_port_in_port_connected(void) { @@ -1488,7 +906,6 @@ void test_sink_port_connected_error(void) size_t src_accept_port_connection_pos; size_t sink_accept_port_connection_pos; size_t src_port_connected_pos; - size_t src_port_disconnected_pos; size_t sink_port_connected_pos; prepare_test(TEST_SINK_PORT_CONNECTED_ERROR, "port connected error: sink"); @@ -1512,8 +929,8 @@ void test_sink_port_connected_error(void) gsrc_def_port = bt_port_output_as_port_const(src_def_port); gsink_def_port = bt_port_input_as_port_const(sink_def_port); - /* We're supposed to have 5 events */ - ok(events->len == 7, "we have the expected number of events"); + /* We're supposed to have 6 events */ + ok(events->len == 6, "we have the expected number of events"); /* Source's port added */ event.type = GRAPH_SRC_OUTPUT_PORT_ADDED; @@ -1559,20 +976,11 @@ void test_sink_port_connected_error(void) ok(has_event(&event), "got the expected sink's port connected event"); sink_port_connected_pos = event_pos(&event); - /* Source's port disconnected */ - event.type = SRC_COMP_OUTPUT_PORT_DISCONNECTED; - event.data.src_comp_output_port_disconnected.comp = gsrc; - event.data.src_comp_output_port_disconnected.self_port = gsrc_def_port; - ok(has_event(&event), "got the expected source's port disconnected event"); - src_port_disconnected_pos = event_pos(&event); - /* Order of events */ ok(src_accept_port_connection_pos < src_port_connected_pos, "event order is good (1)"); ok(sink_accept_port_connection_pos < sink_port_connected_pos, "event order is good (2)"); - ok(sink_port_connected_pos < src_port_disconnected_pos, - "event order is good (3)"); bt_connection_put_ref(conn); bt_graph_put_ref(graph); @@ -1600,8 +1008,6 @@ int main(int argc, char **argv) test_src_port_connected_error(); test_sink_port_connected_error(); test_src_adds_port_in_port_connected(); - test_sink_removes_port_in_consume(); - test_sink_removes_port_in_consume_then_src_removes_disconnected_port(); fini_test(); return exit_status(); } -- 2.34.1