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)
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,
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;
};
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;
};
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;
};
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);
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);
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)
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,
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);
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
*/
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 *` */
# 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);
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);
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,
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);
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,
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
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);
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,
};
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;
#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.
#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
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)
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.
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,
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)
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",
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;
}
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.
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 *);
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)); \
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,
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);
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);
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);
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);
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,
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),
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;
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;
}
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 {
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;
}
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,
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)
{
}
}
-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)
}
}
-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");
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),
"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;
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) {
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");
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;
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;
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;
};
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:
}
}
- 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,
}
}
- 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,
}
}
- 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();
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++;
}
}
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);
-}
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 */
"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,
#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 {
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 {
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;
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;
};
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) {
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) {
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();
}
}
}
-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,
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;
}
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,
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)
{
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);
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);
}
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;
}
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)
{
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");
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;
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);
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();
}