X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=include%2Fbabeltrace%2Fgraph%2Fgraph-internal.h;h=97289cf0f168e4b36d349845a5b0de199e46e34f;hb=5badd463e184894a3bfd5b8db257efc6f92c6374;hp=09927fcf0aeb740538636111772082dd2cbb7e8b;hpb=d6e69534ef08a2dd8bff9eb5af1eab63736b3d31;p=babeltrace.git diff --git a/include/babeltrace/graph/graph-internal.h b/include/babeltrace/graph/graph-internal.h index 09927fcf..97289cf0 100644 --- a/include/babeltrace/graph/graph-internal.h +++ b/include/babeltrace/graph/graph-internal.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include #include @@ -37,6 +39,12 @@ struct bt_component; struct bt_port; +enum bt_graph_configuration_state { + BT_GRAPH_CONFIGURATION_STATE_CONFIGURING, + BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED, + BT_GRAPH_CONFIGURATION_STATE_CONFIGURED, +}; + struct bt_graph { /** * A component graph contains components and point-to-point connection @@ -73,21 +81,17 @@ struct bt_graph { */ bool can_consume; + enum bt_graph_configuration_state config_state; + 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_sink_ports_disconnected; } listeners; /* Pool of `struct bt_message_event *` */ @@ -136,21 +140,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); @@ -196,4 +189,94 @@ const char *bt_graph_status_string(enum bt_graph_status status) } } +static inline +const char *bt_graph_configuration_state_string( + enum bt_graph_configuration_state state) +{ + switch (state) { + case BT_GRAPH_CONFIGURATION_STATE_CONFIGURING: + return "BT_GRAPH_CONFIGURATION_STATE_CONFIGURING"; + case BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED: + return "BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED"; + case BT_GRAPH_CONFIGURATION_STATE_CONFIGURED: + return "BT_GRAPH_CONFIGURATION_STATE_CONFIGURED"; + default: + return "(unknown)"; + } +} + +static inline +enum bt_graph_status bt_graph_configure(struct bt_graph *graph) +{ + enum bt_graph_status status = BT_GRAPH_STATUS_OK; + uint64_t i; + + if (likely(graph->config_state == + BT_GRAPH_CONFIGURATION_STATE_CONFIGURED)) { + goto end; + } + + graph->config_state = BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED; + + for (i = 0; i < graph->components->len; i++) { + struct bt_component *comp = graph->components->pdata[i]; + struct bt_component_sink *comp_sink = (void *) comp; + struct bt_component_class_sink *comp_cls_sink = + (void *) comp->class; + + if (comp->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { + continue; + } + + if (comp_sink->graph_is_configured_method_called) { + continue; + } + + if (comp_cls_sink->methods.graph_is_configured) { + enum bt_self_component_status comp_status; + +#ifdef BT_LIB_LOGD + BT_LIB_LOGD("Calling user's \"graph is configured\" method: " + "%![graph-]+g, %![comp-]+c", + graph, comp); +#endif + + comp_status = comp_cls_sink->methods.graph_is_configured( + (void *) comp_sink); + +#ifdef BT_LIB_LOGD + BT_LIB_LOGD("User method returned: status=%s", + bt_self_component_status_string(comp_status)); +#endif + +#ifdef BT_ASSERT_PRE + BT_ASSERT_PRE(comp_status == BT_SELF_COMPONENT_STATUS_OK || + comp_status == BT_SELF_COMPONENT_STATUS_ERROR || + comp_status == BT_SELF_COMPONENT_STATUS_NOMEM, + "Unexpected returned status: status=%s", + bt_self_component_status_string(comp_status)); +#endif + + if (comp_status != BT_SELF_COMPONENT_STATUS_OK) { +#ifdef BT_LIB_LOGW + BT_LIB_LOGW("User's \"graph is configured\" method failed: " + "%![comp-]+c, status=%s", + comp, + bt_self_component_status_string( + comp_status)); +#endif + + goto end; + } + } + + comp_sink->graph_is_configured_method_called = true; + } + + graph->config_state = BT_GRAPH_CONFIGURATION_STATE_CONFIGURED; + +end: + return status; +} + #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */