lib: add sink component class's "graph is configured" method
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 21 Feb 2019 22:12:11 +0000 (17:12 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
commit5badd463e184894a3bfd5b8db257efc6f92c6374
tree38ef958c1467e29fdf6cf2866044660f26c1d238
parent9a6502b6c579bb9371cd8bd8c5064074c80918d4
lib: add sink component class's "graph is configured" method

All filter component classes implement the same logic currently to
support their instance being connected input first or output first.

Before this patch, if a filter component was connected to a sink
component, the sink component's "input port connected" method was called
and this is where the sink component had to create an input port message
iterator. This made the filter message iterator initialize, but it was
possible that the filter's input ports were not connected yet. To
support this connection order, the filter message iterator had to add
itself to a list of iterators within the component's private data, and
upstream iterators had to be initialized when the filter component's
"input port connected" method was called. Also, when the filter message
iterator was finalized, it had to remove itself from the component's
list. This strategy worked, but it was cumbersome and did lead to
duplicated code amongst different filters.

This patch does the following:

* It makes the graph have two phases: configuration and
  post-configuration. The configuration phase is when you create and
  connect components. The post-configuration is as soon as you call
  bt_graph_run(), bt_graph_consume(), or
  bt_port_output_message_iterator_create().

* It makes it incorrect (validated in developer mode) to create an input
  port message iterator during the graph's configuration phase. In other
  words, an "input port connected" method cannot call
  bt_self_component_port_input_message_iterator_create() anymore.

* It adds an optional sink component class's "graph is configured"
  method. This method is considered to be called when the graph is
  configured (post-configuration phase): it is called at the beginning
  of bt_graph_run() or bt_graph_consume() when it was not previously
  called.

  This is where a sink can call
  bt_self_component_port_input_message_iterator_create() now. This leads
  to a chain of message iterator initialization which all occur during
  the post-configuration phase. This guarantees to the initialization
  methods that ports are connected, and that disconnected ports will
  never be connected.

This is not a big change for sink component classes, if any: for the
`sink.text.pretty`, `sink.utils.counter`, and `sink.utils.dummy`
component classes, the "input port connected" method is simply replaced
with the "graph is configured" method.

This is however a big change for filter component classes. For example,
the `flt.utils.muxer` component class is much simpler as of this patch:
it simply creates all its upstream message iterators in its message
iterator initialization method, and hundreds of lines of codes are
removed.

Checking that the graph is configured at the beginning of
bt_graph_consume() could potentially have a performance impact, but I
did not measure this. If it's the case, then we would need a dedicated
graph function, for example bt_graph_confirm_configuration(), to call
the "graph is configured" methods once before calling bt_graph_consume()
in a loop.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
20 files changed:
include/babeltrace/graph/component-class-internal.h
include/babeltrace/graph/component-class-sink.h
include/babeltrace/graph/component-sink-internal.h
include/babeltrace/graph/graph-internal.h
include/babeltrace/plugin/plugin-dev.h
lib/graph/component-class.c
lib/graph/component.c
lib/graph/graph.c
lib/graph/iterator.c
lib/lib-logging.c
lib/plugin/plugin-so.c
plugins/text/plugin.c
plugins/text/pretty/pretty.c
plugins/text/pretty/pretty.h
plugins/utils/counter/counter.c
plugins/utils/counter/counter.h
plugins/utils/dummy/dummy.c
plugins/utils/dummy/dummy.h
plugins/utils/muxer/muxer.c
plugins/utils/plugin.c
This page took 0.026981 seconds and 4 git commands to generate.