lib: add bt_graph_add_simple_sink_component()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 5 Aug 2019 20:15:32 +0000 (16:15 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Aug 2019 18:05:21 +0000 (14:05 -0400)
commit5efafa1acd5d42b0f555f77223fc809dbc53f4b3
tree4ce76668e550682b137d7695a9219d0fe0337221
parentdcf9ee12edab13c9fa446a869f2acee0f2f2404b
lib: add bt_graph_add_simple_sink_component()

This patch adds bt_graph_add_simple_sink_component(), an easy way to add
a simple sink component which has a single message iterator iterating a
single input port named `in` and which calls user-provided functions at
specific locations.

This makes it possible to create a sink component without having to:

* Create a sink component class with initialization, "graph is
  configured", "consume", and finalization methods.

* Create an input port in the component class's initialization method.

* Create an input port message iterator in the component class's "graph
  is configured" method.

* Put the input port message iterator's reference in the component
  class's finalization method.

The goal of this new function is to make it easy to get messages at the
sink endpoint of a graph, just like we used to do with the output port
message iterator concept (but the graph model is honored now). The user
must still call bt_graph_run() or bt_graph_run_once() to make her
consume function (see details below) called: the added simple sink
component is not special in any way.

bt_graph_add_simple_sink_component() receives three function pointers
(and custom user data):

Initialize (optional):
    Called after the simple sink component creates the input port
    message iterator in the "graph is configured" method.

    The user function receives the message iterator to perform any
    initial task.

Consume:
    Called for each "consume" method call of the simple sink component.

    The user function receives the message iterator and can get the next
    messages with bt_self_component_port_input_message_iterator_next()
    as usual.

Finalize (optional):
    Called when the simple sink component is finalized.

    The message iterator is not available at this point.

I'm not wrapping this one in Python because it's so easy to replicate
with our bindings:

    class _SimpleSink:
        def __init__(self, params, consume_cb):
            self._consume_cb = consume_cb
            self._add_input_port('in')

        def _user_graph_is_configured(self):
            self._msg_iter = self._create_input_port_message_iterator(
                self._input_ports['in']
            )

        def _consume(self):
            self._consume_cb(self._msg_iter)

    def _mein_consume(msg_iter):
        ...

    ...
    graph.add_component(_SimpleSink, 'simple', _mein_consume)
    ...

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I02aaae16215160cd861c2a76793adddf808202d6
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1828
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Tested-by: jenkins <jenkins@lttng.org>
include/babeltrace2/graph/graph.h
src/lib/graph/Makefile.am
src/lib/graph/component-class-sink-simple.c [new file with mode: 0644]
src/lib/graph/component-class-sink-simple.h [new file with mode: 0644]
src/lib/graph/graph.c
This page took 0.025204 seconds and 4 git commands to generate.